mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-03-21 10:28:10 +00:00
tests: check correct revert on invalid tests (#33543)
This PR fixes an issue where `evm statetest` would not verify the post-state root hash if the test case expected an exception (e.g. invalid transaction). The fix involves: 1. Modifying `tests/state_test_util.go` in the `Run` method. 2. When an expected error occurs (`err != nil`), we now check if `post.Root` is defined. 3. If defined, we recalculate the intermediate root from the current state (which is reverted to the pre-transaction snapshot upon error). 4. We use `GetChainConfig` and `IsEIP158` to ensure the correct state clearing rules are applied when calculating the root, avoiding regressions on forks that require EIP-158 state clearing. 5. If the calculated root mismatches the expected root, the test now fails. This ensures that state tests are strictly verified against their expected post-state, even for failure scenarios. Fixes issue #33527 --------- Co-authored-by: MariusVanDerWijden <m.vanderwijden@live.de>
This commit is contained in:
parent
4eb5b66d9e
commit
7cd400612f
1 changed files with 14 additions and 0 deletions
|
|
@ -234,6 +234,20 @@ func (t *StateTest) Run(subtest StateSubtest, vmconfig vm.Config, snapshotter bo
|
|||
if err != nil {
|
||||
// Here, an error exists but it was expected.
|
||||
// We do not check the post state or logs.
|
||||
// However, if the test defines a post state root, we should check it.
|
||||
// In case of an error, the state is reverted to the snapshot, so we need to
|
||||
// recalculate the root.
|
||||
post := t.json.Post[subtest.Fork][subtest.Index]
|
||||
if post.Root != (common.UnprefixedHash{}) {
|
||||
config, _, err := GetChainConfig(subtest.Fork)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get chain config: %w", err)
|
||||
}
|
||||
root = st.StateDB.IntermediateRoot(config.IsEIP158(new(big.Int).SetUint64(t.json.Env.Number)))
|
||||
if root != common.Hash(post.Root) {
|
||||
return fmt.Errorf("post-state root does not match the pre-state root, indicates an error in the test: got %x, want %x", root, post.Root)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
post := t.json.Post[subtest.Fork][subtest.Index]
|
||||
|
|
|
|||
Loading…
Reference in a new issue