From 08ed4371af085156526c6ef235a5bb8cd388823d Mon Sep 17 00:00:00 2001 From: atheeshp <59333759+atheeshp@users.noreply.github.com> Date: Mon, 29 Aug 2022 18:45:36 +0530 Subject: [PATCH 1/6] fix: x/gov migrations (#13045) * fix migration tests * add change log * Update CHANGELOG.md * review changes * review changes --- CHANGELOG.md | 1 + x/genutil/migrations/v047/migrate.go | 19 +++++++++ x/gov/migrations/v3/json.go | 11 ++--- x/gov/migrations/v3/json_test.go | 23 +++++----- x/gov/migrations/v4/json.go | 25 +++++++++++ x/gov/migrations/v4/json_test.go | 64 ++++++++++++++++++++++++++++ 6 files changed, 124 insertions(+), 19 deletions(-) create mode 100644 x/gov/migrations/v4/json.go create mode 100644 x/gov/migrations/v4/json_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 069a91f883ce..caa81209e359 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -140,6 +140,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (store) [#12945](https://github.com/cosmos/cosmos-sdk/pull/12945) Fix nil end semantics in store/cachekv/iterator when iterating a dirty cache. * (export) [#13029](https://github.com/cosmos/cosmos-sdk/pull/13029) Fix exporting the blockParams regression. * (x/gov) [#13051](https://github.com/cosmos/cosmos-sdk/pull/13051) In SubmitPropsal, when a legacy msg fails it's handler call, wrap the error as ErrInvalidProposalContent (instead of ErrNoProposalHandlerExists). +* (x/gov) [#13045](https://github.com/cosmos/cosmos-sdk/pull/13045) Fix gov migrations for v3(0.46). ### Deprecated diff --git a/x/genutil/migrations/v047/migrate.go b/x/genutil/migrations/v047/migrate.go index 2d322fb6174b..699b24a0a590 100644 --- a/x/genutil/migrations/v047/migrate.go +++ b/x/genutil/migrations/v047/migrate.go @@ -5,6 +5,8 @@ import ( bankv4 "github.com/cosmos/cosmos-sdk/x/bank/migrations/v4" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/genutil/types" + v4gov "github.com/cosmos/cosmos-sdk/x/gov/migrations/v4" + v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" ) // Migrate migrates exported state from v0.46 to a v0.47 genesis state. @@ -17,5 +19,22 @@ func Migrate(appState types.AppMap, clientCtx client.Context) types.AppMap { newBankState := bankv4.MigrateGenState(oldBankState) appState[banktypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(newBankState) } + + if govOldState, ok := appState[v4gov.ModuleName]; ok { + // unmarshal relative source genesis application state + var old v1.GenesisState + clientCtx.Codec.MustUnmarshalJSON(govOldState, &old) + + // delete deprecated x/gov genesis state + delete(appState, v4gov.ModuleName) + + // set the x/gov genesis state with new state. + new, err := v4gov.MigrateJSON(&old) + if err != nil { + panic(err) + } + appState[v4gov.ModuleName] = clientCtx.Codec.MustMarshalJSON(new) + } + return appState } diff --git a/x/gov/migrations/v3/json.go b/x/gov/migrations/v3/json.go index 94116b776564..327e83a58b19 100644 --- a/x/gov/migrations/v3/json.go +++ b/x/gov/migrations/v3/json.go @@ -27,13 +27,8 @@ func MigrateJSON(oldState *v1beta1.GenesisState) (*v1.GenesisState, error) { Deposits: convertToNewDeposits(oldState.Deposits), Votes: newVotes, Proposals: newProps, - Params: &v1.Params{ - MinDeposit: depParams.MinDeposit, - MaxDepositPeriod: depParams.MaxDepositPeriod, - VotingPeriod: votingParms.VotingPeriod, - Quorum: tallyParams.Quorum, - Threshold: tallyParams.Threshold, - VetoThreshold: tallyParams.VetoThreshold, - }, + DepositParams: &depParams, + VotingParams: &votingParms, + TallyParams: &tallyParams, }, nil } diff --git a/x/gov/migrations/v3/json_test.go b/x/gov/migrations/v3/json_test.go index 6eee6b86bad2..7cc1ccd93dcb 100644 --- a/x/gov/migrations/v3/json_test.go +++ b/x/gov/migrations/v3/json_test.go @@ -74,22 +74,17 @@ func TestMigrateJSON(t *testing.T) { // Make sure about: // - Proposals use MsgExecLegacyContent expected := `{ - "deposit_params": null, - "deposits": [], - "params": { + "deposit_params": { "max_deposit_period": "172800s", "min_deposit": [ { "amount": "10000000", "denom": "stake" } - ], - "min_initial_deposit_ratio": "", - "quorum": "0.334000000000000000", - "threshold": "0.500000000000000000", - "veto_threshold": "0.334000000000000000", - "voting_period": "172800s" + ] }, + "deposits": [], + "params": null, "proposals": [ { "deposit_end_time": "2001-09-09T01:46:40Z", @@ -125,7 +120,11 @@ func TestMigrateJSON(t *testing.T) { } ], "starting_proposal_id": "1", - "tally_params": null, + "tally_params": { + "quorum": "0.334000000000000000", + "threshold": "0.500000000000000000", + "veto_threshold": "0.334000000000000000" + }, "votes": [ { "metadata": "", @@ -150,7 +149,9 @@ func TestMigrateJSON(t *testing.T) { "voter": "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh" } ], - "voting_params": null + "voting_params": { + "voting_period": "172800s" + } }` require.Equal(t, expected, string(indentedBz)) diff --git a/x/gov/migrations/v4/json.go b/x/gov/migrations/v4/json.go new file mode 100644 index 000000000000..f633167aec34 --- /dev/null +++ b/x/gov/migrations/v4/json.go @@ -0,0 +1,25 @@ +package v4 + +import ( + v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" +) + +func MigrateJSON(oldState *v1.GenesisState) (*v1.GenesisState, error) { + params := v1.NewParams( + oldState.DepositParams.MinDeposit, + *oldState.DepositParams.MaxDepositPeriod, + *oldState.VotingParams.VotingPeriod, + oldState.TallyParams.Quorum, + oldState.TallyParams.Threshold, + oldState.TallyParams.VetoThreshold, + v1.DefaultParams().MinInitialDepositRatio, + ) + + return &v1.GenesisState{ + StartingProposalId: oldState.StartingProposalId, + Deposits: oldState.Deposits, + Votes: oldState.Votes, + Proposals: oldState.Proposals, + Params: ¶ms, + }, nil +} diff --git a/x/gov/migrations/v4/json_test.go b/x/gov/migrations/v4/json_test.go new file mode 100644 index 000000000000..0b58e63d7607 --- /dev/null +++ b/x/gov/migrations/v4/json_test.go @@ -0,0 +1,64 @@ +package v4_test + +import ( + "encoding/json" + "testing" + + "github.com/cosmos/cosmos-sdk/client" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + "github.com/cosmos/cosmos-sdk/x/gov" + v4 "github.com/cosmos/cosmos-sdk/x/gov/migrations/v4" + v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + "github.com/stretchr/testify/require" +) + +func TestMigrateJSON(t *testing.T) { + encodingConfig := moduletestutil.MakeTestEncodingConfig(gov.AppModuleBasic{}) + clientCtx := client.Context{}. + WithInterfaceRegistry(encodingConfig.InterfaceRegistry). + WithTxConfig(encodingConfig.TxConfig). + WithCodec(encodingConfig.Codec) + + govGenState := v1.DefaultGenesisState() + + migrated, err := v4.MigrateJSON(govGenState) + require.NoError(t, err) + + bz, err := clientCtx.Codec.MarshalJSON(migrated) + require.NoError(t, err) + + // Indent the JSON bz correctly. + var jsonObj map[string]interface{} + err = json.Unmarshal(bz, &jsonObj) + require.NoError(t, err) + indentedBz, err := json.MarshalIndent(jsonObj, "", "\t") + require.NoError(t, err) + + // Make sure about: + // - Proposals use MsgExecLegacyContent + expected := `{ + "deposit_params": null, + "deposits": [], + "params": { + "max_deposit_period": "172800s", + "min_deposit": [ + { + "amount": "10000000", + "denom": "stake" + } + ], + "min_initial_deposit_ratio": "0.000000000000000000", + "quorum": "0.334000000000000000", + "threshold": "0.500000000000000000", + "veto_threshold": "0.334000000000000000", + "voting_period": "172800s" + }, + "proposals": [], + "starting_proposal_id": "1", + "tally_params": null, + "votes": [], + "voting_params": null +}` + + require.Equal(t, expected, string(indentedBz)) +} From b44aecad4b2a1b732b23f328e579b6ee52e8cfda Mon Sep 17 00:00:00 2001 From: Marko Date: Mon, 29 Aug 2022 15:45:15 +0200 Subject: [PATCH 2/6] chore: add short tempalte for epics (#13072) * add short tempalte for epics * revert go.sum --- .github/ISSUE_TEMPLATE/epics.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/epics.md diff --git a/.github/ISSUE_TEMPLATE/epics.md b/.github/ISSUE_TEMPLATE/epics.md new file mode 100644 index 000000000000..17aecab892cc --- /dev/null +++ b/.github/ISSUE_TEMPLATE/epics.md @@ -0,0 +1,30 @@ +--- +name: Epic +about: Create an epic/user + +--- + + + +## Summary + + + +## Problem Definition + + + +## Work Breakdown + + From 7b746717baee037a0628e945041fa02d0ccb2d16 Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaurym@users.noreply.github.com> Date: Mon, 29 Aug 2022 16:24:51 +0200 Subject: [PATCH 3/6] test(gov): Remove `simapp` references from module tests and simulations (#13043) ## Description 0 occurences of "simapp" in x/gov. closes: #12752 - [x] Move some x/gov module tests (those in x/gov root folder) to tests/integration, as they rely on a new module x/distribution - [x] convert rest of x/gov module tests to use depinject - [x] remove simapp references from x/gov/simulations - [x] 0 occurences of "simapp" in x/gov --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable) --- simapp/params/weights.go | 3 - tests/integration/gov/common_test.go | 29 ++++ tests/integration/gov/genesis_test.go | 159 ++++++++++++++++++++ {x => tests/integration}/gov/module_test.go | 0 testutil/configurator/configurator.go | 16 ++ testutil/sims/weights.go | 3 - x/auth/client/testutil/suite.go | 3 - x/feegrant/client/testutil/suite.go | 4 - x/gov/abci_test.go | 146 +++++++++--------- x/gov/common_test.go | 39 +++++ x/gov/genesis_test.go | 111 +------------- x/gov/simulation/operations.go | 20 ++- x/gov/simulation/operations_test.go | 121 +++++++++------ 13 files changed, 413 insertions(+), 241 deletions(-) create mode 100644 tests/integration/gov/common_test.go create mode 100644 tests/integration/gov/genesis_test.go rename {x => tests/integration}/gov/module_test.go (100%) diff --git a/simapp/params/weights.go b/simapp/params/weights.go index f5e89fff02a7..59e092969ed6 100644 --- a/simapp/params/weights.go +++ b/simapp/params/weights.go @@ -4,9 +4,6 @@ package params const ( DefaultWeightMsgSend int = 100 DefaultWeightMsgMultiSend int = 10 - DefaultWeightMsgDeposit int = 100 - DefaultWeightMsgVote int = 67 - DefaultWeightMsgVoteWeighted int = 33 DefaultWeightMsgCreateValidator int = 100 DefaultWeightMsgEditValidator int = 5 DefaultWeightMsgDelegate int = 100 diff --git a/tests/integration/gov/common_test.go b/tests/integration/gov/common_test.go new file mode 100644 index 000000000000..27e6932c6046 --- /dev/null +++ b/tests/integration/gov/common_test.go @@ -0,0 +1,29 @@ +package gov_test + +import ( + "testing" + + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/cosmos/cosmos-sdk/x/gov/types" + v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/stretchr/testify/require" +) + +var ( + valTokens = sdk.TokensFromConsensusPower(42, sdk.DefaultPowerReduction) + TestProposal = v1beta1.NewTextProposal("Test", "description") + TestDescription = stakingtypes.NewDescription("T", "E", "S", "T", "Z") + TestCommissionRates = stakingtypes.NewCommissionRates(math.LegacyZeroDec(), math.LegacyZeroDec(), math.LegacyZeroDec()) +) + +// mkTestLegacyContent creates a MsgExecLegacyContent for testing purposes. +func mkTestLegacyContent(t *testing.T) *v1.MsgExecLegacyContent { + msgContent, err := v1.NewLegacyContent(TestProposal, authtypes.NewModuleAddress(types.ModuleName).String()) + require.NoError(t, err) + + return msgContent +} diff --git a/tests/integration/gov/genesis_test.go b/tests/integration/gov/genesis_test.go new file mode 100644 index 000000000000..ef8ecf93f423 --- /dev/null +++ b/tests/integration/gov/genesis_test.go @@ -0,0 +1,159 @@ +package gov_test + +import ( + "encoding/json" + "testing" + + "github.com/stretchr/testify/require" + abci "github.com/tendermint/tendermint/abci/types" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/runtime" + "github.com/cosmos/cosmos-sdk/testutil/configurator" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" + sdk "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/cosmos-sdk/x/auth" + authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + _ "github.com/cosmos/cosmos-sdk/x/bank" + bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + _ "github.com/cosmos/cosmos-sdk/x/distribution" + distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" + distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + "github.com/cosmos/cosmos-sdk/x/gov" + "github.com/cosmos/cosmos-sdk/x/gov/keeper" + "github.com/cosmos/cosmos-sdk/x/gov/types" + v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + _ "github.com/cosmos/cosmos-sdk/x/params" + _ "github.com/cosmos/cosmos-sdk/x/staking" + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" +) + +type suite struct { + cdc codec.Codec + app *runtime.App + AccountKeeper authkeeper.AccountKeeper + BankKeeper bankkeeper.Keeper + DistrKeeper distrkeeper.Keeper + GovKeeper *keeper.Keeper + StakingKeeper *stakingkeeper.Keeper + appBuilder *runtime.AppBuilder +} + +var appConfig = configurator.NewAppConfig( + configurator.ParamsModule(), + configurator.AuthModule(), + configurator.StakingModule(), + configurator.BankModule(), + configurator.GovModule(), + configurator.DistributionModule(), + configurator.MintModule(), +) + +func TestImportExportQueues(t *testing.T) { + var err error + + s1 := suite{} + s1.app, err = simtestutil.SetupWithConfiguration( + appConfig, + simtestutil.DefaultStartUpConfig(), + &s1.AccountKeeper, &s1.BankKeeper, &s1.DistrKeeper, &s1.GovKeeper, &s1.StakingKeeper, &s1.cdc, &s1.appBuilder, + ) + require.NoError(t, err) + + ctx := s1.app.BaseApp.NewContext(false, tmproto.Header{}) + addrs := simtestutil.AddTestAddrs(s1.BankKeeper, s1.StakingKeeper, ctx, 1, valTokens) + + header := tmproto.Header{Height: s1.app.LastBlockHeight() + 1} + s1.app.BeginBlock(abci.RequestBeginBlock{Header: header}) + + ctx = s1.app.BaseApp.NewContext(false, tmproto.Header{}) + // Create two proposals, put the second into the voting period + proposal1, err := s1.GovKeeper.SubmitProposal(ctx, []sdk.Msg{mkTestLegacyContent(t)}, "") + require.NoError(t, err) + proposalID1 := proposal1.Id + + proposal2, err := s1.GovKeeper.SubmitProposal(ctx, []sdk.Msg{mkTestLegacyContent(t)}, "") + require.NoError(t, err) + proposalID2 := proposal2.Id + + votingStarted, err := s1.GovKeeper.AddDeposit(ctx, proposalID2, addrs[0], s1.GovKeeper.GetParams(ctx).MinDeposit) + require.NoError(t, err) + require.True(t, votingStarted) + + proposal1, ok := s1.GovKeeper.GetProposal(ctx, proposalID1) + require.True(t, ok) + proposal2, ok = s1.GovKeeper.GetProposal(ctx, proposalID2) + require.True(t, ok) + require.True(t, proposal1.Status == v1.StatusDepositPeriod) + require.True(t, proposal2.Status == v1.StatusVotingPeriod) + + authGenState := s1.AccountKeeper.ExportGenesis(ctx) + bankGenState := s1.BankKeeper.ExportGenesis(ctx) + stakingGenState := s1.StakingKeeper.ExportGenesis(ctx) + distributionGenState := s1.DistrKeeper.ExportGenesis(ctx) + + // export the state and import it into a new app + govGenState := gov.ExportGenesis(ctx, s1.GovKeeper) + genesisState := s1.appBuilder.DefaultGenesis() + + genesisState[authtypes.ModuleName] = s1.cdc.MustMarshalJSON(authGenState) + genesisState[banktypes.ModuleName] = s1.cdc.MustMarshalJSON(bankGenState) + genesisState[types.ModuleName] = s1.cdc.MustMarshalJSON(govGenState) + genesisState[stakingtypes.ModuleName] = s1.cdc.MustMarshalJSON(stakingGenState) + genesisState[distributiontypes.ModuleName] = s1.cdc.MustMarshalJSON(distributionGenState) + + stateBytes, err := json.MarshalIndent(genesisState, "", " ") + require.NoError(t, err) + + s2 := suite{} + s2.app, err = simtestutil.SetupWithConfiguration( + appConfig, + simtestutil.DefaultStartUpConfig(), + &s2.AccountKeeper, &s2.BankKeeper, &s2.DistrKeeper, &s2.GovKeeper, &s2.StakingKeeper, &s2.cdc, &s2.appBuilder, + ) + require.NoError(t, err) + + s2.app.InitChain( + abci.RequestInitChain{ + Validators: []abci.ValidatorUpdate{}, + ConsensusParams: simtestutil.DefaultConsensusParams, + AppStateBytes: stateBytes, + }, + ) + + s2.app.Commit() + s2.app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: s2.app.LastBlockHeight() + 1}}) + + header = tmproto.Header{Height: s2.app.LastBlockHeight() + 1} + s2.app.BeginBlock(abci.RequestBeginBlock{Header: header}) + + ctx2 := s2.app.BaseApp.NewContext(false, tmproto.Header{}) + + // Jump the time forward past the DepositPeriod and VotingPeriod + ctx2 = ctx2.WithBlockTime(ctx2.BlockHeader().Time.Add(*s2.GovKeeper.GetParams(ctx2).MaxDepositPeriod).Add(*s2.GovKeeper.GetParams(ctx2).VotingPeriod)) + + // Make sure that they are still in the DepositPeriod and VotingPeriod respectively + proposal1, ok = s2.GovKeeper.GetProposal(ctx2, proposalID1) + require.True(t, ok) + proposal2, ok = s2.GovKeeper.GetProposal(ctx2, proposalID2) + require.True(t, ok) + require.True(t, proposal1.Status == v1.StatusDepositPeriod) + require.True(t, proposal2.Status == v1.StatusVotingPeriod) + + macc := s2.GovKeeper.GetGovernanceAccount(ctx2) + require.Equal(t, sdk.Coins(s2.GovKeeper.GetParams(ctx2).MinDeposit), s2.BankKeeper.GetAllBalances(ctx2, macc.GetAddress())) + + // Run the endblocker. Check to make sure that proposal1 is removed from state, and proposal2 is finished VotingPeriod. + gov.EndBlocker(ctx2, s2.GovKeeper) + + proposal1, ok = s2.GovKeeper.GetProposal(ctx2, proposalID1) + require.False(t, ok) + + proposal2, ok = s2.GovKeeper.GetProposal(ctx2, proposalID2) + require.True(t, ok) + require.True(t, proposal2.Status == v1.StatusRejected) +} diff --git a/x/gov/module_test.go b/tests/integration/gov/module_test.go similarity index 100% rename from x/gov/module_test.go rename to tests/integration/gov/module_test.go diff --git a/testutil/configurator/configurator.go b/testutil/configurator/configurator.go index 92a003de0760..4c0c950ba48e 100644 --- a/testutil/configurator/configurator.go +++ b/testutil/configurator/configurator.go @@ -9,6 +9,7 @@ import ( feegrantmodulev1 "cosmossdk.io/api/cosmos/feegrant/module/v1" genutilmodulev1 "cosmossdk.io/api/cosmos/genutil/module/v1" govmodulev1 "cosmossdk.io/api/cosmos/gov/module/v1" + mintmodulev1 "cosmossdk.io/api/cosmos/mint/module/v1" paramsmodulev1 "cosmossdk.io/api/cosmos/params/module/v1" slashingmodulev1 "cosmossdk.io/api/cosmos/slashing/module/v1" stakingmodulev1 "cosmossdk.io/api/cosmos/staking/module/v1" @@ -197,6 +198,21 @@ func GovModule() ModuleOption { } } +func MintModule() ModuleOption { + return func(config *appConfig) { + config.moduleConfigs["mint"] = &appv1alpha1.ModuleConfig{ + Name: "mint", + Config: appconfig.WrapAny(&mintmodulev1.Module{}), + GolangBindings: []*appv1alpha1.GolangBinding{ + { + InterfaceType: "github.com/cosmos/cosmos-sdk/x/mint/types/types.StakingKeeper", + Implementation: "github.com/cosmos/cosmos-sdk/x/staking/keeper/*keeper.Keeper", + }, + }, + } + } +} + func OmitInitGenesis() ModuleOption { return func(config *appConfig) { config.setInitGenesis = false diff --git a/testutil/sims/weights.go b/testutil/sims/weights.go index c85345ffb74e..18403f95c62d 100644 --- a/testutil/sims/weights.go +++ b/testutil/sims/weights.go @@ -8,9 +8,6 @@ const ( DefaultWeightMsgWithdrawDelegationReward int = 50 DefaultWeightMsgWithdrawValidatorCommission int = 50 DefaultWeightMsgFundCommunityPool int = 50 - DefaultWeightMsgDeposit int = 100 - DefaultWeightMsgVote int = 67 - DefaultWeightMsgVoteWeighted int = 33 DefaultWeightMsgUnjail int = 100 DefaultWeightMsgCreateValidator int = 100 DefaultWeightMsgEditValidator int = 5 diff --git a/x/auth/client/testutil/suite.go b/x/auth/client/testutil/suite.go index fa0918d39561..5e6e78d1580b 100644 --- a/x/auth/client/testutil/suite.go +++ b/x/auth/client/testutil/suite.go @@ -1566,10 +1566,7 @@ func (s *IntegrationTestSuite) TestSignWithMultiSignersAminoJSON() { require.Equal(sdk.NewCoins(val0Coin, val1Coin), queryRes.Balances) } -// TODO to re-enable in #12274 func (s *IntegrationTestSuite) TestAuxSigner() { - s.T().Skip() - require := s.Require() val := s.network.Validators[0] val0Coin := sdk.NewCoin(fmt.Sprintf("%stoken", val.Moniker), sdk.NewInt(10)) diff --git a/x/feegrant/client/testutil/suite.go b/x/feegrant/client/testutil/suite.go index 7411976dd15a..dd4e3c7c61e2 100644 --- a/x/feegrant/client/testutil/suite.go +++ b/x/feegrant/client/testutil/suite.go @@ -713,8 +713,6 @@ func (s *IntegrationTestSuite) TestNewCmdRevokeFeegrant() { } func (s *IntegrationTestSuite) TestTxWithFeeGrant() { - s.T().Skip() // TODO to re-enable in #12274 - val := s.network.Validators[0] clientCtx := val.ClientCtx granter := val.Address @@ -804,8 +802,6 @@ func (s *IntegrationTestSuite) TestTxWithFeeGrant() { } func (s *IntegrationTestSuite) TestFilteredFeeAllowance() { - s.T().Skip() // TODO to re-enable in #12274 - val := s.network.Validators[0] granter := val.Address diff --git a/x/gov/abci_test.go b/x/gov/abci_test.go index 248c82a94add..bf7432feed96 100644 --- a/x/gov/abci_test.go +++ b/x/gov/abci_test.go @@ -9,7 +9,7 @@ import ( abci "github.com/tendermint/tendermint/abci/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - "github.com/cosmos/cosmos-sdk/simapp" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/gov" "github.com/cosmos/cosmos-sdk/x/gov/keeper" @@ -21,16 +21,17 @@ import ( ) func TestTickExpiredDepositPeriod(t *testing.T) { - app := simapp.Setup(t, false) + suite := createTestSuite(t) + app := suite.App ctx := app.BaseApp.NewContext(false, tmproto.Header{}) - addrs := simapp.AddTestAddrs(app, ctx, 10, valTokens) + addrs := simtestutil.AddTestAddrs(suite.BankKeeper, suite.StakingKeeper, ctx, 10, valTokens) header := tmproto.Header{Height: app.LastBlockHeight() + 1} app.BeginBlock(abci.RequestBeginBlock{Header: header}) - govMsgSvr := keeper.NewMsgServerImpl(app.GovKeeper) + govMsgSvr := keeper.NewMsgServerImpl(suite.GovKeeper) - inactiveQueue := app.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) + inactiveQueue := suite.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) require.False(t, inactiveQueue.Valid()) inactiveQueue.Close() @@ -46,7 +47,7 @@ func TestTickExpiredDepositPeriod(t *testing.T) { require.NoError(t, err) require.NotNil(t, res) - inactiveQueue = app.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) + inactiveQueue = suite.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) require.False(t, inactiveQueue.Valid()) inactiveQueue.Close() @@ -54,36 +55,37 @@ func TestTickExpiredDepositPeriod(t *testing.T) { newHeader.Time = ctx.BlockHeader().Time.Add(time.Duration(1) * time.Second) ctx = ctx.WithBlockHeader(newHeader) - inactiveQueue = app.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) + inactiveQueue = suite.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) require.False(t, inactiveQueue.Valid()) inactiveQueue.Close() newHeader = ctx.BlockHeader() - newHeader.Time = ctx.BlockHeader().Time.Add(*app.GovKeeper.GetParams(ctx).MaxDepositPeriod) + newHeader.Time = ctx.BlockHeader().Time.Add(*suite.GovKeeper.GetParams(ctx).MaxDepositPeriod) ctx = ctx.WithBlockHeader(newHeader) - inactiveQueue = app.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) + inactiveQueue = suite.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) require.True(t, inactiveQueue.Valid()) inactiveQueue.Close() - gov.EndBlocker(ctx, app.GovKeeper) + gov.EndBlocker(ctx, suite.GovKeeper) - inactiveQueue = app.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) + inactiveQueue = suite.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) require.False(t, inactiveQueue.Valid()) inactiveQueue.Close() } func TestTickMultipleExpiredDepositPeriod(t *testing.T) { - app := simapp.Setup(t, false) + suite := createTestSuite(t) + app := suite.App ctx := app.BaseApp.NewContext(false, tmproto.Header{}) - addrs := simapp.AddTestAddrs(app, ctx, 10, valTokens) + addrs := simtestutil.AddTestAddrs(suite.BankKeeper, suite.StakingKeeper, ctx, 10, valTokens) header := tmproto.Header{Height: app.LastBlockHeight() + 1} app.BeginBlock(abci.RequestBeginBlock{Header: header}) - govMsgSvr := keeper.NewMsgServerImpl(app.GovKeeper) + govMsgSvr := keeper.NewMsgServerImpl(suite.GovKeeper) - inactiveQueue := app.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) + inactiveQueue := suite.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) require.False(t, inactiveQueue.Valid()) inactiveQueue.Close() @@ -99,7 +101,7 @@ func TestTickMultipleExpiredDepositPeriod(t *testing.T) { require.NoError(t, err) require.NotNil(t, res) - inactiveQueue = app.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) + inactiveQueue = suite.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) require.False(t, inactiveQueue.Valid()) inactiveQueue.Close() @@ -107,7 +109,7 @@ func TestTickMultipleExpiredDepositPeriod(t *testing.T) { newHeader.Time = ctx.BlockHeader().Time.Add(time.Duration(2) * time.Second) ctx = ctx.WithBlockHeader(newHeader) - inactiveQueue = app.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) + inactiveQueue = suite.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) require.False(t, inactiveQueue.Valid()) inactiveQueue.Close() @@ -124,16 +126,16 @@ func TestTickMultipleExpiredDepositPeriod(t *testing.T) { require.NotNil(t, res) newHeader = ctx.BlockHeader() - newHeader.Time = ctx.BlockHeader().Time.Add(*app.GovKeeper.GetParams(ctx).MaxDepositPeriod).Add(time.Duration(-1) * time.Second) + newHeader.Time = ctx.BlockHeader().Time.Add(*suite.GovKeeper.GetParams(ctx).MaxDepositPeriod).Add(time.Duration(-1) * time.Second) ctx = ctx.WithBlockHeader(newHeader) - inactiveQueue = app.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) + inactiveQueue = suite.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) require.True(t, inactiveQueue.Valid()) inactiveQueue.Close() - gov.EndBlocker(ctx, app.GovKeeper) + gov.EndBlocker(ctx, suite.GovKeeper) - inactiveQueue = app.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) + inactiveQueue = suite.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) require.False(t, inactiveQueue.Valid()) inactiveQueue.Close() @@ -141,31 +143,32 @@ func TestTickMultipleExpiredDepositPeriod(t *testing.T) { newHeader.Time = ctx.BlockHeader().Time.Add(time.Duration(5) * time.Second) ctx = ctx.WithBlockHeader(newHeader) - inactiveQueue = app.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) + inactiveQueue = suite.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) require.True(t, inactiveQueue.Valid()) inactiveQueue.Close() - gov.EndBlocker(ctx, app.GovKeeper) + gov.EndBlocker(ctx, suite.GovKeeper) - inactiveQueue = app.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) + inactiveQueue = suite.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) require.False(t, inactiveQueue.Valid()) inactiveQueue.Close() } func TestTickPassedDepositPeriod(t *testing.T) { - app := simapp.Setup(t, false) + suite := createTestSuite(t) + app := suite.App ctx := app.BaseApp.NewContext(false, tmproto.Header{}) - addrs := simapp.AddTestAddrs(app, ctx, 10, valTokens) + addrs := simtestutil.AddTestAddrs(suite.BankKeeper, suite.StakingKeeper, ctx, 10, valTokens) header := tmproto.Header{Height: app.LastBlockHeight() + 1} app.BeginBlock(abci.RequestBeginBlock{Header: header}) - govMsgSvr := keeper.NewMsgServerImpl(app.GovKeeper) + govMsgSvr := keeper.NewMsgServerImpl(suite.GovKeeper) - inactiveQueue := app.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) + inactiveQueue := suite.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) require.False(t, inactiveQueue.Valid()) inactiveQueue.Close() - activeQueue := app.GovKeeper.ActiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) + activeQueue := suite.GovKeeper.ActiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) require.False(t, activeQueue.Valid()) activeQueue.Close() @@ -183,7 +186,7 @@ func TestTickPassedDepositPeriod(t *testing.T) { proposalID := res.ProposalId - inactiveQueue = app.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) + inactiveQueue = suite.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) require.False(t, inactiveQueue.Valid()) inactiveQueue.Close() @@ -191,7 +194,7 @@ func TestTickPassedDepositPeriod(t *testing.T) { newHeader.Time = ctx.BlockHeader().Time.Add(time.Duration(1) * time.Second) ctx = ctx.WithBlockHeader(newHeader) - inactiveQueue = app.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) + inactiveQueue = suite.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) require.False(t, inactiveQueue.Valid()) inactiveQueue.Close() @@ -201,31 +204,32 @@ func TestTickPassedDepositPeriod(t *testing.T) { require.NoError(t, err) require.NotNil(t, res1) - activeQueue = app.GovKeeper.ActiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) + activeQueue = suite.GovKeeper.ActiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) require.False(t, activeQueue.Valid()) activeQueue.Close() } func TestTickPassedVotingPeriod(t *testing.T) { - app := simapp.Setup(t, false) + suite := createTestSuite(t) + app := suite.App ctx := app.BaseApp.NewContext(false, tmproto.Header{}) - addrs := simapp.AddTestAddrs(app, ctx, 10, valTokens) + addrs := simtestutil.AddTestAddrs(suite.BankKeeper, suite.StakingKeeper, ctx, 10, valTokens) SortAddresses(addrs) header := tmproto.Header{Height: app.LastBlockHeight() + 1} app.BeginBlock(abci.RequestBeginBlock{Header: header}) - govMsgSvr := keeper.NewMsgServerImpl(app.GovKeeper) + govMsgSvr := keeper.NewMsgServerImpl(suite.GovKeeper) - inactiveQueue := app.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) + inactiveQueue := suite.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) require.False(t, inactiveQueue.Valid()) inactiveQueue.Close() - activeQueue := app.GovKeeper.ActiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) + activeQueue := suite.GovKeeper.ActiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) require.False(t, activeQueue.Valid()) activeQueue.Close() - proposalCoins := sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, app.StakingKeeper.TokensFromConsensusPower(ctx, 5))} + proposalCoins := sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, suite.StakingKeeper.TokensFromConsensusPower(ctx, 5))} newProposalMsg, err := v1.NewMsgSubmitProposal([]sdk.Msg{mkTestLegacyContent(t)}, proposalCoins, addrs[0].String(), "") require.NoError(t, err) @@ -248,39 +252,40 @@ func TestTickPassedVotingPeriod(t *testing.T) { require.NotNil(t, res1) newHeader = ctx.BlockHeader() - newHeader.Time = ctx.BlockHeader().Time.Add(*app.GovKeeper.GetParams(ctx).MaxDepositPeriod).Add(*app.GovKeeper.GetParams(ctx).VotingPeriod) + newHeader.Time = ctx.BlockHeader().Time.Add(*suite.GovKeeper.GetParams(ctx).MaxDepositPeriod).Add(*suite.GovKeeper.GetParams(ctx).VotingPeriod) ctx = ctx.WithBlockHeader(newHeader) - inactiveQueue = app.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) + inactiveQueue = suite.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) require.False(t, inactiveQueue.Valid()) inactiveQueue.Close() - activeQueue = app.GovKeeper.ActiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) + activeQueue = suite.GovKeeper.ActiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) require.True(t, activeQueue.Valid()) activeProposalID := types.GetProposalIDFromBytes(activeQueue.Value()) - proposal, ok := app.GovKeeper.GetProposal(ctx, activeProposalID) + proposal, ok := suite.GovKeeper.GetProposal(ctx, activeProposalID) require.True(t, ok) require.Equal(t, v1.StatusVotingPeriod, proposal.Status) activeQueue.Close() - gov.EndBlocker(ctx, app.GovKeeper) + gov.EndBlocker(ctx, suite.GovKeeper) - activeQueue = app.GovKeeper.ActiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) + activeQueue = suite.GovKeeper.ActiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) require.False(t, activeQueue.Valid()) activeQueue.Close() } func TestProposalPassedEndblocker(t *testing.T) { - app := simapp.Setup(t, false) + suite := createTestSuite(t) + app := suite.App ctx := app.BaseApp.NewContext(false, tmproto.Header{}) - addrs := simapp.AddTestAddrs(app, ctx, 10, valTokens) + addrs := simtestutil.AddTestAddrs(suite.BankKeeper, suite.StakingKeeper, ctx, 10, valTokens) SortAddresses(addrs) - govMsgSvr := keeper.NewMsgServerImpl(app.GovKeeper) - stakingMsgSvr := stakingkeeper.NewMsgServerImpl(app.StakingKeeper) + govMsgSvr := keeper.NewMsgServerImpl(suite.GovKeeper) + stakingMsgSvr := stakingkeeper.NewMsgServerImpl(suite.StakingKeeper) header := tmproto.Header{Height: app.LastBlockHeight() + 1} app.BeginBlock(abci.RequestBeginBlock{Header: header}) @@ -288,78 +293,79 @@ func TestProposalPassedEndblocker(t *testing.T) { valAddr := sdk.ValAddress(addrs[0]) createValidators(t, stakingMsgSvr, ctx, []sdk.ValAddress{valAddr}, []int64{10}) - staking.EndBlocker(ctx, app.StakingKeeper) + staking.EndBlocker(ctx, suite.StakingKeeper) - macc := app.GovKeeper.GetGovernanceAccount(ctx) + macc := suite.GovKeeper.GetGovernanceAccount(ctx) require.NotNil(t, macc) - initialModuleAccCoins := app.BankKeeper.GetAllBalances(ctx, macc.GetAddress()) + initialModuleAccCoins := suite.BankKeeper.GetAllBalances(ctx, macc.GetAddress()) - proposal, err := app.GovKeeper.SubmitProposal(ctx, []sdk.Msg{mkTestLegacyContent(t)}, "") + proposal, err := suite.GovKeeper.SubmitProposal(ctx, []sdk.Msg{mkTestLegacyContent(t)}, "") require.NoError(t, err) - proposalCoins := sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, app.StakingKeeper.TokensFromConsensusPower(ctx, 10))} + proposalCoins := sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, suite.StakingKeeper.TokensFromConsensusPower(ctx, 10))} newDepositMsg := v1.NewMsgDeposit(addrs[0], proposal.Id, proposalCoins) res, err := govMsgSvr.Deposit(sdk.WrapSDKContext(ctx), newDepositMsg) require.NoError(t, err) require.NotNil(t, res) - macc = app.GovKeeper.GetGovernanceAccount(ctx) + macc = suite.GovKeeper.GetGovernanceAccount(ctx) require.NotNil(t, macc) - moduleAccCoins := app.BankKeeper.GetAllBalances(ctx, macc.GetAddress()) + moduleAccCoins := suite.BankKeeper.GetAllBalances(ctx, macc.GetAddress()) deposits := initialModuleAccCoins.Add(proposal.TotalDeposit...).Add(proposalCoins...) require.True(t, moduleAccCoins.IsEqual(deposits)) - err = app.GovKeeper.AddVote(ctx, proposal.Id, addrs[0], v1.NewNonSplitVoteOption(v1.OptionYes), "") + err = suite.GovKeeper.AddVote(ctx, proposal.Id, addrs[0], v1.NewNonSplitVoteOption(v1.OptionYes), "") require.NoError(t, err) newHeader := ctx.BlockHeader() - newHeader.Time = ctx.BlockHeader().Time.Add(*app.GovKeeper.GetParams(ctx).MaxDepositPeriod).Add(*app.GovKeeper.GetParams(ctx).VotingPeriod) + newHeader.Time = ctx.BlockHeader().Time.Add(*suite.GovKeeper.GetParams(ctx).MaxDepositPeriod).Add(*suite.GovKeeper.GetParams(ctx).VotingPeriod) ctx = ctx.WithBlockHeader(newHeader) - gov.EndBlocker(ctx, app.GovKeeper) + gov.EndBlocker(ctx, suite.GovKeeper) - macc = app.GovKeeper.GetGovernanceAccount(ctx) + macc = suite.GovKeeper.GetGovernanceAccount(ctx) require.NotNil(t, macc) - require.True(t, app.BankKeeper.GetAllBalances(ctx, macc.GetAddress()).IsEqual(initialModuleAccCoins)) + require.True(t, suite.BankKeeper.GetAllBalances(ctx, macc.GetAddress()).IsEqual(initialModuleAccCoins)) } func TestEndBlockerProposalHandlerFailed(t *testing.T) { - app := simapp.Setup(t, false) + suite := createTestSuite(t) + app := suite.App ctx := app.BaseApp.NewContext(false, tmproto.Header{}) - addrs := simapp.AddTestAddrs(app, ctx, 1, valTokens) + addrs := simtestutil.AddTestAddrs(suite.BankKeeper, suite.StakingKeeper, ctx, 1, valTokens) SortAddresses(addrs) - stakingMsgSvr := stakingkeeper.NewMsgServerImpl(app.StakingKeeper) + stakingMsgSvr := stakingkeeper.NewMsgServerImpl(suite.StakingKeeper) header := tmproto.Header{Height: app.LastBlockHeight() + 1} app.BeginBlock(abci.RequestBeginBlock{Header: header}) valAddr := sdk.ValAddress(addrs[0]) createValidators(t, stakingMsgSvr, ctx, []sdk.ValAddress{valAddr}, []int64{10}) - staking.EndBlocker(ctx, app.StakingKeeper) + staking.EndBlocker(ctx, suite.StakingKeeper) // Create a proposal where the handler will pass for the test proposal // because the value of contextKeyBadProposal is true. ctx = ctx.WithValue(contextKeyBadProposal, true) - proposal, err := app.GovKeeper.SubmitProposal(ctx, []sdk.Msg{mkTestLegacyContent(t)}, "") + proposal, err := suite.GovKeeper.SubmitProposal(ctx, []sdk.Msg{mkTestLegacyContent(t)}, "") require.NoError(t, err) - proposalCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, app.StakingKeeper.TokensFromConsensusPower(ctx, 10))) + proposalCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, suite.StakingKeeper.TokensFromConsensusPower(ctx, 10))) newDepositMsg := v1.NewMsgDeposit(addrs[0], proposal.Id, proposalCoins) - govMsgSvr := keeper.NewMsgServerImpl(app.GovKeeper) + govMsgSvr := keeper.NewMsgServerImpl(suite.GovKeeper) res, err := govMsgSvr.Deposit(sdk.WrapSDKContext(ctx), newDepositMsg) require.NoError(t, err) require.NotNil(t, res) - err = app.GovKeeper.AddVote(ctx, proposal.Id, addrs[0], v1.NewNonSplitVoteOption(v1.OptionYes), "") + err = suite.GovKeeper.AddVote(ctx, proposal.Id, addrs[0], v1.NewNonSplitVoteOption(v1.OptionYes), "") require.NoError(t, err) newHeader := ctx.BlockHeader() - newHeader.Time = ctx.BlockHeader().Time.Add(*app.GovKeeper.GetParams(ctx).MaxDepositPeriod).Add(*app.GovKeeper.GetParams(ctx).VotingPeriod) + newHeader.Time = ctx.BlockHeader().Time.Add(*suite.GovKeeper.GetParams(ctx).MaxDepositPeriod).Add(*suite.GovKeeper.GetParams(ctx).VotingPeriod) ctx = ctx.WithBlockHeader(newHeader) // Set the contextKeyBadProposal value to false so that the handler will fail @@ -367,7 +373,7 @@ func TestEndBlockerProposalHandlerFailed(t *testing.T) { ctx = ctx.WithValue(contextKeyBadProposal, false) // validate that the proposal fails/has been rejected - gov.EndBlocker(ctx, app.GovKeeper) + gov.EndBlocker(ctx, suite.GovKeeper) } func createValidators(t *testing.T, stakingMsgSvr stakingtypes.MsgServer, ctx sdk.Context, addrs []sdk.ValAddress, powerAmt []int64) { diff --git a/x/gov/common_test.go b/x/gov/common_test.go index 69e5e9075522..2c9212eaaa63 100644 --- a/x/gov/common_test.go +++ b/x/gov/common_test.go @@ -9,11 +9,22 @@ import ( "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + "github.com/cosmos/cosmos-sdk/runtime" + "github.com/cosmos/cosmos-sdk/testutil/configurator" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/cosmos-sdk/x/auth" + authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + _ "github.com/cosmos/cosmos-sdk/x/bank" + bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + "github.com/cosmos/cosmos-sdk/x/gov/keeper" "github.com/cosmos/cosmos-sdk/x/gov/types" v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + _ "github.com/cosmos/cosmos-sdk/x/params" + _ "github.com/cosmos/cosmos-sdk/x/staking" + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/stretchr/testify/require" ) @@ -86,3 +97,31 @@ var pubkeys = []cryptotypes.PubKey{ ed25519.GenPrivKey().PubKey(), ed25519.GenPrivKey().PubKey(), } + +type suite struct { + AccountKeeper authkeeper.AccountKeeper + BankKeeper bankkeeper.Keeper + GovKeeper *keeper.Keeper + StakingKeeper *stakingkeeper.Keeper + App *runtime.App +} + +func createTestSuite(t *testing.T) suite { + res := suite{} + + app, err := simtestutil.SetupWithConfiguration( + configurator.NewAppConfig( + configurator.ParamsModule(), + configurator.AuthModule(), + configurator.StakingModule(), + configurator.BankModule(), + configurator.GovModule(), + ), + simtestutil.DefaultStartUpConfig(), + &res.AccountKeeper, &res.BankKeeper, &res.GovKeeper, &res.StakingKeeper, + ) + require.NoError(t, err) + + res.App = app + return res +} diff --git a/x/gov/genesis_test.go b/x/gov/genesis_test.go index d7c0c6b677ec..c24995de7726 100644 --- a/x/gov/genesis_test.go +++ b/x/gov/genesis_test.go @@ -1,127 +1,22 @@ package gov_test import ( - "encoding/json" "testing" "github.com/stretchr/testify/require" - abci "github.com/tendermint/tendermint/abci/types" - "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - dbm "github.com/tendermint/tm-db" - "github.com/cosmos/cosmos-sdk/simapp" - simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" 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" - distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" "github.com/cosmos/cosmos-sdk/x/gov" - "github.com/cosmos/cosmos-sdk/x/gov/types" v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) -func TestImportExportQueues(t *testing.T) { - app := simapp.Setup(t, false) - ctx := app.BaseApp.NewContext(false, tmproto.Header{}) - addrs := simapp.AddTestAddrs(app, ctx, 2, valTokens) - - SortAddresses(addrs) - - header := tmproto.Header{Height: app.LastBlockHeight() + 1} - app.BeginBlock(abci.RequestBeginBlock{Header: header}) - - ctx = app.BaseApp.NewContext(false, tmproto.Header{}) - // Create two proposals, put the second into the voting period - proposal1, err := app.GovKeeper.SubmitProposal(ctx, []sdk.Msg{mkTestLegacyContent(t)}, "") - require.NoError(t, err) - proposalID1 := proposal1.Id - - proposal2, err := app.GovKeeper.SubmitProposal(ctx, []sdk.Msg{mkTestLegacyContent(t)}, "") - require.NoError(t, err) - proposalID2 := proposal2.Id - - votingStarted, err := app.GovKeeper.AddDeposit(ctx, proposalID2, addrs[0], app.GovKeeper.GetParams(ctx).MinDeposit) - require.NoError(t, err) - require.True(t, votingStarted) - - proposal1, ok := app.GovKeeper.GetProposal(ctx, proposalID1) - require.True(t, ok) - proposal2, ok = app.GovKeeper.GetProposal(ctx, proposalID2) - require.True(t, ok) - require.True(t, proposal1.Status == v1.StatusDepositPeriod) - require.True(t, proposal2.Status == v1.StatusVotingPeriod) - - authGenState := app.AccountKeeper.ExportGenesis(ctx) - bankGenState := app.BankKeeper.ExportGenesis(ctx) - stakingGenState := app.StakingKeeper.ExportGenesis(ctx) - distributionGenState := app.DistrKeeper.ExportGenesis(ctx) - - // export the state and import it into a new app - govGenState := gov.ExportGenesis(ctx, app.GovKeeper) - genesisState := simapp.NewDefaultGenesisState(app.AppCodec()) - - genesisState[authtypes.ModuleName] = app.AppCodec().MustMarshalJSON(authGenState) - genesisState[banktypes.ModuleName] = app.AppCodec().MustMarshalJSON(bankGenState) - genesisState[types.ModuleName] = app.AppCodec().MustMarshalJSON(govGenState) - genesisState[stakingtypes.ModuleName] = app.AppCodec().MustMarshalJSON(stakingGenState) - genesisState[distributiontypes.ModuleName] = app.AppCodec().MustMarshalJSON(distributionGenState) - - stateBytes, err := json.MarshalIndent(genesisState, "", " ") - if err != nil { - panic(err) - } - - db := dbm.NewMemDB() - app2 := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, simtestutil.NewAppOptionsWithFlagHome(simapp.DefaultNodeHome)) - - app2.InitChain( - abci.RequestInitChain{ - Validators: []abci.ValidatorUpdate{}, - ConsensusParams: simtestutil.DefaultConsensusParams, - AppStateBytes: stateBytes, - }, - ) - - app2.Commit() - app2.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: app2.LastBlockHeight() + 1}}) - - header = tmproto.Header{Height: app2.LastBlockHeight() + 1} - app2.BeginBlock(abci.RequestBeginBlock{Header: header}) - - ctx2 := app2.BaseApp.NewContext(false, tmproto.Header{}) - - // Jump the time forward past the DepositPeriod and VotingPeriod - ctx2 = ctx2.WithBlockTime(ctx2.BlockHeader().Time.Add(*app2.GovKeeper.GetParams(ctx2).MaxDepositPeriod).Add(*app2.GovKeeper.GetParams(ctx2).VotingPeriod)) - - // Make sure that they are still in the DepositPeriod and VotingPeriod respectively - proposal1, ok = app2.GovKeeper.GetProposal(ctx2, proposalID1) - require.True(t, ok) - proposal2, ok = app2.GovKeeper.GetProposal(ctx2, proposalID2) - require.True(t, ok) - require.True(t, proposal1.Status == v1.StatusDepositPeriod) - require.True(t, proposal2.Status == v1.StatusVotingPeriod) - - macc := app2.GovKeeper.GetGovernanceAccount(ctx2) - require.Equal(t, sdk.Coins(app2.GovKeeper.GetParams(ctx2).MinDeposit), app2.BankKeeper.GetAllBalances(ctx2, macc.GetAddress())) - - // Run the endblocker. Check to make sure that proposal1 is removed from state, and proposal2 is finished VotingPeriod. - gov.EndBlocker(ctx2, app2.GovKeeper) - - proposal1, ok = app2.GovKeeper.GetProposal(ctx2, proposalID1) - require.False(t, ok) - - proposal2, ok = app2.GovKeeper.GetProposal(ctx2, proposalID2) - require.True(t, ok) - require.True(t, proposal2.Status == v1.StatusRejected) -} - func TestImportExportQueues_ErrorUnconsistentState(t *testing.T) { - app := simapp.Setup(t, false) + suite := createTestSuite(t) + app := suite.App ctx := app.BaseApp.NewContext(false, tmproto.Header{}) require.Panics(t, func() { - gov.InitGenesis(ctx, app.AccountKeeper, app.BankKeeper, app.GovKeeper, &v1.GenesisState{ + gov.InitGenesis(ctx, suite.AccountKeeper, suite.BankKeeper, suite.GovKeeper, &v1.GenesisState{ Deposits: v1.Deposits{ { ProposalId: 1234, diff --git a/x/gov/simulation/operations.go b/x/gov/simulation/operations.go index bdd53e433f2f..9b101267ed57 100644 --- a/x/gov/simulation/operations.go +++ b/x/gov/simulation/operations.go @@ -7,9 +7,9 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" - simappparams "github.com/cosmos/cosmos-sdk/simapp/params" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/gov/keeper" "github.com/cosmos/cosmos-sdk/x/gov/types" @@ -34,6 +34,10 @@ const ( OpWeightMsgDeposit = "op_weight_msg_deposit" OpWeightMsgVote = "op_weight_msg_vote" OpWeightMsgVoteWeighted = "op_weight_msg_weighted_vote" + + DefaultWeightMsgDeposit = 100 + DefaultWeightMsgVote = 67 + DefaultWeightMsgVoteWeighted = 33 ) // WeightedOperations returns all the operations from the module with their respective weights @@ -46,19 +50,19 @@ func WeightedOperations(appParams simtypes.AppParams, cdc codec.JSONCodec, ak ty appParams.GetOrGenerate(cdc, OpWeightMsgDeposit, &weightMsgDeposit, nil, func(_ *rand.Rand) { - weightMsgDeposit = simappparams.DefaultWeightMsgDeposit + weightMsgDeposit = DefaultWeightMsgDeposit }, ) appParams.GetOrGenerate(cdc, OpWeightMsgVote, &weightMsgVote, nil, func(_ *rand.Rand) { - weightMsgVote = simappparams.DefaultWeightMsgVote + weightMsgVote = DefaultWeightMsgVote }, ) appParams.GetOrGenerate(cdc, OpWeightMsgVoteWeighted, &weightMsgVoteWeighted, nil, func(_ *rand.Rand) { - weightMsgVoteWeighted = simappparams.DefaultWeightMsgVoteWeighted + weightMsgVoteWeighted = DefaultWeightMsgVoteWeighted }, ) @@ -165,7 +169,7 @@ func SimulateMsgSubmitProposal(ak types.AccountKeeper, bk types.BankKeeper, k *k } } - txGen := simappparams.MakeTestEncodingConfig().TxConfig + txGen := moduletestutil.MakeTestEncodingConfig().TxConfig tx, err := simtestutil.GenSignedMockTx( r, txGen, @@ -256,7 +260,7 @@ func SimulateMsgDeposit(ak types.AccountKeeper, bk types.BankKeeper, k *keeper.K txCtx := simulation.OperationInput{ R: r, App: app, - TxGen: simappparams.MakeTestEncodingConfig().TxConfig, + TxGen: moduletestutil.MakeTestEncodingConfig().TxConfig, Cdc: nil, Msg: msg, MsgType: msg.Type(), @@ -306,7 +310,7 @@ func operationSimulateMsgVote(ak types.AccountKeeper, bk types.BankKeeper, k *ke txCtx := simulation.OperationInput{ R: r, App: app, - TxGen: simappparams.MakeTestEncodingConfig().TxConfig, + TxGen: moduletestutil.MakeTestEncodingConfig().TxConfig, Cdc: nil, Msg: msg, MsgType: msg.Type(), @@ -358,7 +362,7 @@ func operationSimulateMsgVoteWeighted(ak types.AccountKeeper, bk types.BankKeepe txCtx := simulation.OperationInput{ R: r, App: app, - TxGen: simappparams.MakeTestEncodingConfig().TxConfig, + TxGen: moduletestutil.MakeTestEncodingConfig().TxConfig, Cdc: nil, Msg: msg, MsgType: msg.Type(), diff --git a/x/gov/simulation/operations_test.go b/x/gov/simulation/operations_test.go index 4f1a6e331f11..267934307206 100644 --- a/x/gov/simulation/operations_test.go +++ b/x/gov/simulation/operations_test.go @@ -10,16 +10,26 @@ import ( abci "github.com/tendermint/tendermint/abci/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - "github.com/cosmos/cosmos-sdk/simapp" - simappparams "github.com/cosmos/cosmos-sdk/simapp/params" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/runtime" + "github.com/cosmos/cosmos-sdk/testutil/configurator" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + _ "github.com/cosmos/cosmos-sdk/x/auth" + authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + _ "github.com/cosmos/cosmos-sdk/x/auth/tx/module" + _ "github.com/cosmos/cosmos-sdk/x/bank" + bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" "github.com/cosmos/cosmos-sdk/x/bank/testutil" + "github.com/cosmos/cosmos-sdk/x/gov/keeper" "github.com/cosmos/cosmos-sdk/x/gov/simulation" "github.com/cosmos/cosmos-sdk/x/gov/types" v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" + _ "github.com/cosmos/cosmos-sdk/x/params" + _ "github.com/cosmos/cosmos-sdk/x/staking" + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" ) type MockWeightedProposalContent struct { @@ -56,20 +66,21 @@ func mockWeightedProposalContent(n int) []simtypes.WeightedProposalContent { // TestWeightedOperations tests the weights of the operations. func TestWeightedOperations(t *testing.T) { - app, ctx := createTestApp(t, false) + suite, ctx := createTestSuite(t, false) + app := suite.App ctx.WithChainID("test-chain") - cdc := app.AppCodec() + cdc := suite.cdc appParams := make(simtypes.AppParams) - weightesOps := simulation.WeightedOperations(appParams, cdc, app.AccountKeeper, - app.BankKeeper, app.GovKeeper, mockWeightedProposalContent(3), + weightesOps := simulation.WeightedOperations(appParams, cdc, suite.AccountKeeper, + suite.BankKeeper, suite.GovKeeper, mockWeightedProposalContent(3), ) // setup 3 accounts s := rand.NewSource(1) r := rand.New(s) - accs := getTestingAccounts(t, r, app, ctx, 3) + accs := getTestingAccounts(t, r, suite.AccountKeeper, suite.BankKeeper, suite.StakingKeeper, ctx, 3) expected := []struct { weight int @@ -79,9 +90,9 @@ func TestWeightedOperations(t *testing.T) { {0, types.ModuleName, simulation.TypeMsgSubmitProposal}, {1, types.ModuleName, simulation.TypeMsgSubmitProposal}, {2, types.ModuleName, simulation.TypeMsgSubmitProposal}, - {simappparams.DefaultWeightMsgDeposit, types.ModuleName, simulation.TypeMsgDeposit}, - {simappparams.DefaultWeightMsgVote, types.ModuleName, simulation.TypeMsgVote}, - {simappparams.DefaultWeightMsgVoteWeighted, types.ModuleName, simulation.TypeMsgVoteWeighted}, + {simulation.DefaultWeightMsgDeposit, types.ModuleName, simulation.TypeMsgDeposit}, + {simulation.DefaultWeightMsgVote, types.ModuleName, simulation.TypeMsgVote}, + {simulation.DefaultWeightMsgVoteWeighted, types.ModuleName, simulation.TypeMsgVoteWeighted}, } for i, w := range weightesOps { @@ -100,18 +111,19 @@ func TestWeightedOperations(t *testing.T) { // TestSimulateMsgSubmitProposal tests the normal scenario of a valid message of type TypeMsgSubmitProposal. // Abnormal scenarios, where errors occur, are not tested here. func TestSimulateMsgSubmitProposal(t *testing.T) { - app, ctx := createTestApp(t, false) + suite, ctx := createTestSuite(t, false) + app := suite.App // setup 3 accounts s := rand.NewSource(1) r := rand.New(s) - accounts := getTestingAccounts(t, r, app, ctx, 3) + accounts := getTestingAccounts(t, r, suite.AccountKeeper, suite.BankKeeper, suite.StakingKeeper, ctx, 3) // begin a new block app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: app.LastBlockHeight() + 1, AppHash: app.LastCommitID().Hash}}) // execute operation - op := simulation.SimulateMsgSubmitProposal(app.AccountKeeper, app.BankKeeper, app.GovKeeper, MockWeightedProposalContent{3}.ContentSimulatorFn()) + op := simulation.SimulateMsgSubmitProposal(suite.AccountKeeper, suite.BankKeeper, suite.GovKeeper, MockWeightedProposalContent{3}.ContentSimulatorFn()) operationMsg, _, err := op(r, app.BaseApp, ctx, accounts, "") require.NoError(t, err) @@ -132,33 +144,34 @@ func TestSimulateMsgSubmitProposal(t *testing.T) { // TestSimulateMsgDeposit tests the normal scenario of a valid message of type TypeMsgDeposit. // Abnormal scenarios, where errors occur, are not tested here. func TestSimulateMsgDeposit(t *testing.T) { - app, ctx := createTestApp(t, false) + suite, ctx := createTestSuite(t, false) + app := suite.App blockTime := time.Now().UTC() ctx = ctx.WithBlockTime(blockTime) // setup 3 accounts s := rand.NewSource(1) r := rand.New(s) - accounts := getTestingAccounts(t, r, app, ctx, 3) + accounts := getTestingAccounts(t, r, suite.AccountKeeper, suite.BankKeeper, suite.StakingKeeper, ctx, 3) // setup a proposal content := v1beta1.NewTextProposal("Test", "description") - contentMsg, err := v1.NewLegacyContent(content, app.GovKeeper.GetGovernanceAccount(ctx).GetAddress().String()) + contentMsg, err := v1.NewLegacyContent(content, suite.GovKeeper.GetGovernanceAccount(ctx).GetAddress().String()) require.NoError(t, err) submitTime := ctx.BlockHeader().Time - depositPeriod := app.GovKeeper.GetParams(ctx).MaxDepositPeriod + depositPeriod := suite.GovKeeper.GetParams(ctx).MaxDepositPeriod proposal, err := v1.NewProposal([]sdk.Msg{contentMsg}, 1, "", submitTime, submitTime.Add(*depositPeriod)) require.NoError(t, err) - app.GovKeeper.SetProposal(ctx, proposal) + suite.GovKeeper.SetProposal(ctx, proposal) // begin a new block app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: app.LastBlockHeight() + 1, AppHash: app.LastCommitID().Hash, Time: blockTime}}) // execute operation - op := simulation.SimulateMsgDeposit(app.AccountKeeper, app.BankKeeper, app.GovKeeper) + op := simulation.SimulateMsgDeposit(suite.AccountKeeper, suite.BankKeeper, suite.GovKeeper) operationMsg, _, err := op(r, app.BaseApp, ctx, accounts, "") require.NoError(t, err) @@ -178,33 +191,34 @@ func TestSimulateMsgDeposit(t *testing.T) { // TestSimulateMsgVote tests the normal scenario of a valid message of type TypeMsgVote. // Abnormal scenarios, where errors occur, are not tested here. func TestSimulateMsgVote(t *testing.T) { - app, ctx := createTestApp(t, false) + suite, ctx := createTestSuite(t, false) + app := suite.App blockTime := time.Now().UTC() ctx = ctx.WithBlockTime(blockTime) // setup 3 accounts s := rand.NewSource(1) r := rand.New(s) - accounts := getTestingAccounts(t, r, app, ctx, 3) + accounts := getTestingAccounts(t, r, suite.AccountKeeper, suite.BankKeeper, suite.StakingKeeper, ctx, 3) // setup a proposal - govAcc := app.GovKeeper.GetGovernanceAccount(ctx).GetAddress().String() + govAcc := suite.GovKeeper.GetGovernanceAccount(ctx).GetAddress().String() contentMsg, err := v1.NewLegacyContent(v1beta1.NewTextProposal("Test", "description"), govAcc) require.NoError(t, err) submitTime := ctx.BlockHeader().Time - depositPeriod := app.GovKeeper.GetParams(ctx).MaxDepositPeriod + depositPeriod := suite.GovKeeper.GetParams(ctx).MaxDepositPeriod proposal, err := v1.NewProposal([]sdk.Msg{contentMsg}, 1, "", submitTime, submitTime.Add(*depositPeriod)) require.NoError(t, err) - app.GovKeeper.ActivateVotingPeriod(ctx, proposal) + suite.GovKeeper.ActivateVotingPeriod(ctx, proposal) // begin a new block app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: app.LastBlockHeight() + 1, AppHash: app.LastCommitID().Hash, Time: blockTime}}) // execute operation - op := simulation.SimulateMsgVote(app.AccountKeeper, app.BankKeeper, app.GovKeeper) + op := simulation.SimulateMsgVote(suite.AccountKeeper, suite.BankKeeper, suite.GovKeeper) operationMsg, _, err := op(r, app.BaseApp, ctx, accounts, "") require.NoError(t, err) @@ -222,32 +236,33 @@ func TestSimulateMsgVote(t *testing.T) { // TestSimulateMsgVoteWeighted tests the normal scenario of a valid message of type TypeMsgVoteWeighted. // Abnormal scenarios, where errors occur, are not tested here. func TestSimulateMsgVoteWeighted(t *testing.T) { - app, ctx := createTestApp(t, false) + suite, ctx := createTestSuite(t, false) + app := suite.App blockTime := time.Now().UTC() ctx = ctx.WithBlockTime(blockTime) // setup 3 accounts s := rand.NewSource(1) r := rand.New(s) - accounts := getTestingAccounts(t, r, app, ctx, 3) + accounts := getTestingAccounts(t, r, suite.AccountKeeper, suite.BankKeeper, suite.StakingKeeper, ctx, 3) // setup a proposal - govAcc := app.GovKeeper.GetGovernanceAccount(ctx).GetAddress().String() + govAcc := suite.GovKeeper.GetGovernanceAccount(ctx).GetAddress().String() contentMsg, err := v1.NewLegacyContent(v1beta1.NewTextProposal("Test", "description"), govAcc) require.NoError(t, err) submitTime := ctx.BlockHeader().Time - depositPeriod := app.GovKeeper.GetParams(ctx).MaxDepositPeriod + depositPeriod := suite.GovKeeper.GetParams(ctx).MaxDepositPeriod proposal, err := v1.NewProposal([]sdk.Msg{contentMsg}, 1, "", submitTime, submitTime.Add(*depositPeriod)) require.NoError(t, err) - app.GovKeeper.ActivateVotingPeriod(ctx, proposal) + suite.GovKeeper.ActivateVotingPeriod(ctx, proposal) // begin a new block app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: app.LastBlockHeight() + 1, AppHash: app.LastCommitID().Hash, Time: blockTime}}) // execute operation - op := simulation.SimulateMsgVoteWeighted(app.AccountKeeper, app.BankKeeper, app.GovKeeper) + op := simulation.SimulateMsgVoteWeighted(suite.AccountKeeper, suite.BankKeeper, suite.GovKeeper) operationMsg, _, err := op(r, app.BaseApp, ctx, accounts, "") require.NoError(t, err) @@ -262,28 +277,50 @@ func TestSimulateMsgVoteWeighted(t *testing.T) { require.Equal(t, simulation.TypeMsgVoteWeighted, msg.Type()) } +type suite struct { + cdc codec.Codec + AccountKeeper authkeeper.AccountKeeper + BankKeeper bankkeeper.Keeper + GovKeeper *keeper.Keeper + StakingKeeper *stakingkeeper.Keeper + App *runtime.App +} + // returns context and an app with updated mint keeper -func createTestApp(t *testing.T, isCheckTx bool) (*simapp.SimApp, sdk.Context) { - app := simapp.Setup(t, isCheckTx) +func createTestSuite(t *testing.T, isCheckTx bool) (suite, sdk.Context) { + res := suite{} + + app, err := simtestutil.Setup(configurator.NewAppConfig( + configurator.AuthModule(), + configurator.TxModule(), + configurator.ParamsModule(), + configurator.BankModule(), + configurator.StakingModule(), + configurator.GovModule(), + ), &res.AccountKeeper, &res.BankKeeper, &res.GovKeeper, &res.StakingKeeper, &res.cdc) + require.NoError(t, err) ctx := app.BaseApp.NewContext(isCheckTx, tmproto.Header{}) - app.MintKeeper.SetParams(ctx, minttypes.DefaultParams()) - app.MintKeeper.SetMinter(ctx, minttypes.DefaultInitialMinter()) - return app, ctx + res.App = app + return res, ctx } -func getTestingAccounts(t *testing.T, r *rand.Rand, app *simapp.SimApp, ctx sdk.Context, n int) []simtypes.Account { +func getTestingAccounts( + t *testing.T, r *rand.Rand, + accountKeeper authkeeper.AccountKeeper, bankKeeper bankkeeper.Keeper, stakingKeeper *stakingkeeper.Keeper, + ctx sdk.Context, n int, +) []simtypes.Account { accounts := simtypes.RandomAccounts(r, n) - initAmt := app.StakingKeeper.TokensFromConsensusPower(ctx, 200) + initAmt := stakingKeeper.TokensFromConsensusPower(ctx, 200) initCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initAmt)) // add coins to the accounts for _, account := range accounts { - acc := app.AccountKeeper.NewAccountWithAddress(ctx, account.Address) - app.AccountKeeper.SetAccount(ctx, acc) - require.NoError(t, testutil.FundAccount(app.BankKeeper, ctx, account.Address, initCoins)) + acc := accountKeeper.NewAccountWithAddress(ctx, account.Address) + accountKeeper.SetAccount(ctx, acc) + require.NoError(t, testutil.FundAccount(bankKeeper, ctx, account.Address, initCoins)) } return accounts From 48017b75a0e6b05454fb6b47de200ae31e27be74 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Aug 2022 18:37:43 +0200 Subject: [PATCH 4/6] build(deps): Bump github.com/rs/zerolog from 1.27.0 to 1.28.0 (#13075) --- go.mod | 2 +- go.sum | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index eaf0d63f8953..2470cd9d4867 100644 --- a/go.mod +++ b/go.mod @@ -45,7 +45,7 @@ require ( github.com/prometheus/common v0.37.0 github.com/rakyll/statik v0.1.7 github.com/regen-network/cosmos-proto v0.3.1 - github.com/rs/zerolog v1.27.0 + github.com/rs/zerolog v1.28.0 github.com/spf13/cast v1.5.0 github.com/spf13/cobra v1.5.0 github.com/spf13/pflag v1.0.5 diff --git a/go.sum b/go.sum index ebb6a1dae2ad..5b302c078fa3 100644 --- a/go.sum +++ b/go.sum @@ -932,9 +932,9 @@ github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XF github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/rs/cors v1.8.2 h1:KCooALfAYGs415Cwu5ABvv9n9509fSiG5SQJn/AQo4U= github.com/rs/cors v1.8.2/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= -github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= -github.com/rs/zerolog v1.27.0 h1:1T7qCieN22GVc8S4Q2yuexzBb1EqjbgjSH9RohbMjKs= -github.com/rs/zerolog v1.27.0/go.mod h1:7frBqO0oezxmnO7GF86FY++uy8I0Tk/If5ni1G9Qc0U= +github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= +github.com/rs/zerolog v1.28.0 h1:MirSo27VyNi7RJYP3078AA1+Cyzd2GB66qy3aUHvsWY= +github.com/rs/zerolog v1.28.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= From 338ef7bb3c506342c5f34d5e8dfb4406d2ce6ce8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Aug 2022 17:00:29 +0000 Subject: [PATCH 5/6] build(deps): Bump pgregory.net/rapid from 0.4.8 to 0.5.1 in /orm (#13080) --- orm/go.mod | 2 +- orm/go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/orm/go.mod b/orm/go.mod index 0aefbe955575..865c2f97e99d 100644 --- a/orm/go.mod +++ b/orm/go.mod @@ -15,7 +15,7 @@ require ( google.golang.org/grpc v1.49.0 google.golang.org/protobuf v1.28.1 gotest.tools/v3 v3.3.0 - pgregory.net/rapid v0.4.8 + pgregory.net/rapid v0.5.1 ) require ( diff --git a/orm/go.sum b/orm/go.sum index 7b2e2dc4fd57..5c41e186dc96 100644 --- a/orm/go.sum +++ b/orm/go.sum @@ -257,5 +257,5 @@ gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools/v3 v3.3.0 h1:MfDY1b1/0xN1CyMlQDac0ziEy9zJQd9CXBRRDHw2jJo= gotest.tools/v3 v3.3.0/go.mod h1:Mcr9QNxkg0uMvy/YElmo4SpXgJKWgQvYrT7Kw5RzJ1A= pgregory.net/rapid v0.4.7/go.mod h1:UYpPVyjFHzYBGHIxLFoupi8vwk6rXNzRY9OMvVxFIOU= -pgregory.net/rapid v0.4.8 h1:d+5SGZWUbJPbl3ss6tmPFqnNeQR6VDOFly+eTjwPiEw= -pgregory.net/rapid v0.4.8/go.mod h1:Z5PbWqjvWR1I3UGjvboUuan4fe4ZYEYNLNQLExzCoUs= +pgregory.net/rapid v0.5.1 h1:U7LVKOJavGH81G5buGiyztKCmpQLfepzitHEKDLQ8ug= +pgregory.net/rapid v0.5.1/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04= From 8436dc17415df20a9adaa9634c6bd63ff31dcb50 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Aug 2022 17:08:43 +0000 Subject: [PATCH 6/6] build(deps): Bump github.com/rs/zerolog in /cosmovisor (#13081) --- cosmovisor/go.mod | 2 +- cosmovisor/go.sum | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cosmovisor/go.mod b/cosmovisor/go.mod index 3a521bc46eb6..5ac625e845f2 100644 --- a/cosmovisor/go.mod +++ b/cosmovisor/go.mod @@ -6,7 +6,7 @@ require ( github.com/cosmos/cosmos-sdk v0.46.1 github.com/hashicorp/go-getter v1.6.2 github.com/otiai10/copy v1.7.0 - github.com/rs/zerolog v1.27.0 + github.com/rs/zerolog v1.28.0 github.com/spf13/cobra v1.5.0 github.com/stretchr/testify v1.8.0 ) diff --git a/cosmovisor/go.sum b/cosmovisor/go.sum index e922f9de6cae..0b5e39a728c4 100644 --- a/cosmovisor/go.sum +++ b/cosmovisor/go.sum @@ -524,9 +524,9 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg= github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o= github.com/rs/cors v1.8.2 h1:KCooALfAYGs415Cwu5ABvv9n9509fSiG5SQJn/AQo4U= -github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= -github.com/rs/zerolog v1.27.0 h1:1T7qCieN22GVc8S4Q2yuexzBb1EqjbgjSH9RohbMjKs= -github.com/rs/zerolog v1.27.0/go.mod h1:7frBqO0oezxmnO7GF86FY++uy8I0Tk/If5ni1G9Qc0U= +github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= +github.com/rs/zerolog v1.28.0 h1:MirSo27VyNi7RJYP3078AA1+Cyzd2GB66qy3aUHvsWY= +github.com/rs/zerolog v1.28.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sasha-s/go-deadlock v0.2.1-0.20190427202633-1595213edefa h1:0U2s5loxrTy6/VgfVoLuVLFJcURKLH49ie0zSch7gh4=