Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
28 changes: 28 additions & 0 deletions core/state/statedb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Loading