Skip to content

Commit

Permalink
test: re-enable vote inheritance and improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tbruyelle committed Feb 21, 2024
1 parent 4bd0d82 commit e257af4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 14 deletions.
4 changes: 0 additions & 4 deletions x/gov/keeper/tally.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ func (keeper Keeper) Tally(ctx sdk.Context, proposal types.Proposal) (passes boo
return false
})

/* DISABLED on GovGen - Voting can only be done with your own stake
// iterate over the validators again to tally their voting power
for _, val := range currValidators {
if len(val.Vote) == 0 {
Expand All @@ -89,8 +87,6 @@ func (keeper Keeper) Tally(ctx sdk.Context, proposal types.Proposal) (passes boo
totalVotingPower = totalVotingPower.Add(votingPower)
}

*/

tallyParams := keeper.GetTallyParams(ctx)
tallyResults = types.NewTallyResultFromMap(results)

Expand Down
51 changes: 41 additions & 10 deletions x/gov/keeper/tally_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ func TestTallyDelgatorInherit(t *testing.T) {
app := govgenhelpers.SetupNoValset(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})

addrs, vals := createValidators(t, ctx, app, []int64{5, 6, 7})
valPowers := []int64{5, 6, 7}
addrs, vals := createValidators(t, ctx, app, valPowers)

delTokens := app.StakingKeeper.TokensFromConsensusPower(ctx, 30)
val3, found := app.StakingKeeper.GetValidator(ctx, vals[2])
Expand All @@ -307,16 +308,27 @@ func TestTallyDelgatorInherit(t *testing.T) {
require.True(t, ok)
passes, burnDeposits, tallyResults := app.GovKeeper.Tally(ctx, proposal)

require.False(t, passes)
require.True(t, passes)
require.False(t, burnDeposits)
require.False(t, tallyResults.Equals(types.EmptyTallyResult()))
valSelfDelegations := []sdk.Int{
app.StakingKeeper.TokensFromConsensusPower(ctx, valPowers[0]),
app.StakingKeeper.TokensFromConsensusPower(ctx, valPowers[1]),
app.StakingKeeper.TokensFromConsensusPower(ctx, valPowers[2]),
}
require.Equal(t, tallyResults.String(), types.NewTallyResult(
valSelfDelegations[2].Add(delTokens),
sdk.ZeroInt(),
valSelfDelegations[0].Add(valSelfDelegations[1]),
sdk.ZeroInt(),
).String())
}

func TestTallyDelgatorMultipleOverride(t *testing.T) {
app := govgenhelpers.SetupNoValset(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})

addrs, vals := createValidators(t, ctx, app, []int64{5, 6, 7})
valPowers := []int64{5, 6, 7}
addrs, vals := createValidators(t, ctx, app, valPowers)

delTokens := app.StakingKeeper.TokensFromConsensusPower(ctx, 10)
val1, found := app.StakingKeeper.GetValidator(ctx, vals[0])
Expand Down Expand Up @@ -349,7 +361,17 @@ func TestTallyDelgatorMultipleOverride(t *testing.T) {

require.False(t, passes)
require.False(t, burnDeposits)
require.False(t, tallyResults.Equals(types.EmptyTallyResult()))
valSelfDelegations := []sdk.Int{
app.StakingKeeper.TokensFromConsensusPower(ctx, valPowers[0]),
app.StakingKeeper.TokensFromConsensusPower(ctx, valPowers[1]),
app.StakingKeeper.TokensFromConsensusPower(ctx, valPowers[2]),
}
require.Equal(t, tallyResults.String(), types.NewTallyResult(
valSelfDelegations[0].Add(valSelfDelegations[1]).Add(valSelfDelegations[2]),
sdk.ZeroInt(),
delTokens.Add(delTokens),
sdk.ZeroInt(),
).String())
}

// As validators can only vote with their own stake, delegators don't inherit votes from validators
Expand All @@ -358,9 +380,8 @@ func TestTallyDelgatorMultipleInherit(t *testing.T) {
app := govgenhelpers.SetupNoValset(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})

createValidators(t, ctx, app, []int64{25, 6, 7})

addrs, vals := createValidators(t, ctx, app, []int64{5, 6, 7})
valPowers := []int64{5, 6, 7}
addrs, vals := createValidators(t, ctx, app, valPowers)

delTokens := app.StakingKeeper.TokensFromConsensusPower(ctx, 10)
val2, found := app.StakingKeeper.GetValidator(ctx, vals[1])
Expand Down Expand Up @@ -390,9 +411,19 @@ func TestTallyDelgatorMultipleInherit(t *testing.T) {
require.True(t, ok)
passes, burnDeposits, tallyResults := app.GovKeeper.Tally(ctx, proposal)

require.True(t, passes)
require.False(t, passes)
require.False(t, burnDeposits)
require.False(t, tallyResults.Equals(types.EmptyTallyResult()))
valSelfDelegations := []sdk.Int{
app.StakingKeeper.TokensFromConsensusPower(ctx, valPowers[0]),
app.StakingKeeper.TokensFromConsensusPower(ctx, valPowers[1]),
app.StakingKeeper.TokensFromConsensusPower(ctx, valPowers[2]),
}
require.Equal(t, tallyResults.String(), types.NewTallyResult(
valSelfDelegations[0],
sdk.ZeroInt(),
valSelfDelegations[1].Add(valSelfDelegations[2]).Add(delTokens).Add(delTokens),
sdk.ZeroInt(),
).String())
}

func TestTallyJailedValidator(t *testing.T) {
Expand Down

0 comments on commit e257af4

Please sign in to comment.