2018-06-21 17:19:14 -07:00
|
|
|
package gov
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2018-09-20 07:53:52 -07:00
|
|
|
"time"
|
2018-06-21 17:19:14 -07:00
|
|
|
|
2018-06-29 18:10:15 -07:00
|
|
|
"github.com/stretchr/testify/require"
|
2018-06-21 17:19:14 -07:00
|
|
|
|
2018-12-10 06:27:25 -08:00
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
|
|
|
2018-06-21 17:19:14 -07:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2019-04-30 09:31:38 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/staking"
|
2018-06-21 17:19:14 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestTickExpiredDepositPeriod(t *testing.T) {
|
2019-04-30 09:31:38 -07:00
|
|
|
input := getMockApp(t, 10, GenesisState{}, nil)
|
2019-03-07 21:52:19 -08:00
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
header := abci.Header{Height: input.mApp.LastBlockHeight() + 1}
|
|
|
|
input.mApp.BeginBlock(abci.RequestBeginBlock{Header: header})
|
2019-03-07 21:52:19 -08:00
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
ctx := input.mApp.BaseApp.NewContext(false, abci.Header{})
|
|
|
|
govHandler := NewHandler(input.keeper)
|
2018-06-21 17:19:14 -07:00
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
inactiveQueue := input.keeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time)
|
2018-11-06 23:33:18 -08:00
|
|
|
require.False(t, inactiveQueue.Valid())
|
|
|
|
inactiveQueue.Close()
|
2018-06-21 17:19:14 -07:00
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
newProposalMsg := NewMsgSubmitProposal(
|
|
|
|
ContentFromProposalType("test", "test", ProposalTypeText),
|
|
|
|
sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 5)},
|
|
|
|
input.addrs[0],
|
|
|
|
)
|
2018-06-21 17:19:14 -07:00
|
|
|
|
|
|
|
res := govHandler(ctx, newProposalMsg)
|
2018-06-29 18:10:15 -07:00
|
|
|
require.True(t, res.IsOK())
|
2018-06-21 17:19:14 -07:00
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
inactiveQueue = input.keeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time)
|
2018-11-06 23:33:18 -08:00
|
|
|
require.False(t, inactiveQueue.Valid())
|
|
|
|
inactiveQueue.Close()
|
2018-06-21 17:19:14 -07:00
|
|
|
|
2018-09-20 07:53:52 -07:00
|
|
|
newHeader := ctx.BlockHeader()
|
|
|
|
newHeader.Time = ctx.BlockHeader().Time.Add(time.Duration(1) * time.Second)
|
|
|
|
ctx = ctx.WithBlockHeader(newHeader)
|
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
inactiveQueue = input.keeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time)
|
2018-11-06 23:33:18 -08:00
|
|
|
require.False(t, inactiveQueue.Valid())
|
|
|
|
inactiveQueue.Close()
|
2018-06-21 17:19:14 -07:00
|
|
|
|
2018-09-20 07:53:52 -07:00
|
|
|
newHeader = ctx.BlockHeader()
|
2019-04-30 09:31:38 -07:00
|
|
|
newHeader.Time = ctx.BlockHeader().Time.Add(input.keeper.GetDepositParams(ctx).MaxDepositPeriod)
|
2018-09-20 07:53:52 -07:00
|
|
|
ctx = ctx.WithBlockHeader(newHeader)
|
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
inactiveQueue = input.keeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time)
|
2018-11-06 23:33:18 -08:00
|
|
|
require.True(t, inactiveQueue.Valid())
|
|
|
|
inactiveQueue.Close()
|
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
EndBlocker(ctx, input.keeper)
|
2018-11-06 23:33:18 -08:00
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
inactiveQueue = input.keeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time)
|
2018-11-06 23:33:18 -08:00
|
|
|
require.False(t, inactiveQueue.Valid())
|
|
|
|
inactiveQueue.Close()
|
2018-06-21 17:19:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTickMultipleExpiredDepositPeriod(t *testing.T) {
|
2019-04-30 09:31:38 -07:00
|
|
|
input := getMockApp(t, 10, GenesisState{}, nil)
|
2019-03-07 21:52:19 -08:00
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
header := abci.Header{Height: input.mApp.LastBlockHeight() + 1}
|
|
|
|
input.mApp.BeginBlock(abci.RequestBeginBlock{Header: header})
|
2019-03-07 21:52:19 -08:00
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
ctx := input.mApp.BaseApp.NewContext(false, abci.Header{})
|
|
|
|
govHandler := NewHandler(input.keeper)
|
2018-06-21 17:19:14 -07:00
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
inactiveQueue := input.keeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time)
|
2018-11-06 23:33:18 -08:00
|
|
|
require.False(t, inactiveQueue.Valid())
|
|
|
|
inactiveQueue.Close()
|
2018-06-21 17:19:14 -07:00
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
newProposalMsg := NewMsgSubmitProposal(
|
|
|
|
ContentFromProposalType("test", "test", ProposalTypeText),
|
|
|
|
sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 5)},
|
|
|
|
input.addrs[0],
|
|
|
|
)
|
2018-06-21 17:19:14 -07:00
|
|
|
|
|
|
|
res := govHandler(ctx, newProposalMsg)
|
2018-06-29 18:10:15 -07:00
|
|
|
require.True(t, res.IsOK())
|
2018-06-21 17:19:14 -07:00
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
inactiveQueue = input.keeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time)
|
2018-11-06 23:33:18 -08:00
|
|
|
require.False(t, inactiveQueue.Valid())
|
|
|
|
inactiveQueue.Close()
|
2018-06-21 17:19:14 -07:00
|
|
|
|
2018-09-20 07:53:52 -07:00
|
|
|
newHeader := ctx.BlockHeader()
|
|
|
|
newHeader.Time = ctx.BlockHeader().Time.Add(time.Duration(2) * time.Second)
|
|
|
|
ctx = ctx.WithBlockHeader(newHeader)
|
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
inactiveQueue = input.keeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time)
|
2018-11-06 23:33:18 -08:00
|
|
|
require.False(t, inactiveQueue.Valid())
|
|
|
|
inactiveQueue.Close()
|
2018-06-21 17:19:14 -07:00
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
newProposalMsg2 := NewMsgSubmitProposal(
|
|
|
|
ContentFromProposalType("test2", "test2", ProposalTypeText),
|
|
|
|
sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 5)},
|
|
|
|
input.addrs[0],
|
|
|
|
)
|
|
|
|
|
2018-06-21 17:19:14 -07:00
|
|
|
res = govHandler(ctx, newProposalMsg2)
|
2018-06-29 18:10:15 -07:00
|
|
|
require.True(t, res.IsOK())
|
2018-06-21 17:19:14 -07:00
|
|
|
|
2018-09-20 07:53:52 -07:00
|
|
|
newHeader = ctx.BlockHeader()
|
2019-04-30 09:31:38 -07:00
|
|
|
newHeader.Time = ctx.BlockHeader().Time.Add(input.keeper.GetDepositParams(ctx).MaxDepositPeriod).Add(time.Duration(-1) * time.Second)
|
2018-09-20 07:53:52 -07:00
|
|
|
ctx = ctx.WithBlockHeader(newHeader)
|
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
inactiveQueue = input.keeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time)
|
2018-11-06 23:33:18 -08:00
|
|
|
require.True(t, inactiveQueue.Valid())
|
|
|
|
inactiveQueue.Close()
|
2019-04-30 09:31:38 -07:00
|
|
|
EndBlocker(ctx, input.keeper)
|
|
|
|
inactiveQueue = input.keeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time)
|
2018-11-06 23:33:18 -08:00
|
|
|
require.False(t, inactiveQueue.Valid())
|
|
|
|
inactiveQueue.Close()
|
2018-06-21 17:19:14 -07:00
|
|
|
|
2018-09-20 07:53:52 -07:00
|
|
|
newHeader = ctx.BlockHeader()
|
|
|
|
newHeader.Time = ctx.BlockHeader().Time.Add(time.Duration(5) * time.Second)
|
|
|
|
ctx = ctx.WithBlockHeader(newHeader)
|
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
inactiveQueue = input.keeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time)
|
2018-11-06 23:33:18 -08:00
|
|
|
require.True(t, inactiveQueue.Valid())
|
|
|
|
inactiveQueue.Close()
|
2019-04-30 09:31:38 -07:00
|
|
|
EndBlocker(ctx, input.keeper)
|
|
|
|
inactiveQueue = input.keeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time)
|
2018-11-06 23:33:18 -08:00
|
|
|
require.False(t, inactiveQueue.Valid())
|
|
|
|
inactiveQueue.Close()
|
2018-06-21 17:19:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTickPassedDepositPeriod(t *testing.T) {
|
2019-04-30 09:31:38 -07:00
|
|
|
input := getMockApp(t, 10, GenesisState{}, nil)
|
2019-03-07 21:52:19 -08:00
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
header := abci.Header{Height: input.mApp.LastBlockHeight() + 1}
|
|
|
|
input.mApp.BeginBlock(abci.RequestBeginBlock{Header: header})
|
2019-03-07 21:52:19 -08:00
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
ctx := input.mApp.BaseApp.NewContext(false, abci.Header{})
|
|
|
|
govHandler := NewHandler(input.keeper)
|
2018-06-21 17:19:14 -07:00
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
inactiveQueue := input.keeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time)
|
2018-11-06 23:33:18 -08:00
|
|
|
require.False(t, inactiveQueue.Valid())
|
|
|
|
inactiveQueue.Close()
|
2019-04-30 09:31:38 -07:00
|
|
|
activeQueue := input.keeper.ActiveProposalQueueIterator(ctx, ctx.BlockHeader().Time)
|
2018-11-06 23:33:18 -08:00
|
|
|
require.False(t, activeQueue.Valid())
|
|
|
|
activeQueue.Close()
|
2018-06-21 17:19:14 -07:00
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
newProposalMsg := NewMsgSubmitProposal(
|
|
|
|
ContentFromProposalType("test2", "test2", ProposalTypeText),
|
|
|
|
sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 5)},
|
|
|
|
input.addrs[0],
|
|
|
|
)
|
2018-06-21 17:19:14 -07:00
|
|
|
|
|
|
|
res := govHandler(ctx, newProposalMsg)
|
2018-06-29 18:10:15 -07:00
|
|
|
require.True(t, res.IsOK())
|
2018-11-06 23:33:18 -08:00
|
|
|
var proposalID uint64
|
2019-04-30 09:31:38 -07:00
|
|
|
input.keeper.cdc.MustUnmarshalBinaryLengthPrefixed(res.Data, &proposalID)
|
2018-06-21 17:19:14 -07:00
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
inactiveQueue = input.keeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time)
|
2018-11-06 23:33:18 -08:00
|
|
|
require.False(t, inactiveQueue.Valid())
|
|
|
|
inactiveQueue.Close()
|
2018-06-21 17:19:14 -07:00
|
|
|
|
2018-09-20 07:53:52 -07:00
|
|
|
newHeader := ctx.BlockHeader()
|
|
|
|
newHeader.Time = ctx.BlockHeader().Time.Add(time.Duration(1) * time.Second)
|
|
|
|
ctx = ctx.WithBlockHeader(newHeader)
|
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
inactiveQueue = input.keeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time)
|
2018-11-06 23:33:18 -08:00
|
|
|
require.False(t, inactiveQueue.Valid())
|
|
|
|
inactiveQueue.Close()
|
2018-06-21 17:19:14 -07:00
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
newDepositMsg := NewMsgDeposit(input.addrs[1], proposalID, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 5)})
|
2018-06-21 17:19:14 -07:00
|
|
|
res = govHandler(ctx, newDepositMsg)
|
2018-06-29 18:10:15 -07:00
|
|
|
require.True(t, res.IsOK())
|
2018-06-21 17:19:14 -07:00
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
activeQueue = input.keeper.ActiveProposalQueueIterator(ctx, ctx.BlockHeader().Time)
|
2018-11-06 23:33:18 -08:00
|
|
|
require.False(t, activeQueue.Valid())
|
|
|
|
activeQueue.Close()
|
2018-06-21 17:19:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTickPassedVotingPeriod(t *testing.T) {
|
2019-04-30 09:31:38 -07:00
|
|
|
input := getMockApp(t, 10, GenesisState{}, nil)
|
|
|
|
SortAddresses(input.addrs)
|
2019-03-07 21:52:19 -08:00
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
header := abci.Header{Height: input.mApp.LastBlockHeight() + 1}
|
|
|
|
input.mApp.BeginBlock(abci.RequestBeginBlock{Header: header})
|
2019-03-07 21:52:19 -08:00
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
ctx := input.mApp.BaseApp.NewContext(false, abci.Header{})
|
|
|
|
govHandler := NewHandler(input.keeper)
|
2018-06-21 17:19:14 -07:00
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
inactiveQueue := input.keeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time)
|
2018-11-06 23:33:18 -08:00
|
|
|
require.False(t, inactiveQueue.Valid())
|
|
|
|
inactiveQueue.Close()
|
2019-04-30 09:31:38 -07:00
|
|
|
activeQueue := input.keeper.ActiveProposalQueueIterator(ctx, ctx.BlockHeader().Time)
|
2018-11-06 23:33:18 -08:00
|
|
|
require.False(t, activeQueue.Valid())
|
|
|
|
activeQueue.Close()
|
2018-06-21 17:19:14 -07:00
|
|
|
|
2019-06-12 08:57:47 -07:00
|
|
|
proposalCoins := sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, sdk.TokensFromConsensusPower(5))}
|
2019-04-30 09:31:38 -07:00
|
|
|
newProposalMsg := NewMsgSubmitProposal(testProposal(), proposalCoins, input.addrs[0])
|
2018-06-21 17:19:14 -07:00
|
|
|
|
|
|
|
res := govHandler(ctx, newProposalMsg)
|
2018-06-29 18:10:15 -07:00
|
|
|
require.True(t, res.IsOK())
|
2018-11-06 23:33:18 -08:00
|
|
|
var proposalID uint64
|
2019-04-30 09:31:38 -07:00
|
|
|
input.keeper.cdc.MustUnmarshalBinaryLengthPrefixed(res.Data, &proposalID)
|
2018-06-21 17:19:14 -07:00
|
|
|
|
2018-09-20 07:53:52 -07:00
|
|
|
newHeader := ctx.BlockHeader()
|
|
|
|
newHeader.Time = ctx.BlockHeader().Time.Add(time.Duration(1) * time.Second)
|
|
|
|
ctx = ctx.WithBlockHeader(newHeader)
|
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
newDepositMsg := NewMsgDeposit(input.addrs[1], proposalID, proposalCoins)
|
2018-06-21 17:19:14 -07:00
|
|
|
res = govHandler(ctx, newDepositMsg)
|
2018-06-29 18:10:15 -07:00
|
|
|
require.True(t, res.IsOK())
|
2018-06-21 17:19:14 -07:00
|
|
|
|
2018-09-20 07:53:52 -07:00
|
|
|
newHeader = ctx.BlockHeader()
|
2019-04-30 09:31:38 -07:00
|
|
|
newHeader.Time = ctx.BlockHeader().Time.Add(input.keeper.GetDepositParams(ctx).MaxDepositPeriod).Add(input.keeper.GetVotingParams(ctx).VotingPeriod)
|
2018-09-20 07:53:52 -07:00
|
|
|
ctx = ctx.WithBlockHeader(newHeader)
|
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
inactiveQueue = input.keeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time)
|
2018-11-06 23:33:18 -08:00
|
|
|
require.False(t, inactiveQueue.Valid())
|
|
|
|
inactiveQueue.Close()
|
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
activeQueue = input.keeper.ActiveProposalQueueIterator(ctx, ctx.BlockHeader().Time)
|
2018-11-06 23:33:18 -08:00
|
|
|
require.True(t, activeQueue.Valid())
|
2019-04-30 09:31:38 -07:00
|
|
|
|
2018-11-06 23:33:18 -08:00
|
|
|
var activeProposalID uint64
|
2019-04-30 09:31:38 -07:00
|
|
|
|
|
|
|
require.NoError(t, input.keeper.cdc.UnmarshalBinaryLengthPrefixed(activeQueue.Value(), &activeProposalID))
|
|
|
|
proposal, ok := input.keeper.GetProposal(ctx, activeProposalID)
|
2019-03-15 09:47:47 -07:00
|
|
|
require.True(t, ok)
|
|
|
|
require.Equal(t, StatusVotingPeriod, proposal.Status)
|
2019-06-04 11:38:11 -07:00
|
|
|
depositsIterator := input.keeper.GetDepositsIterator(ctx, proposalID)
|
2018-06-29 18:10:15 -07:00
|
|
|
require.True(t, depositsIterator.Valid())
|
2018-06-21 17:19:14 -07:00
|
|
|
depositsIterator.Close()
|
2018-11-06 23:33:18 -08:00
|
|
|
activeQueue.Close()
|
2018-06-21 17:19:14 -07:00
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
EndBlocker(ctx, input.keeper)
|
2018-06-21 17:19:14 -07:00
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
activeQueue = input.keeper.ActiveProposalQueueIterator(ctx, ctx.BlockHeader().Time)
|
2018-11-06 23:33:18 -08:00
|
|
|
require.False(t, activeQueue.Valid())
|
|
|
|
activeQueue.Close()
|
2018-06-21 17:19:14 -07:00
|
|
|
}
|
2019-04-30 09:31:38 -07:00
|
|
|
|
|
|
|
func TestProposalPassedEndblocker(t *testing.T) {
|
|
|
|
input := getMockApp(t, 1, GenesisState{}, nil)
|
|
|
|
SortAddresses(input.addrs)
|
|
|
|
|
|
|
|
handler := NewHandler(input.keeper)
|
|
|
|
stakingHandler := staking.NewHandler(input.sk)
|
|
|
|
|
|
|
|
header := abci.Header{Height: input.mApp.LastBlockHeight() + 1}
|
|
|
|
input.mApp.BeginBlock(abci.RequestBeginBlock{Header: header})
|
|
|
|
ctx := input.mApp.BaseApp.NewContext(false, abci.Header{})
|
|
|
|
|
|
|
|
valAddr := sdk.ValAddress(input.addrs[0])
|
|
|
|
|
|
|
|
createValidators(t, stakingHandler, ctx, []sdk.ValAddress{valAddr}, []int64{10})
|
|
|
|
staking.EndBlocker(ctx, input.sk)
|
|
|
|
|
2019-06-28 13:11:27 -07:00
|
|
|
macc := input.keeper.GetGovernanceAccount(ctx)
|
|
|
|
require.NotNil(t, macc)
|
|
|
|
initialModuleAccCoins := macc.GetCoins()
|
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
proposal, err := input.keeper.SubmitProposal(ctx, testProposal())
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-06-12 08:57:47 -07:00
|
|
|
proposalCoins := sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, sdk.TokensFromConsensusPower(10))}
|
2019-04-30 09:31:38 -07:00
|
|
|
newDepositMsg := NewMsgDeposit(input.addrs[0], proposal.ProposalID, proposalCoins)
|
|
|
|
res := handler(ctx, newDepositMsg)
|
|
|
|
require.True(t, res.IsOK())
|
|
|
|
|
2019-06-28 13:11:27 -07:00
|
|
|
macc = input.keeper.GetGovernanceAccount(ctx)
|
|
|
|
require.NotNil(t, macc)
|
|
|
|
moduleAccCoins := macc.GetCoins()
|
|
|
|
|
|
|
|
deposits := initialModuleAccCoins.Add(proposal.TotalDeposit).Add(proposalCoins)
|
|
|
|
require.True(t, moduleAccCoins.IsEqual(deposits))
|
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
err = input.keeper.AddVote(ctx, proposal.ProposalID, input.addrs[0], OptionYes)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
newHeader := ctx.BlockHeader()
|
|
|
|
newHeader.Time = ctx.BlockHeader().Time.Add(input.keeper.GetDepositParams(ctx).MaxDepositPeriod).Add(input.keeper.GetVotingParams(ctx).VotingPeriod)
|
|
|
|
ctx = ctx.WithBlockHeader(newHeader)
|
|
|
|
|
2019-06-26 09:03:25 -07:00
|
|
|
EndBlocker(ctx, input.keeper)
|
2019-06-28 13:11:27 -07:00
|
|
|
|
|
|
|
macc = input.keeper.GetGovernanceAccount(ctx)
|
|
|
|
require.NotNil(t, macc)
|
|
|
|
require.True(t, macc.GetCoins().IsEqual(initialModuleAccCoins))
|
2019-04-30 09:31:38 -07:00
|
|
|
}
|
2019-05-30 11:31:35 -07:00
|
|
|
|
|
|
|
func TestEndBlockerProposalHandlerFailed(t *testing.T) {
|
|
|
|
input := getMockApp(t, 1, GenesisState{}, nil)
|
|
|
|
SortAddresses(input.addrs)
|
|
|
|
|
|
|
|
// hijack the router to one that will fail in a proposal's handler
|
|
|
|
input.keeper.router = NewRouter().AddRoute(RouterKey, badProposalHandler)
|
|
|
|
|
|
|
|
handler := NewHandler(input.keeper)
|
|
|
|
stakingHandler := staking.NewHandler(input.sk)
|
|
|
|
|
|
|
|
header := abci.Header{Height: input.mApp.LastBlockHeight() + 1}
|
|
|
|
input.mApp.BeginBlock(abci.RequestBeginBlock{Header: header})
|
|
|
|
ctx := input.mApp.BaseApp.NewContext(false, abci.Header{})
|
|
|
|
|
|
|
|
valAddr := sdk.ValAddress(input.addrs[0])
|
|
|
|
|
|
|
|
createValidators(t, stakingHandler, ctx, []sdk.ValAddress{valAddr}, []int64{10})
|
|
|
|
staking.EndBlocker(ctx, input.sk)
|
|
|
|
|
|
|
|
// Create a proposal where the handler will pass for the test proposal
|
|
|
|
// because the value of contextKeyBadProposal is true.
|
|
|
|
ctx = ctx.WithValue(contextKeyBadProposal, true)
|
|
|
|
proposal, err := input.keeper.SubmitProposal(ctx, testProposal())
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-06-12 08:57:47 -07:00
|
|
|
proposalCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.TokensFromConsensusPower(10)))
|
2019-05-30 11:31:35 -07:00
|
|
|
newDepositMsg := NewMsgDeposit(input.addrs[0], proposal.ProposalID, proposalCoins)
|
|
|
|
res := handler(ctx, newDepositMsg)
|
|
|
|
require.True(t, res.IsOK())
|
|
|
|
|
|
|
|
err = input.keeper.AddVote(ctx, proposal.ProposalID, input.addrs[0], OptionYes)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
newHeader := ctx.BlockHeader()
|
|
|
|
newHeader.Time = ctx.BlockHeader().Time.Add(input.keeper.GetDepositParams(ctx).MaxDepositPeriod).Add(input.keeper.GetVotingParams(ctx).VotingPeriod)
|
|
|
|
ctx = ctx.WithBlockHeader(newHeader)
|
|
|
|
|
|
|
|
// Set the contextKeyBadProposal value to false so that the handler will fail
|
|
|
|
// during the processing of the proposal in the EndBlocker.
|
|
|
|
ctx = ctx.WithValue(contextKeyBadProposal, false)
|
|
|
|
|
|
|
|
// validate that the proposal fails/has been rejected
|
2019-06-26 09:03:25 -07:00
|
|
|
EndBlocker(ctx, input.keeper)
|
2019-05-30 11:31:35 -07:00
|
|
|
}
|