diff --git a/x/upgrade/integration_test.go b/x/upgrade/integration_test.go index 1f61b9db69..1ef940e5f5 100644 --- a/x/upgrade/integration_test.go +++ b/x/upgrade/integration_test.go @@ -14,6 +14,9 @@ import ( tmversion "github.com/tendermint/tendermint/proto/tendermint/version" ) +// TestUpgradeIntegration uses the real application including the upgrade keeper (and staking keeper). It +// simulates an upgrade scenario with a single validator which signals for the version change, checks the quorum +// has been reached and then calls TryUpgrade, asserting that the upgrade module returns the new app version func TestUpgradeIntegration(t *testing.T) { app, _ := testutil.SetupTestAppWithGenesisValSet(app.DefaultConsensusParams()) ctx := sdk.NewContext(app.CommitMultiStore(), tmtypes.Header{ diff --git a/x/upgrade/tally_test.go b/x/upgrade/tally_test.go index 474c4c2fbc..c172180bd2 100644 --- a/x/upgrade/tally_test.go +++ b/x/upgrade/tally_test.go @@ -139,6 +139,7 @@ func TestTallyingLogic(t *testing.T) { // remove one of the validators from the set delete(mockStakingKeeper.validators, testutil.ValAddrs[1].String()) + // the validator had 1 voting power, so we deduct it from the total mockStakingKeeper.totalVotingPower-- res, err = upgradeKeeper.VersionTally(goCtx, &types.QueryVersionTallyRequest{ @@ -176,6 +177,7 @@ func TestEmptyStore(t *testing.T) { }) require.NoError(t, err) require.EqualValues(t, 0, res.VotingPower) + // 120 is the summation in voting power of the four validators require.EqualValues(t, 120, res.TotalVotingPower) } @@ -191,15 +193,14 @@ func setup(t *testing.T) (upgrade.Keeper, sdk.Context, *mockStakingKeeper) { App: 1, }, }, false, log.NewNopLogger()) - mockStakingKeeper := &mockStakingKeeper{ - totalVotingPower: 120, - validators: map[string]int64{ + mockStakingKeeper := newMockStakingKeeper( + map[string]int64{ testutil.ValAddrs[0].String(): 40, testutil.ValAddrs[1].String(): 1, testutil.ValAddrs[2].String(): 60, testutil.ValAddrs[3].String(): 19, }, - } + ) upgradeKeeper := upgrade.NewKeeper(upgradeStore, 0, mockStakingKeeper) return upgradeKeeper, mockCtx, mockStakingKeeper @@ -212,6 +213,17 @@ type mockStakingKeeper struct { validators map[string]int64 } +func newMockStakingKeeper(validators map[string]int64) *mockStakingKeeper { + totalVotingPower := int64(0) + for _, power := range validators { + totalVotingPower += power + } + return &mockStakingKeeper{ + totalVotingPower: totalVotingPower, + validators: validators, + } +} + func (m *mockStakingKeeper) GetLastTotalPower(_ sdk.Context) math.Int { return math.NewInt(m.totalVotingPower) }