Run executes a specific subtest.
(subtest StateSubtest, vmconfig vm.Config)
| 122 | |
| 123 | // Run executes a specific subtest. |
| 124 | func (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 | |
| 157 | func (t *StateTest) gasLimit(subtest StateSubtest) uint64 { |
| 158 | return t.json.Tx.GasLimit[t.json.Post[subtest.Fork][subtest.Index].Indexes.Gas] |
nothing calls this directly
no test coverage detected