From e0460dd60683366a1760774da5e6fb408bf365cb Mon Sep 17 00:00:00 2001 From: Adam Hanna Date: Tue, 3 Sep 2024 12:12:16 -0700 Subject: [PATCH 1/2] adds test --- x/gov/keeper/tally_test.go | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/x/gov/keeper/tally_test.go b/x/gov/keeper/tally_test.go index 29cabb1c..9c08f223 100644 --- a/x/gov/keeper/tally_test.go +++ b/x/gov/keeper/tally_test.go @@ -52,6 +52,7 @@ func newTallyFixture(t *testing.T, ctx sdk.Context, proposal v1.Proposal, keeper: govKeeper, mocks: mocks, } + mocks.stakingKeeper.EXPECT().TotalBondedTokens(gomock.Any()). DoAndReturn(func(_ context.Context) sdkmath.Int { return sdkmath.NewInt(s.totalBonded) @@ -381,3 +382,42 @@ func TestTally(t *testing.T) { }) } } + +func TestTally_SelfDelegation(t *testing.T) { + // Set up test data + numVals := 10 + numDelegators := 5 + addrs := simtestutil.CreateRandomAccounts(numVals + numDelegators) + valAddrs := simtestutil.ConvertAddrsToValAddrs(addrs[:numVals]) + delAddrs := addrs[numVals:] + + govKeeper, mocks, _, ctx := setupGovKeeper(t, mockAccountKeeperExpectations) + params := v1.DefaultParams() + // Ensure params value are different than false + params.BurnVoteQuorum = true + params.BurnVoteVeto = true + err := govKeeper.SetParams(ctx, params) + require.NoError(t, err) + + proposal, err := govKeeper.SubmitProposal(ctx, TestProposal, "", "title", "summary", delAddrs[1]) + require.NoError(t, err) + govKeeper.ActivateVotingPeriod(ctx, proposal) + + // Create a new tally fixture with self-delegation + s := newTallyFixture(t, ctx, proposal, valAddrs, delAddrs, govKeeper, mocks) + + s.delegate(s.delAddrs[0], s.valAddrs[0], 10) // delegate tokens + + // Vote + voteOption := v1.VoteOption_VOTE_OPTION_YES + s.vote(delAddrs[0], voteOption) + s.validatorVote(s.valAddrs[0], voteOption) + + // Call Tally + pass, burn, tally := s.keeper.Tally(ctx, proposal) + + // Assert expected results + assert.True(t, pass) + assert.False(t, burn) + assert.Equal(t, v1.TallyResult{YesCount: "11", AbstainCount: "0", NoCount: "0", NoWithVetoCount: "0"}, tally) +} From ba1b5c19e0d6d348246fdd9e7704fee264e2ce83 Mon Sep 17 00:00:00 2001 From: Adam Hanna Date: Tue, 3 Sep 2024 12:13:35 -0700 Subject: [PATCH 2/2] change name --- x/gov/keeper/tally_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/gov/keeper/tally_test.go b/x/gov/keeper/tally_test.go index 9c08f223..5ca92dcd 100644 --- a/x/gov/keeper/tally_test.go +++ b/x/gov/keeper/tally_test.go @@ -383,7 +383,7 @@ func TestTally(t *testing.T) { } } -func TestTally_SelfDelegation(t *testing.T) { +func TestTally_Delegation(t *testing.T) { // Set up test data numVals := 10 numDelegators := 5