migrate TestProposalQueues to use simapp
This commit is contained in:
parent
0c938123d9
commit
2afd22f37e
|
@ -119,7 +119,7 @@ func (keeper Keeper) AddDeposit(ctx sdk.Context, proposalID uint64, depositorAdd
|
||||||
// Check if deposit has provided sufficient total funds to transition the proposal into the voting period
|
// Check if deposit has provided sufficient total funds to transition the proposal into the voting period
|
||||||
activatedVotingPeriod := false
|
activatedVotingPeriod := false
|
||||||
if proposal.Status == types.StatusDepositPeriod && proposal.TotalDeposit.IsAllGTE(keeper.GetDepositParams(ctx).MinDeposit) {
|
if proposal.Status == types.StatusDepositPeriod && proposal.TotalDeposit.IsAllGTE(keeper.GetDepositParams(ctx).MinDeposit) {
|
||||||
keeper.activateVotingPeriod(ctx, proposal)
|
keeper.ActivateVotingPeriod(ctx, proposal)
|
||||||
activatedVotingPeriod = true
|
activatedVotingPeriod = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,8 @@ package keeper_test
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/simapp"
|
"github.com/cosmos/cosmos-sdk/simapp"
|
||||||
abci "github.com/tendermint/tendermint/abci/types"
|
abci "github.com/tendermint/tendermint/abci/types"
|
||||||
|
|
||||||
|
@ -24,3 +26,31 @@ func TestIncrementProposalNumber(t *testing.T) {
|
||||||
|
|
||||||
require.Equal(t, uint64(6), proposal6.ProposalID)
|
require.Equal(t, uint64(6), proposal6.ProposalID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestProposalQueues(t *testing.T) {
|
||||||
|
app := simapp.Setup(false)
|
||||||
|
ctx := app.BaseApp.NewContext(false, abci.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.ProposalID)
|
||||||
|
inactiveIterator.Close()
|
||||||
|
|
||||||
|
app.GovKeeper.ActivateVotingPeriod(ctx, proposal)
|
||||||
|
|
||||||
|
proposal, ok := app.GovKeeper.GetProposal(ctx, proposal.ProposalID)
|
||||||
|
require.True(t, ok)
|
||||||
|
|
||||||
|
activeIterator := app.GovKeeper.ActiveProposalQueueIterator(ctx, proposal.VotingEndTime)
|
||||||
|
require.True(t, activeIterator.Valid())
|
||||||
|
app.Codec().UnmarshalBinaryLengthPrefixed(activeIterator.Value(), &proposalID)
|
||||||
|
require.Equal(t, proposalID, proposal.ProposalID)
|
||||||
|
activeIterator.Close()
|
||||||
|
}
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
package keeper
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestProposalQueues(t *testing.T) {
|
|
||||||
ctx, _, _, keeper, _, _ := createTestInput(t, false, 100) // nolint: dogsled
|
|
||||||
|
|
||||||
// create test proposals
|
|
||||||
tp := TestProposal
|
|
||||||
proposal, err := keeper.SubmitProposal(ctx, tp)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
inactiveIterator := keeper.InactiveProposalQueueIterator(ctx, proposal.DepositEndTime)
|
|
||||||
require.True(t, inactiveIterator.Valid())
|
|
||||||
|
|
||||||
proposalID := types.GetProposalIDFromBytes(inactiveIterator.Value())
|
|
||||||
require.Equal(t, proposalID, proposal.ProposalID)
|
|
||||||
inactiveIterator.Close()
|
|
||||||
|
|
||||||
keeper.activateVotingPeriod(ctx, proposal)
|
|
||||||
|
|
||||||
proposal, ok := keeper.GetProposal(ctx, proposal.ProposalID)
|
|
||||||
require.True(t, ok)
|
|
||||||
|
|
||||||
activeIterator := keeper.ActiveProposalQueueIterator(ctx, proposal.VotingEndTime)
|
|
||||||
require.True(t, activeIterator.Valid())
|
|
||||||
keeper.cdc.UnmarshalBinaryLengthPrefixed(activeIterator.Value(), &proposalID)
|
|
||||||
require.Equal(t, proposalID, proposal.ProposalID)
|
|
||||||
activeIterator.Close()
|
|
||||||
}
|
|
|
@ -167,7 +167,7 @@ func (keeper Keeper) SetProposalID(ctx sdk.Context, proposalID uint64) {
|
||||||
store.Set(types.ProposalIDKey, types.GetProposalIDBytes(proposalID))
|
store.Set(types.ProposalIDKey, types.GetProposalIDBytes(proposalID))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (keeper Keeper) activateVotingPeriod(ctx sdk.Context, proposal types.Proposal) {
|
func (keeper Keeper) ActivateVotingPeriod(ctx sdk.Context, proposal types.Proposal) {
|
||||||
proposal.VotingStartTime = ctx.BlockHeader().Time
|
proposal.VotingStartTime = ctx.BlockHeader().Time
|
||||||
votingPeriod := keeper.GetVotingParams(ctx).VotingPeriod
|
votingPeriod := keeper.GetVotingParams(ctx).VotingPeriod
|
||||||
proposal.VotingEndTime = proposal.VotingStartTime.Add(votingPeriod)
|
proposal.VotingEndTime = proposal.VotingStartTime.Add(votingPeriod)
|
||||||
|
|
|
@ -36,7 +36,7 @@ func TestActivateVotingPeriod(t *testing.T) {
|
||||||
|
|
||||||
require.True(t, proposal.VotingStartTime.Equal(time.Time{}))
|
require.True(t, proposal.VotingStartTime.Equal(time.Time{}))
|
||||||
|
|
||||||
keeper.activateVotingPeriod(ctx, proposal)
|
keeper.ActivateVotingPeriod(ctx, proposal)
|
||||||
|
|
||||||
require.True(t, proposal.VotingStartTime.Equal(ctx.BlockHeader().Time))
|
require.True(t, proposal.VotingStartTime.Equal(ctx.BlockHeader().Time))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue