@@ -74,6 +74,16 @@ func TestGetBlockByHashArgs(t *testing.T) {
7474 }
7575}
7676
77+ func TestGetBlockByHashEmpty (t * testing.T ) {
78+ input := `[]`
79+
80+ args := new (GetBlockByHashArgs )
81+ err := json .Unmarshal ([]byte (input ), & args )
82+ if err == nil {
83+ t .Error ("Expected error but didn't get one" )
84+ }
85+ }
86+
7787func TestGetBlockByNumberArgs (t * testing.T ) {
7888 input := `["0x1b4", false]`
7989 expected := new (GetBlockByNumberArgs )
@@ -94,6 +104,16 @@ func TestGetBlockByNumberArgs(t *testing.T) {
94104 }
95105}
96106
107+ func TestGetBlockByNumberEmpty (t * testing.T ) {
108+ input := `[]`
109+
110+ args := new (GetBlockByNumberArgs )
111+ err := json .Unmarshal ([]byte (input ), & args )
112+ if err == nil {
113+ t .Error ("Expected error but didn't get one" )
114+ }
115+ }
116+
97117func TestNewTxArgs (t * testing.T ) {
98118 input := `[{"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
99119 "to": "0xd46e8dd67c5d32be8058bb8eb970870f072445675",
@@ -139,6 +159,16 @@ func TestNewTxArgs(t *testing.T) {
139159 }
140160}
141161
162+ func TestNewTxArgsEmpty (t * testing.T ) {
163+ input := `[]`
164+
165+ args := new (NewTxArgs )
166+ err := json .Unmarshal ([]byte (input ), & args )
167+ if err == nil {
168+ t .Error ("Expected error but didn't get one" )
169+ }
170+ }
171+
142172func TestGetStorageArgs (t * testing.T ) {
143173 input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "latest"]`
144174 expected := new (GetStorageArgs )
@@ -163,6 +193,16 @@ func TestGetStorageArgs(t *testing.T) {
163193 }
164194}
165195
196+ func TestGetStorageEmptyArgs (t * testing.T ) {
197+ input := `[]`
198+
199+ args := new (GetStorageArgs )
200+ err := json .Unmarshal ([]byte (input ), & args )
201+ if err == nil {
202+ t .Error ("Expected error but didn't get one" )
203+ }
204+ }
205+
166206func TestGetStorageAtArgs (t * testing.T ) {
167207 input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "0x0", "0x2"]`
168208 expected := new (GetStorageAtArgs )
@@ -192,6 +232,16 @@ func TestGetStorageAtArgs(t *testing.T) {
192232 }
193233}
194234
235+ func TestGetStorageAtEmptyArgs (t * testing.T ) {
236+ input := `[]`
237+
238+ args := new (GetStorageAtArgs )
239+ err := json .Unmarshal ([]byte (input ), & args )
240+ if err == nil {
241+ t .Error ("Expected error but didn't get one" )
242+ }
243+ }
244+
195245func TestGetTxCountArgs (t * testing.T ) {
196246 input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "latest"]`
197247 expected := new (GetTxCountArgs )
@@ -216,6 +266,16 @@ func TestGetTxCountArgs(t *testing.T) {
216266 }
217267}
218268
269+ func TestGetTxCountEmptyArgs (t * testing.T ) {
270+ input := `[]`
271+
272+ args := new (GetTxCountArgs )
273+ err := json .Unmarshal ([]byte (input ), & args )
274+ if err == nil {
275+ t .Error ("Expected error but didn't get one" )
276+ }
277+ }
278+
219279func TestGetDataArgs (t * testing.T ) {
220280 input := `["0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8", "latest"]`
221281 expected := new (GetDataArgs )
@@ -240,6 +300,16 @@ func TestGetDataArgs(t *testing.T) {
240300 }
241301}
242302
303+ func TestGetDataEmptyArgs (t * testing.T ) {
304+ input := `[]`
305+
306+ args := new (GetDataArgs )
307+ err := json .Unmarshal ([]byte (input ), & args )
308+ if err == nil {
309+ t .Error ("Expected error but didn't get one" )
310+ }
311+ }
312+
243313func TestFilterOptions (t * testing.T ) {
244314 input := `[{
245315 "fromBlock": "0x1",
@@ -286,6 +356,56 @@ func TestFilterOptions(t *testing.T) {
286356 // }
287357}
288358
359+ func TestFilterOptionsWords (t * testing.T ) {
360+ input := `[{
361+ "fromBlock": "latest",
362+ "toBlock": "pending"
363+ }]`
364+ expected := new (FilterOptions )
365+ expected .Earliest = 0
366+ expected .Latest = - 1
367+
368+ args := new (FilterOptions )
369+ if err := json .Unmarshal ([]byte (input ), & args ); err != nil {
370+ t .Error (err )
371+ }
372+
373+ if expected .Earliest != args .Earliest {
374+ t .Errorf ("Earliest shoud be %#v but is %#v" , expected .Earliest , args .Earliest )
375+ }
376+
377+ if expected .Latest != args .Latest {
378+ t .Errorf ("Latest shoud be %#v but is %#v" , expected .Latest , args .Latest )
379+ }
380+ }
381+
382+ func TestFilterOptionsNums (t * testing.T ) {
383+ input := `[{
384+ "fromBlock": 2,
385+ "toBlock": 3
386+ }]`
387+
388+ args := new (FilterOptions )
389+ err := json .Unmarshal ([]byte (input ), & args )
390+ switch err .(type ) {
391+ case * DecodeParamError :
392+ break
393+ default :
394+ t .Errorf ("Should have *DecodeParamError but instead have %T" , err )
395+ }
396+
397+ }
398+
399+ func TestFilterOptionsEmptyArgs (t * testing.T ) {
400+ input := `[]`
401+
402+ args := new (FilterOptions )
403+ err := json .Unmarshal ([]byte (input ), & args )
404+ if err == nil {
405+ t .Error ("Expected error but didn't get one" )
406+ }
407+ }
408+
289409func TestDbArgs (t * testing.T ) {
290410 input := `["0x74657374","0x6b6579","0x6d79537472696e67"]`
291411 expected := new (DbArgs )
0 commit comments