|
42 | 42 | testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
43 | 43 | testAddr = crypto.PubkeyToAddress(testKey.PublicKey)
|
44 | 44 | testContract = common.HexToAddress("0xbeef")
|
| 45 | + testEmpty = common.HexToAddress("0xeeee") |
45 | 46 | testSlot = common.HexToHash("0xdeadbeef")
|
46 | 47 | testValue = crypto.Keccak256Hash(testSlot[:])
|
47 | 48 | testBalance = big.NewInt(2e15)
|
@@ -80,8 +81,11 @@ func newTestBackend(t *testing.T) (*node.Node, []*types.Block) {
|
80 | 81 | func generateTestChain() (*core.Genesis, []*types.Block) {
|
81 | 82 | genesis := &core.Genesis{
|
82 | 83 | 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 | + }, |
85 | 89 | ExtraData: []byte("test genesis"),
|
86 | 90 | Timestamp: 9000,
|
87 | 91 | }
|
@@ -110,6 +114,12 @@ func TestGethClient(t *testing.T) {
|
110 | 114 | }, {
|
111 | 115 | "TestGetProof2",
|
112 | 116 | 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) }, |
113 | 123 | }, {
|
114 | 124 | "TestGetProofCanonicalizeKeys",
|
115 | 125 | func(t *testing.T) { testGetProofCanonicalizeKeys(t, client) },
|
@@ -274,6 +284,38 @@ func testGetProofCanonicalizeKeys(t *testing.T, client *rpc.Client) {
|
274 | 284 | }
|
275 | 285 | }
|
276 | 286 |
|
| 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 | + |
277 | 319 | func testGCStats(t *testing.T, client *rpc.Client) {
|
278 | 320 | ec := New(client)
|
279 | 321 | _, err := ec.GCStats(context.Background())
|
|
0 commit comments