diff --git a/core/state/statedb.go b/core/state/statedb.go index e6b5fb8192..c5c72a7d94 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -425,7 +425,7 @@ func (s *StateDB) ApplyMVWriteSet(writes []blockstm.WriteDescriptor) { case CodePath: s.SetCode(addr, sr.GetCode(addr)) case SuicidePath: - stateObject := sr.getStateObject(addr) + stateObject := s.getStateObject(addr) if stateObject != nil { s.SelfDestruct(addr) } diff --git a/core/state/statedb_test.go b/core/state/statedb_test.go index 22d365bce5..614dafcef8 100644 --- a/core/state/statedb_test.go +++ b/core/state/statedb_test.go @@ -1997,3 +1997,31 @@ func TestStorageDirtiness(t *testing.T) { state.RevertToSnapshot(snap) checkDirty(common.Hash{0x1}, common.Hash{0x1}, true) } + +func TestShouldDeleteSmartContractIfItExistsInState(t *testing.T) { + t.Parallel() + + code := []byte{1, 2, 3} + + db := NewDatabase(triedb.NewDatabase(rawdb.NewMemoryDatabase(), triedb.HashDefaults), nil) + mvhm := blockstm.MakeMVHashMap() + s, _ := NewWithMVHashmap(common.Hash{}, db, nil, mvhm) + + addr := common.HexToAddress("0x01") + s.getOrNewStateObject(addr) + s.CreateContract(addr) + s.SetCode(addr, code) + s.Finalise(true) + + secondDB := s.Copy() + secondDB.SelfDestruct(addr) + + codeBeforeDeletion := s.GetCode(addr) + assert.Equal(t, code, codeBeforeDeletion, "smart contract should exist before deletion") + + s.ApplyMVWriteSet(secondDB.MVWriteList()) + s.Finalise(true) + + codeAfterDeletion := s.GetCode(addr) + assert.Equal(t, []byte(nil), codeAfterDeletion, "smart contract should be deleted") +}