diff --git a/x/gov/simulation/operations.go b/x/gov/simulation/operations.go index 1256fed08eb..f180144432f 100644 --- a/x/gov/simulation/operations.go +++ b/x/gov/simulation/operations.go @@ -26,7 +26,6 @@ var ( TypeMsgVoteWeighted = sdk.MsgTypeURL(&v1.MsgVoteWeighted{}) TypeMsgSubmitProposal = sdk.MsgTypeURL(&v1.MsgSubmitProposal{}) TypeMsgCancelProposal = sdk.MsgTypeURL(&v1.MsgCancelProposal{}) - TypeMsgUpdateParams = sdk.MsgTypeURL(&v1.MsgUpdateParams{}) ) // Simulation operation weights constants @@ -84,7 +83,8 @@ func WeightedOperations(appParams simtypes.AppParams, cdc codec.JSONCodec, ak ty wMsg := wMsg // pin variable var weight int appParams.GetOrGenerate(cdc, wMsg.AppParamsKey(), &weight, nil, - func(_ *rand.Rand) { weight = wMsg.DefaultWeight() }) + func(_ *rand.Rand) { weight = wMsg.DefaultWeight() }, + ) wProposalOps = append( wProposalOps, @@ -101,7 +101,8 @@ func WeightedOperations(appParams simtypes.AppParams, cdc codec.JSONCodec, ak ty wContent := wContent // pin variable var weight int appParams.GetOrGenerate(cdc, wContent.AppParamsKey(), &weight, nil, - func(_ *rand.Rand) { weight = wContent.DefaultWeight() }) + func(_ *rand.Rand) { weight = wContent.DefaultWeight() }, + ) wLegacyProposalOps = append( wLegacyProposalOps, @@ -138,29 +139,15 @@ func WeightedOperations(appParams simtypes.AppParams, cdc codec.JSONCodec, ak ty // voting on the proposal, and subsequently slashing the proposal. It is implemented using // future operations. func SimulateMsgSubmitProposal(ak types.AccountKeeper, bk types.BankKeeper, k *keeper.Keeper, msgSim simtypes.MsgSimulatorFn) simtypes.Operation { - return func( - r *rand.Rand, - app *baseapp.BaseApp, - ctx sdk.Context, - accs []simtypes.Account, - chainID string, + return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { - simAccount, _ := simtypes.RandomAcc(r, accs) - deposit, skip, err := randomDeposit(r, ctx, ak, bk, k, simAccount.Address, true) - switch { - case skip: - return simtypes.NoOpMsg(types.ModuleName, TypeMsgSubmitProposal, "skip deposit"), nil, nil - case err != nil: - return simtypes.NoOpMsg(types.ModuleName, TypeMsgSubmitProposal, "unable to generate deposit"), nil, err - } - msgs := []sdk.Msg{} proposalMsg := msgSim(r, ctx, accs) if proposalMsg != nil { msgs = append(msgs, proposalMsg) } - return simulateMsgSubmitProposal(ak, bk, k, msgs, simAccount, deposit)(r, app, ctx, accs, chainID) + return simulateMsgSubmitProposal(ak, bk, k, msgs)(r, app, ctx, accs, chainID) } } @@ -168,9 +155,7 @@ func SimulateMsgSubmitProposal(ak types.AccountKeeper, bk types.BankKeeper, k *k // voting on the proposal, and subsequently slashing the proposal. It is implemented using // future operations. func SimulateMsgSubmitLegacyProposal(ak types.AccountKeeper, bk types.BankKeeper, k *keeper.Keeper, contentSim simtypes.ContentSimulatorFn) simtypes.Operation { //nolint:staticcheck - return func( - r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, - accs []simtypes.Account, chainID string, + return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { // 1) submit proposal now content := contentSim(r, ctx, accs) @@ -178,33 +163,17 @@ func SimulateMsgSubmitLegacyProposal(ak types.AccountKeeper, bk types.BankKeeper return simtypes.NoOpMsg(types.ModuleName, TypeMsgSubmitProposal, "content is nil"), nil, nil } - simAccount, _ := simtypes.RandomAcc(r, accs) - deposit, skip, err := randomDeposit(r, ctx, ak, bk, k, simAccount.Address, true) - switch { - case skip: - return simtypes.NoOpMsg(types.ModuleName, TypeMsgSubmitProposal, "skip deposit"), nil, nil - case err != nil: - return simtypes.NoOpMsg(types.ModuleName, TypeMsgSubmitProposal, "unable to generate deposit"), nil, err - } - - macc := k.GetGovernanceAccount(ctx) - contentMsg, err := v1.NewLegacyContent(content, macc.GetAddress().String()) + govacc := k.GetGovernanceAccount(ctx) + contentMsg, err := v1.NewLegacyContent(content, govacc.GetAddress().String()) if err != nil { return simtypes.NoOpMsg(types.ModuleName, TypeMsgSubmitProposal, "error converting legacy content into proposal message"), nil, err } - return simulateMsgSubmitProposal(ak, bk, k, []sdk.Msg{contentMsg}, simAccount, deposit)(r, app, ctx, accs, chainID) + return simulateMsgSubmitProposal(ak, bk, k, []sdk.Msg{contentMsg})(r, app, ctx, accs, chainID) } } -func simulateMsgSubmitProposal( - ak types.AccountKeeper, - bk types.BankKeeper, - k *keeper.Keeper, - proposalMsgs []sdk.Msg, - simAccount simtypes.Account, - deposit sdk.Coins, -) simtypes.Operation { +func simulateMsgSubmitProposal(ak types.AccountKeeper, bk types.BankKeeper, k *keeper.Keeper, proposalMsgs []sdk.Msg) simtypes.Operation { // The states are: // column 1: All validators vote // column 2: 90% vote @@ -233,6 +202,15 @@ func simulateMsgSubmitProposal( accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + simAccount, _ := simtypes.RandomAcc(r, accs) + deposit, skip, err := randomDeposit(r, ctx, ak, bk, k, simAccount.Address, true) + switch { + case skip: + return simtypes.NoOpMsg(types.ModuleName, TypeMsgSubmitProposal, "skip deposit"), nil, nil + case err != nil: + return simtypes.NoOpMsg(types.ModuleName, TypeMsgSubmitProposal, "unable to generate deposit"), nil, err + } + msg, err := v1.NewMsgSubmitProposal( proposalMsgs, deposit, @@ -246,23 +224,12 @@ func simulateMsgSubmitProposal( } account := ak.GetAccount(ctx, simAccount.Address) - spendable := bk.SpendableCoins(ctx, account.GetAddress()) - - var fees sdk.Coins - coins, hasNeg := spendable.SafeSub(deposit...) - if !hasNeg { - fees, err = simtypes.RandomFees(r, ctx, coins) - if err != nil { - return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to generate fees"), nil, err - } - } - txGen := moduletestutil.MakeTestEncodingConfig().TxConfig tx, err := simtestutil.GenSignedMockTx( r, txGen, []sdk.Msg{msg}, - fees, + sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 0)}, simtestutil.DefaultGenTxGas, chainID, []uint64{account.GetAccountNumber()}, diff --git a/x/gov/simulation/operations_test.go b/x/gov/simulation/operations_test.go index 7d34ad040ef..bd599984124 100644 --- a/x/gov/simulation/operations_test.go +++ b/x/gov/simulation/operations_test.go @@ -6,7 +6,6 @@ import ( "testing" "time" - storetypes "cosmossdk.io/store/types" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" @@ -115,8 +114,9 @@ func TestWeightedOperations(t *testing.T) { {0, types.ModuleName, simulation.TypeMsgSubmitProposal}, } + require.Equal(t, len(weightesOps), len(expected), "number of operations should be the same") for i, w := range weightesOps { - operationMsg, _, err := w.Op()(r, app.BaseApp, ctx.WithBlockGasMeter(storetypes.NewInfiniteGasMeter()), accs, ctx.ChainID()) + operationMsg, _, err := w.Op()(r, app.BaseApp, ctx, accs, ctx.ChainID()) require.NoError(t, err) // the following checks are very much dependent from the ordering of the output given diff --git a/x/nft/module/module.go b/x/nft/module/module.go index 7be7d071bce..2baae00b465 100644 --- a/x/nft/module/module.go +++ b/x/nft/module/module.go @@ -162,12 +162,6 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) { simulation.RandomizedGenState(simState) } -// ProposalContents returns all the nft content functions used to -// simulate governance proposals. -func (am AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent { - return nil -} - // RegisterStoreDecoder registers a decoder for nft module's types func (am AppModule) RegisterStoreDecoder(sdr simtypes.StoreDecoderRegistry) { sdr[keeper.StoreKey] = simulation.NewDecodeStore(am.cdc)