Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
evm: fix keep balance when resetting an account (#353)
Browse files Browse the repository at this point in the history
* keep balance when override account

* Update CHANGELOG.md

Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
  • Loading branch information
yihuang and fedekunze committed Jul 26, 2021
1 parent 30cc004 commit 2828fa1
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 1 addition & 9 deletions x/evm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}
}
4 changes: 2 additions & 2 deletions x/evm/keeper/statedb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
},
},
{
Expand Down

0 comments on commit 2828fa1

Please sign in to comment.