From b72d2921b4647a676d95b136b611f74946c77a4c Mon Sep 17 00:00:00 2001 From: Xuanyu Hu Date: Wed, 7 Jan 2026 14:44:01 +0800 Subject: [PATCH] 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. --- tests/state_test_util.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/state_test_util.go b/tests/state_test_util.go index 1d6cc8db70..cefa3dfe6a 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -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]