Skip to content

Commit 84041e8

Browse files
ethclient/gethclient: return storage proofs in GetProof (#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 5a584c2 commit 84041e8

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

@@ -73,7 +75,7 @@ func generateTestChain() (*core.Genesis, []*types.Block) {
7375
config := params.AllEthashProtocolChanges
7476
genesis := &core.Genesis{
7577
Config: config,
76-
Alloc: core.GenesisAlloc{testAddr: {Balance: testBalance}},
78+
Alloc: core.GenesisAlloc{testAddr: {Balance: testBalance, Storage: map[common.Hash]common.Hash{testSlot: testValue}}},
7779
ExtraData: []byte("test genesis"),
7880
Timestamp: 9000,
7981
}
@@ -191,7 +193,7 @@ func testAccessList(t *testing.T, client *rpc.Client) {
191193
func testGetProof(t *testing.T, client *rpc.Client) {
192194
ec := New(client)
193195
ethcl := ethclient.NewClient(client)
194-
result, err := ec.GetProof(context.Background(), testAddr, []string{}, nil)
196+
result, err := ec.GetProof(context.Background(), testAddr, []string{testSlot.String()}, nil)
195197
if err != nil {
196198
t.Fatal(err)
197199
}
@@ -208,6 +210,19 @@ func testGetProof(t *testing.T, client *rpc.Client) {
208210
if result.Balance.Cmp(balance) != 0 {
209211
t.Fatalf("invalid balance, want: %v got: %v", balance, result.Balance)
210212
}
213+
// test storage
214+
if len(result.StorageProof) != 1 {
215+
t.Fatalf("invalid storage proof, want 1 proof, got %v proof(s)", len(result.StorageProof))
216+
}
217+
proof := result.StorageProof[0]
218+
slotValue, _ := ethcl.StorageAt(context.Background(), testAddr, testSlot, nil)
219+
if !bytes.Equal(slotValue, proof.Value.Bytes()) {
220+
t.Fatalf("invalid storage proof value, want: %v, got: %v", slotValue, proof.Value.Bytes())
221+
}
222+
if proof.Key != testSlot.String() {
223+
t.Fatalf("invalid storage proof key, want: %v, got: %v", testSlot.String(), proof.Key)
224+
}
225+
211226
}
212227

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

0 commit comments

Comments
 (0)