Skip to content

Commit 82f6798

Browse files
jsvisacolinlyguo
authored andcommitted
ethclient: add empty/nonexist account testcase for eth_getProof RPC (ethereum#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 961b050 commit 82f6798

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

ethclient/gethclient/gethclient_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ var (
4343
testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
4444
testAddr = crypto.PubkeyToAddress(testKey.PublicKey)
4545
testContract = common.HexToAddress("0xbeef")
46+
testEmpty = common.HexToAddress("0xeeee")
4647
testSlot = common.HexToHash("0xdeadbeef")
4748
testValue = crypto.Keccak256Hash(testSlot[:])
4849
testBalance = big.NewInt(2e15)
@@ -96,6 +97,7 @@ func generateTestChain() (*core.Genesis, []*types.Block) {
9697
rcfg.IsCurieSlot: common.BytesToHash([]byte{1}),
9798
},
9899
},
100+
testEmpty: {Balance: big.NewInt(1)},
99101
},
100102
ExtraData: []byte("test genesis"),
101103
Timestamp: 9000,
@@ -125,6 +127,12 @@ func TestGethClient(t *testing.T) {
125127
}, {
126128
"TestGetProof2",
127129
func(t *testing.T) { testGetProof(t, client, testContract) },
130+
}, {
131+
"TestGetProofEmpty",
132+
func(t *testing.T) { testGetProof(t, client, testEmpty) },
133+
}, {
134+
"TestGetProofNonExistent",
135+
func(t *testing.T) { testGetProofNonExistent(t, client) },
128136
}, {
129137
"TestGetProofCanonicalizeKeys",
130138
func(t *testing.T) { testGetProofCanonicalizeKeys(t, client) },
@@ -292,6 +300,38 @@ func testGetProofCanonicalizeKeys(t *testing.T, client *rpc.Client) {
292300
}
293301
}
294302

303+
func testGetProofNonExistent(t *testing.T, client *rpc.Client) {
304+
addr := common.HexToAddress("0x0001")
305+
ec := New(client)
306+
result, err := ec.GetProof(context.Background(), addr, nil, nil)
307+
if err != nil {
308+
t.Fatal(err)
309+
}
310+
if result.Address != addr {
311+
t.Fatalf("unexpected address, have: %v want: %v", result.Address, addr)
312+
}
313+
// test nonce
314+
if result.Nonce != 0 {
315+
t.Fatalf("invalid nonce, want: %v got: %v", 0, result.Nonce)
316+
}
317+
// test balance
318+
if result.Balance.Cmp(big.NewInt(0)) != 0 {
319+
t.Fatalf("invalid balance, want: %v got: %v", 0, result.Balance)
320+
}
321+
// test storage
322+
if have := len(result.StorageProof); have != 0 {
323+
t.Fatalf("invalid storage proof, want 0 proof, got %v proof(s)", have)
324+
}
325+
// test codeHash
326+
if have, want := result.CodeHash, (common.Hash{}); have != want {
327+
t.Fatalf("codehash wrong, have %v want %v ", have, want)
328+
}
329+
// test codeHash
330+
if have, want := result.StorageHash, (common.Hash{}); have != want {
331+
t.Fatalf("storagehash wrong, have %v want %v ", have, want)
332+
}
333+
}
334+
295335
func testGCStats(t *testing.T, client *rpc.Client) {
296336
ec := New(client)
297337
_, err := ec.GCStats(context.Background())

0 commit comments

Comments
 (0)