forked from cerc-io/plugeth
GetStorageArgs
This commit is contained in:
parent
966cfa4bdd
commit
bd1a54f076
@ -106,11 +106,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := args.requirements(); err != nil {
|
*reply = api.xethAtStateNum(args.BlockNumber).State().SafeGet(args.Address.Hex()).Storage()
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
*reply = api.xethAtStateNum(args.BlockNumber).State().SafeGet(args.Address).Storage()
|
|
||||||
case "eth_getStorageAt":
|
case "eth_getStorageAt":
|
||||||
args := new(GetStorageAtArgs)
|
args := new(GetStorageAtArgs)
|
||||||
if err := json.Unmarshal(req.Params, &args); err != nil {
|
if err := json.Unmarshal(req.Params, &args); err != nil {
|
||||||
|
13
rpc/args.go
13
rpc/args.go
@ -149,7 +149,7 @@ func (args *NewTxArgs) UnmarshalJSON(b []byte) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type GetStorageArgs struct {
|
type GetStorageArgs struct {
|
||||||
Address string
|
Address common.Address
|
||||||
BlockNumber int64
|
BlockNumber int64
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,9 +165,9 @@ func (args *GetStorageArgs) UnmarshalJSON(b []byte) (err error) {
|
|||||||
|
|
||||||
addstr, ok := obj[0].(string)
|
addstr, ok := obj[0].(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return NewDecodeParamError("Address is not a string")
|
return NewDecodeParamError("address is not a string")
|
||||||
}
|
}
|
||||||
args.Address = addstr
|
args.Address = common.HexToAddress(addstr)
|
||||||
|
|
||||||
if len(obj) > 1 {
|
if len(obj) > 1 {
|
||||||
if err := blockHeight(obj[1], &args.BlockNumber); err != nil {
|
if err := blockHeight(obj[1], &args.BlockNumber); err != nil {
|
||||||
@ -178,13 +178,6 @@ func (args *GetStorageArgs) UnmarshalJSON(b []byte) (err error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (args *GetStorageArgs) requirements() error {
|
|
||||||
if len(args.Address) == 0 {
|
|
||||||
return NewValidationError("Address", "cannot be blank")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetStorageAtArgs struct {
|
type GetStorageAtArgs struct {
|
||||||
Address string
|
Address string
|
||||||
Key string
|
Key string
|
||||||
|
@ -239,7 +239,7 @@ func TestNewTxArgsFromEmpty(t *testing.T) {
|
|||||||
func TestGetStorageArgs(t *testing.T) {
|
func TestGetStorageArgs(t *testing.T) {
|
||||||
input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "latest"]`
|
input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "latest"]`
|
||||||
expected := new(GetStorageArgs)
|
expected := new(GetStorageArgs)
|
||||||
expected.Address = "0x407d73d8a49eeb85d32cf465507dd71d507100c1"
|
expected.Address = common.HexToAddress("0x407d73d8a49eeb85d32cf465507dd71d507100c1")
|
||||||
expected.BlockNumber = -1
|
expected.BlockNumber = -1
|
||||||
|
|
||||||
args := new(GetStorageArgs)
|
args := new(GetStorageArgs)
|
||||||
@ -247,10 +247,6 @@ func TestGetStorageArgs(t *testing.T) {
|
|||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := args.requirements(); err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if expected.Address != args.Address {
|
if expected.Address != args.Address {
|
||||||
t.Errorf("Address shoud be %#v but is %#v", expected.Address, args.Address)
|
t.Errorf("Address shoud be %#v but is %#v", expected.Address, args.Address)
|
||||||
}
|
}
|
||||||
@ -260,13 +256,63 @@ func TestGetStorageArgs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetStorageInvalidArgs(t *testing.T) {
|
||||||
|
input := `{}`
|
||||||
|
|
||||||
|
args := new(GetStorageArgs)
|
||||||
|
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 TestGetStorageInvalidBlockheight(t *testing.T) {
|
||||||
|
input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1", {}]`
|
||||||
|
|
||||||
|
args := new(GetStorageArgs)
|
||||||
|
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 TestGetStorageEmptyArgs(t *testing.T) {
|
func TestGetStorageEmptyArgs(t *testing.T) {
|
||||||
input := `[]`
|
input := `[]`
|
||||||
|
|
||||||
args := new(GetStorageArgs)
|
args := new(GetStorageArgs)
|
||||||
err := json.Unmarshal([]byte(input), &args)
|
err := json.Unmarshal([]byte(input), &args)
|
||||||
if err == nil {
|
switch err.(type) {
|
||||||
|
case nil:
|
||||||
t.Error("Expected error but didn't get one")
|
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 TestGetStorageAddressInt(t *testing.T) {
|
||||||
|
input := `[32456785432456, "latest"]`
|
||||||
|
|
||||||
|
args := new(GetStorageArgs)
|
||||||
|
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())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user