From b8621968f3a34cf07f6d2ef0f8b019c767c27824 Mon Sep 17 00:00:00 2001 From: beer-1 Date: Mon, 11 Nov 2024 01:55:14 +0900 Subject: [PATCH] write test --- x/gov/abci.go | 2 +- x/gov/abci_test.go | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/x/gov/abci.go b/x/gov/abci.go index 91d72c5f..85db1a1e 100644 --- a/x/gov/abci.go +++ b/x/gov/abci.go @@ -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 diff --git a/x/gov/abci_test.go b/x/gov/abci_test.go index 5fddd242..f53f2eda 100644 --- a/x/gov/abci_test.go +++ b/x/gov/abci_test.go @@ -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) +}