HashIndexArgs
This commit is contained in:
parent
cb103c089a
commit
3472823be9
@ -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")
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user