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

Function MakePreState

tests/state_test_util.go:161–176  ·  view source on GitHub ↗
(db database.Database, accounts core.GenesisAlloc)

Source from the content-addressed store, hash-verified

159}
160
161func MakePreState(db database.Database, accounts core.GenesisAlloc) *state.StateDB {
162 sdb := state.NewDatabase(db)
163 statedb, _ := state.New(common.Hash{}, sdb)
164 for addr, a := range accounts {
165 statedb.SetCode(addr, a.Code)
166 statedb.SetNonce(addr, a.Nonce)
167 statedb.SetBalance(addr, a.Balance)
168 for k, v := range a.Storage {
169 statedb.SetState(addr, k, v)
170 }
171 }
172 // Commit and re-open to start with a clean state.
173 root, _ := statedb.Commit(false)
174 statedb, _ = state.New(root, sdb)
175 return statedb
176}
177
178func (t *StateTest) genesis(config *configs.ChainConfig) *core.Genesis {
179 return &core.Genesis{

Callers 2

RunMethod · 0.85
RunMethod · 0.85

Calls 5

SetCodeMethod · 0.65
SetNonceMethod · 0.65
SetStateMethod · 0.65
CommitMethod · 0.65
SetBalanceMethod · 0.45

Tested by

no test coverage detected