args_test.go 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651
  1. // Copyright 2015 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. package api
  17. import (
  18. "bytes"
  19. "encoding/json"
  20. "fmt"
  21. "math/big"
  22. "testing"
  23. "github.com/ethereum/go-ethereum/rpc/shared"
  24. )
  25. func TestBlockheightInvalidString(t *testing.T) {
  26. v := "foo"
  27. var num int64
  28. str := ExpectInvalidTypeError(blockHeight(v, &num))
  29. if len(str) > 0 {
  30. t.Error(str)
  31. }
  32. }
  33. func TestBlockheightEarliest(t *testing.T) {
  34. v := "earliest"
  35. e := int64(0)
  36. var num int64
  37. err := blockHeight(v, &num)
  38. if err != nil {
  39. t.Error(err)
  40. }
  41. if num != e {
  42. t.Errorf("Expected %s but got %s", e, num)
  43. }
  44. }
  45. func TestBlockheightLatest(t *testing.T) {
  46. v := "latest"
  47. e := int64(-1)
  48. var num int64
  49. err := blockHeight(v, &num)
  50. if err != nil {
  51. t.Error(err)
  52. }
  53. if num != e {
  54. t.Errorf("Expected %s but got %s", e, num)
  55. }
  56. }
  57. func TestBlockheightPending(t *testing.T) {
  58. v := "pending"
  59. e := int64(-2)
  60. var num int64
  61. err := blockHeight(v, &num)
  62. if err != nil {
  63. t.Error(err)
  64. }
  65. if num != e {
  66. t.Errorf("Expected %s but got %s", e, num)
  67. }
  68. }
  69. func ExpectValidationError(err error) string {
  70. var str string
  71. switch err.(type) {
  72. case nil:
  73. str = "Expected error but didn't get one"
  74. case *shared.ValidationError:
  75. break
  76. default:
  77. str = fmt.Sprintf("Expected *rpc.ValidationError but got %T with message `%s`", err, err.Error())
  78. }
  79. return str
  80. }
  81. func ExpectInvalidTypeError(err error) string {
  82. var str string
  83. switch err.(type) {
  84. case nil:
  85. str = "Expected error but didn't get one"
  86. case *shared.InvalidTypeError:
  87. break
  88. default:
  89. str = fmt.Sprintf("Expected *rpc.InvalidTypeError but got %T with message `%s`", err, err.Error())
  90. }
  91. return str
  92. }
  93. func ExpectInsufficientParamsError(err error) string {
  94. var str string
  95. switch err.(type) {
  96. case nil:
  97. str = "Expected error but didn't get one"
  98. case *shared.InsufficientParamsError:
  99. break
  100. default:
  101. str = fmt.Sprintf("Expected *rpc.InsufficientParamsError but got %T with message %s", err, err.Error())
  102. }
  103. return str
  104. }
  105. func ExpectDecodeParamError(err error) string {
  106. var str string
  107. switch err.(type) {
  108. case nil:
  109. str = "Expected error but didn't get one"
  110. case *shared.DecodeParamError:
  111. break
  112. default:
  113. str = fmt.Sprintf("Expected *rpc.DecodeParamError but got %T with message `%s`", err, err.Error())
  114. }
  115. return str
  116. }
  117. func TestSha3(t *testing.T) {
  118. input := `["0x68656c6c6f20776f726c64"]`
  119. expected := "0x68656c6c6f20776f726c64"
  120. args := new(Sha3Args)
  121. json.Unmarshal([]byte(input), &args)
  122. if args.Data != expected {
  123. t.Error("got %s expected %s", input, expected)
  124. }
  125. }
  126. func TestSha3ArgsInvalid(t *testing.T) {
  127. input := `{}`
  128. args := new(Sha3Args)
  129. str := ExpectDecodeParamError(json.Unmarshal([]byte(input), &args))
  130. if len(str) > 0 {
  131. t.Error(str)
  132. }
  133. }
  134. func TestSha3ArgsEmpty(t *testing.T) {
  135. input := `[]`
  136. args := new(Sha3Args)
  137. str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), &args))
  138. if len(str) > 0 {
  139. t.Error(str)
  140. }
  141. }
  142. func TestSha3ArgsDataInvalid(t *testing.T) {
  143. input := `[4]`
  144. args := new(Sha3Args)
  145. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  146. if len(str) > 0 {
  147. t.Error(str)
  148. }
  149. }
  150. func TestGetBalanceArgs(t *testing.T) {
  151. input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "0x1f"]`
  152. expected := new(GetBalanceArgs)
  153. expected.Address = "0x407d73d8a49eeb85d32cf465507dd71d507100c1"
  154. expected.BlockNumber = 31
  155. args := new(GetBalanceArgs)
  156. if err := json.Unmarshal([]byte(input), &args); err != nil {
  157. t.Error(err)
  158. }
  159. if args.Address != expected.Address {
  160. t.Errorf("Address should be %v but is %v", expected.Address, args.Address)
  161. }
  162. if args.BlockNumber != expected.BlockNumber {
  163. t.Errorf("BlockNumber should be %v but is %v", expected.BlockNumber, args.BlockNumber)
  164. }
  165. }
  166. func TestGetBalanceArgsBlocknumMissing(t *testing.T) {
  167. input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1"]`
  168. expected := new(GetBalanceArgs)
  169. expected.Address = "0x407d73d8a49eeb85d32cf465507dd71d507100c1"
  170. expected.BlockNumber = -1
  171. args := new(GetBalanceArgs)
  172. if err := json.Unmarshal([]byte(input), &args); err != nil {
  173. t.Error(err)
  174. }
  175. if args.Address != expected.Address {
  176. t.Errorf("Address should be %v but is %v", expected.Address, args.Address)
  177. }
  178. if args.BlockNumber != expected.BlockNumber {
  179. t.Errorf("BlockNumber should be %v but is %v", expected.BlockNumber, args.BlockNumber)
  180. }
  181. }
  182. func TestGetBalanceArgsLatest(t *testing.T) {
  183. input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "latest"]`
  184. expected := new(GetBalanceArgs)
  185. expected.Address = "0x407d73d8a49eeb85d32cf465507dd71d507100c1"
  186. expected.BlockNumber = -1
  187. args := new(GetBalanceArgs)
  188. if err := json.Unmarshal([]byte(input), &args); err != nil {
  189. t.Error(err)
  190. }
  191. if args.Address != expected.Address {
  192. t.Errorf("Address should be %v but is %v", expected.Address, args.Address)
  193. }
  194. if args.BlockNumber != expected.BlockNumber {
  195. t.Errorf("BlockNumber should be %v but is %v", expected.BlockNumber, args.BlockNumber)
  196. }
  197. }
  198. func TestGetBalanceArgsEmpty(t *testing.T) {
  199. input := `[]`
  200. args := new(GetBalanceArgs)
  201. str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), &args))
  202. if len(str) > 0 {
  203. t.Error(str)
  204. }
  205. }
  206. func TestGetBalanceArgsInvalid(t *testing.T) {
  207. input := `6`
  208. args := new(GetBalanceArgs)
  209. str := ExpectDecodeParamError(json.Unmarshal([]byte(input), &args))
  210. if len(str) > 0 {
  211. t.Error(str)
  212. }
  213. }
  214. func TestGetBalanceArgsBlockInvalid(t *testing.T) {
  215. input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1", false]`
  216. args := new(GetBalanceArgs)
  217. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  218. if len(str) > 0 {
  219. t.Error(str)
  220. }
  221. }
  222. func TestGetBalanceArgsAddressInvalid(t *testing.T) {
  223. input := `[-9, "latest"]`
  224. args := new(GetBalanceArgs)
  225. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  226. if len(str) > 0 {
  227. t.Error(str)
  228. }
  229. }
  230. func TestGetBlockByHashArgs(t *testing.T) {
  231. input := `["0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331", true]`
  232. expected := new(GetBlockByHashArgs)
  233. expected.BlockHash = "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331"
  234. expected.IncludeTxs = true
  235. args := new(GetBlockByHashArgs)
  236. if err := json.Unmarshal([]byte(input), &args); err != nil {
  237. t.Error(err)
  238. }
  239. if args.BlockHash != expected.BlockHash {
  240. t.Errorf("BlockHash should be %v but is %v", expected.BlockHash, args.BlockHash)
  241. }
  242. if args.IncludeTxs != expected.IncludeTxs {
  243. t.Errorf("IncludeTxs should be %v but is %v", expected.IncludeTxs, args.IncludeTxs)
  244. }
  245. }
  246. func TestGetBlockByHashArgsEmpty(t *testing.T) {
  247. input := `[]`
  248. args := new(GetBlockByHashArgs)
  249. str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), &args))
  250. if len(str) > 0 {
  251. t.Error(str)
  252. }
  253. }
  254. func TestGetBlockByHashArgsInvalid(t *testing.T) {
  255. input := `{}`
  256. args := new(GetBlockByHashArgs)
  257. str := ExpectDecodeParamError(json.Unmarshal([]byte(input), &args))
  258. if len(str) > 0 {
  259. t.Error(str)
  260. }
  261. }
  262. func TestGetBlockByHashArgsHashInt(t *testing.T) {
  263. input := `[8]`
  264. args := new(GetBlockByHashArgs)
  265. str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), &args))
  266. if len(str) > 0 {
  267. t.Error(str)
  268. }
  269. }
  270. func TestGetBlockByHashArgsHashBool(t *testing.T) {
  271. input := `[false, true]`
  272. args := new(GetBlockByHashArgs)
  273. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  274. if len(str) > 0 {
  275. t.Error(str)
  276. }
  277. }
  278. func TestGetBlockByNumberArgsBlockNum(t *testing.T) {
  279. input := `[436, false]`
  280. expected := new(GetBlockByNumberArgs)
  281. expected.BlockNumber = 436
  282. expected.IncludeTxs = false
  283. args := new(GetBlockByNumberArgs)
  284. if err := json.Unmarshal([]byte(input), &args); err != nil {
  285. t.Error(err)
  286. }
  287. if args.BlockNumber != expected.BlockNumber {
  288. t.Errorf("BlockNumber should be %v but is %v", expected.BlockNumber, args.BlockNumber)
  289. }
  290. if args.IncludeTxs != expected.IncludeTxs {
  291. t.Errorf("IncludeTxs should be %v but is %v", expected.IncludeTxs, args.IncludeTxs)
  292. }
  293. }
  294. func TestGetBlockByNumberArgsBlockHex(t *testing.T) {
  295. input := `["0x1b4", false]`
  296. expected := new(GetBlockByNumberArgs)
  297. expected.BlockNumber = 436
  298. expected.IncludeTxs = false
  299. args := new(GetBlockByNumberArgs)
  300. if err := json.Unmarshal([]byte(input), &args); err != nil {
  301. t.Error(err)
  302. }
  303. if args.BlockNumber != expected.BlockNumber {
  304. t.Errorf("BlockNumber should be %v but is %v", expected.BlockNumber, args.BlockNumber)
  305. }
  306. if args.IncludeTxs != expected.IncludeTxs {
  307. t.Errorf("IncludeTxs should be %v but is %v", expected.IncludeTxs, args.IncludeTxs)
  308. }
  309. }
  310. func TestGetBlockByNumberArgsWords(t *testing.T) {
  311. input := `["earliest", true]`
  312. expected := new(GetBlockByNumberArgs)
  313. expected.BlockNumber = 0
  314. expected.IncludeTxs = true
  315. args := new(GetBlockByNumberArgs)
  316. if err := json.Unmarshal([]byte(input), &args); err != nil {
  317. t.Error(err)
  318. }
  319. if args.BlockNumber != expected.BlockNumber {
  320. t.Errorf("BlockNumber should be %v but is %v", expected.BlockNumber, args.BlockNumber)
  321. }
  322. if args.IncludeTxs != expected.IncludeTxs {
  323. t.Errorf("IncludeTxs should be %v but is %v", expected.IncludeTxs, args.IncludeTxs)
  324. }
  325. }
  326. func TestGetBlockByNumberEmpty(t *testing.T) {
  327. input := `[]`
  328. args := new(GetBlockByNumberArgs)
  329. str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), &args))
  330. if len(str) > 0 {
  331. t.Error(str)
  332. }
  333. }
  334. func TestGetBlockByNumberShort(t *testing.T) {
  335. input := `["0xbbb"]`
  336. args := new(GetBlockByNumberArgs)
  337. str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), &args))
  338. if len(str) > 0 {
  339. t.Error(str)
  340. }
  341. }
  342. func TestGetBlockByNumberBool(t *testing.T) {
  343. input := `[true, true]`
  344. args := new(GetBlockByNumberArgs)
  345. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  346. if len(str) > 0 {
  347. t.Error(str)
  348. }
  349. }
  350. func TestGetBlockByNumberBlockObject(t *testing.T) {
  351. input := `{}`
  352. args := new(GetBlockByNumberArgs)
  353. str := ExpectDecodeParamError(json.Unmarshal([]byte(input), &args))
  354. if len(str) > 0 {
  355. t.Error(str)
  356. }
  357. }
  358. func TestNewTxArgs(t *testing.T) {
  359. input := `[{"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
  360. "to": "0xd46e8dd67c5d32be8058bb8eb970870f072445675",
  361. "gas": "0x76c0",
  362. "gasPrice": "0x9184e72a000",
  363. "value": "0x9184e72a000",
  364. "data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"},
  365. "0x10"]`
  366. expected := new(NewTxArgs)
  367. expected.From = "0xb60e8dd61c5d32be8058bb8eb970870f07233155"
  368. expected.To = "0xd46e8dd67c5d32be8058bb8eb970870f072445675"
  369. expected.Gas = big.NewInt(30400)
  370. expected.GasPrice = big.NewInt(10000000000000)
  371. expected.Value = big.NewInt(10000000000000)
  372. expected.Data = "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
  373. expected.BlockNumber = big.NewInt(16).Int64()
  374. args := new(NewTxArgs)
  375. if err := json.Unmarshal([]byte(input), &args); err != nil {
  376. t.Error(err)
  377. }
  378. if expected.From != args.From {
  379. t.Errorf("From shoud be %#v but is %#v", expected.From, args.From)
  380. }
  381. if expected.To != args.To {
  382. t.Errorf("To shoud be %#v but is %#v", expected.To, args.To)
  383. }
  384. if bytes.Compare(expected.Gas.Bytes(), args.Gas.Bytes()) != 0 {
  385. t.Errorf("Gas shoud be %#v but is %#v", expected.Gas.Bytes(), args.Gas.Bytes())
  386. }
  387. if bytes.Compare(expected.GasPrice.Bytes(), args.GasPrice.Bytes()) != 0 {
  388. t.Errorf("GasPrice shoud be %#v but is %#v", expected.GasPrice, args.GasPrice)
  389. }
  390. if bytes.Compare(expected.Value.Bytes(), args.Value.Bytes()) != 0 {
  391. t.Errorf("Value shoud be %#v but is %#v", expected.Value, args.Value)
  392. }
  393. if expected.Data != args.Data {
  394. t.Errorf("Data shoud be %#v but is %#v", expected.Data, args.Data)
  395. }
  396. if expected.BlockNumber != args.BlockNumber {
  397. t.Errorf("BlockNumber shoud be %#v but is %#v", expected.BlockNumber, args.BlockNumber)
  398. }
  399. }
  400. func TestNewTxArgsInt(t *testing.T) {
  401. input := `[{"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
  402. "to": "0xd46e8dd67c5d32be8058bb8eb970870f072445675",
  403. "gas": 100,
  404. "gasPrice": 50,
  405. "value": 8765456789,
  406. "data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"},
  407. 5]`
  408. expected := new(NewTxArgs)
  409. expected.Gas = big.NewInt(100)
  410. expected.GasPrice = big.NewInt(50)
  411. expected.Value = big.NewInt(8765456789)
  412. expected.BlockNumber = int64(5)
  413. args := new(NewTxArgs)
  414. if err := json.Unmarshal([]byte(input), &args); err != nil {
  415. t.Error(err)
  416. }
  417. if bytes.Compare(expected.Gas.Bytes(), args.Gas.Bytes()) != 0 {
  418. t.Errorf("Gas shoud be %v but is %v", expected.Gas, args.Gas)
  419. }
  420. if bytes.Compare(expected.GasPrice.Bytes(), args.GasPrice.Bytes()) != 0 {
  421. t.Errorf("GasPrice shoud be %v but is %v", expected.GasPrice, args.GasPrice)
  422. }
  423. if bytes.Compare(expected.Value.Bytes(), args.Value.Bytes()) != 0 {
  424. t.Errorf("Value shoud be %v but is %v", expected.Value, args.Value)
  425. }
  426. if expected.BlockNumber != args.BlockNumber {
  427. t.Errorf("BlockNumber shoud be %v but is %v", expected.BlockNumber, args.BlockNumber)
  428. }
  429. }
  430. func TestNewTxArgsBlockBool(t *testing.T) {
  431. input := `[{"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
  432. "to": "0xd46e8dd67c5d32be8058bb8eb970870f072445675",
  433. "gas": "0x76c0",
  434. "gasPrice": "0x9184e72a000",
  435. "value": "0x9184e72a000",
  436. "data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"},
  437. false]`
  438. args := new(NewTxArgs)
  439. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  440. if len(str) > 0 {
  441. t.Error(str)
  442. }
  443. }
  444. func TestNewTxArgsGasInvalid(t *testing.T) {
  445. input := `[{"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
  446. "to": "0xd46e8dd67c5d32be8058bb8eb970870f072445675",
  447. "gas": false,
  448. "gasPrice": "0x9184e72a000",
  449. "value": "0x9184e72a000",
  450. "data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
  451. }]`
  452. args := new(NewTxArgs)
  453. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  454. if len(str) > 0 {
  455. t.Error(str)
  456. }
  457. }
  458. func TestNewTxArgsGaspriceInvalid(t *testing.T) {
  459. input := `[{"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
  460. "to": "0xd46e8dd67c5d32be8058bb8eb970870f072445675",
  461. "gas": "0x76c0",
  462. "gasPrice": false,
  463. "value": "0x9184e72a000",
  464. "data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
  465. }]`
  466. args := new(NewTxArgs)
  467. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  468. if len(str) > 0 {
  469. t.Error(str)
  470. }
  471. }
  472. func TestNewTxArgsValueInvalid(t *testing.T) {
  473. input := `[{"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
  474. "to": "0xd46e8dd67c5d32be8058bb8eb970870f072445675",
  475. "gas": "0x76c0",
  476. "gasPrice": "0x9184e72a000",
  477. "value": false,
  478. "data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
  479. }]`
  480. args := new(NewTxArgs)
  481. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  482. if len(str) > 0 {
  483. t.Error(str)
  484. }
  485. }
  486. func TestNewTxArgsGasMissing(t *testing.T) {
  487. input := `[{"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
  488. "to": "0xd46e8dd67c5d32be8058bb8eb970870f072445675",
  489. "gasPrice": "0x9184e72a000",
  490. "value": "0x9184e72a000",
  491. "data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
  492. }]`
  493. expected := new(NewTxArgs)
  494. expected.Gas = nil
  495. args := new(NewTxArgs)
  496. if err := json.Unmarshal([]byte(input), &args); err != nil {
  497. t.Error(err)
  498. }
  499. if args.Gas != expected.Gas {
  500. // if bytes.Compare(expected.Gas.Bytes(), args.Gas.Bytes()) != 0 {
  501. t.Errorf("Gas shoud be %v but is %v", expected.Gas, args.Gas)
  502. }
  503. }
  504. func TestNewTxArgsBlockGaspriceMissing(t *testing.T) {
  505. input := `[{
  506. "from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
  507. "to": "0xd46e8dd67c5d32be8058bb8eb970870f072445675",
  508. "gas": "0x76c0",
  509. "value": "0x9184e72a000",
  510. "data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
  511. }]`
  512. expected := new(NewTxArgs)
  513. expected.GasPrice = nil
  514. args := new(NewTxArgs)
  515. if err := json.Unmarshal([]byte(input), &args); err != nil {
  516. t.Error(err)
  517. }
  518. if args.GasPrice != expected.GasPrice {
  519. // if bytes.Compare(expected.GasPrice.Bytes(), args.GasPrice.Bytes()) != 0 {
  520. t.Errorf("GasPrice shoud be %v but is %v", expected.GasPrice, args.GasPrice)
  521. }
  522. }
  523. func TestNewTxArgsValueMissing(t *testing.T) {
  524. input := `[{
  525. "from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
  526. "to": "0xd46e8dd67c5d32be8058bb8eb970870f072445675",
  527. "gas": "0x76c0",
  528. "gasPrice": "0x9184e72a000",
  529. "data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
  530. }]`
  531. expected := new(NewTxArgs)
  532. expected.Value = big.NewInt(0)
  533. args := new(NewTxArgs)
  534. if err := json.Unmarshal([]byte(input), &args); err != nil {
  535. t.Error(err)
  536. }
  537. if bytes.Compare(expected.Value.Bytes(), args.Value.Bytes()) != 0 {
  538. t.Errorf("Value shoud be %v but is %v", expected.Value, args.Value)
  539. }
  540. }
  541. func TestNewTxArgsEmpty(t *testing.T) {
  542. input := `[]`
  543. args := new(NewTxArgs)
  544. str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), &args))
  545. if len(str) > 0 {
  546. t.Error(str)
  547. }
  548. }
  549. func TestNewTxArgsInvalid(t *testing.T) {
  550. input := `{}`
  551. args := new(NewTxArgs)
  552. str := ExpectDecodeParamError(json.Unmarshal([]byte(input), &args))
  553. if len(str) > 0 {
  554. t.Error(str)
  555. }
  556. }
  557. func TestNewTxArgsNotStrings(t *testing.T) {
  558. input := `[{"from":6}]`
  559. args := new(NewTxArgs)
  560. str := ExpectDecodeParamError(json.Unmarshal([]byte(input), &args))
  561. if len(str) > 0 {
  562. t.Error(str)
  563. }
  564. }
  565. func TestNewTxArgsFromEmpty(t *testing.T) {
  566. input := `[{"to": "0xb60e8dd61c5d32be8058bb8eb970870f07233155"}]`
  567. args := new(NewTxArgs)
  568. str := ExpectValidationError(json.Unmarshal([]byte(input), &args))
  569. if len(str) > 0 {
  570. t.Error(str)
  571. }
  572. }
  573. func TestCallArgs(t *testing.T) {
  574. input := `[{"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
  575. "to": "0xd46e8dd67c5d32be8058bb8eb970870f072445675",
  576. "gas": "0x76c0",
  577. "gasPrice": "0x9184e72a000",
  578. "value": "0x9184e72a000",
  579. "data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"},
  580. "0x10"]`
  581. expected := new(CallArgs)
  582. expected.From = "0xb60e8dd61c5d32be8058bb8eb970870f07233155"
  583. expected.To = "0xd46e8dd67c5d32be8058bb8eb970870f072445675"
  584. expected.Gas = big.NewInt(30400)
  585. expected.GasPrice = big.NewInt(10000000000000)
  586. expected.Value = big.NewInt(10000000000000)
  587. expected.Data = "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
  588. expected.BlockNumber = big.NewInt(16).Int64()
  589. args := new(CallArgs)
  590. if err := json.Unmarshal([]byte(input), &args); err != nil {
  591. t.Error(err)
  592. }
  593. if expected.To != args.To {
  594. t.Errorf("To shoud be %#v but is %#v", expected.To, args.To)
  595. }
  596. if bytes.Compare(expected.Gas.Bytes(), args.Gas.Bytes()) != 0 {
  597. t.Errorf("Gas shoud be %#v but is %#v", expected.Gas.Bytes(), args.Gas.Bytes())
  598. }
  599. if bytes.Compare(expected.GasPrice.Bytes(), args.GasPrice.Bytes()) != 0 {
  600. t.Errorf("GasPrice shoud be %#v but is %#v", expected.GasPrice, args.GasPrice)
  601. }
  602. if bytes.Compare(expected.Value.Bytes(), args.Value.Bytes()) != 0 {
  603. t.Errorf("Value shoud be %#v but is %#v", expected.Value, args.Value)
  604. }
  605. if expected.Data != args.Data {
  606. t.Errorf("Data shoud be %#v but is %#v", expected.Data, args.Data)
  607. }
  608. if expected.BlockNumber != args.BlockNumber {
  609. t.Errorf("BlockNumber shoud be %#v but is %#v", expected.BlockNumber, args.BlockNumber)
  610. }
  611. }
  612. func TestCallArgsInt(t *testing.T) {
  613. input := `[{"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
  614. "to": "0xd46e8dd67c5d32be8058bb8eb970870f072445675",
  615. "gas": 100,
  616. "gasPrice": 50,
  617. "value": 8765456789,
  618. "data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"},
  619. 5]`
  620. expected := new(CallArgs)
  621. expected.Gas = big.NewInt(100)
  622. expected.GasPrice = big.NewInt(50)
  623. expected.Value = big.NewInt(8765456789)
  624. expected.BlockNumber = int64(5)
  625. args := new(CallArgs)
  626. if err := json.Unmarshal([]byte(input), &args); err != nil {
  627. t.Error(err)
  628. }
  629. if bytes.Compare(expected.Gas.Bytes(), args.Gas.Bytes()) != 0 {
  630. t.Errorf("Gas shoud be %v but is %v", expected.Gas, args.Gas)
  631. }
  632. if bytes.Compare(expected.GasPrice.Bytes(), args.GasPrice.Bytes()) != 0 {
  633. t.Errorf("GasPrice shoud be %v but is %v", expected.GasPrice, args.GasPrice)
  634. }
  635. if bytes.Compare(expected.Value.Bytes(), args.Value.Bytes()) != 0 {
  636. t.Errorf("Value shoud be %v but is %v", expected.Value, args.Value)
  637. }
  638. if expected.BlockNumber != args.BlockNumber {
  639. t.Errorf("BlockNumber shoud be %v but is %v", expected.BlockNumber, args.BlockNumber)
  640. }
  641. }
  642. func TestCallArgsBlockBool(t *testing.T) {
  643. input := `[{"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
  644. "to": "0xd46e8dd67c5d32be8058bb8eb970870f072445675",
  645. "gas": "0x76c0",
  646. "gasPrice": "0x9184e72a000",
  647. "value": "0x9184e72a000",
  648. "data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"},
  649. false]`
  650. args := new(CallArgs)
  651. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  652. if len(str) > 0 {
  653. t.Error(str)
  654. }
  655. }
  656. func TestCallArgsGasInvalid(t *testing.T) {
  657. input := `[{"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
  658. "to": "0xd46e8dd67c5d32be8058bb8eb970870f072445675",
  659. "gas": false,
  660. "gasPrice": "0x9184e72a000",
  661. "value": "0x9184e72a000",
  662. "data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
  663. }]`
  664. args := new(CallArgs)
  665. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  666. if len(str) > 0 {
  667. t.Error(str)
  668. }
  669. }
  670. func TestCallArgsGaspriceInvalid(t *testing.T) {
  671. input := `[{"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
  672. "to": "0xd46e8dd67c5d32be8058bb8eb970870f072445675",
  673. "gas": "0x76c0",
  674. "gasPrice": false,
  675. "value": "0x9184e72a000",
  676. "data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
  677. }]`
  678. args := new(CallArgs)
  679. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  680. if len(str) > 0 {
  681. t.Error(str)
  682. }
  683. }
  684. func TestCallArgsValueInvalid(t *testing.T) {
  685. input := `[{"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
  686. "to": "0xd46e8dd67c5d32be8058bb8eb970870f072445675",
  687. "gas": "0x76c0",
  688. "gasPrice": "0x9184e72a000",
  689. "value": false,
  690. "data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
  691. }]`
  692. args := new(CallArgs)
  693. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  694. if len(str) > 0 {
  695. t.Error(str)
  696. }
  697. }
  698. func TestCallArgsGasMissing(t *testing.T) {
  699. input := `[{"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
  700. "to": "0xd46e8dd67c5d32be8058bb8eb970870f072445675",
  701. "gasPrice": "0x9184e72a000",
  702. "value": "0x9184e72a000",
  703. "data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
  704. }]`
  705. args := new(CallArgs)
  706. if err := json.Unmarshal([]byte(input), &args); err != nil {
  707. t.Error(err)
  708. }
  709. expected := new(CallArgs)
  710. expected.Gas = nil
  711. if args.Gas != expected.Gas {
  712. // if bytes.Compare(expected.Gas.Bytes(), args.Gas.Bytes()) != 0 {
  713. t.Errorf("Gas shoud be %v but is %v", expected.Gas, args.Gas)
  714. }
  715. }
  716. func TestCallArgsBlockGaspriceMissing(t *testing.T) {
  717. input := `[{
  718. "from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
  719. "to": "0xd46e8dd67c5d32be8058bb8eb970870f072445675",
  720. "gas": "0x76c0",
  721. "value": "0x9184e72a000",
  722. "data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
  723. }]`
  724. args := new(CallArgs)
  725. if err := json.Unmarshal([]byte(input), &args); err != nil {
  726. t.Error(err)
  727. }
  728. expected := new(CallArgs)
  729. expected.GasPrice = nil
  730. if args.GasPrice != expected.GasPrice {
  731. // if bytes.Compare(expected.GasPrice.Bytes(), args.GasPrice.Bytes()) != 0 {
  732. t.Errorf("GasPrice shoud be %v but is %v", expected.GasPrice, args.GasPrice)
  733. }
  734. }
  735. func TestCallArgsValueMissing(t *testing.T) {
  736. input := `[{
  737. "from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
  738. "to": "0xd46e8dd67c5d32be8058bb8eb970870f072445675",
  739. "gas": "0x76c0",
  740. "gasPrice": "0x9184e72a000",
  741. "data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
  742. }]`
  743. args := new(CallArgs)
  744. if err := json.Unmarshal([]byte(input), &args); err != nil {
  745. t.Error(err)
  746. }
  747. expected := new(CallArgs)
  748. expected.Value = big.NewInt(int64(0))
  749. if bytes.Compare(expected.Value.Bytes(), args.Value.Bytes()) != 0 {
  750. t.Errorf("GasPrice shoud be %v but is %v", expected.Value, args.Value)
  751. }
  752. }
  753. func TestCallArgsEmpty(t *testing.T) {
  754. input := `[]`
  755. args := new(CallArgs)
  756. str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), &args))
  757. if len(str) > 0 {
  758. t.Error(str)
  759. }
  760. }
  761. func TestCallArgsInvalid(t *testing.T) {
  762. input := `{}`
  763. args := new(CallArgs)
  764. str := ExpectDecodeParamError(json.Unmarshal([]byte(input), &args))
  765. if len(str) > 0 {
  766. t.Error(str)
  767. }
  768. }
  769. func TestCallArgsNotStrings(t *testing.T) {
  770. input := `[{"from":6}]`
  771. args := new(CallArgs)
  772. str := ExpectDecodeParamError(json.Unmarshal([]byte(input), &args))
  773. if len(str) > 0 {
  774. t.Error(str)
  775. }
  776. }
  777. func TestCallArgsToEmpty(t *testing.T) {
  778. input := `[{"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155"}]`
  779. args := new(CallArgs)
  780. err := json.Unmarshal([]byte(input), &args)
  781. if err != nil {
  782. t.Error("Did not expect error. Got", err)
  783. }
  784. }
  785. func TestGetStorageArgs(t *testing.T) {
  786. input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "latest"]`
  787. expected := new(GetStorageArgs)
  788. expected.Address = "0x407d73d8a49eeb85d32cf465507dd71d507100c1"
  789. expected.BlockNumber = -1
  790. args := new(GetStorageArgs)
  791. if err := json.Unmarshal([]byte(input), &args); err != nil {
  792. t.Error(err)
  793. }
  794. if expected.Address != args.Address {
  795. t.Errorf("Address shoud be %#v but is %#v", expected.Address, args.Address)
  796. }
  797. if expected.BlockNumber != args.BlockNumber {
  798. t.Errorf("BlockNumber shoud be %#v but is %#v", expected.BlockNumber, args.BlockNumber)
  799. }
  800. }
  801. func TestGetStorageArgsMissingBlocknum(t *testing.T) {
  802. input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1"]`
  803. expected := new(GetStorageArgs)
  804. expected.Address = "0x407d73d8a49eeb85d32cf465507dd71d507100c1"
  805. expected.BlockNumber = -1
  806. args := new(GetStorageArgs)
  807. if err := json.Unmarshal([]byte(input), &args); err != nil {
  808. t.Error(err)
  809. }
  810. if expected.Address != args.Address {
  811. t.Errorf("Address shoud be %#v but is %#v", expected.Address, args.Address)
  812. }
  813. if expected.BlockNumber != args.BlockNumber {
  814. t.Errorf("BlockNumber shoud be %#v but is %#v", expected.BlockNumber, args.BlockNumber)
  815. }
  816. }
  817. func TestGetStorageInvalidArgs(t *testing.T) {
  818. input := `{}`
  819. args := new(GetStorageArgs)
  820. str := ExpectDecodeParamError(json.Unmarshal([]byte(input), &args))
  821. if len(str) > 0 {
  822. t.Error(str)
  823. }
  824. }
  825. func TestGetStorageInvalidBlockheight(t *testing.T) {
  826. input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1", {}]`
  827. args := new(GetStorageArgs)
  828. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  829. if len(str) > 0 {
  830. t.Error(str)
  831. }
  832. }
  833. func TestGetStorageEmptyArgs(t *testing.T) {
  834. input := `[]`
  835. args := new(GetStorageArgs)
  836. str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), &args))
  837. if len(str) > 0 {
  838. t.Error(str)
  839. }
  840. }
  841. func TestGetStorageAddressInt(t *testing.T) {
  842. input := `[32456785432456, "latest"]`
  843. args := new(GetStorageArgs)
  844. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  845. if len(str) > 0 {
  846. t.Error(str)
  847. }
  848. }
  849. func TestGetStorageAtArgs(t *testing.T) {
  850. input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "0x0", "0x2"]`
  851. expected := new(GetStorageAtArgs)
  852. expected.Address = "0x407d73d8a49eeb85d32cf465507dd71d507100c1"
  853. expected.Key = "0x0"
  854. expected.BlockNumber = 2
  855. args := new(GetStorageAtArgs)
  856. if err := json.Unmarshal([]byte(input), &args); err != nil {
  857. t.Error(err)
  858. }
  859. if expected.Address != args.Address {
  860. t.Errorf("Address shoud be %#v but is %#v", expected.Address, args.Address)
  861. }
  862. if expected.Key != args.Key {
  863. t.Errorf("Address shoud be %#v but is %#v", expected.Address, args.Address)
  864. }
  865. if expected.BlockNumber != args.BlockNumber {
  866. t.Errorf("BlockNumber shoud be %#v but is %#v", expected.BlockNumber, args.BlockNumber)
  867. }
  868. }
  869. func TestGetStorageAtArgsMissingBlocknum(t *testing.T) {
  870. input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "0x0"]`
  871. expected := new(GetStorageAtArgs)
  872. expected.Address = "0x407d73d8a49eeb85d32cf465507dd71d507100c1"
  873. expected.Key = "0x0"
  874. expected.BlockNumber = -1
  875. args := new(GetStorageAtArgs)
  876. if err := json.Unmarshal([]byte(input), &args); err != nil {
  877. t.Error(err)
  878. }
  879. if expected.Address != args.Address {
  880. t.Errorf("Address shoud be %#v but is %#v", expected.Address, args.Address)
  881. }
  882. if expected.Key != args.Key {
  883. t.Errorf("Address shoud be %#v but is %#v", expected.Address, args.Address)
  884. }
  885. if expected.BlockNumber != args.BlockNumber {
  886. t.Errorf("BlockNumber shoud be %#v but is %#v", expected.BlockNumber, args.BlockNumber)
  887. }
  888. }
  889. func TestGetStorageAtEmptyArgs(t *testing.T) {
  890. input := `[]`
  891. args := new(GetStorageAtArgs)
  892. str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), &args))
  893. if len(str) > 0 {
  894. t.Error(str)
  895. }
  896. }
  897. func TestGetStorageAtArgsInvalid(t *testing.T) {
  898. input := `{}`
  899. args := new(GetStorageAtArgs)
  900. str := ExpectDecodeParamError(json.Unmarshal([]byte(input), &args))
  901. if len(str) > 0 {
  902. t.Error(str)
  903. }
  904. }
  905. func TestGetStorageAtArgsAddressNotString(t *testing.T) {
  906. input := `[true, "0x0", "0x2"]`
  907. args := new(GetStorageAtArgs)
  908. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  909. if len(str) > 0 {
  910. t.Error(str)
  911. }
  912. }
  913. func TestGetStorageAtArgsKeyNotString(t *testing.T) {
  914. input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1", true, "0x2"]`
  915. args := new(GetStorageAtArgs)
  916. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  917. if len(str) > 0 {
  918. t.Error(str)
  919. }
  920. }
  921. func TestGetStorageAtArgsValueNotString(t *testing.T) {
  922. input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "0x1", true]`
  923. args := new(GetStorageAtArgs)
  924. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  925. if len(str) > 0 {
  926. t.Error(str)
  927. }
  928. }
  929. func TestGetTxCountArgs(t *testing.T) {
  930. input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "pending"]`
  931. expected := new(GetTxCountArgs)
  932. expected.Address = "0x407d73d8a49eeb85d32cf465507dd71d507100c1"
  933. expected.BlockNumber = -2
  934. args := new(GetTxCountArgs)
  935. if err := json.Unmarshal([]byte(input), &args); err != nil {
  936. t.Error(err)
  937. }
  938. if expected.Address != args.Address {
  939. t.Errorf("Address shoud be %#v but is %#v", expected.Address, args.Address)
  940. }
  941. if expected.BlockNumber != args.BlockNumber {
  942. t.Errorf("BlockNumber shoud be %#v but is %#v", expected.BlockNumber, args.BlockNumber)
  943. }
  944. }
  945. func TestGetTxCountEmptyArgs(t *testing.T) {
  946. input := `[]`
  947. args := new(GetTxCountArgs)
  948. str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), &args))
  949. if len(str) > 0 {
  950. t.Error(str)
  951. }
  952. }
  953. func TestGetTxCountEmptyArgsInvalid(t *testing.T) {
  954. input := `false`
  955. args := new(GetTxCountArgs)
  956. str := ExpectDecodeParamError(json.Unmarshal([]byte(input), &args))
  957. if len(str) > 0 {
  958. t.Error(str)
  959. }
  960. }
  961. func TestGetTxCountAddressNotString(t *testing.T) {
  962. input := `[false, "pending"]`
  963. args := new(GetTxCountArgs)
  964. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  965. if len(str) > 0 {
  966. t.Error(str)
  967. }
  968. }
  969. func TestGetTxCountBlockheightMissing(t *testing.T) {
  970. input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1"]`
  971. expected := new(GetTxCountArgs)
  972. expected.Address = "0x407d73d8a49eeb85d32cf465507dd71d507100c1"
  973. expected.BlockNumber = -1
  974. args := new(GetTxCountArgs)
  975. if err := json.Unmarshal([]byte(input), &args); err != nil {
  976. t.Error(err)
  977. }
  978. if expected.Address != args.Address {
  979. t.Errorf("Address shoud be %#v but is %#v", expected.Address, args.Address)
  980. }
  981. if expected.BlockNumber != args.BlockNumber {
  982. t.Errorf("BlockNumber shoud be %#v but is %#v", expected.BlockNumber, args.BlockNumber)
  983. }
  984. }
  985. func TestGetTxCountBlockheightInvalid(t *testing.T) {
  986. input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1", {}]`
  987. args := new(GetTxCountArgs)
  988. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  989. if len(str) > 0 {
  990. t.Error(str)
  991. }
  992. }
  993. func TestGetDataArgs(t *testing.T) {
  994. input := `["0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8", "latest"]`
  995. expected := new(GetDataArgs)
  996. expected.Address = "0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8"
  997. expected.BlockNumber = -1
  998. args := new(GetDataArgs)
  999. if err := json.Unmarshal([]byte(input), &args); err != nil {
  1000. t.Error(err)
  1001. }
  1002. if expected.Address != args.Address {
  1003. t.Errorf("Address shoud be %#v but is %#v", expected.Address, args.Address)
  1004. }
  1005. if expected.BlockNumber != args.BlockNumber {
  1006. t.Errorf("BlockNumber shoud be %#v but is %#v", expected.BlockNumber, args.BlockNumber)
  1007. }
  1008. }
  1009. func TestGetDataArgsBlocknumMissing(t *testing.T) {
  1010. input := `["0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8"]`
  1011. expected := new(GetDataArgs)
  1012. expected.Address = "0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8"
  1013. expected.BlockNumber = -1
  1014. args := new(GetDataArgs)
  1015. if err := json.Unmarshal([]byte(input), &args); err != nil {
  1016. t.Error(err)
  1017. }
  1018. if expected.Address != args.Address {
  1019. t.Errorf("Address shoud be %#v but is %#v", expected.Address, args.Address)
  1020. }
  1021. if expected.BlockNumber != args.BlockNumber {
  1022. t.Errorf("BlockNumber shoud be %#v but is %#v", expected.BlockNumber, args.BlockNumber)
  1023. }
  1024. }
  1025. func TestGetDataArgsEmpty(t *testing.T) {
  1026. input := `[]`
  1027. args := new(GetDataArgs)
  1028. str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), &args))
  1029. if len(str) > 0 {
  1030. t.Error(str)
  1031. }
  1032. }
  1033. func TestGetDataArgsInvalid(t *testing.T) {
  1034. input := `{}`
  1035. args := new(GetDataArgs)
  1036. str := ExpectDecodeParamError(json.Unmarshal([]byte(input), &args))
  1037. if len(str) > 0 {
  1038. t.Error(str)
  1039. }
  1040. }
  1041. func TestGetDataArgsAddressNotString(t *testing.T) {
  1042. input := `[12, "latest"]`
  1043. args := new(GetDataArgs)
  1044. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  1045. if len(str) > 0 {
  1046. t.Error(str)
  1047. }
  1048. }
  1049. func TestGetDataArgsBlocknumberNotString(t *testing.T) {
  1050. input := `["0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8", false]`
  1051. args := new(GetDataArgs)
  1052. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  1053. if len(str) > 0 {
  1054. t.Error(str)
  1055. }
  1056. }
  1057. func TestBlockFilterArgs(t *testing.T) {
  1058. input := `[{
  1059. "fromBlock": "0x1",
  1060. "toBlock": "0x2",
  1061. "limit": "0x3",
  1062. "offset": "0x0",
  1063. "address": "0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8",
  1064. "topics":
  1065. [
  1066. ["0xAA", "0xBB"],
  1067. ["0xCC", "0xDD"]
  1068. ]
  1069. }]`
  1070. expected := new(BlockFilterArgs)
  1071. expected.Earliest = 1
  1072. expected.Latest = 2
  1073. expected.Max = 3
  1074. expected.Skip = 0
  1075. expected.Address = []string{"0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8"}
  1076. expected.Topics = [][]string{
  1077. []string{"0xAA", "0xBB"},
  1078. []string{"0xCC", "0xDD"},
  1079. }
  1080. args := new(BlockFilterArgs)
  1081. if err := json.Unmarshal([]byte(input), &args); err != nil {
  1082. t.Error(err)
  1083. }
  1084. if expected.Earliest != args.Earliest {
  1085. t.Errorf("Earliest shoud be %#v but is %#v", expected.Earliest, args.Earliest)
  1086. }
  1087. if expected.Latest != args.Latest {
  1088. t.Errorf("Latest shoud be %#v but is %#v", expected.Latest, args.Latest)
  1089. }
  1090. if expected.Max != args.Max {
  1091. t.Errorf("Max shoud be %#v but is %#v", expected.Max, args.Max)
  1092. }
  1093. if expected.Skip != args.Skip {
  1094. t.Errorf("Skip shoud be %#v but is %#v", expected.Skip, args.Skip)
  1095. }
  1096. if expected.Address[0] != args.Address[0] {
  1097. t.Errorf("Address shoud be %#v but is %#v", expected.Address, args.Address)
  1098. }
  1099. if expected.Topics[0][0] != args.Topics[0][0] {
  1100. t.Errorf("Topics shoud be %#v but is %#v", expected.Topics, args.Topics)
  1101. }
  1102. if expected.Topics[0][1] != args.Topics[0][1] {
  1103. t.Errorf("Topics shoud be %#v but is %#v", expected.Topics, args.Topics)
  1104. }
  1105. if expected.Topics[1][0] != args.Topics[1][0] {
  1106. t.Errorf("Topics shoud be %#v but is %#v", expected.Topics, args.Topics)
  1107. }
  1108. if expected.Topics[1][1] != args.Topics[1][1] {
  1109. t.Errorf("Topics shoud be %#v but is %#v", expected.Topics, args.Topics)
  1110. }
  1111. }
  1112. func TestBlockFilterArgsDefaults(t *testing.T) {
  1113. input := `[{
  1114. "address": ["0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8"],
  1115. "topics": ["0xAA","0xBB"]
  1116. }]`
  1117. expected := new(BlockFilterArgs)
  1118. expected.Earliest = -1
  1119. expected.Latest = -1
  1120. expected.Max = 100
  1121. expected.Skip = 0
  1122. expected.Address = []string{"0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8"}
  1123. expected.Topics = [][]string{[]string{"0xAA"}, []string{"0xBB"}}
  1124. args := new(BlockFilterArgs)
  1125. if err := json.Unmarshal([]byte(input), &args); err != nil {
  1126. t.Error(err)
  1127. }
  1128. if expected.Earliest != args.Earliest {
  1129. t.Errorf("Earliest shoud be %#v but is %#v", expected.Earliest, args.Earliest)
  1130. }
  1131. if expected.Latest != args.Latest {
  1132. t.Errorf("Latest shoud be %#v but is %#v", expected.Latest, args.Latest)
  1133. }
  1134. if expected.Max != args.Max {
  1135. t.Errorf("Max shoud be %#v but is %#v", expected.Max, args.Max)
  1136. }
  1137. if expected.Skip != args.Skip {
  1138. t.Errorf("Skip shoud be %#v but is %#v", expected.Skip, args.Skip)
  1139. }
  1140. if expected.Address[0] != args.Address[0] {
  1141. t.Errorf("Address shoud be %#v but is %#v", expected.Address, args.Address)
  1142. }
  1143. if expected.Topics[0][0] != args.Topics[0][0] {
  1144. t.Errorf("Topics shoud be %#v but is %#v", expected.Topics, args.Topics)
  1145. }
  1146. if expected.Topics[1][0] != args.Topics[1][0] {
  1147. t.Errorf("Topics shoud be %#v but is %#v", expected.Topics, args.Topics)
  1148. }
  1149. }
  1150. func TestBlockFilterArgsWords(t *testing.T) {
  1151. input := `[{
  1152. "fromBlock": "latest",
  1153. "toBlock": "pending"
  1154. }]`
  1155. expected := new(BlockFilterArgs)
  1156. expected.Earliest = -1
  1157. expected.Latest = -2
  1158. args := new(BlockFilterArgs)
  1159. if err := json.Unmarshal([]byte(input), &args); err != nil {
  1160. t.Error(err)
  1161. }
  1162. if expected.Earliest != args.Earliest {
  1163. t.Errorf("Earliest shoud be %#v but is %#v", expected.Earliest, args.Earliest)
  1164. }
  1165. if expected.Latest != args.Latest {
  1166. t.Errorf("Latest shoud be %#v but is %#v", expected.Latest, args.Latest)
  1167. }
  1168. }
  1169. func TestBlockFilterArgsInvalid(t *testing.T) {
  1170. input := `{}`
  1171. args := new(BlockFilterArgs)
  1172. str := ExpectDecodeParamError(json.Unmarshal([]byte(input), &args))
  1173. if len(str) > 0 {
  1174. t.Error(str)
  1175. }
  1176. }
  1177. func TestBlockFilterArgsFromBool(t *testing.T) {
  1178. input := `[{
  1179. "fromBlock": true,
  1180. "toBlock": "pending"
  1181. }]`
  1182. args := new(BlockFilterArgs)
  1183. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  1184. if len(str) > 0 {
  1185. t.Error(str)
  1186. }
  1187. }
  1188. func TestBlockFilterArgsToBool(t *testing.T) {
  1189. input := `[{
  1190. "fromBlock": "pending",
  1191. "toBlock": true
  1192. }]`
  1193. args := new(BlockFilterArgs)
  1194. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  1195. if len(str) > 0 {
  1196. t.Error(str)
  1197. }
  1198. }
  1199. func TestBlockFilterArgsEmptyArgs(t *testing.T) {
  1200. input := `[]`
  1201. args := new(BlockFilterArgs)
  1202. err := json.Unmarshal([]byte(input), &args)
  1203. if err == nil {
  1204. t.Error("Expected error but didn't get one")
  1205. }
  1206. }
  1207. func TestBlockFilterArgsLimitInvalid(t *testing.T) {
  1208. input := `[{"limit": false}]`
  1209. args := new(BlockFilterArgs)
  1210. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  1211. if len(str) > 0 {
  1212. t.Error(str)
  1213. }
  1214. }
  1215. func TestBlockFilterArgsOffsetInvalid(t *testing.T) {
  1216. input := `[{"offset": true}]`
  1217. args := new(BlockFilterArgs)
  1218. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  1219. if len(str) > 0 {
  1220. t.Error(str)
  1221. }
  1222. }
  1223. func TestBlockFilterArgsAddressInt(t *testing.T) {
  1224. input := `[{
  1225. "address": 1,
  1226. "topics": "0x12341234"}]`
  1227. args := new(BlockFilterArgs)
  1228. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  1229. if len(str) > 0 {
  1230. t.Error(str)
  1231. }
  1232. }
  1233. func TestBlockFilterArgsAddressSliceInt(t *testing.T) {
  1234. input := `[{
  1235. "address": [1],
  1236. "topics": "0x12341234"}]`
  1237. args := new(BlockFilterArgs)
  1238. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  1239. if len(str) > 0 {
  1240. t.Error(str)
  1241. }
  1242. }
  1243. func TestBlockFilterArgsTopicInt(t *testing.T) {
  1244. input := `[{
  1245. "address": ["0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8"],
  1246. "topics": 1}]`
  1247. args := new(BlockFilterArgs)
  1248. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  1249. if len(str) > 0 {
  1250. t.Error(str)
  1251. }
  1252. }
  1253. func TestBlockFilterArgsTopicSliceInt(t *testing.T) {
  1254. input := `[{
  1255. "address": "0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8",
  1256. "topics": [1]}]`
  1257. args := new(BlockFilterArgs)
  1258. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  1259. if len(str) > 0 {
  1260. t.Error(str)
  1261. }
  1262. }
  1263. func TestBlockFilterArgsTopicSliceInt2(t *testing.T) {
  1264. input := `[{
  1265. "address": "0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8",
  1266. "topics": ["0xAA", [1]]}]`
  1267. args := new(BlockFilterArgs)
  1268. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  1269. if len(str) > 0 {
  1270. t.Error(str)
  1271. }
  1272. }
  1273. func TestBlockFilterArgsTopicComplex(t *testing.T) {
  1274. input := `[{
  1275. "address": "0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8",
  1276. "topics": ["0xAA", ["0xBB", "0xCC"]]
  1277. }]`
  1278. args := new(BlockFilterArgs)
  1279. if err := json.Unmarshal([]byte(input), &args); err != nil {
  1280. t.Error(err)
  1281. fmt.Printf("%v\n", args)
  1282. return
  1283. }
  1284. if args.Topics[0][0] != "0xAA" {
  1285. t.Errorf("Topic should be %s but is %s", "0xAA", args.Topics[0][0])
  1286. }
  1287. if args.Topics[1][0] != "0xBB" {
  1288. t.Errorf("Topic should be %s but is %s", "0xBB", args.Topics[0][0])
  1289. }
  1290. if args.Topics[1][1] != "0xCC" {
  1291. t.Errorf("Topic should be %s but is %s", "0xCC", args.Topics[0][0])
  1292. }
  1293. }
  1294. func TestDbArgs(t *testing.T) {
  1295. input := `["testDB","myKey","0xbeef"]`
  1296. expected := new(DbArgs)
  1297. expected.Database = "testDB"
  1298. expected.Key = "myKey"
  1299. expected.Value = []byte("0xbeef")
  1300. args := new(DbArgs)
  1301. if err := json.Unmarshal([]byte(input), &args); err != nil {
  1302. t.Error(err)
  1303. }
  1304. if err := args.requirements(); err != nil {
  1305. t.Error(err)
  1306. }
  1307. if expected.Database != args.Database {
  1308. t.Errorf("Database shoud be %#v but is %#v", expected.Database, args.Database)
  1309. }
  1310. if expected.Key != args.Key {
  1311. t.Errorf("Key shoud be %#v but is %#v", expected.Key, args.Key)
  1312. }
  1313. if bytes.Compare(expected.Value, args.Value) != 0 {
  1314. t.Errorf("Value shoud be %#v but is %#v", expected.Value, args.Value)
  1315. }
  1316. }
  1317. func TestDbArgsInvalid(t *testing.T) {
  1318. input := `{}`
  1319. args := new(DbArgs)
  1320. str := ExpectDecodeParamError(json.Unmarshal([]byte(input), &args))
  1321. if len(str) > 0 {
  1322. t.Error(str)
  1323. }
  1324. }
  1325. func TestDbArgsEmpty(t *testing.T) {
  1326. input := `[]`
  1327. args := new(DbArgs)
  1328. str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), &args))
  1329. if len(str) > 0 {
  1330. t.Error(str)
  1331. }
  1332. }
  1333. func TestDbArgsDatabaseType(t *testing.T) {
  1334. input := `[true, "keyval", "valval"]`
  1335. args := new(DbArgs)
  1336. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  1337. if len(str) > 0 {
  1338. t.Error(str)
  1339. }
  1340. }
  1341. func TestDbArgsKeyType(t *testing.T) {
  1342. input := `["dbval", 3, "valval"]`
  1343. args := new(DbArgs)
  1344. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  1345. if len(str) > 0 {
  1346. t.Error(str)
  1347. }
  1348. }
  1349. func TestDbArgsValType(t *testing.T) {
  1350. input := `["dbval", "keyval", {}]`
  1351. args := new(DbArgs)
  1352. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  1353. if len(str) > 0 {
  1354. t.Error(str)
  1355. }
  1356. }
  1357. func TestDbArgsDatabaseEmpty(t *testing.T) {
  1358. input := `["", "keyval", "valval"]`
  1359. args := new(DbArgs)
  1360. if err := json.Unmarshal([]byte(input), &args); err != nil {
  1361. t.Error(err.Error())
  1362. }
  1363. str := ExpectValidationError(args.requirements())
  1364. if len(str) > 0 {
  1365. t.Error(str)
  1366. }
  1367. }
  1368. func TestDbArgsKeyEmpty(t *testing.T) {
  1369. input := `["dbval", "", "valval"]`
  1370. args := new(DbArgs)
  1371. if err := json.Unmarshal([]byte(input), &args); err != nil {
  1372. t.Error(err.Error())
  1373. }
  1374. str := ExpectValidationError(args.requirements())
  1375. if len(str) > 0 {
  1376. t.Error(str)
  1377. }
  1378. }
  1379. func TestDbHexArgs(t *testing.T) {
  1380. input := `["testDB","myKey","0xbeef"]`
  1381. expected := new(DbHexArgs)
  1382. expected.Database = "testDB"
  1383. expected.Key = "myKey"
  1384. expected.Value = []byte{0xbe, 0xef}
  1385. args := new(DbHexArgs)
  1386. if err := json.Unmarshal([]byte(input), &args); err != nil {
  1387. t.Error(err)
  1388. }
  1389. if err := args.requirements(); err != nil {
  1390. t.Error(err)
  1391. }
  1392. if expected.Database != args.Database {
  1393. t.Errorf("Database shoud be %#v but is %#v", expected.Database, args.Database)
  1394. }
  1395. if expected.Key != args.Key {
  1396. t.Errorf("Key shoud be %#v but is %#v", expected.Key, args.Key)
  1397. }
  1398. if bytes.Compare(expected.Value, args.Value) != 0 {
  1399. t.Errorf("Value shoud be %#v but is %#v", expected.Value, args.Value)
  1400. }
  1401. }
  1402. func TestDbHexArgsInvalid(t *testing.T) {
  1403. input := `{}`
  1404. args := new(DbHexArgs)
  1405. str := ExpectDecodeParamError(json.Unmarshal([]byte(input), &args))
  1406. if len(str) > 0 {
  1407. t.Error(str)
  1408. }
  1409. }
  1410. func TestDbHexArgsEmpty(t *testing.T) {
  1411. input := `[]`
  1412. args := new(DbHexArgs)
  1413. str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), &args))
  1414. if len(str) > 0 {
  1415. t.Error(str)
  1416. }
  1417. }
  1418. func TestDbHexArgsDatabaseType(t *testing.T) {
  1419. input := `[true, "keyval", "valval"]`
  1420. args := new(DbHexArgs)
  1421. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  1422. if len(str) > 0 {
  1423. t.Error(str)
  1424. }
  1425. }
  1426. func TestDbHexArgsKeyType(t *testing.T) {
  1427. input := `["dbval", 3, "valval"]`
  1428. args := new(DbHexArgs)
  1429. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  1430. if len(str) > 0 {
  1431. t.Error(str)
  1432. }
  1433. }
  1434. func TestDbHexArgsValType(t *testing.T) {
  1435. input := `["dbval", "keyval", {}]`
  1436. args := new(DbHexArgs)
  1437. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  1438. if len(str) > 0 {
  1439. t.Error(str)
  1440. }
  1441. }
  1442. func TestDbHexArgsDatabaseEmpty(t *testing.T) {
  1443. input := `["", "keyval", "valval"]`
  1444. args := new(DbHexArgs)
  1445. if err := json.Unmarshal([]byte(input), &args); err != nil {
  1446. t.Error(err.Error())
  1447. }
  1448. str := ExpectValidationError(args.requirements())
  1449. if len(str) > 0 {
  1450. t.Error(str)
  1451. }
  1452. }
  1453. func TestDbHexArgsKeyEmpty(t *testing.T) {
  1454. input := `["dbval", "", "valval"]`
  1455. args := new(DbHexArgs)
  1456. if err := json.Unmarshal([]byte(input), &args); err != nil {
  1457. t.Error(err.Error())
  1458. }
  1459. str := ExpectValidationError(args.requirements())
  1460. if len(str) > 0 {
  1461. t.Error(str)
  1462. }
  1463. }
  1464. func TestWhisperMessageArgs(t *testing.T) {
  1465. input := `[{"from":"0xc931d93e97ab07fe42d923478ba2465f2",
  1466. "topics": ["0x68656c6c6f20776f726c64"],
  1467. "payload":"0x68656c6c6f20776f726c64",
  1468. "ttl": "0x64",
  1469. "priority": "0x64"}]`
  1470. expected := new(WhisperMessageArgs)
  1471. expected.From = "0xc931d93e97ab07fe42d923478ba2465f2"
  1472. expected.To = ""
  1473. expected.Payload = "0x68656c6c6f20776f726c64"
  1474. expected.Priority = 100
  1475. expected.Ttl = 100
  1476. // expected.Topics = []string{"0x68656c6c6f20776f726c64"}
  1477. args := new(WhisperMessageArgs)
  1478. if err := json.Unmarshal([]byte(input), &args); err != nil {
  1479. t.Error(err)
  1480. }
  1481. if expected.From != args.From {
  1482. t.Errorf("From shoud be %#v but is %#v", expected.From, args.From)
  1483. }
  1484. if expected.To != args.To {
  1485. t.Errorf("To shoud be %#v but is %#v", expected.To, args.To)
  1486. }
  1487. if expected.Payload != args.Payload {
  1488. t.Errorf("Value shoud be %#v but is %#v", expected.Payload, args.Payload)
  1489. }
  1490. if expected.Ttl != args.Ttl {
  1491. t.Errorf("Ttl shoud be %#v but is %#v", expected.Ttl, args.Ttl)
  1492. }
  1493. if expected.Priority != args.Priority {
  1494. t.Errorf("Priority shoud be %#v but is %#v", expected.Priority, args.Priority)
  1495. }
  1496. // if expected.Topics != args.Topics {
  1497. // t.Errorf("Topic shoud be %#v but is %#v", expected.Topic, args.Topic)
  1498. // }
  1499. }
  1500. func TestWhisperMessageArgsInt(t *testing.T) {
  1501. input := `[{"from":"0xc931d93e97ab07fe42d923478ba2465f2",
  1502. "topics": ["0x68656c6c6f20776f726c64"],
  1503. "payload":"0x68656c6c6f20776f726c64",
  1504. "ttl": 12,
  1505. "priority": 16}]`
  1506. expected := new(WhisperMessageArgs)
  1507. expected.From = "0xc931d93e97ab07fe42d923478ba2465f2"
  1508. expected.To = ""
  1509. expected.Payload = "0x68656c6c6f20776f726c64"
  1510. expected.Priority = 16
  1511. expected.Ttl = 12
  1512. // expected.Topics = []string{"0x68656c6c6f20776f726c64"}
  1513. args := new(WhisperMessageArgs)
  1514. if err := json.Unmarshal([]byte(input), &args); err != nil {
  1515. t.Error(err)
  1516. }
  1517. if expected.From != args.From {
  1518. t.Errorf("From shoud be %#v but is %#v", expected.From, args.From)
  1519. }
  1520. if expected.To != args.To {
  1521. t.Errorf("To shoud be %#v but is %#v", expected.To, args.To)
  1522. }
  1523. if expected.Payload != args.Payload {
  1524. t.Errorf("Value shoud be %#v but is %#v", expected.Payload, args.Payload)
  1525. }
  1526. if expected.Ttl != args.Ttl {
  1527. t.Errorf("Ttl shoud be %v but is %v", expected.Ttl, args.Ttl)
  1528. }
  1529. if expected.Priority != args.Priority {
  1530. t.Errorf("Priority shoud be %v but is %v", expected.Priority, args.Priority)
  1531. }
  1532. // if expected.Topics != args.Topics {
  1533. // t.Errorf("Topic shoud be %#v but is %#v", expected.Topic, args.Topic)
  1534. // }
  1535. }
  1536. func TestWhisperMessageArgsInvalid(t *testing.T) {
  1537. input := `{}`
  1538. args := new(WhisperMessageArgs)
  1539. str := ExpectDecodeParamError(json.Unmarshal([]byte(input), args))
  1540. if len(str) > 0 {
  1541. t.Error(str)
  1542. }
  1543. }
  1544. func TestWhisperMessageArgsEmpty(t *testing.T) {
  1545. input := `[]`
  1546. args := new(WhisperMessageArgs)
  1547. str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), args))
  1548. if len(str) > 0 {
  1549. t.Error(str)
  1550. }
  1551. }
  1552. func TestWhisperMessageArgsTtlBool(t *testing.T) {
  1553. input := `[{"from":"0xc931d93e97ab07fe42d923478ba2465f2",
  1554. "topics": ["0x68656c6c6f20776f726c64"],
  1555. "payload":"0x68656c6c6f20776f726c64",
  1556. "ttl": true,
  1557. "priority": "0x64"}]`
  1558. args := new(WhisperMessageArgs)
  1559. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), args))
  1560. if len(str) > 0 {
  1561. t.Error(str)
  1562. }
  1563. }
  1564. func TestWhisperMessageArgsPriorityBool(t *testing.T) {
  1565. input := `[{"from":"0xc931d93e97ab07fe42d923478ba2465f2",
  1566. "topics": ["0x68656c6c6f20776f726c64"],
  1567. "payload":"0x68656c6c6f20776f726c64",
  1568. "ttl": "0x12",
  1569. "priority": true}]`
  1570. args := new(WhisperMessageArgs)
  1571. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), args))
  1572. if len(str) > 0 {
  1573. t.Error(str)
  1574. }
  1575. }
  1576. func TestFilterIdArgs(t *testing.T) {
  1577. input := `["0x7"]`
  1578. expected := new(FilterIdArgs)
  1579. expected.Id = 7
  1580. args := new(FilterIdArgs)
  1581. if err := json.Unmarshal([]byte(input), &args); err != nil {
  1582. t.Error(err)
  1583. }
  1584. if expected.Id != args.Id {
  1585. t.Errorf("Id shoud be %#v but is %#v", expected.Id, args.Id)
  1586. }
  1587. }
  1588. func TestFilterIdArgsInvalid(t *testing.T) {
  1589. input := `{}`
  1590. args := new(FilterIdArgs)
  1591. str := ExpectDecodeParamError(json.Unmarshal([]byte(input), &args))
  1592. if len(str) > 0 {
  1593. t.Errorf(str)
  1594. }
  1595. }
  1596. func TestFilterIdArgsEmpty(t *testing.T) {
  1597. input := `[]`
  1598. args := new(FilterIdArgs)
  1599. str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), &args))
  1600. if len(str) > 0 {
  1601. t.Errorf(str)
  1602. }
  1603. }
  1604. func TestFilterIdArgsBool(t *testing.T) {
  1605. input := `[true]`
  1606. args := new(FilterIdArgs)
  1607. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  1608. if len(str) > 0 {
  1609. t.Errorf(str)
  1610. }
  1611. }
  1612. func TestWhisperFilterArgs(t *testing.T) {
  1613. input := `[{"topics": ["0x68656c6c6f20776f726c64"], "to": "0x34ag445g3455b34"}]`
  1614. expected := new(WhisperFilterArgs)
  1615. expected.To = "0x34ag445g3455b34"
  1616. expected.Topics = [][]string{[]string{"0x68656c6c6f20776f726c64"}}
  1617. args := new(WhisperFilterArgs)
  1618. if err := json.Unmarshal([]byte(input), &args); err != nil {
  1619. t.Error(err)
  1620. }
  1621. if expected.To != args.To {
  1622. t.Errorf("To shoud be %#v but is %#v", expected.To, args.To)
  1623. }
  1624. // if expected.Topics != args.Topics {
  1625. // t.Errorf("Topics shoud be %#v but is %#v", expected.Topics, args.Topics)
  1626. // }
  1627. }
  1628. func TestWhisperFilterArgsInvalid(t *testing.T) {
  1629. input := `{}`
  1630. args := new(WhisperFilterArgs)
  1631. str := ExpectDecodeParamError(json.Unmarshal([]byte(input), args))
  1632. if len(str) > 0 {
  1633. t.Error(str)
  1634. }
  1635. }
  1636. func TestWhisperFilterArgsEmpty(t *testing.T) {
  1637. input := `[]`
  1638. args := new(WhisperFilterArgs)
  1639. str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), args))
  1640. if len(str) > 0 {
  1641. t.Error(str)
  1642. }
  1643. }
  1644. func TestWhisperFilterArgsToInt(t *testing.T) {
  1645. input := `[{"to": 2}]`
  1646. args := new(WhisperFilterArgs)
  1647. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), args))
  1648. if len(str) > 0 {
  1649. t.Error(str)
  1650. }
  1651. }
  1652. func TestWhisperFilterArgsToBool(t *testing.T) {
  1653. input := `[{"topics": ["0x68656c6c6f20776f726c64"], "to": false}]`
  1654. args := new(WhisperFilterArgs)
  1655. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), args))
  1656. if len(str) > 0 {
  1657. t.Error(str)
  1658. }
  1659. }
  1660. func TestWhisperFilterArgsToMissing(t *testing.T) {
  1661. input := `[{"topics": ["0x68656c6c6f20776f726c64"]}]`
  1662. expected := new(WhisperFilterArgs)
  1663. expected.To = ""
  1664. args := new(WhisperFilterArgs)
  1665. if err := json.Unmarshal([]byte(input), &args); err != nil {
  1666. t.Error(err)
  1667. }
  1668. if args.To != expected.To {
  1669. t.Errorf("To shoud be %v but is %v", expected.To, args.To)
  1670. }
  1671. }
  1672. func TestWhisperFilterArgsTopicInt(t *testing.T) {
  1673. input := `[{"topics": [6], "to": "0x34ag445g3455b34"}]`
  1674. args := new(WhisperFilterArgs)
  1675. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), args))
  1676. if len(str) > 0 {
  1677. t.Error(str)
  1678. }
  1679. }
  1680. func TestCompileArgs(t *testing.T) {
  1681. input := `["contract test { function multiply(uint a) returns(uint d) { return a * 7; } }"]`
  1682. expected := new(CompileArgs)
  1683. expected.Source = `contract test { function multiply(uint a) returns(uint d) { return a * 7; } }`
  1684. args := new(CompileArgs)
  1685. if err := json.Unmarshal([]byte(input), &args); err != nil {
  1686. t.Error(err)
  1687. }
  1688. if expected.Source != args.Source {
  1689. t.Errorf("Source shoud be %#v but is %#v", expected.Source, args.Source)
  1690. }
  1691. }
  1692. func TestCompileArgsInvalid(t *testing.T) {
  1693. input := `{}`
  1694. args := new(CompileArgs)
  1695. str := ExpectDecodeParamError(json.Unmarshal([]byte(input), args))
  1696. if len(str) > 0 {
  1697. t.Error(str)
  1698. }
  1699. }
  1700. func TestCompileArgsEmpty(t *testing.T) {
  1701. input := `[]`
  1702. args := new(CompileArgs)
  1703. str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), args))
  1704. if len(str) > 0 {
  1705. t.Error(str)
  1706. }
  1707. }
  1708. func TestCompileArgsBool(t *testing.T) {
  1709. input := `[false]`
  1710. args := new(CompileArgs)
  1711. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), args))
  1712. if len(str) > 0 {
  1713. t.Error(str)
  1714. }
  1715. }
  1716. func TestFilterStringArgs(t *testing.T) {
  1717. input := `["pending"]`
  1718. expected := new(FilterStringArgs)
  1719. expected.Word = "pending"
  1720. args := new(FilterStringArgs)
  1721. if err := json.Unmarshal([]byte(input), &args); err != nil {
  1722. t.Error(err)
  1723. }
  1724. if expected.Word != args.Word {
  1725. t.Errorf("Word shoud be %#v but is %#v", expected.Word, args.Word)
  1726. }
  1727. }
  1728. func TestFilterStringEmptyArgs(t *testing.T) {
  1729. input := `[]`
  1730. args := new(FilterStringArgs)
  1731. str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), &args))
  1732. if len(str) > 0 {
  1733. t.Errorf(str)
  1734. }
  1735. }
  1736. func TestFilterStringInvalidArgs(t *testing.T) {
  1737. input := `{}`
  1738. args := new(FilterStringArgs)
  1739. str := ExpectDecodeParamError(json.Unmarshal([]byte(input), &args))
  1740. if len(str) > 0 {
  1741. t.Errorf(str)
  1742. }
  1743. }
  1744. func TestFilterStringWordInt(t *testing.T) {
  1745. input := `[7]`
  1746. args := new(FilterStringArgs)
  1747. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  1748. if len(str) > 0 {
  1749. t.Errorf(str)
  1750. }
  1751. }
  1752. func TestFilterStringWordWrong(t *testing.T) {
  1753. input := `["foo"]`
  1754. args := new(FilterStringArgs)
  1755. str := ExpectValidationError(json.Unmarshal([]byte(input), &args))
  1756. if len(str) > 0 {
  1757. t.Errorf(str)
  1758. }
  1759. }
  1760. func TestWhisperIdentityArgs(t *testing.T) {
  1761. input := `["0xc931d93e97ab07fe42d923478ba2465f283"]`
  1762. expected := new(WhisperIdentityArgs)
  1763. expected.Identity = "0xc931d93e97ab07fe42d923478ba2465f283"
  1764. args := new(WhisperIdentityArgs)
  1765. if err := json.Unmarshal([]byte(input), &args); err != nil {
  1766. t.Error(err)
  1767. }
  1768. if expected.Identity != args.Identity {
  1769. t.Errorf("Identity shoud be %#v but is %#v", expected.Identity, args.Identity)
  1770. }
  1771. }
  1772. func TestWhisperIdentityArgsInvalid(t *testing.T) {
  1773. input := `{}`
  1774. args := new(WhisperIdentityArgs)
  1775. str := ExpectDecodeParamError(json.Unmarshal([]byte(input), &args))
  1776. if len(str) > 0 {
  1777. t.Errorf(str)
  1778. }
  1779. }
  1780. func TestWhisperIdentityArgsEmpty(t *testing.T) {
  1781. input := `[]`
  1782. args := new(WhisperIdentityArgs)
  1783. str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), &args))
  1784. if len(str) > 0 {
  1785. t.Errorf(str)
  1786. }
  1787. }
  1788. func TestWhisperIdentityArgsInt(t *testing.T) {
  1789. input := `[4]`
  1790. args := new(WhisperIdentityArgs)
  1791. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  1792. if len(str) > 0 {
  1793. t.Errorf(str)
  1794. }
  1795. }
  1796. func TestBlockNumArgs(t *testing.T) {
  1797. input := `["0x29a"]`
  1798. expected := new(BlockNumIndexArgs)
  1799. expected.BlockNumber = 666
  1800. args := new(BlockNumArg)
  1801. if err := json.Unmarshal([]byte(input), &args); err != nil {
  1802. t.Error(err)
  1803. }
  1804. if expected.BlockNumber != args.BlockNumber {
  1805. t.Errorf("BlockNumber shoud be %#v but is %#v", expected.BlockNumber, args.BlockNumber)
  1806. }
  1807. }
  1808. func TestBlockNumArgsWord(t *testing.T) {
  1809. input := `["pending"]`
  1810. expected := new(BlockNumIndexArgs)
  1811. expected.BlockNumber = -2
  1812. args := new(BlockNumArg)
  1813. if err := json.Unmarshal([]byte(input), &args); err != nil {
  1814. t.Error(err)
  1815. }
  1816. if expected.BlockNumber != args.BlockNumber {
  1817. t.Errorf("BlockNumber shoud be %#v but is %#v", expected.BlockNumber, args.BlockNumber)
  1818. }
  1819. }
  1820. func TestBlockNumArgsInvalid(t *testing.T) {
  1821. input := `{}`
  1822. args := new(BlockNumArg)
  1823. str := ExpectDecodeParamError(json.Unmarshal([]byte(input), &args))
  1824. if len(str) > 0 {
  1825. t.Error(str)
  1826. }
  1827. }
  1828. func TestBlockNumArgsEmpty(t *testing.T) {
  1829. input := `[]`
  1830. args := new(BlockNumArg)
  1831. str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), &args))
  1832. if len(str) > 0 {
  1833. t.Error(str)
  1834. }
  1835. }
  1836. func TestBlockNumArgsBool(t *testing.T) {
  1837. input := `[true]`
  1838. args := new(BlockNumArg)
  1839. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  1840. if len(str) > 0 {
  1841. t.Error(str)
  1842. }
  1843. }
  1844. func TestBlockNumIndexArgs(t *testing.T) {
  1845. input := `["0x29a", "0x0"]`
  1846. expected := new(BlockNumIndexArgs)
  1847. expected.BlockNumber = 666
  1848. expected.Index = 0
  1849. args := new(BlockNumIndexArgs)
  1850. if err := json.Unmarshal([]byte(input), &args); err != nil {
  1851. t.Error(err)
  1852. }
  1853. if expected.BlockNumber != args.BlockNumber {
  1854. t.Errorf("BlockNumber shoud be %#v but is %#v", expected.BlockNumber, args.BlockNumber)
  1855. }
  1856. if expected.Index != args.Index {
  1857. t.Errorf("Index shoud be %#v but is %#v", expected.Index, args.Index)
  1858. }
  1859. }
  1860. func TestBlockNumIndexArgsWord(t *testing.T) {
  1861. input := `["latest", 67]`
  1862. expected := new(BlockNumIndexArgs)
  1863. expected.BlockNumber = -1
  1864. expected.Index = 67
  1865. args := new(BlockNumIndexArgs)
  1866. if err := json.Unmarshal([]byte(input), &args); err != nil {
  1867. t.Error(err)
  1868. }
  1869. if expected.BlockNumber != args.BlockNumber {
  1870. t.Errorf("BlockNumber shoud be %#v but is %#v", expected.BlockNumber, args.BlockNumber)
  1871. }
  1872. if expected.Index != args.Index {
  1873. t.Errorf("Index shoud be %#v but is %#v", expected.Index, args.Index)
  1874. }
  1875. }
  1876. func TestBlockNumIndexArgsEmpty(t *testing.T) {
  1877. input := `[]`
  1878. args := new(BlockNumIndexArgs)
  1879. str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), &args))
  1880. if len(str) > 0 {
  1881. t.Error(str)
  1882. }
  1883. }
  1884. func TestBlockNumIndexArgsInvalid(t *testing.T) {
  1885. input := `"foo"`
  1886. args := new(BlockNumIndexArgs)
  1887. str := ExpectDecodeParamError(json.Unmarshal([]byte(input), &args))
  1888. if len(str) > 0 {
  1889. t.Error(str)
  1890. }
  1891. }
  1892. func TestBlockNumIndexArgsBlocknumInvalid(t *testing.T) {
  1893. input := `[{}, "0x1"]`
  1894. args := new(BlockNumIndexArgs)
  1895. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  1896. if len(str) > 0 {
  1897. t.Error(str)
  1898. }
  1899. }
  1900. func TestBlockNumIndexArgsIndexInvalid(t *testing.T) {
  1901. input := `["0x29a", true]`
  1902. args := new(BlockNumIndexArgs)
  1903. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  1904. if len(str) > 0 {
  1905. t.Error(str)
  1906. }
  1907. }
  1908. func TestHashIndexArgs(t *testing.T) {
  1909. input := `["0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", "0x1"]`
  1910. expected := new(HashIndexArgs)
  1911. expected.Hash = "0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b"
  1912. expected.Index = 1
  1913. args := new(HashIndexArgs)
  1914. if err := json.Unmarshal([]byte(input), &args); err != nil {
  1915. t.Error(err)
  1916. }
  1917. if expected.Hash != args.Hash {
  1918. t.Errorf("Hash shoud be %#v but is %#v", expected.Hash, args.Hash)
  1919. }
  1920. if expected.Index != args.Index {
  1921. t.Errorf("Index shoud be %#v but is %#v", expected.Index, args.Index)
  1922. }
  1923. }
  1924. func TestHashIndexArgsEmpty(t *testing.T) {
  1925. input := `[]`
  1926. args := new(HashIndexArgs)
  1927. str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), &args))
  1928. if len(str) > 0 {
  1929. t.Error(str)
  1930. }
  1931. }
  1932. func TestHashIndexArgsInvalid(t *testing.T) {
  1933. input := `{}`
  1934. args := new(HashIndexArgs)
  1935. str := ExpectDecodeParamError(json.Unmarshal([]byte(input), &args))
  1936. if len(str) > 0 {
  1937. t.Error(str)
  1938. }
  1939. }
  1940. func TestHashIndexArgsInvalidHash(t *testing.T) {
  1941. input := `[7, "0x1"]`
  1942. args := new(HashIndexArgs)
  1943. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  1944. if len(str) > 0 {
  1945. t.Error(str)
  1946. }
  1947. }
  1948. func TestHashIndexArgsInvalidIndex(t *testing.T) {
  1949. input := `["0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", false]`
  1950. args := new(HashIndexArgs)
  1951. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  1952. if len(str) > 0 {
  1953. t.Error(str)
  1954. }
  1955. }
  1956. func TestHashArgs(t *testing.T) {
  1957. input := `["0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b"]`
  1958. expected := new(HashIndexArgs)
  1959. expected.Hash = "0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b"
  1960. args := new(HashArgs)
  1961. if err := json.Unmarshal([]byte(input), &args); err != nil {
  1962. t.Error(err)
  1963. }
  1964. if expected.Hash != args.Hash {
  1965. t.Errorf("Hash shoud be %#v but is %#v", expected.Hash, args.Hash)
  1966. }
  1967. }
  1968. func TestHashArgsEmpty(t *testing.T) {
  1969. input := `[]`
  1970. args := new(HashArgs)
  1971. str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), &args))
  1972. if len(str) > 0 {
  1973. t.Error(str)
  1974. }
  1975. }
  1976. func TestHashArgsInvalid(t *testing.T) {
  1977. input := `{}`
  1978. args := new(HashArgs)
  1979. str := ExpectDecodeParamError(json.Unmarshal([]byte(input), &args))
  1980. if len(str) > 0 {
  1981. t.Error(str)
  1982. }
  1983. }
  1984. func TestHashArgsInvalidHash(t *testing.T) {
  1985. input := `[7]`
  1986. args := new(HashArgs)
  1987. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
  1988. if len(str) > 0 {
  1989. t.Error(str)
  1990. }
  1991. }
  1992. func TestSubmitWorkArgs(t *testing.T) {
  1993. input := `["0x0000000000000001", "0x1234567890abcdef1234567890abcdef", "0xD1GE5700000000000000000000000000"]`
  1994. expected := new(SubmitWorkArgs)
  1995. expected.Nonce = 1
  1996. expected.Header = "0x1234567890abcdef1234567890abcdef"
  1997. expected.Digest = "0xD1GE5700000000000000000000000000"
  1998. args := new(SubmitWorkArgs)
  1999. if err := json.Unmarshal([]byte(input), &args); err != nil {
  2000. t.Error(err)
  2001. }
  2002. if expected.Nonce != args.Nonce {
  2003. t.Errorf("Nonce shoud be %d but is %d", expected.Nonce, args.Nonce)
  2004. }
  2005. if expected.Header != args.Header {
  2006. t.Errorf("Header shoud be %#v but is %#v", expected.Header, args.Header)
  2007. }
  2008. if expected.Digest != args.Digest {
  2009. t.Errorf("Digest shoud be %#v but is %#v", expected.Digest, args.Digest)
  2010. }
  2011. }
  2012. func TestSubmitWorkArgsInvalid(t *testing.T) {
  2013. input := `{}`
  2014. args := new(SubmitWorkArgs)
  2015. str := ExpectDecodeParamError(json.Unmarshal([]byte(input), args))
  2016. if len(str) > 0 {
  2017. t.Error(str)
  2018. }
  2019. }
  2020. func TestSubmitWorkArgsEmpty(t *testing.T) {
  2021. input := `[]`
  2022. args := new(SubmitWorkArgs)
  2023. str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), args))
  2024. if len(str) > 0 {
  2025. t.Error(str)
  2026. }
  2027. }
  2028. func TestSubmitWorkArgsNonceInt(t *testing.T) {
  2029. input := `[1, "0x1234567890abcdef1234567890abcdef", "0xD1GE5700000000000000000000000000"]`
  2030. args := new(SubmitWorkArgs)
  2031. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), args))
  2032. if len(str) > 0 {
  2033. t.Error(str)
  2034. }
  2035. }
  2036. func TestSubmitWorkArgsHeaderInt(t *testing.T) {
  2037. input := `["0x0000000000000001", 1, "0xD1GE5700000000000000000000000000"]`
  2038. args := new(SubmitWorkArgs)
  2039. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), args))
  2040. if len(str) > 0 {
  2041. t.Error(str)
  2042. }
  2043. }
  2044. func TestSubmitWorkArgsDigestInt(t *testing.T) {
  2045. input := `["0x0000000000000001", "0x1234567890abcdef1234567890abcdef", 1]`
  2046. args := new(SubmitWorkArgs)
  2047. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), args))
  2048. if len(str) > 0 {
  2049. t.Error(str)
  2050. }
  2051. }
  2052. func TestBlockHeightFromJsonInvalid(t *testing.T) {
  2053. var num int64
  2054. var msg json.RawMessage = []byte(`}{`)
  2055. str := ExpectDecodeParamError(blockHeightFromJson(msg, &num))
  2056. if len(str) > 0 {
  2057. t.Error(str)
  2058. }
  2059. }
  2060. func TestSourceArgsEmpty(t *testing.T) {
  2061. input := `[]`
  2062. args := new(SourceArgs)
  2063. str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), &args))
  2064. if len(str) > 0 {
  2065. t.Error(str)
  2066. }
  2067. }
  2068. func TestSigArgs(t *testing.T) {
  2069. input := `["0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", "0x0"]`
  2070. expected := new(NewSigArgs)
  2071. expected.From = "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"
  2072. expected.Data = "0x0"
  2073. args := new(NewSigArgs)
  2074. if err := json.Unmarshal([]byte(input), &args); err != nil {
  2075. t.Error(err)
  2076. }
  2077. if expected.From != args.From {
  2078. t.Errorf("From should be %v but is %v", expected.From, args.From)
  2079. }
  2080. if expected.Data != args.Data {
  2081. t.Errorf("Data should be %v but is %v", expected.Data, args.Data)
  2082. }
  2083. }
  2084. func TestSigArgsEmptyData(t *testing.T) {
  2085. input := `["0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", ""]`
  2086. args := new(NewSigArgs)
  2087. str := ExpectValidationError(json.Unmarshal([]byte(input), args))
  2088. if len(str) > 0 {
  2089. t.Error(str)
  2090. }
  2091. }
  2092. func TestSigArgsDataType(t *testing.T) {
  2093. input := `["0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", 13]`
  2094. args := new(NewSigArgs)
  2095. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), args))
  2096. if len(str) > 0 {
  2097. t.Error(str)
  2098. }
  2099. }
  2100. func TestSigArgsEmptyFrom(t *testing.T) {
  2101. input := `["", "0x0"]`
  2102. args := new(NewSigArgs)
  2103. str := ExpectValidationError(json.Unmarshal([]byte(input), args))
  2104. if len(str) > 0 {
  2105. t.Error(str)
  2106. }
  2107. }
  2108. func TestSigArgsFromType(t *testing.T) {
  2109. input := `[false, "0x0"]`
  2110. args := new(NewSigArgs)
  2111. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), args))
  2112. if len(str) > 0 {
  2113. t.Error(str)
  2114. }
  2115. }
  2116. func TestSigArgsEmpty(t *testing.T) {
  2117. input := `[]`
  2118. args := new(NewSigArgs)
  2119. str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), args))
  2120. if len(str) > 0 {
  2121. t.Error(str)
  2122. }
  2123. }
  2124. func TestDataArgs(t *testing.T) {
  2125. input := `["0x0123"]`
  2126. expected := new(NewDataArgs)
  2127. expected.Data = "0x0123"
  2128. args := new(NewDataArgs)
  2129. if err := json.Unmarshal([]byte(input), &args); err != nil {
  2130. t.Error(err)
  2131. }
  2132. if expected.Data != args.Data {
  2133. t.Errorf("Data should be %v but is %v", expected.Data, args.Data)
  2134. }
  2135. }
  2136. func TestDataArgsEmptyData(t *testing.T) {
  2137. input := `[""]`
  2138. args := new(NewDataArgs)
  2139. str := ExpectValidationError(json.Unmarshal([]byte(input), args))
  2140. if len(str) > 0 {
  2141. t.Error(str)
  2142. }
  2143. }
  2144. func TestDataArgsDataType(t *testing.T) {
  2145. input := `[13]`
  2146. args := new(NewDataArgs)
  2147. str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), args))
  2148. if len(str) > 0 {
  2149. t.Error(str)
  2150. }
  2151. }
  2152. func TestDataArgsEmpty(t *testing.T) {
  2153. input := `[]`
  2154. args := new(NewDataArgs)
  2155. str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), args))
  2156. if len(str) > 0 {
  2157. t.Error(str)
  2158. }
  2159. }
  2160. func TestDataArgsInvalid(t *testing.T) {
  2161. input := `{}`
  2162. args := new(NewDataArgs)
  2163. str := ExpectDecodeParamError(json.Unmarshal([]byte(input), args))
  2164. if len(str) > 0 {
  2165. t.Error(str)
  2166. }
  2167. }