args_test.go 62 KB

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