args_test.go 65 KB

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