Tests that updating a state trie does not leak any database writes prior to actually committing the state.
(t *testing.T)
| 37 | // Tests that updating a state trie does not leak any database writes prior to |
| 38 | // actually committing the state. |
| 39 | func TestUpdateLeaks(t *testing.T) { |
| 40 | // Create an empty state database |
| 41 | db := database.NewMemDatabase() |
| 42 | state, _ := New(common.Hash{}, NewDatabase(db)) |
| 43 | |
| 44 | // Update it with some accounts |
| 45 | for i := byte(0); i < 255; i++ { |
| 46 | addr := common.BytesToAddress([]byte{i}) |
| 47 | state.AddBalance(addr, big.NewInt(int64(11*i))) |
| 48 | state.SetNonce(addr, uint64(42*i)) |
| 49 | if i%2 == 0 { |
| 50 | state.SetState(addr, common.BytesToHash([]byte{i, i, i}), common.BytesToHash([]byte{i, i, i, i})) |
| 51 | } |
| 52 | if i%3 == 0 { |
| 53 | state.SetCode(addr, []byte{i, i, i, i, i}) |
| 54 | } |
| 55 | state.IntermediateRoot(false) |
| 56 | } |
| 57 | // Ensure that no data was leaked into the database |
| 58 | for _, key := range db.Keys() { |
| 59 | value, _ := db.Get(key) |
| 60 | t.Errorf("State leaked into database: %x -> %x", key, value) |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | // Tests that no intermediate state of an object is stored into the database, |
| 65 | // only the one right before the commit. |
nothing calls this directly
no test coverage detected