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

Function checkStateAccounts

core/state/sync_test.go:71–91  ·  view source on GitHub ↗

checkStateAccounts cross references a reconstructed state with an expected account array.

(t *testing.T, db database.Database, root common.Hash, accounts []*testAccount)

Source from the content-addressed store, hash-verified

69// checkStateAccounts cross references a reconstructed state with an expected
70// account array.
71func checkStateAccounts(t *testing.T, db database.Database, root common.Hash, accounts []*testAccount) {
72 // Check root availability and state contents
73 state, err := New(root, NewDatabase(db))
74 if err != nil {
75 t.Fatalf("failed to create state trie at %x: %v", root, err)
76 }
77 if err := checkStateConsistency(db, root); err != nil {
78 t.Fatalf("inconsistent state trie at %x: %v", root, err)
79 }
80 for i, acc := range accounts {
81 if balance := state.GetBalance(acc.address); balance.Cmp(acc.balance) != 0 {
82 t.Errorf("account %d: balance mismatch: have %v, want %v", i, balance, acc.balance)
83 }
84 if nonce := state.GetNonce(acc.address); nonce != acc.nonce {
85 t.Errorf("account %d: nonce mismatch: have %v, want %v", i, nonce, acc.nonce)
86 }
87 if code := state.GetCode(acc.address); !bytes.Equal(code, acc.code) {
88 t.Errorf("account %d: code mismatch: have %x, want %x", i, code, acc.code)
89 }
90 }
91}
92
93// checkTrieConsistency checks that all nodes in a (sub-)trie are indeed present.
94func checkTrieConsistency(db database.Database, root common.Hash) error {

Calls 8

NewDatabaseFunction · 0.85
checkStateConsistencyFunction · 0.85
CmpMethod · 0.80
NewFunction · 0.70
GetBalanceMethod · 0.65
GetNonceMethod · 0.65
GetCodeMethod · 0.65
EqualMethod · 0.65

Tested by

no test coverage detected