Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
swelf19 committed Jul 2, 2024
1 parent d2f25d2 commit 1028a94
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 29 deletions.
10 changes: 10 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
)
Expand Down Expand Up @@ -1076,6 +1077,7 @@ func New(
ibcswaptypes.ModuleName,
dextypes.ModuleName,
dynamicfeestypes.ModuleName,
genutiltypes.ModuleName,
)

app.mm.RegisterInvariants(&app.CrisisKeeper)
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions cmd/neutrond/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down
22 changes: 13 additions & 9 deletions testutil/contractmanager/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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)

Expand All @@ -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,
Expand Down
18 changes: 12 additions & 6 deletions testutil/cron/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)

Expand All @@ -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{},
Expand Down
18 changes: 12 additions & 6 deletions testutil/interchainqueries/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)

Expand All @@ -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{},
Expand Down
18 changes: 12 additions & 6 deletions testutil/interchaintxs/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)

Expand All @@ -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{},
Expand Down
28 changes: 28 additions & 0 deletions testutil/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

0 comments on commit 1028a94

Please sign in to comment.