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:
parent
30cc004e76
commit
2828fa1e62
@ -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#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
|
* (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.
|
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
|
### API Breaking
|
||||||
|
|
||||||
|
@ -316,17 +316,9 @@ func (k Keeper) ClearBalance(addr sdk.AccAddress) (prevBalance sdk.Coin, err err
|
|||||||
return prevBalance, nil
|
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.
|
// with the given address.
|
||||||
func (k Keeper) ResetAccount(addr common.Address) {
|
func (k Keeper) ResetAccount(addr common.Address) {
|
||||||
k.DeleteCode(addr)
|
k.DeleteCode(addr)
|
||||||
k.DeleteAccountStorage(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,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -27,14 +27,14 @@ func (suite *KeeperTestSuite) TestCreateAccount() {
|
|||||||
callback func(common.Address)
|
callback func(common.Address)
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"reset account",
|
"reset account (keep balance)",
|
||||||
suite.address,
|
suite.address,
|
||||||
func(addr common.Address) {
|
func(addr common.Address) {
|
||||||
suite.app.EvmKeeper.AddBalance(addr, big.NewInt(100))
|
suite.app.EvmKeeper.AddBalance(addr, big.NewInt(100))
|
||||||
suite.Require().NotZero(suite.app.EvmKeeper.GetBalance(addr).Int64())
|
suite.Require().NotZero(suite.app.EvmKeeper.GetBalance(addr).Int64())
|
||||||
},
|
},
|
||||||
func(addr common.Address) {
|
func(addr common.Address) {
|
||||||
suite.Require().Zero(suite.app.EvmKeeper.GetBalance(addr).Int64())
|
suite.Require().Equal(suite.app.EvmKeeper.GetBalance(addr).Int64(), int64(100))
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user