Skip to content

Commit c3b8364

Browse files
committed
core/state: add createcontract to journal fuzzing
1 parent 10482a8 commit c3b8364

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

core/state/statedb_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,27 @@ func newTestAction(addr common.Address, r *rand.Rand) testAction {
385385
}
386386
},
387387
},
388+
{
389+
name: "CreateContract",
390+
fn: func(a testAction, s *StateDB) {
391+
if !s.Exist(addr) {
392+
s.CreateAccount(addr)
393+
}
394+
contractHash := s.GetCodeHash(addr)
395+
emptyCode := contractHash == (common.Hash{}) || contractHash == types.EmptyCodeHash
396+
storageRoot := s.GetStorageRoot(addr)
397+
emptyStorage := storageRoot == (common.Hash{}) || storageRoot == types.EmptyRootHash
398+
if s.GetNonce(addr) == 0 && emptyCode && emptyStorage {
399+
s.CreateContract(addr)
400+
// We also set some code here, to prevent the
401+
// CreateContract action from being performed twice in a row,
402+
// which would cause a difference in state when unrolling
403+
// the journal. (CreateContact assumes created was false prior to
404+
// invocation, and the journal rollback sets it to false).
405+
s.SetCode(addr, []byte{1})
406+
}
407+
},
408+
},
388409
{
389410
name: "SelfDestruct",
390411
fn: func(a testAction, s *StateDB) {

0 commit comments

Comments
 (0)