mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 10:05:18 +00:00
fix(evmutil): create module account on InitGenesis (#1655)
* fix(evmutil): create module account on InitGenesis ensures the creation of the x/evmutil module account on init genesis. * update changelog * cleanup debug logging
This commit is contained in:
parent
2bcfe5c0be
commit
15c243224c
@ -36,6 +36,11 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Bug Fixes
|
||||
- (evmutil) [#1655] Initialize x/evmutil module account in InitGenesis
|
||||
|
||||
## [v0.24.0]
|
||||
|
||||
### Features
|
||||
- (evmutil) [#1590] & [#1596] Add allow list param of sdk native denoms that can be transferred to evm
|
||||
- (evmutil) [#1591] & [#1596] Configure module to support deploying ERC20KavaWrappedCosmosCoin contracts
|
||||
@ -268,6 +273,7 @@ the [changelog](https://github.com/cosmos/cosmos-sdk/blob/v0.38.4/CHANGELOG.md).
|
||||
- [#257](https://github.com/Kava-Labs/kava/pulls/257) Include scripts to run
|
||||
large-scale simulations remotely using aws-batch
|
||||
|
||||
[#1655]: https://github.com/Kava-Labs/kava/pull/1655
|
||||
[#1624]: https://github.com/Kava-Labs/kava/pull/1624
|
||||
[#1622]: https://github.com/Kava-Labs/kava/pull/1622
|
||||
[#1614]: https://github.com/Kava-Labs/kava/pull/1614
|
||||
@ -307,7 +313,8 @@ the [changelog](https://github.com/cosmos/cosmos-sdk/blob/v0.38.4/CHANGELOG.md).
|
||||
[#750]: https://github.com/Kava-Labs/kava/pull/750
|
||||
[#751]: https://github.com/Kava-Labs/kava/pull/751
|
||||
[#780]: https://github.com/Kava-Labs/kava/pull/780
|
||||
[unreleased]: https://github.com/Kava-Labs/kava/compare/v0.23.2...HEAD
|
||||
[unreleased]: https://github.com/Kava-Labs/kava/compare/v0.24.0...HEAD
|
||||
[v0.24.0]: https://github.com/Kava-Labs/kava/compare/v0.24.0...v0.23.2
|
||||
[v0.23.2]: https://github.com/Kava-Labs/kava/compare/v0.23.1...v0.23.2
|
||||
[v0.23.1]: https://github.com/Kava-Labs/kava/compare/v0.23.0...v0.23.1
|
||||
[v0.23.0]: https://github.com/Kava-Labs/kava/compare/v0.21.1...v0.23.0
|
||||
|
@ -782,7 +782,7 @@ func NewApp(
|
||||
hard.NewAppModule(app.hardKeeper, app.accountKeeper, app.bankKeeper, app.pricefeedKeeper),
|
||||
committee.NewAppModule(app.committeeKeeper, app.accountKeeper),
|
||||
incentive.NewAppModule(app.incentiveKeeper, app.accountKeeper, app.bankKeeper, app.cdpKeeper),
|
||||
evmutil.NewAppModule(app.evmutilKeeper, app.bankKeeper),
|
||||
evmutil.NewAppModule(app.evmutilKeeper, app.bankKeeper, app.accountKeeper),
|
||||
savings.NewAppModule(app.savingsKeeper, app.accountKeeper, app.bankKeeper),
|
||||
liquid.NewAppModule(app.liquidKeeper),
|
||||
earn.NewAppModule(app.earnKeeper, app.accountKeeper, app.bankKeeper),
|
||||
|
@ -10,13 +10,18 @@ import (
|
||||
)
|
||||
|
||||
// InitGenesis initializes the store state from a genesis state.
|
||||
func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, gs *types.GenesisState) {
|
||||
func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, gs *types.GenesisState, ak types.AccountKeeper) {
|
||||
if err := gs.Validate(); err != nil {
|
||||
panic(fmt.Sprintf("failed to validate %s genesis state: %s", types.ModuleName, err))
|
||||
}
|
||||
|
||||
keeper.SetParams(ctx, gs.Params)
|
||||
|
||||
// initialize module account
|
||||
if moduleAcc := ak.GetModuleAccount(ctx, types.ModuleName); moduleAcc == nil {
|
||||
panic(fmt.Sprintf("%s module account has not been set", types.ModuleName))
|
||||
}
|
||||
|
||||
for _, account := range gs.Accounts {
|
||||
keeper.SetAccount(ctx, account)
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
"github.com/kava-labs/kava/x/evmutil"
|
||||
"github.com/kava-labs/kava/x/evmutil/testutil"
|
||||
"github.com/kava-labs/kava/x/evmutil/types"
|
||||
@ -28,7 +29,7 @@ func (s *genesisTestSuite) TestInitGenesis_SetAccounts() {
|
||||
)
|
||||
accounts := s.Keeper.GetAllAccounts(s.Ctx)
|
||||
s.Require().Len(accounts, 0)
|
||||
evmutil.InitGenesis(s.Ctx, s.Keeper, gs)
|
||||
evmutil.InitGenesis(s.Ctx, s.Keeper, gs, s.AccountKeeper)
|
||||
accounts = s.Keeper.GetAllAccounts(s.Ctx)
|
||||
s.Require().Len(accounts, 1)
|
||||
account := s.Keeper.GetAccount(s.Ctx, s.Addrs[0])
|
||||
@ -47,7 +48,7 @@ func (s *genesisTestSuite) TestInitGenesis_SetParams() {
|
||||
[]types.Account{},
|
||||
params,
|
||||
)
|
||||
evmutil.InitGenesis(s.Ctx, s.Keeper, gs)
|
||||
evmutil.InitGenesis(s.Ctx, s.Keeper, gs, s.AccountKeeper)
|
||||
params = s.Keeper.GetParams(s.Ctx)
|
||||
s.Require().Len(params.EnabledConversionPairs, 1)
|
||||
s.Require().Equal(conversionPair, params.EnabledConversionPairs[0])
|
||||
@ -61,10 +62,25 @@ func (s *genesisTestSuite) TestInitGenesis_ValidateFail() {
|
||||
types.DefaultParams(),
|
||||
)
|
||||
s.Require().Panics(func() {
|
||||
evmutil.InitGenesis(s.Ctx, s.Keeper, gs)
|
||||
evmutil.InitGenesis(s.Ctx, s.Keeper, gs, s.AccountKeeper)
|
||||
})
|
||||
}
|
||||
|
||||
func (s *genesisTestSuite) TestInitGenesis_ModuleAccount() {
|
||||
gs := types.NewGenesisState(
|
||||
[]types.Account{},
|
||||
types.DefaultParams(),
|
||||
)
|
||||
s.Require().NotPanics(func() {
|
||||
evmutil.InitGenesis(s.Ctx, s.Keeper, gs, s.AccountKeeper)
|
||||
})
|
||||
// check for module account this way b/c GetModuleAccount creates if not existing.
|
||||
acc := s.AccountKeeper.GetAccount(s.Ctx, s.AccountKeeper.GetModuleAddress(types.ModuleName))
|
||||
s.Require().NotNil(acc)
|
||||
_, ok := acc.(authtypes.ModuleAccountI)
|
||||
s.Require().True(ok)
|
||||
}
|
||||
|
||||
func (s *genesisTestSuite) TestExportGenesis() {
|
||||
accounts := []types.Account{
|
||||
{Address: s.Addrs[0], Balance: sdkmath.NewInt(10)},
|
||||
|
@ -184,7 +184,7 @@ func (k Keeper) LockERC20Tokens(
|
||||
contractAddr := pair.GetAddress()
|
||||
initiatorStartBal, err := k.QueryERC20BalanceOf(ctx, contractAddr, initiator)
|
||||
if err != nil {
|
||||
return errorsmod.Wrapf(types.ErrEVMCall, "failed to retrieve balance %s", err.Error())
|
||||
return errorsmod.Wrapf(types.ErrEVMCall, "failed to retrieve balance: %s", err.Error())
|
||||
}
|
||||
|
||||
res, err := k.CallEVM(
|
||||
|
@ -345,7 +345,7 @@ func (suite *ConversionTestSuite) TestConvertERC20ToCoin_EmptyContract() {
|
||||
convertAmt,
|
||||
)
|
||||
suite.Require().Error(err)
|
||||
suite.Require().ErrorContains(err, "contract call failed: method 'balanceOf'")
|
||||
suite.Require().ErrorContains(err, "failed to retrieve balance: failed to unpack method balanceOf")
|
||||
|
||||
// bank balance should not change
|
||||
bal := suite.App.GetBankKeeper().GetBalance(suite.Ctx, userAddr, pair.Denom)
|
||||
|
@ -236,6 +236,10 @@ func unpackERC20ResToBigInt(res *evmtypes.MsgEthereumTxResponse, methodName stri
|
||||
return nil, status.Error(codes.Internal, res.VmError)
|
||||
}
|
||||
|
||||
if len(res.Ret) == 0 {
|
||||
return nil, fmt.Errorf("failed to unpack method %s: expected response to be big.Int but found nil", methodName)
|
||||
}
|
||||
|
||||
anyOutput, err := types.ERC20MintableBurnableContract.ABI.Unpack(methodName, res.Ret)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(
|
||||
|
@ -95,15 +95,17 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command {
|
||||
type AppModule struct {
|
||||
AppModuleBasic
|
||||
|
||||
keeper keeper.Keeper
|
||||
bankKeeper types.BankKeeper
|
||||
keeper keeper.Keeper
|
||||
accountKeeer types.AccountKeeper
|
||||
bankKeeper types.BankKeeper
|
||||
}
|
||||
|
||||
// NewAppModule creates a new AppModule object
|
||||
func NewAppModule(keeper keeper.Keeper, bankKeeper types.BankKeeper) AppModule {
|
||||
func NewAppModule(keeper keeper.Keeper, bankKeeper types.BankKeeper, accountKeeper types.AccountKeeper) AppModule {
|
||||
return AppModule{
|
||||
AppModuleBasic: NewAppModuleBasic(),
|
||||
keeper: keeper,
|
||||
accountKeeer: accountKeeper,
|
||||
bankKeeper: bankKeeper,
|
||||
}
|
||||
}
|
||||
@ -146,7 +148,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.Ra
|
||||
// Initialize global index to index in genesis state
|
||||
cdc.MustUnmarshalJSON(gs, &genState)
|
||||
|
||||
InitGenesis(ctx, am.keeper, &genState)
|
||||
InitGenesis(ctx, am.keeper, &genState, am.accountKeeer)
|
||||
return []abci.ValidatorUpdate{}
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/core/vm"
|
||||
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
||||
@ -11,6 +12,7 @@ import (
|
||||
|
||||
// AccountKeeper defines the expected account keeper interface
|
||||
type AccountKeeper interface {
|
||||
GetModuleAccount(ctx sdk.Context, moduleName string) authtypes.ModuleAccountI
|
||||
GetModuleAddress(moduleName string) sdk.AccAddress
|
||||
GetSequence(sdk.Context, sdk.AccAddress) (uint64, error)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user