From 8bb2f149d69f166746d7a8dab49689a55fb8653d Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Thu, 9 Jul 2020 07:18:42 +0530 Subject: [PATCH 01/15] update helpers to use tx generator --- simapp/helpers/test_helpers.go | 57 +++++++++++++++++++++++++--------- simapp/simd/cmd/genaccounts.go | 2 +- 2 files changed, 44 insertions(+), 15 deletions(-) diff --git a/simapp/helpers/test_helpers.go b/simapp/helpers/test_helpers.go index fa7b6d648bd0..4e8634d2d20b 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 { + sigs := make([]signing.SignatureV2, len(priv)) //nolint:staticcheck // SA1019: authtypes.StdSignature is deprecated // create a random length memo r := rand.New(rand.NewSource(time.Now().UnixNano())) memo := simulation.RandStringOfLength(r, simulation.RandIntBetween(r, 0, 100)) + signMode := gen.SignModeHandler().DefaultMode() + + for i, p := range priv { + sigs[i] = signing.SignatureV2{ + PubKey: p.PubKey(), + Data: &signing.SingleSignatureData{ + SignMode: signMode, + }, + } + } + + tx := gen.NewTxBuilder() + err := tx.SetMsgs(msgs...) + if err != nil { + panic(err) + } + err = tx.SetSignatures(sigs...) + if err != nil { + panic(err) + } + tx.SetMemo(memo) + tx.SetFeeAmount(feeAmt) + tx.SetGasLimit(gas) 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)) + 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) } - - sigs[i] = authtypes.StdSignature{ //nolint:staticcheck // SA1019: authtypes.StdSignature is deprecated - PubKey: p.PubKey().Bytes(), - Signature: sig, + 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 authtypes.NewStdTx(msgs, fee, sigs, memo) + return tx.GetTx() } diff --git a/simapp/simd/cmd/genaccounts.go b/simapp/simd/cmd/genaccounts.go index 8cfefc18657d..a1792ccdd2e7 100644 --- a/simapp/simd/cmd/genaccounts.go +++ b/simapp/simd/cmd/genaccounts.go @@ -39,7 +39,7 @@ 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 + depCdc := clientCtx.JSONMarshaler cdc := clientCtx.JSONMarshaler.(codec.Marshaler) serverCtx := server.GetServerContextFromCmd(cmd) From 06de08eb4090008ba7c806101106dbf294865247 Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Thu, 9 Jul 2020 07:46:08 +0530 Subject: [PATCH 02/15] update modules to use tx generator --- simapp/simd/cmd/genaccounts.go | 2 +- simapp/test_helpers.go | 11 +++++++---- x/bank/app_test.go | 19 +++++++++++++------ x/bank/simulation/operations.go | 5 ++++- x/distribution/simulation/operations.go | 8 ++++++++ x/gov/simulation/operations.go | 6 ++++++ x/slashing/simulation/operations.go | 2 ++ x/staking/app_test.go | 10 ++++++---- x/staking/simulation/operations.go | 10 ++++++++++ 9 files changed, 57 insertions(+), 16 deletions(-) diff --git a/simapp/simd/cmd/genaccounts.go b/simapp/simd/cmd/genaccounts.go index a1792ccdd2e7..1aef49d9bef5 100644 --- a/simapp/simd/cmd/genaccounts.go +++ b/simapp/simd/cmd/genaccounts.go @@ -40,7 +40,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) depCdc := clientCtx.JSONMarshaler - cdc := clientCtx.JSONMarshaler.(codec.Marshaler) + cdc := depCdc.(codec.Marshaler) serverCtx := server.GetServerContextFromCmd(cmd) config := serverCtx.Config diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index 6ba55f418a93..20ec7f46a4f5 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( + txGen, msgs, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 0)}, helpers.DefaultGenTxGas, @@ -326,7 +328,7 @@ func SignCheckDeliver( priv..., ) - txBytes, err := cdc.MarshalBinaryBare(tx) + txBytes, err := txGen.TxEncoder()(tx) require.Nil(t, err) // Must simulate now as CheckTx doesn't run Msgs anymore @@ -361,10 +363,11 @@ 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(msgs []sdk.Msg, txGen client.TxGenerator, accNums []uint64, initSeqNums []uint64, numToGenerate int, priv ...crypto.PrivKey) []sdk.Tx { + txs := make([]sdk.Tx, numToGenerate) for i := 0; i < numToGenerate; i++ { txs[i] = helpers.GenTx( + txGen, msgs, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 0)}, helpers.DefaultGenTxGas, diff --git a/x/bank/app_test.go b/x/bank/app_test.go index c409260ed8f9..5465f171c32b 100644 --- a/x/bank/app_test.go +++ b/x/bank/app_test.go @@ -5,6 +5,7 @@ import ( "github.com/stretchr/testify/require" + simappparams "github.com/cosmos/cosmos-sdk/simapp/params" distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" abci "github.com/tendermint/tendermint/abci/types" @@ -110,7 +111,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 := simappparams.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 +179,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 := simappparams.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 +250,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 := simappparams.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 +302,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 := simappparams.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 +357,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 := simappparams.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 +410,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 := simappparams.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/simulation/operations.go b/x/bank/simulation/operations.go index 103a55d0aa6f..6d99752611c4 100644 --- a/x/bank/simulation/operations.go +++ b/x/bank/simulation/operations.go @@ -103,8 +103,9 @@ func sendMsgSend( return err } } - + txGen := simappparams.MakeEncodingConfig().TxGenerator tx := helpers.GenTx( + txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, @@ -247,7 +248,9 @@ func sendMsgMultiSend( } } + txGen := simappparams.MakeEncodingConfig().TxGenerator tx := helpers.GenTx( + txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, diff --git a/x/distribution/simulation/operations.go b/x/distribution/simulation/operations.go index fb3170e59aea..8362e6c93b7b 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) + txGen := simappparams.MakeEncodingConfig().TxGenerator tx := helpers.GenTx( + txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, @@ -147,7 +149,9 @@ func SimulateMsgWithdrawDelegatorReward(ak types.AccountKeeper, bk types.BankKee msg := types.NewMsgWithdrawDelegatorReward(simAccount.Address, validator.GetOperator()) + txGen := simappparams.MakeEncodingConfig().TxGenerator tx := helpers.GenTx( + txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, @@ -197,7 +201,9 @@ func SimulateMsgWithdrawValidatorCommission(ak types.AccountKeeper, bk types.Ban msg := types.NewMsgWithdrawValidatorCommission(validator.GetOperator()) + txGen := simappparams.MakeEncodingConfig().TxGenerator tx := helpers.GenTx( + txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, @@ -247,7 +253,9 @@ func SimulateMsgFundCommunityPool(ak types.AccountKeeper, bk types.BankKeeper, k } msg := types.NewMsgFundCommunityPool(fundAmount, funder.Address) + txGen := simappparams.MakeEncodingConfig().TxGenerator tx := helpers.GenTx( + txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, diff --git a/x/gov/simulation/operations.go b/x/gov/simulation/operations.go index 80da7c5b0da7..36cbf0b686c4 100644 --- a/x/gov/simulation/operations.go +++ b/x/gov/simulation/operations.go @@ -142,7 +142,9 @@ func SimulateSubmitProposal( } } + txGen := simappparams.MakeEncodingConfig().TxGenerator tx := helpers.GenTx( + txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, @@ -224,7 +226,9 @@ func SimulateMsgDeposit(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Ke } } + txGen := simappparams.MakeEncodingConfig().TxGenerator tx := helpers.GenTx( + txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, @@ -282,7 +286,9 @@ func operationSimulateMsgVote(ak types.AccountKeeper, bk types.BankKeeper, k kee return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate fees"), nil, err } + txGen := simappparams.MakeEncodingConfig().TxGenerator tx := helpers.GenTx( + txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, diff --git a/x/slashing/simulation/operations.go b/x/slashing/simulation/operations.go index e597913f35d4..12e75958baa4 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()) + txGen := simappparams.MakeEncodingConfig().TxGenerator tx := helpers.GenTx( + txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, diff --git a/x/staking/app_test.go b/x/staking/app_test.go index 1b637698d002..caff1ebba031 100644 --- a/x/staking/app_test.go +++ b/x/staking/app_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" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -69,7 +70,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 := simappparams.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 +91,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 +102,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 +111,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 bcdc4ee3f4b5..2ec9374db731 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()) + txGen := simappparams.MakeEncodingConfig().TxGenerator tx := helpers.GenTx( + txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, @@ -217,7 +219,9 @@ func SimulateMsgEditValidator(ak types.AccountKeeper, bk types.BankKeeper, k kee msg := types.NewMsgEditValidator(address, description, &newCommissionRate, nil) + txGen := simappparams.MakeEncodingConfig().TxGenerator tx := helpers.GenTx( + txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, @@ -285,7 +289,9 @@ func SimulateMsgDelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper.K msg := types.NewMsgDelegate(simAccount.Address, val.GetOperator(), bondAmt) + txGen := simappparams.MakeEncodingConfig().TxGenerator tx := helpers.GenTx( + txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, @@ -367,7 +373,9 @@ func SimulateMsgUndelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate fees"), nil, err } + txGen := simappparams.MakeEncodingConfig().TxGenerator tx := helpers.GenTx( + txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, @@ -472,7 +480,9 @@ func SimulateMsgBeginRedelegate(ak types.AccountKeeper, bk types.BankKeeper, k k sdk.NewCoin(k.BondDenom(ctx), redAmt), ) + txGen := simappparams.MakeEncodingConfig().TxGenerator tx := helpers.GenTx( + txGen, []sdk.Msg{msg}, fees, helpers.DefaultGenTxGas, From e8e34b6711c174930cbee84d0dfc36bc4f130458 Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Thu, 9 Jul 2020 07:48:33 +0530 Subject: [PATCH 03/15] add todo --- x/ibc/testing/chain.go | 1 + 1 file changed, 1 insertion(+) diff --git a/x/ibc/testing/chain.go b/x/ibc/testing/chain.go index 63b1bdf06de7..65328e373aaa 100644 --- a/x/ibc/testing/chain.go +++ b/x/ibc/testing/chain.go @@ -200,6 +200,7 @@ func (chain *TestChain) NextBlock() { // SendMsg delivers a transaction through the application. It updates the senders sequence // number and updates the TestChain's headers. +// TODO: Update SignCheckDeliver to use tx generator func (chain *TestChain) SendMsg(msg sdk.Msg) error { _, _, err := simapp.SignCheckDeliver( chain.t, From 5c65e5988f9ad6269c99c398e9ad738c3024543f Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Thu, 9 Jul 2020 07:49:36 +0530 Subject: [PATCH 04/15] update ibc to use txG --- x/ibc/testing/chain.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/x/ibc/testing/chain.go b/x/ibc/testing/chain.go index 65328e373aaa..19ac4826d19c 100644 --- a/x/ibc/testing/chain.go +++ b/x/ibc/testing/chain.go @@ -17,6 +17,7 @@ import ( "github.com/tendermint/tendermint/version" "github.com/cosmos/cosmos-sdk/simapp" + simappparams "github.com/cosmos/cosmos-sdk/simapp/params" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -200,11 +201,11 @@ func (chain *TestChain) NextBlock() { // SendMsg delivers a transaction through the application. It updates the senders sequence // number and updates the TestChain's headers. -// TODO: Update SignCheckDeliver to use tx generator func (chain *TestChain) SendMsg(msg sdk.Msg) error { + txGen := simappparams.MakeEncodingConfig().TxGenerator _, _, err := simapp.SignCheckDeliver( chain.t, - chain.App.Codec(), + txGen, chain.App.BaseApp, chain.GetContext().BlockHeader(), []sdk.Msg{msg}, From 7493dc372ccc40b2c821f721cbc600fa0ecba662 Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Thu, 9 Jul 2020 08:31:09 +0530 Subject: [PATCH 05/15] fix lint --- simapp/helpers/test_helpers.go | 2 +- x/ibc/testing/chain.go | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/simapp/helpers/test_helpers.go b/simapp/helpers/test_helpers.go index 4e8634d2d20b..a1858cde5d6f 100644 --- a/simapp/helpers/test_helpers.go +++ b/simapp/helpers/test_helpers.go @@ -21,7 +21,7 @@ const ( // GenTx generates a signed mock transaction. func GenTx(gen client.TxGenerator, msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, chainID string, accnums []uint64, seq []uint64, priv ...crypto.PrivKey) sdk.Tx { - sigs := make([]signing.SignatureV2, len(priv)) //nolint:staticcheck // SA1019: authtypes.StdSignature is deprecated + sigs := make([]signing.SignatureV2, len(priv)) // create a random length memo r := rand.New(rand.NewSource(time.Now().UnixNano())) diff --git a/x/ibc/testing/chain.go b/x/ibc/testing/chain.go index 19ac4826d19c..adbd347b3a67 100644 --- a/x/ibc/testing/chain.go +++ b/x/ibc/testing/chain.go @@ -17,7 +17,6 @@ import ( "github.com/tendermint/tendermint/version" "github.com/cosmos/cosmos-sdk/simapp" - simappparams "github.com/cosmos/cosmos-sdk/simapp/params" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -201,11 +200,11 @@ func (chain *TestChain) NextBlock() { // SendMsg delivers a transaction through the application. It updates the senders sequence // number and updates the TestChain's headers. +// TODO: update SignCheckDeliver to use tx generator func (chain *TestChain) SendMsg(msg sdk.Msg) error { - txGen := simappparams.MakeEncodingConfig().TxGenerator _, _, err := simapp.SignCheckDeliver( chain.t, - txGen, + chain.App.Codec(), chain.App.BaseApp, chain.GetContext().BlockHeader(), []sdk.Msg{msg}, From 666fb640839db348462b594f783675624c1b9ca5 Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Fri, 10 Jul 2020 15:34:07 +0530 Subject: [PATCH 06/15] Eliminate panics from Gentx --- simapp/helpers/test_helpers.go | 8 ++++---- simapp/test_helpers.go | 14 +++++++++----- x/bank/bench_test.go | 9 +++++++-- x/bank/simulation/operations.go | 10 ++++++++-- x/distribution/simulation/operations.go | 20 ++++++++++++++++---- x/gov/simulation/operations.go | 16 ++++++++++++---- x/slashing/simulation/operations.go | 5 ++++- x/staking/simulation/operations.go | 25 ++++++++++++++++++++----- 8 files changed, 80 insertions(+), 27 deletions(-) diff --git a/simapp/helpers/test_helpers.go b/simapp/helpers/test_helpers.go index a1858cde5d6f..5f71e24a8cc1 100644 --- a/simapp/helpers/test_helpers.go +++ b/simapp/helpers/test_helpers.go @@ -20,7 +20,7 @@ const ( ) // GenTx generates a signed mock transaction. -func GenTx(gen client.TxGenerator, msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, chainID string, accnums []uint64, seq []uint64, priv ...crypto.PrivKey) sdk.Tx { +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 @@ -42,11 +42,11 @@ func GenTx(gen client.TxGenerator, msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, tx := gen.NewTxBuilder() err := tx.SetMsgs(msgs...) if err != nil { - panic(err) + return nil, err } err = tx.SetSignatures(sigs...) if err != nil { - panic(err) + return nil, err } tx.SetMemo(memo) tx.SetFeeAmount(feeAmt) @@ -73,5 +73,5 @@ func GenTx(gen client.TxGenerator, msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, } } - return tx.GetTx() + return tx.GetTx(), nil } diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index 20ec7f46a4f5..0479a42d2216 100644 --- a/simapp/test_helpers.go +++ b/simapp/test_helpers.go @@ -317,7 +317,7 @@ func SignCheckDeliver( 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)}, @@ -327,7 +327,7 @@ func SignCheckDeliver( seq, priv..., ) - + require.NoError(t, err) txBytes, err := txGen.TxEncoder()(tx) require.Nil(t, err) @@ -363,10 +363,11 @@ 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, txGen client.TxGenerator, accNums []uint64, initSeqNums []uint64, numToGenerate int, priv ...crypto.PrivKey) []sdk.Tx { +func GenSequenceOfTxs(msgs []sdk.Msg, txGen client.TxGenerator, 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)}, @@ -376,10 +377,13 @@ func GenSequenceOfTxs(msgs []sdk.Msg, txGen client.TxGenerator, accNums []uint64 initSeqNums, priv..., ) + if err != nil { + break + } incrementAllSequenceNumbers(initSeqNums) } - return txs + return txs, err } func incrementAllSequenceNumbers(initSeqNums []uint64) { diff --git a/x/bank/bench_test.go b/x/bank/bench_test.go index b380fa073bc4..d9e23efdf6f3 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([]sdk.Msg{sendMsg1}, txGen, []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([]sdk.Msg{multiSendMsg1}, txGen, []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 6d99752611c4..3ed09ce72fd2 100644 --- a/x/bank/simulation/operations.go +++ b/x/bank/simulation/operations.go @@ -104,7 +104,7 @@ func sendMsgSend( } } txGen := simappparams.MakeEncodingConfig().TxGenerator - tx := helpers.GenTx( + tx, err := helpers.GenTx( txGen, []sdk.Msg{msg}, fees, @@ -114,6 +114,9 @@ func sendMsgSend( []uint64{account.GetSequence()}, privkeys..., ) + if err != nil { + simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx") + } _, _, err = app.Deliver(tx) if err != nil { @@ -249,7 +252,7 @@ func sendMsgMultiSend( } txGen := simappparams.MakeEncodingConfig().TxGenerator - tx := helpers.GenTx( + tx, err := helpers.GenTx( txGen, []sdk.Msg{msg}, fees, @@ -259,6 +262,9 @@ func sendMsgMultiSend( sequenceNumbers, privkeys..., ) + if err != nil { + simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx") + } _, _, err = app.Deliver(tx) if err != nil { diff --git a/x/distribution/simulation/operations.go b/x/distribution/simulation/operations.go index 8362e6c93b7b..61d68e963503 100644 --- a/x/distribution/simulation/operations.go +++ b/x/distribution/simulation/operations.go @@ -101,7 +101,7 @@ func SimulateMsgSetWithdrawAddress(ak types.AccountKeeper, bk types.BankKeeper, msg := types.NewMsgSetWithdrawAddress(simAccount.Address, simToAccount.Address) txGen := simappparams.MakeEncodingConfig().TxGenerator - tx := helpers.GenTx( + tx, err := helpers.GenTx( txGen, []sdk.Msg{msg}, fees, @@ -111,6 +111,9 @@ func SimulateMsgSetWithdrawAddress(ak types.AccountKeeper, bk types.BankKeeper, []uint64{account.GetSequence()}, simAccount.PrivKey, ) + if err != nil { + simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx") + } _, _, err = app.Deliver(tx) if err != nil { @@ -150,7 +153,7 @@ func SimulateMsgWithdrawDelegatorReward(ak types.AccountKeeper, bk types.BankKee msg := types.NewMsgWithdrawDelegatorReward(simAccount.Address, validator.GetOperator()) txGen := simappparams.MakeEncodingConfig().TxGenerator - tx := helpers.GenTx( + tx, err := helpers.GenTx( txGen, []sdk.Msg{msg}, fees, @@ -160,6 +163,9 @@ func SimulateMsgWithdrawDelegatorReward(ak types.AccountKeeper, bk types.BankKee []uint64{account.GetSequence()}, simAccount.PrivKey, ) + if err != nil { + simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx") + } _, _, err = app.Deliver(tx) if err != nil { @@ -202,7 +208,7 @@ func SimulateMsgWithdrawValidatorCommission(ak types.AccountKeeper, bk types.Ban msg := types.NewMsgWithdrawValidatorCommission(validator.GetOperator()) txGen := simappparams.MakeEncodingConfig().TxGenerator - tx := helpers.GenTx( + tx, err := helpers.GenTx( txGen, []sdk.Msg{msg}, fees, @@ -212,6 +218,9 @@ func SimulateMsgWithdrawValidatorCommission(ak types.AccountKeeper, bk types.Ban []uint64{account.GetSequence()}, simAccount.PrivKey, ) + if err != nil { + simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx") + } _, _, err = app.Deliver(tx) if err != nil { @@ -254,7 +263,7 @@ func SimulateMsgFundCommunityPool(ak types.AccountKeeper, bk types.BankKeeper, k msg := types.NewMsgFundCommunityPool(fundAmount, funder.Address) txGen := simappparams.MakeEncodingConfig().TxGenerator - tx := helpers.GenTx( + tx, err := helpers.GenTx( txGen, []sdk.Msg{msg}, fees, @@ -264,6 +273,9 @@ func SimulateMsgFundCommunityPool(ak types.AccountKeeper, bk types.BankKeeper, k []uint64{account.GetSequence()}, funder.PrivKey, ) + if err != nil { + simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx") + } _, _, err = app.Deliver(tx) if err != nil { diff --git a/x/gov/simulation/operations.go b/x/gov/simulation/operations.go index 36cbf0b686c4..5f57caa80305 100644 --- a/x/gov/simulation/operations.go +++ b/x/gov/simulation/operations.go @@ -143,7 +143,7 @@ func SimulateSubmitProposal( } txGen := simappparams.MakeEncodingConfig().TxGenerator - tx := helpers.GenTx( + tx, err := helpers.GenTx( txGen, []sdk.Msg{msg}, fees, @@ -153,6 +153,9 @@ func SimulateSubmitProposal( []uint64{account.GetSequence()}, simAccount.PrivKey, ) + if err != nil { + simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx") + } _, _, err = app.Deliver(tx) if err != nil { @@ -227,7 +230,7 @@ func SimulateMsgDeposit(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Ke } txGen := simappparams.MakeEncodingConfig().TxGenerator - tx := helpers.GenTx( + tx, err := helpers.GenTx( txGen, []sdk.Msg{msg}, fees, @@ -237,7 +240,9 @@ func SimulateMsgDeposit(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Ke []uint64{account.GetSequence()}, simAccount.PrivKey, ) - + if err != nil { + simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx") + } _, _, err = app.Deliver(tx) if err != nil { return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to deliver tx"), nil, err @@ -287,7 +292,7 @@ func operationSimulateMsgVote(ak types.AccountKeeper, bk types.BankKeeper, k kee } txGen := simappparams.MakeEncodingConfig().TxGenerator - tx := helpers.GenTx( + tx, err := helpers.GenTx( txGen, []sdk.Msg{msg}, fees, @@ -297,6 +302,9 @@ func operationSimulateMsgVote(ak types.AccountKeeper, bk types.BankKeeper, k kee []uint64{account.GetSequence()}, simAccount.PrivKey, ) + if err != nil { + simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx") + } _, _, err = app.Deliver(tx) if err != nil { diff --git a/x/slashing/simulation/operations.go b/x/slashing/simulation/operations.go index 12e75958baa4..c5a8fb692512 100644 --- a/x/slashing/simulation/operations.go +++ b/x/slashing/simulation/operations.go @@ -87,7 +87,7 @@ func SimulateMsgUnjail(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Kee msg := types.NewMsgUnjail(validator.GetOperator()) txGen := simappparams.MakeEncodingConfig().TxGenerator - tx := helpers.GenTx( + tx, err := helpers.GenTx( txGen, []sdk.Msg{msg}, fees, @@ -97,6 +97,9 @@ func SimulateMsgUnjail(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Kee []uint64{account.GetSequence()}, simAccount.PrivKey, ) + if err != nil { + simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx") + } _, res, err := app.Deliver(tx) diff --git a/x/staking/simulation/operations.go b/x/staking/simulation/operations.go index 2ec9374db731..8131aea1ecf3 100644 --- a/x/staking/simulation/operations.go +++ b/x/staking/simulation/operations.go @@ -152,7 +152,7 @@ func SimulateMsgCreateValidator(ak types.AccountKeeper, bk types.BankKeeper, k k selfDelegation, description, commission, sdk.OneInt()) txGen := simappparams.MakeEncodingConfig().TxGenerator - tx := helpers.GenTx( + tx, err := helpers.GenTx( txGen, []sdk.Msg{msg}, fees, @@ -162,6 +162,9 @@ func SimulateMsgCreateValidator(ak types.AccountKeeper, bk types.BankKeeper, k k []uint64{account.GetSequence()}, simAccount.PrivKey, ) + if err != nil { + simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx") + } _, _, err = app.Deliver(tx) if err != nil { @@ -220,7 +223,7 @@ func SimulateMsgEditValidator(ak types.AccountKeeper, bk types.BankKeeper, k kee msg := types.NewMsgEditValidator(address, description, &newCommissionRate, nil) txGen := simappparams.MakeEncodingConfig().TxGenerator - tx := helpers.GenTx( + tx, err := helpers.GenTx( txGen, []sdk.Msg{msg}, fees, @@ -230,6 +233,9 @@ func SimulateMsgEditValidator(ak types.AccountKeeper, bk types.BankKeeper, k kee []uint64{account.GetSequence()}, simAccount.PrivKey, ) + if err != nil { + simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx") + } _, _, err = app.Deliver(tx) if err != nil { @@ -290,7 +296,7 @@ func SimulateMsgDelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper.K msg := types.NewMsgDelegate(simAccount.Address, val.GetOperator(), bondAmt) txGen := simappparams.MakeEncodingConfig().TxGenerator - tx := helpers.GenTx( + tx, err := helpers.GenTx( txGen, []sdk.Msg{msg}, fees, @@ -300,6 +306,9 @@ func SimulateMsgDelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper.K []uint64{account.GetSequence()}, simAccount.PrivKey, ) + if err != nil { + simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx") + } _, _, err = app.Deliver(tx) if err != nil { @@ -374,7 +383,7 @@ func SimulateMsgUndelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper } txGen := simappparams.MakeEncodingConfig().TxGenerator - tx := helpers.GenTx( + tx, err := helpers.GenTx( txGen, []sdk.Msg{msg}, fees, @@ -384,6 +393,9 @@ func SimulateMsgUndelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper []uint64{account.GetSequence()}, simAccount.PrivKey, ) + if err != nil { + simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx") + } _, _, err = app.Deliver(tx) if err != nil { @@ -481,7 +493,7 @@ func SimulateMsgBeginRedelegate(ak types.AccountKeeper, bk types.BankKeeper, k k ) txGen := simappparams.MakeEncodingConfig().TxGenerator - tx := helpers.GenTx( + tx, err := helpers.GenTx( txGen, []sdk.Msg{msg}, fees, @@ -491,6 +503,9 @@ func SimulateMsgBeginRedelegate(ak types.AccountKeeper, bk types.BankKeeper, k k []uint64{account.GetSequence()}, simAccount.PrivKey, ) + if err != nil { + simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx") + } _, _, err = app.Deliver(tx) if err != nil { From 2531b7be6af4e82a425b3b930b466ef0d1d761af Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Fri, 10 Jul 2020 15:59:46 +0530 Subject: [PATCH 07/15] update module ops --- x/bank/simulation/operations.go | 2 +- x/distribution/simulation/operations.go | 8 ++++---- x/gov/simulation/operations.go | 6 +++--- x/slashing/simulation/operations.go | 2 +- x/staking/simulation/operations.go | 10 +++++----- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/x/bank/simulation/operations.go b/x/bank/simulation/operations.go index 3ed09ce72fd2..7a30013286be 100644 --- a/x/bank/simulation/operations.go +++ b/x/bank/simulation/operations.go @@ -115,7 +115,7 @@ func sendMsgSend( privkeys..., ) if err != nil { - simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx") + return err } _, _, err = app.Deliver(tx) diff --git a/x/distribution/simulation/operations.go b/x/distribution/simulation/operations.go index 61d68e963503..8d90c01bbb31 100644 --- a/x/distribution/simulation/operations.go +++ b/x/distribution/simulation/operations.go @@ -112,7 +112,7 @@ func SimulateMsgSetWithdrawAddress(ak types.AccountKeeper, bk types.BankKeeper, simAccount.PrivKey, ) if err != nil { - simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx") + return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err } _, _, err = app.Deliver(tx) @@ -164,7 +164,7 @@ func SimulateMsgWithdrawDelegatorReward(ak types.AccountKeeper, bk types.BankKee simAccount.PrivKey, ) if err != nil { - simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx") + return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err } _, _, err = app.Deliver(tx) @@ -219,7 +219,7 @@ func SimulateMsgWithdrawValidatorCommission(ak types.AccountKeeper, bk types.Ban simAccount.PrivKey, ) if err != nil { - simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx") + return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err } _, _, err = app.Deliver(tx) @@ -274,7 +274,7 @@ func SimulateMsgFundCommunityPool(ak types.AccountKeeper, bk types.BankKeeper, k funder.PrivKey, ) if err != nil { - simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx") + return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err } _, _, err = app.Deliver(tx) diff --git a/x/gov/simulation/operations.go b/x/gov/simulation/operations.go index 5f57caa80305..1c6e96857104 100644 --- a/x/gov/simulation/operations.go +++ b/x/gov/simulation/operations.go @@ -154,7 +154,7 @@ func SimulateSubmitProposal( simAccount.PrivKey, ) if err != nil { - simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx") + return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err } _, _, err = app.Deliver(tx) @@ -241,7 +241,7 @@ func SimulateMsgDeposit(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Ke simAccount.PrivKey, ) if err != nil { - simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx") + return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err } _, _, err = app.Deliver(tx) if err != nil { @@ -303,7 +303,7 @@ func operationSimulateMsgVote(ak types.AccountKeeper, bk types.BankKeeper, k kee simAccount.PrivKey, ) if err != nil { - simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx") + return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err } _, _, err = app.Deliver(tx) diff --git a/x/slashing/simulation/operations.go b/x/slashing/simulation/operations.go index c5a8fb692512..cfcf5c2a413e 100644 --- a/x/slashing/simulation/operations.go +++ b/x/slashing/simulation/operations.go @@ -98,7 +98,7 @@ func SimulateMsgUnjail(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Kee simAccount.PrivKey, ) if err != nil { - simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx") + return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err } _, res, err := app.Deliver(tx) diff --git a/x/staking/simulation/operations.go b/x/staking/simulation/operations.go index 8131aea1ecf3..e0b97e8e1965 100644 --- a/x/staking/simulation/operations.go +++ b/x/staking/simulation/operations.go @@ -163,7 +163,7 @@ func SimulateMsgCreateValidator(ak types.AccountKeeper, bk types.BankKeeper, k k simAccount.PrivKey, ) if err != nil { - simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx") + return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err } _, _, err = app.Deliver(tx) @@ -234,7 +234,7 @@ func SimulateMsgEditValidator(ak types.AccountKeeper, bk types.BankKeeper, k kee simAccount.PrivKey, ) if err != nil { - simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx") + return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err } _, _, err = app.Deliver(tx) @@ -307,7 +307,7 @@ func SimulateMsgDelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper.K simAccount.PrivKey, ) if err != nil { - simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx") + return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err } _, _, err = app.Deliver(tx) @@ -394,7 +394,7 @@ func SimulateMsgUndelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper simAccount.PrivKey, ) if err != nil { - simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx") + return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err } _, _, err = app.Deliver(tx) @@ -504,7 +504,7 @@ func SimulateMsgBeginRedelegate(ak types.AccountKeeper, bk types.BankKeeper, k k simAccount.PrivKey, ) if err != nil { - simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx") + return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err } _, _, err = app.Deliver(tx) From 3d5383ca0be72ac3e0220b0ff848c6a974a70cdc Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Fri, 10 Jul 2020 16:18:02 +0530 Subject: [PATCH 08/15] fix lgtm alert --- x/bank/simulation/operations.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/bank/simulation/operations.go b/x/bank/simulation/operations.go index 7a30013286be..92bf6db75a74 100644 --- a/x/bank/simulation/operations.go +++ b/x/bank/simulation/operations.go @@ -263,7 +263,7 @@ func sendMsgMultiSend( privkeys..., ) if err != nil { - simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx") + return err } _, _, err = app.Deliver(tx) From a238cba4e2d1acea12aea11aa680590551eafc44 Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Sun, 12 Jul 2020 22:35:21 +0530 Subject: [PATCH 09/15] update ibc with txG --- x/bank/app_test.go | 13 ++++++------- x/ibc/testing/chain.go | 7 ++++++- x/slashing/app_test.go | 5 +++-- x/staking/app_test.go | 3 +-- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/x/bank/app_test.go b/x/bank/app_test.go index 5465f171c32b..0516baee5d73 100644 --- a/x/bank/app_test.go +++ b/x/bank/app_test.go @@ -5,7 +5,6 @@ import ( "github.com/stretchr/testify/require" - simappparams "github.com/cosmos/cosmos-sdk/simapp/params" distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" abci "github.com/tendermint/tendermint/abci/types" @@ -111,7 +110,7 @@ func TestSendNotEnoughBalance(t *testing.T) { sendMsg := types.NewMsgSend(addr1, addr2, sdk.Coins{sdk.NewInt64Coin("foocoin", 100)}) header := abci.Header{Height: app.LastBlockHeight() + 1} - txGen := simappparams.MakeEncodingConfig().TxGenerator + 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) @@ -179,7 +178,7 @@ func TestSendToModuleAcc(t *testing.T) { origSeq := res1.GetSequence() header := abci.Header{Height: app.LastBlockHeight() + 1} - txGen := simappparams.MakeEncodingConfig().TxGenerator + 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) @@ -250,7 +249,7 @@ func TestMsgMultiSendWithAccounts(t *testing.T) { for _, tc := range testCases { header := abci.Header{Height: app.LastBlockHeight() + 1} - txGen := simappparams.MakeEncodingConfig().TxGenerator + 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) @@ -302,7 +301,7 @@ func TestMsgMultiSendMultipleOut(t *testing.T) { for _, tc := range testCases { header := abci.Header{Height: app.LastBlockHeight() + 1} - txGen := simappparams.MakeEncodingConfig().TxGenerator + 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) @@ -357,7 +356,7 @@ func TestMsgMultiSendMultipleInOut(t *testing.T) { for _, tc := range testCases { header := abci.Header{Height: app.LastBlockHeight() + 1} - txGen := simappparams.MakeEncodingConfig().TxGenerator + 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) @@ -410,7 +409,7 @@ func TestMsgMultiSendDependent(t *testing.T) { for _, tc := range testCases { header := abci.Header{Height: app.LastBlockHeight() + 1} - txGen := simappparams.MakeEncodingConfig().TxGenerator + 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) diff --git a/x/ibc/testing/chain.go b/x/ibc/testing/chain.go index adbd347b3a67..f208bcb6aa73 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" @@ -67,6 +68,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 @@ -114,6 +116,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, @@ -122,6 +126,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 b9031f17834f..629bb621e84b 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/staking/app_test.go b/x/staking/app_test.go index caff1ebba031..bc1f41bda128 100644 --- a/x/staking/app_test.go +++ b/x/staking/app_test.go @@ -7,7 +7,6 @@ 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" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -70,7 +69,7 @@ func TestStakingMsgs(t *testing.T) { ) header := abci.Header{Height: app.LastBlockHeight() + 1} - txGen := simappparams.MakeEncodingConfig().TxGenerator + 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)}) From b432be950a91892a92d741cc20c532e47b235769 Mon Sep 17 00:00:00 2001 From: SaReN Date: Mon, 13 Jul 2020 18:21:25 +0530 Subject: [PATCH 10/15] Remove todo Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> --- x/ibc/testing/chain.go | 1 - 1 file changed, 1 deletion(-) diff --git a/x/ibc/testing/chain.go b/x/ibc/testing/chain.go index f208bcb6aa73..68654502eab2 100644 --- a/x/ibc/testing/chain.go +++ b/x/ibc/testing/chain.go @@ -205,7 +205,6 @@ func (chain *TestChain) NextBlock() { // SendMsg delivers a transaction through the application. It updates the senders sequence // number and updates the TestChain's headers. -// TODO: update SignCheckDeliver to use tx generator func (chain *TestChain) SendMsg(msg sdk.Msg) error { _, _, err := simapp.SignCheckDeliver( chain.t, From 643ed20487f7d69d83160c9f058d6b6f2f045df0 Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Tue, 14 Jul 2020 19:17:56 +0530 Subject: [PATCH 11/15] move simapp/helpers to test_helpers --- simapp/helpers/test_helpers.go | 77 ------------------------ simapp/sim_test.go | 3 +- simapp/test_helpers.go | 78 +++++++++++++++++++++++-- simapp/utils.go | 3 +- x/bank/simulation/operations.go | 10 ++-- x/distribution/simulation/operations.go | 18 +++--- x/gov/simulation/operations.go | 14 ++--- x/slashing/simulation/operations.go | 6 +- x/staking/simulation/operations.go | 22 +++---- 9 files changed, 109 insertions(+), 122 deletions(-) delete mode 100644 simapp/helpers/test_helpers.go diff --git a/simapp/helpers/test_helpers.go b/simapp/helpers/test_helpers.go deleted file mode 100644 index 5f71e24a8cc1..000000000000 --- a/simapp/helpers/test_helpers.go +++ /dev/null @@ -1,77 +0,0 @@ -package helpers - -import ( - "math/rand" - "time" - - "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" - "github.com/cosmos/cosmos-sdk/types/tx/signing" - authsign "github.com/cosmos/cosmos-sdk/x/auth/signing" -) - -// SimAppChainID hardcoded chainID for simulation -const ( - DefaultGenTxGas = 1000000 - SimAppChainID = "simulation-app" -) - -// GenTx generates a signed mock transaction. -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)) - - signMode := gen.SignModeHandler().DefaultMode() - - for i, p := range priv { - sigs[i] = signing.SignatureV2{ - PubKey: p.PubKey(), - Data: &signing.SingleSignatureData{ - SignMode: signMode, - }, - } - } - - 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/sim_test.go b/simapp/sim_test.go index 83acd4a24f06..18f8890f379f 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -14,7 +14,6 @@ import ( dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/baseapp" - "github.com/cosmos/cosmos-sdk/simapp/helpers" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -256,7 +255,7 @@ func TestAppStateDeterminism(t *testing.T) { config.ExportParamsPath = "" config.OnOperation = false config.AllInvariants = false - config.ChainID = helpers.SimAppChainID + config.ChainID = SimAppChainID numSeeds := 3 numTimesToRunPerSeed := 5 diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index 0479a42d2216..31c44f60d0fe 100644 --- a/simapp/test_helpers.go +++ b/simapp/test_helpers.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/hex" "fmt" + "math/rand" "strconv" "testing" "time" @@ -19,13 +20,21 @@ import ( 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" + "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/types/tx/signing" + authsign "github.com/cosmos/cosmos-sdk/x/auth/signing" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) +// SimAppChainID hardcoded chainID for simulation +const ( + DefaultGenTxGas = 1000000 + SimAppChainID = "simulation-app" +) + // DefaultConsensusParams defines the default Tendermint consensus params used in // SimApp testing. var DefaultConsensusParams = &abci.ConsensusParams{ @@ -308,6 +317,63 @@ func CheckBalance(t *testing.T, app *SimApp, addr sdk.AccAddress, balances sdk.C require.True(t, balances.IsEqual(app.BankKeeper.GetAllBalances(ctxCheck, addr))) } +// GenTx generates a signed mock transaction. +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)) + + signMode := gen.SignModeHandler().DefaultMode() + + for i, p := range priv { + sigs[i] = signing.SignatureV2{ + PubKey: p.PubKey(), + Data: &signing.SingleSignatureData{ + SignMode: signMode, + }, + } + } + + 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 +} + // SignCheckDeliver checks a generated signed transaction and simulates a // block commitment with the given transaction. A test assertion is made using // the parameter 'expPass' against the result. A corresponding result is @@ -317,11 +383,11 @@ func SignCheckDeliver( accNums, seq []uint64, expSimPass, expPass bool, priv ...crypto.PrivKey, ) (sdk.GasInfo, *sdk.Result, error) { - tx, err := helpers.GenTx( + tx, err := GenTx( txGen, msgs, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 0)}, - helpers.DefaultGenTxGas, + DefaultGenTxGas, "", accNums, seq, @@ -363,15 +429,15 @@ 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, txGen client.TxGenerator, accNums []uint64, initSeqNums []uint64, numToGenerate int, priv ...crypto.PrivKey) ([]sdk.Tx, error) { +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], err = helpers.GenTx( + txs[i], err = GenTx( txGen, msgs, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 0)}, - helpers.DefaultGenTxGas, + DefaultGenTxGas, "", accNums, initSeqNums, diff --git a/simapp/utils.go b/simapp/utils.go index 6ac89055dc8e..5cda88760271 100644 --- a/simapp/utils.go +++ b/simapp/utils.go @@ -10,7 +10,6 @@ import ( dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/simapp/helpers" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" @@ -25,7 +24,7 @@ func SetupSimulation(dirPrefix, dbName string) (simtypes.Config, dbm.DB, string, } config := NewConfigFromFlags() - config.ChainID = helpers.SimAppChainID + config.ChainID = SimAppChainID var logger log.Logger if FlagVerboseValue { diff --git a/x/bank/simulation/operations.go b/x/bank/simulation/operations.go index 92bf6db75a74..681a97aa5c59 100644 --- a/x/bank/simulation/operations.go +++ b/x/bank/simulation/operations.go @@ -7,7 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/simapp/helpers" + "github.com/cosmos/cosmos-sdk/simapp" simappparams "github.com/cosmos/cosmos-sdk/simapp/params" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" @@ -104,11 +104,11 @@ func sendMsgSend( } } txGen := simappparams.MakeEncodingConfig().TxGenerator - tx, err := helpers.GenTx( + tx, err := simapp.GenTx( txGen, []sdk.Msg{msg}, fees, - helpers.DefaultGenTxGas, + simapp.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, @@ -252,11 +252,11 @@ func sendMsgMultiSend( } txGen := simappparams.MakeEncodingConfig().TxGenerator - tx, err := helpers.GenTx( + tx, err := simapp.GenTx( txGen, []sdk.Msg{msg}, fees, - helpers.DefaultGenTxGas, + simapp.DefaultGenTxGas, chainID, accountNumbers, sequenceNumbers, diff --git a/x/distribution/simulation/operations.go b/x/distribution/simulation/operations.go index 8d90c01bbb31..dcd055a29fcc 100644 --- a/x/distribution/simulation/operations.go +++ b/x/distribution/simulation/operations.go @@ -6,7 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/simapp/helpers" + "github.com/cosmos/cosmos-sdk/simapp" simappparams "github.com/cosmos/cosmos-sdk/simapp/params" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" @@ -101,11 +101,11 @@ func SimulateMsgSetWithdrawAddress(ak types.AccountKeeper, bk types.BankKeeper, msg := types.NewMsgSetWithdrawAddress(simAccount.Address, simToAccount.Address) txGen := simappparams.MakeEncodingConfig().TxGenerator - tx, err := helpers.GenTx( + tx, err := simapp.GenTx( txGen, []sdk.Msg{msg}, fees, - helpers.DefaultGenTxGas, + simapp.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, @@ -153,11 +153,11 @@ func SimulateMsgWithdrawDelegatorReward(ak types.AccountKeeper, bk types.BankKee msg := types.NewMsgWithdrawDelegatorReward(simAccount.Address, validator.GetOperator()) txGen := simappparams.MakeEncodingConfig().TxGenerator - tx, err := helpers.GenTx( + tx, err := simapp.GenTx( txGen, []sdk.Msg{msg}, fees, - helpers.DefaultGenTxGas, + simapp.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, @@ -208,11 +208,11 @@ func SimulateMsgWithdrawValidatorCommission(ak types.AccountKeeper, bk types.Ban msg := types.NewMsgWithdrawValidatorCommission(validator.GetOperator()) txGen := simappparams.MakeEncodingConfig().TxGenerator - tx, err := helpers.GenTx( + tx, err := simapp.GenTx( txGen, []sdk.Msg{msg}, fees, - helpers.DefaultGenTxGas, + simapp.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, @@ -263,11 +263,11 @@ func SimulateMsgFundCommunityPool(ak types.AccountKeeper, bk types.BankKeeper, k msg := types.NewMsgFundCommunityPool(fundAmount, funder.Address) txGen := simappparams.MakeEncodingConfig().TxGenerator - tx, err := helpers.GenTx( + tx, err := simapp.GenTx( txGen, []sdk.Msg{msg}, fees, - helpers.DefaultGenTxGas, + simapp.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, diff --git a/x/gov/simulation/operations.go b/x/gov/simulation/operations.go index 1c6e96857104..76b77e22e7db 100644 --- a/x/gov/simulation/operations.go +++ b/x/gov/simulation/operations.go @@ -7,7 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/simapp/helpers" + "github.com/cosmos/cosmos-sdk/simapp" simappparams "github.com/cosmos/cosmos-sdk/simapp/params" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" @@ -143,11 +143,11 @@ func SimulateSubmitProposal( } txGen := simappparams.MakeEncodingConfig().TxGenerator - tx, err := helpers.GenTx( + tx, err := simapp.GenTx( txGen, []sdk.Msg{msg}, fees, - helpers.DefaultGenTxGas, + simapp.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, @@ -230,11 +230,11 @@ func SimulateMsgDeposit(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Ke } txGen := simappparams.MakeEncodingConfig().TxGenerator - tx, err := helpers.GenTx( + tx, err := simapp.GenTx( txGen, []sdk.Msg{msg}, fees, - helpers.DefaultGenTxGas, + simapp.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, @@ -292,11 +292,11 @@ func operationSimulateMsgVote(ak types.AccountKeeper, bk types.BankKeeper, k kee } txGen := simappparams.MakeEncodingConfig().TxGenerator - tx, err := helpers.GenTx( + tx, err := simapp.GenTx( txGen, []sdk.Msg{msg}, fees, - helpers.DefaultGenTxGas, + simapp.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, diff --git a/x/slashing/simulation/operations.go b/x/slashing/simulation/operations.go index cfcf5c2a413e..e71011327a21 100644 --- a/x/slashing/simulation/operations.go +++ b/x/slashing/simulation/operations.go @@ -6,7 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/simapp/helpers" + "github.com/cosmos/cosmos-sdk/simapp" simappparams "github.com/cosmos/cosmos-sdk/simapp/params" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" @@ -87,11 +87,11 @@ func SimulateMsgUnjail(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Kee msg := types.NewMsgUnjail(validator.GetOperator()) txGen := simappparams.MakeEncodingConfig().TxGenerator - tx, err := helpers.GenTx( + tx, err := simapp.GenTx( txGen, []sdk.Msg{msg}, fees, - helpers.DefaultGenTxGas, + simapp.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, diff --git a/x/staking/simulation/operations.go b/x/staking/simulation/operations.go index fbd9e444d060..831f10493014 100644 --- a/x/staking/simulation/operations.go +++ b/x/staking/simulation/operations.go @@ -6,7 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/simapp/helpers" + "github.com/cosmos/cosmos-sdk/simapp" simappparams "github.com/cosmos/cosmos-sdk/simapp/params" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" @@ -152,11 +152,11 @@ func SimulateMsgCreateValidator(ak types.AccountKeeper, bk types.BankKeeper, k k selfDelegation, description, commission, sdk.OneInt()) txGen := simappparams.MakeEncodingConfig().TxGenerator - tx, err := helpers.GenTx( + tx, err := simapp.GenTx( txGen, []sdk.Msg{msg}, fees, - helpers.DefaultGenTxGas, + simapp.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, @@ -223,11 +223,11 @@ func SimulateMsgEditValidator(ak types.AccountKeeper, bk types.BankKeeper, k kee msg := types.NewMsgEditValidator(address, description, &newCommissionRate, nil) txGen := simappparams.MakeEncodingConfig().TxGenerator - tx, err := helpers.GenTx( + tx, err := simapp.GenTx( txGen, []sdk.Msg{msg}, fees, - helpers.DefaultGenTxGas, + simapp.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, @@ -296,11 +296,11 @@ func SimulateMsgDelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper.K msg := types.NewMsgDelegate(simAccount.Address, val.GetOperator(), bondAmt) txGen := simappparams.MakeEncodingConfig().TxGenerator - tx, err := helpers.GenTx( + tx, err := simapp.GenTx( txGen, []sdk.Msg{msg}, fees, - helpers.DefaultGenTxGas, + simapp.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, @@ -386,11 +386,11 @@ func SimulateMsgUndelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper } txGen := simappparams.MakeEncodingConfig().TxGenerator - tx, err := helpers.GenTx( + tx, err := simapp.GenTx( txGen, []sdk.Msg{msg}, fees, - helpers.DefaultGenTxGas, + simapp.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, @@ -499,11 +499,11 @@ func SimulateMsgBeginRedelegate(ak types.AccountKeeper, bk types.BankKeeper, k k ) txGen := simappparams.MakeEncodingConfig().TxGenerator - tx, err := helpers.GenTx( + tx, err := simapp.GenTx( txGen, []sdk.Msg{msg}, fees, - helpers.DefaultGenTxGas, + simapp.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, From 2d70c54dc8b3f65772b2c591f443a6f861df0c91 Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Tue, 14 Jul 2020 19:34:20 +0530 Subject: [PATCH 12/15] revert simapp/helpers to test_helpers --- simapp/helpers/new_test_helpers.go | 77 ++++++++++++++++++++++++ simapp/sim_test.go | 3 +- simapp/test_helpers.go | 78 ++----------------------- simapp/utils.go | 3 +- x/bank/simulation/operations.go | 10 ++-- x/distribution/simulation/operations.go | 18 +++--- x/gov/simulation/operations.go | 14 ++--- x/slashing/simulation/operations.go | 6 +- x/staking/simulation/operations.go | 22 +++---- 9 files changed, 122 insertions(+), 109 deletions(-) create mode 100644 simapp/helpers/new_test_helpers.go diff --git a/simapp/helpers/new_test_helpers.go b/simapp/helpers/new_test_helpers.go new file mode 100644 index 000000000000..5f71e24a8cc1 --- /dev/null +++ b/simapp/helpers/new_test_helpers.go @@ -0,0 +1,77 @@ +package helpers + +import ( + "math/rand" + "time" + + "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" + "github.com/cosmos/cosmos-sdk/types/tx/signing" + authsign "github.com/cosmos/cosmos-sdk/x/auth/signing" +) + +// SimAppChainID hardcoded chainID for simulation +const ( + DefaultGenTxGas = 1000000 + SimAppChainID = "simulation-app" +) + +// GenTx generates a signed mock transaction. +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)) + + signMode := gen.SignModeHandler().DefaultMode() + + for i, p := range priv { + sigs[i] = signing.SignatureV2{ + PubKey: p.PubKey(), + Data: &signing.SingleSignatureData{ + SignMode: signMode, + }, + } + } + + 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/sim_test.go b/simapp/sim_test.go index 18f8890f379f..83acd4a24f06 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -14,6 +14,7 @@ import ( dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/simapp/helpers" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -255,7 +256,7 @@ func TestAppStateDeterminism(t *testing.T) { config.ExportParamsPath = "" config.OnOperation = false config.AllInvariants = false - config.ChainID = SimAppChainID + config.ChainID = helpers.SimAppChainID numSeeds := 3 numTimesToRunPerSeed := 5 diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index 31c44f60d0fe..0479a42d2216 100644 --- a/simapp/test_helpers.go +++ b/simapp/test_helpers.go @@ -4,7 +4,6 @@ import ( "bytes" "encoding/hex" "fmt" - "math/rand" "strconv" "testing" "time" @@ -20,21 +19,13 @@ import ( 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" - "github.com/cosmos/cosmos-sdk/types/simulation" - "github.com/cosmos/cosmos-sdk/types/tx/signing" - authsign "github.com/cosmos/cosmos-sdk/x/auth/signing" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) -// SimAppChainID hardcoded chainID for simulation -const ( - DefaultGenTxGas = 1000000 - SimAppChainID = "simulation-app" -) - // DefaultConsensusParams defines the default Tendermint consensus params used in // SimApp testing. var DefaultConsensusParams = &abci.ConsensusParams{ @@ -317,63 +308,6 @@ func CheckBalance(t *testing.T, app *SimApp, addr sdk.AccAddress, balances sdk.C require.True(t, balances.IsEqual(app.BankKeeper.GetAllBalances(ctxCheck, addr))) } -// GenTx generates a signed mock transaction. -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)) - - signMode := gen.SignModeHandler().DefaultMode() - - for i, p := range priv { - sigs[i] = signing.SignatureV2{ - PubKey: p.PubKey(), - Data: &signing.SingleSignatureData{ - SignMode: signMode, - }, - } - } - - 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 -} - // SignCheckDeliver checks a generated signed transaction and simulates a // block commitment with the given transaction. A test assertion is made using // the parameter 'expPass' against the result. A corresponding result is @@ -383,11 +317,11 @@ func SignCheckDeliver( accNums, seq []uint64, expSimPass, expPass bool, priv ...crypto.PrivKey, ) (sdk.GasInfo, *sdk.Result, error) { - tx, err := GenTx( + tx, err := helpers.GenTx( txGen, msgs, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 0)}, - DefaultGenTxGas, + helpers.DefaultGenTxGas, "", accNums, seq, @@ -429,15 +363,15 @@ 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(txGen client.TxGenerator, msgs []sdk.Msg, accNums []uint64, initSeqNums []uint64, numToGenerate int, priv ...crypto.PrivKey) ([]sdk.Tx, error) { +func GenSequenceOfTxs(msgs []sdk.Msg, txGen client.TxGenerator, 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], err = GenTx( + txs[i], err = helpers.GenTx( txGen, msgs, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 0)}, - DefaultGenTxGas, + helpers.DefaultGenTxGas, "", accNums, initSeqNums, diff --git a/simapp/utils.go b/simapp/utils.go index 5cda88760271..6ac89055dc8e 100644 --- a/simapp/utils.go +++ b/simapp/utils.go @@ -10,6 +10,7 @@ import ( dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/simapp/helpers" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" @@ -24,7 +25,7 @@ func SetupSimulation(dirPrefix, dbName string) (simtypes.Config, dbm.DB, string, } config := NewConfigFromFlags() - config.ChainID = SimAppChainID + config.ChainID = helpers.SimAppChainID var logger log.Logger if FlagVerboseValue { diff --git a/x/bank/simulation/operations.go b/x/bank/simulation/operations.go index 681a97aa5c59..92bf6db75a74 100644 --- a/x/bank/simulation/operations.go +++ b/x/bank/simulation/operations.go @@ -7,7 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/simapp" + "github.com/cosmos/cosmos-sdk/simapp/helpers" simappparams "github.com/cosmos/cosmos-sdk/simapp/params" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" @@ -104,11 +104,11 @@ func sendMsgSend( } } txGen := simappparams.MakeEncodingConfig().TxGenerator - tx, err := simapp.GenTx( + tx, err := helpers.GenTx( txGen, []sdk.Msg{msg}, fees, - simapp.DefaultGenTxGas, + helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, @@ -252,11 +252,11 @@ func sendMsgMultiSend( } txGen := simappparams.MakeEncodingConfig().TxGenerator - tx, err := simapp.GenTx( + tx, err := helpers.GenTx( txGen, []sdk.Msg{msg}, fees, - simapp.DefaultGenTxGas, + helpers.DefaultGenTxGas, chainID, accountNumbers, sequenceNumbers, diff --git a/x/distribution/simulation/operations.go b/x/distribution/simulation/operations.go index dcd055a29fcc..8d90c01bbb31 100644 --- a/x/distribution/simulation/operations.go +++ b/x/distribution/simulation/operations.go @@ -6,7 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/simapp" + "github.com/cosmos/cosmos-sdk/simapp/helpers" simappparams "github.com/cosmos/cosmos-sdk/simapp/params" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" @@ -101,11 +101,11 @@ func SimulateMsgSetWithdrawAddress(ak types.AccountKeeper, bk types.BankKeeper, msg := types.NewMsgSetWithdrawAddress(simAccount.Address, simToAccount.Address) txGen := simappparams.MakeEncodingConfig().TxGenerator - tx, err := simapp.GenTx( + tx, err := helpers.GenTx( txGen, []sdk.Msg{msg}, fees, - simapp.DefaultGenTxGas, + helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, @@ -153,11 +153,11 @@ func SimulateMsgWithdrawDelegatorReward(ak types.AccountKeeper, bk types.BankKee msg := types.NewMsgWithdrawDelegatorReward(simAccount.Address, validator.GetOperator()) txGen := simappparams.MakeEncodingConfig().TxGenerator - tx, err := simapp.GenTx( + tx, err := helpers.GenTx( txGen, []sdk.Msg{msg}, fees, - simapp.DefaultGenTxGas, + helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, @@ -208,11 +208,11 @@ func SimulateMsgWithdrawValidatorCommission(ak types.AccountKeeper, bk types.Ban msg := types.NewMsgWithdrawValidatorCommission(validator.GetOperator()) txGen := simappparams.MakeEncodingConfig().TxGenerator - tx, err := simapp.GenTx( + tx, err := helpers.GenTx( txGen, []sdk.Msg{msg}, fees, - simapp.DefaultGenTxGas, + helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, @@ -263,11 +263,11 @@ func SimulateMsgFundCommunityPool(ak types.AccountKeeper, bk types.BankKeeper, k msg := types.NewMsgFundCommunityPool(fundAmount, funder.Address) txGen := simappparams.MakeEncodingConfig().TxGenerator - tx, err := simapp.GenTx( + tx, err := helpers.GenTx( txGen, []sdk.Msg{msg}, fees, - simapp.DefaultGenTxGas, + helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, diff --git a/x/gov/simulation/operations.go b/x/gov/simulation/operations.go index 76b77e22e7db..1c6e96857104 100644 --- a/x/gov/simulation/operations.go +++ b/x/gov/simulation/operations.go @@ -7,7 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/simapp" + "github.com/cosmos/cosmos-sdk/simapp/helpers" simappparams "github.com/cosmos/cosmos-sdk/simapp/params" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" @@ -143,11 +143,11 @@ func SimulateSubmitProposal( } txGen := simappparams.MakeEncodingConfig().TxGenerator - tx, err := simapp.GenTx( + tx, err := helpers.GenTx( txGen, []sdk.Msg{msg}, fees, - simapp.DefaultGenTxGas, + helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, @@ -230,11 +230,11 @@ func SimulateMsgDeposit(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Ke } txGen := simappparams.MakeEncodingConfig().TxGenerator - tx, err := simapp.GenTx( + tx, err := helpers.GenTx( txGen, []sdk.Msg{msg}, fees, - simapp.DefaultGenTxGas, + helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, @@ -292,11 +292,11 @@ func operationSimulateMsgVote(ak types.AccountKeeper, bk types.BankKeeper, k kee } txGen := simappparams.MakeEncodingConfig().TxGenerator - tx, err := simapp.GenTx( + tx, err := helpers.GenTx( txGen, []sdk.Msg{msg}, fees, - simapp.DefaultGenTxGas, + helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, diff --git a/x/slashing/simulation/operations.go b/x/slashing/simulation/operations.go index e71011327a21..cfcf5c2a413e 100644 --- a/x/slashing/simulation/operations.go +++ b/x/slashing/simulation/operations.go @@ -6,7 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/simapp" + "github.com/cosmos/cosmos-sdk/simapp/helpers" simappparams "github.com/cosmos/cosmos-sdk/simapp/params" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" @@ -87,11 +87,11 @@ func SimulateMsgUnjail(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Kee msg := types.NewMsgUnjail(validator.GetOperator()) txGen := simappparams.MakeEncodingConfig().TxGenerator - tx, err := simapp.GenTx( + tx, err := helpers.GenTx( txGen, []sdk.Msg{msg}, fees, - simapp.DefaultGenTxGas, + helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, diff --git a/x/staking/simulation/operations.go b/x/staking/simulation/operations.go index 831f10493014..fbd9e444d060 100644 --- a/x/staking/simulation/operations.go +++ b/x/staking/simulation/operations.go @@ -6,7 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/simapp" + "github.com/cosmos/cosmos-sdk/simapp/helpers" simappparams "github.com/cosmos/cosmos-sdk/simapp/params" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" @@ -152,11 +152,11 @@ func SimulateMsgCreateValidator(ak types.AccountKeeper, bk types.BankKeeper, k k selfDelegation, description, commission, sdk.OneInt()) txGen := simappparams.MakeEncodingConfig().TxGenerator - tx, err := simapp.GenTx( + tx, err := helpers.GenTx( txGen, []sdk.Msg{msg}, fees, - simapp.DefaultGenTxGas, + helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, @@ -223,11 +223,11 @@ func SimulateMsgEditValidator(ak types.AccountKeeper, bk types.BankKeeper, k kee msg := types.NewMsgEditValidator(address, description, &newCommissionRate, nil) txGen := simappparams.MakeEncodingConfig().TxGenerator - tx, err := simapp.GenTx( + tx, err := helpers.GenTx( txGen, []sdk.Msg{msg}, fees, - simapp.DefaultGenTxGas, + helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, @@ -296,11 +296,11 @@ func SimulateMsgDelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper.K msg := types.NewMsgDelegate(simAccount.Address, val.GetOperator(), bondAmt) txGen := simappparams.MakeEncodingConfig().TxGenerator - tx, err := simapp.GenTx( + tx, err := helpers.GenTx( txGen, []sdk.Msg{msg}, fees, - simapp.DefaultGenTxGas, + helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, @@ -386,11 +386,11 @@ func SimulateMsgUndelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper } txGen := simappparams.MakeEncodingConfig().TxGenerator - tx, err := simapp.GenTx( + tx, err := helpers.GenTx( txGen, []sdk.Msg{msg}, fees, - simapp.DefaultGenTxGas, + helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, @@ -499,11 +499,11 @@ func SimulateMsgBeginRedelegate(ak types.AccountKeeper, bk types.BankKeeper, k k ) txGen := simappparams.MakeEncodingConfig().TxGenerator - tx, err := simapp.GenTx( + tx, err := helpers.GenTx( txGen, []sdk.Msg{msg}, fees, - simapp.DefaultGenTxGas, + helpers.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, []uint64{account.GetSequence()}, From 13c7ef620c45f728f31bb4dc79520c126124106e Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Tue, 14 Jul 2020 19:37:16 +0530 Subject: [PATCH 13/15] revert renaming --- simapp/helpers/{new_test_helpers.go => test_helpers.go} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename simapp/helpers/{new_test_helpers.go => test_helpers.go} (100%) diff --git a/simapp/helpers/new_test_helpers.go b/simapp/helpers/test_helpers.go similarity index 100% rename from simapp/helpers/new_test_helpers.go rename to simapp/helpers/test_helpers.go From 9f18e3b265d14ac7a9dd0fdb7d49669f09f80ecb Mon Sep 17 00:00:00 2001 From: SaReN Date: Tue, 14 Jul 2020 19:39:09 +0530 Subject: [PATCH 14/15] address suggestion Co-authored-by: Aaron Craelius --- simapp/test_helpers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index 0479a42d2216..758b84d4b616 100644 --- a/simapp/test_helpers.go +++ b/simapp/test_helpers.go @@ -363,7 +363,7 @@ 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, txGen client.TxGenerator, accNums []uint64, initSeqNums []uint64, numToGenerate int, priv ...crypto.PrivKey) ([]sdk.Tx, error) { +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++ { From 6393ec68821a52019b71eb535c8e568e637c712e Mon Sep 17 00:00:00 2001 From: sahith-narahari Date: Tue, 14 Jul 2020 22:56:50 +0530 Subject: [PATCH 15/15] fix tests --- x/bank/bench_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/bank/bench_test.go b/x/bank/bench_test.go index d9e23efdf6f3..f82384ad47fb 100644 --- a/x/bank/bench_test.go +++ b/x/bank/bench_test.go @@ -35,7 +35,7 @@ func BenchmarkOneBankSendTxPerBlock(b *testing.B) { txGen := simappparams.MakeEncodingConfig().TxGenerator // Precompute all txs - txs, err := simapp.GenSequenceOfTxs([]sdk.Msg{sendMsg1}, txGen, []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() @@ -77,7 +77,7 @@ func BenchmarkOneBankMultiSendTxPerBlock(b *testing.B) { txGen := simappparams.MakeEncodingConfig().TxGenerator // Precompute all txs - txs, err := simapp.GenSequenceOfTxs([]sdk.Msg{multiSendMsg1}, txGen, []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()