diff --git a/CHANGELOG.md b/CHANGELOG.md index f08dbf338..ab81aad5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,6 +60,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Improvements +* [#1197](https://github.com/NibiruChain/nibiru/pull/1197) - refactor(testutil): clean up `x/common/testutil` test setup code * [#1193](https://github.com/NibiruChain/nibiru/pull/1193) - refactor(oracle): clean up `x/oracle/keeper` tests * [#1192](https://github.com/NibiruChain/nibiru/pull/1192) - feat: chaosnet docker-compose * [#1191](https://github.com/NibiruChain/nibiru/pull/1191) - fix(oracle): default whitelisted pairs diff --git a/app/ante.go b/app/ante.go index 89ccfdeb3..6495ea5b3 100644 --- a/app/ante.go +++ b/app/ante.go @@ -1,6 +1,8 @@ package app import ( + wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" + wasmTypes "github.com/CosmWasm/wasmd/x/wasm/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth/ante" @@ -8,9 +10,6 @@ import ( ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper" feeante "github.com/NibiruChain/nibiru/app/antedecorators/fee" - - wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" - wasmTypes "github.com/CosmWasm/wasmd/x/wasm/types" ) type AnteHandlerOptions struct { diff --git a/app/antedecorators/fee/testutil_test.go b/app/antedecorators/fee/testutil_test.go index 3d70158ca..859071629 100644 --- a/app/antedecorators/fee/testutil_test.go +++ b/app/antedecorators/fee/testutil_test.go @@ -11,12 +11,10 @@ import ( "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/cosmos-sdk/x/auth/ante" xauthsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/stretchr/testify/suite" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/NibiruChain/nibiru/app" - "github.com/NibiruChain/nibiru/simapp" + "github.com/NibiruChain/nibiru/x/common/testutil/testapp" ) // AnteTestSuite is a test suite to be used with ante handler tests. @@ -30,18 +28,9 @@ type AnteTestSuite struct { txBuilder client.TxBuilder } -// returns context and app with params set on account keeper -func createTestApp(isCheckTx bool) (*app.NibiruApp, sdk.Context) { - app := simapp.NewTestNibiruApp(true) - ctx := app.BaseApp.NewContext(isCheckTx, tmproto.Header{}) - app.AccountKeeper.SetParams(ctx, authtypes.DefaultParams()) - - return app, ctx -} - // SetupTest setups a new test, with new app, context, and anteHandler. func (suite *AnteTestSuite) SetupTest(isCheckTx bool) { - suite.app, suite.ctx = createTestApp(isCheckTx) + suite.app, suite.ctx = testapp.NewNibiruTestAppAndContext(false) suite.ctx = suite.ctx.WithBlockHeight(1) // Set up TxConfig. diff --git a/app/ibc_test.go b/app/ibc_test.go index 23b348c2a..b420ac921 100644 --- a/app/ibc_test.go +++ b/app/ibc_test.go @@ -16,8 +16,8 @@ import ( "github.com/stretchr/testify/suite" "github.com/NibiruChain/nibiru/app" - "github.com/NibiruChain/nibiru/simapp" "github.com/NibiruChain/nibiru/x/common/testutil" + "github.com/NibiruChain/nibiru/x/common/testutil/testapp" ) // init changes the value of 'DefaultTestingAppInit' to use custom initialization. @@ -35,7 +35,7 @@ func SetupNibiruTestingApp() ( defaultGenesis map[string]json.RawMessage, ) { // create testing app - nibiruApp, _ := simapp.NewTestNibiruAppAndContext(true) + nibiruApp, _ := testapp.NewNibiruTestAppAndContext(true) // Create genesis state encCdc := app.MakeTestEncodingConfig() diff --git a/simapp/sim_test.go b/simapp/sim_test.go index 06bf7e140..4afb8d3ff 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -7,6 +7,8 @@ import ( "os" "testing" + "github.com/NibiruChain/nibiru/app" + "github.com/NibiruChain/nibiru/x/common/testutil/testapp" sdkSimapp "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/simapp/helpers" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" @@ -35,23 +37,24 @@ func TestFullAppSimulation(tb *testing.T) { } }() - nibiru := NewTestNibiruApp( /*shouldUseDefaultGenesis*/ true) + encoding := app.MakeTestEncodingConfig() + app := testapp.NewNibiruTestApp(app.NewDefaultGenesisState(encoding.Marshaler)) // Run randomized simulation: _, simParams, simErr := simulation.SimulateFromSeed( /* tb */ tb, /* w */ os.Stdout, - /* app */ nibiru.BaseApp, - /* appStateFn */ AppStateFn(nibiru.AppCodec(), nibiru.SimulationManager()), + /* app */ app.BaseApp, + /* appStateFn */ AppStateFn(app.AppCodec(), app.SimulationManager()), /* randAccFn */ simulationtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1 - /* ops */ sdkSimapp.SimulationOperations(nibiru, nibiru.AppCodec(), config), // Run all registered operations - /* blockedAddrs */ nibiru.ModuleAccountAddrs(), + /* ops */ sdkSimapp.SimulationOperations(app, app.AppCodec(), config), // Run all registered operations + /* blockedAddrs */ app.ModuleAccountAddrs(), /* config */ config, - /* cdc */ nibiru.AppCodec(), + /* cdc */ app.AppCodec(), ) // export state and simParams before the simulation error is checked - if err = sdkSimapp.CheckExportSimulation(nibiru, config, simParams); err != nil { + if err = sdkSimapp.CheckExportSimulation(app, config, simParams); err != nil { tb.Fatal(err) } @@ -69,6 +72,8 @@ func TestAppStateDeterminism(t *testing.T) { t.Skip("skipping application simulation") } + encoding := app.MakeTestEncodingConfig() + config := sdkSimapp.NewConfigFromFlags() config.InitialBlockHeight = 1 config.ExportParamsPath = "" @@ -85,7 +90,7 @@ func TestAppStateDeterminism(t *testing.T) { for j := 0; j < numTimesToRunPerSeed; j++ { db := dbm.NewMemDB() - app := NewTestNibiruApp( /*shouldUseDefaultGenesis*/ true) + app := testapp.NewNibiruTestApp(app.NewDefaultGenesisState(encoding.Marshaler)) fmt.Printf( "running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n", diff --git a/simapp/testapp.go b/simapp/testapp.go deleted file mode 100644 index acdc114b7..000000000 --- a/simapp/testapp.go +++ /dev/null @@ -1,132 +0,0 @@ -package simapp - -import ( - "encoding/json" - "os" - "path/filepath" - "time" - - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/simapp" - sdk "github.com/cosmos/cosmos-sdk/types" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - abci "github.com/tendermint/tendermint/abci/types" - "github.com/tendermint/tendermint/libs/log" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - tmdb "github.com/tendermint/tm-db" - - "github.com/NibiruChain/nibiru/app" - "github.com/NibiruChain/nibiru/x/common" - "github.com/NibiruChain/nibiru/x/common/asset" - "github.com/NibiruChain/nibiru/x/common/denoms" -) - -// NewTestNibiruApp creates an application instance ('app.NibiruApp') with an in-memory -// database ('tmdb.MemDB') and disabled logging. It either uses the application's -// default genesis state or a blank one. -func NewTestNibiruApp(shouldUseDefaultGenesis bool) *app.NibiruApp { - encoding := simapp.MakeTestEncodingConfig() - var appGenesis app.GenesisState - if shouldUseDefaultGenesis { - appGenesis = app.NewDefaultGenesisState(encoding.Marshaler) - } - return NewTestNibiruAppWithGenesis(appGenesis) -} - -// NewTestNibiruAppAndContext creates an 'app.NibiruApp' instance with an in-memory -// 'tmdb.MemDB' and fresh 'sdk.Context'. -func NewTestNibiruAppAndContext(shouldUseDefaultGenesis bool) (*app.NibiruApp, sdk.Context) { - newNibiruApp := NewTestNibiruApp(shouldUseDefaultGenesis) - ctx := newNibiruApp.NewContext(false, tmproto.Header{}) - - newNibiruApp.OracleKeeper.SetPrice(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(20000)) - // newNibiruApp.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), sdk.NewDec(10)) - newNibiruApp.OracleKeeper.SetPrice(ctx, "xxx:yyy", sdk.NewDec(20000)) - - return newNibiruApp, ctx -} - -// NewTestNibiruAppWithGenesis initializes a chain with the given genesis state to -// creates an application instance ('app.NibiruApp'). This app uses an -// in-memory database ('tmdb.MemDB') and has logging disabled. -func NewTestNibiruAppWithGenesis(gen app.GenesisState) *app.NibiruApp { - userHomeDir, err := os.UserHomeDir() - if err != nil { - panic(err) - } - - nodeHome := filepath.Join(userHomeDir, ".nibid") - db := tmdb.NewMemDB() - logger := log.NewNopLogger() - - encoding := app.MakeTestEncodingConfig() - - nibiruApp := app.NewNibiruApp( - logger, - db, - /*traceStore=*/ nil, - /*loadLatest=*/ true, - /*skipUpgradeHeights=*/ map[int64]bool{}, - /*homePath=*/ nodeHome, - /*invCheckPeriod=*/ 0, - /*encodingConfig=*/ encoding, - /*appOpts=*/ simapp.EmptyAppOptions{}, - ) - - stateBytes, err := json.MarshalIndent(gen, "", " ") - if err != nil { - panic(err) - } - - nibiruApp.InitChain(abci.RequestInitChain{ - ConsensusParams: simapp.DefaultConsensusParams, - AppStateBytes: stateBytes, - }) - - return nibiruApp -} - -// ---------------------------------------------------------------------------- -// Genesis -// ---------------------------------------------------------------------------- - -const ( - GenOracleAddress = "nibi1zuxt7fvuxgj69mjxu3auca96zemqef5u2yemly" -) - -/* - NewTestGenesisStateFromDefault returns 'NewGenesisState' using the default - -genesis as input. The blockchain genesis state is represented as a map from module -identifier strings to raw json messages. -*/ -func NewTestGenesisStateFromDefault() app.GenesisState { - encodingConfig := app.MakeTestEncodingConfig() - codec := encodingConfig.Marshaler - genState := app.NewDefaultGenesisState(codec) - return NewTestGenesisState(codec, genState) -} - -/* -NewTestGenesisState transforms 'inGenState' to add genesis parameter changes -that are well suited to integration testing, then returns the transformed genesis. -The blockchain genesis state is represented as a map from module identifier strings -to raw json messages. - -Args: -- codec: Serializer for the module genesis state proto.Messages -- inGenState: Input genesis state before the custom test setup is applied -*/ -func NewTestGenesisState(codec codec.Codec, inGenState app.GenesisState, -) (testGenState app.GenesisState) { - testGenState = inGenState - - // Set short voting period to allow fast gov proposals in tests - var govGenState govtypes.GenesisState - codec.MustUnmarshalJSON(testGenState[govtypes.ModuleName], &govGenState) - govGenState.VotingParams.VotingPeriod = time.Second * 20 - govGenState.DepositParams.MinDeposit = sdk.NewCoins(sdk.NewInt64Coin(denoms.NIBI, 1*common.Precision)) // min deposit of 1 NIBI - testGenState[govtypes.ModuleName] = codec.MustMarshalJSON(&govGenState) - - return testGenState -} diff --git a/x/common/testutil/cli/network.go b/x/common/testutil/cli/network.go index 65f5d60bd..88514ddf3 100644 --- a/x/common/testutil/cli/network.go +++ b/x/common/testutil/cli/network.go @@ -14,9 +14,10 @@ import ( "testing" "time" - "github.com/NibiruChain/nibiru/simapp" "github.com/NibiruChain/nibiru/x/common/denoms" + "github.com/NibiruChain/nibiru/x/common/testutil/testapp" + "github.com/NibiruChain/nibiru/app" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/codec" @@ -43,8 +44,6 @@ import ( "github.com/tendermint/tendermint/node" tmclient "github.com/tendermint/tendermint/rpc/client" "google.golang.org/grpc" - - "github.com/NibiruChain/nibiru/app" ) // package-wide network lock to only allow one test network at a time @@ -137,7 +136,7 @@ func BuildNetworkConfig(appGenesis app.GenesisState) Config { InterfaceRegistry: encCfg.InterfaceRegistry, AccountRetriever: authtypes.AccountRetriever{}, AppConstructor: func(val Validator) servertypes.Application { - return simapp.NewTestNibiruAppWithGenesis(appGenesis) + return testapp.NewNibiruTestApp(appGenesis) }, GenesisState: appGenesis, TimeoutCommit: time.Second / 2, diff --git a/x/common/testutil/genesis/genesis.go b/x/common/testutil/genesis/genesis.go new file mode 100644 index 000000000..5a36f2568 --- /dev/null +++ b/x/common/testutil/genesis/genesis.go @@ -0,0 +1,32 @@ +package genesis + +import ( + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + + "github.com/NibiruChain/nibiru/app" + "github.com/NibiruChain/nibiru/x/common/denoms" +) + +/* + NewTestGenesisState returns 'NewGenesisState' using the default + +genesis as input. The blockchain genesis state is represented as a map from module +identifier strings to raw json messages. +*/ +func NewTestGenesisState() app.GenesisState { + encodingConfig := app.MakeTestEncodingConfig() + codec := encodingConfig.Marshaler + genState := app.NewDefaultGenesisState(codec) + + // Set short voting period to allow fast gov proposals in tests + var govGenState govtypes.GenesisState + codec.MustUnmarshalJSON(genState[govtypes.ModuleName], &govGenState) + govGenState.VotingParams.VotingPeriod = time.Second * 20 + govGenState.DepositParams.MinDeposit = sdk.NewCoins(sdk.NewInt64Coin(denoms.NIBI, 1_000_000)) // min deposit of 1 NIBI + genState[govtypes.ModuleName] = codec.MustMarshalJSON(&govGenState) + + return genState +} diff --git a/x/common/testutil/testapp/config.go b/x/common/testutil/testapp/config.go deleted file mode 100644 index 741c56863..000000000 --- a/x/common/testutil/testapp/config.go +++ /dev/null @@ -1,52 +0,0 @@ -package testapp - -import ( - "fmt" - "time" - - "github.com/cosmos/cosmos-sdk/crypto/hd" - "github.com/cosmos/cosmos-sdk/crypto/keyring" - servertypes "github.com/cosmos/cosmos-sdk/server/types" - storetypes "github.com/cosmos/cosmos-sdk/store/types" - sdk "github.com/cosmos/cosmos-sdk/types" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - tmrand "github.com/tendermint/tendermint/libs/rand" - - "github.com/NibiruChain/nibiru/app" - "github.com/NibiruChain/nibiru/x/common/denoms" - "github.com/NibiruChain/nibiru/x/common/testutil/cli" -) - -// BuildNetworkConfig returns a configuration for a local in-testing network -func BuildNetworkConfig(appGenesis GenesisState) cli.Config { - encCfg := app.MakeTestEncodingConfig() - - return cli.Config{ - Codec: encCfg.Marshaler, - TxConfig: encCfg.TxConfig, - LegacyAmino: encCfg.Amino, - InterfaceRegistry: encCfg.InterfaceRegistry, - AccountRetriever: authtypes.AccountRetriever{}, - AppConstructor: func(val cli.Validator) servertypes.Application { - return NewTestNibiruAppWithGenesis(appGenesis) - }, - GenesisState: appGenesis, - TimeoutCommit: time.Second / 2, - ChainID: "chain-" + tmrand.NewRand().Str(6), - NumValidators: 1, - BondDenom: denoms.NIBI, - MinGasPrices: fmt.Sprintf("0.000006%s", denoms.NIBI), - AccountTokens: sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction), - StakingTokens: sdk.TokensFromConsensusPower(500, sdk.DefaultPowerReduction), - BondedTokens: sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction), - StartingTokens: sdk.NewCoins( - sdk.NewCoin(denoms.NUSD, sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction)), - sdk.NewCoin(denoms.NIBI, sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction)), - sdk.NewCoin(denoms.USDC, sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction)), - ), - PruningStrategy: storetypes.PruningOptionNothing, - CleanupDir: true, - SigningAlgo: string(hd.Secp256k1Type), - KeyringOptions: []keyring.Option{}, - } -} diff --git a/x/common/testutil/testapp/genesis.go b/x/common/testutil/testapp/genesis.go deleted file mode 100644 index a7aaea9f7..000000000 --- a/x/common/testutil/testapp/genesis.go +++ /dev/null @@ -1,81 +0,0 @@ -package testapp - -import ( - "encoding/json" - "io" - "os" - - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" - simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - tmjson "github.com/tendermint/tendermint/libs/json" - tmtypes "github.com/tendermint/tendermint/types" - - "github.com/NibiruChain/nibiru/app" -) - -// AppStateFromGenesisFileFn util function to generate the genesis AppState -// from a genesis.json file. -func AppStateFromGenesisFileFn(r io.Reader, cdc codec.JSONCodec, genesisFile string) (tmtypes.GenesisDoc, []simtypes.Account) { - bytes, err := os.ReadFile(genesisFile) - if err != nil { - panic(err) - } - - var genesis tmtypes.GenesisDoc - // NOTE: Tendermint uses a custom JSON decoder for GenesisDoc - err = tmjson.Unmarshal(bytes, &genesis) - if err != nil { - panic(err) - } - - var appState GenesisState - err = json.Unmarshal(genesis.AppState, &appState) - if err != nil { - panic(err) - } - - var authGenesis authtypes.GenesisState - if appState[authtypes.ModuleName] != nil { - cdc.MustUnmarshalJSON(appState[authtypes.ModuleName], &authGenesis) - } - - newAccs := make([]simtypes.Account, len(authGenesis.Accounts)) - for i, acc := range authGenesis.Accounts { - // Pick a random private key, since we don't know the actual key - // This should be fine as it's only used for mock Tendermint validators - // and these keys are never actually used to sign by mock Tendermint. - privkeySeed := make([]byte, 15) - if _, err := r.Read(privkeySeed); err != nil { - panic(err) - } - - privKey := secp256k1.GenPrivKeyFromSecret(privkeySeed) - - a, ok := acc.GetCachedValue().(authtypes.AccountI) - if !ok { - panic("expected account") - } - - // create simulator accounts - simAcc := simtypes.Account{PrivKey: privKey, PubKey: privKey.PubKey(), Address: a.GetAddress()} - newAccs[i] = simAcc - } - - return genesis, newAccs -} - -// GenesisState of the blockchain is represented here as a map of raw json -// messages key'd by a identifier string. -// The identifier is used to determine which module genesis information belongs -// to so it may be appropriately routed during init chain. -// Within this application default genesis information is retrieved from -// the ModuleBasicManager which populates json from each BasicModule -// object provided to it during init. -type GenesisState map[string]json.RawMessage - -// NewDefaultGenesisState generates the default state for the application. -func NewDefaultGenesisState(cdc codec.JSONCodec) GenesisState { - return app.ModuleBasics.DefaultGenesis(cdc) -} diff --git a/x/common/testutil/testapp/testapp.go b/x/common/testutil/testapp/testapp.go index 8ac6cf01c..991b64b4d 100644 --- a/x/common/testutil/testapp/testapp.go +++ b/x/common/testutil/testapp/testapp.go @@ -4,46 +4,42 @@ import ( "encoding/json" "os" "path/filepath" - "time" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmdb "github.com/tendermint/tm-db" "github.com/NibiruChain/nibiru/app" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" ) -// NewTestNibiruApp creates an application instance ('app.NibiruApp') with an in-memory -// database ('tmdb.MemDB') and disabled logging. It either uses the application's -// default genesis state or a blank one. -func NewTestNibiruApp(shouldUseDefaultGenesis bool) *app.NibiruApp { +// NewNibiruTestAppAndContext creates an 'app.NibiruApp' instance with an in-memory +// 'tmdb.MemDB' and fresh 'sdk.Context'. +func NewNibiruTestAppAndContext(shouldUseDefaultGenesis bool) (*app.NibiruApp, sdk.Context) { encoding := simapp.MakeTestEncodingConfig() - var appGenesis GenesisState + var appGenesis app.GenesisState if shouldUseDefaultGenesis { - appGenesis = NewDefaultGenesisState(encoding.Marshaler) + appGenesis = app.NewDefaultGenesisState(encoding.Marshaler) } - return NewTestNibiruAppWithGenesis(appGenesis) -} -// NewTestNibiruAppAndContext creates an 'app.NibiruApp' instance with an in-memory -// 'tmdb.MemDB' and fresh 'sdk.Context'. -func NewTestNibiruAppAndContext(shouldUseDefaultGenesis bool) (*app.NibiruApp, sdk.Context) { - newNibiruApp := NewTestNibiruApp(shouldUseDefaultGenesis) + newNibiruApp := NewNibiruTestApp(appGenesis) ctx := newNibiruApp.NewContext(false, tmproto.Header{}) + newNibiruApp.OracleKeeper.SetPrice(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(20000)) + // newNibiruApp.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), sdk.NewDec(10)) + newNibiruApp.OracleKeeper.SetPrice(ctx, "xxx:yyy", sdk.NewDec(20000)) + return newNibiruApp, ctx } -// NewTestNibiruAppWithGenesis initializes a chain with the given genesis state to +// newNibiruTestApp initializes a chain with the given genesis state to // creates an application instance ('app.NibiruApp'). This app uses an // in-memory database ('tmdb.MemDB') and has logging disabled. -func NewTestNibiruAppWithGenesis(gen GenesisState) *app.NibiruApp { +func NewNibiruTestApp(gen app.GenesisState) *app.NibiruApp { userHomeDir, err := os.UserHomeDir() if err != nil { panic(err) @@ -79,48 +75,3 @@ func NewTestNibiruAppWithGenesis(gen GenesisState) *app.NibiruApp { return nibiruApp } - -// ---------------------------------------------------------------------------- -// Genesis -// ---------------------------------------------------------------------------- - -const ( - GenOracleAddress = "nibi1zuxt7fvuxgj69mjxu3auca96zemqef5u2yemly" -) - -/* - NewTestGenesisStateFromDefault returns 'NewGenesisState' using the default - -genesis as input. The blockchain genesis state is represented as a map from module -identifier strings to raw json messages. -*/ -func NewTestGenesisStateFromDefault() GenesisState { - encodingConfig := app.MakeTestEncodingConfig() - codec := encodingConfig.Marshaler - genState := NewDefaultGenesisState(codec) - return NewTestGenesisState(codec, genState) -} - -/* -NewTestGenesisState transforms 'inGenState' to add genesis parameter changes -that are well suited to integration testing, then returns the transformed genesis. -The blockchain genesis state is represented as a map from module identifier strings -to raw json messages. - -Args: -- codec: Serializer for the module genesis state proto.Messages -- inGenState: Input genesis state before the custom test setup is applied -*/ -func NewTestGenesisState(codec codec.Codec, inGenState GenesisState, -) (testGenState GenesisState) { - testGenState = inGenState - - // Set short voting period to allow fast gov proposals in tests - var govGenState govtypes.GenesisState - codec.MustUnmarshalJSON(testGenState[govtypes.ModuleName], &govGenState) - govGenState.VotingParams.VotingPeriod = time.Second * 20 - govGenState.DepositParams.MinDeposit = sdk.NewCoins(sdk.NewInt64Coin(denoms.NIBI, 1_000_000)) // min deposit of 1 NIBI - testGenState[govtypes.ModuleName] = codec.MustMarshalJSON(&govGenState) - - return testGenState -} diff --git a/x/common/testutil/testapp/testapp_test.go b/x/common/testutil/testapp/testapp_test.go deleted file mode 100644 index e9505e907..000000000 --- a/x/common/testutil/testapp/testapp_test.go +++ /dev/null @@ -1,52 +0,0 @@ -package testapp_test - -import ( - "testing" - "time" - - "github.com/NibiruChain/nibiru/simapp" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/suite" - - "github.com/NibiruChain/nibiru/app" - oracletypes "github.com/NibiruChain/nibiru/x/oracle/types" -) - -type TestappSuite struct { - suite.Suite - - genOracle sdk.AccAddress - twapLookbackWindow time.Duration -} - -func (s *TestappSuite) SetupSuite() { - app.SetPrefixes(app.AccountAddressPrefix) - s.genOracle = sdk.MustAccAddressFromBech32(simapp.GenOracleAddress) - s.twapLookbackWindow = oracletypes.DefaultTwapLookbackWindow -} - -func (s *TestappSuite) TestNewTestGenesisState() { - encodingConfig := app.MakeTestEncodingConfig() - codec := encodingConfig.Marshaler - - defaultGenState := app.NewDefaultGenesisState(codec) - testGenState := simapp.NewTestGenesisStateFromDefault() - - var testGenOracleState oracletypes.GenesisState - testGenOracleStateJSON := testGenState[oracletypes.ModuleName] - codec.MustUnmarshalJSON(testGenOracleStateJSON, &testGenOracleState) - bzTest := codec.MustMarshalJSON(&testGenOracleState) - - var defaultGenOracleState oracletypes.GenesisState - defaultGenOracleStateJSON := defaultGenState[oracletypes.ModuleName] - codec.MustUnmarshalJSON(defaultGenOracleStateJSON, &defaultGenOracleState) - bzDefault := codec.MustMarshalJSON(&defaultGenOracleState) - - s.Assert().EqualValues(bzTest, bzDefault) - s.Assert().EqualValues(testGenOracleState, defaultGenOracleState) -} - -func TestTestappSuite(t *testing.T) { - suite.Run(t, new(TestappSuite)) -} diff --git a/x/epochs/abci_test.go b/x/epochs/abci_test.go index 21cfa3f89..bd97a60da 100644 --- a/x/epochs/abci_test.go +++ b/x/epochs/abci_test.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/require" "github.com/NibiruChain/nibiru/app" - "github.com/NibiruChain/nibiru/simapp" + "github.com/NibiruChain/nibiru/x/common/testutil/testapp" "github.com/NibiruChain/nibiru/x/epochs" "github.com/NibiruChain/nibiru/x/epochs/keeper" "github.com/NibiruChain/nibiru/x/epochs/types" @@ -99,7 +99,7 @@ func TestEpochInfoChangesBeginBlockerAndInitGenesis(t *testing.T) { } for _, test := range tests { - app, ctx = simapp.NewTestNibiruAppAndContext(true) + app, ctx = testapp.NewNibiruTestAppAndContext(true) // On init genesis, default epochs information is set // To check init genesis again, should make it fresh status @@ -140,7 +140,7 @@ func TestEpochInfoChangesBeginBlockerAndInitGenesis(t *testing.T) { } func TestEpochStartingOneMonthAfterInitGenesis(t *testing.T) { - app, ctx := simapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) // On init genesis, default epochs information is set // To check init genesis again, should make it fresh status @@ -212,7 +212,7 @@ func TestLegacyEpochSerialization(t *testing.T) { } now := time.Now() - app, ctx := simapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) // On init genesis, default epochs information is set // To check init genesis again, should make it fresh status epochInfos := app.EpochsKeeper.AllEpochInfos(ctx) diff --git a/x/epochs/genesis_test.go b/x/epochs/genesis_test.go index 6efc14c88..a967d6226 100644 --- a/x/epochs/genesis_test.go +++ b/x/epochs/genesis_test.go @@ -6,13 +6,13 @@ import ( "github.com/stretchr/testify/require" - "github.com/NibiruChain/nibiru/simapp" + "github.com/NibiruChain/nibiru/x/common/testutil/testapp" "github.com/NibiruChain/nibiru/x/epochs" "github.com/NibiruChain/nibiru/x/epochs/types" ) func TestEpochsExportGenesis(t *testing.T) { - app, ctx := simapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) chainStartTime := ctx.BlockTime() chainStartHeight := ctx.BlockHeight() @@ -54,7 +54,7 @@ func TestEpochsExportGenesis(t *testing.T) { } func TestEpochsInitGenesis(t *testing.T) { - app, ctx := simapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) // On init genesis, default epochs information is set // To check init genesis again, should make it fresh status epochInfos := app.EpochsKeeper.AllEpochInfos(ctx) diff --git a/x/epochs/keeper/grpc_query_test.go b/x/epochs/keeper/grpc_query_test.go index 6871cddb9..63b1a5251 100644 --- a/x/epochs/keeper/grpc_query_test.go +++ b/x/epochs/keeper/grpc_query_test.go @@ -8,14 +8,14 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/stretchr/testify/require" - "github.com/NibiruChain/nibiru/simapp" + "github.com/NibiruChain/nibiru/x/common/testutil/testapp" "github.com/NibiruChain/nibiru/x/epochs/keeper" "github.com/NibiruChain/nibiru/x/epochs/types" ) func TestQueryEpochInfos(t *testing.T) { - nibiruApp, ctx := simapp.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) queryHelper := baseapp.NewQueryServerTestHelper(ctx, nibiruApp.InterfaceRegistry()) types.RegisterQueryServer(queryHelper, keeper.NewQuerier(nibiruApp.EpochsKeeper)) diff --git a/x/epochs/keeper/keeper_test.go b/x/epochs/keeper/keeper_test.go index 27361b5f5..c0546ccbd 100644 --- a/x/epochs/keeper/keeper_test.go +++ b/x/epochs/keeper/keeper_test.go @@ -6,13 +6,12 @@ import ( "github.com/stretchr/testify/require" - "github.com/NibiruChain/nibiru/simapp" - + "github.com/NibiruChain/nibiru/x/common/testutil/testapp" "github.com/NibiruChain/nibiru/x/epochs/types" ) func TestUpsertEpochInfo_HappyPath(t *testing.T) { - nibiruApp, ctx := simapp.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) epochInfo := types.EpochInfo{ Identifier: "monthly", @@ -39,7 +38,7 @@ func TestUpsertEpochInfo_HappyPath(t *testing.T) { } func TestEpochExists(t *testing.T) { - nibiruApp, ctx := simapp.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) epochInfo := types.EpochInfo{ Identifier: "monthly", @@ -56,7 +55,7 @@ func TestEpochExists(t *testing.T) { } func TestItFailsAddingEpochThatExists(t *testing.T) { - nibiruApp, ctx := simapp.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) epochInfo := types.EpochInfo{ Identifier: "monthly", diff --git a/x/oracle/integration_test/app_test.go b/x/oracle/integration_test/app_test.go index 549aea0b2..eff42de52 100644 --- a/x/oracle/integration_test/app_test.go +++ b/x/oracle/integration_test/app_test.go @@ -10,9 +10,9 @@ import ( "github.com/stretchr/testify/suite" "github.com/NibiruChain/nibiru/app" - "github.com/NibiruChain/nibiru/simapp" "github.com/NibiruChain/nibiru/x/common/asset" testutilcli "github.com/NibiruChain/nibiru/x/common/testutil/cli" + "github.com/NibiruChain/nibiru/x/common/testutil/genesis" "github.com/NibiruChain/nibiru/x/oracle/types" ) @@ -25,7 +25,7 @@ type IntegrationTestSuite struct { func (s *IntegrationTestSuite) SetupTest() { app.SetPrefixes(app.AccountAddressPrefix) - s.cfg = testutilcli.BuildNetworkConfig(simapp.NewTestGenesisStateFromDefault()) + s.cfg = testutilcli.BuildNetworkConfig(genesis.NewTestGenesisState()) s.cfg.NumValidators = 4 s.cfg.GenesisState[types.ModuleName] = s.cfg.Codec.MustMarshalJSON(func() codec.ProtoMarshaler { gs := types.DefaultGenesisState() diff --git a/x/perp/client/cli/cli_test.go b/x/perp/client/cli/cli_test.go index 26cfd54c3..56a931b6c 100644 --- a/x/perp/client/cli/cli_test.go +++ b/x/perp/client/cli/cli_test.go @@ -13,11 +13,11 @@ import ( "google.golang.org/grpc/status" "github.com/NibiruChain/nibiru/app" - "github.com/NibiruChain/nibiru/simapp" "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" testutilcli "github.com/NibiruChain/nibiru/x/common/testutil/cli" + "github.com/NibiruChain/nibiru/x/common/testutil/genesis" oracletypes "github.com/NibiruChain/nibiru/x/oracle/types" "github.com/NibiruChain/nibiru/x/perp/client/cli" perptypes "github.com/NibiruChain/nibiru/x/perp/types" @@ -47,7 +47,7 @@ func (s *IntegrationTestSuite) SetupSuite() { app.SetPrefixes(app.AccountAddressPrefix) encodingConfig := app.MakeTestEncodingConfig() - genesisState := simapp.NewTestGenesisStateFromDefault() + genesisState := genesis.NewTestGenesisState() // setup vpool vpoolGenesis := vpooltypes.DefaultGenesis() diff --git a/x/perp/genesis_test.go b/x/perp/genesis_test.go index c979e9cf8..493bf3f2b 100644 --- a/x/perp/genesis_test.go +++ b/x/perp/genesis_test.go @@ -6,77 +6,74 @@ import ( "time" "github.com/NibiruChain/collections" - + "github.com/NibiruChain/nibiru/app" "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/common/testutil" - - simapp2 "github.com/NibiruChain/nibiru/simapp" - + "github.com/NibiruChain/nibiru/x/common/testutil/testapp" + "github.com/NibiruChain/nibiru/x/perp" + "github.com/NibiruChain/nibiru/x/perp/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - - "github.com/NibiruChain/nibiru/x/perp" - "github.com/NibiruChain/nibiru/x/perp/types" ) func TestGenesis(t *testing.T) { - t.Run("success", func(t *testing.T) { - app := simapp2.NewTestNibiruApp(false) - ctxUncached := app.NewContext(false, tmproto.Header{}) - ctx, _ := ctxUncached.CacheContext() + encodingConfig := app.MakeTestEncodingConfig() + app := testapp.NewNibiruTestApp(app.NewDefaultGenesisState(encodingConfig.Marshaler)) - // create some params - app.PerpKeeper.SetParams(ctx, types.Params{ - Stopped: true, - FeePoolFeeRatio: sdk.MustNewDecFromStr("0.00001"), - EcosystemFundFeeRatio: sdk.MustNewDecFromStr("0.000005"), - LiquidationFeeRatio: sdk.MustNewDecFromStr("0.000007"), - PartialLiquidationRatio: sdk.MustNewDecFromStr("0.00001"), - TwapLookbackWindow: 15 * time.Minute, - }) + ctxUncached := app.NewContext(false, tmproto.Header{}) + ctx, _ := ctxUncached.CacheContext() - // create some positions - for i := int64(0); i < 100; i++ { - addr := testutil.AccAddress() - app.PerpKeeper.Positions.Insert(ctx, collections.Join(asset.Registry.Pair(denoms.NIBI, denoms.NUSD), addr), types.Position{ - TraderAddress: addr.String(), - Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), - Size_: sdk.NewDec(i + 1), - Margin: sdk.NewDec(i * 2), - OpenNotional: sdk.NewDec(i * 100), - LatestCumulativePremiumFraction: sdk.NewDec(5 * 100), - BlockNumber: i, - }) - } + // create some params + app.PerpKeeper.SetParams(ctx, types.Params{ + Stopped: true, + FeePoolFeeRatio: sdk.MustNewDecFromStr("0.00001"), + EcosystemFundFeeRatio: sdk.MustNewDecFromStr("0.000005"), + LiquidationFeeRatio: sdk.MustNewDecFromStr("0.000007"), + PartialLiquidationRatio: sdk.MustNewDecFromStr("0.00001"), + TwapLookbackWindow: 15 * time.Minute, + }) - // create some prepaid bad debt - for i := 0; i < 10; i++ { - app.PerpKeeper.PrepaidBadDebt.Insert(ctx, fmt.Sprintf("%d", i), types.PrepaidBadDebt{ - Denom: fmt.Sprintf("%d", i), - Amount: sdk.NewInt(int64(i)), - }) - } + // create some positions + for i := int64(0); i < 100; i++ { + addr := testutil.AccAddress() + app.PerpKeeper.Positions.Insert(ctx, collections.Join(asset.Registry.Pair(denoms.NIBI, denoms.NUSD), addr), types.Position{ + TraderAddress: addr.String(), + Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), + Size_: sdk.NewDec(i + 1), + Margin: sdk.NewDec(i * 2), + OpenNotional: sdk.NewDec(i * 100), + LatestCumulativePremiumFraction: sdk.NewDec(5 * 100), + BlockNumber: i, + }) + } - // export genesis - genState := perp.ExportGenesis(ctx, app.PerpKeeper) + // create some prepaid bad debt + for i := 0; i < 10; i++ { + app.PerpKeeper.PrepaidBadDebt.Insert(ctx, fmt.Sprintf("%d", i), types.PrepaidBadDebt{ + Denom: fmt.Sprintf("%d", i), + Amount: sdk.NewInt(int64(i)), + }) + } - // create new context and init genesis - ctx, _ = ctxUncached.CacheContext() - perp.InitGenesis(ctx, app.PerpKeeper, *genState) + // export genesis + genState := perp.ExportGenesis(ctx, app.PerpKeeper) - // export again to ensure they match - genStateAfterInit := perp.ExportGenesis(ctx, app.PerpKeeper) - require.Equal(t, genState.Params, genStateAfterInit.Params) - for i, pm := range genState.PairMetadata { - require.Equal(t, pm, genStateAfterInit.PairMetadata[i]) - } - require.Equalf(t, genState.PairMetadata, genStateAfterInit.PairMetadata, "%s <-> %s", genState.PairMetadata, genStateAfterInit.PairMetadata) - require.Equal(t, genState.PrepaidBadDebts, genStateAfterInit.PrepaidBadDebts) - require.Equal(t, len(genState.Positions), len(genStateAfterInit.Positions)) - for i, pos := range genState.Positions { - require.Equalf(t, pos, genStateAfterInit.Positions[i], "%s <-> %s", pos, genStateAfterInit.Positions[i]) - } - }) + // create new context and init genesis + ctx, _ = ctxUncached.CacheContext() + perp.InitGenesis(ctx, app.PerpKeeper, *genState) + + // export again to ensure they match + genStateAfterInit := perp.ExportGenesis(ctx, app.PerpKeeper) + require.Equal(t, genState.Params, genStateAfterInit.Params) + for i, pm := range genState.PairMetadata { + require.Equal(t, pm, genStateAfterInit.PairMetadata[i]) + } + require.Equalf(t, genState.PairMetadata, genStateAfterInit.PairMetadata, "%s <-> %s", genState.PairMetadata, genStateAfterInit.PairMetadata) + require.Equal(t, genState.PrepaidBadDebts, genStateAfterInit.PrepaidBadDebts) + require.Equal(t, len(genState.Positions), len(genStateAfterInit.Positions)) + for i, pos := range genState.Positions { + require.Equalf(t, pos, genStateAfterInit.Positions[i], "%s <-> %s", pos, genStateAfterInit.Positions[i]) + } } diff --git a/x/perp/keeper/calc_test.go b/x/perp/keeper/calc_test.go index addbf54f5..63049ba1a 100644 --- a/x/perp/keeper/calc_test.go +++ b/x/perp/keeper/calc_test.go @@ -8,11 +8,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/NibiruChain/nibiru/simapp" "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/common/testutil" + "github.com/NibiruChain/nibiru/x/common/testutil/testapp" "github.com/NibiruChain/nibiru/x/perp/keeper" "github.com/NibiruChain/nibiru/x/perp/types" vpooltypes "github.com/NibiruChain/nibiru/x/vpool/types" @@ -26,7 +26,7 @@ func TestCalcRemainMarginWithFundingPayment(t *testing.T) { { name: "get - no positions set raises vpool not found error", test: func() { - nibiruApp, ctx := simapp.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) marginDelta := sdk.OneDec() _, err := nibiruApp.PerpKeeper.CalcRemainMarginWithFundingPayment( @@ -40,7 +40,7 @@ func TestCalcRemainMarginWithFundingPayment(t *testing.T) { name: "signedRemainMargin negative bc of marginDelta", test: func() { t.Log("Setup Nibiru app, pair, and trader") - nibiruApp, ctx := simapp.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) trader := testutil.AccAddress() pair := asset.MustNewPair("osmo:nusd") @@ -93,7 +93,7 @@ func TestCalcRemainMarginWithFundingPayment(t *testing.T) { name: "large fPayment lowers pos value by half", test: func() { t.Log("Setup Nibiru app, pair, and trader") - nibiruApp, ctx := simapp.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) trader := testutil.AccAddress() pair := asset.MustNewPair("osmo:nusd") diff --git a/x/perp/keeper/clearing_house_integration_test.go b/x/perp/keeper/clearing_house_integration_test.go index bb042a7af..f435030a7 100644 --- a/x/perp/keeper/clearing_house_integration_test.go +++ b/x/perp/keeper/clearing_house_integration_test.go @@ -11,12 +11,12 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - nibisimapp "github.com/NibiruChain/nibiru/simapp" "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/common/testutil" testutilevents "github.com/NibiruChain/nibiru/x/common/testutil" + "github.com/NibiruChain/nibiru/x/common/testutil/testapp" "github.com/NibiruChain/nibiru/x/perp/keeper" "github.com/NibiruChain/nibiru/x/perp/types" vpooltypes "github.com/NibiruChain/nibiru/x/vpool/types" @@ -261,7 +261,7 @@ func TestOpenPositionSuccess(t *testing.T) { tc := testCase t.Run(tc.name, func(t *testing.T) { t.Log("Setup Nibiru app and constants") - nibiruApp, ctx := nibisimapp.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) traderAddr := testutil.AccAddress() exchangedSize := tc.expectedSize @@ -514,7 +514,7 @@ func TestOpenPositionError(t *testing.T) { tc := testCase t.Run(tc.name, func(t *testing.T) { t.Log("Setup Nibiru app and constants") - nibiruApp, ctx := nibisimapp.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) traderAddr := testutil.AccAddress() t.Log("initialize vpool") @@ -564,7 +564,7 @@ func TestOpenPositionInvalidPair(t *testing.T) { name: "open pos - uninitialized pool raised pair not supported error", test: func() { t.Log("Setup Nibiru app, pair, and trader without a vpool.") - nibiruApp, ctx := nibisimapp.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) pair := asset.MustNewPair("xxx:yyy") trader := testutil.AccAddress() @@ -584,7 +584,7 @@ func TestOpenPositionInvalidPair(t *testing.T) { name: "open pos - vpool not set on the perp PairMetadata ", test: func() { t.Log("Setup Nibiru app, pair, and trader") - nibiruApp, ctx := nibisimapp.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) pair := asset.MustNewPair("xxx:yyy") t.Log("Set vpool defined by pair on VpoolKeeper") diff --git a/x/perp/keeper/grpc_query_test.go b/x/perp/keeper/grpc_query_test.go index 54410ed3d..43e5c3028 100644 --- a/x/perp/keeper/grpc_query_test.go +++ b/x/perp/keeper/grpc_query_test.go @@ -9,11 +9,11 @@ import ( "github.com/stretchr/testify/require" "github.com/NibiruChain/nibiru/app" - "github.com/NibiruChain/nibiru/simapp" "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/common/testutil" + "github.com/NibiruChain/nibiru/x/common/testutil/testapp" "github.com/NibiruChain/nibiru/x/perp/keeper" "github.com/NibiruChain/nibiru/x/perp/types" vpooltypes "github.com/NibiruChain/nibiru/x/vpool/types" @@ -23,7 +23,7 @@ func initAppVpools( t *testing.T, quoteAssetReserve sdk.Dec, baseAssetReserve sdk.Dec, ) (sdk.Context, *app.NibiruApp, types.QueryServer) { t.Log("initialize app and keeper") - nibiruApp, ctx := simapp.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) perpKeeper := &nibiruApp.PerpKeeper vpoolKeeper := &nibiruApp.VpoolKeeper queryServer := keeper.NewQuerier(*perpKeeper) diff --git a/x/perp/keeper/keeper_test.go b/x/perp/keeper/keeper_test.go index e8d8ed451..003936272 100644 --- a/x/perp/keeper/keeper_test.go +++ b/x/perp/keeper/keeper_test.go @@ -4,12 +4,11 @@ import ( "testing" "time" - "github.com/NibiruChain/nibiru/simapp" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" + "github.com/NibiruChain/nibiru/x/common/testutil/testapp" "github.com/NibiruChain/nibiru/x/perp/types" ) @@ -44,7 +43,7 @@ func TestGetAndSetParams(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - nibiruApp, ctx := simapp.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) perpKeeper := &nibiruApp.PerpKeeper params := tc.requiredParams() @@ -57,7 +56,7 @@ func TestGetAndSetParams(t *testing.T) { func TestGetAndSetParams_Errors(t *testing.T) { t.Run("Calling Get without setting causes a panic", func(t *testing.T) { - nibiruApp, ctx := simapp.NewTestNibiruAppAndContext(false) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(false) perpKeeper := &nibiruApp.PerpKeeper require.Panics( diff --git a/x/perp/keeper/liquidate_test.go b/x/perp/keeper/liquidate_test.go index da35727fc..53e1c6012 100644 --- a/x/perp/keeper/liquidate_test.go +++ b/x/perp/keeper/liquidate_test.go @@ -10,13 +10,12 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - nibisimapp "github.com/NibiruChain/nibiru/simapp" - simapp2 "github.com/NibiruChain/nibiru/simapp" "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/common/testutil" testutilevents "github.com/NibiruChain/nibiru/x/common/testutil" + "github.com/NibiruChain/nibiru/x/common/testutil/testapp" "github.com/NibiruChain/nibiru/x/perp/keeper" "github.com/NibiruChain/nibiru/x/perp/types" vpooltypes "github.com/NibiruChain/nibiru/x/vpool/types" @@ -81,7 +80,7 @@ func TestExecuteFullLiquidation(t *testing.T) { for name, testCase := range testCases { tc := testCase t.Run(name, func(t *testing.T) { - nibiruApp, ctx := simapp2.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) ctx = ctx.WithBlockTime(time.Now()) perpKeeper := &nibiruApp.PerpKeeper @@ -260,7 +259,7 @@ func TestExecutePartialLiquidation(t *testing.T) { for _, testCase := range testCases { tc := testCase t.Run(tc.name, func(t *testing.T) { - nibiruApp, ctx := simapp2.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) ctx = ctx.WithBlockTime(time.Now()) t.Log("Set vpool defined by pair on VpoolKeeper") @@ -432,7 +431,7 @@ func TestMultiLiquidate(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := nibisimapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) ctx = ctx.WithBlockTime(time.Now()) setLiquidator(ctx, app.PerpKeeper, tc.liquidator) msgServer := keeper.NewMsgServerImpl(app.PerpKeeper) diff --git a/x/perp/keeper/margin_test.go b/x/perp/keeper/margin_test.go index e03beff63..fb5f9509d 100644 --- a/x/perp/keeper/margin_test.go +++ b/x/perp/keeper/margin_test.go @@ -10,11 +10,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - simapp2 "github.com/NibiruChain/nibiru/simapp" "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" testutilevents "github.com/NibiruChain/nibiru/x/common/testutil" + "github.com/NibiruChain/nibiru/x/common/testutil/testapp" "github.com/NibiruChain/nibiru/x/perp/keeper" "github.com/NibiruChain/nibiru/x/perp/types" vpooltypes "github.com/NibiruChain/nibiru/x/vpool/types" @@ -52,7 +52,7 @@ func TestAddMarginSuccess(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - nibiruApp, ctx := simapp2.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) traderAddr := sdk.MustAccAddressFromBech32(tc.initialPosition.TraderAddress) t.Log("add trader funds") @@ -115,7 +115,7 @@ func TestRemoveMargin(t *testing.T) { test: func() { removeAmt := sdk.NewInt(5) - nibiruApp, ctx := simapp2.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) trader := testutilevents.AccAddress() pair := asset.MustNewPair("osmo:nusd") @@ -128,7 +128,7 @@ func TestRemoveMargin(t *testing.T) { name: "pool exists but trader doesn't have position - fail", test: func() { t.Log("Setup Nibiru app, pair, and trader") - nibiruApp, ctx := simapp2.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) trader := testutilevents.AccAddress() pair := asset.MustNewPair("osmo:nusd") @@ -160,7 +160,7 @@ func TestRemoveMargin(t *testing.T) { name: "remove margin from healthy position", test: func() { t.Log("Setup Nibiru app, pair, and trader") - nibiruApp, ctx := simapp2.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) ctx = ctx.WithBlockTime(time.Now()) traderAddr := testutilevents.AccAddress() pair := asset.MustNewPair("xxx:yyy") diff --git a/x/perp/keeper/msg_server_test.go b/x/perp/keeper/msg_server_test.go index 4ed01b940..4c9afb656 100644 --- a/x/perp/keeper/msg_server_test.go +++ b/x/perp/keeper/msg_server_test.go @@ -13,11 +13,11 @@ import ( "github.com/NibiruChain/collections" - nibisimapp "github.com/NibiruChain/nibiru/simapp" "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/common/testutil" + "github.com/NibiruChain/nibiru/x/common/testutil/testapp" "github.com/NibiruChain/nibiru/x/perp/keeper" "github.com/NibiruChain/nibiru/x/perp/types" vpooltypes "github.com/NibiruChain/nibiru/x/vpool/types" @@ -73,7 +73,7 @@ func TestMsgServerAddMargin(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := nibisimapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) msgServer := keeper.NewMsgServerImpl(app.PerpKeeper) traderAddr := testutil.AccAddress() @@ -194,7 +194,7 @@ func TestMsgServerRemoveMargin(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := nibisimapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) msgServer := keeper.NewMsgServerImpl(app.PerpKeeper) traderAddr := testutil.AccAddress() @@ -281,7 +281,7 @@ func TestMsgServerOpenPosition(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := nibisimapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) ctx = ctx.WithBlockTime(time.Now()) msgServer := keeper.NewMsgServerImpl(app.PerpKeeper) @@ -368,7 +368,7 @@ func TestMsgServerClosePosition(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := nibisimapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) msgServer := keeper.NewMsgServerImpl(app.PerpKeeper) t.Log("create vpool") @@ -431,7 +431,7 @@ func setLiquidator(ctx sdk.Context, perpKeeper keeper.Keeper, liquidator sdk.Acc } func TestMsgServerMultiLiquidate(t *testing.T) { - app, ctx := nibisimapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) ctx = ctx.WithBlockTime(time.Now()) msgServer := keeper.NewMsgServerImpl(app.PerpKeeper) @@ -543,7 +543,7 @@ func TestMsgServerMultiLiquidate(t *testing.T) { } func TestMsgServerMultiLiquidate_NotAuthorized(t *testing.T) { - app, ctx := nibisimapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) ctx = ctx.WithBlockTime(time.Now()) msgServer := keeper.NewMsgServerImpl(app.PerpKeeper) @@ -614,7 +614,7 @@ func TestMsgServerMultiLiquidate_NotAuthorized(t *testing.T) { } func TestMsgServerMultiLiquidate_AllFailed(t *testing.T) { - app, ctx := nibisimapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) ctx = ctx.WithBlockTime(time.Now()) msgServer := keeper.NewMsgServerImpl(app.PerpKeeper) @@ -714,7 +714,7 @@ func TestMsgServerDonateToEcosystemFund(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := nibisimapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) msgServer := keeper.NewMsgServerImpl(app.PerpKeeper) require.NoError(t, simapp.FundAccount(app.BankKeeper, ctx, tc.sender, tc.initialFunds)) diff --git a/x/perp/keeper/perp_test.go b/x/perp/keeper/perp_test.go index a545eba7c..1930682c8 100644 --- a/x/perp/keeper/perp_test.go +++ b/x/perp/keeper/perp_test.go @@ -10,10 +10,10 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" - nibisimapp "github.com/NibiruChain/nibiru/simapp" "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/testutil" + "github.com/NibiruChain/nibiru/x/common/testutil/testapp" "github.com/NibiruChain/nibiru/x/perp/keeper" "github.com/NibiruChain/nibiru/x/perp/types" vpooltypes "github.com/NibiruChain/nibiru/x/vpool/types" @@ -23,7 +23,7 @@ func TestKeeperClosePosition(t *testing.T) { // TODO(mercilex): simulate funding payments t.Run("success", func(t *testing.T) { t.Log("Setup Nibiru app, pair, and trader") - nibiruApp, ctx := nibisimapp.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) ctx = ctx.WithBlockTime(time.Now()) pair := asset.MustNewPair("xxx:yyy") diff --git a/x/perp/module_test.go b/x/perp/module_test.go index 601b2c6a9..6627a2088 100644 --- a/x/perp/module_test.go +++ b/x/perp/module_test.go @@ -3,17 +3,16 @@ package perp_test import ( "testing" - "github.com/NibiruChain/nibiru/simapp" - "github.com/stretchr/testify/assert" + "github.com/NibiruChain/nibiru/x/common/testutil/testapp" "github.com/NibiruChain/nibiru/x/perp/types" ) // TestModuleAccounts verifies that all x/perp module accounts are connected // to the base application func TestModuleAccounts(t *testing.T) { - nibiruApp, ctx := simapp.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) perpAcc := nibiruApp.PerpKeeper.AccountKeeper.GetModuleAccount( ctx, types.ModuleName) diff --git a/x/perp/types/expected_keepers_test.go b/x/perp/types/expected_keepers_test.go index 6aeb7584e..ef37304d5 100644 --- a/x/perp/types/expected_keepers_test.go +++ b/x/perp/types/expected_keepers_test.go @@ -4,10 +4,9 @@ import ( "reflect" "testing" - "github.com/NibiruChain/nibiru/simapp" - "github.com/stretchr/testify/assert" + "github.com/NibiruChain/nibiru/x/common/testutil/testapp" "github.com/NibiruChain/nibiru/x/perp/types" ) @@ -18,7 +17,7 @@ TestExpectedKeepers verifies that the expected keeper interfaces in x/perp 'NibiruApp.KeeperName' */ func TestExpectedKeepers(t *testing.T) { - nibiruApp, _ := simapp.NewTestNibiruAppAndContext(true) + nibiruApp, _ := testapp.NewNibiruTestAppAndContext(true) testCases := []struct { name string expectedKeeper interface{} diff --git a/x/spot/client/testutil/cli_test.go b/x/spot/client/testutil/cli_test.go index 3548b0132..fb563d776 100644 --- a/x/spot/client/testutil/cli_test.go +++ b/x/spot/client/testutil/cli_test.go @@ -8,7 +8,8 @@ import ( "github.com/NibiruChain/nibiru/app" "github.com/NibiruChain/nibiru/x/common/denoms" - "github.com/NibiruChain/nibiru/x/common/testutil/testapp" + testutilcli "github.com/NibiruChain/nibiru/x/common/testutil/cli" + genesis "github.com/NibiruChain/nibiru/x/common/testutil/genesis" ) func TestIntegrationTestSuite(t *testing.T) { @@ -24,14 +25,14 @@ func TestIntegrationTestSuite(t *testing.T) { } app.SetPrefixes(app.AccountAddressPrefix) - genesisState := testapp.NewTestGenesisStateFromDefault() + genesisState := genesis.NewTestGenesisState() genesisState = WhitelistGenesisAssets( genesisState, coinsFromGenesis, ) - cfg := testapp.BuildNetworkConfig(genesisState) + cfg := testutilcli.BuildNetworkConfig(genesisState) cfg.StartingTokens = sdk.NewCoins( sdk.NewInt64Coin(denoms.NIBI, 2e12), // for pool creation fee and more for tx fees ) diff --git a/x/spot/client/testutil/test_helpers.go b/x/spot/client/testutil/test_helpers.go index ed1b1c537..d5d449f32 100644 --- a/x/spot/client/testutil/test_helpers.go +++ b/x/spot/client/testutil/test_helpers.go @@ -14,7 +14,6 @@ import ( "github.com/NibiruChain/nibiru/app" "github.com/NibiruChain/nibiru/x/common/denoms" - "github.com/NibiruChain/nibiru/x/common/testutil/testapp" "github.com/NibiruChain/nibiru/x/spot/client/cli" "github.com/NibiruChain/nibiru/x/spot/types" ) @@ -141,7 +140,7 @@ func ExecMsgSwapAssets( } // WhitelistGenesisAssets given a testapp.GenesisState includes the whitelisted assets into spot Whitelisted assets. -func WhitelistGenesisAssets(state testapp.GenesisState, assets []string) testapp.GenesisState { +func WhitelistGenesisAssets(state app.GenesisState, assets []string) app.GenesisState { encConfig := app.MakeTestEncodingConfig() jsonState := state[types.ModuleName] diff --git a/x/spot/genesis_test.go b/x/spot/genesis_test.go index 73dd37cbf..a2b998e27 100644 --- a/x/spot/genesis_test.go +++ b/x/spot/genesis_test.go @@ -16,7 +16,7 @@ func TestGenesis(t *testing.T) { Params: types.DefaultParams(), } - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) spot.InitGenesis(ctx, app.SpotKeeper, genesisState) got := spot.ExportGenesis(ctx, app.SpotKeeper) require.NotNil(t, got) diff --git a/x/spot/keeper/balances_test.go b/x/spot/keeper/balances_test.go index 5f8ca96aa..5519f1b47 100644 --- a/x/spot/keeper/balances_test.go +++ b/x/spot/keeper/balances_test.go @@ -53,7 +53,7 @@ func TestCheckBalances(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) // fund user account sender := testutil.AccAddress() diff --git a/x/spot/keeper/grpc_query_test.go b/x/spot/keeper/grpc_query_test.go index a23d4ade2..30d8065aa 100644 --- a/x/spot/keeper/grpc_query_test.go +++ b/x/spot/keeper/grpc_query_test.go @@ -17,7 +17,7 @@ import ( ) func TestParamsQuery(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) params := types.DefaultParams() app.SpotKeeper.SetParams(ctx, params) @@ -89,7 +89,7 @@ func TestQueryPoolHappyPath(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) app.SpotKeeper.SetPool(ctx, tc.existingPool) queryServer := keeper.NewQuerier(app.SpotKeeper) @@ -115,7 +115,7 @@ func TestQueryPoolFail(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) queryServer := keeper.NewQuerier(app.SpotKeeper) resp, err := queryServer.Pool(sdk.WrapSDKContext(ctx), nil) require.Error(t, err) @@ -232,7 +232,7 @@ func TestQueryPools(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) for _, existingPool := range tc.existingPools { app.SpotKeeper.SetPool(ctx, existingPool) } @@ -311,7 +311,7 @@ func TestQueryNumPools(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) sender := testutil.AccAddress() // need funds to create pools require.NoError(t, simapp.FundAccount( @@ -420,7 +420,7 @@ func TestQueryPoolParams(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) app.SpotKeeper.SetPool(ctx, tc.existingPool) queryServer := keeper.NewQuerier(app.SpotKeeper) @@ -457,7 +457,7 @@ func TestQueryTotalShares(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) app.SpotKeeper.SetPool(ctx, tc.existingPool) @@ -530,7 +530,7 @@ func TestQuerySpotPrice(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) app.SpotKeeper.SetPool(ctx, tc.existingPool) @@ -592,7 +592,7 @@ func TestQueryEstimateSwapExactAmountIn(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) app.SpotKeeper.SetPool(ctx, tc.existingPool) queryServer := keeper.NewQuerier(app.SpotKeeper) @@ -654,7 +654,7 @@ func TestQueryEstimateSwapExactAmountOut(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) app.SpotKeeper.SetPool(ctx, tc.existingPool) queryServer := keeper.NewQuerier(app.SpotKeeper) @@ -722,7 +722,7 @@ func TestQueryEstimateJoinExactAmountIn(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) app.SpotKeeper.SetPool(ctx, tc.existingPool) queryServer := keeper.NewQuerier(app.SpotKeeper) @@ -787,7 +787,7 @@ func TestQueryEstimateExitExactAmountIn(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) app.SpotKeeper.SetPool(ctx, tc.existingPool) queryServer := keeper.NewQuerier(app.SpotKeeper) diff --git a/x/spot/keeper/keeper_test.go b/x/spot/keeper/keeper_test.go index f872c7639..225acdf2d 100644 --- a/x/spot/keeper/keeper_test.go +++ b/x/spot/keeper/keeper_test.go @@ -20,7 +20,7 @@ import ( ) func TestGetAndSetNextPoolNumber(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) // Write to store app.SpotKeeper.SetNextPoolNumber(ctx, 150) @@ -32,7 +32,7 @@ func TestGetAndSetNextPoolNumber(t *testing.T) { } func TestGetNextPoolNumberAndIncrement(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) // Write a pool number app.SpotKeeper.SetNextPoolNumber(ctx, 200) @@ -49,7 +49,7 @@ func TestGetNextPoolNumberAndIncrement(t *testing.T) { } func TestSetAndFetchPool(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) pool := types.Pool{ Id: 150, @@ -158,7 +158,7 @@ func TestFetchPoolFromPair(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) app.SpotKeeper.SetPool(ctx, types.Pool{ Id: 1, @@ -220,7 +220,7 @@ func TestFetchPoolFromPair(t *testing.T) { } func TestNewPool(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) poolCreationFeeCoin := sdk.NewInt64Coin(denoms.NIBI, 1000*common.Precision) app.SpotKeeper.SetParams(ctx, types.NewParams( @@ -291,7 +291,7 @@ func TestNewPool(t *testing.T) { } func TestNewPoolNotEnoughFunds(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) app.SpotKeeper.SetParams(ctx, types.NewParams( /*startingPoolNumber=*/ 1, @@ -332,7 +332,7 @@ func TestNewPoolNotEnoughFunds(t *testing.T) { } func TestNewPoolTooLittleAssets(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) userAddr, err := sdk.AccAddressFromBech32(testutil.AccAddress().String()) require.NoError(t, err) @@ -353,7 +353,7 @@ func TestNewPoolTooLittleAssets(t *testing.T) { } func TestKeeperNewPoolNotWhitelistedAssets(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) userAddr, err := sdk.AccAddressFromBech32(testutil.AccAddress().String()) require.NoError(t, err) @@ -378,7 +378,7 @@ func TestKeeperNewPoolNotWhitelistedAssets(t *testing.T) { } func TestNewPoolTooManyAssets(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) userAddr, err := sdk.AccAddressFromBech32(testutil.AccAddress().String()) require.NoError(t, err) @@ -423,7 +423,7 @@ func TestNewPoolTooManyAssets(t *testing.T) { } func TestNewPoolDups(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) userAddr, err := sdk.AccAddressFromBech32(testutil.AccAddress().String()) require.NoError(t, err) @@ -578,7 +578,7 @@ func TestJoinPool(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) poolAddr := testutil.AccAddress() tc.initialPool.Address = poolAddr.String() @@ -737,7 +737,7 @@ func TestJoinPoolAllAssets(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) poolAddr := testutil.AccAddress() tc.initialPool.Address = poolAddr.String() @@ -850,7 +850,7 @@ func TestExitPool(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) poolAddr := testutil.AccAddress() tc.initialPool.Address = poolAddr.String() diff --git a/x/spot/keeper/liquidity_test.go b/x/spot/keeper/liquidity_test.go index db2cbb8d1..300ca27e8 100644 --- a/x/spot/keeper/liquidity_test.go +++ b/x/spot/keeper/liquidity_test.go @@ -12,7 +12,7 @@ import ( ) func TestGetSetDenomLiquidity(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) // Write to store coin := sdk.NewCoin("nibi", sdk.NewInt(1_000)) @@ -25,7 +25,7 @@ func TestGetSetDenomLiquidity(t *testing.T) { } func TestGetTotalLiquidity(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) // Write to store coinMap := map[string]sdk.Int{ @@ -64,7 +64,7 @@ func assertLiqValues( } func TestSetTotalLiquidity(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) // Write to store assert.NoError(t, app.SpotKeeper.SetTotalLiquidity(ctx, sdk.NewCoins( @@ -83,7 +83,7 @@ func TestSetTotalLiquidity(t *testing.T) { } func TestRecordTotalLiquidityIncrease(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) // Write to store assert.NoError(t, app.SpotKeeper.SetTotalLiquidity(ctx, sdk.NewCoins( @@ -104,7 +104,7 @@ func TestRecordTotalLiquidityIncrease(t *testing.T) { } func TestRecordTotalLiquidityDecrease(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) // Write to store assert.NoError(t, app.SpotKeeper.SetTotalLiquidity(ctx, sdk.NewCoins( diff --git a/x/spot/keeper/msg_server_test.go b/x/spot/keeper/msg_server_test.go index 10e39de1d..33f657dbb 100644 --- a/x/spot/keeper/msg_server_test.go +++ b/x/spot/keeper/msg_server_test.go @@ -274,7 +274,7 @@ func TestCreatePool(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) msgServer := keeper.NewMsgServerImpl(app.SpotKeeper) if tc.creatorAddr == nil { @@ -407,7 +407,7 @@ func TestCreateExitJoinPool(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) msgServer := keeper.NewMsgServerImpl(app.SpotKeeper) if tc.creatorAddr == nil { @@ -666,7 +666,7 @@ func TestMsgServerJoinPool(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) poolAddr := testutil.AccAddress() tc.initialPool.Address = poolAddr.String() @@ -868,7 +868,7 @@ func TestMsgServerExitPool(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) poolAddr := testutil.AccAddress() tc.initialPool.Address = poolAddr.String() @@ -1213,7 +1213,7 @@ func TestMsgServerSwapAssets(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) msgServer := keeper.NewMsgServerImpl(app.SpotKeeper) // fund pool account diff --git a/x/spot/keeper/params_test.go b/x/spot/keeper/params_test.go index ee034c0ce..82b9df59d 100644 --- a/x/spot/keeper/params_test.go +++ b/x/spot/keeper/params_test.go @@ -10,7 +10,7 @@ import ( ) func TestGetParams(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) params := types.DefaultParams() app.SpotKeeper.SetParams(ctx, params) diff --git a/x/spot/keeper/swap_test.go b/x/spot/keeper/swap_test.go index 69623e5a0..c775ec7cc 100644 --- a/x/spot/keeper/swap_test.go +++ b/x/spot/keeper/swap_test.go @@ -257,7 +257,7 @@ func TestSwapExactAmountIn(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) // fund pool account poolAddr := testutil.AccAddress() @@ -349,7 +349,7 @@ func TestDoubleSwapExactAmountIn(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := testapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) // fund pool account poolAddr := testutil.AccAddress() diff --git a/x/stablecoin/abci_test.go b/x/stablecoin/abci_test.go index a396519fb..ad54f6b23 100644 --- a/x/stablecoin/abci_test.go +++ b/x/stablecoin/abci_test.go @@ -5,13 +5,13 @@ import ( "time" "github.com/NibiruChain/nibiru/app" - "github.com/NibiruChain/nibiru/simapp" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" + "github.com/NibiruChain/nibiru/x/common/testutil/testapp" "github.com/NibiruChain/nibiru/x/epochs" otypes "github.com/NibiruChain/nibiru/x/oracle/types" ) @@ -115,7 +115,7 @@ func TestEpochInfoChangesBeginBlockerAndInitGenesis(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.Name, func(t *testing.T) { - app, ctx = simapp.NewTestNibiruAppAndContext(true) + app, ctx = testapp.NewNibiruTestAppAndContext(true) ctx = ctx.WithBlockHeight(1) price = tc.price @@ -131,7 +131,7 @@ func TestEpochInfoChangesBeginBlockerAndInitGenesis(t *testing.T) { } func TestEpochInfoChangesCollateralValidity(t *testing.T) { - app, ctx := simapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewNibiruTestAppAndContext(true) runBlock := func(duration time.Duration) { ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1).WithBlockTime(ctx.BlockTime().Add(duration)) diff --git a/x/stablecoin/client/cli/cli_test.go b/x/stablecoin/client/cli/cli_test.go index 7fc09151d..4cd516673 100644 --- a/x/stablecoin/client/cli/cli_test.go +++ b/x/stablecoin/client/cli/cli_test.go @@ -4,8 +4,6 @@ import ( "fmt" "testing" - "github.com/NibiruChain/nibiru/simapp" - "github.com/cosmos/cosmos-sdk/client/flags" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" sdk "github.com/cosmos/cosmos-sdk/types" @@ -20,6 +18,7 @@ import ( "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" testutilcli "github.com/NibiruChain/nibiru/x/common/testutil/cli" + "github.com/NibiruChain/nibiru/x/common/testutil/genesis" oracletypes "github.com/NibiruChain/nibiru/x/oracle/types" "github.com/NibiruChain/nibiru/x/stablecoin/client/cli" stabletypes "github.com/NibiruChain/nibiru/x/stablecoin/types" @@ -46,7 +45,7 @@ func (s *IntegrationTestSuite) SetupSuite() { app.SetPrefixes(app.AccountAddressPrefix) encodingConfig := app.MakeTestEncodingConfig() - genesisState := simapp.NewTestGenesisStateFromDefault() + genesisState := genesis.NewTestGenesisState() // x/stablecoin genesis state stableGen := stabletypes.DefaultGenesis() diff --git a/x/stablecoin/genesis_test.go b/x/stablecoin/genesis_test.go index 5b95a324f..3bae4bae4 100644 --- a/x/stablecoin/genesis_test.go +++ b/x/stablecoin/genesis_test.go @@ -5,8 +5,7 @@ import ( "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/common/testutil" - - "github.com/NibiruChain/nibiru/simapp" + "github.com/NibiruChain/nibiru/x/common/testutil/testapp" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" @@ -21,7 +20,7 @@ func TestGenesis(t *testing.T) { ModuleAccountBalance: sdk.NewCoin(denoms.USDC, sdk.ZeroInt()), } - nibiruApp, ctx := simapp.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) k := nibiruApp.StablecoinKeeper stablecoin.InitGenesis(ctx, k, genesisState) got := stablecoin.ExportGenesis(ctx, k) diff --git a/x/stablecoin/keeper/collateral_ratio_test.go b/x/stablecoin/keeper/collateral_ratio_test.go index dc1d9263f..e1171d9e8 100644 --- a/x/stablecoin/keeper/collateral_ratio_test.go +++ b/x/stablecoin/keeper/collateral_ratio_test.go @@ -9,11 +9,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - simapp2 "github.com/NibiruChain/nibiru/simapp" "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/common/testutil" + "github.com/NibiruChain/nibiru/x/common/testutil/testapp" "github.com/NibiruChain/nibiru/x/stablecoin/types" ) @@ -27,7 +27,7 @@ func TestSetCollRatio_Input(t *testing.T) { executeTest := func(t *testing.T, testCase TestCase) { tc := testCase t.Run(tc.name, func(t *testing.T) { - nibiruApp, ctx := simapp2.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) stablecoinKeeper := &nibiruApp.StablecoinKeeper err := stablecoinKeeper.SetCollRatio(ctx, tc.inCollRatio) @@ -76,7 +76,7 @@ func TestSetCollRatioUpdate(t *testing.T) { executeTest := func(t *testing.T, testCase TestCase) { tc := testCase t.Run(tc.name, func(t *testing.T) { - nibiruApp, ctx := simapp2.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) stablecoinKeeper := &nibiruApp.StablecoinKeeper oracleKeeper := &nibiruApp.OracleKeeper @@ -135,7 +135,7 @@ func TestSetCollRatioUpdate(t *testing.T) { func TestGetCollRatio_Input(t *testing.T) { testName := "GetCollRatio after setting default params returns expected value" t.Run(testName, func(t *testing.T) { - nibiruApp, ctx := simapp2.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) stablecoinKeeper := &nibiruApp.StablecoinKeeper stablecoinKeeper.SetParams(ctx, types.DefaultParams()) @@ -148,7 +148,7 @@ func TestGetCollRatio_Input(t *testing.T) { testName = "Setting to non-default value returns expected value" t.Run(testName, func(t *testing.T) { - nibiruApp, ctx := simapp2.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) stablecoinKeeper := &nibiruApp.StablecoinKeeper expectedCollRatio := sdk.MustNewDecFromStr("0.5") @@ -210,7 +210,7 @@ func TestStableRequiredForTargetCollRatio(t *testing.T) { for _, testCase := range testCases { tc := testCase t.Run(tc.name, func(t *testing.T) { - nibiruApp, ctx := simapp2.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) stablecoinKeeper := &nibiruApp.StablecoinKeeper require.NoError(t, stablecoinKeeper.SetCollRatio(ctx, tc.targetCollRatio)) require.NoError(t, nibiruApp.BankKeeper.MintCoins( @@ -284,7 +284,7 @@ func TestRecollateralizeCollAmtForTargetCollRatio(t *testing.T) { for _, testCase := range expectedPasses { tc := testCase t.Run(tc.name, func(t *testing.T) { - nibiruApp, ctx := simapp2.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) stablecoinKeeper := &nibiruApp.StablecoinKeeper require.NoError(t, stablecoinKeeper.SetCollRatio(ctx, tc.targetCollRatio)) require.NoError(t, nibiruApp.BankKeeper.MintCoins( @@ -323,7 +323,7 @@ func TestRecollateralizeCollAmtForTargetCollRatio(t *testing.T) { for _, testCase := range expectedFails { tc := testCase t.Run(tc.name, func(t *testing.T) { - nibiruApp, ctx := simapp2.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) stablecoinKeeper := &nibiruApp.StablecoinKeeper require.NoError(t, stablecoinKeeper.SetCollRatio(ctx, tc.targetCollRatio)) require.NoError(t, nibiruApp.BankKeeper.MintCoins( @@ -445,7 +445,7 @@ func TestGovAmtFromFullRecollateralize(t *testing.T) { for _, testCase := range testCases { tc := testCase t.Run(tc.name, func(t *testing.T) { - nibiruApp, ctx := simapp2.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) stablecoinKeeper := &nibiruApp.StablecoinKeeper require.NoError(t, stablecoinKeeper.SetCollRatio(ctx, tc.targetCollRatio)) require.NoError(t, nibiruApp.BankKeeper.MintCoins( @@ -696,7 +696,7 @@ func TestRecollateralize(t *testing.T) { t.Run(tc.name, func(t *testing.T) { require.EqualValues(t, tc.expectedNeededUSD, tc.scenario.CalcNeededUSD()) - nibiruApp, ctx := simapp2.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) stablecoinKeeper := &nibiruApp.StablecoinKeeper require.NoError(t, stablecoinKeeper.SetCollRatio(ctx, tc.scenario.collRatio)) require.NoError(t, nibiruApp.BankKeeper.MintCoins( @@ -754,7 +754,7 @@ func TestRecollateralize_Short(t *testing.T) { { name: "invalid address - error", test: func() { - nibiruApp, ctx := simapp2.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) goCtx := sdk.WrapSDKContext(ctx) msg := &types.MsgRecollateralize{ @@ -767,7 +767,7 @@ func TestRecollateralize_Short(t *testing.T) { { name: "prices expired - error", test: func() { - nibiruApp, ctx := simapp2.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) goCtx := sdk.WrapSDKContext(ctx) sender := testutil.AccAddress() msg := &types.MsgRecollateralize{ @@ -812,7 +812,7 @@ func TestBuyback_MsgFormat(t *testing.T) { } { tc := testCase t.Run(tc.name, func(t *testing.T) { - nibiruApp, ctx := simapp2.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) msg := types.MsgBuyback{ Creator: tc.caller, Gov: tc.gov, @@ -1065,7 +1065,7 @@ func TestBuyback(t *testing.T) { t.Run(tc.name, func(t *testing.T) { require.EqualValues(t, tc.expectedNeededUSD, tc.scenario.CalcNeededUSD()) - nibiruApp, ctx := simapp2.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) stablecoinKeeper := &nibiruApp.StablecoinKeeper require.NoError(t, stablecoinKeeper.SetCollRatio(ctx, tc.scenario.collRatio)) @@ -1180,7 +1180,7 @@ func TestBuybackGovAmtForTargetCollRatio(t *testing.T) { for _, testCase := range testCases { tc := testCase t.Run(tc.name, func(t *testing.T) { - nibiruApp, ctx := simapp2.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) stablecoinKeeper := &nibiruApp.StablecoinKeeper require.NoError(t, stablecoinKeeper.SetCollRatio(ctx, tc.scenario.collRatio)) require.NoError(t, nibiruApp.BankKeeper.MintCoins( diff --git a/x/stablecoin/keeper/grpc_query_test.go b/x/stablecoin/keeper/grpc_query_test.go index f346b2c0c..304e39ae5 100644 --- a/x/stablecoin/keeper/grpc_query_test.go +++ b/x/stablecoin/keeper/grpc_query_test.go @@ -3,16 +3,15 @@ package keeper_test import ( "testing" - "github.com/NibiruChain/nibiru/simapp" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" + "github.com/NibiruChain/nibiru/x/common/testutil/testapp" "github.com/NibiruChain/nibiru/x/stablecoin/types" ) func TestParamsQuery(t *testing.T) { - nibiruApp, ctx := simapp.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) keeper := &nibiruApp.StablecoinKeeper wctx := sdk.WrapSDKContext(ctx) params := types.DefaultParams() diff --git a/x/stablecoin/keeper/keeper_test.go b/x/stablecoin/keeper/keeper_test.go index ecab7b51f..8839d9d21 100644 --- a/x/stablecoin/keeper/keeper_test.go +++ b/x/stablecoin/keeper/keeper_test.go @@ -3,12 +3,11 @@ package keeper_test import ( "testing" - "github.com/NibiruChain/nibiru/simapp" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" + "github.com/NibiruChain/nibiru/x/common/testutil/testapp" "github.com/NibiruChain/nibiru/x/stablecoin/types" ) @@ -48,7 +47,7 @@ func TestGetAndSetParams(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - nibiruApp, ctx := simapp.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) stableKeeper := nibiruApp.StablecoinKeeper params := tc.requiredParams() @@ -61,7 +60,7 @@ func TestGetAndSetParams(t *testing.T) { func TestGetAndSetParams_Errors(t *testing.T) { t.Run("Calling Get without setting causes a panic", func(t *testing.T) { - nibiruApp, ctx := simapp.NewTestNibiruAppAndContext(false) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(false) stableKeeper := nibiruApp.StablecoinKeeper require.Panics( diff --git a/x/stablecoin/keeper/mint_burn_stable_test.go b/x/stablecoin/keeper/mint_burn_stable_test.go index c74838d0c..940f97e3f 100644 --- a/x/stablecoin/keeper/mint_burn_stable_test.go +++ b/x/stablecoin/keeper/mint_burn_stable_test.go @@ -9,11 +9,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - simapp2 "github.com/NibiruChain/nibiru/simapp" "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/common/testutil" + "github.com/NibiruChain/nibiru/x/common/testutil/testapp" "github.com/NibiruChain/nibiru/x/stablecoin/types" ) @@ -113,14 +113,13 @@ func TestMsgMintStableResponse_HappyPath(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - nibiruApp, ctx := simapp2.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) acc, _ := sdk.AccAddressFromBech32(tc.msgMint.Creator) // We get module account, to create it. nibiruApp.AccountKeeper.GetModuleAccount(ctx, types.StableEFModuleAccount) // Set up pairs for the oracle keeper. - collRatio := sdk.MustNewDecFromStr("0.9") feeRatio := sdk.MustNewDecFromStr("0.002") feeRatioEF := sdk.MustNewDecFromStr("0.5") @@ -272,7 +271,7 @@ func TestMsgMintStableResponse_NotEnoughFunds(t *testing.T) { for _, testCase := range testCases { tc := testCase t.Run(tc.name, func(t *testing.T) { - nibiruApp, ctx := simapp2.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) acc, _ := sdk.AccAddressFromBech32(tc.msgMint.Creator) // We get module account, to create it. @@ -417,7 +416,7 @@ func TestMsgBurnResponse_NotEnoughFunds(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - nibiruApp, ctx := simapp2.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) acc, _ := sdk.AccAddressFromBech32(tc.msgBurn.Creator) // Set stablecoin params @@ -543,7 +542,7 @@ func TestMsgBurnResponse_HappyPath(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - nibiruApp, ctx := simapp2.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) acc, _ := sdk.AccAddressFromBech32(tc.msgBurn.Creator) // Set stablecoin params diff --git a/x/stablecoin/keeper/msg_server_test.go b/x/stablecoin/keeper/msg_server_test.go index c44ae2bb9..c7f37b37f 100644 --- a/x/stablecoin/keeper/msg_server_test.go +++ b/x/stablecoin/keeper/msg_server_test.go @@ -3,10 +3,9 @@ package keeper_test import ( "testing" - "github.com/NibiruChain/nibiru/simapp" - "github.com/stretchr/testify/require" + "github.com/NibiruChain/nibiru/x/common/testutil/testapp" sckeeper "github.com/NibiruChain/nibiru/x/stablecoin/keeper" ) @@ -24,7 +23,7 @@ func TestNewMsgServerImpl(t *testing.T) { }) } - nibiruApp, _ := simapp.NewTestNibiruAppAndContext(true) + nibiruApp, _ := testapp.NewNibiruTestAppAndContext(true) testCases := []TestCase{ { name: "Default NibiruApp.StablecoinKeeper, should pass", diff --git a/x/stablecoin/keeper/params_test.go b/x/stablecoin/keeper/params_test.go index b5b5e2d95..74e0851eb 100644 --- a/x/stablecoin/keeper/params_test.go +++ b/x/stablecoin/keeper/params_test.go @@ -4,17 +4,16 @@ import ( "fmt" "testing" - "github.com/NibiruChain/nibiru/simapp" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/testutil/testapp" "github.com/NibiruChain/nibiru/x/stablecoin/types" ) func TestGetParams(t *testing.T) { - nibiruApp, ctx := simapp.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) stableKeeper := &nibiruApp.StablecoinKeeper params := types.DefaultParams() diff --git a/x/stablecoin/keeper/supply_test.go b/x/stablecoin/keeper/supply_test.go index c03a03562..58f880705 100644 --- a/x/stablecoin/keeper/supply_test.go +++ b/x/stablecoin/keeper/supply_test.go @@ -6,8 +6,7 @@ import ( "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/common/testutil" - - "github.com/NibiruChain/nibiru/simapp" + "github.com/NibiruChain/nibiru/x/common/testutil/testapp" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" @@ -18,7 +17,7 @@ import ( ) func TestKeeper_GetStableMarketCap(t *testing.T) { - nibiruApp, ctx := simapp.NewTestNibiruAppAndContext(false) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(false) k := nibiruApp.StablecoinKeeper // We set some supply @@ -34,7 +33,7 @@ func TestKeeper_GetStableMarketCap(t *testing.T) { } func TestKeeper_GetGovMarketCap(t *testing.T) { - nibiruApp, ctx := simapp.NewTestNibiruAppAndContext(false) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(false) keeper := nibiruApp.StablecoinKeeper poolAccountAddr := testutil.AccAddress() @@ -71,7 +70,7 @@ func TestKeeper_GetGovMarketCap(t *testing.T) { } func TestKeeper_GetLiquidityRatio_AndBands(t *testing.T) { - nibiruApp, ctx := simapp.NewTestNibiruAppAndContext(false) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(false) keeper := nibiruApp.StablecoinKeeper poolAccountAddr := testutil.AccAddress() diff --git a/x/stablecoin/module_simulation.go b/x/stablecoin/module_simulation.go index d471f2f93..edccf4f8c 100644 --- a/x/stablecoin/module_simulation.go +++ b/x/stablecoin/module_simulation.go @@ -3,10 +3,6 @@ package stablecoin import ( "math/rand" - "github.com/NibiruChain/nibiru/x/common/testutil" - - "github.com/cosmos/cosmos-sdk/baseapp" - simappparams "github.com/cosmos/cosmos-sdk/simapp/params" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" @@ -16,15 +12,6 @@ import ( "github.com/NibiruChain/nibiru/x/stablecoin/types" ) -// avoid unused import issue -var ( - _ = testutil.AccAddress - _ = scsim.FindAccount - _ = simappparams.StakePerAccount - _ = simulation.MsgEntryKind - _ = baseapp.Paramspace -) - const ( defaultWeightMsgMintStable int = 100 ) diff --git a/x/stablecoin/types/expected_keepers_test.go b/x/stablecoin/types/expected_keepers_test.go index 42dd739c3..3774e1ba9 100644 --- a/x/stablecoin/types/expected_keepers_test.go +++ b/x/stablecoin/types/expected_keepers_test.go @@ -4,10 +4,9 @@ import ( "reflect" "testing" - "github.com/NibiruChain/nibiru/simapp" - "github.com/stretchr/testify/assert" + "github.com/NibiruChain/nibiru/x/common/testutil/testapp" sctypes "github.com/NibiruChain/nibiru/x/stablecoin/types" ) @@ -20,7 +19,7 @@ func TestExpectedKeepers(t *testing.T) { appKeeper interface{} } - nibiruApp, _ := simapp.NewTestNibiruAppAndContext(true) + nibiruApp, _ := testapp.NewNibiruTestAppAndContext(true) testCases := []TestCase{ { name: "OracleKeeper from x/oracle", diff --git a/x/util/keeper/query_server_test.go b/x/util/keeper/query_server_test.go index 8cc74926a..bd8939841 100644 --- a/x/util/keeper/query_server_test.go +++ b/x/util/keeper/query_server_test.go @@ -6,14 +6,14 @@ import ( sdktypes "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" - "github.com/NibiruChain/nibiru/simapp" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/testutil/testapp" "github.com/NibiruChain/nibiru/x/util/keeper" "github.com/NibiruChain/nibiru/x/util/types" ) func TestQueryServer_ModuleAccounts(t *testing.T) { - app, ctx := simapp.NewTestNibiruAppAndContext(false) + app, ctx := testapp.NewNibiruTestAppAndContext(false) goCtx := sdktypes.WrapSDKContext(ctx) qServer := keeper.NewQueryServer(app.BankKeeper) diff --git a/x/vpool/abci_test.go b/x/vpool/abci_test.go index c7fa60e2b..bb69e6737 100644 --- a/x/vpool/abci_test.go +++ b/x/vpool/abci_test.go @@ -9,16 +9,16 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/NibiruChain/nibiru/simapp" "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/common/testutil" + "github.com/NibiruChain/nibiru/x/common/testutil/testapp" "github.com/NibiruChain/nibiru/x/vpool" "github.com/NibiruChain/nibiru/x/vpool/types" ) func TestSnapshotUpdates(t *testing.T) { - nibiruApp, ctx := simapp.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) vpoolKeeper := nibiruApp.VpoolKeeper runBlock := func(duration time.Duration) { diff --git a/x/vpool/client/cli/cli_test.go b/x/vpool/client/cli/cli_test.go index bd0192ad7..5b3287550 100644 --- a/x/vpool/client/cli/cli_test.go +++ b/x/vpool/client/cli/cli_test.go @@ -14,11 +14,11 @@ import ( abcitypes "github.com/tendermint/tendermint/abci/types" "github.com/NibiruChain/nibiru/app" - "github.com/NibiruChain/nibiru/simapp" "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" testutilcli "github.com/NibiruChain/nibiru/x/common/testutil/cli" + "github.com/NibiruChain/nibiru/x/common/testutil/genesis" oracletypes "github.com/NibiruChain/nibiru/x/oracle/types" "github.com/NibiruChain/nibiru/x/vpool/client/cli" vpooltypes "github.com/NibiruChain/nibiru/x/vpool/types" @@ -72,7 +72,7 @@ func (s *IntegrationTestSuite) SetupSuite() { app.SetPrefixes(app.AccountAddressPrefix) encodingConfig := app.MakeTestEncodingConfig() - genesisState := simapp.NewTestGenesisStateFromDefault() + genesisState := genesis.NewTestGenesisState() vpoolGenesis := vpooltypes.DefaultGenesis() vpoolGenesis.Vpools = []vpooltypes.Vpool{ START_VPOOLS[asset.Registry.Pair(denoms.ETH, denoms.NUSD)], diff --git a/x/vpool/genesis_test.go b/x/vpool/genesis_test.go index 67bd0917f..7a9922858 100644 --- a/x/vpool/genesis_test.go +++ b/x/vpool/genesis_test.go @@ -8,9 +8,9 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" - "github.com/NibiruChain/nibiru/simapp" "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/common/asset" + "github.com/NibiruChain/nibiru/x/common/testutil/testapp" "github.com/NibiruChain/nibiru/x/vpool" "github.com/NibiruChain/nibiru/x/vpool/types" ) @@ -47,7 +47,7 @@ func TestGenesis(t *testing.T) { Vpools: vpools, } - nibiruApp, ctx := simapp.NewTestNibiruAppAndContext(true) + nibiruApp, ctx := testapp.NewNibiruTestAppAndContext(true) k := nibiruApp.VpoolKeeper vpool.InitGenesis(ctx, k, genesisState) diff --git a/x/wasm/cli/cli_test.go b/x/wasm/cli/cli_test.go index 45fde1954..d41ad91e6 100644 --- a/x/wasm/cli/cli_test.go +++ b/x/wasm/cli/cli_test.go @@ -14,11 +14,11 @@ import ( "github.com/stretchr/testify/suite" "github.com/NibiruChain/nibiru/app" - "github.com/NibiruChain/nibiru/simapp" "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" testutilcli "github.com/NibiruChain/nibiru/x/common/testutil/cli" + "github.com/NibiruChain/nibiru/x/common/testutil/genesis" vpooltypes "github.com/NibiruChain/nibiru/x/vpool/types" ) @@ -46,7 +46,7 @@ func (s *IntegrationTestSuite) SetupSuite() { app.SetPrefixes(app.AccountAddressPrefix) encodingConfig := app.MakeTestEncodingConfig() - genesisState := simapp.NewTestGenesisStateFromDefault() + genesisState := genesis.NewTestGenesisState() vpoolGenesis := vpooltypes.DefaultGenesis() vpoolGenesis.Vpools = []vpooltypes.Vpool{ {