aboutsummaryrefslogtreecommitdiffstats
path: root/rpc
diff options
context:
space:
mode:
authorTaylor Gerring <taylor.gerring@gmail.com>2015-03-26 21:17:32 +0800
committerTaylor Gerring <taylor.gerring@gmail.com>2015-03-26 21:17:32 +0800
commit3472823be94acc5b999dcb8741901b3e0c07f5d6 (patch)
treeb9dbde3af918ed179e0aff69a089c496bff0e105 /rpc
parentcb103c089a7c9238326e6a9bb336e375281ca622 (diff)
downloadgo-tangerine-3472823be94acc5b999dcb8741901b3e0c07f5d6.tar
go-tangerine-3472823be94acc5b999dcb8741901b3e0c07f5d6.tar.gz
go-tangerine-3472823be94acc5b999dcb8741901b3e0c07f5d6.tar.bz2
go-tangerine-3472823be94acc5b999dcb8741901b3e0c07f5d6.tar.lz
go-tangerine-3472823be94acc5b999dcb8741901b3e0c07f5d6.tar.xz
go-tangerine-3472823be94acc5b999dcb8741901b3e0c07f5d6.tar.zst
go-tangerine-3472823be94acc5b999dcb8741901b3e0c07f5d6.zip
HashIndexArgs
Diffstat (limited to 'rpc')
-rw-r--r--rpc/api.go6
-rw-r--r--rpc/args.go4
-rw-r--r--rpc/args_test.go62
3 files changed, 66 insertions, 6 deletions
diff --git a/rpc/api.go b/rpc/api.go
index 0f5bac657..ff166264b 100644
--- a/rpc/api.go
+++ b/rpc/api.go
@@ -212,7 +212,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
args := new(HashIndexArgs)
if err := json.Unmarshal(req.Params, &args); err != nil {
}
- tx := api.xeth().EthTransactionByHash(args.Hash)
+ tx := api.xeth().EthTransactionByHash(args.Hash.Hex())
if tx != nil {
*reply = NewTransactionRes(tx)
}
@@ -222,7 +222,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
return err
}
- block := api.xeth().EthBlockByHexstring(args.Hash)
+ block := api.xeth().EthBlockByHash(args.Hash)
br := NewBlockRes(block)
br.fullTx = true
@@ -250,7 +250,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
return err
}
- br := NewBlockRes(api.xeth().EthBlockByHexstring(args.Hash))
+ br := NewBlockRes(api.xeth().EthBlockByHash(args.Hash))
if args.Index > int64(len(br.Uncles)) || args.Index < 0 {
return NewValidationError("Index", "does not exist")
diff --git a/rpc/args.go b/rpc/args.go
index 34ed84fc2..d3449928b 100644
--- a/rpc/args.go
+++ b/rpc/args.go
@@ -342,7 +342,7 @@ func (args *BlockNumIndexArgs) UnmarshalJSON(b []byte) (err error) {
}
type HashIndexArgs struct {
- Hash string
+ Hash common.Hash
Index int64
}
@@ -361,7 +361,7 @@ func (args *HashIndexArgs) UnmarshalJSON(b []byte) (err error) {
if !ok {
return NewInvalidTypeError("hash", "not a string")
}
- args.Hash = arg0
+ args.Hash = common.HexToHash(arg0)
if len(obj) > 1 {
arg1, ok := obj[1].(string)
diff --git a/rpc/args_test.go b/rpc/args_test.go
index 82bdcd257..ab74721b3 100644
--- a/rpc/args_test.go
+++ b/rpc/args_test.go
@@ -1139,7 +1139,7 @@ func TestBlockNumIndexArgsIndexInvalid(t *testing.T) {
func TestHashIndexArgs(t *testing.T) {
input := `["0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", "0x1"]`
expected := new(HashIndexArgs)
- expected.Hash = "0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b"
+ expected.Hash = common.HexToHash("0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b")
expected.Index = 1
args := new(HashIndexArgs)
@@ -1156,6 +1156,66 @@ func TestHashIndexArgs(t *testing.T) {
}
}
+func TestHashIndexArgsEmpty(t *testing.T) {
+ input := `[]`
+
+ args := new(HashIndexArgs)
+ err := json.Unmarshal([]byte(input), &args)
+ 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 TestHashIndexArgsInvalid(t *testing.T) {
+ input := `{}`
+
+ args := new(HashIndexArgs)
+ 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 TestHashIndexArgsInvalidHash(t *testing.T) {
+ input := `[7, "0x1"]`
+
+ args := new(HashIndexArgs)
+ 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 TestHashIndexArgsInvalidIndex(t *testing.T) {
+ input := `["0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", false]`
+
+ args := new(HashIndexArgs)
+ 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 TestSubmitWorkArgs(t *testing.T) {
input := `["0x0000000000000001", "0x1234567890abcdef1234567890abcdef", "0xD1GE5700000000000000000000000000"]`
expected := new(SubmitWorkArgs)