Skip to content

Commit ce5a480

Browse files
authored
ethclient: add empty/nonexist account testcase for eth_getProof RPC (#28482)
Adds testcases for eth_getProof endpoint for the following cases: - the account/contract does not exist - the account/contract exists but is empty.
1 parent 2f4833b commit ce5a480

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

ethclient/gethclient/gethclient_test.go

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ var (
4242
testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
4343
testAddr = crypto.PubkeyToAddress(testKey.PublicKey)
4444
testContract = common.HexToAddress("0xbeef")
45+
testEmpty = common.HexToAddress("0xeeee")
4546
testSlot = common.HexToHash("0xdeadbeef")
4647
testValue = crypto.Keccak256Hash(testSlot[:])
4748
testBalance = big.NewInt(2e15)
@@ -80,8 +81,11 @@ func newTestBackend(t *testing.T) (*node.Node, []*types.Block) {
8081
func generateTestChain() (*core.Genesis, []*types.Block) {
8182
genesis := &core.Genesis{
8283
Config: params.AllEthashProtocolChanges,
83-
Alloc: core.GenesisAlloc{testAddr: {Balance: testBalance, Storage: map[common.Hash]common.Hash{testSlot: testValue}},
84-
testContract: {Nonce: 1, Code: []byte{0x13, 0x37}}},
84+
Alloc: core.GenesisAlloc{
85+
testAddr: {Balance: testBalance, Storage: map[common.Hash]common.Hash{testSlot: testValue}},
86+
testContract: {Nonce: 1, Code: []byte{0x13, 0x37}},
87+
testEmpty: {Balance: big.NewInt(1)},
88+
},
8589
ExtraData: []byte("test genesis"),
8690
Timestamp: 9000,
8791
}
@@ -110,6 +114,12 @@ func TestGethClient(t *testing.T) {
110114
}, {
111115
"TestGetProof2",
112116
func(t *testing.T) { testGetProof(t, client, testContract) },
117+
}, {
118+
"TestGetProofEmpty",
119+
func(t *testing.T) { testGetProof(t, client, testEmpty) },
120+
}, {
121+
"TestGetProofNonExistent",
122+
func(t *testing.T) { testGetProofNonExistent(t, client) },
113123
}, {
114124
"TestGetProofCanonicalizeKeys",
115125
func(t *testing.T) { testGetProofCanonicalizeKeys(t, client) },
@@ -274,6 +284,38 @@ func testGetProofCanonicalizeKeys(t *testing.T, client *rpc.Client) {
274284
}
275285
}
276286

287+
func testGetProofNonExistent(t *testing.T, client *rpc.Client) {
288+
addr := common.HexToAddress("0x0001")
289+
ec := New(client)
290+
result, err := ec.GetProof(context.Background(), addr, nil, nil)
291+
if err != nil {
292+
t.Fatal(err)
293+
}
294+
if result.Address != addr {
295+
t.Fatalf("unexpected address, have: %v want: %v", result.Address, addr)
296+
}
297+
// test nonce
298+
if result.Nonce != 0 {
299+
t.Fatalf("invalid nonce, want: %v got: %v", 0, result.Nonce)
300+
}
301+
// test balance
302+
if result.Balance.Cmp(big.NewInt(0)) != 0 {
303+
t.Fatalf("invalid balance, want: %v got: %v", 0, result.Balance)
304+
}
305+
// test storage
306+
if have := len(result.StorageProof); have != 0 {
307+
t.Fatalf("invalid storage proof, want 0 proof, got %v proof(s)", have)
308+
}
309+
// test codeHash
310+
if have, want := result.CodeHash, (common.Hash{}); have != want {
311+
t.Fatalf("codehash wrong, have %v want %v ", have, want)
312+
}
313+
// test codeHash
314+
if have, want := result.StorageHash, (common.Hash{}); have != want {
315+
t.Fatalf("storagehash wrong, have %v want %v ", have, want)
316+
}
317+
}
318+
277319
func testGCStats(t *testing.T, client *rpc.Client) {
278320
ec := New(client)
279321
_, err := ec.GCStats(context.Background())

0 commit comments

Comments
 (0)