From b06d4e1627487cf55917266b9389f95d27f149bd Mon Sep 17 00:00:00 2001 From: Lockwarr Date: Thu, 9 May 2024 15:30:57 +0300 Subject: [PATCH 1/6] fix: use basicmodulemanager as recommended in sdk-50 upgrade guide --- app/app.go | 134 +++++++++++------- app/encoding.go | 2 - app/genesis.go | 6 +- app/params/encoding.go | 5 + cmd/neutrond/root.go | 19 +-- testutil/contractmanager/network/network.go | 25 +++- testutil/cron/network/network.go | 27 +++- testutil/interchainqueries/network/network.go | 25 +++- testutil/interchaintxs/network/network.go | 25 +++- testutil/test_helpers.go | 3 +- 10 files changed, 184 insertions(+), 87 deletions(-) diff --git a/app/app.go b/app/app.go index c72f39e08..f54bf6535 100644 --- a/app/app.go +++ b/app/app.go @@ -45,9 +45,6 @@ import ( wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" "github.com/cosmos/cosmos-sdk/runtime" - "github.com/cosmos/cosmos-sdk/x/genutil" - genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" - tendermint "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" "github.com/neutron-org/neutron/v4/docs" @@ -99,6 +96,9 @@ import ( "github.com/cosmos/cosmos-sdk/x/crisis" crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper" crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" + "github.com/cosmos/cosmos-sdk/x/genutil" + genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" + govclient "github.com/cosmos/cosmos-sdk/x/gov/client" "github.com/cosmos/cosmos-sdk/x/params" paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" @@ -142,7 +142,6 @@ import ( adminmodulecli "github.com/cosmos/admin-module/x/adminmodule/client/cli" adminmodulekeeper "github.com/cosmos/admin-module/x/adminmodule/keeper" adminmoduletypes "github.com/cosmos/admin-module/x/adminmodule/types" - govclient "github.com/cosmos/cosmos-sdk/x/gov/client" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" appparams "github.com/neutron-org/neutron/v4/app/params" @@ -220,52 +219,52 @@ var ( // ModuleBasics defines the module BasicManager is in charge of setting up basic, // non-dependant module elements, such as codec registration // and genesis verification. - ModuleBasics = module.NewBasicManager( - auth.AppModuleBasic{}, - authzmodule.AppModuleBasic{}, - bank.AppModuleBasic{}, - capability.AppModuleBasic{}, - genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator), - params.AppModuleBasic{}, - crisis.AppModuleBasic{}, - slashing.AppModuleBasic{}, - feegrantmodule.AppModuleBasic{}, - ibc.AppModuleBasic{}, - ica.AppModuleBasic{}, - tendermint.AppModuleBasic{}, - upgrade.AppModuleBasic{}, - evidence.AppModuleBasic{}, - transferSudo.AppModuleBasic{}, - vesting.AppModuleBasic{}, - ccvconsumer.AppModuleBasic{}, - wasm.AppModuleBasic{}, - tokenfactory.AppModuleBasic{}, - interchainqueries.AppModuleBasic{}, - interchaintxs.AppModuleBasic{}, - feerefunder.AppModuleBasic{}, - feeburner.AppModuleBasic{}, - contractmanager.AppModuleBasic{}, - cron.AppModuleBasic{}, - adminmodule.NewAppModuleBasic( - govclient.NewProposalHandler( - adminmodulecli.NewSubmitParamChangeProposalTxCmd, - ), - govclient.NewProposalHandler( - adminmodulecli.NewCmdSubmitUpgradeProposal, - ), - govclient.NewProposalHandler( - adminmodulecli.NewCmdSubmitCancelUpgradeProposal, - ), - ), - ibchooks.AppModuleBasic{}, - packetforward.AppModuleBasic{}, - auction.AppModuleBasic{}, - globalfee.AppModule{}, - dex.AppModuleBasic{}, - ibcswap.AppModuleBasic{}, - oracle.AppModuleBasic{}, - marketmap.AppModuleBasic{}, - ) + // ModuleBasics = module.NewBasicManager( + // auth.AppModuleBasic{}, + // authzmodule.AppModuleBasic{}, + // bank.AppModuleBasic{}, + // capability.AppModuleBasic{}, + // genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator), + // params.AppModuleBasic{}, + // crisis.AppModuleBasic{}, + // slashing.AppModuleBasic{}, + // feegrantmodule.AppModuleBasic{}, + // ibc.AppModuleBasic{}, + // ica.AppModuleBasic{}, + // tendermint.AppModuleBasic{}, + // upgrade.AppModuleBasic{}, + // evidence.AppModuleBasic{}, + // transferSudo.AppModuleBasic{}, + // vesting.AppModuleBasic{}, + // ccvconsumer.AppModuleBasic{}, + // wasm.AppModuleBasic{}, + // tokenfactory.AppModuleBasic{}, + // interchainqueries.AppModuleBasic{}, + // interchaintxs.AppModuleBasic{}, + // feerefunder.AppModuleBasic{}, + // feeburner.AppModuleBasic{}, + // contractmanager.AppModuleBasic{}, + // cron.AppModuleBasic{}, + // adminmodule.NewAppModuleBasic( + // govclient.NewProposalHandler( + // adminmodulecli.NewSubmitParamChangeProposalTxCmd, + // ), + // govclient.NewProposalHandler( + // adminmodulecli.NewCmdSubmitUpgradeProposal, + // ), + // govclient.NewProposalHandler( + // adminmodulecli.NewCmdSubmitCancelUpgradeProposal, + // ), + // ), + // ibchooks.AppModuleBasic{}, + // packetforward.AppModuleBasic{}, + // auction.AppModuleBasic{}, + // globalfee.AppModule{}, + // dex.AppModuleBasic{}, + // ibcswap.AppModuleBasic{}, + // oracle.AppModuleBasic{}, + // marketmap.AppModuleBasic{}, + // ) // module account permissions maccPerms = map[string][]string{ @@ -382,7 +381,8 @@ type App struct { oracleClient oracleclient.OracleClient // mm is the module manager - mm *module.Manager + mm *module.Manager + BasicModuleManager module.BasicManager // sm is the simulation manager sm *module.SimulationManager @@ -417,12 +417,12 @@ func New( skipUpgradeHeights map[int64]bool, homePath string, invCheckPeriod uint, - encodingConfig appparams.EncodingConfig, appOpts servertypes.AppOptions, wasmOpts []wasmkeeper.Option, baseAppOptions ...func(*baseapp.BaseApp), ) *App { overrideWasmVariables() + encodingConfig := MakeEncodingConfig() appCodec := encodingConfig.Marshaler legacyAmino := encodingConfig.Amino @@ -919,6 +919,34 @@ func New( crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)), ) + // BasicModuleManager defines the module BasicManager is in charge of setting up basic, + // non-dependant module elements, such as codec registration and genesis verification. + // By default it is composed of all the module from the module manager. + // Additionally, app module basics can be overwritten by passing them as argument. + app.BasicModuleManager = module.NewBasicManagerFromManager( + app.mm, + map[string]module.AppModuleBasic{ + genutiltypes.ModuleName: genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator), + adminmoduletypes.ModuleName: adminmodule.NewAppModuleBasic( + govclient.NewProposalHandler( + adminmodulecli.NewSubmitParamChangeProposalTxCmd, + ), + govclient.NewProposalHandler( + adminmodulecli.NewCmdSubmitUpgradeProposal, + ), + govclient.NewProposalHandler( + adminmodulecli.NewCmdSubmitCancelUpgradeProposal, + ), + ), + }, + ) + app.BasicModuleManager.RegisterLegacyAminoCodec(encodingConfig.Amino) + app.BasicModuleManager.RegisterInterfaces(encodingConfig.InterfaceRegistry) + + app.mm.SetOrderPreBlockers( + upgradetypes.ModuleName, + ) + // During begin block slashing happens after distr.BeginBlocker so that // there is nothing left over in the validator feerefunder pool to keep the // CanWithdrawInvariant invariant. @@ -1509,7 +1537,7 @@ func (app *App) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig // Register new tendermint queries routes from grpc-gateway. cmtservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter) - ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter) + app.BasicModuleManager.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter) // Register app's swagger ui if apiConfig.Swagger { diff --git a/app/encoding.go b/app/encoding.go index 7ff2d3085..7b81f932f 100644 --- a/app/encoding.go +++ b/app/encoding.go @@ -11,7 +11,5 @@ func MakeEncodingConfig() params.EncodingConfig { encodingConfig := params.MakeEncodingConfig() std.RegisterLegacyAminoCodec(encodingConfig.Amino) std.RegisterInterfaces(encodingConfig.InterfaceRegistry) - ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino) - ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry) return encodingConfig } diff --git a/app/genesis.go b/app/genesis.go index 6397a5f64..38b43c7eb 100644 --- a/app/genesis.go +++ b/app/genesis.go @@ -2,8 +2,6 @@ package app import ( "encoding/json" - - "github.com/cosmos/cosmos-sdk/codec" ) // GenesisState is the genesis state of the blockchain represented here as a map of raw json @@ -16,13 +14,13 @@ import ( type GenesisState map[string]json.RawMessage // NewDefaultGenesisState generates the default state for the application. -func NewDefaultGenesisState(cdc codec.JSONCodec) GenesisState { +func (app *App) NewDefaultGenesisState() GenesisState { // This ugly hack is required to alter globalfee module genesis state // because in current chain implementation staking module is absent which is required by globalfee module // and we can't use default genesis state for globalfee module. // If we do not alter globalfee module genesis state, then we will get panic during tests run. - genesisState := ModuleBasics.DefaultGenesis(cdc) + genesisState := app.BasicModuleManager.DefaultGenesis(app.appCodec) // globalFeeGenesisState := globalfeetypes.GenesisState{ // Params: globalfeetypes.Params{ // MinimumGasPrices: sdk.DecCoins{ diff --git a/app/params/encoding.go b/app/params/encoding.go index 066043d42..75eaba1fd 100644 --- a/app/params/encoding.go +++ b/app/params/encoding.go @@ -37,6 +37,11 @@ func MakeEncodingConfig() EncodingConfig { if err != nil { panic(err) } + + if err := reg.SigningContext().Validate(); err != nil { + panic(err) + } + marshaler := codec.NewProtoCodec(reg) txCfg := tx.NewTxConfig(marshaler, tx.DefaultSignModes) diff --git a/cmd/neutrond/root.go b/cmd/neutrond/root.go index 6c8cd3651..2a6a64dad 100644 --- a/cmd/neutrond/root.go +++ b/cmd/neutrond/root.go @@ -29,6 +29,7 @@ import ( serverconfig "github.com/cosmos/cosmos-sdk/server/config" servertypes "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/testutil/sims" + "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/version" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -62,7 +63,6 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) { map[int64]bool{}, app.DefaultNodeHome, 0, - encodingConfig, sims.NewAppOptionsWithFlagHome(app.DefaultNodeHome), nil, ) @@ -109,7 +109,7 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) { }, } - initRootCmd(rootCmd, encodingConfig) + initRootCmd(rootCmd, encodingConfig, tempApp.BasicModuleManager) autoCliOpts := tempApp.AutoCliOpts() initClientCtx, _ = config.ReadFromClientConfig(initClientCtx) @@ -129,16 +129,19 @@ func initAppConfig() (string, interface{}) { return serverconfig.DefaultConfigTemplate, srvCfg } -func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) { +func initRootCmd(rootCmd *cobra.Command, + encodingConfig params.EncodingConfig, + moduleBasics module.BasicManager, +) { debugCmd := debug.Cmd() debugCmd.AddCommand(genContractAddressCmd()) - gentxModule := app.ModuleBasics[genutiltypes.ModuleName].(genutil.AppModuleBasic) + gentxModule := moduleBasics[genutiltypes.ModuleName].(genutil.AppModuleBasic) rootCmd.AddCommand( - genutilcli.InitCmd(app.ModuleBasics, app.DefaultNodeHome), + genutilcli.InitCmd(moduleBasics, app.DefaultNodeHome), genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome, gentxModule.GenTxValidator, encodingConfig.TxConfig.SigningContext().ValidatorAddressCodec()), - genutilcli.GenTxCmd(app.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome, encodingConfig.TxConfig.SigningContext().ValidatorAddressCodec()), - genutilcli.ValidateGenesisCmd(app.ModuleBasics), + genutilcli.GenTxCmd(moduleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome, encodingConfig.TxConfig.SigningContext().ValidatorAddressCodec()), + genutilcli.ValidateGenesisCmd(moduleBasics), AddGenesisAccountCmd(app.DefaultNodeHome), addGenesisWasmMsgCmd(app.DefaultNodeHome), tmcli.NewCompletionCmd(rootCmd, true), @@ -274,7 +277,6 @@ func (ac appCreator) newApp( return app.New(logger, db, traceStore, true, skipUpgradeHeights, cast.ToString(appOpts.Get(flags.FlagHome)), cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)), - ac.encCfg, appOpts, wasmOpts, baseapp.SetPruning(pruningOpts), @@ -316,7 +318,6 @@ func (ac appCreator) appExport( map[int64]bool{}, homePath, cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)), - ac.encCfg, appOpts, emptyWasmOpts, ) diff --git a/testutil/contractmanager/network/network.go b/testutil/contractmanager/network/network.go index 914c654ce..5ec38fbe7 100644 --- a/testutil/contractmanager/network/network.go +++ b/testutil/contractmanager/network/network.go @@ -8,6 +8,7 @@ import ( db "github.com/cosmos/cosmos-db" "github.com/stretchr/testify/require" + "cosmossdk.io/log" pruningtypes "cosmossdk.io/store/pruning/types" tmrand "github.com/cometbft/cometbft/libs/rand" "github.com/cosmos/cosmos-sdk/baseapp" @@ -55,9 +56,26 @@ func New(t *testing.T, configs ...network.Config) *network.Network { // DefaultConfig will initialize config for the network with custom application, // genesis and single validator. All other parameters are inherited from cosmos-sdk/testutil/network.DefaultConfig func DefaultConfig() network.Config { + memoryDB := db.NewMemDB() + + // TODO: move to depinject + // we "pre"-instantiate the application for getting the injected/configured encoding configuration + // note, this is not necessary when using app wiring, as depinject can be directly used + tempApp := app.New( + log.NewNopLogger(), + memoryDB, + nil, + false, + map[int64]bool{}, + app.DefaultNodeHome, + 0, + sims.NewAppOptionsWithFlagHome(app.DefaultNodeHome), + nil, + ) + // app doesn't have these modules anymore, but we need them for test setup, which uses gentx and MsgCreateValidator - app.ModuleBasics[genutiltypes.ModuleName] = genutil.AppModuleBasic{} - app.ModuleBasics[stakingtypes.ModuleName] = staking.AppModuleBasic{} + tempApp.BasicModuleManager[genutiltypes.ModuleName] = genutil.AppModuleBasic{} + tempApp.BasicModuleManager[stakingtypes.ModuleName] = staking.AppModuleBasic{} encoding := app.MakeEncodingConfig() chainID := "chain-" + tmrand.NewRand().Str(6) @@ -79,7 +97,6 @@ func DefaultConfig() network.Config { return app.New( val.GetCtx().Logger, db.NewMemDB(), nil, true, map[int64]bool{}, val.GetCtx().Config.RootDir, 0, - encoding, sims.EmptyAppOptions{}, nil, baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.GetAppConfig().Pruning)), @@ -87,7 +104,7 @@ func DefaultConfig() network.Config { baseapp.SetChainID(chainID), ) }, - GenesisState: app.ModuleBasics.DefaultGenesis(encoding.Marshaler), + GenesisState: tempApp.BasicModuleManager.DefaultGenesis(encoding.Marshaler), TimeoutCommit: 2 * time.Second, ChainID: chainID, // Some changes are introduced to make the tests run as if neutron is a standalone chain. diff --git a/testutil/cron/network/network.go b/testutil/cron/network/network.go index 7a419741e..b19121026 100644 --- a/testutil/cron/network/network.go +++ b/testutil/cron/network/network.go @@ -7,6 +7,7 @@ import ( "github.com/neutron-org/neutron/v4/app/config" + "cosmossdk.io/log" pruningtypes "cosmossdk.io/store/pruning/types" db "github.com/cosmos/cosmos-db" "github.com/stretchr/testify/require" @@ -63,9 +64,26 @@ func New(t *testing.T, configs ...network.Config) *network.Network { // DefaultConfig will initialize config for the network with custom application, // genesis and single validator. All other parameters are inherited from cosmos-sdk/testutil/network.DefaultConfig func DefaultConfig() network.Config { - // app doesn't have this modules anymore, but we need them for test setup, which uses gentx and MsgCreateValidator - app.ModuleBasics[genutiltypes.ModuleName] = genutil.AppModuleBasic{} - app.ModuleBasics[stakingtypes.ModuleName] = staking.AppModuleBasic{} + memoryDB := db.NewMemDB() + + // TODO: move to depinject + // we "pre"-instantiate the application for getting the injected/configured encoding configuration + // note, this is not necessary when using app wiring, as depinject can be directly used + tempApp := app.New( + log.NewNopLogger(), + memoryDB, + nil, + false, + map[int64]bool{}, + app.DefaultNodeHome, + 0, + sims.NewAppOptionsWithFlagHome(app.DefaultNodeHome), + nil, + ) + + // app doesn't have these modules anymore, but we need them for test setup, which uses gentx and MsgCreateValidator + tempApp.BasicModuleManager[genutiltypes.ModuleName] = genutil.AppModuleBasic{} + tempApp.BasicModuleManager[stakingtypes.ModuleName] = staking.AppModuleBasic{} encoding := app.MakeEncodingConfig() chainID := "chain-" + tmrand.NewRand().Str(6) @@ -87,7 +105,6 @@ func DefaultConfig() network.Config { return app.New( val.GetCtx().Logger, db.NewMemDB(), nil, true, map[int64]bool{}, val.GetCtx().Config.RootDir, 0, - encoding, sims.EmptyAppOptions{}, nil, baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.GetAppConfig().Pruning)), @@ -95,7 +112,7 @@ func DefaultConfig() network.Config { baseapp.SetChainID(chainID), ) }, - GenesisState: app.ModuleBasics.DefaultGenesis(encoding.Marshaler), + GenesisState: tempApp.BasicModuleManager.DefaultGenesis(encoding.Marshaler), TimeoutCommit: 2 * time.Second, ChainID: chainID, // Some changes are introduced to make the tests run as if neutron is a standalone chain. diff --git a/testutil/interchainqueries/network/network.go b/testutil/interchainqueries/network/network.go index de29f6782..1ac780187 100644 --- a/testutil/interchainqueries/network/network.go +++ b/testutil/interchainqueries/network/network.go @@ -5,6 +5,7 @@ import ( "testing" "time" + "cosmossdk.io/log" pruningtypes "cosmossdk.io/store/pruning/types" db "github.com/cosmos/cosmos-db" "github.com/stretchr/testify/require" @@ -55,9 +56,26 @@ func New(t *testing.T, configs ...network.Config) *network.Network { // DefaultConfig will initialize config for the network with custom application, // genesis and single validator. All other parameters are inherited from cosmos-sdk/testutil/network.DefaultConfig func DefaultConfig() network.Config { + memoryDB := db.NewMemDB() + + // TODO: move to depinject + // we "pre"-instantiate the application for getting the injected/configured encoding configuration + // note, this is not necessary when using app wiring, as depinject can be directly used + tempApp := app.New( + log.NewNopLogger(), + memoryDB, + nil, + false, + map[int64]bool{}, + app.DefaultNodeHome, + 0, + sims.NewAppOptionsWithFlagHome(app.DefaultNodeHome), + nil, + ) + // app doesn't have these modules anymore, but we need them for test setup, which uses gentx and MsgCreateValidator - app.ModuleBasics[genutiltypes.ModuleName] = genutil.AppModuleBasic{} - app.ModuleBasics[stakingtypes.ModuleName] = staking.AppModuleBasic{} + tempApp.BasicModuleManager[genutiltypes.ModuleName] = genutil.AppModuleBasic{} + tempApp.BasicModuleManager[stakingtypes.ModuleName] = staking.AppModuleBasic{} encoding := app.MakeEncodingConfig() chainID := "chain-" + tmrand.NewRand().Str(6) @@ -75,7 +93,6 @@ func DefaultConfig() network.Config { return app.New( val.GetCtx().Logger, db.NewMemDB(), nil, true, map[int64]bool{}, val.GetCtx().Config.RootDir, 0, - encoding, sims.EmptyAppOptions{}, nil, baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.GetAppConfig().Pruning)), @@ -83,7 +100,7 @@ func DefaultConfig() network.Config { baseapp.SetChainID(chainID), ) }, - GenesisState: app.ModuleBasics.DefaultGenesis(encoding.Marshaler), + GenesisState: tempApp.BasicModuleManager.DefaultGenesis(encoding.Marshaler), TimeoutCommit: 2 * time.Second, ChainID: chainID, // Some changes are introduced to make the tests run as if neutron is a standalone chain. diff --git a/testutil/interchaintxs/network/network.go b/testutil/interchaintxs/network/network.go index f8fe9393d..f052b09b6 100644 --- a/testutil/interchaintxs/network/network.go +++ b/testutil/interchaintxs/network/network.go @@ -5,6 +5,7 @@ import ( "testing" "time" + "cosmossdk.io/log" pruningtypes "cosmossdk.io/store/pruning/types" db "github.com/cosmos/cosmos-db" "github.com/stretchr/testify/require" @@ -56,9 +57,26 @@ func New(t *testing.T, configs ...network.Config) *network.Network { // DefaultConfig will initialize config for the network with custom application, // genesis and single validator. All other parameters are inherited from cosmos-sdk/testutil/network.DefaultConfig func DefaultConfig() network.Config { + memoryDB := db.NewMemDB() + + // TODO: move to depinject + // we "pre"-instantiate the application for getting the injected/configured encoding configuration + // note, this is not necessary when using app wiring, as depinject can be directly used + tempApp := app.New( + log.NewNopLogger(), + memoryDB, + nil, + false, + map[int64]bool{}, + app.DefaultNodeHome, + 0, + sims.NewAppOptionsWithFlagHome(app.DefaultNodeHome), + nil, + ) + // app doesn't have these modules anymore, but we need them for test setup, which uses gentx and MsgCreateValidator - app.ModuleBasics[genutiltypes.ModuleName] = genutil.AppModuleBasic{} - app.ModuleBasics[stakingtypes.ModuleName] = staking.AppModuleBasic{} + tempApp.BasicModuleManager[genutiltypes.ModuleName] = genutil.AppModuleBasic{} + tempApp.BasicModuleManager[stakingtypes.ModuleName] = staking.AppModuleBasic{} encoding := app.MakeEncodingConfig() chainID := "chain-" + tmrand.NewRand().Str(6) @@ -80,7 +98,6 @@ func DefaultConfig() network.Config { return app.New( val.GetCtx().Logger, db.NewMemDB(), nil, true, map[int64]bool{}, val.GetCtx().Config.RootDir, 0, - encoding, sims.EmptyAppOptions{}, nil, baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.GetAppConfig().Pruning)), @@ -88,7 +105,7 @@ func DefaultConfig() network.Config { baseapp.SetChainID(chainID), ) }, - GenesisState: app.ModuleBasics.DefaultGenesis(encoding.Marshaler), + GenesisState: tempApp.BasicModuleManager.DefaultGenesis(encoding.Marshaler), TimeoutCommit: 2 * time.Second, ChainID: chainID, // Some changes are introduced to make the tests run as if neutron is a standalone chain. diff --git a/testutil/test_helpers.go b/testutil/test_helpers.go index f8323d80a..fa2dc32db 100644 --- a/testutil/test_helpers.go +++ b/testutil/test_helpers.go @@ -427,7 +427,6 @@ func SetupTestingApp(initValUpdates []cometbfttypes.ValidatorUpdate) func() (ibc map[int64]bool{}, homePath, 0, - encoding, sims.EmptyAppOptions{}, nil, ) @@ -437,7 +436,7 @@ func SetupTestingApp(initValUpdates []cometbfttypes.ValidatorUpdate) func() (ibc // and then we manually init baseapp and load states testApp.LoadLatest() - genesisState := app.NewDefaultGenesisState(testApp.AppCodec()) + genesisState := testApp.NewDefaultGenesisState() // TODO: why isn't it in the `testApp.TestInitChainer`? // NOTE ibc-go/v7/testing.SetupWithGenesisValSet requires a staking module From c0447c0b8566eef047c2284812606777fcc975ba Mon Sep 17 00:00:00 2001 From: Lockwarr Date: Fri, 10 May 2024 09:25:02 +0300 Subject: [PATCH 2/6] fix: register custom app module basics for transfer module --- app/app.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/app.go b/app/app.go index f54bf6535..2cd6bbe35 100644 --- a/app/app.go +++ b/app/app.go @@ -127,6 +127,7 @@ import ( ibchost "github.com/cosmos/ibc-go/v8/modules/core/exported" ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper" ibctesting "github.com/cosmos/ibc-go/v8/testing" + "github.com/spf13/cast" govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" @@ -938,6 +939,8 @@ func New( adminmodulecli.NewCmdSubmitCancelUpgradeProposal, ), ), + // Manually register the transfer module since we dont use a native ibc-go transfer module but a custom implementation + ibctransfertypes.ModuleName: transferSudo.AppModuleBasic{}, }, ) app.BasicModuleManager.RegisterLegacyAminoCodec(encodingConfig.Amino) From f0ad333b39203915a18a708b0670bd8c9a3c503b Mon Sep 17 00:00:00 2001 From: swelf Date: Mon, 1 Jul 2024 22:36:41 +0300 Subject: [PATCH 3/6] fixed tests --- app/app.go | 13 ++----------- testutil/contractmanager/network/network.go | 9 +++++---- testutil/cron/network/network.go | 7 ++++--- testutil/interchainqueries/network/network.go | 7 ++++--- testutil/interchaintxs/network/network.go | 7 ++++--- 5 files changed, 19 insertions(+), 24 deletions(-) diff --git a/app/app.go b/app/app.go index 2cd6bbe35..095554be1 100644 --- a/app/app.go +++ b/app/app.go @@ -3,6 +3,7 @@ package app import ( "context" "fmt" + tendermint "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" "io" "io/fs" "net/http" @@ -246,17 +247,6 @@ var ( // feeburner.AppModuleBasic{}, // contractmanager.AppModuleBasic{}, // cron.AppModuleBasic{}, - // adminmodule.NewAppModuleBasic( - // govclient.NewProposalHandler( - // adminmodulecli.NewSubmitParamChangeProposalTxCmd, - // ), - // govclient.NewProposalHandler( - // adminmodulecli.NewCmdSubmitUpgradeProposal, - // ), - // govclient.NewProposalHandler( - // adminmodulecli.NewCmdSubmitCancelUpgradeProposal, - // ), - // ), // ibchooks.AppModuleBasic{}, // packetforward.AppModuleBasic{}, // auction.AppModuleBasic{}, @@ -897,6 +887,7 @@ func New( evidence.NewAppModule(app.EvidenceKeeper), ibc.NewAppModule(app.IBCKeeper), params.NewAppModule(app.ParamsKeeper), + tendermint.NewAppModule(), transferModule, consumerModule, icaModule, diff --git a/testutil/contractmanager/network/network.go b/testutil/contractmanager/network/network.go index 5ec38fbe7..05549e673 100644 --- a/testutil/contractmanager/network/network.go +++ b/testutil/contractmanager/network/network.go @@ -2,6 +2,7 @@ package network import ( "fmt" + "github.com/cosmos/cosmos-sdk/baseapp" "testing" "time" @@ -11,7 +12,6 @@ import ( "cosmossdk.io/log" pruningtypes "cosmossdk.io/store/pruning/types" tmrand "github.com/cometbft/cometbft/libs/rand" - "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" servertypes "github.com/cosmos/cosmos-sdk/server/types" @@ -72,12 +72,13 @@ func DefaultConfig() network.Config { sims.NewAppOptionsWithFlagHome(app.DefaultNodeHome), nil, ) + encoding := app.MakeEncodingConfig() // app doesn't have these modules anymore, but we need them for test setup, which uses gentx and MsgCreateValidator - tempApp.BasicModuleManager[genutiltypes.ModuleName] = genutil.AppModuleBasic{} - tempApp.BasicModuleManager[stakingtypes.ModuleName] = staking.AppModuleBasic{} + tempApp.BasicModuleManager[genutiltypes.ModuleName] = genutil.AppModule{} + tempApp.BasicModuleManager[stakingtypes.ModuleName] = staking.AppModule{} + tempApp.BasicModuleManager.RegisterInterfaces(encoding.InterfaceRegistry) - encoding := app.MakeEncodingConfig() chainID := "chain-" + tmrand.NewRand().Str(6) return network.Config{ Codec: encoding.Marshaler, diff --git a/testutil/cron/network/network.go b/testutil/cron/network/network.go index b19121026..a3a067179 100644 --- a/testutil/cron/network/network.go +++ b/testutil/cron/network/network.go @@ -80,12 +80,13 @@ func DefaultConfig() network.Config { sims.NewAppOptionsWithFlagHome(app.DefaultNodeHome), nil, ) + encoding := app.MakeEncodingConfig() // app doesn't have these modules anymore, but we need them for test setup, which uses gentx and MsgCreateValidator - tempApp.BasicModuleManager[genutiltypes.ModuleName] = genutil.AppModuleBasic{} - tempApp.BasicModuleManager[stakingtypes.ModuleName] = staking.AppModuleBasic{} + tempApp.BasicModuleManager[genutiltypes.ModuleName] = genutil.AppModule{} + tempApp.BasicModuleManager[stakingtypes.ModuleName] = staking.AppModule{} + tempApp.BasicModuleManager.RegisterInterfaces(encoding.InterfaceRegistry) - encoding := app.MakeEncodingConfig() chainID := "chain-" + tmrand.NewRand().Str(6) return network.Config{ Codec: encoding.Marshaler, diff --git a/testutil/interchainqueries/network/network.go b/testutil/interchainqueries/network/network.go index 1ac780187..a740d86b2 100644 --- a/testutil/interchainqueries/network/network.go +++ b/testutil/interchainqueries/network/network.go @@ -72,12 +72,13 @@ func DefaultConfig() network.Config { sims.NewAppOptionsWithFlagHome(app.DefaultNodeHome), nil, ) + encoding := app.MakeEncodingConfig() // app doesn't have these modules anymore, but we need them for test setup, which uses gentx and MsgCreateValidator - tempApp.BasicModuleManager[genutiltypes.ModuleName] = genutil.AppModuleBasic{} - tempApp.BasicModuleManager[stakingtypes.ModuleName] = staking.AppModuleBasic{} + tempApp.BasicModuleManager[genutiltypes.ModuleName] = genutil.AppModule{} + tempApp.BasicModuleManager[stakingtypes.ModuleName] = staking.AppModule{} + tempApp.BasicModuleManager.RegisterInterfaces(encoding.InterfaceRegistry) - encoding := app.MakeEncodingConfig() chainID := "chain-" + tmrand.NewRand().Str(6) return network.Config{ Codec: encoding.Marshaler, diff --git a/testutil/interchaintxs/network/network.go b/testutil/interchaintxs/network/network.go index f052b09b6..b36ff7f81 100644 --- a/testutil/interchaintxs/network/network.go +++ b/testutil/interchaintxs/network/network.go @@ -73,12 +73,13 @@ func DefaultConfig() network.Config { sims.NewAppOptionsWithFlagHome(app.DefaultNodeHome), nil, ) + encoding := app.MakeEncodingConfig() // app doesn't have these modules anymore, but we need them for test setup, which uses gentx and MsgCreateValidator - tempApp.BasicModuleManager[genutiltypes.ModuleName] = genutil.AppModuleBasic{} - tempApp.BasicModuleManager[stakingtypes.ModuleName] = staking.AppModuleBasic{} + tempApp.BasicModuleManager[genutiltypes.ModuleName] = genutil.AppModule{} + tempApp.BasicModuleManager[stakingtypes.ModuleName] = staking.AppModule{} + tempApp.BasicModuleManager.RegisterInterfaces(encoding.InterfaceRegistry) - encoding := app.MakeEncodingConfig() chainID := "chain-" + tmrand.NewRand().Str(6) return network.Config{ Codec: encoding.Marshaler, From d2f25d2ed3aef52f266e48ca2dacf2ab8f317262 Mon Sep 17 00:00:00 2001 From: swelf Date: Tue, 2 Jul 2024 13:25:15 +0300 Subject: [PATCH 4/6] removed commented code --- app/app.go | 39 --------------------------------------- 1 file changed, 39 deletions(-) diff --git a/app/app.go b/app/app.go index 4efcd10fd..90362516c 100644 --- a/app/app.go +++ b/app/app.go @@ -231,45 +231,6 @@ var ( // DefaultNodeHome default home directories for the application daemon DefaultNodeHome string - // ModuleBasics defines the module BasicManager is in charge of setting up basic, - // non-dependant module elements, such as codec registration - // and genesis verification. - // ModuleBasics = module.NewBasicManager( - // auth.AppModuleBasic{}, - // authzmodule.AppModuleBasic{}, - // bank.AppModuleBasic{}, - // capability.AppModuleBasic{}, - // genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator), - // params.AppModuleBasic{}, - // crisis.AppModuleBasic{}, - // slashing.AppModuleBasic{}, - // feegrantmodule.AppModuleBasic{}, - // ibc.AppModuleBasic{}, - // ica.AppModuleBasic{}, - // tendermint.AppModuleBasic{}, - // upgrade.AppModuleBasic{}, - // evidence.AppModuleBasic{}, - // transferSudo.AppModuleBasic{}, - // vesting.AppModuleBasic{}, - // ccvconsumer.AppModuleBasic{}, - // wasm.AppModuleBasic{}, - // tokenfactory.AppModuleBasic{}, - // interchainqueries.AppModuleBasic{}, - // interchaintxs.AppModuleBasic{}, - // feerefunder.AppModuleBasic{}, - // feeburner.AppModuleBasic{}, - // contractmanager.AppModuleBasic{}, - // cron.AppModuleBasic{}, - // ibchooks.AppModuleBasic{}, - // packetforward.AppModuleBasic{}, - // auction.AppModuleBasic{}, - // globalfee.AppModule{}, - // dex.AppModuleBasic{}, - // ibcswap.AppModuleBasic{}, - // oracle.AppModuleBasic{}, - // marketmap.AppModuleBasic{}, - // ) - // module account permissions maccPerms = map[string][]string{ authtypes.FeeCollectorName: nil, From 1028a94e796aaad11f95e26a19ec9c48d7975af7 Mon Sep 17 00:00:00 2001 From: swelf Date: Tue, 2 Jul 2024 21:47:54 +0300 Subject: [PATCH 5/6] fixed tests --- app/app.go | 10 +++++++ cmd/neutrond/root.go | 8 ++++-- testutil/contractmanager/network/network.go | 22 +++++++++------ testutil/cron/network/network.go | 18 ++++++++---- testutil/interchainqueries/network/network.go | 18 ++++++++---- testutil/interchaintxs/network/network.go | 18 ++++++++---- testutil/test_helpers.go | 28 +++++++++++++++++++ 7 files changed, 93 insertions(+), 29 deletions(-) diff --git a/app/app.go b/app/app.go index 90362516c..2daceff3a 100644 --- a/app/app.go +++ b/app/app.go @@ -926,6 +926,7 @@ func New( marketmapModule, oracleModule, auction.NewAppModule(appCodec, app.AuctionKeeper), + genutil.NewAppModule(app.AccountKeeper, app.ConsumerKeeper, app, encodingConfig.TxConfig), // always be last to make sure that it checks for all invariants and not only part of them crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)), ) @@ -1076,6 +1077,7 @@ func New( ibcswaptypes.ModuleName, dextypes.ModuleName, dynamicfeestypes.ModuleName, + genutiltypes.ModuleName, ) app.mm.RegisterInvariants(&app.CrisisKeeper) @@ -1531,6 +1533,14 @@ func (app *App) AppCodec() codec.Codec { return app.appCodec } +func (app *App) InterfaceRegistry() types.InterfaceRegistry { + return app.interfaceRegistry +} + +func (app *App) GetConfigurator() module.Configurator { + return app.configurator +} + // GetKey returns the KVStoreKey for the provided store key. // // NOTE: This is solely to be used for testing purposes. diff --git a/cmd/neutrond/root.go b/cmd/neutrond/root.go index 8ed030f5c..d23060cfb 100644 --- a/cmd/neutrond/root.go +++ b/cmd/neutrond/root.go @@ -49,8 +49,6 @@ import ( // NewRootCmd creates a new root command for neutrond. It is called once in the // main function. func NewRootCmd() (*cobra.Command, params.EncodingConfig) { - encodingConfig := app.MakeEncodingConfig() - // create a temporary application for use in constructing query + tx commands initAppOptions := viper.New() tempDir := tempDir() @@ -66,6 +64,12 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) { sims.NewAppOptionsWithFlagHome(app.DefaultNodeHome), nil, ) + encodingConfig := params.EncodingConfig{ + InterfaceRegistry: tempApplication.InterfaceRegistry(), + Marshaler: tempApplication.AppCodec(), + TxConfig: tempApplication.GetTxConfig(), + Amino: tempApplication.LegacyAmino(), + } defer func() { if err := tempApplication.Close(); err != nil { panic(err) diff --git a/testutil/contractmanager/network/network.go b/testutil/contractmanager/network/network.go index dd1dfca19..701a442af 100644 --- a/testutil/contractmanager/network/network.go +++ b/testutil/contractmanager/network/network.go @@ -3,6 +3,8 @@ package network import ( "fmt" "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/x/staking" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/neutron-org/neutron/v4/testutil" "testing" "time" @@ -20,11 +22,6 @@ import ( "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/cosmos/cosmos-sdk/x/genutil" - genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" - "github.com/cosmos/cosmos-sdk/x/staking" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/neutron-org/neutron/v4/app/params" "github.com/neutron-org/neutron/v4/app" @@ -75,10 +72,13 @@ func DefaultConfig() network.Config { sims.NewAppOptionsWithFlagHome(tempHome), nil, ) - encoding := app.MakeEncodingConfig() - - // app doesn't have these modules anymore, but we need them for test setup, which uses gentx and MsgCreateValidator - tempApp.BasicModuleManager[genutiltypes.ModuleName] = genutil.AppModule{} + encoding := params.EncodingConfig{ + InterfaceRegistry: tempApp.InterfaceRegistry(), + Marshaler: tempApp.AppCodec(), + TxConfig: tempApp.GetTxConfig(), + Amino: tempApp.LegacyAmino(), + } + // app doesn't have this module, but we need it for test setup, which uses MsgCreateValidator tempApp.BasicModuleManager[stakingtypes.ModuleName] = staking.AppModule{} tempApp.BasicModuleManager.RegisterInterfaces(encoding.InterfaceRegistry) @@ -97,6 +97,10 @@ func DefaultConfig() network.Config { if err != nil { panic(err) } + err = testutil.ModifyGenesisClearGenTxs(val.(network.Validator)) + if err != nil { + panic(err) + } return app.New( val.GetCtx().Logger, db.NewMemDB(), nil, true, map[int64]bool{}, val.GetCtx().Config.RootDir, 0, diff --git a/testutil/cron/network/network.go b/testutil/cron/network/network.go index b98b16ab0..c60d398e8 100644 --- a/testutil/cron/network/network.go +++ b/testutil/cron/network/network.go @@ -13,8 +13,6 @@ import ( db "github.com/cosmos/cosmos-db" "github.com/stretchr/testify/require" - "github.com/cosmos/cosmos-sdk/x/genutil" - genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" "github.com/cosmos/cosmos-sdk/x/staking" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -83,10 +81,13 @@ func DefaultConfig() network.Config { sims.NewAppOptionsWithFlagHome(tempHome), nil, ) - encoding := app.MakeEncodingConfig() - - // app doesn't have these modules anymore, but we need them for test setup, which uses gentx and MsgCreateValidator - tempApp.BasicModuleManager[genutiltypes.ModuleName] = genutil.AppModule{} + encoding := params.EncodingConfig{ + InterfaceRegistry: tempApp.InterfaceRegistry(), + Marshaler: tempApp.AppCodec(), + TxConfig: tempApp.GetTxConfig(), + Amino: tempApp.LegacyAmino(), + } + // app doesn't have this module, but we need it for test setup, which uses MsgCreateValidator tempApp.BasicModuleManager[stakingtypes.ModuleName] = staking.AppModule{} tempApp.BasicModuleManager.RegisterInterfaces(encoding.InterfaceRegistry) @@ -106,6 +107,11 @@ func DefaultConfig() network.Config { panic(err) } + err = testutil.ModifyGenesisClearGenTxs(val.(network.Validator)) + if err != nil { + panic(err) + } + return app.New( val.GetCtx().Logger, db.NewMemDB(), nil, true, map[int64]bool{}, val.GetCtx().Config.RootDir, 0, sims.EmptyAppOptions{}, diff --git a/testutil/interchainqueries/network/network.go b/testutil/interchainqueries/network/network.go index 59879c206..4dfa03fb1 100644 --- a/testutil/interchainqueries/network/network.go +++ b/testutil/interchainqueries/network/network.go @@ -20,8 +20,6 @@ import ( "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/cosmos/cosmos-sdk/x/genutil" - genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" "github.com/cosmos/cosmos-sdk/x/staking" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -75,10 +73,13 @@ func DefaultConfig() network.Config { sims.NewAppOptionsWithFlagHome(tempHome), nil, ) - encoding := app.MakeEncodingConfig() - - // app doesn't have these modules anymore, but we need them for test setup, which uses gentx and MsgCreateValidator - tempApp.BasicModuleManager[genutiltypes.ModuleName] = genutil.AppModule{} + encoding := params.EncodingConfig{ + InterfaceRegistry: tempApp.InterfaceRegistry(), + Marshaler: tempApp.AppCodec(), + TxConfig: tempApp.GetTxConfig(), + Amino: tempApp.LegacyAmino(), + } + // app doesn't have this module, but we need it for test setup, which uses MsgCreateValidator tempApp.BasicModuleManager[stakingtypes.ModuleName] = staking.AppModule{} tempApp.BasicModuleManager.RegisterInterfaces(encoding.InterfaceRegistry) @@ -94,6 +95,11 @@ func DefaultConfig() network.Config { panic(err) } + err = testutil.ModifyGenesisClearGenTxs(val.(network.Validator)) + if err != nil { + panic(err) + } + return app.New( val.GetCtx().Logger, db.NewMemDB(), nil, true, map[int64]bool{}, val.GetCtx().Config.RootDir, 0, sims.EmptyAppOptions{}, diff --git a/testutil/interchaintxs/network/network.go b/testutil/interchaintxs/network/network.go index 0ec3c61a1..5840b1358 100644 --- a/testutil/interchaintxs/network/network.go +++ b/testutil/interchaintxs/network/network.go @@ -20,8 +20,6 @@ import ( "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/cosmos/cosmos-sdk/x/genutil" - genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" "github.com/cosmos/cosmos-sdk/x/staking" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -76,10 +74,13 @@ func DefaultConfig() network.Config { sims.NewAppOptionsWithFlagHome(tempHome), nil, ) - encoding := app.MakeEncodingConfig() - - // app doesn't have these modules anymore, but we need them for test setup, which uses gentx and MsgCreateValidator - tempApp.BasicModuleManager[genutiltypes.ModuleName] = genutil.AppModule{} + encoding := params.EncodingConfig{ + InterfaceRegistry: tempApp.InterfaceRegistry(), + Marshaler: tempApp.AppCodec(), + TxConfig: tempApp.GetTxConfig(), + Amino: tempApp.LegacyAmino(), + } + // app doesn't have this module, but we need it for test setup, which uses MsgCreateValidator tempApp.BasicModuleManager[stakingtypes.ModuleName] = staking.AppModule{} tempApp.BasicModuleManager.RegisterInterfaces(encoding.InterfaceRegistry) @@ -99,6 +100,11 @@ func DefaultConfig() network.Config { panic(err) } + err = testutil.ModifyGenesisClearGenTxs(val.(network.Validator)) + if err != nil { + panic(err) + } + return app.New( val.GetCtx().Logger, db.NewMemDB(), nil, true, map[int64]bool{}, val.GetCtx().Config.RootDir, 0, sims.EmptyAppOptions{}, diff --git a/testutil/test_helpers.go b/testutil/test_helpers.go index fcc82d083..9e30fb072 100644 --- a/testutil/test_helpers.go +++ b/testutil/test_helpers.go @@ -2,8 +2,12 @@ package testutil import ( "bytes" + "cosmossdk.io/errors" "encoding/json" "fmt" + "github.com/cosmos/cosmos-sdk/testutil/network" + "github.com/cosmos/cosmos-sdk/x/genutil" + genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" "os" "path" "testing" @@ -507,3 +511,27 @@ func SetupTransferPath(path *ibctesting.Path) error { return path.EndpointB.ChanOpenConfirm() } + +// ModifyGenesisClearGenTxs removes MsgCreateValidator messages from a final test genesis +func ModifyGenesisClearGenTxs(val network.Validator) error { + genFile := val.Ctx.Config.GenesisFile() + appState, genDoc, err := genutiltypes.GenesisStateFromGenFile(genFile) + if err != nil { + return errors.Wrap(err, "failed to read genesis from the file") + } + + appState[genutiltypes.ModuleName] = []byte(`{"gen_txs":[]}`) + + appStateJSON, err := json.Marshal(appState) + if err != nil { + return errors.Wrap(err, "failed to marshal application genesis state into JSON") + } + + genDoc.AppState = appStateJSON + err = genutil.ExportGenesisFile(genDoc, genFile) + if err != nil { + return errors.Wrap(err, "failed to export genesis state") + } + + return nil +} From 80094743df471a04521d9598a70f60a97196a913 Mon Sep 17 00:00:00 2001 From: swelf Date: Wed, 3 Jul 2024 13:23:44 +0300 Subject: [PATCH 6/6] lint --- app/app.go | 3 ++- testutil/contractmanager/network/network.go | 7 +++++-- testutil/cron/network/network.go | 3 ++- testutil/interchainqueries/network/network.go | 3 ++- testutil/interchaintxs/network/network.go | 3 ++- testutil/test_helpers.go | 10 ++++++---- 6 files changed, 19 insertions(+), 10 deletions(-) diff --git a/app/app.go b/app/app.go index 2daceff3a..db0f38b43 100644 --- a/app/app.go +++ b/app/app.go @@ -3,7 +3,6 @@ package app import ( "context" "fmt" - tendermint "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" "io" "io/fs" "net/http" @@ -11,6 +10,8 @@ import ( "path/filepath" "time" + tendermint "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" + "github.com/neutron-org/neutron/v4/x/dynamicfees" dynamicfeestypes "github.com/neutron-org/neutron/v4/x/dynamicfees/types" diff --git a/testutil/contractmanager/network/network.go b/testutil/contractmanager/network/network.go index 701a442af..19312b6e4 100644 --- a/testutil/contractmanager/network/network.go +++ b/testutil/contractmanager/network/network.go @@ -2,12 +2,14 @@ package network import ( "fmt" + "testing" + "time" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/x/staking" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/neutron-org/neutron/v4/testutil" - "testing" - "time" db "github.com/cosmos/cosmos-db" "github.com/stretchr/testify/require" @@ -22,6 +24,7 @@ import ( "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/neutron-org/neutron/v4/app/params" "github.com/neutron-org/neutron/v4/app" diff --git a/testutil/cron/network/network.go b/testutil/cron/network/network.go index c60d398e8..b8dba2ad3 100644 --- a/testutil/cron/network/network.go +++ b/testutil/cron/network/network.go @@ -2,10 +2,11 @@ package network import ( "fmt" - "github.com/neutron-org/neutron/v4/testutil" "testing" "time" + "github.com/neutron-org/neutron/v4/testutil" + "github.com/neutron-org/neutron/v4/app/config" "cosmossdk.io/log" diff --git a/testutil/interchainqueries/network/network.go b/testutil/interchainqueries/network/network.go index 4dfa03fb1..ac4154e98 100644 --- a/testutil/interchainqueries/network/network.go +++ b/testutil/interchainqueries/network/network.go @@ -2,10 +2,11 @@ package network import ( "fmt" - "github.com/neutron-org/neutron/v4/testutil" "testing" "time" + "github.com/neutron-org/neutron/v4/testutil" + "cosmossdk.io/log" pruningtypes "cosmossdk.io/store/pruning/types" db "github.com/cosmos/cosmos-db" diff --git a/testutil/interchaintxs/network/network.go b/testutil/interchaintxs/network/network.go index 5840b1358..fc1020e51 100644 --- a/testutil/interchaintxs/network/network.go +++ b/testutil/interchaintxs/network/network.go @@ -2,10 +2,11 @@ package network import ( "fmt" - "github.com/neutron-org/neutron/v4/testutil" "testing" "time" + "github.com/neutron-org/neutron/v4/testutil" + "cosmossdk.io/log" pruningtypes "cosmossdk.io/store/pruning/types" db "github.com/cosmos/cosmos-db" diff --git a/testutil/test_helpers.go b/testutil/test_helpers.go index 9e30fb072..98bc32916 100644 --- a/testutil/test_helpers.go +++ b/testutil/test_helpers.go @@ -2,17 +2,19 @@ package testutil import ( "bytes" - "cosmossdk.io/errors" "encoding/json" "fmt" - "github.com/cosmos/cosmos-sdk/testutil/network" - "github.com/cosmos/cosmos-sdk/x/genutil" - genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" "os" "path" "testing" "time" + "cosmossdk.io/errors" + + "github.com/cosmos/cosmos-sdk/testutil/network" + "github.com/cosmos/cosmos-sdk/x/genutil" + genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" + tmrand "github.com/cometbft/cometbft/libs/rand" "github.com/neutron-org/neutron/v4/utils"