aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTaylor Gerring <taylor.gerring@gmail.com>2015-04-23 02:14:10 +0800
committerTaylor Gerring <taylor.gerring@gmail.com>2015-04-23 02:14:10 +0800
commit35ad9febceacbb0a40efe84b08205bb13222c1b5 (patch)
treef8d8ea9b60a096808dfea338f4b4af33b10e72f8
parent5f6c8832af98d9b8529b2ab771942f1536b0b081 (diff)
downloadgo-tangerine-35ad9febceacbb0a40efe84b08205bb13222c1b5.tar
go-tangerine-35ad9febceacbb0a40efe84b08205bb13222c1b5.tar.gz
go-tangerine-35ad9febceacbb0a40efe84b08205bb13222c1b5.tar.bz2
go-tangerine-35ad9febceacbb0a40efe84b08205bb13222c1b5.tar.lz
go-tangerine-35ad9febceacbb0a40efe84b08205bb13222c1b5.tar.xz
go-tangerine-35ad9febceacbb0a40efe84b08205bb13222c1b5.tar.zst
go-tangerine-35ad9febceacbb0a40efe84b08205bb13222c1b5.zip
Update eth_getBlockByNumber to accept words
-rw-r--r--rpc/args.go8
-rw-r--r--rpc/args_test.go19
2 files changed, 21 insertions, 6 deletions
diff --git a/rpc/args.go b/rpc/args.go
index d31773ff7..9f99456e6 100644
--- a/rpc/args.go
+++ b/rpc/args.go
@@ -145,12 +145,8 @@ func (args *GetBlockByNumberArgs) UnmarshalJSON(b []byte) (err error) {
return NewInsufficientParamsError(len(obj), 2)
}
- if v, ok := obj[0].(float64); ok {
- args.BlockNumber = int64(v)
- } else if v, ok := obj[0].(string); ok {
- args.BlockNumber = common.Big(v).Int64()
- } else {
- return NewInvalidTypeError("blockNumber", "not a number or string")
+ if err := blockHeight(obj[0], &args.BlockNumber); err != nil {
+ return err
}
args.IncludeTxs = obj[1].(bool)
diff --git a/rpc/args_test.go b/rpc/args_test.go
index cfe6c0c45..e78981a41 100644
--- a/rpc/args_test.go
+++ b/rpc/args_test.go
@@ -355,6 +355,25 @@ func TestGetBlockByNumberArgsBlockHex(t *testing.T) {
t.Errorf("IncludeTxs should be %v but is %v", expected.IncludeTxs, args.IncludeTxs)
}
}
+func TestGetBlockByNumberArgsWords(t *testing.T) {
+ input := `["earliest", true]`
+ expected := new(GetBlockByNumberArgs)
+ expected.BlockNumber = 0
+ expected.IncludeTxs = true
+
+ args := new(GetBlockByNumberArgs)
+ if err := json.Unmarshal([]byte(input), &args); err != nil {
+ t.Error(err)
+ }
+
+ if args.BlockNumber != expected.BlockNumber {
+ t.Errorf("BlockNumber should be %v but is %v", expected.BlockNumber, args.BlockNumber)
+ }
+
+ if args.IncludeTxs != expected.IncludeTxs {
+ t.Errorf("IncludeTxs should be %v but is %v", expected.IncludeTxs, args.IncludeTxs)
+ }
+}
func TestGetBlockByNumberEmpty(t *testing.T) {
input := `[]`