migrate TestTallyNoOneVotes to use simapp
This commit is contained in:
parent
80bfd0d2dc
commit
8c0d32c8a8
|
@ -3,6 +3,13 @@ package keeper_test
|
|||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/simapp/codec"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
)
|
||||
|
||||
|
@ -15,3 +22,38 @@ func ProposalEqual(proposalA types.Proposal, proposalB types.Proposal) bool {
|
|||
return bytes.Equal(types.ModuleCdc.MustMarshalBinaryBare(proposalA),
|
||||
types.ModuleCdc.MustMarshalBinaryBare(proposalB))
|
||||
}
|
||||
|
||||
func createValidators(ctx sdk.Context, app *simapp.SimApp, powers []int64) {
|
||||
addrs := simapp.AddTestAddrsIncremental(app, ctx, 3, sdk.NewInt(10000000))
|
||||
valAddrs := simapp.ConvertAddrsToValAddrs(addrs)
|
||||
pks := simapp.CreateTestPubKeys(3)
|
||||
|
||||
appCodec := codec.NewAppCodec(app.Codec())
|
||||
app.StakingKeeper = staking.NewKeeper(
|
||||
appCodec,
|
||||
app.GetKey(staking.StoreKey),
|
||||
app.BankKeeper,
|
||||
app.SupplyKeeper,
|
||||
app.GetSubspace(staking.ModuleName),
|
||||
)
|
||||
|
||||
val1 := staking.NewValidator(valAddrs[0], pks[0], staking.Description{})
|
||||
val2 := staking.NewValidator(valAddrs[1], pks[1], staking.Description{})
|
||||
val3 := staking.NewValidator(valAddrs[2], pks[2], staking.Description{})
|
||||
|
||||
app.StakingKeeper.SetValidator(ctx, val1)
|
||||
app.StakingKeeper.SetValidator(ctx, val2)
|
||||
app.StakingKeeper.SetValidator(ctx, val3)
|
||||
app.StakingKeeper.SetValidatorByConsAddr(ctx, val1)
|
||||
app.StakingKeeper.SetValidatorByConsAddr(ctx, val2)
|
||||
app.StakingKeeper.SetValidatorByConsAddr(ctx, val3)
|
||||
app.StakingKeeper.SetNewValidatorByPowerIndex(ctx, val1)
|
||||
app.StakingKeeper.SetNewValidatorByPowerIndex(ctx, val2)
|
||||
app.StakingKeeper.SetNewValidatorByPowerIndex(ctx, val3)
|
||||
|
||||
_, _ = app.StakingKeeper.Delegate(ctx, addrs[0], sdk.TokensFromConsensusPower(powers[0]), sdk.Unbonded, val1, true)
|
||||
_, _ = app.StakingKeeper.Delegate(ctx, addrs[1], sdk.TokensFromConsensusPower(powers[1]), sdk.Unbonded, val2, true)
|
||||
_, _ = app.StakingKeeper.Delegate(ctx, addrs[2], sdk.TokensFromConsensusPower(powers[2]), sdk.Unbonded, val3, true)
|
||||
|
||||
_ = staking.EndBlocker(ctx, app.StakingKeeper)
|
||||
}
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
package keeper
|
|
@ -0,0 +1,416 @@
|
|||
package keeper
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||
)
|
||||
|
||||
func TestTallyNoQuorum(t *testing.T) {
|
||||
ctx, _, _, keeper, sk, _ := createTestInput(t, false, 100)
|
||||
createValidators(ctx, sk, []int64{2, 5, 0})
|
||||
|
||||
tp := TestProposal
|
||||
proposal, err := keeper.SubmitProposal(ctx, tp)
|
||||
require.NoError(t, err)
|
||||
proposalID := proposal.ProposalID
|
||||
proposal.Status = types.StatusVotingPeriod
|
||||
keeper.SetProposal(ctx, proposal)
|
||||
|
||||
err = keeper.AddVote(ctx, proposalID, TestAddrs[0], types.OptionYes)
|
||||
require.Nil(t, err)
|
||||
|
||||
proposal, ok := keeper.GetProposal(ctx, proposalID)
|
||||
require.True(t, ok)
|
||||
passes, burnDeposits, _ := keeper.Tally(ctx, proposal)
|
||||
require.False(t, passes)
|
||||
require.True(t, burnDeposits)
|
||||
}
|
||||
|
||||
func TestTallyOnlyValidatorsAllYes(t *testing.T) {
|
||||
ctx, _, _, keeper, sk, _ := createTestInput(t, false, 100)
|
||||
createValidators(ctx, sk, []int64{5, 5, 5})
|
||||
|
||||
tp := TestProposal
|
||||
proposal, err := keeper.SubmitProposal(ctx, tp)
|
||||
require.NoError(t, err)
|
||||
proposalID := proposal.ProposalID
|
||||
proposal.Status = types.StatusVotingPeriod
|
||||
keeper.SetProposal(ctx, proposal)
|
||||
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr1, types.OptionYes))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr2, types.OptionYes))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr3, types.OptionYes))
|
||||
|
||||
proposal, ok := keeper.GetProposal(ctx, proposalID)
|
||||
require.True(t, ok)
|
||||
passes, burnDeposits, tallyResults := keeper.Tally(ctx, proposal)
|
||||
|
||||
require.True(t, passes)
|
||||
require.False(t, burnDeposits)
|
||||
require.False(t, tallyResults.Equals(types.EmptyTallyResult()))
|
||||
}
|
||||
|
||||
func TestTallyOnlyValidators51No(t *testing.T) {
|
||||
ctx, _, _, keeper, sk, _ := createTestInput(t, false, 100)
|
||||
createValidators(ctx, sk, []int64{5, 6, 0})
|
||||
|
||||
tp := TestProposal
|
||||
proposal, err := keeper.SubmitProposal(ctx, tp)
|
||||
require.NoError(t, err)
|
||||
proposalID := proposal.ProposalID
|
||||
proposal.Status = types.StatusVotingPeriod
|
||||
keeper.SetProposal(ctx, proposal)
|
||||
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr1, types.OptionYes))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr2, types.OptionNo))
|
||||
|
||||
proposal, ok := keeper.GetProposal(ctx, proposalID)
|
||||
require.True(t, ok)
|
||||
passes, burnDeposits, _ := keeper.Tally(ctx, proposal)
|
||||
|
||||
require.False(t, passes)
|
||||
require.False(t, burnDeposits)
|
||||
}
|
||||
|
||||
func TestTallyOnlyValidators51Yes(t *testing.T) {
|
||||
ctx, _, _, keeper, sk, _ := createTestInput(t, false, 100)
|
||||
createValidators(ctx, sk, []int64{5, 6, 0})
|
||||
|
||||
tp := TestProposal
|
||||
proposal, err := keeper.SubmitProposal(ctx, tp)
|
||||
require.NoError(t, err)
|
||||
proposalID := proposal.ProposalID
|
||||
proposal.Status = types.StatusVotingPeriod
|
||||
keeper.SetProposal(ctx, proposal)
|
||||
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr1, types.OptionNo))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr2, types.OptionYes))
|
||||
|
||||
proposal, ok := keeper.GetProposal(ctx, proposalID)
|
||||
require.True(t, ok)
|
||||
passes, burnDeposits, tallyResults := keeper.Tally(ctx, proposal)
|
||||
|
||||
require.True(t, passes)
|
||||
require.False(t, burnDeposits)
|
||||
require.False(t, tallyResults.Equals(types.EmptyTallyResult()))
|
||||
}
|
||||
|
||||
func TestTallyOnlyValidatorsVetoed(t *testing.T) {
|
||||
ctx, _, _, keeper, sk, _ := createTestInput(t, false, 100)
|
||||
createValidators(ctx, sk, []int64{6, 6, 7})
|
||||
|
||||
tp := TestProposal
|
||||
proposal, err := keeper.SubmitProposal(ctx, tp)
|
||||
require.NoError(t, err)
|
||||
proposalID := proposal.ProposalID
|
||||
proposal.Status = types.StatusVotingPeriod
|
||||
keeper.SetProposal(ctx, proposal)
|
||||
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr1, types.OptionYes))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr2, types.OptionYes))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr3, types.OptionNoWithVeto))
|
||||
|
||||
proposal, ok := keeper.GetProposal(ctx, proposalID)
|
||||
require.True(t, ok)
|
||||
passes, burnDeposits, tallyResults := keeper.Tally(ctx, proposal)
|
||||
|
||||
require.False(t, passes)
|
||||
require.True(t, burnDeposits)
|
||||
require.False(t, tallyResults.Equals(types.EmptyTallyResult()))
|
||||
|
||||
}
|
||||
|
||||
func TestTallyOnlyValidatorsAbstainPasses(t *testing.T) {
|
||||
ctx, _, _, keeper, sk, _ := createTestInput(t, false, 100)
|
||||
createValidators(ctx, sk, []int64{6, 6, 7})
|
||||
|
||||
tp := TestProposal
|
||||
proposal, err := keeper.SubmitProposal(ctx, tp)
|
||||
require.NoError(t, err)
|
||||
proposalID := proposal.ProposalID
|
||||
proposal.Status = types.StatusVotingPeriod
|
||||
keeper.SetProposal(ctx, proposal)
|
||||
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr1, types.OptionAbstain))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr2, types.OptionNo))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr3, types.OptionYes))
|
||||
|
||||
proposal, ok := keeper.GetProposal(ctx, proposalID)
|
||||
require.True(t, ok)
|
||||
passes, burnDeposits, tallyResults := keeper.Tally(ctx, proposal)
|
||||
|
||||
require.True(t, passes)
|
||||
require.False(t, burnDeposits)
|
||||
require.False(t, tallyResults.Equals(types.EmptyTallyResult()))
|
||||
}
|
||||
|
||||
func TestTallyOnlyValidatorsAbstainFails(t *testing.T) {
|
||||
ctx, _, _, keeper, sk, _ := createTestInput(t, false, 100)
|
||||
createValidators(ctx, sk, []int64{6, 6, 7})
|
||||
|
||||
tp := TestProposal
|
||||
proposal, err := keeper.SubmitProposal(ctx, tp)
|
||||
require.NoError(t, err)
|
||||
proposalID := proposal.ProposalID
|
||||
proposal.Status = types.StatusVotingPeriod
|
||||
keeper.SetProposal(ctx, proposal)
|
||||
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr1, types.OptionAbstain))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr2, types.OptionYes))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr3, types.OptionNo))
|
||||
|
||||
proposal, ok := keeper.GetProposal(ctx, proposalID)
|
||||
require.True(t, ok)
|
||||
passes, burnDeposits, tallyResults := keeper.Tally(ctx, proposal)
|
||||
|
||||
require.False(t, passes)
|
||||
require.False(t, burnDeposits)
|
||||
require.False(t, tallyResults.Equals(types.EmptyTallyResult()))
|
||||
}
|
||||
|
||||
func TestTallyOnlyValidatorsNonVoter(t *testing.T) {
|
||||
ctx, _, _, keeper, sk, _ := createTestInput(t, false, 100)
|
||||
createValidators(ctx, sk, []int64{5, 6, 7})
|
||||
|
||||
tp := TestProposal
|
||||
proposal, err := keeper.SubmitProposal(ctx, tp)
|
||||
require.NoError(t, err)
|
||||
proposalID := proposal.ProposalID
|
||||
proposal.Status = types.StatusVotingPeriod
|
||||
keeper.SetProposal(ctx, proposal)
|
||||
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr1, types.OptionYes))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr2, types.OptionNo))
|
||||
|
||||
proposal, ok := keeper.GetProposal(ctx, proposalID)
|
||||
require.True(t, ok)
|
||||
passes, burnDeposits, tallyResults := keeper.Tally(ctx, proposal)
|
||||
|
||||
require.False(t, passes)
|
||||
require.False(t, burnDeposits)
|
||||
require.False(t, tallyResults.Equals(types.EmptyTallyResult()))
|
||||
}
|
||||
|
||||
func TestTallyDelgatorOverride(t *testing.T) {
|
||||
ctx, _, _, keeper, sk, _ := createTestInput(t, false, 100)
|
||||
createValidators(ctx, sk, []int64{5, 6, 7})
|
||||
|
||||
delTokens := sdk.TokensFromConsensusPower(30)
|
||||
val1, found := sk.GetValidator(ctx, valOpAddr1)
|
||||
require.True(t, found)
|
||||
|
||||
_, err := sk.Delegate(ctx, TestAddrs[0], delTokens, sdk.Unbonded, val1, true)
|
||||
require.NoError(t, err)
|
||||
|
||||
_ = staking.EndBlocker(ctx, sk)
|
||||
|
||||
tp := TestProposal
|
||||
proposal, err := keeper.SubmitProposal(ctx, tp)
|
||||
require.NoError(t, err)
|
||||
proposalID := proposal.ProposalID
|
||||
proposal.Status = types.StatusVotingPeriod
|
||||
keeper.SetProposal(ctx, proposal)
|
||||
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr1, types.OptionYes))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr2, types.OptionYes))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr3, types.OptionYes))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, TestAddrs[0], types.OptionNo))
|
||||
|
||||
proposal, ok := keeper.GetProposal(ctx, proposalID)
|
||||
require.True(t, ok)
|
||||
passes, burnDeposits, tallyResults := keeper.Tally(ctx, proposal)
|
||||
|
||||
require.False(t, passes)
|
||||
require.False(t, burnDeposits)
|
||||
require.False(t, tallyResults.Equals(types.EmptyTallyResult()))
|
||||
}
|
||||
|
||||
func TestTallyDelgatorInherit(t *testing.T) {
|
||||
ctx, _, _, keeper, sk, _ := createTestInput(t, false, 100)
|
||||
createValidators(ctx, sk, []int64{5, 6, 7})
|
||||
|
||||
delTokens := sdk.TokensFromConsensusPower(30)
|
||||
val3, found := sk.GetValidator(ctx, valOpAddr3)
|
||||
require.True(t, found)
|
||||
|
||||
_, err := sk.Delegate(ctx, TestAddrs[0], delTokens, sdk.Unbonded, val3, true)
|
||||
require.NoError(t, err)
|
||||
|
||||
_ = staking.EndBlocker(ctx, sk)
|
||||
|
||||
tp := TestProposal
|
||||
proposal, err := keeper.SubmitProposal(ctx, tp)
|
||||
require.NoError(t, err)
|
||||
proposalID := proposal.ProposalID
|
||||
proposal.Status = types.StatusVotingPeriod
|
||||
keeper.SetProposal(ctx, proposal)
|
||||
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr1, types.OptionNo))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr2, types.OptionNo))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr3, types.OptionYes))
|
||||
|
||||
proposal, ok := keeper.GetProposal(ctx, proposalID)
|
||||
require.True(t, ok)
|
||||
passes, burnDeposits, tallyResults := keeper.Tally(ctx, proposal)
|
||||
|
||||
require.True(t, passes)
|
||||
require.False(t, burnDeposits)
|
||||
require.False(t, tallyResults.Equals(types.EmptyTallyResult()))
|
||||
}
|
||||
|
||||
func TestTallyDelgatorMultipleOverride(t *testing.T) {
|
||||
ctx, _, _, keeper, sk, _ := createTestInput(t, false, 100)
|
||||
createValidators(ctx, sk, []int64{5, 6, 7})
|
||||
|
||||
delTokens := sdk.TokensFromConsensusPower(10)
|
||||
val1, found := sk.GetValidator(ctx, valOpAddr1)
|
||||
require.True(t, found)
|
||||
val2, found := sk.GetValidator(ctx, valOpAddr2)
|
||||
require.True(t, found)
|
||||
|
||||
_, err := sk.Delegate(ctx, TestAddrs[0], delTokens, sdk.Unbonded, val1, true)
|
||||
require.NoError(t, err)
|
||||
_, err = sk.Delegate(ctx, TestAddrs[0], delTokens, sdk.Unbonded, val2, true)
|
||||
require.NoError(t, err)
|
||||
|
||||
_ = staking.EndBlocker(ctx, sk)
|
||||
|
||||
tp := TestProposal
|
||||
proposal, err := keeper.SubmitProposal(ctx, tp)
|
||||
require.NoError(t, err)
|
||||
proposalID := proposal.ProposalID
|
||||
proposal.Status = types.StatusVotingPeriod
|
||||
keeper.SetProposal(ctx, proposal)
|
||||
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr1, types.OptionYes))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr2, types.OptionYes))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr3, types.OptionYes))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, TestAddrs[0], types.OptionNo))
|
||||
|
||||
proposal, ok := keeper.GetProposal(ctx, proposalID)
|
||||
require.True(t, ok)
|
||||
passes, burnDeposits, tallyResults := keeper.Tally(ctx, proposal)
|
||||
|
||||
require.False(t, passes)
|
||||
require.False(t, burnDeposits)
|
||||
require.False(t, tallyResults.Equals(types.EmptyTallyResult()))
|
||||
}
|
||||
|
||||
func TestTallyDelgatorMultipleInherit(t *testing.T) {
|
||||
ctx, _, _, keeper, sk, _ := createTestInput(t, false, 100)
|
||||
createValidators(ctx, sk, []int64{25, 6, 7})
|
||||
|
||||
delTokens := sdk.TokensFromConsensusPower(10)
|
||||
val2, found := sk.GetValidator(ctx, valOpAddr2)
|
||||
require.True(t, found)
|
||||
val3, found := sk.GetValidator(ctx, valOpAddr3)
|
||||
require.True(t, found)
|
||||
|
||||
_, err := sk.Delegate(ctx, TestAddrs[0], delTokens, sdk.Unbonded, val2, true)
|
||||
require.NoError(t, err)
|
||||
_, err = sk.Delegate(ctx, TestAddrs[0], delTokens, sdk.Unbonded, val3, true)
|
||||
require.NoError(t, err)
|
||||
|
||||
_ = staking.EndBlocker(ctx, sk)
|
||||
|
||||
tp := TestProposal
|
||||
proposal, err := keeper.SubmitProposal(ctx, tp)
|
||||
require.NoError(t, err)
|
||||
proposalID := proposal.ProposalID
|
||||
proposal.Status = types.StatusVotingPeriod
|
||||
keeper.SetProposal(ctx, proposal)
|
||||
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr1, types.OptionYes))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr2, types.OptionNo))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr3, types.OptionNo))
|
||||
|
||||
proposal, ok := keeper.GetProposal(ctx, proposalID)
|
||||
require.True(t, ok)
|
||||
passes, burnDeposits, tallyResults := keeper.Tally(ctx, proposal)
|
||||
|
||||
require.False(t, passes)
|
||||
require.False(t, burnDeposits)
|
||||
require.False(t, tallyResults.Equals(types.EmptyTallyResult()))
|
||||
}
|
||||
|
||||
func TestTallyJailedValidator(t *testing.T) {
|
||||
ctx, _, _, keeper, sk, _ := createTestInput(t, false, 100)
|
||||
createValidators(ctx, sk, []int64{25, 6, 7})
|
||||
|
||||
delTokens := sdk.TokensFromConsensusPower(10)
|
||||
val2, found := sk.GetValidator(ctx, valOpAddr2)
|
||||
require.True(t, found)
|
||||
val3, found := sk.GetValidator(ctx, valOpAddr3)
|
||||
require.True(t, found)
|
||||
|
||||
_, err := sk.Delegate(ctx, TestAddrs[0], delTokens, sdk.Unbonded, val2, true)
|
||||
require.NoError(t, err)
|
||||
_, err = sk.Delegate(ctx, TestAddrs[0], delTokens, sdk.Unbonded, val3, true)
|
||||
require.NoError(t, err)
|
||||
|
||||
_ = staking.EndBlocker(ctx, sk)
|
||||
|
||||
sk.Jail(ctx, sdk.ConsAddress(val2.GetConsPubKey().Address()))
|
||||
|
||||
tp := TestProposal
|
||||
proposal, err := keeper.SubmitProposal(ctx, tp)
|
||||
require.NoError(t, err)
|
||||
proposalID := proposal.ProposalID
|
||||
proposal.Status = types.StatusVotingPeriod
|
||||
keeper.SetProposal(ctx, proposal)
|
||||
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr1, types.OptionYes))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr2, types.OptionNo))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr3, types.OptionNo))
|
||||
|
||||
proposal, ok := keeper.GetProposal(ctx, proposalID)
|
||||
require.True(t, ok)
|
||||
passes, burnDeposits, tallyResults := keeper.Tally(ctx, proposal)
|
||||
|
||||
require.True(t, passes)
|
||||
require.False(t, burnDeposits)
|
||||
require.False(t, tallyResults.Equals(types.EmptyTallyResult()))
|
||||
}
|
||||
|
||||
func TestTallyValidatorMultipleDelegations(t *testing.T) {
|
||||
ctx, _, _, keeper, sk, _ := createTestInput(t, false, 100)
|
||||
createValidators(ctx, sk, []int64{10, 10, 10})
|
||||
|
||||
delTokens := sdk.TokensFromConsensusPower(10)
|
||||
val2, found := sk.GetValidator(ctx, valOpAddr2)
|
||||
require.True(t, found)
|
||||
|
||||
_, err := sk.Delegate(ctx, valAccAddr1, delTokens, sdk.Unbonded, val2, true)
|
||||
require.NoError(t, err)
|
||||
|
||||
tp := TestProposal
|
||||
proposal, err := keeper.SubmitProposal(ctx, tp)
|
||||
require.NoError(t, err)
|
||||
proposalID := proposal.ProposalID
|
||||
proposal.Status = types.StatusVotingPeriod
|
||||
keeper.SetProposal(ctx, proposal)
|
||||
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr1, types.OptionYes))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr2, types.OptionNo))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr3, types.OptionYes))
|
||||
|
||||
proposal, ok := keeper.GetProposal(ctx, proposalID)
|
||||
require.True(t, ok)
|
||||
passes, burnDeposits, tallyResults := keeper.Tally(ctx, proposal)
|
||||
|
||||
require.True(t, passes)
|
||||
require.False(t, burnDeposits)
|
||||
|
||||
expectedYes := sdk.TokensFromConsensusPower(30)
|
||||
expectedAbstain := sdk.TokensFromConsensusPower(0)
|
||||
expectedNo := sdk.TokensFromConsensusPower(10)
|
||||
expectedNoWithVeto := sdk.TokensFromConsensusPower(0)
|
||||
expectedTallyResult := types.NewTallyResult(expectedYes, expectedAbstain, expectedNo, expectedNoWithVeto)
|
||||
|
||||
require.True(t, tallyResults.Equals(expectedTallyResult))
|
||||
}
|
|
@ -1,436 +1,34 @@
|
|||
package keeper
|
||||
package keeper_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||
)
|
||||
|
||||
func TestTallyNoOneVotes(t *testing.T) {
|
||||
ctx, _, _, keeper, sk, _ := createTestInput(t, false, 100)
|
||||
createValidators(ctx, sk, []int64{5, 5, 5})
|
||||
app := simapp.Setup(false)
|
||||
ctx := app.BaseApp.NewContext(false, abci.Header{})
|
||||
|
||||
createValidators(ctx, app, []int64{5, 5, 5})
|
||||
|
||||
tp := TestProposal
|
||||
proposal, err := keeper.SubmitProposal(ctx, tp)
|
||||
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
|
||||
require.NoError(t, err)
|
||||
proposalID := proposal.ProposalID
|
||||
proposal.Status = types.StatusVotingPeriod
|
||||
keeper.SetProposal(ctx, proposal)
|
||||
app.GovKeeper.SetProposal(ctx, proposal)
|
||||
|
||||
proposal, ok := keeper.GetProposal(ctx, proposalID)
|
||||
proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
|
||||
require.True(t, ok)
|
||||
passes, burnDeposits, tallyResults := keeper.Tally(ctx, proposal)
|
||||
passes, burnDeposits, tallyResults := app.GovKeeper.Tally(ctx, proposal)
|
||||
|
||||
require.False(t, passes)
|
||||
require.True(t, burnDeposits)
|
||||
require.True(t, tallyResults.Equals(types.EmptyTallyResult()))
|
||||
}
|
||||
|
||||
func TestTallyNoQuorum(t *testing.T) {
|
||||
ctx, _, _, keeper, sk, _ := createTestInput(t, false, 100)
|
||||
createValidators(ctx, sk, []int64{2, 5, 0})
|
||||
|
||||
tp := TestProposal
|
||||
proposal, err := keeper.SubmitProposal(ctx, tp)
|
||||
require.NoError(t, err)
|
||||
proposalID := proposal.ProposalID
|
||||
proposal.Status = types.StatusVotingPeriod
|
||||
keeper.SetProposal(ctx, proposal)
|
||||
|
||||
err = keeper.AddVote(ctx, proposalID, TestAddrs[0], types.OptionYes)
|
||||
require.Nil(t, err)
|
||||
|
||||
proposal, ok := keeper.GetProposal(ctx, proposalID)
|
||||
require.True(t, ok)
|
||||
passes, burnDeposits, _ := keeper.Tally(ctx, proposal)
|
||||
require.False(t, passes)
|
||||
require.True(t, burnDeposits)
|
||||
}
|
||||
|
||||
func TestTallyOnlyValidatorsAllYes(t *testing.T) {
|
||||
ctx, _, _, keeper, sk, _ := createTestInput(t, false, 100)
|
||||
createValidators(ctx, sk, []int64{5, 5, 5})
|
||||
|
||||
tp := TestProposal
|
||||
proposal, err := keeper.SubmitProposal(ctx, tp)
|
||||
require.NoError(t, err)
|
||||
proposalID := proposal.ProposalID
|
||||
proposal.Status = types.StatusVotingPeriod
|
||||
keeper.SetProposal(ctx, proposal)
|
||||
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr1, types.OptionYes))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr2, types.OptionYes))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr3, types.OptionYes))
|
||||
|
||||
proposal, ok := keeper.GetProposal(ctx, proposalID)
|
||||
require.True(t, ok)
|
||||
passes, burnDeposits, tallyResults := keeper.Tally(ctx, proposal)
|
||||
|
||||
require.True(t, passes)
|
||||
require.False(t, burnDeposits)
|
||||
require.False(t, tallyResults.Equals(types.EmptyTallyResult()))
|
||||
}
|
||||
|
||||
func TestTallyOnlyValidators51No(t *testing.T) {
|
||||
ctx, _, _, keeper, sk, _ := createTestInput(t, false, 100)
|
||||
createValidators(ctx, sk, []int64{5, 6, 0})
|
||||
|
||||
tp := TestProposal
|
||||
proposal, err := keeper.SubmitProposal(ctx, tp)
|
||||
require.NoError(t, err)
|
||||
proposalID := proposal.ProposalID
|
||||
proposal.Status = types.StatusVotingPeriod
|
||||
keeper.SetProposal(ctx, proposal)
|
||||
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr1, types.OptionYes))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr2, types.OptionNo))
|
||||
|
||||
proposal, ok := keeper.GetProposal(ctx, proposalID)
|
||||
require.True(t, ok)
|
||||
passes, burnDeposits, _ := keeper.Tally(ctx, proposal)
|
||||
|
||||
require.False(t, passes)
|
||||
require.False(t, burnDeposits)
|
||||
}
|
||||
|
||||
func TestTallyOnlyValidators51Yes(t *testing.T) {
|
||||
ctx, _, _, keeper, sk, _ := createTestInput(t, false, 100)
|
||||
createValidators(ctx, sk, []int64{5, 6, 0})
|
||||
|
||||
tp := TestProposal
|
||||
proposal, err := keeper.SubmitProposal(ctx, tp)
|
||||
require.NoError(t, err)
|
||||
proposalID := proposal.ProposalID
|
||||
proposal.Status = types.StatusVotingPeriod
|
||||
keeper.SetProposal(ctx, proposal)
|
||||
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr1, types.OptionNo))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr2, types.OptionYes))
|
||||
|
||||
proposal, ok := keeper.GetProposal(ctx, proposalID)
|
||||
require.True(t, ok)
|
||||
passes, burnDeposits, tallyResults := keeper.Tally(ctx, proposal)
|
||||
|
||||
require.True(t, passes)
|
||||
require.False(t, burnDeposits)
|
||||
require.False(t, tallyResults.Equals(types.EmptyTallyResult()))
|
||||
}
|
||||
|
||||
func TestTallyOnlyValidatorsVetoed(t *testing.T) {
|
||||
ctx, _, _, keeper, sk, _ := createTestInput(t, false, 100)
|
||||
createValidators(ctx, sk, []int64{6, 6, 7})
|
||||
|
||||
tp := TestProposal
|
||||
proposal, err := keeper.SubmitProposal(ctx, tp)
|
||||
require.NoError(t, err)
|
||||
proposalID := proposal.ProposalID
|
||||
proposal.Status = types.StatusVotingPeriod
|
||||
keeper.SetProposal(ctx, proposal)
|
||||
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr1, types.OptionYes))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr2, types.OptionYes))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr3, types.OptionNoWithVeto))
|
||||
|
||||
proposal, ok := keeper.GetProposal(ctx, proposalID)
|
||||
require.True(t, ok)
|
||||
passes, burnDeposits, tallyResults := keeper.Tally(ctx, proposal)
|
||||
|
||||
require.False(t, passes)
|
||||
require.True(t, burnDeposits)
|
||||
require.False(t, tallyResults.Equals(types.EmptyTallyResult()))
|
||||
|
||||
}
|
||||
|
||||
func TestTallyOnlyValidatorsAbstainPasses(t *testing.T) {
|
||||
ctx, _, _, keeper, sk, _ := createTestInput(t, false, 100)
|
||||
createValidators(ctx, sk, []int64{6, 6, 7})
|
||||
|
||||
tp := TestProposal
|
||||
proposal, err := keeper.SubmitProposal(ctx, tp)
|
||||
require.NoError(t, err)
|
||||
proposalID := proposal.ProposalID
|
||||
proposal.Status = types.StatusVotingPeriod
|
||||
keeper.SetProposal(ctx, proposal)
|
||||
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr1, types.OptionAbstain))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr2, types.OptionNo))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr3, types.OptionYes))
|
||||
|
||||
proposal, ok := keeper.GetProposal(ctx, proposalID)
|
||||
require.True(t, ok)
|
||||
passes, burnDeposits, tallyResults := keeper.Tally(ctx, proposal)
|
||||
|
||||
require.True(t, passes)
|
||||
require.False(t, burnDeposits)
|
||||
require.False(t, tallyResults.Equals(types.EmptyTallyResult()))
|
||||
}
|
||||
|
||||
func TestTallyOnlyValidatorsAbstainFails(t *testing.T) {
|
||||
ctx, _, _, keeper, sk, _ := createTestInput(t, false, 100)
|
||||
createValidators(ctx, sk, []int64{6, 6, 7})
|
||||
|
||||
tp := TestProposal
|
||||
proposal, err := keeper.SubmitProposal(ctx, tp)
|
||||
require.NoError(t, err)
|
||||
proposalID := proposal.ProposalID
|
||||
proposal.Status = types.StatusVotingPeriod
|
||||
keeper.SetProposal(ctx, proposal)
|
||||
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr1, types.OptionAbstain))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr2, types.OptionYes))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr3, types.OptionNo))
|
||||
|
||||
proposal, ok := keeper.GetProposal(ctx, proposalID)
|
||||
require.True(t, ok)
|
||||
passes, burnDeposits, tallyResults := keeper.Tally(ctx, proposal)
|
||||
|
||||
require.False(t, passes)
|
||||
require.False(t, burnDeposits)
|
||||
require.False(t, tallyResults.Equals(types.EmptyTallyResult()))
|
||||
}
|
||||
|
||||
func TestTallyOnlyValidatorsNonVoter(t *testing.T) {
|
||||
ctx, _, _, keeper, sk, _ := createTestInput(t, false, 100)
|
||||
createValidators(ctx, sk, []int64{5, 6, 7})
|
||||
|
||||
tp := TestProposal
|
||||
proposal, err := keeper.SubmitProposal(ctx, tp)
|
||||
require.NoError(t, err)
|
||||
proposalID := proposal.ProposalID
|
||||
proposal.Status = types.StatusVotingPeriod
|
||||
keeper.SetProposal(ctx, proposal)
|
||||
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr1, types.OptionYes))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr2, types.OptionNo))
|
||||
|
||||
proposal, ok := keeper.GetProposal(ctx, proposalID)
|
||||
require.True(t, ok)
|
||||
passes, burnDeposits, tallyResults := keeper.Tally(ctx, proposal)
|
||||
|
||||
require.False(t, passes)
|
||||
require.False(t, burnDeposits)
|
||||
require.False(t, tallyResults.Equals(types.EmptyTallyResult()))
|
||||
}
|
||||
|
||||
func TestTallyDelgatorOverride(t *testing.T) {
|
||||
ctx, _, _, keeper, sk, _ := createTestInput(t, false, 100)
|
||||
createValidators(ctx, sk, []int64{5, 6, 7})
|
||||
|
||||
delTokens := sdk.TokensFromConsensusPower(30)
|
||||
val1, found := sk.GetValidator(ctx, valOpAddr1)
|
||||
require.True(t, found)
|
||||
|
||||
_, err := sk.Delegate(ctx, TestAddrs[0], delTokens, sdk.Unbonded, val1, true)
|
||||
require.NoError(t, err)
|
||||
|
||||
_ = staking.EndBlocker(ctx, sk)
|
||||
|
||||
tp := TestProposal
|
||||
proposal, err := keeper.SubmitProposal(ctx, tp)
|
||||
require.NoError(t, err)
|
||||
proposalID := proposal.ProposalID
|
||||
proposal.Status = types.StatusVotingPeriod
|
||||
keeper.SetProposal(ctx, proposal)
|
||||
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr1, types.OptionYes))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr2, types.OptionYes))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr3, types.OptionYes))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, TestAddrs[0], types.OptionNo))
|
||||
|
||||
proposal, ok := keeper.GetProposal(ctx, proposalID)
|
||||
require.True(t, ok)
|
||||
passes, burnDeposits, tallyResults := keeper.Tally(ctx, proposal)
|
||||
|
||||
require.False(t, passes)
|
||||
require.False(t, burnDeposits)
|
||||
require.False(t, tallyResults.Equals(types.EmptyTallyResult()))
|
||||
}
|
||||
|
||||
func TestTallyDelgatorInherit(t *testing.T) {
|
||||
ctx, _, _, keeper, sk, _ := createTestInput(t, false, 100)
|
||||
createValidators(ctx, sk, []int64{5, 6, 7})
|
||||
|
||||
delTokens := sdk.TokensFromConsensusPower(30)
|
||||
val3, found := sk.GetValidator(ctx, valOpAddr3)
|
||||
require.True(t, found)
|
||||
|
||||
_, err := sk.Delegate(ctx, TestAddrs[0], delTokens, sdk.Unbonded, val3, true)
|
||||
require.NoError(t, err)
|
||||
|
||||
_ = staking.EndBlocker(ctx, sk)
|
||||
|
||||
tp := TestProposal
|
||||
proposal, err := keeper.SubmitProposal(ctx, tp)
|
||||
require.NoError(t, err)
|
||||
proposalID := proposal.ProposalID
|
||||
proposal.Status = types.StatusVotingPeriod
|
||||
keeper.SetProposal(ctx, proposal)
|
||||
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr1, types.OptionNo))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr2, types.OptionNo))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr3, types.OptionYes))
|
||||
|
||||
proposal, ok := keeper.GetProposal(ctx, proposalID)
|
||||
require.True(t, ok)
|
||||
passes, burnDeposits, tallyResults := keeper.Tally(ctx, proposal)
|
||||
|
||||
require.True(t, passes)
|
||||
require.False(t, burnDeposits)
|
||||
require.False(t, tallyResults.Equals(types.EmptyTallyResult()))
|
||||
}
|
||||
|
||||
func TestTallyDelgatorMultipleOverride(t *testing.T) {
|
||||
ctx, _, _, keeper, sk, _ := createTestInput(t, false, 100)
|
||||
createValidators(ctx, sk, []int64{5, 6, 7})
|
||||
|
||||
delTokens := sdk.TokensFromConsensusPower(10)
|
||||
val1, found := sk.GetValidator(ctx, valOpAddr1)
|
||||
require.True(t, found)
|
||||
val2, found := sk.GetValidator(ctx, valOpAddr2)
|
||||
require.True(t, found)
|
||||
|
||||
_, err := sk.Delegate(ctx, TestAddrs[0], delTokens, sdk.Unbonded, val1, true)
|
||||
require.NoError(t, err)
|
||||
_, err = sk.Delegate(ctx, TestAddrs[0], delTokens, sdk.Unbonded, val2, true)
|
||||
require.NoError(t, err)
|
||||
|
||||
_ = staking.EndBlocker(ctx, sk)
|
||||
|
||||
tp := TestProposal
|
||||
proposal, err := keeper.SubmitProposal(ctx, tp)
|
||||
require.NoError(t, err)
|
||||
proposalID := proposal.ProposalID
|
||||
proposal.Status = types.StatusVotingPeriod
|
||||
keeper.SetProposal(ctx, proposal)
|
||||
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr1, types.OptionYes))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr2, types.OptionYes))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr3, types.OptionYes))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, TestAddrs[0], types.OptionNo))
|
||||
|
||||
proposal, ok := keeper.GetProposal(ctx, proposalID)
|
||||
require.True(t, ok)
|
||||
passes, burnDeposits, tallyResults := keeper.Tally(ctx, proposal)
|
||||
|
||||
require.False(t, passes)
|
||||
require.False(t, burnDeposits)
|
||||
require.False(t, tallyResults.Equals(types.EmptyTallyResult()))
|
||||
}
|
||||
|
||||
func TestTallyDelgatorMultipleInherit(t *testing.T) {
|
||||
ctx, _, _, keeper, sk, _ := createTestInput(t, false, 100)
|
||||
createValidators(ctx, sk, []int64{25, 6, 7})
|
||||
|
||||
delTokens := sdk.TokensFromConsensusPower(10)
|
||||
val2, found := sk.GetValidator(ctx, valOpAddr2)
|
||||
require.True(t, found)
|
||||
val3, found := sk.GetValidator(ctx, valOpAddr3)
|
||||
require.True(t, found)
|
||||
|
||||
_, err := sk.Delegate(ctx, TestAddrs[0], delTokens, sdk.Unbonded, val2, true)
|
||||
require.NoError(t, err)
|
||||
_, err = sk.Delegate(ctx, TestAddrs[0], delTokens, sdk.Unbonded, val3, true)
|
||||
require.NoError(t, err)
|
||||
|
||||
_ = staking.EndBlocker(ctx, sk)
|
||||
|
||||
tp := TestProposal
|
||||
proposal, err := keeper.SubmitProposal(ctx, tp)
|
||||
require.NoError(t, err)
|
||||
proposalID := proposal.ProposalID
|
||||
proposal.Status = types.StatusVotingPeriod
|
||||
keeper.SetProposal(ctx, proposal)
|
||||
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr1, types.OptionYes))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr2, types.OptionNo))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr3, types.OptionNo))
|
||||
|
||||
proposal, ok := keeper.GetProposal(ctx, proposalID)
|
||||
require.True(t, ok)
|
||||
passes, burnDeposits, tallyResults := keeper.Tally(ctx, proposal)
|
||||
|
||||
require.False(t, passes)
|
||||
require.False(t, burnDeposits)
|
||||
require.False(t, tallyResults.Equals(types.EmptyTallyResult()))
|
||||
}
|
||||
|
||||
func TestTallyJailedValidator(t *testing.T) {
|
||||
ctx, _, _, keeper, sk, _ := createTestInput(t, false, 100)
|
||||
createValidators(ctx, sk, []int64{25, 6, 7})
|
||||
|
||||
delTokens := sdk.TokensFromConsensusPower(10)
|
||||
val2, found := sk.GetValidator(ctx, valOpAddr2)
|
||||
require.True(t, found)
|
||||
val3, found := sk.GetValidator(ctx, valOpAddr3)
|
||||
require.True(t, found)
|
||||
|
||||
_, err := sk.Delegate(ctx, TestAddrs[0], delTokens, sdk.Unbonded, val2, true)
|
||||
require.NoError(t, err)
|
||||
_, err = sk.Delegate(ctx, TestAddrs[0], delTokens, sdk.Unbonded, val3, true)
|
||||
require.NoError(t, err)
|
||||
|
||||
_ = staking.EndBlocker(ctx, sk)
|
||||
|
||||
sk.Jail(ctx, sdk.ConsAddress(val2.GetConsPubKey().Address()))
|
||||
|
||||
tp := TestProposal
|
||||
proposal, err := keeper.SubmitProposal(ctx, tp)
|
||||
require.NoError(t, err)
|
||||
proposalID := proposal.ProposalID
|
||||
proposal.Status = types.StatusVotingPeriod
|
||||
keeper.SetProposal(ctx, proposal)
|
||||
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr1, types.OptionYes))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr2, types.OptionNo))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr3, types.OptionNo))
|
||||
|
||||
proposal, ok := keeper.GetProposal(ctx, proposalID)
|
||||
require.True(t, ok)
|
||||
passes, burnDeposits, tallyResults := keeper.Tally(ctx, proposal)
|
||||
|
||||
require.True(t, passes)
|
||||
require.False(t, burnDeposits)
|
||||
require.False(t, tallyResults.Equals(types.EmptyTallyResult()))
|
||||
}
|
||||
|
||||
func TestTallyValidatorMultipleDelegations(t *testing.T) {
|
||||
ctx, _, _, keeper, sk, _ := createTestInput(t, false, 100)
|
||||
createValidators(ctx, sk, []int64{10, 10, 10})
|
||||
|
||||
delTokens := sdk.TokensFromConsensusPower(10)
|
||||
val2, found := sk.GetValidator(ctx, valOpAddr2)
|
||||
require.True(t, found)
|
||||
|
||||
_, err := sk.Delegate(ctx, valAccAddr1, delTokens, sdk.Unbonded, val2, true)
|
||||
require.NoError(t, err)
|
||||
|
||||
tp := TestProposal
|
||||
proposal, err := keeper.SubmitProposal(ctx, tp)
|
||||
require.NoError(t, err)
|
||||
proposalID := proposal.ProposalID
|
||||
proposal.Status = types.StatusVotingPeriod
|
||||
keeper.SetProposal(ctx, proposal)
|
||||
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr1, types.OptionYes))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr2, types.OptionNo))
|
||||
require.NoError(t, keeper.AddVote(ctx, proposalID, valAccAddr3, types.OptionYes))
|
||||
|
||||
proposal, ok := keeper.GetProposal(ctx, proposalID)
|
||||
require.True(t, ok)
|
||||
passes, burnDeposits, tallyResults := keeper.Tally(ctx, proposal)
|
||||
|
||||
require.True(t, passes)
|
||||
require.False(t, burnDeposits)
|
||||
|
||||
expectedYes := sdk.TokensFromConsensusPower(30)
|
||||
expectedAbstain := sdk.TokensFromConsensusPower(0)
|
||||
expectedNo := sdk.TokensFromConsensusPower(10)
|
||||
expectedNoWithVeto := sdk.TokensFromConsensusPower(0)
|
||||
expectedTallyResult := types.NewTallyResult(expectedYes, expectedAbstain, expectedNo, expectedNoWithVeto)
|
||||
|
||||
require.True(t, tallyResults.Equals(expectedTallyResult))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue