Skip to content

Commit 5065e6c

Browse files
authored
triedb/pathdb: fix tester generator (ethereum#30972)
This change fixes is a rare bug in test generator: If the run is very unlucky it can use `modifyAccountOp` / `deleteAccountOp` without creating any account, leading to have a trie root same as the parent. This change makes the first operation always be a creation.
1 parent e75f354 commit 5065e6c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

triedb/pathdb/database_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,12 @@ func (t *tester) generate(parent common.Hash) (common.Hash, *trienode.MergedNode
222222
dirties = make(map[common.Hash]struct{})
223223
)
224224
for i := 0; i < 20; i++ {
225-
switch rand.Intn(opLen) {
225+
// Start with account creation always
226+
op := createAccountOp
227+
if i > 0 {
228+
op = rand.Intn(opLen)
229+
}
230+
switch op {
226231
case createAccountOp:
227232
// account creation
228233
addr := testrand.Address()

0 commit comments

Comments
 (0)