Skip to content

Commit

Permalink
write test
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Nov 10, 2024
1 parent 6b6d77a commit b862196
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion x/gov/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func EndBlocker(ctx sdk.Context, k *keeper.Keeper) error {
}

// quorum not reached and the proposal is not expired; schedule the next tally
if !quorumReached && !ctx.BlockTime().After(*proposal.EmergencyNextTallyTime) {
if !quorumReached && !proposal.VotingEndTime.Before(ctx.BlockTime()) {
nextTallyTime := ctx.BlockTime().Add(params.EmergencyTallyInterval)
if err = k.EmergencyProposalsQueue.Set(ctx, collections.Join(nextTallyTime, proposal.Id), proposal.Id); err != nil {
return false, err
Expand Down
49 changes: 49 additions & 0 deletions x/gov/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,52 @@ func TestTickSingleProposal(t *testing.T) {
})
}
}

func TestEmergencyProposal_Rejected_VotingPeriodOver(t *testing.T) {
app := createAppWithSimpleValidators(t)
ctx := app.BaseApp.NewContext(false)
initTime := ctx.BlockHeader().Time

govMsgSvr := keeper.NewMsgServerImpl(app.GovKeeper)
propMsg := createTextProposalMsg(t, emergencyMinDeposit[0].Amount.Int64(), false)
_, err := govMsgSvr.SubmitProposal(ctx, propMsg)
require.NoError(t, err)

newHeader := ctx.BlockHeader()
newHeader.Time = ctx.BlockHeader().Time.Add(time.Minute)
ctx = ctx.WithBlockHeader(newHeader)

proposal, err := app.GovKeeper.Proposals.Get(ctx, 1)
require.NoError(t, err)
require.True(t, proposal.Emergency)
require.True(t, proposal.EmergencyStartTime.Equal(ctx.BlockTime().Add(-time.Minute)))
require.True(t, proposal.EmergencyNextTallyTime.Equal(ctx.BlockTime().Add(emergencyTallyInterval-time.Minute)))
require.True(t, proposal.SubmitTime.Equal(initTime))
require.True(t, proposal.DepositEndTime.Equal(initTime.Add(depositPeriod)))
require.Equal(t, proposal.Status, v1.StatusVotingPeriod)
require.True(t, proposal.VotingStartTime.Equal(ctx.BlockTime().Add(-time.Minute)))
require.True(t, proposal.VotingEndTime.Equal(ctx.BlockTime().Add(votingPeriod-time.Minute)))

// not enough votes

newHeader = ctx.BlockHeader()
newHeader.Time = ctx.BlockHeader().Time.Add(time.Minute)
ctx = ctx.WithBlockHeader(newHeader)

err = gov.EndBlocker(ctx, app.GovKeeper)
require.NoError(t, err)
proposal, err = app.GovKeeper.Proposals.Get(ctx, 1)
require.NoError(t, err)
require.Equal(t, proposal.Status, v1.StatusVotingPeriod)

// voting period is over; so proposal should be finished
newHeader = ctx.BlockHeader()
newHeader.Time = ctx.BlockHeader().Time.Add(votingPeriod)
ctx = ctx.WithBlockHeader(newHeader)

err = gov.EndBlocker(ctx, app.GovKeeper)
require.NoError(t, err)
proposal, err = app.GovKeeper.Proposals.Get(ctx, 1)
require.NoError(t, err)
require.Equal(t, proposal.Status, v1.StatusRejected)
}

0 comments on commit b862196

Please sign in to comment.