Skip to content

Commit

Permalink
add TestTallyJailedValidator to simapp
Browse files Browse the repository at this point in the history
  • Loading branch information
jgimeno committed Mar 2, 2020
1 parent 7d34306 commit 275b78f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 40 deletions.
40 changes: 0 additions & 40 deletions x/gov/keeper/old_tally_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,8 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/staking"
)

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})
Expand Down
41 changes: 41 additions & 0 deletions x/gov/keeper/tally_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,3 +391,44 @@ func TestTallyDelgatorMultipleInherit(t *testing.T) {
require.False(t, burnDeposits)
require.False(t, tallyResults.Equals(types.EmptyTallyResult()))
}

func TestTallyJailedValidator(t *testing.T) {
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, abci.Header{})

addrs, valAddrs := createValidators(ctx, app, []int64{25, 6, 7})

delTokens := sdk.TokensFromConsensusPower(10)
val2, found := app.StakingKeeper.GetValidator(ctx, valAddrs[1])
require.True(t, found)
val3, found := app.StakingKeeper.GetValidator(ctx, valAddrs[2])
require.True(t, found)

_, err := app.StakingKeeper.Delegate(ctx, addrs[3], delTokens, sdk.Unbonded, val2, true)
require.NoError(t, err)
_, err = app.StakingKeeper.Delegate(ctx, addrs[3], delTokens, sdk.Unbonded, val3, true)
require.NoError(t, err)

_ = staking.EndBlocker(ctx, app.StakingKeeper)

app.StakingKeeper.Jail(ctx, sdk.ConsAddress(val2.GetConsPubKey().Address()))

tp := TestProposal
proposal, err := app.GovKeeper.SubmitProposal(ctx, tp)
require.NoError(t, err)
proposalID := proposal.ProposalID
proposal.Status = types.StatusVotingPeriod
app.GovKeeper.SetProposal(ctx, proposal)

require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[0], types.OptionYes))
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[1], types.OptionNo))
require.NoError(t, app.GovKeeper.AddVote(ctx, proposalID, addrs[2], types.OptionNo))

proposal, ok := app.GovKeeper.GetProposal(ctx, proposalID)
require.True(t, ok)
passes, burnDeposits, tallyResults := app.GovKeeper.Tally(ctx, proposal)

require.True(t, passes)
require.False(t, burnDeposits)
require.False(t, tallyResults.Equals(types.EmptyTallyResult()))
}

0 comments on commit 275b78f

Please sign in to comment.