Skip to content

Commit 91b7349

Browse files
holimanfjl
authored andcommitted
tests: expose internal RunNoVerify method (#20051)
1 parent 52a967c commit 91b7349

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

tests/state_test_util.go

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,29 @@ func (t *StateTest) Subtests() []StateSubtest {
144144
return sub
145145
}
146146

147-
// Run executes a specific subtest.
147+
// Run executes a specific subtest and verifies the post-state and logs
148148
func (t *StateTest) Run(subtest StateSubtest, vmconfig vm.Config) (*state.StateDB, error) {
149+
statedb, root, err := t.RunNoVerify(subtest, vmconfig)
150+
if err != nil {
151+
return statedb, err
152+
}
153+
post := t.json.Post[subtest.Fork][subtest.Index]
154+
// N.B: We need to do this in a two-step process, because the first Commit takes care
155+
// of suicides, and we need to touch the coinbase _after_ it has potentially suicided.
156+
if root != common.Hash(post.Root) {
157+
return statedb, fmt.Errorf("post state root mismatch: got %x, want %x", root, post.Root)
158+
}
159+
if logs := rlpHash(statedb.Logs()); logs != common.Hash(post.Logs) {
160+
return statedb, fmt.Errorf("post state logs hash mismatch: got %x, want %x", logs, post.Logs)
161+
}
162+
return statedb, nil
163+
}
164+
165+
// RunNoVerify runs a specific subtest and returns the statedb and post-state root
166+
func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config) (*state.StateDB, common.Hash, error) {
149167
config, eips, err := getVMConfig(subtest.Fork)
150168
if err != nil {
151-
return nil, UnsupportedForkError{subtest.Fork}
169+
return nil, common.Hash{}, UnsupportedForkError{subtest.Fork}
152170
}
153171
vmconfig.ExtraEips = eips
154172
block := t.genesis(config).ToBlock(nil)
@@ -157,7 +175,7 @@ func (t *StateTest) Run(subtest StateSubtest, vmconfig vm.Config) (*state.StateD
157175
post := t.json.Post[subtest.Fork][subtest.Index]
158176
msg, err := t.json.Tx.toMessage(post)
159177
if err != nil {
160-
return nil, err
178+
return nil, common.Hash{}, err
161179
}
162180
context := core.NewEVMContext(msg, block.Header(), nil, &t.json.Env.Coinbase)
163181
context.GetHash = vmTestBlockHash
@@ -179,15 +197,7 @@ func (t *StateTest) Run(subtest StateSubtest, vmconfig vm.Config) (*state.StateD
179197
statedb.AddBalance(block.Coinbase(), new(big.Int))
180198
// And _now_ get the state root
181199
root := statedb.IntermediateRoot(config.IsEIP158(block.Number()))
182-
// N.B: We need to do this in a two-step process, because the first Commit takes care
183-
// of suicides, and we need to touch the coinbase _after_ it has potentially suicided.
184-
if root != common.Hash(post.Root) {
185-
return statedb, fmt.Errorf("post state root mismatch: got %x, want %x", root, post.Root)
186-
}
187-
if logs := rlpHash(statedb.Logs()); logs != common.Hash(post.Logs) {
188-
return statedb, fmt.Errorf("post state logs hash mismatch: got %x, want %x", logs, post.Logs)
189-
}
190-
return statedb, nil
200+
return statedb, root, nil
191201
}
192202

193203
func (t *StateTest) gasLimit(subtest StateSubtest) uint64 {

0 commit comments

Comments
 (0)