2020-03-02 06:56:26 -08:00
|
|
|
package keeper_test
|
2019-08-08 12:51:18 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2020-07-16 02:16:23 -07:00
|
|
|
"github.com/stretchr/testify/suite"
|
2020-08-14 10:58:53 -07:00
|
|
|
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
2020-01-16 13:46:51 -08:00
|
|
|
|
2020-07-16 02:16:23 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
2020-03-02 07:04:49 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/simapp"
|
2020-07-16 02:16:23 -07:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2020-01-16 13:46:51 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
2019-08-08 12:51:18 -07:00
|
|
|
)
|
|
|
|
|
2020-07-16 02:16:23 -07:00
|
|
|
type KeeperTestSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
|
|
|
|
app *simapp.SimApp
|
|
|
|
ctx sdk.Context
|
|
|
|
queryClient types.QueryClient
|
|
|
|
addrs []sdk.AccAddress
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *KeeperTestSuite) SetupTest() {
|
|
|
|
app := simapp.Setup(false)
|
2020-08-14 10:58:53 -07:00
|
|
|
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
2020-07-16 02:16:23 -07:00
|
|
|
|
|
|
|
queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry())
|
|
|
|
types.RegisterQueryServer(queryHelper, app.GovKeeper)
|
|
|
|
queryClient := types.NewQueryClient(queryHelper)
|
|
|
|
|
|
|
|
suite.app = app
|
|
|
|
suite.ctx = ctx
|
|
|
|
suite.queryClient = queryClient
|
|
|
|
suite.addrs = simapp.AddTestAddrsIncremental(app, ctx, 2, sdk.NewInt(30000000))
|
|
|
|
}
|
|
|
|
|
2019-08-08 12:51:18 -07:00
|
|
|
func TestIncrementProposalNumber(t *testing.T) {
|
2020-03-02 06:56:26 -08:00
|
|
|
app := simapp.Setup(false)
|
2020-08-14 10:58:53 -07:00
|
|
|
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
2019-08-08 12:51:18 -07:00
|
|
|
|
|
|
|
tp := TestProposal
|
2020-03-20 12:24:18 -07:00
|
|
|
_, 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)
|
2020-03-02 06:56:26 -08:00
|
|
|
proposal6, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-08-14 01:55:54 -07:00
|
|
|
require.Equal(t, uint64(6), proposal6.ProposalId)
|
2019-08-08 12:51:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestProposalQueues(t *testing.T) {
|
2020-03-02 06:59:55 -08:00
|
|
|
app := simapp.Setup(false)
|
2020-08-14 10:58:53 -07:00
|
|
|
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
2019-08-08 12:51:18 -07:00
|
|
|
|
|
|
|
// create test proposals
|
|
|
|
tp := TestProposal
|
2020-03-02 06:59:55 -08:00
|
|
|
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-03-02 06:59:55 -08:00
|
|
|
inactiveIterator := app.GovKeeper.InactiveProposalQueueIterator(ctx, proposal.DepositEndTime)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.True(t, inactiveIterator.Valid())
|
|
|
|
|
|
|
|
proposalID := types.GetProposalIDFromBytes(inactiveIterator.Value())
|
2020-08-14 01:55:54 -07:00
|
|
|
require.Equal(t, proposalID, proposal.ProposalId)
|
2019-08-08 12:51:18 -07:00
|
|
|
inactiveIterator.Close()
|
|
|
|
|
2020-03-02 06:59:55 -08:00
|
|
|
app.GovKeeper.ActivateVotingPeriod(ctx, proposal)
|
2019-08-08 12:51:18 -07:00
|
|
|
|
2020-08-14 01:55:54 -07:00
|
|
|
proposal, ok := app.GovKeeper.GetProposal(ctx, proposal.ProposalId)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.True(t, ok)
|
|
|
|
|
2020-03-02 06:59:55 -08:00
|
|
|
activeIterator := app.GovKeeper.ActiveProposalQueueIterator(ctx, proposal.VotingEndTime)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.True(t, activeIterator.Valid())
|
2020-03-02 12:07:51 -08:00
|
|
|
|
2020-03-02 13:46:28 -08:00
|
|
|
proposalID, _ = types.SplitActiveProposalQueueKey(activeIterator.Key())
|
2020-08-14 01:55:54 -07:00
|
|
|
require.Equal(t, proposalID, proposal.ProposalId)
|
2020-03-02 12:07:51 -08:00
|
|
|
|
2019-08-08 12:51:18 -07:00
|
|
|
activeIterator.Close()
|
|
|
|
}
|
2020-07-16 02:16:23 -07:00
|
|
|
|
|
|
|
func TestKeeperTestSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(KeeperTestSuite))
|
|
|
|
}
|