MCPcopy Create free account
hub / github.com/CPChain/chain / TestUpdateLeaks

Function TestUpdateLeaks

core/state/statedb_test.go:39–62  ·  view source on GitHub ↗

Tests that updating a state trie does not leak any database writes prior to actually committing the state.

(t *testing.T)

Source from the content-addressed store, hash-verified

37// Tests that updating a state trie does not leak any database writes prior to
38// actually committing the state.
39func 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.

Callers

nothing calls this directly

Calls 9

KeysMethod · 0.95
GetMethod · 0.95
NewDatabaseFunction · 0.85
IntermediateRootMethod · 0.80
NewFunction · 0.70
AddBalanceMethod · 0.65
SetNonceMethod · 0.65
SetStateMethod · 0.65
SetCodeMethod · 0.65

Tested by

no test coverage detected