## Description ref: #11086 --- ### 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/master/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/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/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)
116 lines
3.8 KiB
Go
116 lines
3.8 KiB
Go
package keeper_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"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"
|
|
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"
|
|
)
|
|
|
|
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 TestIncrementProposalNumber(t *testing.T) {
|
|
app := simapp.Setup(t, false)
|
|
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
|
|
|
tp := TestProposal
|
|
_, err := app.GovKeeper.SubmitProposal(ctx, tp, "")
|
|
require.NoError(t, err)
|
|
_, err = app.GovKeeper.SubmitProposal(ctx, tp, "")
|
|
require.NoError(t, err)
|
|
_, err = app.GovKeeper.SubmitProposal(ctx, tp, "")
|
|
require.NoError(t, err)
|
|
_, err = app.GovKeeper.SubmitProposal(ctx, tp, "")
|
|
require.NoError(t, err)
|
|
_, err = app.GovKeeper.SubmitProposal(ctx, tp, "")
|
|
require.NoError(t, err)
|
|
proposal6, err := app.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{})
|
|
|
|
// create test proposals
|
|
tp := TestProposal
|
|
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp, "")
|
|
require.NoError(t, err)
|
|
|
|
inactiveIterator := app.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)
|
|
|
|
proposal, ok := app.GovKeeper.GetProposal(ctx, proposal.Id)
|
|
require.True(t, ok)
|
|
|
|
activeIterator := app.GovKeeper.ActiveProposalQueueIterator(ctx, *proposal.VotingEndTime)
|
|
require.True(t, activeIterator.Valid())
|
|
|
|
proposalID, _ = types.SplitActiveProposalQueueKey(activeIterator.Key())
|
|
require.Equal(t, proposalID, proposal.Id)
|
|
|
|
activeIterator.Close()
|
|
}
|
|
|
|
func TestKeeperTestSuite(t *testing.T) {
|
|
suite.Run(t, new(KeeperTestSuite))
|
|
}
|