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

Method Run

tests/state_test_util.go:124–155  ·  view source on GitHub ↗

Run executes a specific subtest.

(subtest StateSubtest, vmconfig vm.Config)

Source from the content-addressed store, hash-verified

122
123// Run executes a specific subtest.
124func (t *StateTest) Run(subtest StateSubtest, vmconfig vm.Config) (*state.StateDB, error) {
125 config, ok := Forks[subtest.Fork]
126 if !ok {
127 return nil, UnsupportedForkError{subtest.Fork}
128 }
129 block := t.genesis(config).ToBlock(nil)
130 statedb := MakePreState(database.NewMemDatabase(), t.json.Pre)
131
132 post := t.json.Post[subtest.Fork][subtest.Index]
133 msg, err := t.json.Tx.toMessage(post)
134 if err != nil {
135 return nil, err
136 }
137 context := core.NewEVMContext(msg, block.Header(), nil, &t.json.Env.Coinbase)
138 context.GetHash = vmTestBlockHash
139 evm := vm.NewEVM(context, statedb, config, vmconfig)
140
141 gaspool := new(core.GasPool)
142 gaspool.AddGas(block.GasLimit())
143 snapshot := statedb.Snapshot()
144 if _, _, _, err := core.ApplyMessage(evm, msg, gaspool); err != nil {
145 statedb.RevertToSnapshot(snapshot)
146 }
147 if logs := rlpHash(statedb.Logs()); logs != common.Hash(post.Logs) {
148 return statedb, fmt.Errorf("post state logs hash mismatch: got %x, want %x", logs, post.Logs)
149 }
150 root, _ := statedb.Commit(true)
151 if root != common.Hash(post.Root) {
152 return statedb, fmt.Errorf("post state root mismatch: got %x, want %x", root, post.Root)
153 }
154 return statedb, nil
155}
156
157func (t *StateTest) gasLimit(subtest StateSubtest) uint64 {
158 return t.json.Tx.GasLimit[t.json.Post[subtest.Fork][subtest.Index].Indexes.Gas]

Callers

nothing calls this directly

Calls 13

genesisMethod · 0.95
MakePreStateFunction · 0.85
ToBlockMethod · 0.80
toMessageMethod · 0.80
HeaderMethod · 0.80
AddGasMethod · 0.80
rlpHashFunction · 0.70
SnapshotMethod · 0.65
RevertToSnapshotMethod · 0.65
HashMethod · 0.65
CommitMethod · 0.65
GasLimitMethod · 0.45

Tested by

no test coverage detected