github.com/jeffallen/go-ethereum@v1.1.4-0.20150910155051-571d3236c49c/rpc/api/args_test.go (about)

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