From e402e1dc2e72df2a433b984caeaba771085b2b66 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 2 Apr 2015 13:17:55 +0200 Subject: New args types with stricter checking --- rpc/args_test.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'rpc/args_test.go') diff --git a/rpc/args_test.go b/rpc/args_test.go index 3635882c0..f00899b79 100644 --- a/rpc/args_test.go +++ b/rpc/args_test.go @@ -225,7 +225,7 @@ func TestGetBlockByHashArgsHashInt(t *testing.T) { input := `[8]` args := new(GetBlockByHashArgs) - str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args)) + str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), &args)) if len(str) > 0 { t.Error(str) } @@ -281,6 +281,16 @@ func TestGetBlockByNumberEmpty(t *testing.T) { } } +func TestGetBlockByNumberShort(t *testing.T) { + input := `["0xbbb"]` + + args := new(GetBlockByNumberArgs) + str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), &args)) + if len(str) > 0 { + t.Error(str) + } +} + func TestGetBlockByNumberBool(t *testing.T) { input := `[true, true]` -- cgit v1.2.3 From 015453f5b3f5b78ac8f432aed2247c839a6e5049 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 2 Apr 2015 13:55:53 +0200 Subject: Default Value to 0 for NewTxArgs --- rpc/args_test.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'rpc/args_test.go') diff --git a/rpc/args_test.go b/rpc/args_test.go index f00899b79..8c1e8c478 100644 --- a/rpc/args_test.go +++ b/rpc/args_test.go @@ -500,12 +500,18 @@ func TestNewTxArgsValueMissing(t *testing.T) { "gasPrice": "0x9184e72a000", "data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675" }]` + expected := new(NewTxArgs) + expected.Value = big.NewInt(0) args := new(NewTxArgs) - str := ExpectValidationError(json.Unmarshal([]byte(input), &args)) - if len(str) > 0 { - t.Error(str) + if err := json.Unmarshal([]byte(input), &args); err != nil { + t.Error(err) } + + if bytes.Compare(expected.Value.Bytes(), args.Value.Bytes()) != 0 { + t.Errorf("Value shoud be %v but is %v", expected.Value, args.Value) + } + } func TestNewTxArgsEmpty(t *testing.T) { -- cgit v1.2.3 From b4eef59b6f9631d22fdf62a2b1a40fe05209fccd Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 2 Apr 2015 14:05:14 +0200 Subject: No longer require gas & gas price in transactions Defaults to 0, which is then set to default values in XEth --- rpc/args_test.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'rpc/args_test.go') diff --git a/rpc/args_test.go b/rpc/args_test.go index 8c1e8c478..902f8013e 100644 --- a/rpc/args_test.go +++ b/rpc/args_test.go @@ -468,11 +468,16 @@ func TestNewTxArgsGasMissing(t *testing.T) { "value": "0x9184e72a000", "data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675" }]` + expected := new(NewTxArgs) + expected.Gas = big.NewInt(0) args := new(NewTxArgs) - str := ExpectValidationError(json.Unmarshal([]byte(input), &args)) - if len(str) > 0 { - t.Error(str) + if err := json.Unmarshal([]byte(input), &args); err != nil { + t.Error(err) + } + + if bytes.Compare(expected.Gas.Bytes(), args.Gas.Bytes()) != 0 { + t.Errorf("Gas shoud be %v but is %v", expected.Gas, args.Gas) } } @@ -484,12 +489,18 @@ func TestNewTxArgsBlockGaspriceMissing(t *testing.T) { "value": "0x9184e72a000", "data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675" }]` + expected := new(NewTxArgs) + expected.GasPrice = big.NewInt(0) args := new(NewTxArgs) - str := ExpectValidationError(json.Unmarshal([]byte(input), &args)) - if len(str) > 0 { - t.Error(str) + if err := json.Unmarshal([]byte(input), &args); err != nil { + t.Error(err) } + + if bytes.Compare(expected.GasPrice.Bytes(), args.GasPrice.Bytes()) != 0 { + t.Errorf("GasPrice shoud be %v but is %v", expected.GasPrice, args.GasPrice) + } + } func TestNewTxArgsValueMissing(t *testing.T) { -- cgit v1.2.3