Skip to content

Commit 1861642

Browse files
committed
core/state: check journal dirties in random-snapshot poststate
1 parent 56352c2 commit 1861642

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

core/state/statedb_test.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"math"
2626
"math/rand"
2727
"reflect"
28+
"slices"
2829
"strings"
2930
"sync"
3031
"testing"
@@ -615,7 +616,7 @@ func (test *snapshotTest) checkEqual(state, checkstate *StateDB) error {
615616
checkeq("GetCode", state.GetCode(addr), checkstate.GetCode(addr))
616617
checkeq("GetCodeHash", state.GetCodeHash(addr), checkstate.GetCodeHash(addr))
617618
checkeq("GetCodeSize", state.GetCodeSize(addr), checkstate.GetCodeSize(addr))
618-
// Check created-flag
619+
// Check newContract-flag
619620
if obj := state.getStateObject(addr); obj != nil {
620621
checkeq("IsNewContract", obj.newContract, checkstate.getStateObject(addr).newContract)
621622
}
@@ -659,6 +660,23 @@ func (test *snapshotTest) checkEqual(state, checkstate *StateDB) error {
659660
return fmt.Errorf("got GetLogs(common.Hash{}) == %v, want GetLogs(common.Hash{}) == %v",
660661
state.GetLogs(common.Hash{}, 0, common.Hash{}), checkstate.GetLogs(common.Hash{}, 0, common.Hash{}))
661662
}
663+
if !maps.Equal(state.journal.dirties, checkstate.journal.dirties) {
664+
getKeys := func(dirty map[common.Address]int) string {
665+
var keys []common.Address
666+
out := new(strings.Builder)
667+
for key := range dirty {
668+
keys = append(keys, key)
669+
}
670+
slices.SortFunc(keys, common.Address.Cmp)
671+
for i, key := range keys {
672+
fmt.Fprintf(out, " %d. %v\n", i, key)
673+
}
674+
return out.String()
675+
}
676+
have := getKeys(state.journal.dirties)
677+
want := getKeys(checkstate.journal.dirties)
678+
return fmt.Errorf("dirty-journal set mismatch.\nhave:\n%v\nwant:\n%v\n", have, want)
679+
}
662680
return nil
663681
}
664682

0 commit comments

Comments
 (0)