提交 35ad9feb 编写于 作者: T Taylor Gerring

Update eth_getBlockByNumber to accept words

上级 5f6c8832
...@@ -145,12 +145,8 @@ func (args *GetBlockByNumberArgs) UnmarshalJSON(b []byte) (err error) { ...@@ -145,12 +145,8 @@ func (args *GetBlockByNumberArgs) UnmarshalJSON(b []byte) (err error) {
return NewInsufficientParamsError(len(obj), 2) return NewInsufficientParamsError(len(obj), 2)
} }
if v, ok := obj[0].(float64); ok { if err := blockHeight(obj[0], &args.BlockNumber); err != nil {
args.BlockNumber = int64(v) return err
} else if v, ok := obj[0].(string); ok {
args.BlockNumber = common.Big(v).Int64()
} else {
return NewInvalidTypeError("blockNumber", "not a number or string")
} }
args.IncludeTxs = obj[1].(bool) args.IncludeTxs = obj[1].(bool)
......
...@@ -355,6 +355,25 @@ func TestGetBlockByNumberArgsBlockHex(t *testing.T) { ...@@ -355,6 +355,25 @@ func TestGetBlockByNumberArgsBlockHex(t *testing.T) {
t.Errorf("IncludeTxs should be %v but is %v", expected.IncludeTxs, args.IncludeTxs) 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) { func TestGetBlockByNumberEmpty(t *testing.T) {
input := `[]` input := `[]`
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册