aboutsummaryrefslogtreecommitdiffstats
path: root/rpc
diff options
context:
space:
mode:
authorTaylor Gerring <taylor.gerring@gmail.com>2015-03-26 20:50:22 +0800
committerTaylor Gerring <taylor.gerring@gmail.com>2015-03-26 20:50:22 +0800
commitcd6b3fd28a0624ac27cecf9f3e331a027b9c7e67 (patch)
tree9d63d4aa32a4733b83c6434e999fe3da93683e6b /rpc
parenta49c81547ce32125917c0127c94c9845750e9e30 (diff)
downloadgo-tangerine-cd6b3fd28a0624ac27cecf9f3e331a027b9c7e67.tar
go-tangerine-cd6b3fd28a0624ac27cecf9f3e331a027b9c7e67.tar.gz
go-tangerine-cd6b3fd28a0624ac27cecf9f3e331a027b9c7e67.tar.bz2
go-tangerine-cd6b3fd28a0624ac27cecf9f3e331a027b9c7e67.tar.lz
go-tangerine-cd6b3fd28a0624ac27cecf9f3e331a027b9c7e67.tar.xz
go-tangerine-cd6b3fd28a0624ac27cecf9f3e331a027b9c7e67.tar.zst
go-tangerine-cd6b3fd28a0624ac27cecf9f3e331a027b9c7e67.zip
GetDataArgs
Diffstat (limited to 'rpc')
-rw-r--r--rpc/api.go5
-rw-r--r--rpc/args.go11
-rw-r--r--rpc/args_test.go60
3 files changed, 56 insertions, 20 deletions
diff --git a/rpc/api.go b/rpc/api.go
index aba47eee2..0f5bac657 100644
--- a/rpc/api.go
+++ b/rpc/api.go
@@ -159,10 +159,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
if err := json.Unmarshal(req.Params, &args); err != nil {
return err
}
- if err := args.requirements(); err != nil {
- return err
- }
- *reply = api.xethAtStateNum(args.BlockNumber).CodeAt(args.Address)
+ *reply = api.xethAtStateNum(args.BlockNumber).CodeAt(args.Address.Hex())
case "eth_sendTransaction", "eth_transact":
args := new(NewTxArgs)
if err := json.Unmarshal(req.Params, &args); err != nil {
diff --git a/rpc/args.go b/rpc/args.go
index 30ed1a17c..2b62811e3 100644
--- a/rpc/args.go
+++ b/rpc/args.go
@@ -281,7 +281,7 @@ func (args *GetBalanceArgs) UnmarshalJSON(b []byte) (err error) {
}
type GetDataArgs struct {
- Address string
+ Address common.Address
BlockNumber int64
}
@@ -299,7 +299,7 @@ func (args *GetDataArgs) UnmarshalJSON(b []byte) (err error) {
if !ok {
return NewInvalidTypeError("address", "not a string")
}
- args.Address = addstr
+ args.Address = common.HexToAddress(addstr)
if len(obj) > 1 {
if err := blockHeight(obj[1], &args.BlockNumber); err != nil {
@@ -310,13 +310,6 @@ func (args *GetDataArgs) UnmarshalJSON(b []byte) (err error) {
return nil
}
-func (args *GetDataArgs) requirements() error {
- if len(args.Address) == 0 {
- return NewValidationError("Address", "cannot be blank")
- }
- return nil
-}
-
type BlockNumIndexArgs struct {
BlockNumber int64
Index int64
diff --git a/rpc/args_test.go b/rpc/args_test.go
index 7dec5d8f4..b8df08413 100644
--- a/rpc/args_test.go
+++ b/rpc/args_test.go
@@ -682,7 +682,7 @@ func TestGetTxCountBlockheightInvalid(t *testing.T) {
func TestGetDataArgs(t *testing.T) {
input := `["0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8", "latest"]`
expected := new(GetDataArgs)
- expected.Address = "0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8"
+ expected.Address = common.HexToAddress("0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8")
expected.BlockNumber = -1
args := new(GetDataArgs)
@@ -690,10 +690,6 @@ func TestGetDataArgs(t *testing.T) {
t.Error(err)
}
- if err := args.requirements(); err != nil {
- t.Error(err)
- }
-
if expected.Address != args.Address {
t.Errorf("Address shoud be %#v but is %#v", expected.Address, args.Address)
}
@@ -703,13 +699,63 @@ func TestGetDataArgs(t *testing.T) {
}
}
-func TestGetDataEmptyArgs(t *testing.T) {
+func TestGetDataArgsEmpty(t *testing.T) {
input := `[]`
args := new(GetDataArgs)
err := json.Unmarshal([]byte(input), &args)
- if err == nil {
+ switch err.(type) {
+ case nil:
+ t.Error("Expected error but didn't get one")
+ case *InsufficientParamsError:
+ break
+ default:
+ t.Errorf("Expected *rpc.InsufficientParamsError but got %T with message `%s`", err, err.Error())
+ }
+}
+
+func TestGetDataArgsInvalid(t *testing.T) {
+ input := `{}`
+
+ args := new(GetDataArgs)
+ err := json.Unmarshal([]byte(input), &args)
+ switch err.(type) {
+ case nil:
+ t.Error("Expected error but didn't get one")
+ case *DecodeParamError:
+ break
+ default:
+ t.Errorf("Expected *rpc.DecodeParamError but got %T with message `%s`", err, err.Error())
+ }
+}
+
+func TestGetDataArgsAddressNotString(t *testing.T) {
+ input := `[12, "latest"]`
+
+ args := new(GetDataArgs)
+ err := json.Unmarshal([]byte(input), &args)
+ switch err.(type) {
+ case nil:
+ t.Error("Expected error but didn't get one")
+ case *InvalidTypeError:
+ break
+ default:
+ t.Errorf("Expected *rpc.InvalidTypeError but got %T with message `%s`", err, err.Error())
+ }
+}
+
+func TestGetDataArgsBlocknumberNotString(t *testing.T) {
+ input := `["0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8", false]`
+
+ args := new(GetDataArgs)
+ err := json.Unmarshal([]byte(input), &args)
+ switch err.(type) {
+ case nil:
t.Error("Expected error but didn't get one")
+ case *InvalidTypeError:
+ break
+ default:
+ t.Errorf("Expected *rpc.InvalidTypeError but got %T with message `%s`", err, err.Error())
}
}