tests: expose internal RunNoVerify method (#20051)
This commit is contained in:
parent
52a967cfab
commit
91b7349509
@ -144,11 +144,29 @@ func (t *StateTest) Subtests() []StateSubtest {
|
|||||||
return sub
|
return sub
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run executes a specific subtest.
|
// Run executes a specific subtest and verifies the post-state and logs
|
||||||
func (t *StateTest) Run(subtest StateSubtest, vmconfig vm.Config) (*state.StateDB, error) {
|
func (t *StateTest) Run(subtest StateSubtest, vmconfig vm.Config) (*state.StateDB, error) {
|
||||||
|
statedb, root, err := t.RunNoVerify(subtest, vmconfig)
|
||||||
|
if err != nil {
|
||||||
|
return statedb, err
|
||||||
|
}
|
||||||
|
post := t.json.Post[subtest.Fork][subtest.Index]
|
||||||
|
// N.B: We need to do this in a two-step process, because the first Commit takes care
|
||||||
|
// of suicides, and we need to touch the coinbase _after_ it has potentially suicided.
|
||||||
|
if root != common.Hash(post.Root) {
|
||||||
|
return statedb, fmt.Errorf("post state root mismatch: got %x, want %x", root, post.Root)
|
||||||
|
}
|
||||||
|
if logs := rlpHash(statedb.Logs()); logs != common.Hash(post.Logs) {
|
||||||
|
return statedb, fmt.Errorf("post state logs hash mismatch: got %x, want %x", logs, post.Logs)
|
||||||
|
}
|
||||||
|
return statedb, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// RunNoVerify runs a specific subtest and returns the statedb and post-state root
|
||||||
|
func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config) (*state.StateDB, common.Hash, error) {
|
||||||
config, eips, err := getVMConfig(subtest.Fork)
|
config, eips, err := getVMConfig(subtest.Fork)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, UnsupportedForkError{subtest.Fork}
|
return nil, common.Hash{}, UnsupportedForkError{subtest.Fork}
|
||||||
}
|
}
|
||||||
vmconfig.ExtraEips = eips
|
vmconfig.ExtraEips = eips
|
||||||
block := t.genesis(config).ToBlock(nil)
|
block := t.genesis(config).ToBlock(nil)
|
||||||
@ -157,7 +175,7 @@ func (t *StateTest) Run(subtest StateSubtest, vmconfig vm.Config) (*state.StateD
|
|||||||
post := t.json.Post[subtest.Fork][subtest.Index]
|
post := t.json.Post[subtest.Fork][subtest.Index]
|
||||||
msg, err := t.json.Tx.toMessage(post)
|
msg, err := t.json.Tx.toMessage(post)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, common.Hash{}, err
|
||||||
}
|
}
|
||||||
context := core.NewEVMContext(msg, block.Header(), nil, &t.json.Env.Coinbase)
|
context := core.NewEVMContext(msg, block.Header(), nil, &t.json.Env.Coinbase)
|
||||||
context.GetHash = vmTestBlockHash
|
context.GetHash = vmTestBlockHash
|
||||||
@ -179,15 +197,7 @@ func (t *StateTest) Run(subtest StateSubtest, vmconfig vm.Config) (*state.StateD
|
|||||||
statedb.AddBalance(block.Coinbase(), new(big.Int))
|
statedb.AddBalance(block.Coinbase(), new(big.Int))
|
||||||
// And _now_ get the state root
|
// And _now_ get the state root
|
||||||
root := statedb.IntermediateRoot(config.IsEIP158(block.Number()))
|
root := statedb.IntermediateRoot(config.IsEIP158(block.Number()))
|
||||||
// N.B: We need to do this in a two-step process, because the first Commit takes care
|
return statedb, root, nil
|
||||||
// of suicides, and we need to touch the coinbase _after_ it has potentially suicided.
|
|
||||||
if root != common.Hash(post.Root) {
|
|
||||||
return statedb, fmt.Errorf("post state root mismatch: got %x, want %x", root, post.Root)
|
|
||||||
}
|
|
||||||
if logs := rlpHash(statedb.Logs()); logs != common.Hash(post.Logs) {
|
|
||||||
return statedb, fmt.Errorf("post state logs hash mismatch: got %x, want %x", logs, post.Logs)
|
|
||||||
}
|
|
||||||
return statedb, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *StateTest) gasLimit(subtest StateSubtest) uint64 {
|
func (t *StateTest) gasLimit(subtest StateSubtest) uint64 {
|
||||||
|
Loading…
Reference in New Issue
Block a user