aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2015-04-23 17:11:20 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2015-04-23 17:11:20 +0800
commit359a9773a1bc3ab57697f0bdb82024efb19090e2 (patch)
treed6d2f79b80127ba7de784e4600dddf352613626f
parent69788cb973d3ddac335b165751227c60fb319700 (diff)
parent20bae2b8f6fb46440f0b7e6d83916c422fd84567 (diff)
downloaddexon-359a9773a1bc3ab57697f0bdb82024efb19090e2.tar.gz
dexon-359a9773a1bc3ab57697f0bdb82024efb19090e2.tar.zst
dexon-359a9773a1bc3ab57697f0bdb82024efb19090e2.zip
Merge pull request #783 from tgerring/issue777
Issue 777
-rw-r--r--rpc/args.go16
-rw-r--r--rpc/args_test.go56
2 files changed, 61 insertions, 11 deletions
diff --git a/rpc/args.go b/rpc/args.go
index d31773ff7..7694a3d3f 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)
@@ -539,11 +535,11 @@ func (args *BlockNumIndexArgs) UnmarshalJSON(b []byte) (err error) {
return err
}
- arg1, ok := obj[1].(string)
- if !ok {
- return NewInvalidTypeError("index", "not a string")
+ var arg1 *big.Int
+ if arg1, err = numString(obj[1]); err != nil {
+ return err
}
- args.Index = common.Big(arg1).Int64()
+ args.Index = arg1.Int64()
return nil
}
diff --git a/rpc/args_test.go b/rpc/args_test.go
index cfe6c0c45..2f011bfd9 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 := `[]`
@@ -2165,6 +2184,21 @@ func TestBlockNumArgs(t *testing.T) {
}
}
+func TestBlockNumArgsWord(t *testing.T) {
+ input := `["pending"]`
+ expected := new(BlockNumIndexArgs)
+ expected.BlockNumber = -2
+
+ args := new(BlockNumArg)
+ if err := json.Unmarshal([]byte(input), &args); err != nil {
+ t.Error(err)
+ }
+
+ if expected.BlockNumber != args.BlockNumber {
+ t.Errorf("BlockNumber shoud be %#v but is %#v", expected.BlockNumber, args.BlockNumber)
+ }
+}
+
func TestBlockNumArgsInvalid(t *testing.T) {
input := `{}`
@@ -2214,6 +2248,26 @@ func TestBlockNumIndexArgs(t *testing.T) {
}
}
+func TestBlockNumIndexArgsWord(t *testing.T) {
+ input := `["latest", 67]`
+ expected := new(BlockNumIndexArgs)
+ expected.BlockNumber = -1
+ expected.Index = 67
+
+ args := new(BlockNumIndexArgs)
+ if err := json.Unmarshal([]byte(input), &args); err != nil {
+ t.Error(err)
+ }
+
+ if expected.BlockNumber != args.BlockNumber {
+ t.Errorf("BlockNumber shoud be %#v but is %#v", expected.BlockNumber, args.BlockNumber)
+ }
+
+ if expected.Index != args.Index {
+ t.Errorf("Index shoud be %#v but is %#v", expected.Index, args.Index)
+ }
+}
+
func TestBlockNumIndexArgsEmpty(t *testing.T) {
input := `[]`
@@ -2245,7 +2299,7 @@ func TestBlockNumIndexArgsBlocknumInvalid(t *testing.T) {
}
func TestBlockNumIndexArgsIndexInvalid(t *testing.T) {
- input := `["0x29a", 1]`
+ input := `["0x29a", true]`
args := new(BlockNumIndexArgs)
str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))