Skip to content

Commit

Permalink
ethclient: add empty/nonexist account testcase for eth_getProof RPC (e…
Browse files Browse the repository at this point in the history
…thereum#28482)

Adds testcases for eth_getProof endpoint for the following cases:

- the account/contract does not exist
- the account/contract exists but is empty.
  • Loading branch information
jsvisa authored and colinlyguo committed Oct 31, 2024
1 parent 961b050 commit 82f6798
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions ethclient/gethclient/gethclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var (
testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
testAddr = crypto.PubkeyToAddress(testKey.PublicKey)
testContract = common.HexToAddress("0xbeef")
testEmpty = common.HexToAddress("0xeeee")
testSlot = common.HexToHash("0xdeadbeef")
testValue = crypto.Keccak256Hash(testSlot[:])
testBalance = big.NewInt(2e15)
Expand Down Expand Up @@ -96,6 +97,7 @@ func generateTestChain() (*core.Genesis, []*types.Block) {
rcfg.IsCurieSlot: common.BytesToHash([]byte{1}),
},
},
testEmpty: {Balance: big.NewInt(1)},
},
ExtraData: []byte("test genesis"),
Timestamp: 9000,
Expand Down Expand Up @@ -125,6 +127,12 @@ func TestGethClient(t *testing.T) {
}, {
"TestGetProof2",
func(t *testing.T) { testGetProof(t, client, testContract) },
}, {
"TestGetProofEmpty",
func(t *testing.T) { testGetProof(t, client, testEmpty) },
}, {
"TestGetProofNonExistent",
func(t *testing.T) { testGetProofNonExistent(t, client) },
}, {
"TestGetProofCanonicalizeKeys",
func(t *testing.T) { testGetProofCanonicalizeKeys(t, client) },
Expand Down Expand Up @@ -292,6 +300,38 @@ func testGetProofCanonicalizeKeys(t *testing.T, client *rpc.Client) {
}
}

func testGetProofNonExistent(t *testing.T, client *rpc.Client) {
addr := common.HexToAddress("0x0001")
ec := New(client)
result, err := ec.GetProof(context.Background(), addr, nil, nil)
if err != nil {
t.Fatal(err)
}
if result.Address != addr {
t.Fatalf("unexpected address, have: %v want: %v", result.Address, addr)
}
// test nonce
if result.Nonce != 0 {
t.Fatalf("invalid nonce, want: %v got: %v", 0, result.Nonce)
}
// test balance
if result.Balance.Cmp(big.NewInt(0)) != 0 {
t.Fatalf("invalid balance, want: %v got: %v", 0, result.Balance)
}
// test storage
if have := len(result.StorageProof); have != 0 {
t.Fatalf("invalid storage proof, want 0 proof, got %v proof(s)", have)
}
// test codeHash
if have, want := result.CodeHash, (common.Hash{}); have != want {
t.Fatalf("codehash wrong, have %v want %v ", have, want)
}
// test codeHash
if have, want := result.StorageHash, (common.Hash{}); have != want {
t.Fatalf("storagehash wrong, have %v want %v ", have, want)
}
}

func testGCStats(t *testing.T, client *rpc.Client) {
ec := New(client)
_, err := ec.GCStats(context.Background())
Expand Down

0 comments on commit 82f6798

Please sign in to comment.