mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 20:26:41 +00:00
Check post state root on expected error in state tests
Adds logic to verify the post state root when an error is expected in state tests and a post state root is defined. This ensures the state root matches the expected value after reverting to the snapshot.
This commit is contained in:
parent
957a3602d9
commit
b72d2921b4
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 mismatch: got %x, want %x", root, post.Root)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
post := t.json.Post[subtest.Fork][subtest.Index]
|
||||
|
|
|
|||
Loading…
Reference in a new issue