diff --git a/CHANGELOG.md b/CHANGELOG.md index 7aecf0086326..b3f0df662cad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes +* (testutil) [#12278](https:12278//github.com/cosmos/cosmos-sdk/pull/12278) Move all function from `simapp/helpers` to `testutil/sims` * (testutil) [#12233](https://github.com/cosmos/cosmos-sdk/pull/12233) Move `simapp.TestAddr` to `simtestutil.TestAddr` (`testutil/sims`) * (x/staking) [#12102](https://github.com/cosmos/cosmos-sdk/pull/12102) Staking keeper now is passed by reference instead of copy. Keeper's SetHooks no longer returns keeper. It updates the keeper in place instead. * (linting) [#12141](https://github.com/cosmos/cosmos-sdk/pull/12141) Fix usability related linting for database. This means removing the infix Prefix from `prefix.NewPrefixWriter` and such so that it is `prefix.NewWriter` and making `db.DBConnection` and such into `db.Connection` diff --git a/simapp/sim_test.go b/simapp/sim_test.go index 44145bfd6e2f..189f2d119fe3 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -18,8 +18,8 @@ import ( storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/baseapp" - "github.com/cosmos/cosmos-sdk/simapp/helpers" "github.com/cosmos/cosmos-sdk/store" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -296,7 +296,7 @@ func TestAppStateDeterminism(t *testing.T) { config.ExportParamsPath = "" config.OnOperation = false config.AllInvariants = false - config.ChainID = helpers.SimAppChainID + config.ChainID = simtestutil.SimAppChainID numSeeds := 3 numTimesToRunPerSeed := 5 diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index c3cefdc520ca..aff0a84e3cb9 100644 --- a/simapp/test_helpers.go +++ b/simapp/test_helpers.go @@ -24,7 +24,6 @@ import ( cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/depinject" "github.com/cosmos/cosmos-sdk/server/types" - "github.com/cosmos/cosmos-sdk/simapp/helpers" "github.com/cosmos/cosmos-sdk/simapp/params" "github.com/cosmos/cosmos-sdk/testutil/mock" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -275,11 +274,11 @@ func SignCheckDeliver( t *testing.T, txCfg client.TxConfig, app *bam.BaseApp, header tmproto.Header, msgs []sdk.Msg, chainID string, accNums, accSeqs []uint64, expSimPass, expPass bool, priv ...cryptotypes.PrivKey, ) (sdk.GasInfo, *sdk.Result, error) { - tx, err := helpers.GenSignedMockTx( + tx, err := simtestutil.GenSignedMockTx( txCfg, msgs, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 0)}, - helpers.DefaultGenTxGas, + simtestutil.DefaultGenTxGas, chainID, accNums, accSeqs, @@ -325,11 +324,11 @@ func GenSequenceOfTxs(txGen client.TxConfig, msgs []sdk.Msg, accNums []uint64, i txs := make([]sdk.Tx, numToGenerate) var err error for i := 0; i < numToGenerate; i++ { - txs[i], err = helpers.GenSignedMockTx( + txs[i], err = simtestutil.GenSignedMockTx( txGen, msgs, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 0)}, - helpers.DefaultGenTxGas, + simtestutil.DefaultGenTxGas, "", accNums, initSeqNums, diff --git a/simapp/utils.go b/simapp/utils.go index 8c4a5abd1b78..4ab543464121 100644 --- a/simapp/utils.go +++ b/simapp/utils.go @@ -9,7 +9,7 @@ import ( dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/simapp/helpers" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" "github.com/cosmos/cosmos-sdk/types/module" @@ -25,7 +25,7 @@ func SetupSimulation(dirPrefix, dbName string) (simtypes.Config, dbm.DB, string, } config := NewConfigFromFlags() - config.ChainID = helpers.SimAppChainID + config.ChainID = simtestutil.SimAppChainID var logger log.Logger if FlagVerboseValue { diff --git a/testutil/sims/app_helpers.go b/testutil/sims/app_helpers.go index be27dc96eddd..2f00346b50dc 100644 --- a/testutil/sims/app_helpers.go +++ b/testutil/sims/app_helpers.go @@ -26,6 +26,12 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) +// SimAppChainID hardcoded chainID for simulation +const ( + DefaultGenTxGas = 10000000 + SimAppChainID = "simulation-app" +) + // DefaultConsensusParams defines the default Tendermint consensus params used in // SimApp testing. var DefaultConsensusParams = &tmproto.ConsensusParams{ diff --git a/simapp/helpers/test_helpers.go b/testutil/sims/tx_helpers.go similarity index 77% rename from simapp/helpers/test_helpers.go rename to testutil/sims/tx_helpers.go index 0dc88f9b4623..ef79b9e393b4 100644 --- a/simapp/helpers/test_helpers.go +++ b/testutil/sims/tx_helpers.go @@ -1,4 +1,4 @@ -package helpers +package sims import ( "math/rand" @@ -12,14 +12,8 @@ import ( authsign "github.com/cosmos/cosmos-sdk/x/auth/signing" ) -// SimAppChainID hardcoded chainID for simulation -const ( - DefaultGenTxGas = 10000000 - SimAppChainID = "simulation-app" -) - // GenSignedMockTx generates a signed mock transaction. -func GenSignedMockTx(gen client.TxConfig, msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, chainID string, accNums, accSeqs []uint64, priv ...cryptotypes.PrivKey) (sdk.Tx, error) { +func GenSignedMockTx(txConfig client.TxConfig, msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, chainID string, accNums, accSeqs []uint64, priv ...cryptotypes.PrivKey) (sdk.Tx, error) { sigs := make([]signing.SignatureV2, len(priv)) // create a random length memo @@ -27,7 +21,7 @@ func GenSignedMockTx(gen client.TxConfig, msgs []sdk.Msg, feeAmt sdk.Coins, gas memo := simulation.RandStringOfLength(r, simulation.RandIntBetween(r, 0, 100)) - signMode := gen.SignModeHandler().DefaultMode() + signMode := txConfig.SignModeHandler().DefaultMode() // 1st round: set SignatureV2 with empty signatures, to set correct // signer infos. @@ -41,7 +35,7 @@ func GenSignedMockTx(gen client.TxConfig, msgs []sdk.Msg, feeAmt sdk.Coins, gas } } - tx := gen.NewTxBuilder() + tx := txConfig.NewTxBuilder() err := tx.SetMsgs(msgs...) if err != nil { return nil, err @@ -63,7 +57,7 @@ func GenSignedMockTx(gen client.TxConfig, msgs []sdk.Msg, feeAmt sdk.Coins, gas Sequence: accSeqs[i], PubKey: p.PubKey(), } - signBytes, err := gen.SignModeHandler().GetSignBytes(signMode, signerData, tx.GetTx()) + signBytes, err := txConfig.SignModeHandler().GetSignBytes(signMode, signerData, tx.GetTx()) if err != nil { panic(err) } diff --git a/x/auth/ante/feegrant_test.go b/x/auth/ante/feegrant_test.go index c8689ca3c7a1..5031a37cd312 100644 --- a/x/auth/ante/feegrant_test.go +++ b/x/auth/ante/feegrant_test.go @@ -11,7 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - "github.com/cosmos/cosmos-sdk/simapp/helpers" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/simulation" @@ -144,7 +144,7 @@ func (suite *AnteTestSuite) TestDeductFeesNoDelegation() { accNums, seqs = []uint64{acc.GetAccountNumber()}, []uint64{acc.GetSequence()} } - tx, err := genTxWithFeeGranter(protoTxCfg, msgs, fee, helpers.DefaultGenTxGas, ctx.ChainID(), accNums, seqs, tc.feeAccount, privs...) + tx, err := genTxWithFeeGranter(protoTxCfg, msgs, fee, simtestutil.DefaultGenTxGas, ctx.ChainID(), accNums, seqs, tc.feeAccount, privs...) suite.Require().NoError(err) _, err = feeAnteHandler(ctx, tx, false) // tests only feegrant ante if tc.valid { diff --git a/x/authz/simulation/operations.go b/x/authz/simulation/operations.go index 07b878b57259..5209ca034306 100644 --- a/x/authz/simulation/operations.go +++ b/x/authz/simulation/operations.go @@ -7,8 +7,8 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/simapp/helpers" simappparams "github.com/cosmos/cosmos-sdk/simapp/params" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" @@ -118,11 +118,11 @@ func SimulateMsgGrant(ak authz.AccountKeeper, bk authz.BankKeeper, _ keeper.Keep return simtypes.NoOpMsg(authz.ModuleName, TypeMsgGrant, err.Error()), nil, err } txCfg := simappparams.MakeTestEncodingConfig().TxConfig - tx, err := helpers.GenSignedMockTx( + tx, err := simtestutil.GenSignedMockTx( txCfg, []sdk.Msg{msg}, fees, - helpers.DefaultGenTxGas, + simtestutil.DefaultGenTxGas, chainID, []uint64{granterAcc.GetAccountNumber()}, []uint64{granterAcc.GetSequence()}, @@ -188,11 +188,11 @@ func SimulateMsgRevoke(ak authz.AccountKeeper, bk authz.BankKeeper, k keeper.Kee msg := authz.NewMsgRevoke(granterAddr, granteeAddr, a.MsgTypeURL()) txCfg := simappparams.MakeTestEncodingConfig().TxConfig account := ak.GetAccount(ctx, granterAddr) - tx, err := helpers.GenSignedMockTx( + tx, err := simtestutil.GenSignedMockTx( txCfg, []sdk.Msg{&msg}, fees, - helpers.DefaultGenTxGas, + simtestutil.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, @@ -277,11 +277,11 @@ func SimulateMsgExec(ak authz.AccountKeeper, bk authz.BankKeeper, k keeper.Keepe txCfg := simappparams.MakeTestEncodingConfig().TxConfig granteeAcc := ak.GetAccount(ctx, granteeAddr) - tx, err := helpers.GenSignedMockTx( + tx, err := simtestutil.GenSignedMockTx( txCfg, []sdk.Msg{&msgExec}, fees, - helpers.DefaultGenTxGas, + simtestutil.DefaultGenTxGas, chainID, []uint64{granteeAcc.GetAccountNumber()}, []uint64{granteeAcc.GetSequence()}, diff --git a/x/authz/simulation/operations_test.go b/x/authz/simulation/operations_test.go index fab35b4d63c9..00735b175db0 100644 --- a/x/authz/simulation/operations_test.go +++ b/x/authz/simulation/operations_test.go @@ -57,6 +57,7 @@ func (suite *SimTestSuite) TestWeightedOperations() { for i, w := range weightedOps { op, _, err := w.Op()(r, suite.app.BaseApp, suite.ctx, accs, "") require.NoError(err) + // the following checks are very much dependent from the ordering of the output given // by WeightedOperations. if the ordering in WeightedOperations changes some tests // will fail diff --git a/x/bank/simulation/operations.go b/x/bank/simulation/operations.go index 5ed26c896316..3873bfa3264d 100644 --- a/x/bank/simulation/operations.go +++ b/x/bank/simulation/operations.go @@ -6,8 +6,8 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - "github.com/cosmos/cosmos-sdk/simapp/helpers" simappparams "github.com/cosmos/cosmos-sdk/simapp/params" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/bank/keeper" @@ -137,11 +137,11 @@ func sendMsgSend( } } txGen := simappparams.MakeTestEncodingConfig().TxConfig - tx, err := helpers.GenSignedMockTx( + tx, err := simtestutil.GenSignedMockTx( txGen, []sdk.Msg{msg}, fees, - helpers.DefaultGenTxGas, + simtestutil.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, @@ -350,11 +350,11 @@ func sendMsgMultiSend( } txGen := simappparams.MakeTestEncodingConfig().TxConfig - tx, err := helpers.GenSignedMockTx( + tx, err := simtestutil.GenSignedMockTx( txGen, []sdk.Msg{msg}, fees, - helpers.DefaultGenTxGas, + simtestutil.DefaultGenTxGas, chainID, accountNumbers, sequenceNumbers, diff --git a/x/bank/simulation/operations_test.go b/x/bank/simulation/operations_test.go index f50c2b944885..f20a5c1e0a62 100644 --- a/x/bank/simulation/operations_test.go +++ b/x/bank/simulation/operations_test.go @@ -53,7 +53,9 @@ func (suite *SimTestSuite) TestWeightedOperations() { } for i, w := range weightesOps { - operationMsg, _, _ := w.Op()(r, suite.app.BaseApp, suite.ctx, accs, "") + operationMsg, _, err := w.Op()(r, suite.app.BaseApp, suite.ctx, accs, "") + suite.Require().NoError(err) + // the following checks are very much dependent from the ordering of the output given // by WeightedOperations. if the ordering in WeightedOperations changes some tests // will fail diff --git a/x/distribution/simulation/operations_test.go b/x/distribution/simulation/operations_test.go index fdde63e43caa..37f8c4a38226 100644 --- a/x/distribution/simulation/operations_test.go +++ b/x/distribution/simulation/operations_test.go @@ -45,7 +45,9 @@ func (suite *SimTestSuite) TestWeightedOperations() { } for i, w := range weightesOps { - operationMsg, _, _ := w.Op()(r, suite.app.BaseApp, suite.ctx, accs, "") + operationMsg, _, err := w.Op()(r, suite.app.BaseApp, suite.ctx, accs, "") + suite.Require().NoError(err) + // the following checks are very much dependent from the ordering of the output given // by WeightedOperations. if the ordering in WeightedOperations changes some tests // will fail diff --git a/x/feegrant/simulation/operations_test.go b/x/feegrant/simulation/operations_test.go index 71721becc0e7..1c43eddb73f4 100644 --- a/x/feegrant/simulation/operations_test.go +++ b/x/feegrant/simulation/operations_test.go @@ -85,7 +85,9 @@ func (suite *SimTestSuite) TestWeightedOperations() { } for i, w := range weightedOps { - operationMsg, _, _ := w.Op()(r, app.BaseApp, ctx, accs, ctx.ChainID()) + operationMsg, _, err := w.Op()(r, app.BaseApp, ctx, accs, ctx.ChainID()) + require.NoError(err) + // the following checks are very much dependent from the ordering of the output given // by WeightedOperations. if the ordering in WeightedOperations changes some tests // will fail diff --git a/x/genutil/gentx_test.go b/x/genutil/gentx_test.go index a83b310c46d1..ae9c7ed365bc 100644 --- a/x/genutil/gentx_test.go +++ b/x/genutil/gentx_test.go @@ -10,8 +10,8 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/simapp" - "github.com/cosmos/cosmos-sdk/simapp/helpers" simappparams "github.com/cosmos/cosmos-sdk/simapp/params" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/bank/testutil" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -232,11 +232,11 @@ func (suite *GenTxTestSuite) TestDeliverGenTxs() { _ = suite.setAccountBalance(addr2, 1) msg := banktypes.NewMsgSend(addr1, addr2, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 1)}) - tx, err := helpers.GenSignedMockTx( + tx, err := simtestutil.GenSignedMockTx( suite.encodingConfig.TxConfig, []sdk.Msg{msg}, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 10)}, - helpers.DefaultGenTxGas, + simtestutil.DefaultGenTxGas, suite.ctx.ChainID(), []uint64{7}, []uint64{0}, diff --git a/x/gov/simulation/operations.go b/x/gov/simulation/operations.go index ff7fc4908a49..591eb47abc00 100644 --- a/x/gov/simulation/operations.go +++ b/x/gov/simulation/operations.go @@ -7,8 +7,8 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/simapp/helpers" simappparams "github.com/cosmos/cosmos-sdk/simapp/params" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/gov/keeper" @@ -170,11 +170,11 @@ func SimulateMsgSubmitProposal( } txGen := simappparams.MakeTestEncodingConfig().TxConfig - tx, err := helpers.GenSignedMockTx( + tx, err := simtestutil.GenSignedMockTx( txGen, []sdk.Msg{msg}, fees, - helpers.DefaultGenTxGas, + simtestutil.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, diff --git a/x/gov/simulation/operations_test.go b/x/gov/simulation/operations_test.go index 59c19d870707..685c5596d9b9 100644 --- a/x/gov/simulation/operations_test.go +++ b/x/gov/simulation/operations_test.go @@ -86,6 +86,8 @@ func TestWeightedOperations(t *testing.T) { for i, w := range weightesOps { operationMsg, _, _ := w.Op()(r, app.BaseApp, ctx, accs, ctx.ChainID()) + // require.NoError(t, err) // TODO check if it should be NoError + // the following checks are very much dependent from the ordering of the output given // by WeightedOperations. if the ordering in WeightedOperations changes some tests // will fail diff --git a/x/group/simulation/operations.go b/x/group/simulation/operations.go index 2568acb62341..b4c199c9b68f 100644 --- a/x/group/simulation/operations.go +++ b/x/group/simulation/operations.go @@ -10,8 +10,8 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/simapp/helpers" simappparams "github.com/cosmos/cosmos-sdk/simapp/params" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -261,11 +261,11 @@ func SimulateMsgCreateGroup(ak group.AccountKeeper, bk group.BankKeeper) simtype msg := &group.MsgCreateGroup{Admin: accAddr, Members: members, Metadata: simtypes.RandStringOfLength(r, 10)} txGen := simappparams.MakeTestEncodingConfig().TxConfig - tx, err := helpers.GenSignedMockTx( + tx, err := simtestutil.GenSignedMockTx( txGen, []sdk.Msg{msg}, fees, - helpers.DefaultGenTxGas, + simtestutil.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, @@ -320,11 +320,11 @@ func SimulateMsgCreateGroupWithPolicy(ak group.AccountKeeper, bk group.BankKeepe } txGen := simappparams.MakeTestEncodingConfig().TxConfig - tx, err := helpers.GenSignedMockTx( + tx, err := simtestutil.GenSignedMockTx( txGen, []sdk.Msg{msg}, fees, - helpers.DefaultGenTxGas, + simtestutil.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, @@ -379,11 +379,11 @@ func SimulateMsgCreateGroupPolicy(ak group.AccountKeeper, bk group.BankKeeper, k } txGen := simappparams.MakeTestEncodingConfig().TxConfig - tx, err := helpers.GenSignedMockTx( + tx, err := simtestutil.GenSignedMockTx( txGen, []sdk.Msg{msg}, fees, - helpers.DefaultGenTxGas, + simtestutil.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, @@ -454,11 +454,11 @@ func SimulateMsgSubmitProposal(ak group.AccountKeeper, bk group.BankKeeper, k ke } txGen := simappparams.MakeTestEncodingConfig().TxConfig - tx, err := helpers.GenSignedMockTx( + tx, err := simtestutil.GenSignedMockTx( txGen, []sdk.Msg{&msg}, fees, - helpers.DefaultGenTxGas, + simtestutil.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, @@ -513,11 +513,11 @@ func SimulateMsgUpdateGroupAdmin(ak group.AccountKeeper, bk group.BankKeeper, k } txGen := simappparams.MakeTestEncodingConfig().TxConfig - tx, err := helpers.GenSignedMockTx( + tx, err := simtestutil.GenSignedMockTx( txGen, []sdk.Msg{&msg}, fees, - helpers.DefaultGenTxGas, + simtestutil.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, @@ -563,11 +563,11 @@ func SimulateMsgUpdateGroupMetadata(ak group.AccountKeeper, bk group.BankKeeper, } txGen := simappparams.MakeTestEncodingConfig().TxConfig - tx, err := helpers.GenSignedMockTx( + tx, err := simtestutil.GenSignedMockTx( txGen, []sdk.Msg{&msg}, fees, - helpers.DefaultGenTxGas, + simtestutil.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, @@ -642,11 +642,11 @@ func SimulateMsgUpdateGroupMembers(ak group.AccountKeeper, } txGen := simappparams.MakeTestEncodingConfig().TxConfig - tx, err := helpers.GenSignedMockTx( + tx, err := simtestutil.GenSignedMockTx( txGen, []sdk.Msg{&msg}, fees, - helpers.DefaultGenTxGas, + simtestutil.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, @@ -701,11 +701,11 @@ func SimulateMsgUpdateGroupPolicyAdmin(ak group.AccountKeeper, bk group.BankKeep } txGen := simappparams.MakeTestEncodingConfig().TxConfig - tx, err := helpers.GenSignedMockTx( + tx, err := simtestutil.GenSignedMockTx( txGen, []sdk.Msg{&msg}, fees, - helpers.DefaultGenTxGas, + simtestutil.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, @@ -762,11 +762,11 @@ func SimulateMsgUpdateGroupPolicyDecisionPolicy(ak group.AccountKeeper, } txGen := simappparams.MakeTestEncodingConfig().TxConfig - tx, err := helpers.GenSignedMockTx( + tx, err := simtestutil.GenSignedMockTx( txGen, []sdk.Msg{msg}, fees, - helpers.DefaultGenTxGas, + simtestutil.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, @@ -813,11 +813,11 @@ func SimulateMsgUpdateGroupPolicyMetadata(ak group.AccountKeeper, } txGen := simappparams.MakeTestEncodingConfig().TxConfig - tx, err := helpers.GenSignedMockTx( + tx, err := simtestutil.GenSignedMockTx( txGen, []sdk.Msg{&msg}, fees, - helpers.DefaultGenTxGas, + simtestutil.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, @@ -915,11 +915,11 @@ func SimulateMsgWithdrawProposal(ak group.AccountKeeper, } txGen := simappparams.MakeTestEncodingConfig().TxConfig - tx, err := helpers.GenSignedMockTx( + tx, err := simtestutil.GenSignedMockTx( txGen, []sdk.Msg{&msg}, fees, - helpers.DefaultGenTxGas, + simtestutil.DefaultGenTxGas, chainID, []uint64{proposerAcc.GetAccountNumber()}, []uint64{proposerAcc.GetSequence()}, @@ -1020,11 +1020,11 @@ func SimulateMsgVote(ak group.AccountKeeper, Metadata: simtypes.RandStringOfLength(r, 10), } txGen := simappparams.MakeTestEncodingConfig().TxConfig - tx, err := helpers.GenSignedMockTx( + tx, err := simtestutil.GenSignedMockTx( txGen, []sdk.Msg{&msg}, fees, - helpers.DefaultGenTxGas, + simtestutil.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, @@ -1098,11 +1098,11 @@ func SimulateMsgExec(ak group.AccountKeeper, Executor: acc.Address.String(), } txGen := simappparams.MakeTestEncodingConfig().TxConfig - tx, err := helpers.GenSignedMockTx( + tx, err := simtestutil.GenSignedMockTx( txGen, []sdk.Msg{&msg}, fees, - helpers.DefaultGenTxGas, + simtestutil.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, @@ -1160,11 +1160,11 @@ func SimulateMsgLeaveGroup(k keeper.Keeper, ak group.AccountKeeper, bk group.Ban } txGen := simappparams.MakeTestEncodingConfig().TxConfig - tx, err := helpers.GenSignedMockTx( + tx, err := simtestutil.GenSignedMockTx( txGen, []sdk.Msg{msg}, fees, - helpers.DefaultGenTxGas, + simtestutil.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, diff --git a/x/group/simulation/operations_test.go b/x/group/simulation/operations_test.go index 90476db47fd6..f57784e73fee 100644 --- a/x/group/simulation/operations_test.go +++ b/x/group/simulation/operations_test.go @@ -67,7 +67,9 @@ func (suite *SimTestSuite) TestWeightedOperations() { } for i, w := range weightedOps { - operationMsg, _, _ := w.Op()(r, suite.app.BaseApp, suite.ctx, accs, "") + operationMsg, _, err := w.Op()(r, suite.app.BaseApp, suite.ctx, accs, "") + suite.Require().NoError(err) + // the following checks are very much dependent from the ordering of the output given // by WeightedOperations. if the ordering in WeightedOperations changes some tests // will fail diff --git a/x/nft/simulation/operations.go b/x/nft/simulation/operations.go index 904745c54fb0..e85410066eb1 100644 --- a/x/nft/simulation/operations.go +++ b/x/nft/simulation/operations.go @@ -6,15 +6,14 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/simapp/helpers" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/auth/tx" - "github.com/cosmos/cosmos-sdk/x/nft" + "github.com/cosmos/cosmos-sdk/x/simulation" + "github.com/cosmos/cosmos-sdk/x/nft" "github.com/cosmos/cosmos-sdk/x/nft/keeper" - - "github.com/cosmos/cosmos-sdk/x/simulation" ) //nolint:gosec // these are not hardcoded credentials. @@ -97,26 +96,26 @@ func SimulateMsgSend( } txCfg := tx.NewTxConfig(cdc, tx.DefaultSignModes) - tx, err := helpers.GenSignedMockTx( + tx, err := simtestutil.GenSignedMockTx( txCfg, []sdk.Msg{msg}, fees, - helpers.DefaultGenTxGas, + simtestutil.DefaultGenTxGas, chainID, []uint64{senderAcc.GetAccountNumber()}, []uint64{senderAcc.GetSequence()}, sender.PrivKey, ) + if err != nil { return simtypes.NoOpMsg(nft.ModuleName, TypeMsgSend, "unable to generate mock tx"), nil, err } - _, _, err = app.SimDeliver(txCfg.TxEncoder(), tx) - if err != nil { + if _, _, err = app.SimDeliver(txCfg.TxEncoder(), tx); err != nil { return simtypes.NoOpMsg(nft.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, err } - return simtypes.NewOperationMsg(msg, true, "", cdc), nil, err + return simtypes.NewOperationMsg(msg, true, "", cdc), nil, nil } } diff --git a/x/nft/simulation/operations_test.go b/x/nft/simulation/operations_test.go index 943f6dfac8fc..f417fb9efa6e 100644 --- a/x/nft/simulation/operations_test.go +++ b/x/nft/simulation/operations_test.go @@ -54,6 +54,13 @@ func (suite *SimTestSuite) SetupTest() { suite.app = app suite.ctx = app.BaseApp.NewContext(false, tmproto.Header{}) + + suite.app.BeginBlock(abci.RequestBeginBlock{ + Header: tmproto.Header{ + Height: suite.app.LastBlockHeight() + 1, + AppHash: suite.app.LastCommitID().Hash, + }, + }) } func (suite *SimTestSuite) TestWeightedOperations() { @@ -80,12 +87,14 @@ func (suite *SimTestSuite) TestWeightedOperations() { } for i, w := range weightedOps { - operationMsg, _, _ := w.Op()(r, suite.app.BaseApp, suite.ctx, accs, "") + operationMsg, _, err := w.Op()(r, suite.app.BaseApp, suite.ctx, accs, "") + suite.Require().NoError(err) + // the following checks are very much dependent from the ordering of the output given // by WeightedOperations. if the ordering in WeightedOperations changes some tests // will fail suite.Require().Equal(expected[i].weight, w.Weight(), "weight should be the same") - suite.Require().Contains(expected[i].opMsgRoute, operationMsg.Route, "route should be the same") + suite.Require().Equal(expected[i].opMsgRoute, operationMsg.Route, "route should be the same") suite.Require().Equal(expected[i].opMsgName, operationMsg.Name, "operation Msg name should be the same") } } @@ -113,14 +122,6 @@ func (suite *SimTestSuite) TestSimulateMsgSend() { blockTime := time.Now().UTC() ctx := suite.ctx.WithBlockTime(blockTime) - // begin a new block - suite.app.BeginBlock(abci.RequestBeginBlock{ - Header: tmproto.Header{ - Height: suite.app.LastBlockHeight() + 1, - AppHash: suite.app.LastCommitID().Hash, - }, - }) - // execute operation registry := suite.interfaceRegistry op := simulation.SimulateMsgSend(codec.NewProtoCodec(registry), suite.accountKeeper, suite.bankKeeper, suite.nftKeeper) diff --git a/x/simulation/util.go b/x/simulation/util.go index 3c72f67538cb..cde482813574 100644 --- a/x/simulation/util.go +++ b/x/simulation/util.go @@ -9,7 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/simapp/helpers" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" ) @@ -100,11 +100,11 @@ func GenAndDeliverTxWithRandFees(txCtx OperationInput) (simtypes.OperationMsg, [ // GenAndDeliverTx generates a transactions and delivers it. func GenAndDeliverTx(txCtx OperationInput, fees sdk.Coins) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { account := txCtx.AccountKeeper.GetAccount(txCtx.Context, txCtx.SimAccount.Address) - tx, err := helpers.GenSignedMockTx( + tx, err := simtestutil.GenSignedMockTx( txCtx.TxGen, []sdk.Msg{txCtx.Msg}, fees, - helpers.DefaultGenTxGas, + simtestutil.DefaultGenTxGas, txCtx.Context.ChainID(), []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, diff --git a/x/slashing/simulation/operations.go b/x/slashing/simulation/operations.go index a339fec3b0bf..533fb9a9cec4 100644 --- a/x/slashing/simulation/operations.go +++ b/x/slashing/simulation/operations.go @@ -6,8 +6,8 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/simapp/helpers" simappparams "github.com/cosmos/cosmos-sdk/simapp/params" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" @@ -88,11 +88,11 @@ func SimulateMsgUnjail(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Kee msg := types.NewMsgUnjail(validator.GetOperator()) txGen := simappparams.MakeTestEncodingConfig().TxConfig - tx, err := helpers.GenSignedMockTx( + tx, err := simtestutil.GenSignedMockTx( txGen, []sdk.Msg{msg}, fees, - helpers.DefaultGenTxGas, + simtestutil.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, diff --git a/x/slashing/simulation/operations_test.go b/x/slashing/simulation/operations_test.go index a0dbffb1f360..87c589cf658b 100644 --- a/x/slashing/simulation/operations_test.go +++ b/x/slashing/simulation/operations_test.go @@ -44,7 +44,9 @@ func TestWeightedOperations(t *testing.T) { weightesOps := simulation.WeightedOperations(appParams, cdc, app.AccountKeeper, app.BankKeeper, app.SlashingKeeper, app.StakingKeeper) for i, w := range weightesOps { - operationMsg, _, _ := w.Op()(r, app.BaseApp, ctx, accs, ctx.ChainID()) + operationMsg, _, err := w.Op()(r, app.BaseApp, ctx, accs, ctx.ChainID()) + require.NoError(t, err) + // the following checks are very much dependent from the ordering of the output given // by WeightedOperations. if the ordering in WeightedOperations changes some tests // will fail diff --git a/x/staking/simulation/operations_test.go b/x/staking/simulation/operations_test.go index aa07bafe0649..6fb7bf7f9526 100644 --- a/x/staking/simulation/operations_test.go +++ b/x/staking/simulation/operations_test.go @@ -57,6 +57,8 @@ func TestWeightedOperations(t *testing.T) { for i, w := range weightesOps { operationMsg, _, _ := w.Op()(r, app.BaseApp, ctx, accs, ctx.ChainID()) + // require.NoError(t, err) // TODO check if it should be NoError + // the following checks are very much dependent from the ordering of the output given // by WeightedOperations. if the ordering in WeightedOperations changes some tests // will fail