Skip to content

Commit

Permalink
fixed integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
insumity committed Aug 14, 2024
1 parent 666e11a commit e28bce3
Show file tree
Hide file tree
Showing 28 changed files with 320 additions and 308 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ install: go.sum
go install -ldflags "$(democracyFlags)" ./cmd/interchain-security-cdd
go install -ldflags "$(standaloneFlags)" ./cmd/interchain-security-sd

# run all tests: unit, integration, diff, and E2E
test: test-unit test-integration test-mbt test-e2e
# run all tests: unit, integration, and E2E
test: test-unit test-integration test-e2e

# shortcut for local development
test-dev: test-unit test-integration test-mbt
Expand Down Expand Up @@ -271,4 +271,4 @@ build-docs-local:
###############################################################################

e2e-traces:
cd tests/e2e; go test -timeout 30s -run ^TestWriteExamples -v
cd tests/e2e; go test -timeout 30s -run ^TestWriteExamples -v
2 changes: 1 addition & 1 deletion tests/integration/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (s *CCVTestSuite) getFirstBundle() icstestingutils.ConsumerBundle {
}

func (s *CCVTestSuite) getBundleByIdx(index int) icstestingutils.ConsumerBundle {
return *s.consumerBundles[ibctesting.GetChainID(2+index)]
return *s.consumerBundles[fmt.Sprintf("%d", 2+index)]
}

func (s *CCVTestSuite) providerCtx() sdk.Context {
Expand Down
60 changes: 30 additions & 30 deletions tests/integration/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (s *CCVTestSuite) TestRewardsDistribution() {
// Save the consumer validators total outstanding rewards on the provider
consumerValsOutstandingRewardsFunc := func(ctx sdk.Context) sdk.DecCoins {
totalRewards := sdk.DecCoins{}
vals, err := providerKeeper.GetConsumerValSet(ctx, s.consumerChain.ChainID)
vals, err := providerKeeper.GetConsumerValSet(ctx, s.getFirstBundle().ConsumerId)
s.Require().NoError(err)

for _, v := range vals {
Expand Down Expand Up @@ -160,7 +160,7 @@ func (s *CCVTestSuite) TestRewardsDistribution() {

// Consumer allocations are distributed between the validators and the community pool.
// The decimals resulting from the distribution are expected to remain in the consumer allocations.
rewardsAlloc := providerKeeper.GetConsumerRewardsAllocation(s.providerCtx(), s.consumerChain.ChainID)
rewardsAlloc := providerKeeper.GetConsumerRewardsAllocation(s.providerCtx(), s.getFirstBundle().ConsumerId)
remainingAlloc := rewardsAlloc.Rewards.AmountOf(rewardsIBCdenom)
s.Require().True(remainingAlloc.LTE(math.LegacyOneDec()))

Expand Down Expand Up @@ -598,7 +598,7 @@ func (s *CCVTestSuite) TestIBCTransferMiddleware() {
// update consumer allocation
keeper.SetConsumerRewardsAllocation(
ctx,
s.consumerChain.ChainID,
s.getFirstBundle().ConsumerId,
providertypes.ConsumerRewardsAllocation{
Rewards: sdk.NewDecCoins(sdk.NewDecCoin(sdk.DefaultBondDenom, math.NewInt(100_000))),
},
Expand Down Expand Up @@ -665,7 +665,7 @@ func (s *CCVTestSuite) TestIBCTransferMiddleware() {
rewardsPoolBalance := bankKeeper.GetAllBalances(s.providerCtx(), sdk.MustAccAddressFromBech32(data.Receiver))

// save the consumer's rewards allocated
consumerRewardsAllocations := providerKeeper.GetConsumerRewardsAllocation(s.providerCtx(), s.consumerChain.ChainID)
consumerRewardsAllocations := providerKeeper.GetConsumerRewardsAllocation(s.providerCtx(), s.getFirstBundle().ConsumerId)

// execute middleware OnRecvPacket logic
ack := cbs.OnRecvPacket(s.providerCtx(), packet, sdk.AccAddress{})
Expand All @@ -679,7 +679,7 @@ func (s *CCVTestSuite) TestIBCTransferMiddleware() {
// compute the balance and allocation difference
rewardsTransferred := bankKeeper.GetAllBalances(s.providerCtx(), sdk.MustAccAddressFromBech32(data.Receiver)).
Sub(rewardsPoolBalance...)
rewardsAllocated := providerKeeper.GetConsumerRewardsAllocation(s.providerCtx(), s.consumerChain.ChainID).
rewardsAllocated := providerKeeper.GetConsumerRewardsAllocation(s.providerCtx(), s.getFirstBundle().ConsumerId).
Rewards.Sub(consumerRewardsAllocations.Rewards)

if !tc.expErr {
Expand Down Expand Up @@ -736,11 +736,11 @@ func (s *CCVTestSuite) TestAllocateTokens() {

// Allocate rewards evenly between consumers
rewardsPerChain := totalRewards.QuoInt(math.NewInt(int64(len(s.consumerBundles))))
for chainID := range s.consumerBundles {
for consumerId := range s.consumerBundles {
// update consumer allocation
providerKeeper.SetConsumerRewardsAllocation(
providerCtx,
chainID,
consumerId,
providertypes.ConsumerRewardsAllocation{
Rewards: sdk.NewDecCoinsFromCoins(rewardsPerChain...),
},
Expand Down Expand Up @@ -794,7 +794,7 @@ func (s *CCVTestSuite) TestAllocateTokens() {
// check that the total expected rewards are transferred to the distribution module account

// store the decimal remainders in the consumer reward allocations
allocRemainderPerChain := providerKeeper.GetConsumerRewardsAllocation(providerCtx, s.consumerChain.ChainID).Rewards
allocRemainderPerChain := providerKeeper.GetConsumerRewardsAllocation(providerCtx, s.getFirstBundle().ConsumerId).Rewards

// compute the total rewards distributed to the distribution module balance (validator outstanding rewards + community pool tax),
totalRewardsDistributed := sdk.NewDecCoinsFromCoins(totalRewards...).Sub(allocRemainderPerChain.MulDec(math.LegacyNewDec(int64(consNum))))
Expand Down Expand Up @@ -840,7 +840,7 @@ func (s *CCVTestSuite) TestAllocateTokensToConsumerValidators() {
distributionKeeper := s.providerApp.GetTestDistributionKeeper()
bankKeeper := s.providerApp.GetTestBankKeeper()

chainID := s.consumerChain.ChainID
consumerId := s.getFirstBundle().ConsumerId

testCases := []struct {
name string
Expand All @@ -856,7 +856,7 @@ func (s *CCVTestSuite) TestAllocateTokensToConsumerValidators() {
expAllocated: nil,
},
{
name: "consumer valset is empty - total voting power is zero",
name: "consumerId valset is empty - total voting power is zero",
tokens: sdk.DecCoins{sdk.NewDecCoin(sdk.DefaultBondDenom, math.NewInt(100_000))},
rate: math.LegacyZeroDec(),
expAllocated: nil,
Expand All @@ -881,24 +881,24 @@ func (s *CCVTestSuite) TestAllocateTokensToConsumerValidators() {
s.Run(tc.name, func() {
ctx, _ := s.providerCtx().CacheContext()

// increase the block height so validators are eligible for consumer rewards (see `IsEligibleForConsumerRewards`)
// increase the block height so validators are eligible for consumerId rewards (see `IsEligibleForConsumerRewards`)
ctx = ctx.WithBlockHeight(providerKeeper.GetNumberOfEpochsToStartReceivingRewards(ctx)*providerKeeper.GetBlocksPerEpoch(ctx) +
ctx.BlockHeight())

// change the consumer valset
consuVals, err := providerKeeper.GetConsumerValSet(ctx, chainID)
// change the consumerId valset
consuVals, err := providerKeeper.GetConsumerValSet(ctx, consumerId)
s.Require().NoError(err)
providerKeeper.DeleteConsumerValSet(ctx, chainID)
providerKeeper.SetConsumerValSet(ctx, chainID, consuVals[0:tc.consuValLen])
consuVals, err = providerKeeper.GetConsumerValSet(ctx, chainID)
providerKeeper.DeleteConsumerValSet(ctx, consumerId)
providerKeeper.SetConsumerValSet(ctx, consumerId, consuVals[0:tc.consuValLen])
consuVals, err = providerKeeper.GetConsumerValSet(ctx, consumerId)
s.Require().NoError(err)

// set the same consumer commission rate for all consumer validators
// set the same consumerId commission rate for all consumerId validators
for _, v := range consuVals {
provAddr := providertypes.NewProviderConsAddress(sdk.ConsAddress(v.ProviderConsAddr))
err := providerKeeper.SetConsumerCommissionRate(
ctx,
chainID,
consumerId,
provAddr,
tc.rate,
)
Expand All @@ -908,7 +908,7 @@ func (s *CCVTestSuite) TestAllocateTokensToConsumerValidators() {
// allocate tokens
res := providerKeeper.AllocateTokensToConsumerValidators(
ctx,
chainID,
consumerId,
tc.tokens,
)

Expand Down Expand Up @@ -946,7 +946,7 @@ func (s *CCVTestSuite) TestAllocateTokensToConsumerValidators() {
s.Require().NoError(err)

// check that the withdrawn coins is equal to the entire reward amount
// times the set consumer commission rate
// times the set consumerId commission rate
commission := rewards.Rewards.MulDec(tc.rate)
c, _ := commission.TruncateDecimal()
s.Require().Equal(withdrawnCoins, c)
Expand Down Expand Up @@ -978,7 +978,7 @@ func (s *CCVTestSuite) TestAllocateTokensToConsumerValidatorsWithDifferentValida
distributionKeeper := s.providerApp.GetTestDistributionKeeper()
bankKeeper := s.providerApp.GetTestBankKeeper()

chainID := s.consumerChain.ChainID
consumerId := s.getFirstBundle().ConsumerId

tokens := sdk.DecCoins{sdk.NewDecCoinFromDec(sdk.DefaultBondDenom, math.LegacyNewDecFromIntWithPrec(math.NewInt(999), 2))}
rate := math.LegacyOneDec()
Expand All @@ -991,7 +991,7 @@ func (s *CCVTestSuite) TestAllocateTokensToConsumerValidatorsWithDifferentValida
ctx = ctx.WithBlockHeight(providerKeeper.GetNumberOfEpochsToStartReceivingRewards(ctx)*providerKeeper.GetBlocksPerEpoch(ctx) + 1)

// update the consumer validators
consuVals, err := providerKeeper.GetConsumerValSet(ctx, chainID)
consuVals, err := providerKeeper.GetConsumerValSet(ctx, consumerId)
s.Require().NoError(err)
// first 2 validators were consumer validators since block height 1 and hence get rewards
consuVals[0].JoinHeight = 1
Expand All @@ -1000,19 +1000,19 @@ func (s *CCVTestSuite) TestAllocateTokensToConsumerValidatorsWithDifferentValida
// have not been consumer validators for `GetNumberOfEpochsToStartReceivingRewards * GetBlocksPerEpoch` blocks
consuVals[2].JoinHeight = 2
consuVals[3].JoinHeight = 2
providerKeeper.SetConsumerValSet(ctx, chainID, consuVals)
providerKeeper.SetConsumerValSet(ctx, consumerId, consuVals)

providerKeeper.DeleteConsumerValSet(ctx, chainID)
providerKeeper.SetConsumerValSet(ctx, chainID, consuVals)
consuVals, err = providerKeeper.GetConsumerValSet(ctx, chainID)
providerKeeper.DeleteConsumerValSet(ctx, consumerId)
providerKeeper.SetConsumerValSet(ctx, consumerId, consuVals)
consuVals, err = providerKeeper.GetConsumerValSet(ctx, consumerId)
s.Require().NoError(err)

// set the same consumer commission rate for all consumer validators
for _, v := range consuVals {
provAddr := providertypes.NewProviderConsAddress(sdk.ConsAddress(v.ProviderConsAddr))
err := providerKeeper.SetConsumerCommissionRate(
ctx,
chainID,
consumerId,
provAddr,
rate,
)
Expand All @@ -1022,7 +1022,7 @@ func (s *CCVTestSuite) TestAllocateTokensToConsumerValidatorsWithDifferentValida
// allocate tokens
res := providerKeeper.AllocateTokensToConsumerValidators(
ctx,
chainID,
consumerId,
tokens,
)

Expand Down Expand Up @@ -1098,8 +1098,8 @@ func (s *CCVTestSuite) TestMultiConsumerRewardsDistribution() {

// Iterate over the consumers and perform the reward distribution
// to the provider
for chainID := range s.consumerBundles {
bundle := s.consumerBundles[chainID]
for consumerId := range s.consumerBundles {
bundle := s.consumerBundles[consumerId]
consumerKeeper := bundle.App.GetConsumerKeeper()
bankKeeper := bundle.App.GetTestBankKeeper()
accountKeeper := bundle.App.GetTestAccountKeeper()
Expand Down
Loading

0 comments on commit e28bce3

Please sign in to comment.