2020-03-02 07:38:24 -08:00
|
|
|
package keeper_test
|
2019-08-08 12:51:18 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2020-08-14 10:58:53 -07:00
|
|
|
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
2019-08-08 12:51:18 -07:00
|
|
|
|
2020-03-02 07:38:24 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/simapp"
|
2019-08-08 12:51:18 -07:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2021-12-13 10:48:44 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
2019-08-08 12:51:18 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/staking"
|
2020-10-12 06:56:02 -07:00
|
|
|
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
2019-08-08 12:51:18 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestTallyNoOneVotes(t *testing.T) {
|
2021-08-16 17:52:06 -07:00
|
|
|
app := simapp.Setup(t, false)
|
2020-08-14 10:58:53 -07:00
|
|
|
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
2019-08-08 12:51:18 -07:00
|
|
|
|
2020-10-23 05:07:52 -07:00
|
|
|
createValidators(t, ctx, app, []int64{5, 5, 5})
|
2019-08-08 12:51:18 -07:00
|
|
|
|
|
|
|
tp := TestProposal
|
2020-03-02 07:38:24 -08:00
|
|
|
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.NoError(t, err)
|
2020-08-14 01:55:54 -07:00
|
|
|
proposalID := proposal.ProposalId
|
2021-12-13 10:48:44 -08:00
|
|
|
proposal.Status = v1beta1.StatusVotingPeriod
|
2020-03-02 07:38:24 -08:00
|
|
|
app.GovKeeper.SetProposal(ctx, proposal)
|
2019-08-08 12:51:18 -07:00
|
|
|
|
2020-03-02 07:38:24 -08:00
|
|
|
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.True(t, ok)
|
2020-03-02 07:38:24 -08:00
|
|
|
passes, burnDeposits, tallyResults := app.GovKeeper.Tally(ctx, proposal)
|
2019-08-08 12:51:18 -07:00
|
|
|
|
|
|
|
require.False(t, passes)
|
|
|
|
require.True(t, burnDeposits)
|
2021-12-13 10:48:44 -08:00
|
|
|
require.True(t, tallyResults.Equals(v1beta1.EmptyTallyResult()))
|
2019-08-08 12:51:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTallyNoQuorum(t *testing.T) {
|
2021-08-16 17:52:06 -07:00
|
|
|
app := simapp.Setup(t, false)
|
2020-08-14 10:58:53 -07:00
|
|
|
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
2020-03-02 07:41:41 -08:00
|
|
|
|
2020-10-23 05:07:52 -07:00
|
|
|
createValidators(t, ctx, app, []int64{2, 5, 0})
|
2020-03-02 07:41:41 -08:00
|
|
|
|
|
|
|
addrs := simapp.AddTestAddrsIncremental(app, ctx, 1, sdk.NewInt(10000000))
|
2019-08-08 12:51:18 -07:00
|
|
|
|
|
|
|
tp := TestProposal
|
2020-03-02 07:41:41 -08:00
|
|
|
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.NoError(t, err)
|
2020-08-14 01:55:54 -07:00
|
|
|
proposalID := proposal.ProposalId
|
2021-12-13 10:48:44 -08:00
|
|
|
proposal.Status = v1beta1.StatusVotingPeriod
|
2020-03-02 07:41:41 -08:00
|
|
|
app.GovKeeper.SetProposal(ctx, proposal)
|
2019-08-08 12:51:18 -07:00
|
|
|
|
2021-12-13 10:48:44 -08:00
|
|
|
err = app.GovKeeper.AddVote(ctx, proposalID, addrs[0], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes))
|
2019-08-08 12:51:18 -07:00
|
|
|
require.Nil(t, err)
|
|
|
|
|
2020-03-02 07:41:41 -08:00
|
|
|
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.True(t, ok)
|
2020-03-02 07:41:41 -08:00
|
|
|
passes, burnDeposits, _ := app.GovKeeper.Tally(ctx, proposal)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.False(t, passes)
|
|
|
|
require.True(t, burnDeposits)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTallyOnlyValidatorsAllYes(t *testing.T) {
|
2021-08-16 17:52:06 -07:00
|
|
|
app := simapp.Setup(t, false)
|
2020-08-14 10:58:53 -07:00
|
|
|
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
2019-08-08 12:51:18 -07:00
|
|
|
|
2020-10-23 05:07:52 -07:00
|
|
|
addrs, _ := createValidators(t, ctx, app, []int64{5, 5, 5})
|
2019-08-08 12:51:18 -07:00
|
|
|
tp := TestProposal
|
2020-03-02 07:50:39 -08:00
|
|
|
|
2020-03-02 07:47:06 -08:00
|
|
|
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.NoError(t, err)
|
2020-08-14 01:55:54 -07:00
|
|
|
proposalID := proposal.ProposalId
|
2021-12-13 10:48:44 -08:00
|
|
|
proposal.Status = v1beta1.StatusVotingPeriod
|
2020-03-02 07:47:06 -08:00
|
|
|
app.GovKeeper.SetProposal(ctx, proposal)
|
2019-08-08 12:51:18 -07:00
|
|
|
|
2021-12-13 10:48:44 -08:00
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[0], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[1], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[2], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
2019-08-08 12:51:18 -07:00
|
|
|
|
2020-03-02 07:47:06 -08:00
|
|
|
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.True(t, ok)
|
2020-03-02 07:47:06 -08:00
|
|
|
passes, burnDeposits, tallyResults := app.GovKeeper.Tally(ctx, proposal)
|
2019-08-08 12:51:18 -07:00
|
|
|
|
|
|
|
require.True(t, passes)
|
|
|
|
require.False(t, burnDeposits)
|
2021-12-13 10:48:44 -08:00
|
|
|
require.False(t, tallyResults.Equals(v1beta1.EmptyTallyResult()))
|
2019-08-08 12:51:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTallyOnlyValidators51No(t *testing.T) {
|
2021-08-16 17:52:06 -07:00
|
|
|
app := simapp.Setup(t, false)
|
2020-08-14 10:58:53 -07:00
|
|
|
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
2020-03-02 07:50:39 -08:00
|
|
|
|
2020-10-23 05:07:52 -07:00
|
|
|
valAccAddrs, _ := createValidators(t, ctx, app, []int64{5, 6, 0})
|
2019-08-08 12:51:18 -07:00
|
|
|
|
|
|
|
tp := TestProposal
|
2020-03-02 07:50:39 -08:00
|
|
|
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.NoError(t, err)
|
2020-08-14 01:55:54 -07:00
|
|
|
proposalID := proposal.ProposalId
|
2021-12-13 10:48:44 -08:00
|
|
|
proposal.Status = v1beta1.StatusVotingPeriod
|
2020-03-02 07:50:39 -08:00
|
|
|
app.GovKeeper.SetProposal(ctx, proposal)
|
2019-08-08 12:51:18 -07:00
|
|
|
|
2021-12-13 10:48:44 -08:00
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[0], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[1], v1beta1.NewNonSplitVoteOption(v1beta1.OptionNo)))
|
2019-08-08 12:51:18 -07:00
|
|
|
|
2020-03-02 07:50:39 -08:00
|
|
|
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.True(t, ok)
|
2020-03-02 07:50:39 -08:00
|
|
|
passes, burnDeposits, _ := app.GovKeeper.Tally(ctx, proposal)
|
2019-08-08 12:51:18 -07:00
|
|
|
|
|
|
|
require.False(t, passes)
|
|
|
|
require.False(t, burnDeposits)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTallyOnlyValidators51Yes(t *testing.T) {
|
2021-08-16 17:52:06 -07:00
|
|
|
app := simapp.Setup(t, false)
|
2020-08-14 10:58:53 -07:00
|
|
|
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
2020-03-02 07:53:06 -08:00
|
|
|
|
2020-10-23 05:07:52 -07:00
|
|
|
valAccAddrs, _ := createValidators(t, ctx, app, []int64{5, 6, 0})
|
2019-08-08 12:51:18 -07:00
|
|
|
|
|
|
|
tp := TestProposal
|
2020-03-02 07:53:06 -08:00
|
|
|
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.NoError(t, err)
|
2020-08-14 01:55:54 -07:00
|
|
|
proposalID := proposal.ProposalId
|
2021-12-13 10:48:44 -08:00
|
|
|
proposal.Status = v1beta1.StatusVotingPeriod
|
2020-03-02 07:53:06 -08:00
|
|
|
app.GovKeeper.SetProposal(ctx, proposal)
|
2019-08-08 12:51:18 -07:00
|
|
|
|
2021-12-13 10:48:44 -08:00
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[0], v1beta1.NewNonSplitVoteOption(v1beta1.OptionNo)))
|
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[1], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
2019-08-08 12:51:18 -07:00
|
|
|
|
2020-03-02 07:53:06 -08:00
|
|
|
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.True(t, ok)
|
2020-03-02 07:53:06 -08:00
|
|
|
passes, burnDeposits, tallyResults := app.GovKeeper.Tally(ctx, proposal)
|
2019-08-08 12:51:18 -07:00
|
|
|
|
|
|
|
require.True(t, passes)
|
|
|
|
require.False(t, burnDeposits)
|
2021-12-13 10:48:44 -08:00
|
|
|
require.False(t, tallyResults.Equals(v1beta1.EmptyTallyResult()))
|
2019-08-08 12:51:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTallyOnlyValidatorsVetoed(t *testing.T) {
|
2021-08-16 17:52:06 -07:00
|
|
|
app := simapp.Setup(t, false)
|
2020-08-14 10:58:53 -07:00
|
|
|
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
2020-03-02 08:55:31 -08:00
|
|
|
|
2020-10-23 05:07:52 -07:00
|
|
|
valAccAddrs, _ := createValidators(t, ctx, app, []int64{6, 6, 7})
|
2019-08-08 12:51:18 -07:00
|
|
|
|
|
|
|
tp := TestProposal
|
2020-03-02 08:55:31 -08:00
|
|
|
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.NoError(t, err)
|
2020-08-14 01:55:54 -07:00
|
|
|
proposalID := proposal.ProposalId
|
2021-12-13 10:48:44 -08:00
|
|
|
proposal.Status = v1beta1.StatusVotingPeriod
|
2020-03-02 08:55:31 -08:00
|
|
|
app.GovKeeper.SetProposal(ctx, proposal)
|
2019-08-08 12:51:18 -07:00
|
|
|
|
2021-12-13 10:48:44 -08:00
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[0], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[1], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[2], v1beta1.NewNonSplitVoteOption(v1beta1.OptionNoWithVeto)))
|
2019-08-08 12:51:18 -07:00
|
|
|
|
2020-03-02 08:55:31 -08:00
|
|
|
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.True(t, ok)
|
2020-03-02 08:55:31 -08:00
|
|
|
passes, burnDeposits, tallyResults := app.GovKeeper.Tally(ctx, proposal)
|
2019-08-08 12:51:18 -07:00
|
|
|
|
|
|
|
require.False(t, passes)
|
|
|
|
require.True(t, burnDeposits)
|
2021-12-13 10:48:44 -08:00
|
|
|
require.False(t, tallyResults.Equals(v1beta1.EmptyTallyResult()))
|
2019-08-08 12:51:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTallyOnlyValidatorsAbstainPasses(t *testing.T) {
|
2021-08-16 17:52:06 -07:00
|
|
|
app := simapp.Setup(t, false)
|
2020-08-14 10:58:53 -07:00
|
|
|
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
2020-03-02 08:57:39 -08:00
|
|
|
|
2020-10-23 05:07:52 -07:00
|
|
|
valAccAddrs, _ := createValidators(t, ctx, app, []int64{6, 6, 7})
|
2019-08-08 12:51:18 -07:00
|
|
|
|
|
|
|
tp := TestProposal
|
2020-03-02 08:59:24 -08:00
|
|
|
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.NoError(t, err)
|
2020-08-14 01:55:54 -07:00
|
|
|
proposalID := proposal.ProposalId
|
2021-12-13 10:48:44 -08:00
|
|
|
proposal.Status = v1beta1.StatusVotingPeriod
|
2020-03-02 08:59:24 -08:00
|
|
|
app.GovKeeper.SetProposal(ctx, proposal)
|
2019-08-08 12:51:18 -07:00
|
|
|
|
2021-12-13 10:48:44 -08:00
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[0], v1beta1.NewNonSplitVoteOption(v1beta1.OptionAbstain)))
|
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[1], v1beta1.NewNonSplitVoteOption(v1beta1.OptionNo)))
|
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[2], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
2019-08-08 12:51:18 -07:00
|
|
|
|
2020-03-02 08:59:24 -08:00
|
|
|
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.True(t, ok)
|
2020-03-02 08:59:24 -08:00
|
|
|
passes, burnDeposits, tallyResults := app.GovKeeper.Tally(ctx, proposal)
|
2019-08-08 12:51:18 -07:00
|
|
|
|
|
|
|
require.True(t, passes)
|
|
|
|
require.False(t, burnDeposits)
|
2021-12-13 10:48:44 -08:00
|
|
|
require.False(t, tallyResults.Equals(v1beta1.EmptyTallyResult()))
|
2019-08-08 12:51:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTallyOnlyValidatorsAbstainFails(t *testing.T) {
|
2021-08-16 17:52:06 -07:00
|
|
|
app := simapp.Setup(t, false)
|
2020-08-14 10:58:53 -07:00
|
|
|
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
2020-03-02 08:59:24 -08:00
|
|
|
|
2020-10-23 05:07:52 -07:00
|
|
|
valAccAddrs, _ := createValidators(t, ctx, app, []int64{6, 6, 7})
|
2019-08-08 12:51:18 -07:00
|
|
|
|
|
|
|
tp := TestProposal
|
2020-03-02 08:57:39 -08:00
|
|
|
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.NoError(t, err)
|
2020-08-14 01:55:54 -07:00
|
|
|
proposalID := proposal.ProposalId
|
2021-12-13 10:48:44 -08:00
|
|
|
proposal.Status = v1beta1.StatusVotingPeriod
|
2020-03-02 08:57:39 -08:00
|
|
|
app.GovKeeper.SetProposal(ctx, proposal)
|
2019-08-08 12:51:18 -07:00
|
|
|
|
2021-12-13 10:48:44 -08:00
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[0], v1beta1.NewNonSplitVoteOption(v1beta1.OptionAbstain)))
|
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[1], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddrs[2], v1beta1.NewNonSplitVoteOption(v1beta1.OptionNo)))
|
2019-08-08 12:51:18 -07:00
|
|
|
|
2020-03-02 08:57:39 -08:00
|
|
|
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.True(t, ok)
|
2020-03-02 08:57:39 -08:00
|
|
|
passes, burnDeposits, tallyResults := app.GovKeeper.Tally(ctx, proposal)
|
2019-08-08 12:51:18 -07:00
|
|
|
|
|
|
|
require.False(t, passes)
|
|
|
|
require.False(t, burnDeposits)
|
2021-12-13 10:48:44 -08:00
|
|
|
require.False(t, tallyResults.Equals(v1beta1.EmptyTallyResult()))
|
2019-08-08 12:51:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTallyOnlyValidatorsNonVoter(t *testing.T) {
|
2021-08-16 17:52:06 -07:00
|
|
|
app := simapp.Setup(t, false)
|
2020-08-14 10:58:53 -07:00
|
|
|
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
2020-03-02 09:01:10 -08:00
|
|
|
|
2020-10-23 05:07:52 -07:00
|
|
|
valAccAddrs, _ := createValidators(t, ctx, app, []int64{5, 6, 7})
|
2020-03-02 09:01:10 -08:00
|
|
|
valAccAddr1, valAccAddr2 := valAccAddrs[0], valAccAddrs[1]
|
2019-08-08 12:51:18 -07:00
|
|
|
|
|
|
|
tp := TestProposal
|
2020-03-02 09:01:10 -08:00
|
|
|
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.NoError(t, err)
|
2020-08-14 01:55:54 -07:00
|
|
|
proposalID := proposal.ProposalId
|
2021-12-13 10:48:44 -08:00
|
|
|
proposal.Status = v1beta1.StatusVotingPeriod
|
2020-03-02 09:01:10 -08:00
|
|
|
app.GovKeeper.SetProposal(ctx, proposal)
|
2019-08-08 12:51:18 -07:00
|
|
|
|
2021-12-13 10:48:44 -08:00
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddr1, v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, valAccAddr2, v1beta1.NewNonSplitVoteOption(v1beta1.OptionNo)))
|
2019-08-08 12:51:18 -07:00
|
|
|
|
2020-03-02 09:01:10 -08:00
|
|
|
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.True(t, ok)
|
2020-03-02 09:01:10 -08:00
|
|
|
passes, burnDeposits, tallyResults := app.GovKeeper.Tally(ctx, proposal)
|
2019-08-08 12:51:18 -07:00
|
|
|
|
|
|
|
require.False(t, passes)
|
|
|
|
require.False(t, burnDeposits)
|
2021-12-13 10:48:44 -08:00
|
|
|
require.False(t, tallyResults.Equals(v1beta1.EmptyTallyResult()))
|
2019-08-08 12:51:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTallyDelgatorOverride(t *testing.T) {
|
2021-08-16 17:52:06 -07:00
|
|
|
app := simapp.Setup(t, false)
|
2020-08-14 10:58:53 -07:00
|
|
|
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
2020-03-02 09:08:40 -08:00
|
|
|
|
2020-10-23 05:07:52 -07:00
|
|
|
addrs, valAddrs := createValidators(t, ctx, app, []int64{5, 6, 7})
|
2019-08-08 12:51:18 -07:00
|
|
|
|
2021-01-28 05:54:39 -08:00
|
|
|
delTokens := app.StakingKeeper.TokensFromConsensusPower(ctx, 30)
|
2020-03-02 09:49:14 -08:00
|
|
|
val1, found := app.StakingKeeper.GetValidator(ctx, valAddrs[0])
|
2019-08-08 12:51:18 -07:00
|
|
|
require.True(t, found)
|
|
|
|
|
2020-10-12 06:56:02 -07:00
|
|
|
_, err := app.StakingKeeper.Delegate(ctx, addrs[4], delTokens, stakingtypes.Unbonded, val1, true)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-03-02 09:08:40 -08:00
|
|
|
_ = staking.EndBlocker(ctx, app.StakingKeeper)
|
2019-08-08 12:51:18 -07:00
|
|
|
|
|
|
|
tp := TestProposal
|
2020-03-02 09:08:40 -08:00
|
|
|
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.NoError(t, err)
|
2020-08-14 01:55:54 -07:00
|
|
|
proposalID := proposal.ProposalId
|
2021-12-13 10:48:44 -08:00
|
|
|
proposal.Status = v1beta1.StatusVotingPeriod
|
2020-03-02 09:08:40 -08:00
|
|
|
app.GovKeeper.SetProposal(ctx, proposal)
|
2019-08-08 12:51:18 -07:00
|
|
|
|
2021-12-13 10:48:44 -08:00
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[1], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[2], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[3], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[4], v1beta1.NewNonSplitVoteOption(v1beta1.OptionNo)))
|
2019-08-08 12:51:18 -07:00
|
|
|
|
2020-03-02 09:08:40 -08:00
|
|
|
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.True(t, ok)
|
2020-03-02 09:08:40 -08:00
|
|
|
passes, burnDeposits, tallyResults := app.GovKeeper.Tally(ctx, proposal)
|
2019-08-08 12:51:18 -07:00
|
|
|
|
|
|
|
require.False(t, passes)
|
|
|
|
require.False(t, burnDeposits)
|
2021-12-13 10:48:44 -08:00
|
|
|
require.False(t, tallyResults.Equals(v1beta1.EmptyTallyResult()))
|
2019-08-08 12:51:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTallyDelgatorInherit(t *testing.T) {
|
2021-08-16 17:52:06 -07:00
|
|
|
app := simapp.Setup(t, false)
|
2020-08-14 10:58:53 -07:00
|
|
|
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
2020-03-02 09:49:14 -08:00
|
|
|
|
2020-10-23 05:07:52 -07:00
|
|
|
addrs, vals := createValidators(t, ctx, app, []int64{5, 6, 7})
|
2019-08-08 12:51:18 -07:00
|
|
|
|
2021-01-28 05:54:39 -08:00
|
|
|
delTokens := app.StakingKeeper.TokensFromConsensusPower(ctx, 30)
|
2020-03-02 09:49:14 -08:00
|
|
|
val3, found := app.StakingKeeper.GetValidator(ctx, vals[2])
|
2019-08-08 12:51:18 -07:00
|
|
|
require.True(t, found)
|
|
|
|
|
2020-10-12 06:56:02 -07:00
|
|
|
_, err := app.StakingKeeper.Delegate(ctx, addrs[3], delTokens, stakingtypes.Unbonded, val3, true)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-03-02 09:49:14 -08:00
|
|
|
_ = staking.EndBlocker(ctx, app.StakingKeeper)
|
2019-08-08 12:51:18 -07:00
|
|
|
|
|
|
|
tp := TestProposal
|
2020-03-02 09:49:14 -08:00
|
|
|
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.NoError(t, err)
|
2020-08-14 01:55:54 -07:00
|
|
|
proposalID := proposal.ProposalId
|
2021-12-13 10:48:44 -08:00
|
|
|
proposal.Status = v1beta1.StatusVotingPeriod
|
2020-03-02 09:49:14 -08:00
|
|
|
app.GovKeeper.SetProposal(ctx, proposal)
|
2019-08-08 12:51:18 -07:00
|
|
|
|
2021-12-13 10:48:44 -08:00
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[0], v1beta1.NewNonSplitVoteOption(v1beta1.OptionNo)))
|
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[1], v1beta1.NewNonSplitVoteOption(v1beta1.OptionNo)))
|
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[2], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
2019-08-08 12:51:18 -07:00
|
|
|
|
2020-03-02 09:49:14 -08:00
|
|
|
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.True(t, ok)
|
2020-03-02 09:49:14 -08:00
|
|
|
passes, burnDeposits, tallyResults := app.GovKeeper.Tally(ctx, proposal)
|
2019-08-08 12:51:18 -07:00
|
|
|
|
|
|
|
require.True(t, passes)
|
|
|
|
require.False(t, burnDeposits)
|
2021-12-13 10:48:44 -08:00
|
|
|
require.False(t, tallyResults.Equals(v1beta1.EmptyTallyResult()))
|
2019-08-08 12:51:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTallyDelgatorMultipleOverride(t *testing.T) {
|
2021-08-16 17:52:06 -07:00
|
|
|
app := simapp.Setup(t, false)
|
2020-08-14 10:58:53 -07:00
|
|
|
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
2020-03-02 09:52:45 -08:00
|
|
|
|
2020-10-23 05:07:52 -07:00
|
|
|
addrs, vals := createValidators(t, ctx, app, []int64{5, 6, 7})
|
2019-08-08 12:51:18 -07:00
|
|
|
|
2021-01-28 05:54:39 -08:00
|
|
|
delTokens := app.StakingKeeper.TokensFromConsensusPower(ctx, 10)
|
2020-03-02 09:52:45 -08:00
|
|
|
val1, found := app.StakingKeeper.GetValidator(ctx, vals[0])
|
2019-08-08 12:51:18 -07:00
|
|
|
require.True(t, found)
|
2020-03-02 09:52:45 -08:00
|
|
|
val2, found := app.StakingKeeper.GetValidator(ctx, vals[1])
|
2019-08-08 12:51:18 -07:00
|
|
|
require.True(t, found)
|
|
|
|
|
2020-10-12 06:56:02 -07:00
|
|
|
_, err := app.StakingKeeper.Delegate(ctx, addrs[3], delTokens, stakingtypes.Unbonded, val1, true)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.NoError(t, err)
|
2020-10-12 06:56:02 -07:00
|
|
|
_, err = app.StakingKeeper.Delegate(ctx, addrs[3], delTokens, stakingtypes.Unbonded, val2, true)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-03-02 09:52:45 -08:00
|
|
|
_ = staking.EndBlocker(ctx, app.StakingKeeper)
|
2019-08-08 12:51:18 -07:00
|
|
|
|
|
|
|
tp := TestProposal
|
2020-03-02 09:52:45 -08:00
|
|
|
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.NoError(t, err)
|
2020-08-14 01:55:54 -07:00
|
|
|
proposalID := proposal.ProposalId
|
2021-12-13 10:48:44 -08:00
|
|
|
proposal.Status = v1beta1.StatusVotingPeriod
|
2020-03-02 09:52:45 -08:00
|
|
|
app.GovKeeper.SetProposal(ctx, proposal)
|
2019-08-08 12:51:18 -07:00
|
|
|
|
2021-12-13 10:48:44 -08:00
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[0], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[1], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[2], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[3], v1beta1.NewNonSplitVoteOption(v1beta1.OptionNo)))
|
2019-08-08 12:51:18 -07:00
|
|
|
|
2020-03-02 09:52:45 -08:00
|
|
|
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.True(t, ok)
|
2020-03-02 09:52:45 -08:00
|
|
|
passes, burnDeposits, tallyResults := app.GovKeeper.Tally(ctx, proposal)
|
2019-08-08 12:51:18 -07:00
|
|
|
|
|
|
|
require.False(t, passes)
|
|
|
|
require.False(t, burnDeposits)
|
2021-12-13 10:48:44 -08:00
|
|
|
require.False(t, tallyResults.Equals(v1beta1.EmptyTallyResult()))
|
2019-08-08 12:51:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTallyDelgatorMultipleInherit(t *testing.T) {
|
2021-08-16 17:52:06 -07:00
|
|
|
app := simapp.Setup(t, false)
|
2020-08-14 10:58:53 -07:00
|
|
|
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
2020-03-02 10:17:31 -08:00
|
|
|
|
2020-10-23 05:07:52 -07:00
|
|
|
createValidators(t, ctx, app, []int64{25, 6, 7})
|
2020-03-02 10:17:31 -08:00
|
|
|
|
2020-10-23 05:07:52 -07:00
|
|
|
addrs, vals := createValidators(t, ctx, app, []int64{5, 6, 7})
|
2019-08-08 12:51:18 -07:00
|
|
|
|
2021-01-28 05:54:39 -08:00
|
|
|
delTokens := app.StakingKeeper.TokensFromConsensusPower(ctx, 10)
|
2020-03-02 10:17:31 -08:00
|
|
|
val2, found := app.StakingKeeper.GetValidator(ctx, vals[1])
|
2019-08-08 12:51:18 -07:00
|
|
|
require.True(t, found)
|
2020-03-02 10:17:31 -08:00
|
|
|
val3, found := app.StakingKeeper.GetValidator(ctx, vals[2])
|
2019-08-08 12:51:18 -07:00
|
|
|
require.True(t, found)
|
|
|
|
|
2020-10-12 06:56:02 -07:00
|
|
|
_, err := app.StakingKeeper.Delegate(ctx, addrs[3], delTokens, stakingtypes.Unbonded, val2, true)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.NoError(t, err)
|
2020-10-12 06:56:02 -07:00
|
|
|
_, err = app.StakingKeeper.Delegate(ctx, addrs[3], delTokens, stakingtypes.Unbonded, val3, true)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-03-02 10:17:31 -08:00
|
|
|
_ = staking.EndBlocker(ctx, app.StakingKeeper)
|
2019-08-08 12:51:18 -07:00
|
|
|
|
|
|
|
tp := TestProposal
|
2020-03-02 10:17:31 -08:00
|
|
|
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.NoError(t, err)
|
2020-08-14 01:55:54 -07:00
|
|
|
proposalID := proposal.ProposalId
|
2021-12-13 10:48:44 -08:00
|
|
|
proposal.Status = v1beta1.StatusVotingPeriod
|
2020-03-02 10:17:31 -08:00
|
|
|
app.GovKeeper.SetProposal(ctx, proposal)
|
2019-08-08 12:51:18 -07:00
|
|
|
|
2021-12-13 10:48:44 -08:00
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[0], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[1], v1beta1.NewNonSplitVoteOption(v1beta1.OptionNo)))
|
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[2], v1beta1.NewNonSplitVoteOption(v1beta1.OptionNo)))
|
2019-08-08 12:51:18 -07:00
|
|
|
|
2020-03-02 10:17:31 -08:00
|
|
|
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.True(t, ok)
|
2020-03-02 10:17:31 -08:00
|
|
|
passes, burnDeposits, tallyResults := app.GovKeeper.Tally(ctx, proposal)
|
2019-08-08 12:51:18 -07:00
|
|
|
|
|
|
|
require.False(t, passes)
|
|
|
|
require.False(t, burnDeposits)
|
2021-12-13 10:48:44 -08:00
|
|
|
require.False(t, tallyResults.Equals(v1beta1.EmptyTallyResult()))
|
2019-08-08 12:51:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTallyJailedValidator(t *testing.T) {
|
2021-08-16 17:52:06 -07:00
|
|
|
app := simapp.Setup(t, false)
|
2020-08-14 10:58:53 -07:00
|
|
|
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
2020-03-02 10:25:05 -08:00
|
|
|
|
2020-10-23 05:07:52 -07:00
|
|
|
addrs, valAddrs := createValidators(t, ctx, app, []int64{25, 6, 7})
|
2019-08-08 12:51:18 -07:00
|
|
|
|
2021-01-28 05:54:39 -08:00
|
|
|
delTokens := app.StakingKeeper.TokensFromConsensusPower(ctx, 10)
|
2020-03-02 10:25:05 -08:00
|
|
|
val2, found := app.StakingKeeper.GetValidator(ctx, valAddrs[1])
|
2019-08-08 12:51:18 -07:00
|
|
|
require.True(t, found)
|
2020-03-02 10:25:05 -08:00
|
|
|
val3, found := app.StakingKeeper.GetValidator(ctx, valAddrs[2])
|
2019-08-08 12:51:18 -07:00
|
|
|
require.True(t, found)
|
|
|
|
|
2020-10-12 06:56:02 -07:00
|
|
|
_, err := app.StakingKeeper.Delegate(ctx, addrs[3], delTokens, stakingtypes.Unbonded, val2, true)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.NoError(t, err)
|
2020-10-12 06:56:02 -07:00
|
|
|
_, err = app.StakingKeeper.Delegate(ctx, addrs[3], delTokens, stakingtypes.Unbonded, val3, true)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-03-02 10:25:05 -08:00
|
|
|
_ = staking.EndBlocker(ctx, app.StakingKeeper)
|
2019-08-08 12:51:18 -07:00
|
|
|
|
2020-11-09 08:01:43 -08:00
|
|
|
consAddr, err := val2.GetConsAddr()
|
2020-10-23 05:07:52 -07:00
|
|
|
require.NoError(t, err)
|
2020-11-09 08:01:43 -08:00
|
|
|
app.StakingKeeper.Jail(ctx, sdk.ConsAddress(consAddr.Bytes()))
|
2019-08-08 12:51:18 -07:00
|
|
|
|
|
|
|
tp := TestProposal
|
2020-03-02 10:25:05 -08:00
|
|
|
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.NoError(t, err)
|
2020-08-14 01:55:54 -07:00
|
|
|
proposalID := proposal.ProposalId
|
2021-12-13 10:48:44 -08:00
|
|
|
proposal.Status = v1beta1.StatusVotingPeriod
|
2020-03-02 10:25:05 -08:00
|
|
|
app.GovKeeper.SetProposal(ctx, proposal)
|
2019-08-08 12:51:18 -07:00
|
|
|
|
2021-12-13 10:48:44 -08:00
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[0], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[1], v1beta1.NewNonSplitVoteOption(v1beta1.OptionNo)))
|
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[2], v1beta1.NewNonSplitVoteOption(v1beta1.OptionNo)))
|
2019-08-08 12:51:18 -07:00
|
|
|
|
2020-03-02 10:25:05 -08:00
|
|
|
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
2019-08-08 12:51:18 -07:00
|
|
|
require.True(t, ok)
|
2020-03-02 10:25:05 -08:00
|
|
|
passes, burnDeposits, tallyResults := app.GovKeeper.Tally(ctx, proposal)
|
2019-08-08 12:51:18 -07:00
|
|
|
|
|
|
|
require.True(t, passes)
|
|
|
|
require.False(t, burnDeposits)
|
2021-12-13 10:48:44 -08:00
|
|
|
require.False(t, tallyResults.Equals(v1beta1.EmptyTallyResult()))
|
2019-08-08 12:51:18 -07:00
|
|
|
}
|
2019-10-18 09:38:23 -07:00
|
|
|
|
|
|
|
func TestTallyValidatorMultipleDelegations(t *testing.T) {
|
2021-08-16 17:52:06 -07:00
|
|
|
app := simapp.Setup(t, false)
|
2020-08-14 10:58:53 -07:00
|
|
|
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
2020-03-02 10:46:39 -08:00
|
|
|
|
2020-10-23 05:07:52 -07:00
|
|
|
addrs, valAddrs := createValidators(t, ctx, app, []int64{10, 10, 10})
|
2019-10-18 09:38:23 -07:00
|
|
|
|
2021-01-28 05:54:39 -08:00
|
|
|
delTokens := app.StakingKeeper.TokensFromConsensusPower(ctx, 10)
|
2020-03-02 10:46:39 -08:00
|
|
|
val2, found := app.StakingKeeper.GetValidator(ctx, valAddrs[1])
|
2019-10-18 09:38:23 -07:00
|
|
|
require.True(t, found)
|
|
|
|
|
2020-10-12 06:56:02 -07:00
|
|
|
_, err := app.StakingKeeper.Delegate(ctx, addrs[0], delTokens, stakingtypes.Unbonded, val2, true)
|
2019-10-18 09:38:23 -07:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
tp := TestProposal
|
2020-03-02 10:46:39 -08:00
|
|
|
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
2019-10-18 09:38:23 -07:00
|
|
|
require.NoError(t, err)
|
2020-08-14 01:55:54 -07:00
|
|
|
proposalID := proposal.ProposalId
|
2021-12-13 10:48:44 -08:00
|
|
|
proposal.Status = v1beta1.StatusVotingPeriod
|
2020-03-02 10:46:39 -08:00
|
|
|
app.GovKeeper.SetProposal(ctx, proposal)
|
2019-10-18 09:38:23 -07:00
|
|
|
|
2021-12-13 10:48:44 -08:00
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[0], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[1], v1beta1.NewNonSplitVoteOption(v1beta1.OptionNo)))
|
|
|
|
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[2], v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes)))
|
2019-10-18 09:38:23 -07:00
|
|
|
|
2020-03-02 10:46:39 -08:00
|
|
|
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
2019-10-18 09:38:23 -07:00
|
|
|
require.True(t, ok)
|
2020-03-02 10:46:39 -08:00
|
|
|
passes, burnDeposits, tallyResults := app.GovKeeper.Tally(ctx, proposal)
|
2019-10-18 09:38:23 -07:00
|
|
|
|
|
|
|
require.True(t, passes)
|
|
|
|
require.False(t, burnDeposits)
|
|
|
|
|
2021-01-28 05:54:39 -08:00
|
|
|
expectedYes := app.StakingKeeper.TokensFromConsensusPower(ctx, 30)
|
|
|
|
expectedAbstain := app.StakingKeeper.TokensFromConsensusPower(ctx, 0)
|
|
|
|
expectedNo := app.StakingKeeper.TokensFromConsensusPower(ctx, 10)
|
|
|
|
expectedNoWithVeto := app.StakingKeeper.TokensFromConsensusPower(ctx, 0)
|
2021-12-13 10:48:44 -08:00
|
|
|
expectedTallyResult := v1beta1.NewTallyResult(expectedYes, expectedAbstain, expectedNo, expectedNoWithVeto)
|
2019-10-18 09:38:23 -07:00
|
|
|
|
|
|
|
require.True(t, tallyResults.Equals(expectedTallyResult))
|
|
|
|
}
|