From 1028a94e796aaad11f95e26a19ec9c48d7975af7 Mon Sep 17 00:00:00 2001 From: swelf Date: Tue, 2 Jul 2024 21:47:54 +0300 Subject: [PATCH] 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 +}