Skip to content

Commit

Permalink
add some comments to the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cmwaters committed Dec 7, 2023
1 parent 6f6c72a commit c15ff0b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions x/upgrade/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
20 changes: 16 additions & 4 deletions x/upgrade/tally_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)
}

Expand All @@ -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
Expand All @@ -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)
}
Expand Down

0 comments on commit c15ff0b

Please sign in to comment.