evm: fix keep balance when resetting an account (#353)

* keep balance when override account

* Update CHANGELOG.md

Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
yihuang 2021-07-26 16:15:59 +08:00 committed by GitHub
parent 30cc004e76
commit 2828fa1e62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 11 deletions

View File

@ -46,6 +46,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (evm) [tharsis#68](https://github.com/tharsis/ethermint/issues/68) Replace block hash storage map to use staking `HistoricalInfo`.
* (evm) [tharsis#276](https://github.com/tharsis/ethermint/pull/276) Vm errors don't result in cosmos tx failure, just
different tx state and events.
* (evm) [tharsis#342](https://github.com/tharsis/ethermint/issues/342) Don't clear balance when resetting the account.
### API Breaking

View File

@ -316,17 +316,9 @@ func (k Keeper) ClearBalance(addr sdk.AccAddress) (prevBalance sdk.Coin, err err
return prevBalance, nil
}
// ResetAccount removes the code, storage state and evm denom balance coins stored
// ResetAccount removes the code, storage state, but keep all the native tokens stored
// with the given address.
func (k Keeper) ResetAccount(addr common.Address) {
k.DeleteCode(addr)
k.DeleteAccountStorage(addr)
_, err := k.ClearBalance(addr.Bytes())
if err != nil {
k.Logger(k.ctx).Error(
"failed to clear balance during account reset",
"ethereum-address", addr.Hex(),
"error", err,
)
}
}

View File

@ -27,14 +27,14 @@ func (suite *KeeperTestSuite) TestCreateAccount() {
callback func(common.Address)
}{
{
"reset account",
"reset account (keep balance)",
suite.address,
func(addr common.Address) {
suite.app.EvmKeeper.AddBalance(addr, big.NewInt(100))
suite.Require().NotZero(suite.app.EvmKeeper.GetBalance(addr).Int64())
},
func(addr common.Address) {
suite.Require().Zero(suite.app.EvmKeeper.GetBalance(addr).Int64())
suite.Require().Equal(suite.app.EvmKeeper.GetBalance(addr).Int64(), int64(100))
},
},
{