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

Function makeTestState

core/state/sync_test.go:39–67  ·  view source on GitHub ↗

makeTestState create a sample test state to test node-wise reconstruction.

()

Source from the content-addressed store, hash-verified

37
38// makeTestState create a sample test state to test node-wise reconstruction.
39func makeTestState() (Database, common.Hash, []*testAccount) {
40 // Create an empty state
41 db := NewDatabase(database.NewMemDatabase())
42 state, _ := New(common.Hash{}, db)
43
44 // Fill it with some arbitrary data
45 accounts := []*testAccount{}
46 for i := byte(0); i < 96; i++ {
47 obj := state.GetOrNewStateObject(common.BytesToAddress([]byte{i}))
48 acc := &testAccount{address: common.BytesToAddress([]byte{i})}
49
50 obj.AddBalance(big.NewInt(int64(11 * i)))
51 acc.balance = big.NewInt(int64(11 * i))
52
53 obj.SetNonce(uint64(42 * i))
54 acc.nonce = uint64(42 * i)
55
56 if i%3 == 0 {
57 obj.SetCode(crypto.Keccak256Hash([]byte{i, i, i, i, i}), []byte{i, i, i, i, i})
58 acc.code = []byte{i, i, i, i, i}
59 }
60 state.updateStateObject(obj)
61 accounts = append(accounts, acc)
62 }
63 root, _ := state.Commit(false)
64
65 // Return the generated state
66 return db, root, accounts
67}
68
69// checkStateAccounts cross references a reconstructed state with an expected
70// account array.

Calls 8

NewDatabaseFunction · 0.85
GetOrNewStateObjectMethod · 0.80
updateStateObjectMethod · 0.80
NewFunction · 0.70
AddBalanceMethod · 0.65
SetNonceMethod · 0.65
SetCodeMethod · 0.65
CommitMethod · 0.65

Tested by

no test coverage detected