Sync from fork #74

Merged
0xmuralik merged 232 commits from murali/update-fork into main 2023-01-10 04:50:57 +00:00
2 changed files with 20 additions and 8 deletions
Showing only changes of commit 737c1de694 - Show all commits

View File

@ -1,7 +1,6 @@
package keeper
import (
"bytes"
"fmt"
"math/big"
@ -188,7 +187,7 @@ func (k *Keeper) DeleteAccount(ctx sdk.Context, addr common.Address) error {
}
// NOTE: only Ethereum accounts (contracts) can be selfdestructed
ethAcct, ok := acct.(ethermint.EthAccountI)
_, ok := acct.(ethermint.EthAccountI)
if !ok {
return sdkerrors.Wrapf(types.ErrInvalidAccount, "type %T, address %s", acct, addr)
}
@ -198,12 +197,6 @@ func (k *Keeper) DeleteAccount(ctx sdk.Context, addr common.Address) error {
return err
}
// remove code
codeHashBz := ethAcct.GetCodeHash().Bytes()
if !bytes.Equal(codeHashBz, types.EmptyCodeHash) {
k.SetCode(ctx, codeHashBz, nil)
}
// clear storage
k.ForEachStorage(ctx, addr, func(key, _ common.Hash) bool {
k.SetState(ctx, addr, key, nil)

View File

@ -15,6 +15,7 @@ import (
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/evmos/ethermint/crypto/ethsecp256k1"
"github.com/evmos/ethermint/tests"
"github.com/evmos/ethermint/x/evm/statedb"
"github.com/evmos/ethermint/x/evm/types"
@ -420,12 +421,26 @@ func (suite *KeeperTestSuite) TestSuicide() {
suite.Require().NoError(db.Commit())
db = suite.StateDB()
// Generate 2nd address
privkey, _ := ethsecp256k1.GenerateKey()
key, err := privkey.ToECDSA()
suite.Require().NoError(err)
addr2 := crypto.PubkeyToAddress(key.PublicKey)
// Add code and state to account 2
db.SetCode(addr2, code)
suite.Require().Equal(code, db.GetCode(addr2))
for i := 0; i < 5; i++ {
db.SetState(addr2, common.BytesToHash([]byte(fmt.Sprintf("key%d", i))), common.BytesToHash([]byte(fmt.Sprintf("value%d", i))))
}
// Call Suicide
suite.Require().Equal(true, db.Suicide(suite.address))
// Check suicided is marked
suite.Require().Equal(true, db.HasSuicided(suite.address))
// Commit state
suite.Require().NoError(db.Commit())
db = suite.StateDB()
@ -441,6 +456,10 @@ func (suite *KeeperTestSuite) TestSuicide() {
// Check account is deleted
suite.Require().Equal(common.Hash{}, db.GetCodeHash(suite.address))
// Check code is still present in addr2 and suicided is false
suite.Require().NotNil(db.GetCode(addr2))
suite.Require().Equal(false, db.HasSuicided(addr2))
}
func (suite *KeeperTestSuite) TestExist() {