Skip to content

Commit

Permalink
Add unit test for LastTotalProviderConsensusPower
Browse files Browse the repository at this point in the history
  • Loading branch information
p-offtermatt committed Jul 2, 2024
1 parent bfe43c2 commit 5e30dd9
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions x/ccv/provider/keeper/provider_consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper_test
import (
"testing"

"cosmossdk.io/math"
"github.com/cometbft/cometbft/proto/tendermint/crypto"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -100,3 +101,24 @@ func TestDeleteLastProviderConsensusValSet(t *testing.T) {
storedValidators := providerKeeper.GetLastProviderConsensusValSet(ctx)
require.Empty(t, storedValidators, "validator set should be empty")
}

func TestGetLastTotalProviderConsensusPower(t *testing.T) {
providerKeeper, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t))
defer ctrl.Finish()
validator1 := types.ConsumerValidator{
ProviderConsAddr: []byte("providerConsAddr1"),
Power: 2,
ConsumerPublicKey: &crypto.PublicKey{},
}
validator2 := types.ConsumerValidator{
ProviderConsAddr: []byte("providerConsAddr2"),
Power: 3,
ConsumerPublicKey: &crypto.PublicKey{},
}
nextValidators := []types.ConsumerValidator{validator1, validator2}
providerKeeper.SetLastProviderConsensusValSet(ctx, nextValidators)
// Get the total power of the last stored validator set
totalPower := providerKeeper.GetLastTotalProviderConsensusPower(ctx)
expectedTotalPower := math.NewInt(5)
require.Equal(t, expectedTotalPower, totalPower, "total power does not match")
}

0 comments on commit 5e30dd9

Please sign in to comment.