Skip to content

Commit c5a6e66

Browse files
trianglespheresadoci
authored andcommitted
ethclient/gethclient: return storage proofs in GetProof (ethereum#24697)
Storage proofs were being unmarshalled from the RPC form to the go struct, but were not being included in the final returned struct.
1 parent 504b978 commit c5a6e66

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

ethclient/gethclient/gethclient.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ func (ec *Client) GetProof(ctx context.Context, account common.Address, keys []s
114114
Nonce: uint64(res.Nonce),
115115
CodeHash: res.CodeHash,
116116
StorageHash: res.StorageHash,
117+
StorageProof: storageResults,
117118
}
118119
return &result, err
119120
}

ethclient/gethclient/gethclient_test.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ import (
4040
var (
4141
testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
4242
testAddr = crypto.PubkeyToAddress(testKey.PublicKey)
43+
testSlot = common.HexToHash("0xdeadbeef")
44+
testValue = crypto.Keccak256Hash(testSlot[:])
4345
testBalance = big.NewInt(2e15)
4446
)
4547

@@ -77,7 +79,7 @@ func generateTestChain() (*core.Genesis, []*types.Block) {
7779
config := params.AllEthashProtocolChanges
7880
genesis := &core.Genesis{
7981
Config: config,
80-
Alloc: core.GenesisAlloc{testAddr: {Balance: testBalance}},
82+
Alloc: core.GenesisAlloc{testAddr: {Balance: testBalance, Storage: map[common.Hash]common.Hash{testSlot: testValue}}},
8183
ExtraData: []byte("test genesis"),
8284
Timestamp: 9000,
8385
}
@@ -195,7 +197,7 @@ func testAccessList(t *testing.T, client *rpc.Client) {
195197
func testGetProof(t *testing.T, client *rpc.Client) {
196198
ec := New(client)
197199
ethcl := ethclient.NewClient(client)
198-
result, err := ec.GetProof(context.Background(), testAddr, []string{}, nil)
200+
result, err := ec.GetProof(context.Background(), testAddr, []string{testSlot.String()}, nil)
199201
if err != nil {
200202
t.Fatal(err)
201203
}
@@ -212,6 +214,19 @@ func testGetProof(t *testing.T, client *rpc.Client) {
212214
if result.Balance.Cmp(balance) != 0 {
213215
t.Fatalf("invalid balance, want: %v got: %v", balance, result.Balance)
214216
}
217+
// test storage
218+
if len(result.StorageProof) != 1 {
219+
t.Fatalf("invalid storage proof, want 1 proof, got %v proof(s)", len(result.StorageProof))
220+
}
221+
proof := result.StorageProof[0]
222+
slotValue, _ := ethcl.StorageAt(context.Background(), testAddr, testSlot, nil)
223+
if !bytes.Equal(slotValue, proof.Value.Bytes()) {
224+
t.Fatalf("invalid storage proof value, want: %v, got: %v", slotValue, proof.Value.Bytes())
225+
}
226+
if proof.Key != testSlot.String() {
227+
t.Fatalf("invalid storage proof key, want: %v, got: %v", testSlot.String(), proof.Key)
228+
}
229+
215230
}
216231

217232
func testGCStats(t *testing.T, client *rpc.Client) {

0 commit comments

Comments
 (0)