From c3b8364e603b255ea2124c6e971d1f4f917ee087 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Mon, 15 Apr 2024 10:12:24 +0200 Subject: [PATCH] core/state: add createcontract to journal fuzzing --- core/state/statedb_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/core/state/statedb_test.go b/core/state/statedb_test.go index b75bf732a4..afc07ce3f6 100644 --- a/core/state/statedb_test.go +++ b/core/state/statedb_test.go @@ -385,6 +385,27 @@ func newTestAction(addr common.Address, r *rand.Rand) testAction { } }, }, + { + name: "CreateContract", + fn: func(a testAction, s *StateDB) { + if !s.Exist(addr) { + s.CreateAccount(addr) + } + contractHash := s.GetCodeHash(addr) + emptyCode := contractHash == (common.Hash{}) || contractHash == types.EmptyCodeHash + storageRoot := s.GetStorageRoot(addr) + emptyStorage := storageRoot == (common.Hash{}) || storageRoot == types.EmptyRootHash + if s.GetNonce(addr) == 0 && emptyCode && emptyStorage { + s.CreateContract(addr) + // We also set some code here, to prevent the + // CreateContract action from being performed twice in a row, + // which would cause a difference in state when unrolling + // the journal. (CreateContact assumes created was false prior to + // invocation, and the journal rollback sets it to false). + s.SetCode(addr, []byte{1}) + } + }, + }, { name: "SelfDestruct", fn: func(a testAction, s *StateDB) {