From fc7ee0bf1e4e6afef4aed98515d418281edb7e62 Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaurym@users.noreply.github.com> Date: Thu, 25 Aug 2022 22:15:44 +0200 Subject: [PATCH] test(gov): Refactor x/gov keeper tests to use mocks (#12988) ## Description ref: #12752 - [x] Move some keeper tests into `tests/integration/gov/keeper`, see https://github.com/cosmos/cosmos-sdk/pull/12988#discussion_r954956199 - [x] Don't use simapp in `x/gov/keeper` tests, use mocks instead - [x] Find 0 "simapp" occurence in x/gov/keeper. (Note: other occurrences of simapp are removed in #13043) --- ### 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) --- scripts/mockgen.sh | 3 +- tests/integration/gov/keeper/common_test.go | 79 ++ .../integration/gov/keeper/grpc_query_test.go | 245 ++++ tests/integration/gov/keeper/keeper_test.go | 68 ++ .../integration}/gov/keeper/tally_test.go | 0 testutil/sims/address_helpers.go | 16 +- x/gov/keeper/common_test.go | 121 +- x/gov/keeper/deposit_test.go | 79 +- x/gov/keeper/grpc_query_test.go | 365 ++---- x/gov/keeper/hooks_test.go | 29 +- x/gov/keeper/keeper_test.go | 71 +- x/gov/keeper/msg_server_test.go | 57 +- x/gov/keeper/proposal_test.go | 26 +- x/gov/keeper/vote_test.go | 35 +- x/gov/testutil/expected_keepers.go | 35 + x/gov/testutil/expected_keepers_mocks.go | 1003 +++++++++++++++++ 16 files changed, 1738 insertions(+), 494 deletions(-) create mode 100644 tests/integration/gov/keeper/common_test.go create mode 100644 tests/integration/gov/keeper/grpc_query_test.go create mode 100644 tests/integration/gov/keeper/keeper_test.go rename {x => tests/integration}/gov/keeper/tally_test.go (100%) create mode 100644 x/gov/testutil/expected_keepers.go create mode 100644 x/gov/testutil/expected_keepers_mocks.go diff --git a/scripts/mockgen.sh b/scripts/mockgen.sh index ed1aced410ca..447f039f751d 100755 --- a/scripts/mockgen.sh +++ b/scripts/mockgen.sh @@ -22,4 +22,5 @@ $mockgen_cmd -source=x/bank/types/expected_keepers.go -package testutil -destina $mockgen_cmd -source=x/group/testutil/expected_keepers.go -package testutil -destination x/group/testutil/expected_keepers_mocks.go $mockgen_cmd -source=x/evidence/types/expected_keepers.go -package testutil -destination x/evidence/testutil/expected_keepers_mocks.go $mockgen_cmd -source=x/slashing/types/expected_keepers.go -package testutil -destination x/slashing/testutil/expected_keepers_mocks.go -$mockgen_cmd -source=x/genutil/types/expected_keepers.go -package testutil -destination x/genutil/testutil/expected_keepers_mocks.go \ No newline at end of file +$mockgen_cmd -source=x/genutil/types/expected_keepers.go -package testutil -destination x/genutil/testutil/expected_keepers_mocks.go +$mockgen_cmd -source=x/gov/testutil/expected_keepers.go -package testutil -destination x/gov/testutil/expected_keepers_mocks.go diff --git a/tests/integration/gov/keeper/common_test.go b/tests/integration/gov/keeper/common_test.go new file mode 100644 index 000000000000..f29fa800ba44 --- /dev/null +++ b/tests/integration/gov/keeper/common_test.go @@ -0,0 +1,79 @@ +package keeper_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/cosmos/cosmos-sdk/simapp" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" + "github.com/cosmos/cosmos-sdk/testutil/testdata" + sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/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" + "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" +) + +var ( + _, _, addr = testdata.KeyTestPubAddr() + govAcct = authtypes.NewModuleAddress(types.ModuleName) + TestProposal = getTestProposal() +) + +func getTestProposal() []sdk.Msg { + legacyProposalMsg, err := v1.NewLegacyContent(v1beta1.NewTextProposal("Title", "description"), authtypes.NewModuleAddress(types.ModuleName).String()) + if err != nil { + panic(err) + } + + return []sdk.Msg{ + banktypes.NewMsgSend(govAcct, addr, sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(1000)))), + legacyProposalMsg, + } +} + +func createValidators(t *testing.T, ctx sdk.Context, app *simapp.SimApp, powers []int64) ([]sdk.AccAddress, []sdk.ValAddress) { + addrs := simapp.AddTestAddrsIncremental(app, ctx, 5, sdk.NewInt(30000000)) + valAddrs := simtestutil.ConvertAddrsToValAddrs(addrs) + pks := simtestutil.CreateTestPubKeys(5) + cdc := moduletestutil.MakeTestEncodingConfig().Codec + + app.StakingKeeper = stakingkeeper.NewKeeper( + cdc, + app.GetKey(stakingtypes.StoreKey), + app.AccountKeeper, + app.BankKeeper, + authtypes.NewModuleAddress(types.ModuleName).String(), + ) + + val1, err := stakingtypes.NewValidator(valAddrs[0], pks[0], stakingtypes.Description{}) + require.NoError(t, err) + val2, err := stakingtypes.NewValidator(valAddrs[1], pks[1], stakingtypes.Description{}) + require.NoError(t, err) + val3, err := stakingtypes.NewValidator(valAddrs[2], pks[2], stakingtypes.Description{}) + require.NoError(t, err) + + app.StakingKeeper.SetValidator(ctx, val1) + app.StakingKeeper.SetValidator(ctx, val2) + app.StakingKeeper.SetValidator(ctx, val3) + app.StakingKeeper.SetValidatorByConsAddr(ctx, val1) + app.StakingKeeper.SetValidatorByConsAddr(ctx, val2) + app.StakingKeeper.SetValidatorByConsAddr(ctx, val3) + app.StakingKeeper.SetNewValidatorByPowerIndex(ctx, val1) + app.StakingKeeper.SetNewValidatorByPowerIndex(ctx, val2) + app.StakingKeeper.SetNewValidatorByPowerIndex(ctx, val3) + + _, _ = app.StakingKeeper.Delegate(ctx, addrs[0], app.StakingKeeper.TokensFromConsensusPower(ctx, powers[0]), stakingtypes.Unbonded, val1, true) + _, _ = app.StakingKeeper.Delegate(ctx, addrs[1], app.StakingKeeper.TokensFromConsensusPower(ctx, powers[1]), stakingtypes.Unbonded, val2, true) + _, _ = app.StakingKeeper.Delegate(ctx, addrs[2], app.StakingKeeper.TokensFromConsensusPower(ctx, powers[2]), stakingtypes.Unbonded, val3, true) + + _ = staking.EndBlocker(ctx, app.StakingKeeper) + + return addrs, valAddrs +} diff --git a/tests/integration/gov/keeper/grpc_query_test.go b/tests/integration/gov/keeper/grpc_query_test.go new file mode 100644 index 000000000000..0fd64e2a0ce3 --- /dev/null +++ b/tests/integration/gov/keeper/grpc_query_test.go @@ -0,0 +1,245 @@ +package keeper_test + +import ( + gocontext "context" + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" +) + +func (suite *KeeperTestSuite) TestGRPCQueryTally() { + app, ctx, queryClient := suite.app, suite.ctx, suite.queryClient + + addrs, _ := createValidators(suite.T(), ctx, app, []int64{5, 5, 5}) + + var ( + req *v1.QueryTallyResultRequest + expRes *v1.QueryTallyResultResponse + proposal v1.Proposal + ) + + testCases := []struct { + msg string + malleate func() + expPass bool + }{ + { + "empty request", + func() { + req = &v1.QueryTallyResultRequest{} + }, + false, + }, + { + "zero proposal id request", + func() { + req = &v1.QueryTallyResultRequest{ProposalId: 0} + }, + false, + }, + { + "query non existed proposal", + func() { + req = &v1.QueryTallyResultRequest{ProposalId: 1} + }, + false, + }, + { + "create a proposal and get tally", + func() { + var err error + proposal, err = app.GovKeeper.SubmitProposal(ctx, TestProposal, "") + suite.Require().NoError(err) + suite.Require().NotNil(proposal) + + req = &v1.QueryTallyResultRequest{ProposalId: proposal.Id} + + tallyResult := v1.EmptyTallyResult() + expRes = &v1.QueryTallyResultResponse{ + Tally: &tallyResult, + } + }, + true, + }, + { + "request tally after few votes", + func() { + proposal.Status = v1.StatusVotingPeriod + app.GovKeeper.SetProposal(ctx, proposal) + + suite.Require().NoError(app.GovKeeper.AddVote(ctx, proposal.Id, addrs[0], v1.NewNonSplitVoteOption(v1.OptionYes), "")) + suite.Require().NoError(app.GovKeeper.AddVote(ctx, proposal.Id, addrs[1], v1.NewNonSplitVoteOption(v1.OptionYes), "")) + suite.Require().NoError(app.GovKeeper.AddVote(ctx, proposal.Id, addrs[2], v1.NewNonSplitVoteOption(v1.OptionYes), "")) + + req = &v1.QueryTallyResultRequest{ProposalId: proposal.Id} + + expRes = &v1.QueryTallyResultResponse{ + Tally: &v1.TallyResult{ + YesCount: sdk.NewInt(3 * 5 * 1000000).String(), + NoCount: "0", + AbstainCount: "0", + NoWithVetoCount: "0", + }, + } + }, + true, + }, + { + "request final tally after status changed", + func() { + proposal.Status = v1.StatusPassed + app.GovKeeper.SetProposal(ctx, proposal) + proposal, _ = app.GovKeeper.GetProposal(ctx, proposal.Id) + + req = &v1.QueryTallyResultRequest{ProposalId: proposal.Id} + + expRes = &v1.QueryTallyResultResponse{ + Tally: proposal.FinalTallyResult, + } + }, + true, + }, + } + + for _, testCase := range testCases { + suite.Run(fmt.Sprintf("Case %s", testCase.msg), func() { + testCase.malleate() + + tally, err := queryClient.TallyResult(gocontext.Background(), req) + + if testCase.expPass { + suite.Require().NoError(err) + suite.Require().Equal(expRes.String(), tally.String()) + } else { + suite.Require().Error(err) + suite.Require().Nil(tally) + } + }) + } +} + +func (suite *KeeperTestSuite) TestLegacyGRPCQueryTally() { + app, ctx, queryClient := suite.app, suite.ctx, suite.legacyQueryClient + + addrs, _ := createValidators(suite.T(), ctx, app, []int64{5, 5, 5}) + + var ( + req *v1beta1.QueryTallyResultRequest + expRes *v1beta1.QueryTallyResultResponse + proposal v1.Proposal + ) + + testCases := []struct { + msg string + malleate func() + expPass bool + }{ + { + "empty request", + func() { + req = &v1beta1.QueryTallyResultRequest{} + }, + false, + }, + { + "zero proposal id request", + func() { + req = &v1beta1.QueryTallyResultRequest{ProposalId: 0} + }, + false, + }, + { + "query non existed proposal", + func() { + req = &v1beta1.QueryTallyResultRequest{ProposalId: 1} + }, + false, + }, + { + "create a proposal and get tally", + func() { + var err error + proposal, err = app.GovKeeper.SubmitProposal(ctx, TestProposal, "") + suite.Require().NoError(err) + suite.Require().NotNil(proposal) + + req = &v1beta1.QueryTallyResultRequest{ProposalId: proposal.Id} + + tallyResult := v1beta1.EmptyTallyResult() + expRes = &v1beta1.QueryTallyResultResponse{ + Tally: tallyResult, + } + }, + true, + }, + { + "request tally after few votes", + func() { + proposal.Status = v1.StatusVotingPeriod + app.GovKeeper.SetProposal(ctx, proposal) + + suite.Require().NoError(app.GovKeeper.AddVote(ctx, proposal.Id, addrs[0], v1.NewNonSplitVoteOption(v1.OptionYes), "")) + suite.Require().NoError(app.GovKeeper.AddVote(ctx, proposal.Id, addrs[1], v1.NewNonSplitVoteOption(v1.OptionYes), "")) + suite.Require().NoError(app.GovKeeper.AddVote(ctx, proposal.Id, addrs[2], v1.NewNonSplitVoteOption(v1.OptionYes), "")) + + req = &v1beta1.QueryTallyResultRequest{ProposalId: proposal.Id} + + expRes = &v1beta1.QueryTallyResultResponse{ + Tally: v1beta1.TallyResult{ + Yes: sdk.NewInt(3 * 5 * 1000000), + No: sdk.NewInt(0), + Abstain: sdk.NewInt(0), + NoWithVeto: sdk.NewInt(0), + }, + } + }, + true, + }, + { + "request final tally after status changed", + func() { + proposal.Status = v1.StatusPassed + app.GovKeeper.SetProposal(ctx, proposal) + proposal, _ = app.GovKeeper.GetProposal(ctx, proposal.Id) + + req = &v1beta1.QueryTallyResultRequest{ProposalId: proposal.Id} + + expRes = &v1beta1.QueryTallyResultResponse{ + Tally: v1TallyToV1Beta1Tally(*proposal.FinalTallyResult), + } + }, + true, + }, + } + + for _, testCase := range testCases { + suite.Run(fmt.Sprintf("Case %s", testCase.msg), func() { + testCase.malleate() + + tally, err := queryClient.TallyResult(gocontext.Background(), req) + + if testCase.expPass { + suite.Require().NoError(err) + suite.Require().Equal(expRes.String(), tally.String()) + } else { + suite.Require().Error(err) + suite.Require().Nil(tally) + } + }) + } +} + +func v1TallyToV1Beta1Tally(t v1.TallyResult) v1beta1.TallyResult { + yes, _ := sdk.NewIntFromString(t.YesCount) + no, _ := sdk.NewIntFromString(t.NoCount) + noWithVeto, _ := sdk.NewIntFromString(t.NoWithVetoCount) + abstain, _ := sdk.NewIntFromString(t.AbstainCount) + return v1beta1.TallyResult{ + Yes: yes, + No: no, + NoWithVeto: noWithVeto, + Abstain: abstain, + } +} diff --git a/tests/integration/gov/keeper/keeper_test.go b/tests/integration/gov/keeper/keeper_test.go new file mode 100644 index 000000000000..a937d414f306 --- /dev/null +++ b/tests/integration/gov/keeper/keeper_test.go @@ -0,0 +1,68 @@ +package keeper_test + +import ( + "testing" + + "github.com/stretchr/testify/suite" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/simapp" + sdk "github.com/cosmos/cosmos-sdk/types" + "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" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" +) + +// KeeperTestSuite only tests gov's keeper logic around tallying, since it +// relies on complex interactions with x/staking. +// +// It also uses simapp (and not a depinjected app) because we manually set a +// new app.StakingKeeper in `createValidators`. +type KeeperTestSuite struct { + suite.Suite + + app *simapp.SimApp + ctx sdk.Context + queryClient v1.QueryClient + legacyQueryClient v1beta1.QueryClient + addrs []sdk.AccAddress + msgSrvr v1.MsgServer + legacyMsgSrvr v1beta1.MsgServer +} + +func (suite *KeeperTestSuite) SetupTest() { + app := simapp.Setup(suite.T(), false) + ctx := app.BaseApp.NewContext(false, tmproto.Header{}) + + // Populate the gov account with some coins, as the TestProposal we have + // is a MsgSend from the gov account. + coins := sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(100000))) + err := app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, coins) + suite.NoError(err) + err = app.BankKeeper.SendCoinsFromModuleToModule(ctx, minttypes.ModuleName, types.ModuleName, coins) + suite.NoError(err) + + queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry()) + v1.RegisterQueryServer(queryHelper, app.GovKeeper) + legacyQueryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry()) + v1beta1.RegisterQueryServer(legacyQueryHelper, keeper.NewLegacyQueryServer(app.GovKeeper)) + queryClient := v1.NewQueryClient(queryHelper) + legacyQueryClient := v1beta1.NewQueryClient(legacyQueryHelper) + + suite.app = app + suite.ctx = ctx + suite.queryClient = queryClient + suite.legacyQueryClient = legacyQueryClient + suite.msgSrvr = keeper.NewMsgServerImpl(suite.app.GovKeeper) + + govAcct := suite.app.GovKeeper.GetGovernanceAccount(suite.ctx).GetAddress() + suite.legacyMsgSrvr = keeper.NewLegacyMsgServerImpl(govAcct.String(), suite.msgSrvr) + suite.addrs = simapp.AddTestAddrsIncremental(app, ctx, 2, sdk.NewInt(30000000)) +} + +func TestKeeperTestSuite(t *testing.T) { + suite.Run(t, new(KeeperTestSuite)) +} diff --git a/x/gov/keeper/tally_test.go b/tests/integration/gov/keeper/tally_test.go similarity index 100% rename from x/gov/keeper/tally_test.go rename to tests/integration/gov/keeper/tally_test.go diff --git a/testutil/sims/address_helpers.go b/testutil/sims/address_helpers.go index a76086375a1c..d95279c3236e 100644 --- a/testutil/sims/address_helpers.go +++ b/testutil/sims/address_helpers.go @@ -13,13 +13,19 @@ import ( "github.com/cosmos/cosmos-sdk/types/errors" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" - stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" ) type GenerateAccountStrategy func(int) []sdk.AccAddress +// BondDenomProvider is a subset of the staking keeper's public interface that +// provides the staking bond denom. It is used in arguments in this package's +// functions so that a mock staking keeper can be passed instead of the real one. +type BondDenomProvider interface { + BondDenom(ctx sdk.Context) string +} + // AddTestAddrsFromPubKeys adds the addresses into the SimApp providing only the public keys. -func AddTestAddrsFromPubKeys(bankKeeper bankkeeper.Keeper, stakingKeeper *stakingkeeper.Keeper, ctx sdk.Context, pubKeys []cryptotypes.PubKey, accAmt math.Int) { +func AddTestAddrsFromPubKeys(bankKeeper bankkeeper.Keeper, stakingKeeper BondDenomProvider, ctx sdk.Context, pubKeys []cryptotypes.PubKey, accAmt math.Int) { initCoins := sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), accAmt)) for _, pk := range pubKeys { @@ -29,16 +35,16 @@ func AddTestAddrsFromPubKeys(bankKeeper bankkeeper.Keeper, stakingKeeper *stakin // AddTestAddrs constructs and returns accNum amount of accounts with an // initial balance of accAmt in random order -func AddTestAddrs(bankKeeper bankkeeper.Keeper, stakingKeeper *stakingkeeper.Keeper, ctx sdk.Context, accNum int, accAmt math.Int) []sdk.AccAddress { +func AddTestAddrs(bankKeeper bankkeeper.Keeper, stakingKeeper BondDenomProvider, ctx sdk.Context, accNum int, accAmt math.Int) []sdk.AccAddress { return addTestAddrs(bankKeeper, stakingKeeper, ctx, accNum, accAmt, CreateRandomAccounts) } // AddTestAddrsIncremental constructs and returns accNum amount of accounts with an initial balance of accAmt in random order -func AddTestAddrsIncremental(bankKeeper bankkeeper.Keeper, stakingKeeper *stakingkeeper.Keeper, ctx sdk.Context, accNum int, accAmt math.Int) []sdk.AccAddress { +func AddTestAddrsIncremental(bankKeeper bankkeeper.Keeper, stakingKeeper BondDenomProvider, ctx sdk.Context, accNum int, accAmt math.Int) []sdk.AccAddress { return addTestAddrs(bankKeeper, stakingKeeper, ctx, accNum, accAmt, CreateIncrementalAccounts) } -func addTestAddrs(bankKeeper bankkeeper.Keeper, stakingKeeper *stakingkeeper.Keeper, ctx sdk.Context, accNum int, accAmt math.Int, strategy GenerateAccountStrategy) []sdk.AccAddress { +func addTestAddrs(bankKeeper bankkeeper.Keeper, stakingKeeper BondDenomProvider, ctx sdk.Context, accNum int, accAmt math.Int, strategy GenerateAccountStrategy) []sdk.AccAddress { testAddrs := strategy(accNum) initCoins := sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), accAmt)) diff --git a/x/gov/keeper/common_test.go b/x/gov/keeper/common_test.go index f29fa800ba44..c4e82bee647e 100644 --- a/x/gov/keeper/common_test.go +++ b/x/gov/keeper/common_test.go @@ -1,23 +1,27 @@ package keeper_test import ( + "fmt" "testing" - "github.com/stretchr/testify/require" + "cosmossdk.io/math" + "github.com/golang/mock/gomock" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + tmtime "github.com/tendermint/tendermint/types/time" - "github.com/cosmos/cosmos-sdk/simapp" - simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/cosmos/cosmos-sdk/x/gov/keeper" + govtestutil "github.com/cosmos/cosmos-sdk/x/gov/testutil" "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/staking" - stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" ) var ( @@ -38,42 +42,83 @@ func getTestProposal() []sdk.Msg { } } -func createValidators(t *testing.T, ctx sdk.Context, app *simapp.SimApp, powers []int64) ([]sdk.AccAddress, []sdk.ValAddress) { - addrs := simapp.AddTestAddrsIncremental(app, ctx, 5, sdk.NewInt(30000000)) - valAddrs := simtestutil.ConvertAddrsToValAddrs(addrs) - pks := simtestutil.CreateTestPubKeys(5) - cdc := moduletestutil.MakeTestEncodingConfig().Codec +// setupGovKeeper creates a govKeeper as well as all its dependencies. +func setupGovKeeper(t *testing.T) ( + *keeper.Keeper, + *govtestutil.MockAccountKeeper, + *govtestutil.MockBankKeeper, + *govtestutil.MockStakingKeeper, + moduletestutil.TestEncodingConfig, + sdk.Context, +) { + key := sdk.NewKVStoreKey(types.StoreKey) + testCtx := testutil.DefaultContextWithDB(t, key, sdk.NewTransientStoreKey("transient_test")) + ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{Time: tmtime.Now()}) + encCfg := moduletestutil.MakeTestEncodingConfig() + v1.RegisterInterfaces(encCfg.InterfaceRegistry) + v1beta1.RegisterInterfaces(encCfg.InterfaceRegistry) + banktypes.RegisterInterfaces(encCfg.InterfaceRegistry) - app.StakingKeeper = stakingkeeper.NewKeeper( - cdc, - app.GetKey(stakingtypes.StoreKey), - app.AccountKeeper, - app.BankKeeper, - authtypes.NewModuleAddress(types.ModuleName).String(), - ) + // Create MsgServiceRouter, but don't populate it before creating the gov + // keeper. + msr := baseapp.NewMsgServiceRouter() - val1, err := stakingtypes.NewValidator(valAddrs[0], pks[0], stakingtypes.Description{}) - require.NoError(t, err) - val2, err := stakingtypes.NewValidator(valAddrs[1], pks[1], stakingtypes.Description{}) - require.NoError(t, err) - val3, err := stakingtypes.NewValidator(valAddrs[2], pks[2], stakingtypes.Description{}) - require.NoError(t, err) + // gomock initializations + ctrl := gomock.NewController(t) + acctKeeper := govtestutil.NewMockAccountKeeper(ctrl) + bankKeeper := govtestutil.NewMockBankKeeper(ctrl) + stakingKeeper := govtestutil.NewMockStakingKeeper(ctrl) + acctKeeper.EXPECT().GetModuleAddress(types.ModuleName).Return(govAcct).AnyTimes() + acctKeeper.EXPECT().GetModuleAccount(gomock.Any(), types.ModuleName).Return(authtypes.NewEmptyModuleAccount(types.ModuleName)).AnyTimes() + trackMockBalances(bankKeeper) + stakingKeeper.EXPECT().TokensFromConsensusPower(ctx, gomock.Any()).DoAndReturn(func(ctx sdk.Context, power int64) math.Int { + return sdk.TokensFromConsensusPower(power, math.NewIntFromUint64(1000000)) + }).AnyTimes() + stakingKeeper.EXPECT().BondDenom(ctx).Return("stake").AnyTimes() + stakingKeeper.EXPECT().IterateBondedValidatorsByPower(gomock.Any(), gomock.Any()).AnyTimes() + stakingKeeper.EXPECT().IterateDelegations(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes() + stakingKeeper.EXPECT().TotalBondedTokens(gomock.Any()).Return(math.NewInt(10000000)).AnyTimes() - app.StakingKeeper.SetValidator(ctx, val1) - app.StakingKeeper.SetValidator(ctx, val2) - app.StakingKeeper.SetValidator(ctx, val3) - app.StakingKeeper.SetValidatorByConsAddr(ctx, val1) - app.StakingKeeper.SetValidatorByConsAddr(ctx, val2) - app.StakingKeeper.SetValidatorByConsAddr(ctx, val3) - app.StakingKeeper.SetNewValidatorByPowerIndex(ctx, val1) - app.StakingKeeper.SetNewValidatorByPowerIndex(ctx, val2) - app.StakingKeeper.SetNewValidatorByPowerIndex(ctx, val3) + // Gov keeper initializations + govKeeper := keeper.NewKeeper(encCfg.Codec, key, acctKeeper, bankKeeper, stakingKeeper, msr, types.DefaultConfig(), govAcct.String()) + govKeeper.SetProposalID(ctx, 1) + govRouter := v1beta1.NewRouter() // Also register legacy gov handlers to test them too. + govRouter.AddRoute(types.RouterKey, v1beta1.ProposalHandler) + govKeeper.SetLegacyRouter(govRouter) + govKeeper.SetParams(ctx, v1.DefaultParams()) - _, _ = app.StakingKeeper.Delegate(ctx, addrs[0], app.StakingKeeper.TokensFromConsensusPower(ctx, powers[0]), stakingtypes.Unbonded, val1, true) - _, _ = app.StakingKeeper.Delegate(ctx, addrs[1], app.StakingKeeper.TokensFromConsensusPower(ctx, powers[1]), stakingtypes.Unbonded, val2, true) - _, _ = app.StakingKeeper.Delegate(ctx, addrs[2], app.StakingKeeper.TokensFromConsensusPower(ctx, powers[2]), stakingtypes.Unbonded, val3, true) + // Register all handlers for the MegServiceRouter. + msr.SetInterfaceRegistry(encCfg.InterfaceRegistry) + v1.RegisterMsgServer(msr, keeper.NewMsgServerImpl(govKeeper)) + banktypes.RegisterMsgServer(msr, nil) // Nil is fine here as long as we never execute the proposal's Msgs. - _ = staking.EndBlocker(ctx, app.StakingKeeper) + return govKeeper, acctKeeper, bankKeeper, stakingKeeper, encCfg, ctx +} + +// trackMockBalances sets up expected calls on the Mock BankKeeper, and also +// locally tracks accounts balances (not modules balances). +func trackMockBalances(bankKeeper *govtestutil.MockBankKeeper) { + balances := make(map[string]sdk.Coins) + + // We don't track module account balances. + bankKeeper.EXPECT().MintCoins(gomock.Any(), minttypes.ModuleName, gomock.Any()).AnyTimes() + bankKeeper.EXPECT().BurnCoins(gomock.Any(), types.ModuleName, gomock.Any()).AnyTimes() + bankKeeper.EXPECT().SendCoinsFromModuleToModule(gomock.Any(), minttypes.ModuleName, types.ModuleName, gomock.Any()).AnyTimes() - return addrs, valAddrs + // But we do track normal account balances. + bankKeeper.EXPECT().SendCoinsFromAccountToModule(gomock.Any(), gomock.Any(), types.ModuleName, gomock.Any()).DoAndReturn(func(_ sdk.Context, sender sdk.AccAddress, _ string, coins sdk.Coins) error { + newBalance, negative := balances[sender.String()].SafeSub(coins...) + if negative { + return fmt.Errorf("not enough balance") + } + balances[sender.String()] = newBalance + return nil + }).AnyTimes() + bankKeeper.EXPECT().SendCoinsFromModuleToAccount(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn(func(_ sdk.Context, module string, rcpt sdk.AccAddress, coins sdk.Coins) error { + balances[rcpt.String()] = balances[rcpt.String()].Add(coins...) + return nil + }).AnyTimes() + bankKeeper.EXPECT().GetAllBalances(gomock.Any(), gomock.Any()).DoAndReturn(func(_ sdk.Context, addr sdk.AccAddress) sdk.Coins { + return balances[addr.String()] + }).AnyTimes() } diff --git a/x/gov/keeper/deposit_test.go b/x/gov/keeper/deposit_test.go index 158756ca9780..03c77a3e0765 100644 --- a/x/gov/keeper/deposit_test.go +++ b/x/gov/keeper/deposit_test.go @@ -4,9 +4,8 @@ import ( "testing" "github.com/stretchr/testify/require" - 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" v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" ) @@ -17,105 +16,104 @@ const ( ) func TestDeposits(t *testing.T) { - app := simapp.Setup(t, false) - ctx := app.BaseApp.NewContext(false, tmproto.Header{}) - - TestAddrs := simapp.AddTestAddrsIncremental(app, ctx, 2, sdk.NewInt(10000000)) + govKeeper, _, bankKeeper, stakingKeeper, _, ctx := setupGovKeeper(t) + trackMockBalances(bankKeeper) + TestAddrs := simtestutil.AddTestAddrsIncremental(bankKeeper, stakingKeeper, ctx, 2, sdk.NewInt(10000000)) tp := TestProposal - proposal, err := app.GovKeeper.SubmitProposal(ctx, tp, "") + proposal, err := govKeeper.SubmitProposal(ctx, tp, "") require.NoError(t, err) proposalID := proposal.Id - fourStake := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, app.StakingKeeper.TokensFromConsensusPower(ctx, 4))) - fiveStake := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, app.StakingKeeper.TokensFromConsensusPower(ctx, 5))) + fourStake := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, stakingKeeper.TokensFromConsensusPower(ctx, 4))) + fiveStake := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, stakingKeeper.TokensFromConsensusPower(ctx, 5))) - addr0Initial := app.BankKeeper.GetAllBalances(ctx, TestAddrs[0]) - addr1Initial := app.BankKeeper.GetAllBalances(ctx, TestAddrs[1]) + addr0Initial := bankKeeper.GetAllBalances(ctx, TestAddrs[0]) + addr1Initial := bankKeeper.GetAllBalances(ctx, TestAddrs[1]) require.True(t, sdk.NewCoins(proposal.TotalDeposit...).IsEqual(sdk.NewCoins())) // Check no deposits at beginning - deposit, found := app.GovKeeper.GetDeposit(ctx, proposalID, TestAddrs[1]) + deposit, found := govKeeper.GetDeposit(ctx, proposalID, TestAddrs[1]) require.False(t, found) - proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID) + proposal, ok := govKeeper.GetProposal(ctx, proposalID) require.True(t, ok) require.Nil(t, proposal.VotingStartTime) // Check first deposit - votingStarted, err := app.GovKeeper.AddDeposit(ctx, proposalID, TestAddrs[0], fourStake) + votingStarted, err := govKeeper.AddDeposit(ctx, proposalID, TestAddrs[0], fourStake) require.NoError(t, err) require.False(t, votingStarted) - deposit, found = app.GovKeeper.GetDeposit(ctx, proposalID, TestAddrs[0]) + deposit, found = govKeeper.GetDeposit(ctx, proposalID, TestAddrs[0]) require.True(t, found) require.Equal(t, fourStake, sdk.NewCoins(deposit.Amount...)) require.Equal(t, TestAddrs[0].String(), deposit.Depositor) - proposal, ok = app.GovKeeper.GetProposal(ctx, proposalID) + proposal, ok = govKeeper.GetProposal(ctx, proposalID) require.True(t, ok) require.Equal(t, fourStake, sdk.NewCoins(proposal.TotalDeposit...)) - require.Equal(t, addr0Initial.Sub(fourStake...), app.BankKeeper.GetAllBalances(ctx, TestAddrs[0])) + require.Equal(t, addr0Initial.Sub(fourStake...), bankKeeper.GetAllBalances(ctx, TestAddrs[0])) // Check a second deposit from same address - votingStarted, err = app.GovKeeper.AddDeposit(ctx, proposalID, TestAddrs[0], fiveStake) + votingStarted, err = govKeeper.AddDeposit(ctx, proposalID, TestAddrs[0], fiveStake) require.NoError(t, err) require.False(t, votingStarted) - deposit, found = app.GovKeeper.GetDeposit(ctx, proposalID, TestAddrs[0]) + deposit, found = govKeeper.GetDeposit(ctx, proposalID, TestAddrs[0]) require.True(t, found) require.Equal(t, fourStake.Add(fiveStake...), sdk.NewCoins(deposit.Amount...)) require.Equal(t, TestAddrs[0].String(), deposit.Depositor) - proposal, ok = app.GovKeeper.GetProposal(ctx, proposalID) + proposal, ok = govKeeper.GetProposal(ctx, proposalID) require.True(t, ok) require.Equal(t, fourStake.Add(fiveStake...), sdk.NewCoins(proposal.TotalDeposit...)) - require.Equal(t, addr0Initial.Sub(fourStake...).Sub(fiveStake...), app.BankKeeper.GetAllBalances(ctx, TestAddrs[0])) + require.Equal(t, addr0Initial.Sub(fourStake...).Sub(fiveStake...), bankKeeper.GetAllBalances(ctx, TestAddrs[0])) // Check third deposit from a new address - votingStarted, err = app.GovKeeper.AddDeposit(ctx, proposalID, TestAddrs[1], fourStake) + votingStarted, err = govKeeper.AddDeposit(ctx, proposalID, TestAddrs[1], fourStake) require.NoError(t, err) require.True(t, votingStarted) - deposit, found = app.GovKeeper.GetDeposit(ctx, proposalID, TestAddrs[1]) + deposit, found = govKeeper.GetDeposit(ctx, proposalID, TestAddrs[1]) require.True(t, found) require.Equal(t, TestAddrs[1].String(), deposit.Depositor) require.Equal(t, fourStake, sdk.NewCoins(deposit.Amount...)) - proposal, ok = app.GovKeeper.GetProposal(ctx, proposalID) + proposal, ok = govKeeper.GetProposal(ctx, proposalID) require.True(t, ok) require.Equal(t, fourStake.Add(fiveStake...).Add(fourStake...), sdk.NewCoins(proposal.TotalDeposit...)) - require.Equal(t, addr1Initial.Sub(fourStake...), app.BankKeeper.GetAllBalances(ctx, TestAddrs[1])) + require.Equal(t, addr1Initial.Sub(fourStake...), bankKeeper.GetAllBalances(ctx, TestAddrs[1])) // Check that proposal moved to voting period - proposal, ok = app.GovKeeper.GetProposal(ctx, proposalID) + proposal, ok = govKeeper.GetProposal(ctx, proposalID) require.True(t, ok) require.True(t, proposal.VotingStartTime.Equal(ctx.BlockHeader().Time)) // Test deposit iterator // NOTE order of deposits is determined by the addresses - deposits := app.GovKeeper.GetAllDeposits(ctx) + deposits := govKeeper.GetAllDeposits(ctx) require.Len(t, deposits, 2) - require.Equal(t, deposits, app.GovKeeper.GetDeposits(ctx, proposalID)) + require.Equal(t, deposits, govKeeper.GetDeposits(ctx, proposalID)) require.Equal(t, TestAddrs[0].String(), deposits[0].Depositor) require.Equal(t, fourStake.Add(fiveStake...), sdk.NewCoins(deposits[0].Amount...)) require.Equal(t, TestAddrs[1].String(), deposits[1].Depositor) require.Equal(t, fourStake, sdk.NewCoins(deposits[1].Amount...)) // Test Refund Deposits - deposit, found = app.GovKeeper.GetDeposit(ctx, proposalID, TestAddrs[1]) + deposit, found = govKeeper.GetDeposit(ctx, proposalID, TestAddrs[1]) require.True(t, found) require.Equal(t, fourStake, sdk.NewCoins(deposit.Amount...)) - app.GovKeeper.RefundAndDeleteDeposits(ctx, proposalID) - deposit, found = app.GovKeeper.GetDeposit(ctx, proposalID, TestAddrs[1]) + govKeeper.RefundAndDeleteDeposits(ctx, proposalID) + deposit, found = govKeeper.GetDeposit(ctx, proposalID, TestAddrs[1]) require.False(t, found) - require.Equal(t, addr0Initial, app.BankKeeper.GetAllBalances(ctx, TestAddrs[0])) - require.Equal(t, addr1Initial, app.BankKeeper.GetAllBalances(ctx, TestAddrs[1])) + require.Equal(t, addr0Initial, bankKeeper.GetAllBalances(ctx, TestAddrs[0])) + require.Equal(t, addr1Initial, bankKeeper.GetAllBalances(ctx, TestAddrs[1])) // Test delete and burn deposits - proposal, err = app.GovKeeper.SubmitProposal(ctx, tp, "") + proposal, err = govKeeper.SubmitProposal(ctx, tp, "") require.NoError(t, err) proposalID = proposal.Id - _, err = app.GovKeeper.AddDeposit(ctx, proposalID, TestAddrs[0], fourStake) + _, err = govKeeper.AddDeposit(ctx, proposalID, TestAddrs[0], fourStake) require.NoError(t, err) - app.GovKeeper.DeleteAndBurnDeposits(ctx, proposalID) - deposits = app.GovKeeper.GetDeposits(ctx, proposalID) + govKeeper.DeleteAndBurnDeposits(ctx, proposalID) + deposits = govKeeper.GetDeposits(ctx, proposalID) require.Len(t, deposits, 0) - require.Equal(t, addr0Initial.Sub(fourStake...), app.BankKeeper.GetAllBalances(ctx, TestAddrs[0])) + require.Equal(t, addr0Initial.Sub(fourStake...), bankKeeper.GetAllBalances(ctx, TestAddrs[0])) } func TestValidateInitialDeposit(t *testing.T) { @@ -195,10 +193,7 @@ func TestValidateInitialDeposit(t *testing.T) { for name, tc := range testcases { t.Run(name, func(t *testing.T) { - app := simapp.Setup(t, false) - ctx := app.BaseApp.NewContext(false, tmproto.Header{}) - - govKeeper := app.GovKeeper + govKeeper, _, _, _, _, ctx := setupGovKeeper(t) params := v1.DefaultParams() params.MinDeposit = tc.minDeposit diff --git a/x/gov/keeper/grpc_query_test.go b/x/gov/keeper/grpc_query_test.go index 914721d134d5..de9711dfff97 100644 --- a/x/gov/keeper/grpc_query_test.go +++ b/x/gov/keeper/grpc_query_test.go @@ -5,7 +5,8 @@ import ( "fmt" "cosmossdk.io/math" - "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/types/query" v3 "github.com/cosmos/cosmos-sdk/x/gov/migrations/v3" @@ -14,7 +15,8 @@ import ( ) func (suite *KeeperTestSuite) TestGRPCQueryProposal() { - app, ctx, queryClient := suite.app, suite.ctx, suite.queryClient + suite.reset() + ctx, queryClient := suite.ctx, suite.queryClient var ( req *v1.QueryProposalRequest @@ -36,7 +38,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryProposal() { { "non existing proposal request", func() { - req = &v1.QueryProposalRequest{ProposalId: 3} + req = &v1.QueryProposalRequest{ProposalId: 2} }, false, }, @@ -54,7 +56,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryProposal() { testProposal := v1beta1.NewTextProposal("Proposal", "testing proposal") msgContent, err := v1.NewLegacyContent(testProposal, govAcct.String()) suite.Require().NoError(err) - submittedProposal, err := app.GovKeeper.SubmitProposal(ctx, []sdk.Msg{msgContent}, "") + submittedProposal, err := suite.govKeeper.SubmitProposal(ctx, []sdk.Msg{msgContent}, "") suite.Require().NoError(err) suite.Require().NotEmpty(submittedProposal) @@ -74,9 +76,9 @@ func (suite *KeeperTestSuite) TestGRPCQueryProposal() { suite.Require().NoError(err) // Instead of using MashalJSON, we could compare .String() output too. // https://github.com/cosmos/cosmos-sdk/issues/10965 - expJSON, err := suite.app.AppCodec().MarshalJSON(&expProposal) + expJSON, err := suite.cdc.MarshalJSON(&expProposal) suite.Require().NoError(err) - actualJSON, err := suite.app.AppCodec().MarshalJSON(proposalRes.Proposal) + actualJSON, err := suite.cdc.MarshalJSON(proposalRes.Proposal) suite.Require().NoError(err) suite.Require().Equal(expJSON, actualJSON) } else { @@ -88,7 +90,8 @@ func (suite *KeeperTestSuite) TestGRPCQueryProposal() { } func (suite *KeeperTestSuite) TestLegacyGRPCQueryProposal() { - app, ctx, queryClient := suite.app, suite.ctx, suite.legacyQueryClient + suite.reset() + ctx, queryClient := suite.ctx, suite.legacyQueryClient var ( req *v1beta1.QueryProposalRequest @@ -128,7 +131,7 @@ func (suite *KeeperTestSuite) TestLegacyGRPCQueryProposal() { testProposal := v1beta1.NewTextProposal("Proposal", "testing proposal") msgContent, err := v1.NewLegacyContent(testProposal, govAcct.String()) suite.Require().NoError(err) - submittedProposal, err := app.GovKeeper.SubmitProposal(ctx, []sdk.Msg{msgContent}, "") + submittedProposal, err := suite.govKeeper.SubmitProposal(ctx, []sdk.Msg{msgContent}, "") suite.Require().NoError(err) suite.Require().NotEmpty(submittedProposal) @@ -149,9 +152,9 @@ func (suite *KeeperTestSuite) TestLegacyGRPCQueryProposal() { suite.Require().NoError(err) // Instead of using MashalJSON, we could compare .String() output too. // https://github.com/cosmos/cosmos-sdk/issues/10965 - expJSON, err := suite.app.AppCodec().MarshalJSON(&expProposal) + expJSON, err := suite.cdc.MarshalJSON(&expProposal) suite.Require().NoError(err) - actualJSON, err := suite.app.AppCodec().MarshalJSON(&proposalRes.Proposal) + actualJSON, err := suite.cdc.MarshalJSON(&proposalRes.Proposal) suite.Require().NoError(err) suite.Require().Equal(expJSON, actualJSON) } else { @@ -163,7 +166,8 @@ func (suite *KeeperTestSuite) TestLegacyGRPCQueryProposal() { } func (suite *KeeperTestSuite) TestGRPCQueryProposals() { - app, ctx, queryClient, addrs := suite.app, suite.ctx, suite.queryClient, suite.addrs + suite.reset() + ctx, queryClient, addrs := suite.ctx, suite.queryClient, suite.addrs testProposals := []*v1.Proposal{} @@ -189,11 +193,11 @@ func (suite *KeeperTestSuite) TestGRPCQueryProposals() { func() { // create 5 test proposals for i := 0; i < 5; i++ { - govAddress := app.GovKeeper.GetGovernanceAccount(suite.ctx).GetAddress() + govAddress := suite.govKeeper.GetGovernanceAccount(suite.ctx).GetAddress() testProposal := []sdk.Msg{ v1.NewMsgVote(govAddress, uint64(i), v1.OptionYes, ""), } - proposal, err := app.GovKeeper.SubmitProposal(ctx, testProposal, "") + proposal, err := suite.govKeeper.SubmitProposal(ctx, testProposal, "") suite.Require().NotEmpty(proposal) suite.Require().NoError(err) testProposals = append(testProposals, &proposal) @@ -251,9 +255,9 @@ func (suite *KeeperTestSuite) TestGRPCQueryProposals() { { "request with filter of deposit address", func() { - depositCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, app.StakingKeeper.TokensFromConsensusPower(ctx, 20))) + depositCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, suite.stakingKeeper.TokensFromConsensusPower(ctx, 20))) deposit := v1.NewDeposit(testProposals[0].Id, addrs[0], depositCoins) - app.GovKeeper.SetDeposit(ctx, deposit) + suite.govKeeper.SetDeposit(ctx, deposit) req = &v1.QueryProposalsRequest{ Depositor: addrs[0].String(), @@ -269,8 +273,8 @@ func (suite *KeeperTestSuite) TestGRPCQueryProposals() { "request with filter of deposit address", func() { testProposals[1].Status = v1.StatusVotingPeriod - app.GovKeeper.SetProposal(ctx, *testProposals[1]) - suite.Require().NoError(app.GovKeeper.AddVote(ctx, testProposals[1].Id, addrs[0], v1.NewNonSplitVoteOption(v1.OptionAbstain), "")) + suite.govKeeper.SetProposal(ctx, *testProposals[1]) + suite.Require().NoError(suite.govKeeper.AddVote(ctx, testProposals[1].Id, addrs[0], v1.NewNonSplitVoteOption(v1.OptionAbstain), "")) req = &v1.QueryProposalsRequest{ Voter: addrs[0].String(), @@ -297,9 +301,9 @@ func (suite *KeeperTestSuite) TestGRPCQueryProposals() { for i := 0; i < len(proposals.GetProposals()); i++ { // Instead of using MashalJSON, we could compare .String() output too. // https://github.com/cosmos/cosmos-sdk/issues/10965 - expJSON, err := suite.app.AppCodec().MarshalJSON(expRes.GetProposals()[i]) + expJSON, err := suite.cdc.MarshalJSON(expRes.GetProposals()[i]) suite.Require().NoError(err) - actualJSON, err := suite.app.AppCodec().MarshalJSON(proposals.GetProposals()[i]) + actualJSON, err := suite.cdc.MarshalJSON(proposals.GetProposals()[i]) suite.Require().NoError(err) suite.Require().Equal(expJSON, actualJSON) @@ -314,7 +318,8 @@ func (suite *KeeperTestSuite) TestGRPCQueryProposals() { } func (suite *KeeperTestSuite) TestLegacyGRPCQueryProposals() { - app, ctx, queryClient := suite.app, suite.ctx, suite.legacyQueryClient + suite.reset() + ctx, queryClient := suite.ctx, suite.legacyQueryClient var req *v1beta1.QueryProposalsRequest @@ -330,7 +335,7 @@ func (suite *KeeperTestSuite) TestLegacyGRPCQueryProposals() { testProposal := v1beta1.NewTextProposal("Proposal", "testing proposal") msgContent, err := v1.NewLegacyContent(testProposal, govAcct.String()) suite.Require().NoError(err) - submittedProposal, err := app.GovKeeper.SubmitProposal(ctx, []sdk.Msg{msgContent}, "") + submittedProposal, err := suite.govKeeper.SubmitProposal(ctx, []sdk.Msg{msgContent}, "") suite.Require().NoError(err) suite.Require().NotEmpty(submittedProposal) }, @@ -357,7 +362,7 @@ func (suite *KeeperTestSuite) TestLegacyGRPCQueryProposals() { } func (suite *KeeperTestSuite) TestGRPCQueryVote() { - app, ctx, queryClient, addrs := suite.app, suite.ctx, suite.queryClient, suite.addrs + ctx, queryClient, addrs := suite.ctx, suite.queryClient, suite.addrs var ( req *v1.QueryVoteRequest @@ -411,7 +416,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryVote() { "no votes present", func() { var err error - proposal, err = app.GovKeeper.SubmitProposal(ctx, TestProposal, "") + proposal, err = suite.govKeeper.SubmitProposal(ctx, TestProposal, "") suite.Require().NoError(err) req = &v1.QueryVoteRequest{ @@ -427,8 +432,8 @@ func (suite *KeeperTestSuite) TestGRPCQueryVote() { "valid request", func() { proposal.Status = v1.StatusVotingPeriod - app.GovKeeper.SetProposal(ctx, proposal) - suite.Require().NoError(app.GovKeeper.AddVote(ctx, proposal.Id, addrs[0], v1.NewNonSplitVoteOption(v1.OptionAbstain), "")) + suite.govKeeper.SetProposal(ctx, proposal) + suite.Require().NoError(suite.govKeeper.AddVote(ctx, proposal.Id, addrs[0], v1.NewNonSplitVoteOption(v1.OptionAbstain), "")) req = &v1.QueryVoteRequest{ ProposalId: proposal.Id, @@ -471,7 +476,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryVote() { } func (suite *KeeperTestSuite) TestLegacyGRPCQueryVote() { - app, ctx, queryClient, addrs := suite.app, suite.ctx, suite.legacyQueryClient, suite.addrs + ctx, queryClient, addrs := suite.ctx, suite.legacyQueryClient, suite.addrs var ( req *v1beta1.QueryVoteRequest @@ -525,7 +530,7 @@ func (suite *KeeperTestSuite) TestLegacyGRPCQueryVote() { "no votes present", func() { var err error - proposal, err = app.GovKeeper.SubmitProposal(ctx, TestProposal, "") + proposal, err = suite.govKeeper.SubmitProposal(ctx, TestProposal, "") suite.Require().NoError(err) req = &v1beta1.QueryVoteRequest{ @@ -541,8 +546,8 @@ func (suite *KeeperTestSuite) TestLegacyGRPCQueryVote() { "valid request", func() { proposal.Status = v1.StatusVotingPeriod - app.GovKeeper.SetProposal(ctx, proposal) - suite.Require().NoError(app.GovKeeper.AddVote(ctx, proposal.Id, addrs[0], v1.NewNonSplitVoteOption(v1.OptionAbstain), "")) + suite.govKeeper.SetProposal(ctx, proposal) + suite.Require().NoError(suite.govKeeper.AddVote(ctx, proposal.Id, addrs[0], v1.NewNonSplitVoteOption(v1.OptionAbstain), "")) req = &v1beta1.QueryVoteRequest{ ProposalId: proposal.Id, @@ -585,9 +590,10 @@ func (suite *KeeperTestSuite) TestLegacyGRPCQueryVote() { } func (suite *KeeperTestSuite) TestGRPCQueryVotes() { - app, ctx, queryClient := suite.app, suite.ctx, suite.queryClient + suite.reset() + ctx, queryClient := suite.ctx, suite.queryClient - addrs := simapp.AddTestAddrsIncremental(app, ctx, 2, sdk.NewInt(30000000)) + addrs := simtestutil.AddTestAddrsIncremental(suite.bankKeeper, suite.stakingKeeper, ctx, 2, sdk.NewInt(30000000)) var ( req *v1.QueryVotesRequest @@ -630,7 +636,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryVotes() { "create a proposal and get votes", func() { var err error - proposal, err = app.GovKeeper.SubmitProposal(ctx, TestProposal, "") + proposal, err = suite.govKeeper.SubmitProposal(ctx, TestProposal, "") suite.Require().NoError(err) req = &v1.QueryVotesRequest{ @@ -643,7 +649,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryVotes() { "request after adding 2 votes", func() { proposal.Status = v1.StatusVotingPeriod - app.GovKeeper.SetProposal(ctx, proposal) + suite.govKeeper.SetProposal(ctx, proposal) votes = []*v1.Vote{ {ProposalId: proposal.Id, Voter: addrs[0].String(), Options: v1.NewNonSplitVoteOption(v1.OptionAbstain)}, @@ -653,8 +659,8 @@ func (suite *KeeperTestSuite) TestGRPCQueryVotes() { accAddr2, err2 := sdk.AccAddressFromBech32(votes[1].Voter) suite.Require().NoError(err1) suite.Require().NoError(err2) - suite.Require().NoError(app.GovKeeper.AddVote(ctx, proposal.Id, accAddr1, votes[0].Options, "")) - suite.Require().NoError(app.GovKeeper.AddVote(ctx, proposal.Id, accAddr2, votes[1].Options, "")) + suite.Require().NoError(suite.govKeeper.AddVote(ctx, proposal.Id, accAddr1, votes[0].Options, "")) + suite.Require().NoError(suite.govKeeper.AddVote(ctx, proposal.Id, accAddr2, votes[1].Options, "")) req = &v1.QueryVotesRequest{ ProposalId: proposal.Id, @@ -686,9 +692,10 @@ func (suite *KeeperTestSuite) TestGRPCQueryVotes() { } func (suite *KeeperTestSuite) TestLegacyGRPCQueryVotes() { - app, ctx, queryClient := suite.app, suite.ctx, suite.legacyQueryClient + suite.reset() + ctx, queryClient := suite.ctx, suite.legacyQueryClient - addrs := simapp.AddTestAddrsIncremental(app, ctx, 2, sdk.NewInt(30000000)) + addrs := simtestutil.AddTestAddrsIncremental(suite.bankKeeper, suite.stakingKeeper, ctx, 2, sdk.NewInt(30000000)) var ( req *v1beta1.QueryVotesRequest @@ -731,7 +738,7 @@ func (suite *KeeperTestSuite) TestLegacyGRPCQueryVotes() { "create a proposal and get votes", func() { var err error - proposal, err = app.GovKeeper.SubmitProposal(ctx, TestProposal, "") + proposal, err = suite.govKeeper.SubmitProposal(ctx, TestProposal, "") suite.Require().NoError(err) req = &v1beta1.QueryVotesRequest{ @@ -744,7 +751,7 @@ func (suite *KeeperTestSuite) TestLegacyGRPCQueryVotes() { "request after adding 2 votes", func() { proposal.Status = v1.StatusVotingPeriod - app.GovKeeper.SetProposal(ctx, proposal) + suite.govKeeper.SetProposal(ctx, proposal) votes = []v1beta1.Vote{ {ProposalId: proposal.Id, Voter: addrs[0].String(), Options: v1beta1.NewNonSplitVoteOption(v1beta1.OptionAbstain)}, @@ -754,8 +761,8 @@ func (suite *KeeperTestSuite) TestLegacyGRPCQueryVotes() { accAddr2, err2 := sdk.AccAddressFromBech32(votes[1].Voter) suite.Require().NoError(err1) suite.Require().NoError(err2) - suite.Require().NoError(app.GovKeeper.AddVote(ctx, proposal.Id, accAddr1, v1.NewNonSplitVoteOption(v1.OptionAbstain), "")) - suite.Require().NoError(app.GovKeeper.AddVote(ctx, proposal.Id, accAddr2, v1.NewNonSplitVoteOption(v1.OptionYes), "")) + suite.Require().NoError(suite.govKeeper.AddVote(ctx, proposal.Id, accAddr1, v1.NewNonSplitVoteOption(v1.OptionAbstain), "")) + suite.Require().NoError(suite.govKeeper.AddVote(ctx, proposal.Id, accAddr2, v1.NewNonSplitVoteOption(v1.OptionYes), "")) req = &v1beta1.QueryVotesRequest{ ProposalId: proposal.Id, @@ -961,7 +968,8 @@ func (suite *KeeperTestSuite) TestLegacyGRPCQueryParams() { } func (suite *KeeperTestSuite) TestGRPCQueryDeposit() { - app, ctx, queryClient, addrs := suite.app, suite.ctx, suite.queryClient, suite.addrs + suite.reset() + ctx, queryClient, addrs := suite.ctx, suite.queryClient, suite.addrs var ( req *v1.QueryDepositRequest @@ -1015,7 +1023,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryDeposit() { "no deposits proposal", func() { var err error - proposal, err = app.GovKeeper.SubmitProposal(ctx, TestProposal, "") + proposal, err = suite.govKeeper.SubmitProposal(ctx, TestProposal, "") suite.Require().NoError(err) suite.Require().NotNil(proposal) @@ -1029,9 +1037,9 @@ func (suite *KeeperTestSuite) TestGRPCQueryDeposit() { { "valid request", func() { - depositCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, app.StakingKeeper.TokensFromConsensusPower(ctx, 20))) + depositCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, suite.stakingKeeper.TokensFromConsensusPower(ctx, 20))) deposit := v1.NewDeposit(proposal.Id, addrs[0], depositCoins) - app.GovKeeper.SetDeposit(ctx, deposit) + suite.govKeeper.SetDeposit(ctx, deposit) req = &v1.QueryDepositRequest{ ProposalId: proposal.Id, @@ -1062,7 +1070,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryDeposit() { } func (suite *KeeperTestSuite) TestLegacyGRPCQueryDeposit() { - app, ctx, queryClient, addrs := suite.app, suite.ctx, suite.legacyQueryClient, suite.addrs + ctx, queryClient, addrs := suite.ctx, suite.legacyQueryClient, suite.addrs var ( req *v1beta1.QueryDepositRequest @@ -1116,7 +1124,7 @@ func (suite *KeeperTestSuite) TestLegacyGRPCQueryDeposit() { "no deposits proposal", func() { var err error - proposal, err = app.GovKeeper.SubmitProposal(ctx, TestProposal, "") + proposal, err = suite.govKeeper.SubmitProposal(ctx, TestProposal, "") suite.Require().NoError(err) suite.Require().NotNil(proposal) @@ -1130,10 +1138,10 @@ func (suite *KeeperTestSuite) TestLegacyGRPCQueryDeposit() { { "valid request", func() { - depositCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, app.StakingKeeper.TokensFromConsensusPower(ctx, 20))) + depositCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, suite.stakingKeeper.TokensFromConsensusPower(ctx, 20))) deposit := v1beta1.NewDeposit(proposal.Id, addrs[0], depositCoins) v1deposit := v1.NewDeposit(proposal.Id, addrs[0], depositCoins) - app.GovKeeper.SetDeposit(ctx, v1deposit) + suite.govKeeper.SetDeposit(ctx, v1deposit) req = &v1beta1.QueryDepositRequest{ ProposalId: proposal.Id, @@ -1164,7 +1172,7 @@ func (suite *KeeperTestSuite) TestLegacyGRPCQueryDeposit() { } func (suite *KeeperTestSuite) TestGRPCQueryDeposits() { - app, ctx, queryClient, addrs := suite.app, suite.ctx, suite.queryClient, suite.addrs + ctx, queryClient, addrs := suite.ctx, suite.queryClient, suite.addrs var ( req *v1.QueryDepositsRequest @@ -1206,7 +1214,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryDeposits() { "create a proposal and get deposits", func() { var err error - proposal, err = app.GovKeeper.SubmitProposal(ctx, TestProposal, "") + proposal, err = suite.govKeeper.SubmitProposal(ctx, TestProposal, "") suite.Require().NoError(err) req = &v1.QueryDepositsRequest{ @@ -1218,13 +1226,13 @@ func (suite *KeeperTestSuite) TestGRPCQueryDeposits() { { "get deposits with default limit", func() { - depositAmount1 := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, app.StakingKeeper.TokensFromConsensusPower(ctx, 20))) + depositAmount1 := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, suite.stakingKeeper.TokensFromConsensusPower(ctx, 20))) deposit1 := v1.NewDeposit(proposal.Id, addrs[0], depositAmount1) - app.GovKeeper.SetDeposit(ctx, deposit1) + suite.govKeeper.SetDeposit(ctx, deposit1) - depositAmount2 := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, app.StakingKeeper.TokensFromConsensusPower(ctx, 30))) + depositAmount2 := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, suite.stakingKeeper.TokensFromConsensusPower(ctx, 30))) deposit2 := v1.NewDeposit(proposal.Id, addrs[1], depositAmount2) - app.GovKeeper.SetDeposit(ctx, deposit2) + suite.govKeeper.SetDeposit(ctx, deposit2) deposits := v1.Deposits{&deposit1, &deposit2} @@ -1258,7 +1266,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryDeposits() { } func (suite *KeeperTestSuite) TestLegacyGRPCQueryDeposits() { - app, ctx, queryClient, addrs := suite.app, suite.ctx, suite.legacyQueryClient, suite.addrs + ctx, queryClient, addrs := suite.ctx, suite.legacyQueryClient, suite.addrs var ( req *v1beta1.QueryDepositsRequest @@ -1300,7 +1308,7 @@ func (suite *KeeperTestSuite) TestLegacyGRPCQueryDeposits() { "create a proposal and get deposits", func() { var err error - proposal, err = app.GovKeeper.SubmitProposal(ctx, TestProposal, "") + proposal, err = suite.govKeeper.SubmitProposal(ctx, TestProposal, "") suite.Require().NoError(err) req = &v1beta1.QueryDepositsRequest{ @@ -1312,15 +1320,15 @@ func (suite *KeeperTestSuite) TestLegacyGRPCQueryDeposits() { { "get deposits with default limit", func() { - depositAmount1 := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, app.StakingKeeper.TokensFromConsensusPower(ctx, 20))) + depositAmount1 := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, suite.stakingKeeper.TokensFromConsensusPower(ctx, 20))) deposit1 := v1beta1.NewDeposit(proposal.Id, addrs[0], depositAmount1) v1deposit1 := v1.NewDeposit(proposal.Id, addrs[0], depositAmount1) - app.GovKeeper.SetDeposit(ctx, v1deposit1) + suite.govKeeper.SetDeposit(ctx, v1deposit1) - depositAmount2 := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, app.StakingKeeper.TokensFromConsensusPower(ctx, 30))) + depositAmount2 := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, suite.stakingKeeper.TokensFromConsensusPower(ctx, 30))) deposit2 := v1beta1.NewDeposit(proposal.Id, addrs[1], depositAmount2) v1deposit2 := v1.NewDeposit(proposal.Id, addrs[1], depositAmount2) - app.GovKeeper.SetDeposit(ctx, v1deposit2) + suite.govKeeper.SetDeposit(ctx, v1deposit2) deposits := v1beta1.Deposits{deposit1, deposit2} @@ -1352,238 +1360,3 @@ func (suite *KeeperTestSuite) TestLegacyGRPCQueryDeposits() { }) } } - -func (suite *KeeperTestSuite) TestGRPCQueryTally() { - app, ctx, queryClient := suite.app, suite.ctx, suite.queryClient - - addrs, _ := createValidators(suite.T(), ctx, app, []int64{5, 5, 5}) - - var ( - req *v1.QueryTallyResultRequest - expRes *v1.QueryTallyResultResponse - proposal v1.Proposal - ) - - testCases := []struct { - msg string - malleate func() - expPass bool - }{ - { - "empty request", - func() { - req = &v1.QueryTallyResultRequest{} - }, - false, - }, - { - "zero proposal id request", - func() { - req = &v1.QueryTallyResultRequest{ProposalId: 0} - }, - false, - }, - { - "query non existed proposal", - func() { - req = &v1.QueryTallyResultRequest{ProposalId: 1} - }, - false, - }, - { - "create a proposal and get tally", - func() { - var err error - proposal, err = app.GovKeeper.SubmitProposal(ctx, TestProposal, "") - suite.Require().NoError(err) - suite.Require().NotNil(proposal) - - req = &v1.QueryTallyResultRequest{ProposalId: proposal.Id} - - tallyResult := v1.EmptyTallyResult() - expRes = &v1.QueryTallyResultResponse{ - Tally: &tallyResult, - } - }, - true, - }, - { - "request tally after few votes", - func() { - proposal.Status = v1.StatusVotingPeriod - app.GovKeeper.SetProposal(ctx, proposal) - - suite.Require().NoError(app.GovKeeper.AddVote(ctx, proposal.Id, addrs[0], v1.NewNonSplitVoteOption(v1.OptionYes), "")) - suite.Require().NoError(app.GovKeeper.AddVote(ctx, proposal.Id, addrs[1], v1.NewNonSplitVoteOption(v1.OptionYes), "")) - suite.Require().NoError(app.GovKeeper.AddVote(ctx, proposal.Id, addrs[2], v1.NewNonSplitVoteOption(v1.OptionYes), "")) - - req = &v1.QueryTallyResultRequest{ProposalId: proposal.Id} - - expRes = &v1.QueryTallyResultResponse{ - Tally: &v1.TallyResult{ - YesCount: sdk.NewInt(3 * 5 * 1000000).String(), - NoCount: "0", - AbstainCount: "0", - NoWithVetoCount: "0", - }, - } - }, - true, - }, - { - "request final tally after status changed", - func() { - proposal.Status = v1.StatusPassed - app.GovKeeper.SetProposal(ctx, proposal) - proposal, _ = app.GovKeeper.GetProposal(ctx, proposal.Id) - - req = &v1.QueryTallyResultRequest{ProposalId: proposal.Id} - - expRes = &v1.QueryTallyResultResponse{ - Tally: proposal.FinalTallyResult, - } - }, - true, - }, - } - - for _, testCase := range testCases { - suite.Run(fmt.Sprintf("Case %s", testCase.msg), func() { - testCase.malleate() - - tally, err := queryClient.TallyResult(gocontext.Background(), req) - - if testCase.expPass { - suite.Require().NoError(err) - suite.Require().Equal(expRes.String(), tally.String()) - } else { - suite.Require().Error(err) - suite.Require().Nil(tally) - } - }) - } -} - -func (suite *KeeperTestSuite) TestLegacyGRPCQueryTally() { - app, ctx, queryClient := suite.app, suite.ctx, suite.legacyQueryClient - - addrs, _ := createValidators(suite.T(), ctx, app, []int64{5, 5, 5}) - - var ( - req *v1beta1.QueryTallyResultRequest - expRes *v1beta1.QueryTallyResultResponse - proposal v1.Proposal - ) - - testCases := []struct { - msg string - malleate func() - expPass bool - }{ - { - "empty request", - func() { - req = &v1beta1.QueryTallyResultRequest{} - }, - false, - }, - { - "zero proposal id request", - func() { - req = &v1beta1.QueryTallyResultRequest{ProposalId: 0} - }, - false, - }, - { - "query non existed proposal", - func() { - req = &v1beta1.QueryTallyResultRequest{ProposalId: 1} - }, - false, - }, - { - "create a proposal and get tally", - func() { - var err error - proposal, err = app.GovKeeper.SubmitProposal(ctx, TestProposal, "") - suite.Require().NoError(err) - suite.Require().NotNil(proposal) - - req = &v1beta1.QueryTallyResultRequest{ProposalId: proposal.Id} - - tallyResult := v1beta1.EmptyTallyResult() - expRes = &v1beta1.QueryTallyResultResponse{ - Tally: tallyResult, - } - }, - true, - }, - { - "request tally after few votes", - func() { - proposal.Status = v1.StatusVotingPeriod - app.GovKeeper.SetProposal(ctx, proposal) - - suite.Require().NoError(app.GovKeeper.AddVote(ctx, proposal.Id, addrs[0], v1.NewNonSplitVoteOption(v1.OptionYes), "")) - suite.Require().NoError(app.GovKeeper.AddVote(ctx, proposal.Id, addrs[1], v1.NewNonSplitVoteOption(v1.OptionYes), "")) - suite.Require().NoError(app.GovKeeper.AddVote(ctx, proposal.Id, addrs[2], v1.NewNonSplitVoteOption(v1.OptionYes), "")) - - req = &v1beta1.QueryTallyResultRequest{ProposalId: proposal.Id} - - expRes = &v1beta1.QueryTallyResultResponse{ - Tally: v1beta1.TallyResult{ - Yes: sdk.NewInt(3 * 5 * 1000000), - No: sdk.NewInt(0), - Abstain: sdk.NewInt(0), - NoWithVeto: sdk.NewInt(0), - }, - } - }, - true, - }, - { - "request final tally after status changed", - func() { - proposal.Status = v1.StatusPassed - app.GovKeeper.SetProposal(ctx, proposal) - proposal, _ = app.GovKeeper.GetProposal(ctx, proposal.Id) - - req = &v1beta1.QueryTallyResultRequest{ProposalId: proposal.Id} - - expRes = &v1beta1.QueryTallyResultResponse{ - Tally: v1TallyToV1Beta1Tally(*proposal.FinalTallyResult), - } - }, - true, - }, - } - - for _, testCase := range testCases { - suite.Run(fmt.Sprintf("Case %s", testCase.msg), func() { - testCase.malleate() - - tally, err := queryClient.TallyResult(gocontext.Background(), req) - - if testCase.expPass { - suite.Require().NoError(err) - suite.Require().Equal(expRes.String(), tally.String()) - } else { - suite.Require().Error(err) - suite.Require().Nil(tally) - } - }) - } -} - -func v1TallyToV1Beta1Tally(t v1.TallyResult) v1beta1.TallyResult { - yes, _ := sdk.NewIntFromString(t.YesCount) - no, _ := sdk.NewIntFromString(t.NoCount) - noWithVeto, _ := sdk.NewIntFromString(t.NoWithVetoCount) - abstain, _ := sdk.NewIntFromString(t.AbstainCount) - return v1beta1.TallyResult{ - Yes: yes, - No: no, - NoWithVeto: noWithVeto, - Abstain: abstain, - } -} diff --git a/x/gov/keeper/hooks_test.go b/x/gov/keeper/hooks_test.go index 7773337cdbc6..6df5c3088c90 100644 --- a/x/gov/keeper/hooks_test.go +++ b/x/gov/keeper/hooks_test.go @@ -5,9 +5,8 @@ import ( "time" "github.com/stretchr/testify/require" - 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" @@ -47,16 +46,14 @@ func (h *MockGovHooksReceiver) AfterProposalVotingPeriodEnded(ctx sdk.Context, p } func TestHooks(t *testing.T) { - app := simapp.Setup(t, false) - ctx := app.BaseApp.NewContext(false, tmproto.Header{}) - - minDeposit := app.GovKeeper.GetParams(ctx).MinDeposit - addrs := simapp.AddTestAddrs(app, ctx, 1, minDeposit[0].Amount) + minDeposit := v1.DefaultParams().MinDeposit + govKeeper, _, bankKeeper, stakingKeeper, _, ctx := setupGovKeeper(t) + addrs := simtestutil.AddTestAddrs(bankKeeper, stakingKeeper, ctx, 1, minDeposit[0].Amount) govHooksReceiver := MockGovHooksReceiver{} keeper.UnsafeSetHooks( - app.GovKeeper, types.NewMultiGovHooks(&govHooksReceiver), + govKeeper, types.NewMultiGovHooks(&govHooksReceiver), ) require.False(t, govHooksReceiver.AfterProposalSubmissionValid) @@ -66,32 +63,32 @@ func TestHooks(t *testing.T) { require.False(t, govHooksReceiver.AfterProposalVotingPeriodEndedValid) tp := TestProposal - _, err := app.GovKeeper.SubmitProposal(ctx, tp, "") + _, err := govKeeper.SubmitProposal(ctx, tp, "") require.NoError(t, err) require.True(t, govHooksReceiver.AfterProposalSubmissionValid) 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(*govKeeper.GetParams(ctx).MaxDepositPeriod).Add(time.Duration(1) * time.Second) ctx = ctx.WithBlockHeader(newHeader) - gov.EndBlocker(ctx, app.GovKeeper) + gov.EndBlocker(ctx, govKeeper) require.True(t, govHooksReceiver.AfterProposalFailedMinDepositValid) - p2, err := app.GovKeeper.SubmitProposal(ctx, tp, "") + p2, err := govKeeper.SubmitProposal(ctx, tp, "") require.NoError(t, err) - activated, err := app.GovKeeper.AddDeposit(ctx, p2.Id, addrs[0], minDeposit) + activated, err := govKeeper.AddDeposit(ctx, p2.Id, addrs[0], minDeposit) require.True(t, activated) require.NoError(t, err) require.True(t, govHooksReceiver.AfterProposalDepositValid) - err = app.GovKeeper.AddVote(ctx, p2.Id, addrs[0], v1.NewNonSplitVoteOption(v1.OptionYes), "") + err = govKeeper.AddVote(ctx, p2.Id, addrs[0], v1.NewNonSplitVoteOption(v1.OptionYes), "") require.NoError(t, err) require.True(t, govHooksReceiver.AfterProposalVoteValid) newHeader = ctx.BlockHeader() - newHeader.Time = ctx.BlockHeader().Time.Add(*app.GovKeeper.GetParams(ctx).VotingPeriod).Add(time.Duration(1) * time.Second) + newHeader.Time = ctx.BlockHeader().Time.Add(*govKeeper.GetParams(ctx).VotingPeriod).Add(time.Duration(1) * time.Second) ctx = ctx.WithBlockHeader(newHeader) - gov.EndBlocker(ctx, app.GovKeeper) + gov.EndBlocker(ctx, govKeeper) require.True(t, govHooksReceiver.AfterProposalVotingPeriodEndedValid) } diff --git a/x/gov/keeper/keeper_test.go b/x/gov/keeper/keeper_test.go index 95daf0797e62..c064e3abd612 100644 --- a/x/gov/keeper/keeper_test.go +++ b/x/gov/keeper/keeper_test.go @@ -5,12 +5,13 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/baseapp" - "github.com/cosmos/cosmos-sdk/simapp" + "github.com/cosmos/cosmos-sdk/codec" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/gov/keeper" + govtestutil "github.com/cosmos/cosmos-sdk/x/gov/testutil" "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" @@ -20,8 +21,12 @@ import ( type KeeperTestSuite struct { suite.Suite - app *simapp.SimApp + cdc codec.Codec ctx sdk.Context + govKeeper *keeper.Keeper + acctKeeper *govtestutil.MockAccountKeeper + bankKeeper *govtestutil.MockBankKeeper + stakingKeeper *govtestutil.MockStakingKeeper queryClient v1.QueryClient legacyQueryClient v1beta1.QueryClient addrs []sdk.AccAddress @@ -29,79 +34,83 @@ type KeeperTestSuite struct { legacyMsgSrvr v1beta1.MsgServer } -func (suite *KeeperTestSuite) SetupTest() { - app := simapp.Setup(suite.T(), false) - ctx := app.BaseApp.NewContext(false, tmproto.Header{}) +func (suite *KeeperTestSuite) SetupSuite() { + suite.reset() +} + +func (suite *KeeperTestSuite) reset() { + govKeeper, acctKeeper, bankKeeper, stakingKeeper, encCfg, ctx := setupGovKeeper(suite.T()) // Populate the gov account with some coins, as the TestProposal we have // is a MsgSend from the gov account. coins := sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(100000))) - err := app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, coins) + err := bankKeeper.MintCoins(suite.ctx, minttypes.ModuleName, coins) suite.NoError(err) - err = app.BankKeeper.SendCoinsFromModuleToModule(ctx, minttypes.ModuleName, types.ModuleName, coins) + err = bankKeeper.SendCoinsFromModuleToModule(ctx, minttypes.ModuleName, types.ModuleName, coins) suite.NoError(err) - queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry()) - v1.RegisterQueryServer(queryHelper, app.GovKeeper) - legacyQueryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry()) - v1beta1.RegisterQueryServer(legacyQueryHelper, keeper.NewLegacyQueryServer(app.GovKeeper)) + queryHelper := baseapp.NewQueryServerTestHelper(ctx, encCfg.InterfaceRegistry) + v1.RegisterQueryServer(queryHelper, govKeeper) + legacyQueryHelper := baseapp.NewQueryServerTestHelper(ctx, encCfg.InterfaceRegistry) + v1beta1.RegisterQueryServer(legacyQueryHelper, keeper.NewLegacyQueryServer(govKeeper)) queryClient := v1.NewQueryClient(queryHelper) legacyQueryClient := v1beta1.NewQueryClient(legacyQueryHelper) - suite.app = app suite.ctx = ctx + suite.govKeeper = govKeeper + suite.acctKeeper = acctKeeper + suite.bankKeeper = bankKeeper + suite.stakingKeeper = stakingKeeper + suite.cdc = encCfg.Codec suite.queryClient = queryClient suite.legacyQueryClient = legacyQueryClient - suite.msgSrvr = keeper.NewMsgServerImpl(suite.app.GovKeeper) + suite.msgSrvr = keeper.NewMsgServerImpl(suite.govKeeper) - govAcct := suite.app.GovKeeper.GetGovernanceAccount(suite.ctx).GetAddress() suite.legacyMsgSrvr = keeper.NewLegacyMsgServerImpl(govAcct.String(), suite.msgSrvr) - suite.addrs = simapp.AddTestAddrsIncremental(app, ctx, 2, sdk.NewInt(30000000)) + suite.addrs = simtestutil.AddTestAddrsIncremental(bankKeeper, stakingKeeper, ctx, 3, sdk.NewInt(30000000)) } func TestIncrementProposalNumber(t *testing.T) { - app := simapp.Setup(t, false) - ctx := app.BaseApp.NewContext(false, tmproto.Header{}) + govKeeper, _, _, _, _, ctx := setupGovKeeper(t) tp := TestProposal - _, err := app.GovKeeper.SubmitProposal(ctx, tp, "") + _, err := govKeeper.SubmitProposal(ctx, tp, "") require.NoError(t, err) - _, err = app.GovKeeper.SubmitProposal(ctx, tp, "") + _, err = govKeeper.SubmitProposal(ctx, tp, "") require.NoError(t, err) - _, err = app.GovKeeper.SubmitProposal(ctx, tp, "") + _, err = govKeeper.SubmitProposal(ctx, tp, "") require.NoError(t, err) - _, err = app.GovKeeper.SubmitProposal(ctx, tp, "") + _, err = govKeeper.SubmitProposal(ctx, tp, "") require.NoError(t, err) - _, err = app.GovKeeper.SubmitProposal(ctx, tp, "") + _, err = govKeeper.SubmitProposal(ctx, tp, "") require.NoError(t, err) - proposal6, err := app.GovKeeper.SubmitProposal(ctx, tp, "") + proposal6, err := govKeeper.SubmitProposal(ctx, tp, "") require.NoError(t, err) require.Equal(t, uint64(6), proposal6.Id) } func TestProposalQueues(t *testing.T) { - app := simapp.Setup(t, false) - ctx := app.BaseApp.NewContext(false, tmproto.Header{}) + govKeeper, _, _, _, _, ctx := setupGovKeeper(t) // create test proposals tp := TestProposal - proposal, err := app.GovKeeper.SubmitProposal(ctx, tp, "") + proposal, err := govKeeper.SubmitProposal(ctx, tp, "") require.NoError(t, err) - inactiveIterator := app.GovKeeper.InactiveProposalQueueIterator(ctx, *proposal.DepositEndTime) + inactiveIterator := govKeeper.InactiveProposalQueueIterator(ctx, *proposal.DepositEndTime) require.True(t, inactiveIterator.Valid()) proposalID := types.GetProposalIDFromBytes(inactiveIterator.Value()) require.Equal(t, proposalID, proposal.Id) inactiveIterator.Close() - app.GovKeeper.ActivateVotingPeriod(ctx, proposal) + govKeeper.ActivateVotingPeriod(ctx, proposal) - proposal, ok := app.GovKeeper.GetProposal(ctx, proposal.Id) + proposal, ok := govKeeper.GetProposal(ctx, proposal.Id) require.True(t, ok) - activeIterator := app.GovKeeper.ActiveProposalQueueIterator(ctx, *proposal.VotingEndTime) + activeIterator := govKeeper.ActiveProposalQueueIterator(ctx, *proposal.VotingEndTime) require.True(t, activeIterator.Valid()) proposalID, _ = types.SplitActiveProposalQueueKey(activeIterator.Key()) diff --git a/x/gov/keeper/msg_server_test.go b/x/gov/keeper/msg_server_test.go index ee2ddb040f4c..db9d342da9ae 100644 --- a/x/gov/keeper/msg_server_test.go +++ b/x/gov/keeper/msg_server_test.go @@ -4,26 +4,23 @@ import ( "strings" "time" - "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" - "github.com/cosmos/cosmos-sdk/simapp" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" "github.com/cosmos/cosmos-sdk/testutil/testdata" 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" - "github.com/cosmos/cosmos-sdk/x/gov/keeper" v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" ) func (suite *KeeperTestSuite) TestSubmitProposalReq() { - govAcct := suite.app.GovKeeper.GetGovernanceAccount(suite.ctx).GetAddress() + suite.reset() + govAcct := suite.govKeeper.GetGovernanceAccount(suite.ctx).GetAddress() addrs := suite.addrs proposer := addrs[0] coins := sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(100))) initialDeposit := coins - minDeposit := suite.app.GovKeeper.GetParams(suite.ctx).MinDeposit + minDeposit := suite.govKeeper.GetParams(suite.ctx).MinDeposit bankMsg := &banktypes.MsgSend{ FromAddress: govAcct.String(), ToAddress: proposer.String(), @@ -124,12 +121,13 @@ func (suite *KeeperTestSuite) TestSubmitProposalReq() { } func (suite *KeeperTestSuite) TestVoteReq() { - govAcct := suite.app.GovKeeper.GetGovernanceAccount(suite.ctx).GetAddress() + suite.reset() + govAcct := suite.govKeeper.GetGovernanceAccount(suite.ctx).GetAddress() addrs := suite.addrs proposer := addrs[0] coins := sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(100))) - minDeposit := suite.app.GovKeeper.GetParams(suite.ctx).MinDeposit + minDeposit := suite.govKeeper.GetParams(suite.ctx).MinDeposit bankMsg := &banktypes.MsgSend{ FromAddress: govAcct.String(), ToAddress: proposer.String(), @@ -236,12 +234,13 @@ func (suite *KeeperTestSuite) TestVoteReq() { } func (suite *KeeperTestSuite) TestVoteWeightedReq() { - govAcct := suite.app.GovKeeper.GetGovernanceAccount(suite.ctx).GetAddress() + suite.reset() + govAcct := suite.govKeeper.GetGovernanceAccount(suite.ctx).GetAddress() addrs := suite.addrs proposer := addrs[0] coins := sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(100))) - minDeposit := suite.app.GovKeeper.GetParams(suite.ctx).MinDeposit + minDeposit := suite.govKeeper.GetParams(suite.ctx).MinDeposit bankMsg := &banktypes.MsgSend{ FromAddress: govAcct.String(), ToAddress: proposer.String(), @@ -349,12 +348,12 @@ func (suite *KeeperTestSuite) TestVoteWeightedReq() { } func (suite *KeeperTestSuite) TestDepositReq() { - govAcct := suite.app.GovKeeper.GetGovernanceAccount(suite.ctx).GetAddress() + govAcct := suite.govKeeper.GetGovernanceAccount(suite.ctx).GetAddress() addrs := suite.addrs proposer := addrs[0] coins := sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(100))) - minDeposit := suite.app.GovKeeper.GetParams(suite.ctx).MinDeposit + minDeposit := suite.govKeeper.GetParams(suite.ctx).MinDeposit bankMsg := &banktypes.MsgSend{ FromAddress: govAcct.String(), ToAddress: proposer.String(), @@ -423,7 +422,7 @@ func (suite *KeeperTestSuite) TestLegacyMsgSubmitProposal() { coins := sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(100))) initialDeposit := coins - minDeposit := suite.app.GovKeeper.GetParams(suite.ctx).MinDeposit + minDeposit := suite.govKeeper.GetParams(suite.ctx).MinDeposit cases := map[string]struct { preRun func() (*v1beta1.MsgSubmitProposal, error) @@ -467,12 +466,12 @@ func (suite *KeeperTestSuite) TestLegacyMsgSubmitProposal() { } func (suite *KeeperTestSuite) TestLegacyMsgVote() { - govAcct := suite.app.GovKeeper.GetGovernanceAccount(suite.ctx).GetAddress() + govAcct := suite.govKeeper.GetGovernanceAccount(suite.ctx).GetAddress() addrs := suite.addrs proposer := addrs[0] coins := sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(100))) - minDeposit := suite.app.GovKeeper.GetParams(suite.ctx).MinDeposit + minDeposit := suite.govKeeper.GetParams(suite.ctx).MinDeposit bankMsg := &banktypes.MsgSend{ FromAddress: govAcct.String(), ToAddress: proposer.String(), @@ -569,12 +568,13 @@ func (suite *KeeperTestSuite) TestLegacyMsgVote() { } func (suite *KeeperTestSuite) TestLegacyVoteWeighted() { - govAcct := suite.app.GovKeeper.GetGovernanceAccount(suite.ctx).GetAddress() + suite.reset() + govAcct := suite.govKeeper.GetGovernanceAccount(suite.ctx).GetAddress() addrs := suite.addrs proposer := addrs[0] coins := sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(100))) - minDeposit := suite.app.GovKeeper.GetParams(suite.ctx).MinDeposit + minDeposit := suite.govKeeper.GetParams(suite.ctx).MinDeposit bankMsg := &banktypes.MsgSend{ FromAddress: govAcct.String(), ToAddress: proposer.String(), @@ -672,12 +672,12 @@ func (suite *KeeperTestSuite) TestLegacyVoteWeighted() { } func (suite *KeeperTestSuite) TestLegacyMsgDeposit() { - govAcct := suite.app.GovKeeper.GetGovernanceAccount(suite.ctx).GetAddress() + govAcct := suite.govKeeper.GetGovernanceAccount(suite.ctx).GetAddress() addrs := suite.addrs proposer := addrs[0] coins := sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(100))) - minDeposit := suite.app.GovKeeper.GetParams(suite.ctx).MinDeposit + minDeposit := suite.govKeeper.GetParams(suite.ctx).MinDeposit bankMsg := &banktypes.MsgSend{ FromAddress: govAcct.String(), ToAddress: proposer.String(), @@ -740,7 +740,7 @@ func (suite *KeeperTestSuite) TestLegacyMsgDeposit() { } func (suite *KeeperTestSuite) TestMsgUpdateParams() { - authority := suite.app.GovKeeper.GetAuthority() + authority := suite.govKeeper.GetAuthority() params := v1.DefaultParams() testCases := []struct { name string @@ -1059,17 +1059,8 @@ func (suite *KeeperTestSuite) TestSubmitProposal_InitialDeposit() { for name, tc := range testcases { suite.Run(name, func() { // Setup - privateKey := secp256k1.GenPrivKey() - address := sdk.AccAddress(privateKey.PubKey().Address()) - acc := &authtypes.BaseAccount{ - Address: address.String(), - } - - genAccs := []authtypes.GenesisAccount{acc} - app := simapp.SetupWithGenesisAccounts(suite.T(), genAccs, banktypes.Balance{Address: acc.Address, Coins: tc.accountBalance}) - ctx := app.BaseApp.NewContext(false, tmproto.Header{}) - govKeeper := app.GovKeeper - msgServer := keeper.NewMsgServerImpl(govKeeper) + govKeeper, ctx := suite.govKeeper, suite.ctx + address := simtestutil.AddTestAddrs(suite.bankKeeper, suite.stakingKeeper, ctx, 1, tc.accountBalance[0].Amount)[0] params := v1.DefaultParams() params.MinDeposit = tc.minDeposit @@ -1080,7 +1071,7 @@ func (suite *KeeperTestSuite) TestSubmitProposal_InitialDeposit() { suite.Require().NoError(err) // System under test - _, err = msgServer.SubmitProposal(sdk.WrapSDKContext(ctx), msg) + _, err = suite.msgSrvr.SubmitProposal(sdk.WrapSDKContext(ctx), msg) // Assertions if tc.expectError { diff --git a/x/gov/keeper/proposal_test.go b/x/gov/keeper/proposal_test.go index e4de0c40fd0b..ce655d4aed24 100644 --- a/x/gov/keeper/proposal_test.go +++ b/x/gov/keeper/proposal_test.go @@ -18,30 +18,30 @@ import ( func (suite *KeeperTestSuite) TestGetSetProposal() { tp := TestProposal - proposal, err := suite.app.GovKeeper.SubmitProposal(suite.ctx, tp, "") + proposal, err := suite.govKeeper.SubmitProposal(suite.ctx, tp, "") suite.Require().NoError(err) proposalID := proposal.Id - suite.app.GovKeeper.SetProposal(suite.ctx, proposal) + suite.govKeeper.SetProposal(suite.ctx, proposal) - gotProposal, ok := suite.app.GovKeeper.GetProposal(suite.ctx, proposalID) + gotProposal, ok := suite.govKeeper.GetProposal(suite.ctx, proposalID) suite.Require().True(ok) suite.Require().Equal(proposal, gotProposal) } func (suite *KeeperTestSuite) TestActivateVotingPeriod() { tp := TestProposal - proposal, err := suite.app.GovKeeper.SubmitProposal(suite.ctx, tp, "") + proposal, err := suite.govKeeper.SubmitProposal(suite.ctx, tp, "") suite.Require().NoError(err) suite.Require().Nil(proposal.VotingStartTime) - suite.app.GovKeeper.ActivateVotingPeriod(suite.ctx, proposal) + suite.govKeeper.ActivateVotingPeriod(suite.ctx, proposal) - proposal, ok := suite.app.GovKeeper.GetProposal(suite.ctx, proposal.Id) + proposal, ok := suite.govKeeper.GetProposal(suite.ctx, proposal.Id) suite.Require().True(ok) suite.Require().True(proposal.VotingStartTime.Equal(suite.ctx.BlockHeader().Time)) - activeIterator := suite.app.GovKeeper.ActiveProposalQueueIterator(suite.ctx, *proposal.VotingEndTime) + activeIterator := suite.govKeeper.ActiveProposalQueueIterator(suite.ctx, *proposal.VotingEndTime) suite.Require().True(activeIterator.Valid()) proposalID := types.GetProposalIDFromBytes(activeIterator.Value()) @@ -54,7 +54,7 @@ type invalidProposalRoute struct{ v1beta1.TextProposal } func (invalidProposalRoute) ProposalRoute() string { return "nonexistingroute" } func (suite *KeeperTestSuite) TestSubmitProposal() { - govAcct := suite.app.GovKeeper.GetGovernanceAccount(suite.ctx).GetAddress().String() + govAcct := suite.govKeeper.GetGovernanceAccount(suite.ctx).GetAddress().String() _, _, randomAddr := testdata.KeyTestPubAddr() tp := v1beta1.TextProposal{Title: "title", Description: "description"} @@ -81,7 +81,7 @@ func (suite *KeeperTestSuite) TestSubmitProposal() { for i, tc := range testCases { prop, err := v1.NewLegacyContent(tc.content, tc.authority) suite.Require().NoError(err) - _, err = suite.app.GovKeeper.SubmitProposal(suite.ctx, []sdk.Msg{prop}, tc.metadata) + _, err = suite.govKeeper.SubmitProposal(suite.ctx, []sdk.Msg{prop}, tc.metadata) suite.Require().True(errors.Is(tc.expectedErr, err), "tc #%d; got: %v, expected: %v", i, err, tc.expectedErr) } } @@ -102,11 +102,11 @@ func (suite *KeeperTestSuite) TestGetProposalsFiltered() { if i%2 == 0 { d := v1.NewDeposit(proposalID, addr1, nil) v := v1.NewVote(proposalID, addr1, v1.NewNonSplitVoteOption(v1.OptionYes), "") - suite.app.GovKeeper.SetDeposit(suite.ctx, d) - suite.app.GovKeeper.SetVote(suite.ctx, v) + suite.govKeeper.SetDeposit(suite.ctx, d) + suite.govKeeper.SetVote(suite.ctx, v) } - suite.app.GovKeeper.SetProposal(suite.ctx, p) + suite.govKeeper.SetProposal(suite.ctx, p) proposalID++ } } @@ -131,7 +131,7 @@ func (suite *KeeperTestSuite) TestGetProposalsFiltered() { for i, tc := range testCases { suite.Run(fmt.Sprintf("Test Case %d", i), func() { - proposals := suite.app.GovKeeper.GetProposalsFiltered(suite.ctx, tc.params) + proposals := suite.govKeeper.GetProposalsFiltered(suite.ctx, tc.params) suite.Require().Len(proposals, tc.expectedNumResults) for _, p := range proposals { diff --git a/x/gov/keeper/vote_test.go b/x/gov/keeper/vote_test.go index a1723c0f45b5..10720045dc7e 100644 --- a/x/gov/keeper/vote_test.go +++ b/x/gov/keeper/vote_test.go @@ -4,38 +4,35 @@ import ( "testing" "github.com/stretchr/testify/require" - 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" v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" ) func TestVotes(t *testing.T) { - app := simapp.Setup(t, false) - ctx := app.BaseApp.NewContext(false, tmproto.Header{}) - - addrs := simapp.AddTestAddrsIncremental(app, ctx, 5, sdk.NewInt(30000000)) + govKeeper, _, bankKeeper, stakingKeeper, _, ctx := setupGovKeeper(t) + addrs := simtestutil.AddTestAddrsIncremental(bankKeeper, stakingKeeper, ctx, 2, sdk.NewInt(10000000)) tp := TestProposal - proposal, err := app.GovKeeper.SubmitProposal(ctx, tp, "") + proposal, err := govKeeper.SubmitProposal(ctx, tp, "") require.NoError(t, err) proposalID := proposal.Id metadata := "metadata" var invalidOption v1.VoteOption = 0x10 - require.Error(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[0], v1.NewNonSplitVoteOption(v1.OptionYes), metadata), "proposal not on voting period") - require.Error(t, app.GovKeeper.AddVote(ctx, 10, addrs[0], v1.NewNonSplitVoteOption(v1.OptionYes), ""), "invalid proposal ID") + require.Error(t, govKeeper.AddVote(ctx, proposalID, addrs[0], v1.NewNonSplitVoteOption(v1.OptionYes), metadata), "proposal not on voting period") + require.Error(t, govKeeper.AddVote(ctx, 10, addrs[0], v1.NewNonSplitVoteOption(v1.OptionYes), ""), "invalid proposal ID") proposal.Status = v1.StatusVotingPeriod - app.GovKeeper.SetProposal(ctx, proposal) + govKeeper.SetProposal(ctx, proposal) - require.Error(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[0], v1.NewNonSplitVoteOption(invalidOption), ""), "invalid option") + require.Error(t, govKeeper.AddVote(ctx, proposalID, addrs[0], v1.NewNonSplitVoteOption(invalidOption), ""), "invalid option") // Test first vote - require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[0], v1.NewNonSplitVoteOption(v1.OptionAbstain), metadata)) - vote, found := app.GovKeeper.GetVote(ctx, proposalID, addrs[0]) + require.NoError(t, govKeeper.AddVote(ctx, proposalID, addrs[0], v1.NewNonSplitVoteOption(v1.OptionAbstain), metadata)) + vote, found := govKeeper.GetVote(ctx, proposalID, addrs[0]) require.True(t, found) require.Equal(t, addrs[0].String(), vote.Voter) require.Equal(t, proposalID, vote.ProposalId) @@ -43,8 +40,8 @@ func TestVotes(t *testing.T) { require.Equal(t, v1.OptionAbstain, vote.Options[0].Option) // Test change of vote - require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[0], v1.NewNonSplitVoteOption(v1.OptionYes), "")) - vote, found = app.GovKeeper.GetVote(ctx, proposalID, addrs[0]) + require.NoError(t, govKeeper.AddVote(ctx, proposalID, addrs[0], v1.NewNonSplitVoteOption(v1.OptionYes), "")) + vote, found = govKeeper.GetVote(ctx, proposalID, addrs[0]) require.True(t, found) require.Equal(t, addrs[0].String(), vote.Voter) require.Equal(t, proposalID, vote.ProposalId) @@ -52,13 +49,13 @@ func TestVotes(t *testing.T) { require.Equal(t, v1.OptionYes, vote.Options[0].Option) // Test second vote - require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[1], v1.WeightedVoteOptions{ + require.NoError(t, govKeeper.AddVote(ctx, proposalID, addrs[1], v1.WeightedVoteOptions{ v1.NewWeightedVoteOption(v1.OptionYes, sdk.NewDecWithPrec(60, 2)), v1.NewWeightedVoteOption(v1.OptionNo, sdk.NewDecWithPrec(30, 2)), v1.NewWeightedVoteOption(v1.OptionAbstain, sdk.NewDecWithPrec(5, 2)), v1.NewWeightedVoteOption(v1.OptionNoWithVeto, sdk.NewDecWithPrec(5, 2)), }, "")) - vote, found = app.GovKeeper.GetVote(ctx, proposalID, addrs[1]) + vote, found = govKeeper.GetVote(ctx, proposalID, addrs[1]) require.True(t, found) require.Equal(t, addrs[1].String(), vote.Voter) require.Equal(t, proposalID, vote.ProposalId) @@ -74,9 +71,9 @@ func TestVotes(t *testing.T) { // Test vote iterator // NOTE order of deposits is determined by the addresses - votes := app.GovKeeper.GetAllVotes(ctx) + votes := govKeeper.GetAllVotes(ctx) require.Len(t, votes, 2) - require.Equal(t, votes, app.GovKeeper.GetVotes(ctx, proposalID)) + require.Equal(t, votes, govKeeper.GetVotes(ctx, proposalID)) require.Equal(t, addrs[0].String(), votes[0].Voter) require.Equal(t, proposalID, votes[0].ProposalId) require.True(t, len(votes[0].Options) == 1) diff --git a/x/gov/testutil/expected_keepers.go b/x/gov/testutil/expected_keepers.go new file mode 100644 index 000000000000..669dbc010b2d --- /dev/null +++ b/x/gov/testutil/expected_keepers.go @@ -0,0 +1,35 @@ +// This file only used to generate mocks + +package testutil + +import ( + math "cosmossdk.io/math" + + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + "github.com/cosmos/cosmos-sdk/x/gov/types" +) + +// AccountKeeper extends gov's actual expected AccountKeeper with additional +// methods used in tests. +type AccountKeeper interface { + types.AccountKeeper + + IterateAccounts(ctx sdk.Context, cb func(account authtypes.AccountI) (stop bool)) +} + +// BankKeeper extends gov's actual expected BankKeeper with additional +// methods used in tests. +type BankKeeper interface { + bankkeeper.Keeper +} + +// StakingKeeper extends gov's actual expected StakingKeeper with additional +// methods used in tests. +type StakingKeeper interface { + types.StakingKeeper + + BondDenom(ctx sdk.Context) string + TokensFromConsensusPower(ctx sdk.Context, power int64) math.Int +} diff --git a/x/gov/testutil/expected_keepers_mocks.go b/x/gov/testutil/expected_keepers_mocks.go new file mode 100644 index 000000000000..9fc3d2769f27 --- /dev/null +++ b/x/gov/testutil/expected_keepers_mocks.go @@ -0,0 +1,1003 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: x/gov/testutil/expected_keepers.go + +// Package testutil is a generated GoMock package. +package testutil + +import ( + context "context" + reflect "reflect" + + math "cosmossdk.io/math" + types "github.com/cosmos/cosmos-sdk/types" + query "github.com/cosmos/cosmos-sdk/types/query" + types0 "github.com/cosmos/cosmos-sdk/x/auth/types" + keeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + types1 "github.com/cosmos/cosmos-sdk/x/bank/types" + types2 "github.com/cosmos/cosmos-sdk/x/staking/types" + gomock "github.com/golang/mock/gomock" +) + +// MockAccountKeeper is a mock of AccountKeeper interface. +type MockAccountKeeper struct { + ctrl *gomock.Controller + recorder *MockAccountKeeperMockRecorder +} + +// MockAccountKeeperMockRecorder is the mock recorder for MockAccountKeeper. +type MockAccountKeeperMockRecorder struct { + mock *MockAccountKeeper +} + +// NewMockAccountKeeper creates a new mock instance. +func NewMockAccountKeeper(ctrl *gomock.Controller) *MockAccountKeeper { + mock := &MockAccountKeeper{ctrl: ctrl} + mock.recorder = &MockAccountKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockAccountKeeper) EXPECT() *MockAccountKeeperMockRecorder { + return m.recorder +} + +// GetAccount mocks base method. +func (m *MockAccountKeeper) GetAccount(ctx types.Context, addr types.AccAddress) types0.AccountI { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAccount", ctx, addr) + ret0, _ := ret[0].(types0.AccountI) + return ret0 +} + +// GetAccount indicates an expected call of GetAccount. +func (mr *MockAccountKeeperMockRecorder) GetAccount(ctx, addr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAccount", reflect.TypeOf((*MockAccountKeeper)(nil).GetAccount), ctx, addr) +} + +// GetModuleAccount mocks base method. +func (m *MockAccountKeeper) GetModuleAccount(ctx types.Context, name string) types0.ModuleAccountI { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetModuleAccount", ctx, name) + ret0, _ := ret[0].(types0.ModuleAccountI) + return ret0 +} + +// GetModuleAccount indicates an expected call of GetModuleAccount. +func (mr *MockAccountKeeperMockRecorder) GetModuleAccount(ctx, name interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetModuleAccount", reflect.TypeOf((*MockAccountKeeper)(nil).GetModuleAccount), ctx, name) +} + +// GetModuleAddress mocks base method. +func (m *MockAccountKeeper) GetModuleAddress(name string) types.AccAddress { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetModuleAddress", name) + ret0, _ := ret[0].(types.AccAddress) + return ret0 +} + +// GetModuleAddress indicates an expected call of GetModuleAddress. +func (mr *MockAccountKeeperMockRecorder) GetModuleAddress(name interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetModuleAddress", reflect.TypeOf((*MockAccountKeeper)(nil).GetModuleAddress), name) +} + +// IterateAccounts mocks base method. +func (m *MockAccountKeeper) IterateAccounts(ctx types.Context, cb func(types0.AccountI) bool) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "IterateAccounts", ctx, cb) +} + +// IterateAccounts indicates an expected call of IterateAccounts. +func (mr *MockAccountKeeperMockRecorder) IterateAccounts(ctx, cb interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IterateAccounts", reflect.TypeOf((*MockAccountKeeper)(nil).IterateAccounts), ctx, cb) +} + +// SetModuleAccount mocks base method. +func (m *MockAccountKeeper) SetModuleAccount(arg0 types.Context, arg1 types0.ModuleAccountI) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "SetModuleAccount", arg0, arg1) +} + +// SetModuleAccount indicates an expected call of SetModuleAccount. +func (mr *MockAccountKeeperMockRecorder) SetModuleAccount(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetModuleAccount", reflect.TypeOf((*MockAccountKeeper)(nil).SetModuleAccount), arg0, arg1) +} + +// MockBankKeeper is a mock of BankKeeper interface. +type MockBankKeeper struct { + ctrl *gomock.Controller + recorder *MockBankKeeperMockRecorder +} + +// MockBankKeeperMockRecorder is the mock recorder for MockBankKeeper. +type MockBankKeeperMockRecorder struct { + mock *MockBankKeeper +} + +// NewMockBankKeeper creates a new mock instance. +func NewMockBankKeeper(ctrl *gomock.Controller) *MockBankKeeper { + mock := &MockBankKeeper{ctrl: ctrl} + mock.recorder = &MockBankKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockBankKeeper) EXPECT() *MockBankKeeperMockRecorder { + return m.recorder +} + +// AllBalances mocks base method. +func (m *MockBankKeeper) AllBalances(arg0 context.Context, arg1 *types1.QueryAllBalancesRequest) (*types1.QueryAllBalancesResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AllBalances", arg0, arg1) + ret0, _ := ret[0].(*types1.QueryAllBalancesResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// AllBalances indicates an expected call of AllBalances. +func (mr *MockBankKeeperMockRecorder) AllBalances(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AllBalances", reflect.TypeOf((*MockBankKeeper)(nil).AllBalances), arg0, arg1) +} + +// Balance mocks base method. +func (m *MockBankKeeper) Balance(arg0 context.Context, arg1 *types1.QueryBalanceRequest) (*types1.QueryBalanceResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Balance", arg0, arg1) + ret0, _ := ret[0].(*types1.QueryBalanceResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Balance indicates an expected call of Balance. +func (mr *MockBankKeeperMockRecorder) Balance(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Balance", reflect.TypeOf((*MockBankKeeper)(nil).Balance), arg0, arg1) +} + +// BlockedAddr mocks base method. +func (m *MockBankKeeper) BlockedAddr(addr types.AccAddress) bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "BlockedAddr", addr) + ret0, _ := ret[0].(bool) + return ret0 +} + +// BlockedAddr indicates an expected call of BlockedAddr. +func (mr *MockBankKeeperMockRecorder) BlockedAddr(addr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BlockedAddr", reflect.TypeOf((*MockBankKeeper)(nil).BlockedAddr), addr) +} + +// BurnCoins mocks base method. +func (m *MockBankKeeper) BurnCoins(ctx types.Context, moduleName string, amt types.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "BurnCoins", ctx, moduleName, amt) + ret0, _ := ret[0].(error) + return ret0 +} + +// BurnCoins indicates an expected call of BurnCoins. +func (mr *MockBankKeeperMockRecorder) BurnCoins(ctx, moduleName, amt interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BurnCoins", reflect.TypeOf((*MockBankKeeper)(nil).BurnCoins), ctx, moduleName, amt) +} + +// DelegateCoins mocks base method. +func (m *MockBankKeeper) DelegateCoins(ctx types.Context, delegatorAddr, moduleAccAddr types.AccAddress, amt types.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DelegateCoins", ctx, delegatorAddr, moduleAccAddr, amt) + ret0, _ := ret[0].(error) + return ret0 +} + +// DelegateCoins indicates an expected call of DelegateCoins. +func (mr *MockBankKeeperMockRecorder) DelegateCoins(ctx, delegatorAddr, moduleAccAddr, amt interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DelegateCoins", reflect.TypeOf((*MockBankKeeper)(nil).DelegateCoins), ctx, delegatorAddr, moduleAccAddr, amt) +} + +// DelegateCoinsFromAccountToModule mocks base method. +func (m *MockBankKeeper) DelegateCoinsFromAccountToModule(ctx types.Context, senderAddr types.AccAddress, recipientModule string, amt types.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DelegateCoinsFromAccountToModule", ctx, senderAddr, recipientModule, amt) + ret0, _ := ret[0].(error) + return ret0 +} + +// DelegateCoinsFromAccountToModule indicates an expected call of DelegateCoinsFromAccountToModule. +func (mr *MockBankKeeperMockRecorder) DelegateCoinsFromAccountToModule(ctx, senderAddr, recipientModule, amt interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DelegateCoinsFromAccountToModule", reflect.TypeOf((*MockBankKeeper)(nil).DelegateCoinsFromAccountToModule), ctx, senderAddr, recipientModule, amt) +} + +// DeleteSendEnabled mocks base method. +func (m *MockBankKeeper) DeleteSendEnabled(ctx types.Context, denom string) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "DeleteSendEnabled", ctx, denom) +} + +// DeleteSendEnabled indicates an expected call of DeleteSendEnabled. +func (mr *MockBankKeeperMockRecorder) DeleteSendEnabled(ctx, denom interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteSendEnabled", reflect.TypeOf((*MockBankKeeper)(nil).DeleteSendEnabled), ctx, denom) +} + +// DenomMetadata mocks base method. +func (m *MockBankKeeper) DenomMetadata(arg0 context.Context, arg1 *types1.QueryDenomMetadataRequest) (*types1.QueryDenomMetadataResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DenomMetadata", arg0, arg1) + ret0, _ := ret[0].(*types1.QueryDenomMetadataResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// DenomMetadata indicates an expected call of DenomMetadata. +func (mr *MockBankKeeperMockRecorder) DenomMetadata(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DenomMetadata", reflect.TypeOf((*MockBankKeeper)(nil).DenomMetadata), arg0, arg1) +} + +// DenomOwners mocks base method. +func (m *MockBankKeeper) DenomOwners(arg0 context.Context, arg1 *types1.QueryDenomOwnersRequest) (*types1.QueryDenomOwnersResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DenomOwners", arg0, arg1) + ret0, _ := ret[0].(*types1.QueryDenomOwnersResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// DenomOwners indicates an expected call of DenomOwners. +func (mr *MockBankKeeperMockRecorder) DenomOwners(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DenomOwners", reflect.TypeOf((*MockBankKeeper)(nil).DenomOwners), arg0, arg1) +} + +// DenomsMetadata mocks base method. +func (m *MockBankKeeper) DenomsMetadata(arg0 context.Context, arg1 *types1.QueryDenomsMetadataRequest) (*types1.QueryDenomsMetadataResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DenomsMetadata", arg0, arg1) + ret0, _ := ret[0].(*types1.QueryDenomsMetadataResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// DenomsMetadata indicates an expected call of DenomsMetadata. +func (mr *MockBankKeeperMockRecorder) DenomsMetadata(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DenomsMetadata", reflect.TypeOf((*MockBankKeeper)(nil).DenomsMetadata), arg0, arg1) +} + +// ExportGenesis mocks base method. +func (m *MockBankKeeper) ExportGenesis(arg0 types.Context) *types1.GenesisState { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ExportGenesis", arg0) + ret0, _ := ret[0].(*types1.GenesisState) + return ret0 +} + +// ExportGenesis indicates an expected call of ExportGenesis. +func (mr *MockBankKeeperMockRecorder) ExportGenesis(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExportGenesis", reflect.TypeOf((*MockBankKeeper)(nil).ExportGenesis), arg0) +} + +// GetAccountsBalances mocks base method. +func (m *MockBankKeeper) GetAccountsBalances(ctx types.Context) []types1.Balance { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAccountsBalances", ctx) + ret0, _ := ret[0].([]types1.Balance) + return ret0 +} + +// GetAccountsBalances indicates an expected call of GetAccountsBalances. +func (mr *MockBankKeeperMockRecorder) GetAccountsBalances(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAccountsBalances", reflect.TypeOf((*MockBankKeeper)(nil).GetAccountsBalances), ctx) +} + +// GetAllBalances mocks base method. +func (m *MockBankKeeper) GetAllBalances(ctx types.Context, addr types.AccAddress) types.Coins { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAllBalances", ctx, addr) + ret0, _ := ret[0].(types.Coins) + return ret0 +} + +// GetAllBalances indicates an expected call of GetAllBalances. +func (mr *MockBankKeeperMockRecorder) GetAllBalances(ctx, addr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAllBalances", reflect.TypeOf((*MockBankKeeper)(nil).GetAllBalances), ctx, addr) +} + +// GetAllSendEnabledEntries mocks base method. +func (m *MockBankKeeper) GetAllSendEnabledEntries(ctx types.Context) []types1.SendEnabled { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAllSendEnabledEntries", ctx) + ret0, _ := ret[0].([]types1.SendEnabled) + return ret0 +} + +// GetAllSendEnabledEntries indicates an expected call of GetAllSendEnabledEntries. +func (mr *MockBankKeeperMockRecorder) GetAllSendEnabledEntries(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAllSendEnabledEntries", reflect.TypeOf((*MockBankKeeper)(nil).GetAllSendEnabledEntries), ctx) +} + +// GetAuthority mocks base method. +func (m *MockBankKeeper) GetAuthority() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAuthority") + ret0, _ := ret[0].(string) + return ret0 +} + +// GetAuthority indicates an expected call of GetAuthority. +func (mr *MockBankKeeperMockRecorder) GetAuthority() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAuthority", reflect.TypeOf((*MockBankKeeper)(nil).GetAuthority)) +} + +// GetBalance mocks base method. +func (m *MockBankKeeper) GetBalance(ctx types.Context, addr types.AccAddress, denom string) types.Coin { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetBalance", ctx, addr, denom) + ret0, _ := ret[0].(types.Coin) + return ret0 +} + +// GetBalance indicates an expected call of GetBalance. +func (mr *MockBankKeeperMockRecorder) GetBalance(ctx, addr, denom interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBalance", reflect.TypeOf((*MockBankKeeper)(nil).GetBalance), ctx, addr, denom) +} + +// GetBlockedAddresses mocks base method. +func (m *MockBankKeeper) GetBlockedAddresses() map[string]bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetBlockedAddresses") + ret0, _ := ret[0].(map[string]bool) + return ret0 +} + +// GetBlockedAddresses indicates an expected call of GetBlockedAddresses. +func (mr *MockBankKeeperMockRecorder) GetBlockedAddresses() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBlockedAddresses", reflect.TypeOf((*MockBankKeeper)(nil).GetBlockedAddresses)) +} + +// GetDenomMetaData mocks base method. +func (m *MockBankKeeper) GetDenomMetaData(ctx types.Context, denom string) (types1.Metadata, bool) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetDenomMetaData", ctx, denom) + ret0, _ := ret[0].(types1.Metadata) + ret1, _ := ret[1].(bool) + return ret0, ret1 +} + +// GetDenomMetaData indicates an expected call of GetDenomMetaData. +func (mr *MockBankKeeperMockRecorder) GetDenomMetaData(ctx, denom interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetDenomMetaData", reflect.TypeOf((*MockBankKeeper)(nil).GetDenomMetaData), ctx, denom) +} + +// GetPaginatedTotalSupply mocks base method. +func (m *MockBankKeeper) GetPaginatedTotalSupply(ctx types.Context, pagination *query.PageRequest) (types.Coins, *query.PageResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetPaginatedTotalSupply", ctx, pagination) + ret0, _ := ret[0].(types.Coins) + ret1, _ := ret[1].(*query.PageResponse) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// GetPaginatedTotalSupply indicates an expected call of GetPaginatedTotalSupply. +func (mr *MockBankKeeperMockRecorder) GetPaginatedTotalSupply(ctx, pagination interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPaginatedTotalSupply", reflect.TypeOf((*MockBankKeeper)(nil).GetPaginatedTotalSupply), ctx, pagination) +} + +// GetParams mocks base method. +func (m *MockBankKeeper) GetParams(ctx types.Context) types1.Params { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetParams", ctx) + ret0, _ := ret[0].(types1.Params) + return ret0 +} + +// GetParams indicates an expected call of GetParams. +func (mr *MockBankKeeperMockRecorder) GetParams(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetParams", reflect.TypeOf((*MockBankKeeper)(nil).GetParams), ctx) +} + +// GetSendEnabledEntry mocks base method. +func (m *MockBankKeeper) GetSendEnabledEntry(ctx types.Context, denom string) (types1.SendEnabled, bool) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetSendEnabledEntry", ctx, denom) + ret0, _ := ret[0].(types1.SendEnabled) + ret1, _ := ret[1].(bool) + return ret0, ret1 +} + +// GetSendEnabledEntry indicates an expected call of GetSendEnabledEntry. +func (mr *MockBankKeeperMockRecorder) GetSendEnabledEntry(ctx, denom interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSendEnabledEntry", reflect.TypeOf((*MockBankKeeper)(nil).GetSendEnabledEntry), ctx, denom) +} + +// GetSupply mocks base method. +func (m *MockBankKeeper) GetSupply(ctx types.Context, denom string) types.Coin { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetSupply", ctx, denom) + ret0, _ := ret[0].(types.Coin) + return ret0 +} + +// GetSupply indicates an expected call of GetSupply. +func (mr *MockBankKeeperMockRecorder) GetSupply(ctx, denom interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSupply", reflect.TypeOf((*MockBankKeeper)(nil).GetSupply), ctx, denom) +} + +// HasBalance mocks base method. +func (m *MockBankKeeper) HasBalance(ctx types.Context, addr types.AccAddress, amt types.Coin) bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "HasBalance", ctx, addr, amt) + ret0, _ := ret[0].(bool) + return ret0 +} + +// HasBalance indicates an expected call of HasBalance. +func (mr *MockBankKeeperMockRecorder) HasBalance(ctx, addr, amt interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasBalance", reflect.TypeOf((*MockBankKeeper)(nil).HasBalance), ctx, addr, amt) +} + +// HasDenomMetaData mocks base method. +func (m *MockBankKeeper) HasDenomMetaData(ctx types.Context, denom string) bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "HasDenomMetaData", ctx, denom) + ret0, _ := ret[0].(bool) + return ret0 +} + +// HasDenomMetaData indicates an expected call of HasDenomMetaData. +func (mr *MockBankKeeperMockRecorder) HasDenomMetaData(ctx, denom interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasDenomMetaData", reflect.TypeOf((*MockBankKeeper)(nil).HasDenomMetaData), ctx, denom) +} + +// HasSupply mocks base method. +func (m *MockBankKeeper) HasSupply(ctx types.Context, denom string) bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "HasSupply", ctx, denom) + ret0, _ := ret[0].(bool) + return ret0 +} + +// HasSupply indicates an expected call of HasSupply. +func (mr *MockBankKeeperMockRecorder) HasSupply(ctx, denom interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasSupply", reflect.TypeOf((*MockBankKeeper)(nil).HasSupply), ctx, denom) +} + +// InitGenesis mocks base method. +func (m *MockBankKeeper) InitGenesis(arg0 types.Context, arg1 *types1.GenesisState) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "InitGenesis", arg0, arg1) +} + +// InitGenesis indicates an expected call of InitGenesis. +func (mr *MockBankKeeperMockRecorder) InitGenesis(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InitGenesis", reflect.TypeOf((*MockBankKeeper)(nil).InitGenesis), arg0, arg1) +} + +// InputOutputCoins mocks base method. +func (m *MockBankKeeper) InputOutputCoins(ctx types.Context, inputs []types1.Input, outputs []types1.Output) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "InputOutputCoins", ctx, inputs, outputs) + ret0, _ := ret[0].(error) + return ret0 +} + +// InputOutputCoins indicates an expected call of InputOutputCoins. +func (mr *MockBankKeeperMockRecorder) InputOutputCoins(ctx, inputs, outputs interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InputOutputCoins", reflect.TypeOf((*MockBankKeeper)(nil).InputOutputCoins), ctx, inputs, outputs) +} + +// IsSendEnabledCoin mocks base method. +func (m *MockBankKeeper) IsSendEnabledCoin(ctx types.Context, coin types.Coin) bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsSendEnabledCoin", ctx, coin) + ret0, _ := ret[0].(bool) + return ret0 +} + +// IsSendEnabledCoin indicates an expected call of IsSendEnabledCoin. +func (mr *MockBankKeeperMockRecorder) IsSendEnabledCoin(ctx, coin interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsSendEnabledCoin", reflect.TypeOf((*MockBankKeeper)(nil).IsSendEnabledCoin), ctx, coin) +} + +// IsSendEnabledCoins mocks base method. +func (m *MockBankKeeper) IsSendEnabledCoins(ctx types.Context, coins ...types.Coin) error { + m.ctrl.T.Helper() + varargs := []interface{}{ctx} + for _, a := range coins { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "IsSendEnabledCoins", varargs...) + ret0, _ := ret[0].(error) + return ret0 +} + +// IsSendEnabledCoins indicates an expected call of IsSendEnabledCoins. +func (mr *MockBankKeeperMockRecorder) IsSendEnabledCoins(ctx interface{}, coins ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx}, coins...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsSendEnabledCoins", reflect.TypeOf((*MockBankKeeper)(nil).IsSendEnabledCoins), varargs...) +} + +// IsSendEnabledDenom mocks base method. +func (m *MockBankKeeper) IsSendEnabledDenom(ctx types.Context, denom string) bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsSendEnabledDenom", ctx, denom) + ret0, _ := ret[0].(bool) + return ret0 +} + +// IsSendEnabledDenom indicates an expected call of IsSendEnabledDenom. +func (mr *MockBankKeeperMockRecorder) IsSendEnabledDenom(ctx, denom interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsSendEnabledDenom", reflect.TypeOf((*MockBankKeeper)(nil).IsSendEnabledDenom), ctx, denom) +} + +// IterateAccountBalances mocks base method. +func (m *MockBankKeeper) IterateAccountBalances(ctx types.Context, addr types.AccAddress, cb func(types.Coin) bool) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "IterateAccountBalances", ctx, addr, cb) +} + +// IterateAccountBalances indicates an expected call of IterateAccountBalances. +func (mr *MockBankKeeperMockRecorder) IterateAccountBalances(ctx, addr, cb interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IterateAccountBalances", reflect.TypeOf((*MockBankKeeper)(nil).IterateAccountBalances), ctx, addr, cb) +} + +// IterateAllBalances mocks base method. +func (m *MockBankKeeper) IterateAllBalances(ctx types.Context, cb func(types.AccAddress, types.Coin) bool) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "IterateAllBalances", ctx, cb) +} + +// IterateAllBalances indicates an expected call of IterateAllBalances. +func (mr *MockBankKeeperMockRecorder) IterateAllBalances(ctx, cb interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IterateAllBalances", reflect.TypeOf((*MockBankKeeper)(nil).IterateAllBalances), ctx, cb) +} + +// IterateAllDenomMetaData mocks base method. +func (m *MockBankKeeper) IterateAllDenomMetaData(ctx types.Context, cb func(types1.Metadata) bool) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "IterateAllDenomMetaData", ctx, cb) +} + +// IterateAllDenomMetaData indicates an expected call of IterateAllDenomMetaData. +func (mr *MockBankKeeperMockRecorder) IterateAllDenomMetaData(ctx, cb interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IterateAllDenomMetaData", reflect.TypeOf((*MockBankKeeper)(nil).IterateAllDenomMetaData), ctx, cb) +} + +// IterateSendEnabledEntries mocks base method. +func (m *MockBankKeeper) IterateSendEnabledEntries(ctx types.Context, cb func(string, bool) bool) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "IterateSendEnabledEntries", ctx, cb) +} + +// IterateSendEnabledEntries indicates an expected call of IterateSendEnabledEntries. +func (mr *MockBankKeeperMockRecorder) IterateSendEnabledEntries(ctx, cb interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IterateSendEnabledEntries", reflect.TypeOf((*MockBankKeeper)(nil).IterateSendEnabledEntries), ctx, cb) +} + +// IterateTotalSupply mocks base method. +func (m *MockBankKeeper) IterateTotalSupply(ctx types.Context, cb func(types.Coin) bool) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "IterateTotalSupply", ctx, cb) +} + +// IterateTotalSupply indicates an expected call of IterateTotalSupply. +func (mr *MockBankKeeperMockRecorder) IterateTotalSupply(ctx, cb interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IterateTotalSupply", reflect.TypeOf((*MockBankKeeper)(nil).IterateTotalSupply), ctx, cb) +} + +// LockedCoins mocks base method. +func (m *MockBankKeeper) LockedCoins(ctx types.Context, addr types.AccAddress) types.Coins { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LockedCoins", ctx, addr) + ret0, _ := ret[0].(types.Coins) + return ret0 +} + +// LockedCoins indicates an expected call of LockedCoins. +func (mr *MockBankKeeperMockRecorder) LockedCoins(ctx, addr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LockedCoins", reflect.TypeOf((*MockBankKeeper)(nil).LockedCoins), ctx, addr) +} + +// MintCoins mocks base method. +func (m *MockBankKeeper) MintCoins(ctx types.Context, moduleName string, amt types.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "MintCoins", ctx, moduleName, amt) + ret0, _ := ret[0].(error) + return ret0 +} + +// MintCoins indicates an expected call of MintCoins. +func (mr *MockBankKeeperMockRecorder) MintCoins(ctx, moduleName, amt interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MintCoins", reflect.TypeOf((*MockBankKeeper)(nil).MintCoins), ctx, moduleName, amt) +} + +// Params mocks base method. +func (m *MockBankKeeper) Params(arg0 context.Context, arg1 *types1.QueryParamsRequest) (*types1.QueryParamsResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Params", arg0, arg1) + ret0, _ := ret[0].(*types1.QueryParamsResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Params indicates an expected call of Params. +func (mr *MockBankKeeperMockRecorder) Params(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Params", reflect.TypeOf((*MockBankKeeper)(nil).Params), arg0, arg1) +} + +// SendCoins mocks base method. +func (m *MockBankKeeper) SendCoins(ctx types.Context, fromAddr, toAddr types.AccAddress, amt types.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SendCoins", ctx, fromAddr, toAddr, amt) + ret0, _ := ret[0].(error) + return ret0 +} + +// SendCoins indicates an expected call of SendCoins. +func (mr *MockBankKeeperMockRecorder) SendCoins(ctx, fromAddr, toAddr, amt interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCoins", reflect.TypeOf((*MockBankKeeper)(nil).SendCoins), ctx, fromAddr, toAddr, amt) +} + +// SendCoinsFromAccountToModule mocks base method. +func (m *MockBankKeeper) SendCoinsFromAccountToModule(ctx types.Context, senderAddr types.AccAddress, recipientModule string, amt types.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SendCoinsFromAccountToModule", ctx, senderAddr, recipientModule, amt) + ret0, _ := ret[0].(error) + return ret0 +} + +// SendCoinsFromAccountToModule indicates an expected call of SendCoinsFromAccountToModule. +func (mr *MockBankKeeperMockRecorder) SendCoinsFromAccountToModule(ctx, senderAddr, recipientModule, amt interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCoinsFromAccountToModule", reflect.TypeOf((*MockBankKeeper)(nil).SendCoinsFromAccountToModule), ctx, senderAddr, recipientModule, amt) +} + +// SendCoinsFromModuleToAccount mocks base method. +func (m *MockBankKeeper) SendCoinsFromModuleToAccount(ctx types.Context, senderModule string, recipientAddr types.AccAddress, amt types.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SendCoinsFromModuleToAccount", ctx, senderModule, recipientAddr, amt) + ret0, _ := ret[0].(error) + return ret0 +} + +// SendCoinsFromModuleToAccount indicates an expected call of SendCoinsFromModuleToAccount. +func (mr *MockBankKeeperMockRecorder) SendCoinsFromModuleToAccount(ctx, senderModule, recipientAddr, amt interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCoinsFromModuleToAccount", reflect.TypeOf((*MockBankKeeper)(nil).SendCoinsFromModuleToAccount), ctx, senderModule, recipientAddr, amt) +} + +// SendCoinsFromModuleToModule mocks base method. +func (m *MockBankKeeper) SendCoinsFromModuleToModule(ctx types.Context, senderModule, recipientModule string, amt types.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SendCoinsFromModuleToModule", ctx, senderModule, recipientModule, amt) + ret0, _ := ret[0].(error) + return ret0 +} + +// SendCoinsFromModuleToModule indicates an expected call of SendCoinsFromModuleToModule. +func (mr *MockBankKeeperMockRecorder) SendCoinsFromModuleToModule(ctx, senderModule, recipientModule, amt interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCoinsFromModuleToModule", reflect.TypeOf((*MockBankKeeper)(nil).SendCoinsFromModuleToModule), ctx, senderModule, recipientModule, amt) +} + +// SendEnabled mocks base method. +func (m *MockBankKeeper) SendEnabled(arg0 context.Context, arg1 *types1.QuerySendEnabledRequest) (*types1.QuerySendEnabledResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SendEnabled", arg0, arg1) + ret0, _ := ret[0].(*types1.QuerySendEnabledResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// SendEnabled indicates an expected call of SendEnabled. +func (mr *MockBankKeeperMockRecorder) SendEnabled(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendEnabled", reflect.TypeOf((*MockBankKeeper)(nil).SendEnabled), arg0, arg1) +} + +// SetAllSendEnabled mocks base method. +func (m *MockBankKeeper) SetAllSendEnabled(ctx types.Context, sendEnableds []*types1.SendEnabled) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "SetAllSendEnabled", ctx, sendEnableds) +} + +// SetAllSendEnabled indicates an expected call of SetAllSendEnabled. +func (mr *MockBankKeeperMockRecorder) SetAllSendEnabled(ctx, sendEnableds interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetAllSendEnabled", reflect.TypeOf((*MockBankKeeper)(nil).SetAllSendEnabled), ctx, sendEnableds) +} + +// SetDenomMetaData mocks base method. +func (m *MockBankKeeper) SetDenomMetaData(ctx types.Context, denomMetaData types1.Metadata) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "SetDenomMetaData", ctx, denomMetaData) +} + +// SetDenomMetaData indicates an expected call of SetDenomMetaData. +func (mr *MockBankKeeperMockRecorder) SetDenomMetaData(ctx, denomMetaData interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetDenomMetaData", reflect.TypeOf((*MockBankKeeper)(nil).SetDenomMetaData), ctx, denomMetaData) +} + +// SetParams mocks base method. +func (m *MockBankKeeper) SetParams(ctx types.Context, params types1.Params) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetParams", ctx, params) + ret0, _ := ret[0].(error) + return ret0 +} + +// SetParams indicates an expected call of SetParams. +func (mr *MockBankKeeperMockRecorder) SetParams(ctx, params interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetParams", reflect.TypeOf((*MockBankKeeper)(nil).SetParams), ctx, params) +} + +// SetSendEnabled mocks base method. +func (m *MockBankKeeper) SetSendEnabled(ctx types.Context, denom string, value bool) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "SetSendEnabled", ctx, denom, value) +} + +// SetSendEnabled indicates an expected call of SetSendEnabled. +func (mr *MockBankKeeperMockRecorder) SetSendEnabled(ctx, denom, value interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetSendEnabled", reflect.TypeOf((*MockBankKeeper)(nil).SetSendEnabled), ctx, denom, value) +} + +// SpendableBalances mocks base method. +func (m *MockBankKeeper) SpendableBalances(arg0 context.Context, arg1 *types1.QuerySpendableBalancesRequest) (*types1.QuerySpendableBalancesResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SpendableBalances", arg0, arg1) + ret0, _ := ret[0].(*types1.QuerySpendableBalancesResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// SpendableBalances indicates an expected call of SpendableBalances. +func (mr *MockBankKeeperMockRecorder) SpendableBalances(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SpendableBalances", reflect.TypeOf((*MockBankKeeper)(nil).SpendableBalances), arg0, arg1) +} + +// SpendableCoin mocks base method. +func (m *MockBankKeeper) SpendableCoin(ctx types.Context, addr types.AccAddress, denom string) types.Coin { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SpendableCoin", ctx, addr, denom) + ret0, _ := ret[0].(types.Coin) + return ret0 +} + +// SpendableCoin indicates an expected call of SpendableCoin. +func (mr *MockBankKeeperMockRecorder) SpendableCoin(ctx, addr, denom interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SpendableCoin", reflect.TypeOf((*MockBankKeeper)(nil).SpendableCoin), ctx, addr, denom) +} + +// SpendableCoins mocks base method. +func (m *MockBankKeeper) SpendableCoins(ctx types.Context, addr types.AccAddress) types.Coins { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SpendableCoins", ctx, addr) + ret0, _ := ret[0].(types.Coins) + return ret0 +} + +// SpendableCoins indicates an expected call of SpendableCoins. +func (mr *MockBankKeeperMockRecorder) SpendableCoins(ctx, addr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SpendableCoins", reflect.TypeOf((*MockBankKeeper)(nil).SpendableCoins), ctx, addr) +} + +// SupplyOf mocks base method. +func (m *MockBankKeeper) SupplyOf(arg0 context.Context, arg1 *types1.QuerySupplyOfRequest) (*types1.QuerySupplyOfResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SupplyOf", arg0, arg1) + ret0, _ := ret[0].(*types1.QuerySupplyOfResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// SupplyOf indicates an expected call of SupplyOf. +func (mr *MockBankKeeperMockRecorder) SupplyOf(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SupplyOf", reflect.TypeOf((*MockBankKeeper)(nil).SupplyOf), arg0, arg1) +} + +// TotalSupply mocks base method. +func (m *MockBankKeeper) TotalSupply(arg0 context.Context, arg1 *types1.QueryTotalSupplyRequest) (*types1.QueryTotalSupplyResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "TotalSupply", arg0, arg1) + ret0, _ := ret[0].(*types1.QueryTotalSupplyResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// TotalSupply indicates an expected call of TotalSupply. +func (mr *MockBankKeeperMockRecorder) TotalSupply(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TotalSupply", reflect.TypeOf((*MockBankKeeper)(nil).TotalSupply), arg0, arg1) +} + +// UndelegateCoins mocks base method. +func (m *MockBankKeeper) UndelegateCoins(ctx types.Context, moduleAccAddr, delegatorAddr types.AccAddress, amt types.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UndelegateCoins", ctx, moduleAccAddr, delegatorAddr, amt) + ret0, _ := ret[0].(error) + return ret0 +} + +// UndelegateCoins indicates an expected call of UndelegateCoins. +func (mr *MockBankKeeperMockRecorder) UndelegateCoins(ctx, moduleAccAddr, delegatorAddr, amt interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UndelegateCoins", reflect.TypeOf((*MockBankKeeper)(nil).UndelegateCoins), ctx, moduleAccAddr, delegatorAddr, amt) +} + +// UndelegateCoinsFromModuleToAccount mocks base method. +func (m *MockBankKeeper) UndelegateCoinsFromModuleToAccount(ctx types.Context, senderModule string, recipientAddr types.AccAddress, amt types.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UndelegateCoinsFromModuleToAccount", ctx, senderModule, recipientAddr, amt) + ret0, _ := ret[0].(error) + return ret0 +} + +// UndelegateCoinsFromModuleToAccount indicates an expected call of UndelegateCoinsFromModuleToAccount. +func (mr *MockBankKeeperMockRecorder) UndelegateCoinsFromModuleToAccount(ctx, senderModule, recipientAddr, amt interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UndelegateCoinsFromModuleToAccount", reflect.TypeOf((*MockBankKeeper)(nil).UndelegateCoinsFromModuleToAccount), ctx, senderModule, recipientAddr, amt) +} + +// ValidateBalance mocks base method. +func (m *MockBankKeeper) ValidateBalance(ctx types.Context, addr types.AccAddress) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ValidateBalance", ctx, addr) + ret0, _ := ret[0].(error) + return ret0 +} + +// ValidateBalance indicates an expected call of ValidateBalance. +func (mr *MockBankKeeperMockRecorder) ValidateBalance(ctx, addr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateBalance", reflect.TypeOf((*MockBankKeeper)(nil).ValidateBalance), ctx, addr) +} + +// WithMintCoinsRestriction mocks base method. +func (m *MockBankKeeper) WithMintCoinsRestriction(arg0 keeper.MintingRestrictionFn) keeper.BaseKeeper { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "WithMintCoinsRestriction", arg0) + ret0, _ := ret[0].(keeper.BaseKeeper) + return ret0 +} + +// WithMintCoinsRestriction indicates an expected call of WithMintCoinsRestriction. +func (mr *MockBankKeeperMockRecorder) WithMintCoinsRestriction(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WithMintCoinsRestriction", reflect.TypeOf((*MockBankKeeper)(nil).WithMintCoinsRestriction), arg0) +} + +// MockStakingKeeper is a mock of StakingKeeper interface. +type MockStakingKeeper struct { + ctrl *gomock.Controller + recorder *MockStakingKeeperMockRecorder +} + +// MockStakingKeeperMockRecorder is the mock recorder for MockStakingKeeper. +type MockStakingKeeperMockRecorder struct { + mock *MockStakingKeeper +} + +// NewMockStakingKeeper creates a new mock instance. +func NewMockStakingKeeper(ctrl *gomock.Controller) *MockStakingKeeper { + mock := &MockStakingKeeper{ctrl: ctrl} + mock.recorder = &MockStakingKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockStakingKeeper) EXPECT() *MockStakingKeeperMockRecorder { + return m.recorder +} + +// BondDenom mocks base method. +func (m *MockStakingKeeper) BondDenom(ctx types.Context) string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "BondDenom", ctx) + ret0, _ := ret[0].(string) + return ret0 +} + +// BondDenom indicates an expected call of BondDenom. +func (mr *MockStakingKeeperMockRecorder) BondDenom(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BondDenom", reflect.TypeOf((*MockStakingKeeper)(nil).BondDenom), ctx) +} + +// IterateBondedValidatorsByPower mocks base method. +func (m *MockStakingKeeper) IterateBondedValidatorsByPower(arg0 types.Context, arg1 func(int64, types2.ValidatorI) bool) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "IterateBondedValidatorsByPower", arg0, arg1) +} + +// IterateBondedValidatorsByPower indicates an expected call of IterateBondedValidatorsByPower. +func (mr *MockStakingKeeperMockRecorder) IterateBondedValidatorsByPower(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IterateBondedValidatorsByPower", reflect.TypeOf((*MockStakingKeeper)(nil).IterateBondedValidatorsByPower), arg0, arg1) +} + +// IterateDelegations mocks base method. +func (m *MockStakingKeeper) IterateDelegations(ctx types.Context, delegator types.AccAddress, fn func(int64, types2.DelegationI) bool) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "IterateDelegations", ctx, delegator, fn) +} + +// IterateDelegations indicates an expected call of IterateDelegations. +func (mr *MockStakingKeeperMockRecorder) IterateDelegations(ctx, delegator, fn interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IterateDelegations", reflect.TypeOf((*MockStakingKeeper)(nil).IterateDelegations), ctx, delegator, fn) +} + +// TokensFromConsensusPower mocks base method. +func (m *MockStakingKeeper) TokensFromConsensusPower(ctx types.Context, power int64) math.Int { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "TokensFromConsensusPower", ctx, power) + ret0, _ := ret[0].(math.Int) + return ret0 +} + +// TokensFromConsensusPower indicates an expected call of TokensFromConsensusPower. +func (mr *MockStakingKeeperMockRecorder) TokensFromConsensusPower(ctx, power interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TokensFromConsensusPower", reflect.TypeOf((*MockStakingKeeper)(nil).TokensFromConsensusPower), ctx, power) +} + +// TotalBondedTokens mocks base method. +func (m *MockStakingKeeper) TotalBondedTokens(arg0 types.Context) math.Int { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "TotalBondedTokens", arg0) + ret0, _ := ret[0].(math.Int) + return ret0 +} + +// TotalBondedTokens indicates an expected call of TotalBondedTokens. +func (mr *MockStakingKeeperMockRecorder) TotalBondedTokens(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TotalBondedTokens", reflect.TypeOf((*MockStakingKeeper)(nil).TotalBondedTokens), arg0) +}