From b9f86dd7fe79e2810469a4a86574a0ba6b3bc21f Mon Sep 17 00:00:00 2001 From: SaReN Date: Tue, 14 Jul 2020 23:03:31 +0530 Subject: [PATCH] Update simapp helpers to use Tx generator (#6655) * update helpers to use tx generator * update modules to use tx generator * add todo * update ibc to use txG * fix lint * Eliminate panics from Gentx * update module ops * fix lgtm alert * update ibc with txG * Remove todo Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * move simapp/helpers to test_helpers * revert simapp/helpers to test_helpers * revert renaming * address suggestion Co-authored-by: Aaron Craelius * fix tests Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Co-authored-by: Aaron Craelius Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- simapp/helpers/test_helpers.go | 65 ++++++++++++++++++------- simapp/simd/cmd/genaccounts.go | 4 +- simapp/test_helpers.go | 23 ++++++--- x/bank/app_test.go | 18 ++++--- x/bank/bench_test.go | 9 +++- x/bank/simulation/operations.go | 15 ++++-- x/distribution/simulation/operations.go | 28 +++++++++-- x/gov/simulation/operations.go | 22 +++++++-- x/ibc/testing/chain.go | 7 ++- x/slashing/app_test.go | 5 +- x/slashing/simulation/operations.go | 7 ++- x/staking/app_test.go | 9 ++-- x/staking/simulation/operations.go | 35 +++++++++++-- 13 files changed, 187 insertions(+), 60 deletions(-) diff --git a/simapp/helpers/test_helpers.go b/simapp/helpers/test_helpers.go index fa7b6d648b..5f71e24a8c 100644 --- a/simapp/helpers/test_helpers.go +++ b/simapp/helpers/test_helpers.go @@ -6,9 +6,11 @@ import ( "github.com/tendermint/tendermint/crypto" + "github.com/cosmos/cosmos-sdk/client" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/simulation" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/cosmos/cosmos-sdk/types/tx/signing" + authsign "github.com/cosmos/cosmos-sdk/x/auth/signing" ) // SimAppChainID hardcoded chainID for simulation @@ -18,31 +20,58 @@ const ( ) // GenTx generates a signed mock transaction. -func GenTx(msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, chainID string, accnums []uint64, seq []uint64, priv ...crypto.PrivKey) authtypes.StdTx { - fee := authtypes.StdFee{ //nolint:staticcheck // SA1019: authtypes.StdFee is deprecated - Amount: feeAmt, - Gas: gas, - } - - sigs := make([]authtypes.StdSignature, len(priv)) //nolint:staticcheck // SA1019: authtypes.StdSignature is deprecated +func GenTx(gen client.TxGenerator, msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, chainID string, accnums []uint64, seq []uint64, priv ...crypto.PrivKey) (sdk.Tx, error) { + sigs := make([]signing.SignatureV2, len(priv)) // create a random length memo r := rand.New(rand.NewSource(time.Now().UnixNano())) memo := simulation.RandStringOfLength(r, simulation.RandIntBetween(r, 0, 100)) - for i, p := range priv { - // use a empty chainID for ease of testing - sig, err := p.Sign(authtypes.StdSignBytes(chainID, accnums[i], seq[i], fee, msgs, memo)) - if err != nil { - panic(err) - } + signMode := gen.SignModeHandler().DefaultMode() - sigs[i] = authtypes.StdSignature{ //nolint:staticcheck // SA1019: authtypes.StdSignature is deprecated - PubKey: p.PubKey().Bytes(), - Signature: sig, + for i, p := range priv { + sigs[i] = signing.SignatureV2{ + PubKey: p.PubKey(), + Data: &signing.SingleSignatureData{ + SignMode: signMode, + }, } } - return authtypes.NewStdTx(msgs, fee, sigs, memo) + tx := gen.NewTxBuilder() + err := tx.SetMsgs(msgs...) + if err != nil { + return nil, err + } + err = tx.SetSignatures(sigs...) + if err != nil { + return nil, err + } + tx.SetMemo(memo) + tx.SetFeeAmount(feeAmt) + tx.SetGasLimit(gas) + for i, p := range priv { + // use a empty chainID for ease of testing + signerData := authsign.SignerData{ + ChainID: chainID, + AccountNumber: accnums[i], + AccountSequence: seq[i], + } + signBytes, err := gen.SignModeHandler().GetSignBytes(signMode, signerData, tx.GetTx()) + if err != nil { + panic(err) + } + sig, err := p.Sign(signBytes) + if err != nil { + panic(err) + } + sigs[i].Data.(*signing.SingleSignatureData).Signature = sig + err = tx.SetSignatures(sigs...) + if err != nil { + panic(err) + } + } + + return tx.GetTx(), nil } diff --git a/simapp/simd/cmd/genaccounts.go b/simapp/simd/cmd/genaccounts.go index d5b4ce67dc..5dddc2ee78 100644 --- a/simapp/simd/cmd/genaccounts.go +++ b/simapp/simd/cmd/genaccounts.go @@ -39,8 +39,8 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) - depCdc := clientCtx.Codec - cdc := clientCtx.JSONMarshaler.(codec.Marshaler) + depCdc := clientCtx.JSONMarshaler + cdc := depCdc.(codec.Marshaler) serverCtx := server.GetServerContextFromCmd(cmd) config := serverCtx.Config diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index 6ba55f418a..758b84d4b6 100644 --- a/simapp/test_helpers.go +++ b/simapp/test_helpers.go @@ -17,6 +17,7 @@ import ( dbm "github.com/tendermint/tm-db" bam "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" sdk "github.com/cosmos/cosmos-sdk/types" @@ -312,11 +313,12 @@ func CheckBalance(t *testing.T, app *SimApp, addr sdk.AccAddress, balances sdk.C // the parameter 'expPass' against the result. A corresponding result is // returned. func SignCheckDeliver( - t *testing.T, cdc *codec.Codec, app *bam.BaseApp, header abci.Header, msgs []sdk.Msg, + t *testing.T, txGen client.TxGenerator, app *bam.BaseApp, header abci.Header, msgs []sdk.Msg, accNums, seq []uint64, expSimPass, expPass bool, priv ...crypto.PrivKey, ) (sdk.GasInfo, *sdk.Result, error) { - tx := helpers.GenTx( + tx, err := helpers.GenTx( + txGen, msgs, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 0)}, helpers.DefaultGenTxGas, @@ -325,8 +327,8 @@ func SignCheckDeliver( seq, priv..., ) - - txBytes, err := cdc.MarshalBinaryBare(tx) + require.NoError(t, err) + txBytes, err := txGen.TxEncoder()(tx) require.Nil(t, err) // Must simulate now as CheckTx doesn't run Msgs anymore @@ -361,10 +363,12 @@ func SignCheckDeliver( // GenSequenceOfTxs generates a set of signed transactions of messages, such // that they differ only by having the sequence numbers incremented between // every transaction. -func GenSequenceOfTxs(msgs []sdk.Msg, accNums []uint64, initSeqNums []uint64, numToGenerate int, priv ...crypto.PrivKey) []authtypes.StdTx { - txs := make([]authtypes.StdTx, numToGenerate) +func GenSequenceOfTxs(txGen client.TxGenerator, msgs []sdk.Msg, accNums []uint64, initSeqNums []uint64, numToGenerate int, priv ...crypto.PrivKey) ([]sdk.Tx, error) { + txs := make([]sdk.Tx, numToGenerate) + var err error for i := 0; i < numToGenerate; i++ { - txs[i] = helpers.GenTx( + txs[i], err = helpers.GenTx( + txGen, msgs, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 0)}, helpers.DefaultGenTxGas, @@ -373,10 +377,13 @@ func GenSequenceOfTxs(msgs []sdk.Msg, accNums []uint64, initSeqNums []uint64, nu initSeqNums, priv..., ) + if err != nil { + break + } incrementAllSequenceNumbers(initSeqNums) } - return txs + return txs, err } func incrementAllSequenceNumbers(initSeqNums []uint64) { diff --git a/x/bank/app_test.go b/x/bank/app_test.go index c409260ed8..0516baee5d 100644 --- a/x/bank/app_test.go +++ b/x/bank/app_test.go @@ -110,7 +110,8 @@ func TestSendNotEnoughBalance(t *testing.T) { sendMsg := types.NewMsgSend(addr1, addr2, sdk.Coins{sdk.NewInt64Coin("foocoin", 100)}) header := abci.Header{Height: app.LastBlockHeight() + 1} - _, _, err = simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, []sdk.Msg{sendMsg}, []uint64{origAccNum}, []uint64{origSeq}, false, false, priv1) + txGen := simapp.MakeEncodingConfig().TxGenerator + _, _, err = simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, []sdk.Msg{sendMsg}, []uint64{origAccNum}, []uint64{origSeq}, false, false, priv1) require.Error(t, err) simapp.CheckBalance(t, app, addr1, sdk.Coins{sdk.NewInt64Coin("foocoin", 67)}) @@ -177,7 +178,8 @@ func TestSendToModuleAcc(t *testing.T) { origSeq := res1.GetSequence() header := abci.Header{Height: app.LastBlockHeight() + 1} - _, _, err = simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, []sdk.Msg{test.msg}, []uint64{origAccNum}, []uint64{origSeq}, test.expSimPass, test.expPass, priv1) + txGen := simapp.MakeEncodingConfig().TxGenerator + _, _, err = simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, []sdk.Msg{test.msg}, []uint64{origAccNum}, []uint64{origSeq}, test.expSimPass, test.expPass, priv1) if test.expPass { require.NoError(t, err) } else { @@ -247,7 +249,8 @@ func TestMsgMultiSendWithAccounts(t *testing.T) { for _, tc := range testCases { header := abci.Header{Height: app.LastBlockHeight() + 1} - _, _, err := simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, tc.msgs, tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...) + txGen := simapp.MakeEncodingConfig().TxGenerator + _, _, err := simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, tc.msgs, tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...) if tc.expPass { require.NoError(t, err) } else { @@ -298,7 +301,8 @@ func TestMsgMultiSendMultipleOut(t *testing.T) { for _, tc := range testCases { header := abci.Header{Height: app.LastBlockHeight() + 1} - _, _, err := simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, tc.msgs, tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...) + txGen := simapp.MakeEncodingConfig().TxGenerator + _, _, err := simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, tc.msgs, tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...) require.NoError(t, err) for _, eb := range tc.expectedBalances { @@ -352,7 +356,8 @@ func TestMsgMultiSendMultipleInOut(t *testing.T) { for _, tc := range testCases { header := abci.Header{Height: app.LastBlockHeight() + 1} - _, _, err := simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, tc.msgs, tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...) + txGen := simapp.MakeEncodingConfig().TxGenerator + _, _, err := simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, tc.msgs, tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...) require.NoError(t, err) for _, eb := range tc.expectedBalances { @@ -404,7 +409,8 @@ func TestMsgMultiSendDependent(t *testing.T) { for _, tc := range testCases { header := abci.Header{Height: app.LastBlockHeight() + 1} - _, _, err := simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, tc.msgs, tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...) + txGen := simapp.MakeEncodingConfig().TxGenerator + _, _, err := simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, tc.msgs, tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...) require.NoError(t, err) for _, eb := range tc.expectedBalances { diff --git a/x/bank/bench_test.go b/x/bank/bench_test.go index b380fa073b..f82384ad47 100644 --- a/x/bank/bench_test.go +++ b/x/bank/bench_test.go @@ -7,6 +7,7 @@ import ( abci "github.com/tendermint/tendermint/abci/types" "github.com/cosmos/cosmos-sdk/simapp" + simappparams "github.com/cosmos/cosmos-sdk/simapp/params" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -31,9 +32,11 @@ func BenchmarkOneBankSendTxPerBlock(b *testing.B) { require.NoError(b, err) benchmarkApp.Commit() + txGen := simappparams.MakeEncodingConfig().TxGenerator // Precompute all txs - txs := simapp.GenSequenceOfTxs([]sdk.Msg{sendMsg1}, []uint64{0}, []uint64{uint64(0)}, b.N, priv1) + txs, err := simapp.GenSequenceOfTxs(txGen, []sdk.Msg{sendMsg1}, []uint64{0}, []uint64{uint64(0)}, b.N, priv1) + require.NoError(b, err) b.ResetTimer() height := int64(3) @@ -71,9 +74,11 @@ func BenchmarkOneBankMultiSendTxPerBlock(b *testing.B) { require.NoError(b, err) benchmarkApp.Commit() + txGen := simappparams.MakeEncodingConfig().TxGenerator // Precompute all txs - txs := simapp.GenSequenceOfTxs([]sdk.Msg{multiSendMsg1}, []uint64{0}, []uint64{uint64(0)}, b.N, priv1) + txs, err := simapp.GenSequenceOfTxs(txGen, []sdk.Msg{multiSendMsg1}, []uint64{0}, []uint64{uint64(0)}, b.N, priv1) + require.NoError(b, err) b.ResetTimer() height := int64(3) diff --git a/x/bank/simulation/operations.go b/x/bank/simulation/operations.go index 103a55d0aa..92bf6db75a 100644 --- a/x/bank/simulation/operations.go +++ b/x/bank/simulation/operations.go @@ -103,8 +103,9 @@ func sendMsgSend( return err } } - - tx := helpers.GenTx( + txGen := simappparams.MakeEncodingConfig().TxGenerator + tx, err := helpers.GenTx( + txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, @@ -113,6 +114,9 @@ func sendMsgSend( []uint64{account.GetSequence()}, privkeys..., ) + if err != nil { + return err + } _, _, err = app.Deliver(tx) if err != nil { @@ -247,7 +251,9 @@ func sendMsgMultiSend( } } - tx := helpers.GenTx( + txGen := simappparams.MakeEncodingConfig().TxGenerator + tx, err := helpers.GenTx( + txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, @@ -256,6 +262,9 @@ func sendMsgMultiSend( sequenceNumbers, privkeys..., ) + if err != nil { + return err + } _, _, err = app.Deliver(tx) if err != nil { diff --git a/x/distribution/simulation/operations.go b/x/distribution/simulation/operations.go index fb3170e59a..8d90c01bbb 100644 --- a/x/distribution/simulation/operations.go +++ b/x/distribution/simulation/operations.go @@ -100,7 +100,9 @@ func SimulateMsgSetWithdrawAddress(ak types.AccountKeeper, bk types.BankKeeper, msg := types.NewMsgSetWithdrawAddress(simAccount.Address, simToAccount.Address) - tx := helpers.GenTx( + txGen := simappparams.MakeEncodingConfig().TxGenerator + tx, err := helpers.GenTx( + txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, @@ -109,6 +111,9 @@ func SimulateMsgSetWithdrawAddress(ak types.AccountKeeper, bk types.BankKeeper, []uint64{account.GetSequence()}, simAccount.PrivKey, ) + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err + } _, _, err = app.Deliver(tx) if err != nil { @@ -147,7 +152,9 @@ func SimulateMsgWithdrawDelegatorReward(ak types.AccountKeeper, bk types.BankKee msg := types.NewMsgWithdrawDelegatorReward(simAccount.Address, validator.GetOperator()) - tx := helpers.GenTx( + txGen := simappparams.MakeEncodingConfig().TxGenerator + tx, err := helpers.GenTx( + txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, @@ -156,6 +163,9 @@ func SimulateMsgWithdrawDelegatorReward(ak types.AccountKeeper, bk types.BankKee []uint64{account.GetSequence()}, simAccount.PrivKey, ) + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err + } _, _, err = app.Deliver(tx) if err != nil { @@ -197,7 +207,9 @@ func SimulateMsgWithdrawValidatorCommission(ak types.AccountKeeper, bk types.Ban msg := types.NewMsgWithdrawValidatorCommission(validator.GetOperator()) - tx := helpers.GenTx( + txGen := simappparams.MakeEncodingConfig().TxGenerator + tx, err := helpers.GenTx( + txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, @@ -206,6 +218,9 @@ func SimulateMsgWithdrawValidatorCommission(ak types.AccountKeeper, bk types.Ban []uint64{account.GetSequence()}, simAccount.PrivKey, ) + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err + } _, _, err = app.Deliver(tx) if err != nil { @@ -247,7 +262,9 @@ func SimulateMsgFundCommunityPool(ak types.AccountKeeper, bk types.BankKeeper, k } msg := types.NewMsgFundCommunityPool(fundAmount, funder.Address) - tx := helpers.GenTx( + txGen := simappparams.MakeEncodingConfig().TxGenerator + tx, err := helpers.GenTx( + txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, @@ -256,6 +273,9 @@ func SimulateMsgFundCommunityPool(ak types.AccountKeeper, bk types.BankKeeper, k []uint64{account.GetSequence()}, funder.PrivKey, ) + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err + } _, _, err = app.Deliver(tx) if err != nil { diff --git a/x/gov/simulation/operations.go b/x/gov/simulation/operations.go index 80da7c5b0d..1c6e968571 100644 --- a/x/gov/simulation/operations.go +++ b/x/gov/simulation/operations.go @@ -142,7 +142,9 @@ func SimulateSubmitProposal( } } - tx := helpers.GenTx( + txGen := simappparams.MakeEncodingConfig().TxGenerator + tx, err := helpers.GenTx( + txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, @@ -151,6 +153,9 @@ func SimulateSubmitProposal( []uint64{account.GetSequence()}, simAccount.PrivKey, ) + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err + } _, _, err = app.Deliver(tx) if err != nil { @@ -224,7 +229,9 @@ func SimulateMsgDeposit(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Ke } } - tx := helpers.GenTx( + txGen := simappparams.MakeEncodingConfig().TxGenerator + tx, err := helpers.GenTx( + txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, @@ -233,7 +240,9 @@ func SimulateMsgDeposit(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Ke []uint64{account.GetSequence()}, simAccount.PrivKey, ) - + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err + } _, _, err = app.Deliver(tx) if err != nil { return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to deliver tx"), nil, err @@ -282,7 +291,9 @@ func operationSimulateMsgVote(ak types.AccountKeeper, bk types.BankKeeper, k kee return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate fees"), nil, err } - tx := helpers.GenTx( + txGen := simappparams.MakeEncodingConfig().TxGenerator + tx, err := helpers.GenTx( + txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, @@ -291,6 +302,9 @@ func operationSimulateMsgVote(ak types.AccountKeeper, bk types.BankKeeper, k kee []uint64{account.GetSequence()}, simAccount.PrivKey, ) + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err + } _, _, err = app.Deliver(tx) if err != nil { diff --git a/x/ibc/testing/chain.go b/x/ibc/testing/chain.go index 27725d59e8..dd9fd9d35a 100644 --- a/x/ibc/testing/chain.go +++ b/x/ibc/testing/chain.go @@ -16,6 +16,7 @@ import ( tmtypes "github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/version" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -68,6 +69,7 @@ type TestChain struct { CurrentHeader abci.Header // header for current block height Querier sdk.Querier // TODO: deprecate once clients are migrated to gRPC QueryServer types.QueryServer + TxGenerator client.TxGenerator Vals *tmtypes.ValidatorSet Signers []tmtypes.PrivValidator @@ -115,6 +117,8 @@ func NewTestChain(t *testing.T, chainID string) *TestChain { Time: globalStartTime, } + txGenerator := simapp.MakeEncodingConfig().TxGenerator + // create an account to send transactions from chain := &TestChain{ t: t, @@ -123,6 +127,7 @@ func NewTestChain(t *testing.T, chainID string) *TestChain { CurrentHeader: header, Querier: keeper.NewQuerier(*app.IBCKeeper), QueryServer: app.IBCKeeper, + TxGenerator: txGenerator, Vals: valSet, Signers: signers, senderPrivKey: senderPrivKey, @@ -204,7 +209,7 @@ func (chain *TestChain) NextBlock() { func (chain *TestChain) SendMsg(msg sdk.Msg) error { _, _, err := simapp.SignCheckDeliver( chain.t, - chain.App.Codec(), + chain.TxGenerator, chain.App.BaseApp, chain.GetContext().BlockHeader(), []sdk.Msg{msg}, diff --git a/x/slashing/app_test.go b/x/slashing/app_test.go index b9031f1783..629bb621e8 100644 --- a/x/slashing/app_test.go +++ b/x/slashing/app_test.go @@ -63,7 +63,8 @@ func TestSlashingMsgs(t *testing.T) { ) header := abci.Header{Height: app.LastBlockHeight() + 1} - _, _, err := simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, []sdk.Msg{createValidatorMsg}, []uint64{0}, []uint64{0}, true, true, priv1) + txGen := simapp.MakeEncodingConfig().TxGenerator + _, _, err := simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, []sdk.Msg{createValidatorMsg}, []uint64{0}, []uint64{0}, true, true, priv1) require.NoError(t, err) simapp.CheckBalance(t, app, addr1, sdk.Coins{genCoin.Sub(bondCoin)}) @@ -80,7 +81,7 @@ func TestSlashingMsgs(t *testing.T) { // unjail should fail with unknown validator header = abci.Header{Height: app.LastBlockHeight() + 1} - _, res, err := simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, []sdk.Msg{unjailMsg}, []uint64{0}, []uint64{1}, false, false, priv1) + _, res, err := simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, []sdk.Msg{unjailMsg}, []uint64{0}, []uint64{1}, false, false, priv1) require.Error(t, err) require.Nil(t, res) require.True(t, errors.Is(types.ErrValidatorNotJailed, err)) diff --git a/x/slashing/simulation/operations.go b/x/slashing/simulation/operations.go index e597913f35..cfcf5c2a41 100644 --- a/x/slashing/simulation/operations.go +++ b/x/slashing/simulation/operations.go @@ -86,7 +86,9 @@ func SimulateMsgUnjail(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Kee msg := types.NewMsgUnjail(validator.GetOperator()) - tx := helpers.GenTx( + txGen := simappparams.MakeEncodingConfig().TxGenerator + tx, err := helpers.GenTx( + txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, @@ -95,6 +97,9 @@ func SimulateMsgUnjail(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Kee []uint64{account.GetSequence()}, simAccount.PrivKey, ) + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err + } _, res, err := app.Deliver(tx) diff --git a/x/staking/app_test.go b/x/staking/app_test.go index 1b637698d0..bc1f41bda1 100644 --- a/x/staking/app_test.go +++ b/x/staking/app_test.go @@ -69,7 +69,8 @@ func TestStakingMsgs(t *testing.T) { ) header := abci.Header{Height: app.LastBlockHeight() + 1} - _, _, err := simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, []sdk.Msg{createValidatorMsg}, []uint64{0}, []uint64{0}, true, true, priv1) + txGen := simapp.MakeEncodingConfig().TxGenerator + _, _, err := simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, []sdk.Msg{createValidatorMsg}, []uint64{0}, []uint64{0}, true, true, priv1) require.NoError(t, err) simapp.CheckBalance(t, app, addr1, sdk.Coins{genCoin.Sub(bondCoin)}) @@ -89,7 +90,7 @@ func TestStakingMsgs(t *testing.T) { editValidatorMsg := types.NewMsgEditValidator(sdk.ValAddress(addr1), description, nil, nil) header = abci.Header{Height: app.LastBlockHeight() + 1} - _, _, err = simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, []sdk.Msg{editValidatorMsg}, []uint64{0}, []uint64{1}, true, true, priv1) + _, _, err = simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, []sdk.Msg{editValidatorMsg}, []uint64{0}, []uint64{1}, true, true, priv1) require.NoError(t, err) validator = checkValidator(t, app, sdk.ValAddress(addr1), true) @@ -100,7 +101,7 @@ func TestStakingMsgs(t *testing.T) { delegateMsg := types.NewMsgDelegate(addr2, sdk.ValAddress(addr1), bondCoin) header = abci.Header{Height: app.LastBlockHeight() + 1} - _, _, err = simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, []sdk.Msg{delegateMsg}, []uint64{1}, []uint64{0}, true, true, priv2) + _, _, err = simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, []sdk.Msg{delegateMsg}, []uint64{1}, []uint64{0}, true, true, priv2) require.NoError(t, err) simapp.CheckBalance(t, app, addr2, sdk.Coins{genCoin.Sub(bondCoin)}) @@ -109,7 +110,7 @@ func TestStakingMsgs(t *testing.T) { // begin unbonding beginUnbondingMsg := types.NewMsgUndelegate(addr2, sdk.ValAddress(addr1), bondCoin) header = abci.Header{Height: app.LastBlockHeight() + 1} - _, _, err = simapp.SignCheckDeliver(t, app.Codec(), app.BaseApp, header, []sdk.Msg{beginUnbondingMsg}, []uint64{1}, []uint64{1}, true, true, priv2) + _, _, err = simapp.SignCheckDeliver(t, txGen, app.BaseApp, header, []sdk.Msg{beginUnbondingMsg}, []uint64{1}, []uint64{1}, true, true, priv2) require.NoError(t, err) // delegation should exist anymore diff --git a/x/staking/simulation/operations.go b/x/staking/simulation/operations.go index fbc9a860e1..fbd9e444d0 100644 --- a/x/staking/simulation/operations.go +++ b/x/staking/simulation/operations.go @@ -151,7 +151,9 @@ func SimulateMsgCreateValidator(ak types.AccountKeeper, bk types.BankKeeper, k k msg := types.NewMsgCreateValidator(address, simAccount.PubKey, selfDelegation, description, commission, sdk.OneInt()) - tx := helpers.GenTx( + txGen := simappparams.MakeEncodingConfig().TxGenerator + tx, err := helpers.GenTx( + txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, @@ -160,6 +162,9 @@ func SimulateMsgCreateValidator(ak types.AccountKeeper, bk types.BankKeeper, k k []uint64{account.GetSequence()}, simAccount.PrivKey, ) + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err + } _, _, err = app.Deliver(tx) if err != nil { @@ -217,7 +222,9 @@ func SimulateMsgEditValidator(ak types.AccountKeeper, bk types.BankKeeper, k kee msg := types.NewMsgEditValidator(address, description, &newCommissionRate, nil) - tx := helpers.GenTx( + txGen := simappparams.MakeEncodingConfig().TxGenerator + tx, err := helpers.GenTx( + txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, @@ -226,6 +233,9 @@ func SimulateMsgEditValidator(ak types.AccountKeeper, bk types.BankKeeper, k kee []uint64{account.GetSequence()}, simAccount.PrivKey, ) + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err + } _, _, err = app.Deliver(tx) if err != nil { @@ -285,7 +295,9 @@ func SimulateMsgDelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper.K msg := types.NewMsgDelegate(simAccount.Address, val.GetOperator(), bondAmt) - tx := helpers.GenTx( + txGen := simappparams.MakeEncodingConfig().TxGenerator + tx, err := helpers.GenTx( + txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, @@ -294,6 +306,9 @@ func SimulateMsgDelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper.K []uint64{account.GetSequence()}, simAccount.PrivKey, ) + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err + } _, _, err = app.Deliver(tx) if err != nil { @@ -370,7 +385,9 @@ func SimulateMsgUndelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate fees"), nil, err } - tx := helpers.GenTx( + txGen := simappparams.MakeEncodingConfig().TxGenerator + tx, err := helpers.GenTx( + txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, @@ -379,6 +396,9 @@ func SimulateMsgUndelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper []uint64{account.GetSequence()}, simAccount.PrivKey, ) + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err + } _, _, err = app.Deliver(tx) if err != nil { @@ -478,7 +498,9 @@ func SimulateMsgBeginRedelegate(ak types.AccountKeeper, bk types.BankKeeper, k k sdk.NewCoin(k.BondDenom(ctx), redAmt), ) - tx := helpers.GenTx( + txGen := simappparams.MakeEncodingConfig().TxGenerator + tx, err := helpers.GenTx( + txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, @@ -487,6 +509,9 @@ func SimulateMsgBeginRedelegate(ak types.AccountKeeper, bk types.BankKeeper, k k []uint64{account.GetSequence()}, simAccount.PrivKey, ) + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err + } _, _, err = app.Deliver(tx) if err != nil {