BFT Time
This commit is contained in:
parent
3a62c83873
commit
aafa0d92dd
|
@ -2,6 +2,7 @@ package gov
|
|||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
|
@ -28,12 +29,18 @@ func TestTickExpiredDepositPeriod(t *testing.T) {
|
|||
require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx))
|
||||
require.False(t, shouldPopInactiveProposalQueue(ctx, keeper))
|
||||
|
||||
ctx = ctx.WithBlockHeight(10)
|
||||
newHeader := ctx.BlockHeader()
|
||||
newHeader.Time = ctx.BlockHeader().Time.Add(time.Duration(1) * time.Second)
|
||||
ctx = ctx.WithBlockHeader(newHeader)
|
||||
|
||||
EndBlocker(ctx, keeper)
|
||||
require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx))
|
||||
require.False(t, shouldPopInactiveProposalQueue(ctx, keeper))
|
||||
|
||||
ctx = ctx.WithBlockHeight(250)
|
||||
newHeader = ctx.BlockHeader()
|
||||
newHeader.Time = ctx.BlockHeader().Time.Add(keeper.GetDepositProcedure(ctx).MaxDepositPeriod)
|
||||
ctx = ctx.WithBlockHeader(newHeader)
|
||||
|
||||
require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx))
|
||||
require.True(t, shouldPopInactiveProposalQueue(ctx, keeper))
|
||||
EndBlocker(ctx, keeper)
|
||||
|
@ -59,7 +66,10 @@ func TestTickMultipleExpiredDepositPeriod(t *testing.T) {
|
|||
require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx))
|
||||
require.False(t, shouldPopInactiveProposalQueue(ctx, keeper))
|
||||
|
||||
ctx = ctx.WithBlockHeight(10)
|
||||
newHeader := ctx.BlockHeader()
|
||||
newHeader.Time = ctx.BlockHeader().Time.Add(time.Duration(2) * time.Second)
|
||||
ctx = ctx.WithBlockHeader(newHeader)
|
||||
|
||||
EndBlocker(ctx, keeper)
|
||||
require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx))
|
||||
require.False(t, shouldPopInactiveProposalQueue(ctx, keeper))
|
||||
|
@ -68,14 +78,20 @@ func TestTickMultipleExpiredDepositPeriod(t *testing.T) {
|
|||
res = govHandler(ctx, newProposalMsg2)
|
||||
require.True(t, res.IsOK())
|
||||
|
||||
ctx = ctx.WithBlockHeight(205)
|
||||
newHeader = ctx.BlockHeader()
|
||||
newHeader.Time = ctx.BlockHeader().Time.Add(keeper.GetDepositProcedure(ctx).MaxDepositPeriod).Add(time.Duration(-1) * time.Second)
|
||||
ctx = ctx.WithBlockHeader(newHeader)
|
||||
|
||||
require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx))
|
||||
require.True(t, shouldPopInactiveProposalQueue(ctx, keeper))
|
||||
EndBlocker(ctx, keeper)
|
||||
require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx))
|
||||
require.False(t, shouldPopInactiveProposalQueue(ctx, keeper))
|
||||
|
||||
ctx = ctx.WithBlockHeight(215)
|
||||
newHeader = ctx.BlockHeader()
|
||||
newHeader.Time = ctx.BlockHeader().Time.Add(time.Duration(5) * time.Second)
|
||||
ctx = ctx.WithBlockHeader(newHeader)
|
||||
|
||||
require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx))
|
||||
require.True(t, shouldPopInactiveProposalQueue(ctx, keeper))
|
||||
EndBlocker(ctx, keeper)
|
||||
|
@ -105,7 +121,10 @@ func TestTickPassedDepositPeriod(t *testing.T) {
|
|||
require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx))
|
||||
require.False(t, shouldPopInactiveProposalQueue(ctx, keeper))
|
||||
|
||||
ctx = ctx.WithBlockHeight(10)
|
||||
newHeader := ctx.BlockHeader()
|
||||
newHeader.Time = ctx.BlockHeader().Time.Add(time.Duration(1) * time.Second)
|
||||
ctx = ctx.WithBlockHeader(newHeader)
|
||||
|
||||
EndBlocker(ctx, keeper)
|
||||
require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx))
|
||||
require.False(t, shouldPopInactiveProposalQueue(ctx, keeper))
|
||||
|
@ -146,14 +165,20 @@ func TestTickPassedVotingPeriod(t *testing.T) {
|
|||
var proposalID int64
|
||||
keeper.cdc.UnmarshalBinaryBare(res.Data, &proposalID)
|
||||
|
||||
ctx = ctx.WithBlockHeight(10)
|
||||
newHeader := ctx.BlockHeader()
|
||||
newHeader.Time = ctx.BlockHeader().Time.Add(time.Duration(1) * time.Second)
|
||||
ctx = ctx.WithBlockHeader(newHeader)
|
||||
|
||||
newDepositMsg := NewMsgDeposit(addrs[1], proposalID, sdk.Coins{sdk.NewInt64Coin("steak", 5)})
|
||||
res = govHandler(ctx, newDepositMsg)
|
||||
require.True(t, res.IsOK())
|
||||
|
||||
EndBlocker(ctx, keeper)
|
||||
|
||||
ctx = ctx.WithBlockHeight(215)
|
||||
newHeader = ctx.BlockHeader()
|
||||
newHeader.Time = ctx.BlockHeader().Time.Add(keeper.GetDepositProcedure(ctx).MaxDepositPeriod).Add(keeper.GetDepositProcedure(ctx).MaxDepositPeriod)
|
||||
ctx = ctx.WithBlockHeader(newHeader)
|
||||
|
||||
require.True(t, shouldPopActiveProposalQueue(ctx, keeper))
|
||||
depositsIterator := keeper.GetDeposits(ctx, proposalID)
|
||||
require.True(t, depositsIterator.Valid())
|
||||
|
@ -197,7 +222,10 @@ func TestSlashing(t *testing.T) {
|
|||
var proposalID int64
|
||||
keeper.cdc.UnmarshalBinaryBare(res.Data, &proposalID)
|
||||
|
||||
ctx = ctx.WithBlockHeight(10)
|
||||
newHeader := ctx.BlockHeader()
|
||||
newHeader.Time = ctx.BlockHeader().Time.Add(time.Duration(1) * time.Second)
|
||||
ctx = ctx.WithBlockHeader(newHeader)
|
||||
|
||||
require.Equal(t, StatusVotingPeriod, keeper.GetProposal(ctx, proposalID).GetStatus())
|
||||
|
||||
newVoteMsg := NewMsgVote(addrs[0], proposalID, OptionYes)
|
||||
|
@ -206,7 +234,10 @@ func TestSlashing(t *testing.T) {
|
|||
|
||||
EndBlocker(ctx, keeper)
|
||||
|
||||
ctx = ctx.WithBlockHeight(215)
|
||||
newHeader = ctx.BlockHeader()
|
||||
newHeader.Time = ctx.BlockHeader().Time.Add(keeper.GetDepositProcedure(ctx).MaxDepositPeriod).Add(keeper.GetDepositProcedure(ctx).MaxDepositPeriod)
|
||||
ctx = ctx.WithBlockHeader(newHeader)
|
||||
|
||||
require.Equal(t, StatusVotingPeriod, keeper.GetProposal(ctx, proposalID).GetStatus())
|
||||
|
||||
EndBlocker(ctx, keeper)
|
||||
|
|
|
@ -2,6 +2,7 @@ package gov
|
|||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
|
@ -45,12 +46,12 @@ func TestActivateVotingPeriod(t *testing.T) {
|
|||
|
||||
proposal := keeper.NewTextProposal(ctx, "Test", "description", ProposalTypeText)
|
||||
|
||||
require.Equal(t, int64(-1), proposal.GetVotingStartBlock())
|
||||
require.True(t, proposal.GetVotingStartTime().Equal(time.Time{}))
|
||||
require.Nil(t, keeper.ActiveProposalQueuePeek(ctx))
|
||||
|
||||
keeper.activateVotingPeriod(ctx, proposal)
|
||||
|
||||
require.Equal(t, proposal.GetVotingStartBlock(), ctx.BlockHeight())
|
||||
require.True(t, proposal.GetVotingStartTime().Equal(ctx.BlockHeader().Time))
|
||||
require.Equal(t, proposal.GetProposalID(), keeper.ActiveProposalQueuePeek(ctx).GetProposalID())
|
||||
}
|
||||
|
||||
|
@ -77,7 +78,7 @@ func TestDeposits(t *testing.T) {
|
|||
// Check no deposits at beginning
|
||||
deposit, found := keeper.GetDeposit(ctx, proposalID, addrs[1])
|
||||
require.False(t, found)
|
||||
require.Equal(t, keeper.GetProposal(ctx, proposalID).GetVotingStartBlock(), int64(-1))
|
||||
require.True(t, keeper.GetProposal(ctx, proposalID).GetVotingStartTime().Equal(time.Time{}))
|
||||
require.Nil(t, keeper.ActiveProposalQueuePeek(ctx))
|
||||
|
||||
// Check first deposit
|
||||
|
@ -114,7 +115,7 @@ func TestDeposits(t *testing.T) {
|
|||
require.Equal(t, addr1Initial.Minus(fourSteak), keeper.ck.GetCoins(ctx, addrs[1]))
|
||||
|
||||
// Check that proposal moved to voting period
|
||||
require.Equal(t, ctx.BlockHeight(), keeper.GetProposal(ctx, proposalID).GetVotingStartBlock())
|
||||
require.True(t, keeper.GetProposal(ctx, proposalID).GetVotingStartTime().Equal(ctx.BlockHeader().Time))
|
||||
require.NotNil(t, keeper.ActiveProposalQueuePeek(ctx))
|
||||
require.Equal(t, proposalID, keeper.ActiveProposalQueuePeek(ctx).GetProposalID())
|
||||
|
||||
|
|
Loading…
Reference in New Issue