Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinxie committed Sep 27, 2024
1 parent 554a155 commit c28dcc9
Showing 1 changed file with 42 additions and 3 deletions.
45 changes: 42 additions & 3 deletions action/protocol/execution/evm/evmstatedbadapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/iotexproject/iotex-core/action/protocol"
accountutil "github.com/iotexproject/iotex-core/action/protocol/account/util"
"github.com/iotexproject/iotex-core/blockchain/genesis"
"github.com/iotexproject/iotex-core/db/batch"
"github.com/iotexproject/iotex-core/state"
Expand Down Expand Up @@ -984,9 +985,7 @@ func TestStateDBTransientStorage(t *testing.T) {
FixSnapshotOrderOption(),
)
state, err := NewStateDBAdapter(sm, 1, hash.ZeroHash256, opts...)
if err != nil {
t.Fatal(err)
}
require.NoError(err)
var (
addr0 = common.Address{}
addr1 = common.HexToAddress("1234567890")
Expand Down Expand Up @@ -1022,3 +1021,43 @@ func TestStateDBTransientStorage(t *testing.T) {
}

}

func TestSelfdestruct6780(t *testing.T) {
r := require.New(t)
ctrl := gomock.NewController(t)
sm, err := initMockStateManager(ctrl)
r.NoError(err)
var opts []StateDBAdapterOption
opts = append(opts,
FixSnapshotOrderOption(),
EnableCancunEVMOption(),
)
state, err := NewStateDBAdapter(sm, 1, hash.ZeroHash256, opts...)
r.NoError(err)
_, created, err := accountutil.LoadOrCreateAccount(state.sm, _c4)
r.True(created)
addrs := []common.Address{_c1, _c2, _c3, _c4}
for _, addr := range addrs {
state.CreateAccount(addr)
state.Selfdestruct6780(addr)
state.Snapshot()
r.True(state.Exist(addr))
}
r.NoError(state.CommitContracts())
for _, addr := range addrs[:3] {
r.False(state.Exist(addr))
}
r.True(state.Exist(_c4)) // _c4 is a pre-existing account, won't be deleted by Selfdestruct6780
state.RevertToSnapshot(3)
r.Equal(createdAccount{
_c1: struct{}{}, _c2: struct{}{}, _c3: struct{}{}}, state.createdAccount)
state.RevertToSnapshot(2)
r.Equal(createdAccount{
_c1: struct{}{}, _c2: struct{}{}, _c3: struct{}{}}, state.createdAccount)
state.RevertToSnapshot(1)
r.Equal(createdAccount{
_c1: struct{}{}, _c2: struct{}{}}, state.createdAccount)
state.RevertToSnapshot(0)
r.Equal(createdAccount{
_c1: struct{}{}}, state.createdAccount)
}

0 comments on commit c28dcc9

Please sign in to comment.