aboutsummaryrefslogtreecommitdiffstats
path: root/rpc
diff options
context:
space:
mode:
authorTaylor Gerring <taylor.gerring@gmail.com>2015-04-02 20:49:33 +0800
committerTaylor Gerring <taylor.gerring@gmail.com>2015-04-02 20:49:33 +0800
commit172b34351aeb03d0318d241c0941c27608448cfb (patch)
tree543ed4b302a5f959219827561f79b1b1d021ebba /rpc
parentb9c9d6d798b26942d69ec9d3c3e88a1b8f563fb6 (diff)
downloaddexon-172b34351aeb03d0318d241c0941c27608448cfb.tar.gz
dexon-172b34351aeb03d0318d241c0941c27608448cfb.tar.zst
dexon-172b34351aeb03d0318d241c0941c27608448cfb.zip
HashArgs fix + tests
Diffstat (limited to 'rpc')
-rw-r--r--rpc/api.go1
-rw-r--r--rpc/args_test.go45
2 files changed, 46 insertions, 0 deletions
diff --git a/rpc/api.go b/rpc/api.go
index 8cc86103b..ee2a6a047 100644
--- a/rpc/api.go
+++ b/rpc/api.go
@@ -194,6 +194,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
case "eth_getTransactionByHash":
args := new(HashArgs)
if err := json.Unmarshal(req.Params, &args); err != nil {
+ return err
}
tx, bhash, bnum, txi := api.xeth().EthTransactionByHash(args.Hash)
if tx != nil {
diff --git a/rpc/args_test.go b/rpc/args_test.go
index 902f8013e..0ac8f657b 100644
--- a/rpc/args_test.go
+++ b/rpc/args_test.go
@@ -2090,6 +2090,51 @@ func TestHashIndexArgsInvalidIndex(t *testing.T) {
}
}
+func TestHashArgs(t *testing.T) {
+ input := `["0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b"]`
+ expected := new(HashIndexArgs)
+ expected.Hash = "0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b"
+
+ args := new(HashArgs)
+ if err := json.Unmarshal([]byte(input), &args); err != nil {
+ t.Error(err)
+ }
+
+ if expected.Hash != args.Hash {
+ t.Errorf("Hash shoud be %#v but is %#v", expected.Hash, args.Hash)
+ }
+}
+
+func TestHashArgsEmpty(t *testing.T) {
+ input := `[]`
+
+ args := new(HashArgs)
+ str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), &args))
+ if len(str) > 0 {
+ t.Error(str)
+ }
+}
+
+func TestHashArgsInvalid(t *testing.T) {
+ input := `{}`
+
+ args := new(HashArgs)
+ str := ExpectDecodeParamError(json.Unmarshal([]byte(input), &args))
+ if len(str) > 0 {
+ t.Error(str)
+ }
+}
+
+func TestHashArgsInvalidHash(t *testing.T) {
+ input := `[7]`
+
+ args := new(HashArgs)
+ str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
+ if len(str) > 0 {
+ t.Error(str)
+ }
+}
+
func TestSubmitWorkArgs(t *testing.T) {
input := `["0x0000000000000001", "0x1234567890abcdef1234567890abcdef", "0xD1GE5700000000000000000000000000"]`
expected := new(SubmitWorkArgs)