Skip to content

Commit

Permalink
integration tests fix
Browse files Browse the repository at this point in the history
  • Loading branch information
stana-miric committed Nov 25, 2024
1 parent 99d4eea commit 86fc22c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
7 changes: 4 additions & 3 deletions tests/integration/double_vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,10 @@ func (s *CCVTestSuite) TestHandleConsumerDoubleVoting() {

// verifies that the val gets slashed and has fewer tokens after the slashing
val, _ := s.providerApp.GetTestStakingKeeper().GetValidator(provCtx, provAddr.ToSdkConsAddr().Bytes())
slashFraction, err := s.providerApp.GetTestSlashingKeeper().SlashFractionDoubleSign(provCtx)
infractionParam, err := s.providerApp.GetProviderKeeper().GetInfractionParameters(provCtx, tc.consumerId)
s.Require().NoError(err)
actualTokens := math.LegacyNewDecFromInt(val.GetTokens())
s.Require().True(initialTokens.Sub(initialTokens.Mul(slashFraction)).Equal(actualTokens))
s.Require().True(initialTokens.Sub(initialTokens.Mul(infractionParam.DoubleSign.SlashFraction)).Equal(actualTokens))
} else {
s.Require().Error(err)

Expand Down Expand Up @@ -409,8 +409,9 @@ func (s *CCVTestSuite) TestHandleConsumerDoubleVotingSlashesUndelegationsAndRele
)
s.Require().NoError(err)

slashFraction, err := s.providerApp.GetTestSlashingKeeper().SlashFractionDoubleSign(s.providerCtx())
infractionParam, err := s.providerApp.GetProviderKeeper().GetInfractionParameters(s.providerCtx(), s.getFirstBundle().ConsumerId)
s.Require().NoError(err)
slashFraction := infractionParam.DoubleSign.SlashFraction

// check undelegations are slashed
ubds, _ = s.providerApp.GetTestStakingKeeper().GetUnbondingDelegation(s.providerCtx(), delAddr, valAddr)
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/misbehaviour.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ func (s *CCVTestSuite) TestHandleConsumerMisbehaviour() {
s.Require().True(s.providerApp.GetTestSlashingKeeper().IsTombstoned(s.providerCtx(), provAddr.ToSdkConsAddr()))

validator, _ := s.providerApp.GetTestStakingKeeper().GetValidator(s.providerCtx(), provAddr.ToSdkConsAddr().Bytes())
slashFraction, err := s.providerApp.GetTestSlashingKeeper().SlashFractionDoubleSign(s.providerCtx())
infractionParam, err := s.providerApp.GetProviderKeeper().GetInfractionParameters(s.providerCtx(), s.getFirstBundle().ConsumerId)
s.Require().NoError(err)
slashFraction := infractionParam.DoubleSign.SlashFraction
actualTokens := math.LegacyNewDecFromInt(validator.GetTokens())
s.Require().True(initialTokens.Sub(initialTokens.Mul(slashFraction)).Equal(actualTokens))
}
Expand Down
4 changes: 4 additions & 0 deletions testutil/ibc_testing/generic_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ func AddConsumer[Tp testutil.ProviderApp, Tc testutil.ConsumerApp](
powerShapingParameters := testkeeper.GetTestPowerShapingParameters()
powerShapingParameters.Top_N = consumerTopNParams[index] // isn't used in CreateConsumerClient

infractionPrameters := testkeeper.GetTestInfractionParameters()

consumerId := providerKeeper.FetchAndIncrementConsumerId(providerChain.GetContext())
providerKeeper.SetConsumerChainId(providerChain.GetContext(), consumerId, chainID)
err := providerKeeper.SetConsumerMetadata(providerChain.GetContext(), consumerId, consumerMetadata)
Expand All @@ -164,6 +166,8 @@ func AddConsumer[Tp testutil.ProviderApp, Tc testutil.ConsumerApp](
s.Require().NoError(err)
err = providerKeeper.SetConsumerPowerShapingParameters(providerChain.GetContext(), consumerId, powerShapingParameters)
s.Require().NoError(err)
err = providerKeeper.SetInfractionParameters(providerChain.GetContext(), consumerId, infractionPrameters)
s.Require().NoError(err)
providerKeeper.SetConsumerPhase(providerChain.GetContext(), consumerId, providertypes.CONSUMER_PHASE_INITIALIZED)
if chainID == firstConsumerChainID {
FirstConsumerID = consumerId
Expand Down
14 changes: 14 additions & 0 deletions testutil/keeper/unit_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/stretchr/testify/require"

"cosmossdk.io/log"
math "cosmossdk.io/math"
"cosmossdk.io/store"
"cosmossdk.io/store/metrics"
storetypes "cosmossdk.io/store/types"
Expand Down Expand Up @@ -300,6 +301,19 @@ func GetTestInitializationParameters() providertypes.ConsumerInitializationParam
}
}

func GetTestInfractionParameters() providertypes.InfractionParameters {
return providertypes.InfractionParameters{
DoubleSign: &providertypes.SlashJailParameters{
JailDuration: 1200 * time.Second,
SlashFraction: math.LegacyNewDecWithPrec(5, 1), // 0.5
},
Downtime: &providertypes.SlashJailParameters{
JailDuration: 600 * time.Second,
SlashFraction: math.LegacyNewDec(0),
},
}
}

func GetTestPowerShapingParameters() providertypes.PowerShapingParameters {
return providertypes.PowerShapingParameters{
Top_N: 0,
Expand Down

0 comments on commit 86fc22c

Please sign in to comment.