From b7a161bd0b5d112b89098ecb908a2d6eac76ae5a Mon Sep 17 00:00:00 2001 From: jsvisa Date: Tue, 31 Oct 2023 19:05:50 +0800 Subject: [PATCH] ethclient: add testcase Signed-off-by: jsvisa --- ethclient/gethclient/gethclient_test.go | 34 ++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/ethclient/gethclient/gethclient_test.go b/ethclient/gethclient/gethclient_test.go index 614ba72605..35e93bc4ee 100644 --- a/ethclient/gethclient/gethclient_test.go +++ b/ethclient/gethclient/gethclient_test.go @@ -112,7 +112,7 @@ func TestGethClient(t *testing.T) { func(t *testing.T) { testGetProof(t, client, testContract) }, }, { "TestGetProofNonExistent", - func(t *testing.T) { testGetProof(t, client, common.HexToAddress("0x0001")) }, + func(t *testing.T) { testGetProofNonExistent(t, client) }, }, { "TestGetProofCanonicalizeKeys", func(t *testing.T) { testGetProofCanonicalizeKeys(t, client) }, @@ -277,6 +277,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, []string{testSlot.String()}, 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 len(result.StorageProof) != 1 { + t.Fatalf("invalid storage proof, want 1 proof, got %v proof(s)", len(result.StorageProof)) + } + // test codeHash + if result.CodeHash != types.EmptyCodeHash { + t.Fatalf("codehash wrong, have %v want %v ", result.CodeHash, types.EmptyCodeHash) + } + // test codeHash + if result.StorageHash != types.EmptyRootHash { + t.Fatalf("storagehash wrong, have %v want %v ", result.StorageHash, types.EmptyRootHash) + } +} + func testGCStats(t *testing.T, client *rpc.Client) { ec := New(client) _, err := ec.GCStats(context.Background())