diff --git a/tests/difference/core/driver/common.go b/tests/difference/core/driver/common.go index 8ea1a4cc36..90e97c324b 100644 --- a/tests/difference/core/driver/common.go +++ b/tests/difference/core/driver/common.go @@ -3,6 +3,7 @@ package core import ( "time" + "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -29,8 +30,8 @@ type InitState struct { NumValidators int MaxValidators int InitialDelegatorTokens int - SlashDoublesign sdk.Dec - SlashDowntime sdk.Dec + SlashDoublesign math.LegacyDec + SlashDowntime math.LegacyDec UnbondingP time.Duration UnbondingC time.Duration Trusting time.Duration @@ -45,7 +46,7 @@ var initStateVar InitState func init() { // tokens === power - sdk.DefaultPowerReduction = sdk.NewInt(1) + sdk.DefaultPowerReduction = math.NewInt(1) initStateVar = InitState{ PKSeeds: []string{ // Fixed seeds are used to create the private keys for validators. @@ -59,8 +60,8 @@ func init() { NumValidators: 4, MaxValidators: 2, InitialDelegatorTokens: 10000000000000, - SlashDoublesign: sdk.NewDec(0), - SlashDowntime: sdk.NewDec(0), + SlashDoublesign: math.LegacyNewDec(0), + SlashDowntime: math.LegacyNewDec(0), UnbondingP: time.Second * 70, UnbondingC: time.Second * 50, Trusting: time.Second * 49, diff --git a/tests/difference/core/driver/core_test.go b/tests/difference/core/driver/core_test.go index 17a90760a8..d018b8dbe4 100644 --- a/tests/difference/core/driver/core_test.go +++ b/tests/difference/core/driver/core_test.go @@ -4,6 +4,7 @@ import ( "fmt" "time" + "cosmossdk.io/math" ibctesting "github.com/cosmos/ibc-go/v8/testing" "github.com/stretchr/testify/suite" @@ -149,7 +150,7 @@ func (s *CoreSuite) delegatorBalance() int64 { func (s *CoreSuite) delegate(val, amt int64) { providerStaking := s.providerStakingKeeper() server := stakingkeeper.NewMsgServerImpl(&providerStaking) - coin := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(amt)) + coin := sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(amt)) d := s.delegator() v := s.validator(val) msg := stakingtypes.NewMsgDelegate(d, v, coin) @@ -162,7 +163,7 @@ func (s *CoreSuite) delegate(val, amt int64) { func (s *CoreSuite) undelegate(val, amt int64) { providerStaking := s.providerStakingKeeper() server := stakingkeeper.NewMsgServerImpl(&providerStaking) - coin := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(amt)) + coin := sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(amt)) d := s.delegator() v := s.validator(val) msg := stakingtypes.NewMsgUndelegate(d, v, coin) @@ -180,7 +181,7 @@ func (s *CoreSuite) consumerSlash(val sdk.ConsAddress, h int64, isDowntime bool) } ctx := s.ctx(C) before := len(ctx.EventManager().Events()) - s.consumerKeeper().SlashWithInfractionReason(ctx, val, h, 0, sdk.Dec{}, kind) + s.consumerKeeper().SlashWithInfractionReason(ctx, val, h, 0, math.LegacyDec{}, kind) // consumer module emits packets on slash, so these must be collected. evts := ctx.EventManager().Events() packets := simibc.ParsePacketsFromEvents(evts[before:]) diff --git a/tests/difference/core/driver/setup.go b/tests/difference/core/driver/setup.go index 156eda6e0a..9c50cb6b6c 100644 --- a/tests/difference/core/driver/setup.go +++ b/tests/difference/core/driver/setup.go @@ -6,6 +6,7 @@ import ( "encoding/json" "time" + "cosmossdk.io/math" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types" @@ -133,7 +134,7 @@ func (b *Builder) getAppBytesAndSenders( bal := banktypes.Balance{ Address: acc.GetAddress().String(), - Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewIntFromUint64(amt))), + Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewIntFromUint64(amt))), } accounts = append(accounts, acc) @@ -155,7 +156,7 @@ func (b *Builder) getAppBytesAndSenders( delegations := make([]stakingtypes.Delegation, 0, len(validators.Validators)) // Sum bonded is needed for BondedPool account - sumBonded := sdk.NewInt(0) + sumBonded := math.NewInt(0) initValPowers := []abci.ValidatorUpdate{} for i, val := range validators.Validators { @@ -163,13 +164,13 @@ func (b *Builder) getAppBytesAndSenders( delegation := b.initState.ValStates.Delegation[i] extra := b.initState.ValStates.ValidatorExtraTokens[i] - tokens := sdk.NewInt(int64(delegation + extra)) + tokens := math.NewInt(int64(delegation + extra)) b.suite.Require().Equal(status, stakingtypes.Bonded, "All genesis validators should be bonded") sumBonded = sumBonded.Add(tokens) // delegator account receives delShares shares - delShares := sdk.NewDec(int64(delegation)) + delShares := math.LegacyNewDec(int64(delegation)) // validator has additional sumShares due to extra units - sumShares := sdk.NewDec(int64(delegation + extra)) + sumShares := math.LegacyNewDec(int64(delegation + extra)) pk, err := cryptocodec.FromTmPubKeyInterface(val.PubKey) require.NoError(b.suite.T(), err) @@ -186,8 +187,8 @@ func (b *Builder) getAppBytesAndSenders( Description: stakingtypes.Description{}, UnbondingHeight: int64(0), UnbondingTime: time.Unix(0, 0).UTC(), - Commission: stakingtypes.NewCommission(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()), - MinSelfDelegation: sdk.ZeroInt(), + Commission: stakingtypes.NewCommission(math.LegacyZeroDec(), math.LegacyZeroDec(), math.LegacyZeroDec()), + MinSelfDelegation: math.ZeroInt(), } stakingValidators = append(stakingValidators, validator) @@ -238,7 +239,7 @@ func (b *Builder) getAppBytesAndSenders( // add unbonded amount balances = append(balances, banktypes.Balance{ Address: authtypes.NewModuleAddress(stakingtypes.NotBondedPoolName).String(), - Coins: sdk.Coins{sdk.NewCoin(bondDenom, sdk.ZeroInt())}, + Coins: sdk.Coins{sdk.NewCoin(bondDenom, math.ZeroInt())}, }) // update total funds supply @@ -404,7 +405,7 @@ func (b *Builder) ensureValidatorLexicographicOrderingMatchesModel() { // validators in the setup process. func (b *Builder) delegate(del int, val sdk.ValAddress, amt int64) { d := b.provider().SenderAccounts[del].SenderAccount.GetAddress() - coins := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(amt)) + coins := sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(amt)) msg := stakingtypes.NewMsgDelegate(d, val, coins) providerStaking := b.providerStakingKeeper() pskServer := stakingkeeper.NewMsgServerImpl(&providerStaking) @@ -415,7 +416,7 @@ func (b *Builder) delegate(del int, val sdk.ValAddress, amt int64) { // addValidatorToStakingModule creates an additional validator with zero commission // and zero tokens (zero voting power). func (b *Builder) addValidatorToStakingModule(privVal mock.PV) { - coin := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(0)) + coin := sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(0)) pubKey, err := privVal.GetPubKey() require.NoError(b.suite.T(), err) @@ -432,8 +433,8 @@ func (b *Builder) addValidatorToStakingModule(privVal mock.PV) { sdkPK, coin, stakingtypes.Description{}, - stakingtypes.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()), - sdk.ZeroInt()) + stakingtypes.NewCommissionRates(math.LegacyZeroDec(), math.LegacyZeroDec(), math.LegacyZeroDec()), + math.ZeroInt()) b.suite.Require().NoError(err) providerStaking := b.providerStakingKeeper() pskServer := stakingkeeper.NewMsgServerImpl(&providerStaking) diff --git a/tests/integration/common.go b/tests/integration/common.go index 056e4abfd3..bbafa507e7 100644 --- a/tests/integration/common.go +++ b/tests/integration/common.go @@ -147,12 +147,12 @@ func delegateAndRedelegate(s *CCVTestSuite, delAddr sdk.AccAddress, } // delegate delegates bondAmt to the first validator -func delegate(s *CCVTestSuite, delAddr sdk.AccAddress, bondAmt math.Int) (initBalance math.Int, shares sdk.Dec, valAddr sdk.ValAddress) { +func delegate(s *CCVTestSuite, delAddr sdk.AccAddress, bondAmt math.Int) (initBalance math.Int, shares math.LegacyDec, valAddr sdk.ValAddress) { return delegateByIdx(s, delAddr, bondAmt, 0) } // delegateByIdx delegates bondAmt to the validator at specified index in provider val set -func delegateByIdx(s *CCVTestSuite, delAddr sdk.AccAddress, bondAmt math.Int, idx int) (initBalance math.Int, shares sdk.Dec, valAddr sdk.ValAddress) { +func delegateByIdx(s *CCVTestSuite, delAddr sdk.AccAddress, bondAmt math.Int, idx int) (initBalance math.Int, shares math.LegacyDec, valAddr sdk.ValAddress) { initBalance = getBalance(s, s.providerCtx(), delAddr) // choose a validator validator, valAddr := s.getValByIdx(idx) @@ -172,7 +172,7 @@ func delegateByIdx(s *CCVTestSuite, delAddr sdk.AccAddress, bondAmt math.Int, id } // undelegate unbonds an amount of delegator shares from a given validator -func undelegate(s *CCVTestSuite, delAddr sdk.AccAddress, valAddr sdk.ValAddress, sharesAmount sdk.Dec) (valsetUpdateId uint64) { +func undelegate(s *CCVTestSuite, delAddr sdk.AccAddress, valAddr sdk.ValAddress, sharesAmount math.LegacyDec) (valsetUpdateId uint64) { _, err := s.providerApp.GetTestStakingKeeper().Undelegate(s.providerCtx(), delAddr, valAddr, sharesAmount) s.Require().NoError(err) @@ -185,7 +185,7 @@ func undelegate(s *CCVTestSuite, delAddr sdk.AccAddress, valAddr sdk.ValAddress, // Executes a BeginRedelegation (unbonding and redelegation) operation // on the provider chain using delegated funds from delAddr func redelegate(s *CCVTestSuite, delAddr sdk.AccAddress, valSrcAddr sdk.ValAddress, - valDstAddr sdk.ValAddress, sharesAmount sdk.Dec, + valDstAddr sdk.ValAddress, sharesAmount math.LegacyDec, ) { stakingKeeper := s.providerApp.GetTestStakingKeeper() ctx := s.providerCtx() @@ -595,7 +595,7 @@ func (suite *CCVTestSuite) GetConsumerEndpointClientAndConsState( func (s *CCVTestSuite) setupValidatorPowers() { delAddr := s.providerChain.SenderAccount.GetAddress() for idx := range s.providerChain.Vals.Validators { - delegateByIdx(s, delAddr, sdk.NewInt(999999999), idx) + delegateByIdx(s, delAddr, math.NewInt(999999999), idx) } s.providerChain.NextBlock() diff --git a/tests/integration/democracy.go b/tests/integration/democracy.go index a9a9271f3d..abfd65548a 100644 --- a/tests/integration/democracy.go +++ b/tests/integration/democracy.go @@ -76,13 +76,13 @@ func (s *ConsumerDemocracyTestSuite) TestDemocracyRewardsDistribution() { bankKeeper := s.consumerApp.GetTestBankKeeper() bondDenom := stakingKeeper.BondDenom(s.consumerCtx()) - currentRepresentativesRewards := map[string]sdk.Dec{} - nextRepresentativesRewards := map[string]sdk.Dec{} + currentRepresentativesRewards := map[string]math.LegacyDec{} + nextRepresentativesRewards := map[string]math.LegacyDec{} representativesTokens := map[string]math.Int{} for _, representative := range stakingKeeper.GetAllValidators(s.consumerCtx()) { - currentRepresentativesRewards[representative.OperatorAddress] = sdk.NewDec(0) - nextRepresentativesRewards[representative.OperatorAddress] = sdk.NewDec(0) + currentRepresentativesRewards[representative.OperatorAddress] = math.LegacyNewDec(0) + nextRepresentativesRewards[representative.OperatorAddress] = math.LegacyNewDec(0) representativesTokens[representative.OperatorAddress] = representative.GetTokens() } @@ -90,8 +90,8 @@ func (s *ConsumerDemocracyTestSuite) TestDemocracyRewardsDistribution() { providerRedistributeAccount := accountKeeper.GetModuleAccount(s.consumerCtx(), consumertypes.ConsumerToSendToProviderName) // balance of consumer redistribute address will always be 0 when checked between 2 NextBlock() calls - currentDistrModuleAccountBalance := sdk.NewDecFromInt(bankKeeper.GetBalance(s.consumerCtx(), distrModuleAccount.GetAddress(), bondDenom).Amount) - currentProviderFeeAccountBalance := sdk.NewDecFromInt(bankKeeper.GetBalance(s.consumerCtx(), providerRedistributeAccount.GetAddress(), bondDenom).Amount) + currentDistrModuleAccountBalance := math.LegacyNewDecFromInt(bankKeeper.GetBalance(s.consumerCtx(), distrModuleAccount.GetAddress(), bondDenom).Amount) + currentProviderFeeAccountBalance := math.LegacyNewDecFromInt(bankKeeper.GetBalance(s.consumerCtx(), providerRedistributeAccount.GetAddress(), bondDenom).Amount) currentCommunityPoolBalance := distrKeeper.GetFeePoolCommunityCoins(s.consumerCtx()).AmountOf(bondDenom) for key := range currentRepresentativesRewards { representativeAddr, _ := sdk.ValAddressFromBech32(key) @@ -101,8 +101,8 @@ func (s *ConsumerDemocracyTestSuite) TestDemocracyRewardsDistribution() { s.consumerChain.NextBlock() - nextDistrModuleAccountBalance := sdk.NewDecFromInt(bankKeeper.GetBalance(s.consumerCtx(), distrModuleAccount.GetAddress(), bondDenom).Amount) - nextProviderFeeAccountBalance := sdk.NewDecFromInt(bankKeeper.GetBalance(s.consumerCtx(), providerRedistributeAccount.GetAddress(), bondDenom).Amount) + nextDistrModuleAccountBalance := math.LegacyNewDecFromInt(bankKeeper.GetBalance(s.consumerCtx(), distrModuleAccount.GetAddress(), bondDenom).Amount) + nextProviderFeeAccountBalance := math.LegacyNewDecFromInt(bankKeeper.GetBalance(s.consumerCtx(), providerRedistributeAccount.GetAddress(), bondDenom).Amount) nextCommunityPoolBalance := distrKeeper.GetFeePoolCommunityCoins(s.consumerCtx()).AmountOf(bondDenom) for key := range nextRepresentativesRewards { representativeAddr, _ := sdk.ValAddressFromBech32(key) @@ -113,7 +113,7 @@ func (s *ConsumerDemocracyTestSuite) TestDemocracyRewardsDistribution() { distrModuleDifference := nextDistrModuleAccountBalance.Sub(currentDistrModuleAccountBalance) providerDifference := nextProviderFeeAccountBalance.Sub(currentProviderFeeAccountBalance) communityPoolDifference := nextCommunityPoolBalance.Sub(currentCommunityPoolBalance) - representativeDifference := map[string]sdk.Dec{} + representativeDifference := map[string]math.LegacyDec{} consumerRedistributeDifference := communityPoolDifference for key, currentReward := range currentRepresentativesRewards { @@ -121,7 +121,7 @@ func (s *ConsumerDemocracyTestSuite) TestDemocracyRewardsDistribution() { consumerRedistributeDifference = consumerRedistributeDifference.Add(representativeDifference[key]) } - consumerRedistributionFraction := sdk.MustNewDecFromStr(s.consumerApp.GetConsumerKeeper().GetConsumerRedistributionFrac(s.consumerCtx())) + consumerRedistributionFraction := math.LegacyMustNewDecFromStr(s.consumerApp.GetConsumerKeeper().GetConsumerRedistributionFrac(s.consumerCtx())) // confirm that the total amount given to the community pool plus all representatives is equal to the total amount taken out of distribution s.Require().Equal(distrModuleDifference, consumerRedistributeDifference) @@ -135,13 +135,13 @@ func (s *ConsumerDemocracyTestSuite) TestDemocracyRewardsDistribution() { // check that the fraction actually kept by the provider is the correct fraction. using InEpsilon because the math code uses truncations s.Require().InEpsilon(providerDifference.Quo( providerDifference.Add(distrModuleDifference)).MustFloat64(), - sdk.NewDec(1).Sub(consumerRedistributionFraction).MustFloat64(), float64(0.0001)) + math.LegacyNewDec(1).Sub(consumerRedistributionFraction).MustFloat64(), float64(0.0001)) totalRepresentativePower := stakingKeeper.GetValidatorSet().TotalBondedTokens(s.consumerCtx()) // check that each representative has gotten the correct amount of rewards for key, representativeTokens := range representativesTokens { - powerFraction := sdk.NewDecFromInt(representativeTokens).QuoTruncate(sdk.NewDecFromInt(totalRepresentativePower)) + powerFraction := math.LegacyNewDecFromInt(representativeTokens).QuoTruncate(math.LegacyNewDecFromInt(totalRepresentativePower)) s.Require().Equal(powerFraction, representativeDifference[key].Quo(consumerRedistributeDifference.Sub(communityPoolDifference))) } } @@ -154,7 +154,7 @@ func (s *ConsumerDemocracyTestSuite) TestDemocracyGovernanceWhitelisting() { accountKeeper := s.consumerApp.GetTestAccountKeeper() mintKeeper := s.consumerApp.GetTestMintKeeper() newAuthParamValue := uint64(128) - newMintParamValue := sdk.NewDecWithPrec(1, 1) // "0.100000000000000000" + newMintParamValue := math.LegacyNewDecWithPrec(1, 1) // "0.100000000000000000" votingAccounts := s.consumerChain.SenderAccounts bondDenom := stakingKeeper.BondDenom(s.consumerCtx()) depositAmount := params.MinDeposit diff --git a/tests/integration/distribution.go b/tests/integration/distribution.go index 4775f21237..367fedd1b6 100644 --- a/tests/integration/distribution.go +++ b/tests/integration/distribution.go @@ -3,6 +3,7 @@ package integration import ( "strings" + "cosmossdk.io/math" transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -20,7 +21,7 @@ func (s *CCVTestSuite) TestRewardsDistribution() { // set up channel and delegate some tokens in order for validator set update to be sent to the consumer chain s.SetupCCVChannel(s.path) s.SetupTransferChannel() - bondAmt := sdk.NewInt(10000000) + bondAmt := math.NewInt(10000000) delAddr := s.providerChain.SenderAccount.GetAddress() delegate(s, delAddr, bondAmt) s.providerChain.NextBlock() @@ -46,14 +47,14 @@ func (s *CCVTestSuite) TestRewardsDistribution() { // send coins to the fee pool which is used for reward distribution consumerFeePoolAddr := consumerAccountKeeper.GetModuleAccount(s.consumerCtx(), authtypes.FeeCollectorName).GetAddress() feePoolTokensOld := consumerBankKeeper.GetAllBalances(s.consumerCtx(), consumerFeePoolAddr) - fees := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))) + fees := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(100))) err := consumerBankKeeper.SendCoinsFromAccountToModule(s.consumerCtx(), s.consumerChain.SenderAccount.GetAddress(), authtypes.FeeCollectorName, fees) s.Require().NoError(err) feePoolTokens := consumerBankKeeper.GetAllBalances(s.consumerCtx(), consumerFeePoolAddr) - s.Require().Equal(sdk.NewInt(100).Add(feePoolTokensOld.AmountOf(sdk.DefaultBondDenom)), feePoolTokens.AmountOf(sdk.DefaultBondDenom)) + s.Require().Equal(math.NewInt(100).Add(feePoolTokensOld.AmountOf(sdk.DefaultBondDenom)), feePoolTokens.AmountOf(sdk.DefaultBondDenom)) // calculate the reward for consumer and provider chain. Consumer will receive ConsumerRedistributeFrac, the rest is going to provider - frac, err := sdk.NewDecFromStr(s.consumerApp.GetConsumerKeeper().GetConsumerRedistributionFrac(s.consumerCtx())) + frac, err := math.LegacyNewDecFromStr(s.consumerApp.GetConsumerKeeper().GetConsumerRedistributionFrac(s.consumerCtx())) s.Require().NoError(err) consumerExpectedRewards, _ := sdk.NewDecCoinsFromCoins(feePoolTokens...).MulDec(frac).TruncateDecimal() providerExpectedRewards := feePoolTokens.Sub(consumerExpectedRewards...) @@ -121,7 +122,7 @@ func (s *CCVTestSuite) TestSendRewardsRetries() { // ccv and transmission channels setup s.SetupCCVChannel(s.path) s.SetupTransferChannel() - bondAmt := sdk.NewInt(10000000) + bondAmt := math.NewInt(10000000) delAddr := s.providerChain.SenderAccount.GetAddress() delegate(s, delAddr, bondAmt) s.providerChain.NextBlock() @@ -142,7 +143,7 @@ func (s *CCVTestSuite) TestSendRewardsRetries() { consumerParams.Set(s.consumerCtx(), ccv.KeyBlocksPerDistributionTransmission, int64(1000)) // fill fee pool - fees := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))) + fees := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(100))) err := consumerBankKeeper.SendCoinsFromAccountToModule(s.consumerCtx(), s.consumerChain.SenderAccount.GetAddress(), authtypes.FeeCollectorName, fees) s.Require().NoError(err) @@ -250,7 +251,7 @@ func (s *CCVTestSuite) TestEndBlockRD() { // ccv and transmission channels setup s.SetupCCVChannel(s.path) s.SetupTransferChannel() - bondAmt := sdk.NewInt(10000000) + bondAmt := math.NewInt(10000000) delAddr := s.providerChain.SenderAccount.GetAddress() delegate(s, delAddr, bondAmt) s.providerChain.NextBlock() @@ -272,7 +273,7 @@ func (s *CCVTestSuite) TestEndBlockRD() { consumerParams.Set(s.consumerCtx(), ccv.KeyBlocksPerDistributionTransmission, int64(1000)) // fill fee pool - fees := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))) + fees := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(100))) err := consumerBankKeeper.SendCoinsFromAccountToModule(s.consumerCtx(), s.consumerChain.SenderAccount.GetAddress(), authtypes.FeeCollectorName, fees) s.Require().NoError(err) @@ -335,7 +336,7 @@ func (s *CCVTestSuite) TestSendRewardsToProvider() { ctx, s.consumerChain.SenderAccount.GetAddress(), consumertypes.ConsumerToSendToProviderName, - sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))), + sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(100))), ) s.Require().NoError(err) }, @@ -389,7 +390,7 @@ func (s *CCVTestSuite) TestSendRewardsToProvider() { ctx, s.consumerChain.SenderAccount.GetAddress(), consumertypes.ConsumerToSendToProviderName, - sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))), + sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(100))), ) s.Require().NoError(err) }, @@ -412,7 +413,7 @@ func (s *CCVTestSuite) TestSendRewardsToProvider() { ctx, s.consumerChain.SenderAccount.GetAddress(), consumertypes.ConsumerToSendToProviderName, - sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))), + sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(100))), ) s.Require().NoError(err) }, @@ -426,7 +427,7 @@ func (s *CCVTestSuite) TestSendRewardsToProvider() { // ccv channels setup s.SetupCCVChannel(s.path) - bondAmt := sdk.NewInt(10000000) + bondAmt := math.NewInt(10000000) delAddr := s.providerChain.SenderAccount.GetAddress() delegate(s, delAddr, bondAmt) s.providerChain.NextBlock() diff --git a/tests/integration/expired_client.go b/tests/integration/expired_client.go index ac44943d14..c04d6f525b 100644 --- a/tests/integration/expired_client.go +++ b/tests/integration/expired_client.go @@ -3,13 +3,13 @@ package integration import ( "time" + "cosmossdk.io/math" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported" ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" ibctesting "github.com/cosmos/ibc-go/v8/testing" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" - sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" abci "github.com/cometbft/cometbft/abci/types" @@ -28,7 +28,7 @@ func (s *CCVTestSuite) TestVSCPacketSendExpiredClient() { expireClient(s, Consumer) // bond some tokens on provider to change validator powers - bondAmt := sdk.NewInt(1000000) + bondAmt := math.NewInt(1000000) delAddr := s.providerChain.SenderAccount.GetAddress() delegate(s, delAddr, bondAmt) @@ -91,7 +91,7 @@ func (s *CCVTestSuite) TestConsumerPacketSendExpiredClient() { s.SetupCCVChannel(s.path) // bond some tokens on provider to change validator powers - bondAmt := sdk.NewInt(1000000) + bondAmt := math.NewInt(1000000) delAddr := s.providerChain.SenderAccount.GetAddress() delegate(s, delAddr, bondAmt) diff --git a/tests/integration/key_assignment.go b/tests/integration/key_assignment.go index cc103b5528..faa268a929 100644 --- a/tests/integration/key_assignment.go +++ b/tests/integration/key_assignment.go @@ -1,9 +1,9 @@ package integration import ( + "cosmossdk.io/math" "github.com/cosmos/ibc-go/v8/testing/mock" - sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" tmencoding "github.com/cometbft/cometbft/crypto/encoding" @@ -69,7 +69,7 @@ func (s *CCVTestSuite) TestKeyAssignment() { } // Bond some tokens on provider to change validator powers - bondAmt := sdk.NewInt(1000000) + bondAmt := math.NewInt(1000000) delAddr := s.providerChain.SenderAccount.GetAddress() delegate(s, delAddr, bondAmt) @@ -206,7 +206,7 @@ func (s *CCVTestSuite) TestKeyAssignment() { if !tc.expError { // Bond some tokens on provider to change validator powers - bondAmt := sdk.NewInt(1000000) + bondAmt := math.NewInt(1000000) delAddr := s.providerChain.SenderAccount.GetAddress() delegate(s, delAddr, bondAmt) diff --git a/tests/integration/slashing.go b/tests/integration/slashing.go index d35c9d2b37..00f3434f63 100644 --- a/tests/integration/slashing.go +++ b/tests/integration/slashing.go @@ -7,6 +7,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" + "cosmossdk.io/math" evidencetypes "cosmossdk.io/x/evidence/types" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" sdk "github.com/cosmos/cosmos-sdk/types" @@ -718,7 +719,7 @@ func (suite *CCVTestSuite) TestCISBeforeCCVEstablished() { suite.Require().False(found) consumerKeeper.SlashWithInfractionReason(suite.consumerCtx(), []byte{0x01, 0x02, 0x3}, - 66, 4324, sdk.MustNewDecFromStr("0.05"), stakingtypes.Infraction_INFRACTION_DOWNTIME) + 66, 4324, math.LegacyMustNewDecFromStr("0.05"), stakingtypes.Infraction_INFRACTION_DOWNTIME) // Check slash packet was queued pendingPackets = consumerKeeper.GetPendingPackets(suite.consumerCtx()) diff --git a/tests/integration/stop_consumer.go b/tests/integration/stop_consumer.go index 80e9029713..76a6f5ffd2 100644 --- a/tests/integration/stop_consumer.go +++ b/tests/integration/stop_consumer.go @@ -1,6 +1,7 @@ package integration import ( + "cosmossdk.io/math" channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -31,11 +32,11 @@ func (s *CCVTestSuite) TestStopConsumerChain() { // define variables required for test setup var ( // bond amount - bondAmt = sdk.NewInt(1000000) + bondAmt = math.NewInt(1000000) // number of unbonding operations performed ubdOpsNum = 4 // store new shares created - testShares sdk.Dec + testShares math.LegacyDec ) // populate the provider chain states to setup the test using the following operations: diff --git a/tests/integration/throttle.go b/tests/integration/throttle.go index ebc7096c98..2979c0b9e8 100644 --- a/tests/integration/throttle.go +++ b/tests/integration/throttle.go @@ -3,6 +3,7 @@ package integration import ( "time" + "cosmossdk.io/math" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -572,7 +573,7 @@ func (s *CCVTestSuite) TestQueueOrdering() { // Confirm total power is now 3000 once updated by staking end blocker s.providerChain.NextBlock() totalPower := s.providerApp.GetTestStakingKeeper().GetLastTotalPower(s.providerCtx()) - s.Require().Equal(sdk.NewInt(3000), totalPower) + s.Require().Equal(math.NewInt(3000), totalPower) // Now change replenish frac to 0.67 and fully replenish the meter. params.SlashMeterReplenishFraction = "0.67" @@ -599,10 +600,10 @@ func (s *CCVTestSuite) TestSlashingSmallValidators() { // Setup first val with 1000 power and the rest with 10 power. delAddr := s.providerChain.SenderAccount.GetAddress() - delegateByIdx(s, delAddr, sdk.NewInt(999999999), 0) - delegateByIdx(s, delAddr, sdk.NewInt(9999999), 1) - delegateByIdx(s, delAddr, sdk.NewInt(9999999), 2) - delegateByIdx(s, delAddr, sdk.NewInt(9999999), 3) + delegateByIdx(s, delAddr, math.NewInt(999999999), 0) + delegateByIdx(s, delAddr, math.NewInt(9999999), 1) + delegateByIdx(s, delAddr, math.NewInt(9999999), 2) + delegateByIdx(s, delAddr, math.NewInt(9999999), 3) s.providerChain.NextBlock() // Initialize slash meter @@ -863,7 +864,7 @@ func (s *CCVTestSuite) TestLeadingVSCMaturedAreDequeued() { s.Require().Equal(len(globalEntries), 50*5) // Set slash meter to negative value to not allow any slash packets to be handled. - providerKeeper.SetSlashMeter(s.providerCtx(), sdk.NewInt(-1)) + providerKeeper.SetSlashMeter(s.providerCtx(), math.NewInt(-1)) // Set replenish time candidate so that no replenishment happens next block. providerKeeper.SetSlashMeterReplenishTimeCandidate(s.providerCtx()) diff --git a/tests/integration/unbonding.go b/tests/integration/unbonding.go index 35d1cfbae1..2fed6f033a 100644 --- a/tests/integration/unbonding.go +++ b/tests/integration/unbonding.go @@ -5,8 +5,6 @@ import ( "cosmossdk.io/math" - sdk "github.com/cosmos/cosmos-sdk/types" - providerkeeper "github.com/cosmos/interchain-security/v3/x/ccv/provider/keeper" ccv "github.com/cosmos/interchain-security/v3/x/ccv/types" ) @@ -89,7 +87,7 @@ func (s *CCVTestSuite) TestUndelegationNormalOperation() { providerKeeper.SetVscTimeoutPeriod(s.providerCtx(), providerUnbondingPeriod+consumerUnbondingPeriod+24*time.Hour) // delegate bondAmt and undelegate tc.shareDiv of it - bondAmt := sdk.NewInt(10000000) + bondAmt := math.NewInt(10000000) delAddr := s.providerChain.SenderAccount.GetAddress() initBalance, valsetUpdateID := delegateAndUndelegate(s, delAddr, bondAmt, tc.shareDiv) // - check that staking unbonding op was created and onHold is true @@ -110,7 +108,7 @@ func (s *CCVTestSuite) TestUndelegationNormalOperation() { // - check that staking unbonding op has been deleted checkStakingUnbondingOps(s, valsetUpdateID, false, false, "test: "+tc.name) // - check that necessary delegated coins have been returned - unbondAmt := bondAmt.Sub(bondAmt.Quo(sdk.NewInt(tc.shareDiv))) + unbondAmt := bondAmt.Sub(bondAmt.Quo(math.NewInt(tc.shareDiv))) s.Require().Equal( initBalance.Sub(unbondAmt), getBalance(s, s.providerCtx(), delAddr), @@ -137,7 +135,7 @@ func (s *CCVTestSuite) TestUndelegationVscTimeout() { vscTimeout := providerKeeper.GetVscTimeoutPeriod(s.providerCtx()) // delegate bondAmt and undelegate 1/2 of it - bondAmt := sdk.NewInt(10000000) + bondAmt := math.NewInt(10000000) delAddr := s.providerChain.SenderAccount.GetAddress() initBalance, valsetUpdateID := delegateAndUndelegate(s, delAddr, bondAmt, 2) // - check that staking unbonding op was created and onHold is true @@ -177,7 +175,7 @@ func (s *CCVTestSuite) TestUndelegationVscTimeout() { // - check that staking unbonding op has been deleted checkStakingUnbondingOps(s, valsetUpdateID, false, false) // - check that necessary delegated coins have been returned - unbondAmt := bondAmt.Sub(bondAmt.Quo(sdk.NewInt(2))) + unbondAmt := bondAmt.Sub(bondAmt.Quo(math.NewInt(2))) s.Require().Equal( initBalance.Sub(unbondAmt), getBalance(s, s.providerCtx(), delAddr), @@ -218,7 +216,7 @@ func (s *CCVTestSuite) TestUndelegationDuringInit() { stakingKeeper := s.providerApp.GetTestStakingKeeper() // delegate bondAmt and undelegate 1/2 of it - bondAmt := sdk.NewInt(10000000) + bondAmt := math.NewInt(10000000) delAddr := s.providerChain.SenderAccount.GetAddress() initBalance, valsetUpdateID := delegateAndUndelegate(s, delAddr, bondAmt, 2) // - check that staking unbonding op was created and onHold is true @@ -283,7 +281,7 @@ func (s *CCVTestSuite) TestUndelegationDuringInit() { checkStakingUnbondingOps(s, valsetUpdateID, false, false, "test: "+tc.name) // - check that one quarter the delegated coins have been returned s.Require().Equal( - initBalance.Sub(bondAmt).Sub(bondAmt.Quo(sdk.NewInt(2))), + initBalance.Sub(bondAmt).Sub(bondAmt.Quo(math.NewInt(2))), getBalance(s, s.providerCtx(), delAddr), "unexpected initial balance after unbonding; test: %s", tc.name, ) @@ -312,7 +310,7 @@ func (s *CCVTestSuite) TestUnbondingNoConsumer() { } // delegate bondAmt and undelegate 1/2 of it - bondAmt := sdk.NewInt(10000000) + bondAmt := math.NewInt(10000000) delAddr := s.providerChain.SenderAccount.GetAddress() initBalance, valsetUpdateID := delegateAndUndelegate(s, delAddr, bondAmt, 2) // - check that staking unbonding op was created and onHold is FALSE @@ -333,7 +331,7 @@ func (s *CCVTestSuite) TestUnbondingNoConsumer() { // - check that staking unbonding op has been deleted checkStakingUnbondingOps(s, valsetUpdateID, false, false) // - check that half the coins have been returned - s.Require().True(getBalance(s, s.providerCtx(), delAddr).Equal(initBalance.Sub(bondAmt.Quo(sdk.NewInt(2))))) + s.Require().True(getBalance(s, s.providerCtx(), delAddr).Equal(initBalance.Sub(bondAmt.Quo(math.NewInt(2))))) } // TestRedelegationNoConsumer tests a redelegate transaction @@ -347,7 +345,7 @@ func (s *CCVTestSuite) TestRedelegationNoConsumer() { s.Require().NoError(err) // Setup delegator, bond amount, and src/dst validators - bondAmt := sdk.NewInt(10000000) + bondAmt := math.NewInt(10000000) delAddr := s.providerChain.SenderAccount.GetAddress() _, srcVal := s.getValByIdx(0) _, dstVal := s.getValByIdx(1) @@ -400,7 +398,7 @@ func (s *CCVTestSuite) TestRedelegationProviderFirst() { providerKeeper.SetVscTimeoutPeriod(s.providerCtx(), providerUnbondingPeriod+consumerUnbondingPeriod+24*time.Hour) // Setup delegator, bond amount, and src/dst validators - bondAmt := sdk.NewInt(10000000) + bondAmt := math.NewInt(10000000) delAddr := s.providerChain.SenderAccount.GetAddress() _, srcVal := s.getValByIdx(0) _, dstVal := s.getValByIdx(1) diff --git a/tests/integration/valset_update.go b/tests/integration/valset_update.go index 4e0c6d352d..b4996d622d 100644 --- a/tests/integration/valset_update.go +++ b/tests/integration/valset_update.go @@ -3,10 +3,10 @@ package integration import ( "time" + "cosmossdk.io/math" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" - sdk "github.com/cosmos/cosmos-sdk/types" abci "github.com/cometbft/cometbft/abci/types" @@ -19,7 +19,7 @@ func (s *CCVTestSuite) TestPacketRoundtrip() { s.SetupTransferChannel() // Bond some tokens on provider to change validator powers - bondAmt := sdk.NewInt(1000000) + bondAmt := math.NewInt(1000000) delAddr := s.providerChain.SenderAccount.GetAddress() delegate(s, delAddr, bondAmt) diff --git a/testutil/integration/interfaces.go b/testutil/integration/interfaces.go index 116e4fdf76..1c13ddf803 100644 --- a/testutil/integration/interfaces.go +++ b/testutil/integration/interfaces.go @@ -91,11 +91,11 @@ type DemocConsumerApp interface { type TestStakingKeeper interface { ccvtypes.StakingKeeper Delegate(ctx sdk.Context, delAddr sdk.AccAddress, bondAmt math.Int, tokenSrc types.BondStatus, - validator types.Validator, subtractAccount bool) (newShares sdk.Dec, err error) - Undelegate(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress, sharesAmount sdk.Dec, + validator types.Validator, subtractAccount bool) (newShares math.LegacyDec, err error) + Undelegate(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress, sharesAmount math.LegacyDec, ) (time.Time, error) BeginRedelegation(ctx sdk.Context, delAddr sdk.AccAddress, valSrcAddr, valDstAddr sdk.ValAddress, - sharesAmount sdk.Dec) (completionTime time.Time, err error) + sharesAmount math.LegacyDec) (completionTime time.Time, err error) GetUnbondingDelegationByUnbondingID(ctx sdk.Context, id uint64, ) (ubd types.UnbondingDelegation, found bool) GetRedelegations(ctx sdk.Context, delegator sdk.AccAddress, @@ -141,7 +141,7 @@ type TestDistributionKeeper interface { GetDistributionAccount(ctx sdk.Context) authtypes.ModuleAccountI GetValidatorOutstandingRewards(ctx sdk.Context, val sdk.ValAddress) (rewards distributiontypes.ValidatorOutstandingRewards) - GetCommunityTax(ctx sdk.Context) (percent sdk.Dec) + GetCommunityTax(ctx sdk.Context) (percent math.LegacyDec) } type TestMintKeeper interface { diff --git a/x/ccv/consumer/keeper/distribution.go b/x/ccv/consumer/keeper/distribution.go index f9995d24dd..64240990cb 100644 --- a/x/ccv/consumer/keeper/distribution.go +++ b/x/ccv/consumer/keeper/distribution.go @@ -9,6 +9,7 @@ import ( channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" errorsmod "cosmossdk.io/errors" + "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" @@ -56,7 +57,7 @@ func (k Keeper) DistributeRewardsInternally(ctx sdk.Context) { fpTokens := k.bankKeeper.GetAllBalances(ctx, consumerFeePoolAddr) // split the fee pool, send the consumer's fraction to the consumer redistribution address - frac, err := sdk.NewDecFromStr(k.GetConsumerRedistributionFrac(ctx)) + frac, err := math.LegacyNewDecFromStr(k.GetConsumerRedistributionFrac(ctx)) if err != nil { // ConsumerRedistributionFrac was already validated when set as a param panic(fmt.Errorf("ConsumerRedistributionFrac is invalid: %w", err)) @@ -253,7 +254,7 @@ func (k Keeper) GetEstimatedNextFeeDistribution(ctx sdk.Context) types.NextFeeDi total := k.bankKeeper.GetAllBalances(ctx, consumerFeePoolAddr) fracParam := k.GetConsumerRedistributionFrac(ctx) - frac, err := sdk.NewDecFromStr(fracParam) + frac, err := math.LegacyNewDecFromStr(fracParam) if err != nil { // ConsumerRedistributionFrac was already validated when set as a param panic(fmt.Errorf("ConsumerRedistributionFrac is invalid: %w", err)) diff --git a/x/ccv/consumer/keeper/distribution_test.go b/x/ccv/consumer/keeper/distribution_test.go index 4a611f2d1e..5ba5f70f29 100644 --- a/x/ccv/consumer/keeper/distribution_test.go +++ b/x/ccv/consumer/keeper/distribution_test.go @@ -4,6 +4,7 @@ import ( "strings" "testing" + "cosmossdk.io/math" "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" @@ -30,11 +31,11 @@ func TestGetEstimatedNextFeeDistribution(t *testing.T) { // Setup mock account balance fracParam := consumerKeeper.GetConsumerRedistributionFrac(ctx) - fracDec, err := sdk.NewDecFromStr(fracParam) + fracDec, err := math.LegacyNewDecFromStr(fracParam) require.NoError(t, err) feeAmount := sdk.Coin{ Denom: "MOCK", - Amount: sdk.NewInt(100), + Amount: math.NewInt(100), } feeAmountCoins := sdk.Coins([]sdk.Coin{feeAmount}) feeAmountDec := sdk.NewDecCoinsFromCoins(feeAmountCoins...) diff --git a/x/ccv/consumer/keeper/soft_opt_out.go b/x/ccv/consumer/keeper/soft_opt_out.go index 09b8a9be79..41460e7917 100644 --- a/x/ccv/consumer/keeper/soft_opt_out.go +++ b/x/ccv/consumer/keeper/soft_opt_out.go @@ -4,6 +4,7 @@ import ( "encoding/binary" "sort" + "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/interchain-security/v3/x/ccv/consumer/types" @@ -20,7 +21,7 @@ func (k Keeper) SetSmallestNonOptOutPower(ctx sdk.Context, power uint64) { // is less than [SoftOptOutThreshold] of the total power of all validators. func (k Keeper) UpdateSmallestNonOptOutPower(ctx sdk.Context) { // get soft opt-out threshold - optOutThreshold := sdk.MustNewDecFromStr(k.GetSoftOptOutThreshold(ctx)) + optOutThreshold := math.LegacyMustNewDecFromStr(k.GetSoftOptOutThreshold(ctx)) if optOutThreshold.IsZero() { // If the SoftOptOutThreshold is zero, then soft opt-out is disable. // Setting the smallest non-opt-out power to zero, fixes the diff-testing @@ -44,15 +45,15 @@ func (k Keeper) UpdateSmallestNonOptOutPower(ctx sdk.Context) { }) // get total power in set - totalPower := sdk.ZeroDec() + totalPower := math.LegacyZeroDec() for _, val := range valset { - totalPower = totalPower.Add(sdk.NewDecFromInt(sdk.NewInt(val.Power))) + totalPower = totalPower.Add(math.LegacyNewDecFromInt(math.NewInt(val.Power))) } // get power of the smallest validator that cannot soft opt out - powerSum := sdk.ZeroDec() + powerSum := math.LegacyZeroDec() for _, val := range valset { - powerSum = powerSum.Add(sdk.NewDecFromInt(sdk.NewInt(val.Power))) + powerSum = powerSum.Add(math.LegacyNewDecFromInt(math.NewInt(val.Power))) // if powerSum / totalPower > SoftOptOutThreshold if powerSum.Quo(totalPower).GT(optOutThreshold) { // set smallest non opt out power diff --git a/x/ccv/consumer/keeper/validators.go b/x/ccv/consumer/keeper/validators.go index 2233b22d28..5c1cb06f8b 100644 --- a/x/ccv/consumer/keeper/validators.go +++ b/x/ccv/consumer/keeper/validators.go @@ -111,14 +111,14 @@ func (k Keeper) ValidatorByConsAddr(sdk.Context, sdk.ConsAddress) stakingtypes.V // Calls SlashWithInfractionReason with Infraction_INFRACTION_UNSPECIFIED. // ConsumerKeeper must implement StakingKeeper interface. // This function should not be called anywhere -func (k Keeper) Slash(ctx sdk.Context, addr sdk.ConsAddress, infractionHeight, power int64, slashFactor sdk.Dec) math.Int { +func (k Keeper) Slash(ctx sdk.Context, addr sdk.ConsAddress, infractionHeight, power int64, slashFactor math.LegacyDec) math.Int { return k.SlashWithInfractionReason(ctx, addr, infractionHeight, power, slashFactor, stakingtypes.Infraction_INFRACTION_UNSPECIFIED) } // Slash queues a slashing request for the the provider chain // All queued slashing requests will be cleared in EndBlock // Called by Slashing keeper in SlashWithInfractionReason -func (k Keeper) SlashWithInfractionReason(ctx sdk.Context, addr sdk.ConsAddress, infractionHeight, power int64, slashFactor sdk.Dec, infraction stakingtypes.Infraction) math.Int { +func (k Keeper) SlashWithInfractionReason(ctx sdk.Context, addr sdk.ConsAddress, infractionHeight, power int64, slashFactor math.LegacyDec, infraction stakingtypes.Infraction) math.Int { if infraction == stakingtypes.Infraction_INFRACTION_UNSPECIFIED { return math.NewInt(0) } diff --git a/x/ccv/provider/keeper/genesis_test.go b/x/ccv/provider/keeper/genesis_test.go index adde08d914..27e4503f1e 100644 --- a/x/ccv/provider/keeper/genesis_test.go +++ b/x/ccv/provider/keeper/genesis_test.go @@ -5,6 +5,7 @@ import ( "testing" "time" + "cosmossdk.io/math" host "github.com/cosmos/ibc-go/v8/modules/core/24-host" "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" @@ -137,7 +138,7 @@ func TestInitAndExportGenesis(t *testing.T) { ctx, host.PortPath(ccv.ProviderPortID), ).Return(nil, true).Times(1), mocks.MockStakingKeeper.EXPECT().GetLastTotalPower( - ctx).Return(sdk.NewInt(100)).Times(1), // Return total voting power as 100 + ctx).Return(math.NewInt(100)).Times(1), // Return total voting power as 100 ) // init provider chain @@ -146,9 +147,9 @@ func TestInitAndExportGenesis(t *testing.T) { // Expect slash meter to be initialized to it's allowance value // (replenish fraction * mocked value defined above) slashMeter := pk.GetSlashMeter(ctx) - replenishFraction, err := sdk.NewDecFromStr(pk.GetParams(ctx).SlashMeterReplenishFraction) + replenishFraction, err := math.LegacyNewDecFromStr(pk.GetParams(ctx).SlashMeterReplenishFraction) require.NoError(t, err) - expectedSlashMeterValue := sdk.NewInt(replenishFraction.MulInt(sdk.NewInt(100)).RoundInt64()) + expectedSlashMeterValue := math.NewInt(replenishFraction.MulInt(math.NewInt(100)).RoundInt64()) require.Equal(t, expectedSlashMeterValue, slashMeter) // Expect slash meter replenishment time candidate to be set to the current block time + replenish period diff --git a/x/ccv/provider/keeper/hooks.go b/x/ccv/provider/keeper/hooks.go index 35c9b96301..bdd9d08758 100644 --- a/x/ccv/provider/keeper/hooks.go +++ b/x/ccv/provider/keeper/hooks.go @@ -1,6 +1,7 @@ package keeper import ( + "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -148,7 +149,7 @@ func (h Hooks) AfterDelegationModified(_ sdk.Context, _ sdk.AccAddress, _ sdk.Va return nil } -func (h Hooks) BeforeValidatorSlashed(_ sdk.Context, _ sdk.ValAddress, _ sdk.Dec) error { +func (h Hooks) BeforeValidatorSlashed(_ sdk.Context, _ sdk.ValAddress, _ math.LegacyDec) error { return nil } diff --git a/x/ccv/provider/keeper/params_test.go b/x/ccv/provider/keeper/params_test.go index 3335bf0603..ec938fffe7 100644 --- a/x/ccv/provider/keeper/params_test.go +++ b/x/ccv/provider/keeper/params_test.go @@ -4,6 +4,7 @@ import ( "testing" "time" + "cosmossdk.io/math" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types" ibctmtypes "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" @@ -47,7 +48,7 @@ func TestParams(t *testing.T) { 100, sdk.Coin{ Denom: "stake", - Amount: sdk.NewInt(10000000), + Amount: math.NewInt(10000000), }, ) providerKeeper.SetParams(ctx, newParams) diff --git a/x/ccv/provider/keeper/proposal_test.go b/x/ccv/provider/keeper/proposal_test.go index e321f00d0b..df6b738b1e 100644 --- a/x/ccv/provider/keeper/proposal_test.go +++ b/x/ccv/provider/keeper/proposal_test.go @@ -13,6 +13,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" + "cosmossdk.io/math" evidencetypes "cosmossdk.io/x/evidence/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -796,7 +797,7 @@ func TestMakeConsumerGenesis(t *testing.T) { MaxThrottledPackets: providertypes.DefaultMaxThrottledPackets, ConsumerRewardDenomRegistrationFee: sdk.Coin{ Denom: "stake", - Amount: sdk.NewInt(1000000), + Amount: math.NewInt(1000000), }, } providerKeeper.SetParams(ctx, moduleParams) diff --git a/x/ccv/provider/keeper/throttle_test.go b/x/ccv/provider/keeper/throttle_test.go index a5356b0dc0..437f238008 100644 --- a/x/ccv/provider/keeper/throttle_test.go +++ b/x/ccv/provider/keeper/throttle_test.go @@ -190,20 +190,20 @@ func TestSlashMeterReplenishment(t *testing.T) { { replenishPeriod: time.Minute, replenishFraction: "0.01", - totalPower: sdktypes.NewInt(1000), - expectedAllowance: sdktypes.NewInt(10), + totalPower: math.NewInt(1000), + expectedAllowance: math.NewInt(10), }, { replenishPeriod: time.Hour, replenishFraction: "0.1", - totalPower: sdktypes.NewInt(100000), - expectedAllowance: sdktypes.NewInt(10000), + totalPower: math.NewInt(100000), + expectedAllowance: math.NewInt(10000), }, { replenishPeriod: 30 * time.Minute, replenishFraction: "0.5", - totalPower: sdktypes.NewInt(1000000000000000), - expectedAllowance: sdktypes.NewInt(500000000000000), + totalPower: math.NewInt(1000000000000000), + expectedAllowance: math.NewInt(500000000000000), }, } for _, tc := range testCases { @@ -239,8 +239,8 @@ func TestSlashMeterReplenishment(t *testing.T) { require.Equal(t, now.Add(tc.replenishPeriod), initialReplenishCandidate) // Decrement slash meter - providerKeeper.SetSlashMeter(ctx, providerKeeper.GetSlashMeter(ctx).Sub(sdktypes.NewInt(3))) - require.Equal(t, tc.expectedAllowance.Sub(sdktypes.NewInt(3)), providerKeeper.GetSlashMeter(ctx)) + providerKeeper.SetSlashMeter(ctx, providerKeeper.GetSlashMeter(ctx).Sub(math.NewInt(3))) + require.Equal(t, tc.expectedAllowance.Sub(math.NewInt(3)), providerKeeper.GetSlashMeter(ctx)) // Check for replenishment, confirm meter is not replenished (since no time has passed since init) meterBefore := providerKeeper.GetSlashMeter(ctx) @@ -306,7 +306,7 @@ func TestConsecutiveReplenishments(t *testing.T) { // Any ctx is accepted, and the method will be called multiple times during the tests gomock.InOrder( mocks.MockStakingKeeper.EXPECT().GetLastTotalPower( - gomock.Any()).Return(sdktypes.NewInt(1000)).AnyTimes(), + gomock.Any()).Return(math.NewInt(1000)).AnyTimes(), ) // Now we can initialize the slash meter (this would happen in InitGenesis) @@ -319,45 +319,45 @@ func TestConsecutiveReplenishments(t *testing.T) { require.Equal(t, now.Add(time.Hour), providerKeeper.GetSlashMeterReplenishTimeCandidate(ctx)) // Decrement slash meter to negative value that would take 4 replenishments to recover from - providerKeeper.SetSlashMeter(ctx, sdktypes.NewInt(-150)) + providerKeeper.SetSlashMeter(ctx, math.NewInt(-150)) // Confirm no replenishment occurs when no time has passed, replenish candidate is not updated providerKeeper.CheckForSlashMeterReplenishment(ctx) - require.Equal(t, sdktypes.NewInt(-150), providerKeeper.GetSlashMeter(ctx)) + require.Equal(t, math.NewInt(-150), providerKeeper.GetSlashMeter(ctx)) require.Equal(t, now.Add(time.Hour), providerKeeper.GetSlashMeterReplenishTimeCandidate(ctx)) // Now increment block time past replenishment period and confirm that meter is replenished ONCE, // and replenish candidate is updated to block time + replenish period ctx = ctx.WithBlockTime(ctx.BlockTime().Add(2 * time.Hour)) providerKeeper.CheckForSlashMeterReplenishment(ctx) - require.Equal(t, sdktypes.NewInt(-100), providerKeeper.GetSlashMeter(ctx)) + require.Equal(t, math.NewInt(-100), providerKeeper.GetSlashMeter(ctx)) require.Equal(t, now.Add(3*time.Hour), providerKeeper.GetSlashMeterReplenishTimeCandidate(ctx)) // Note 3 hours, not 2 // Simulate next block and check that no consecutive replenishments occur (replenish period has not passed) // and replenish candidate is not updated ctx = ctx.WithBlockTime(ctx.BlockTime().Add(5 * time.Second)) providerKeeper.CheckForSlashMeterReplenishment(ctx) - require.Equal(t, sdktypes.NewInt(-100), providerKeeper.GetSlashMeter(ctx)) + require.Equal(t, math.NewInt(-100), providerKeeper.GetSlashMeter(ctx)) require.Equal(t, now.Add(3*time.Hour), providerKeeper.GetSlashMeterReplenishTimeCandidate(ctx)) // Increment block time past replenishment period and confirm that meter is replenished ONCE more // and replenish candidate is updated to block time + replenish period ctx = ctx.WithBlockTime(ctx.BlockTime().Add(time.Hour * 1)) providerKeeper.CheckForSlashMeterReplenishment(ctx) - require.Equal(t, sdktypes.NewInt(-50), providerKeeper.GetSlashMeter(ctx)) + require.Equal(t, math.NewInt(-50), providerKeeper.GetSlashMeter(ctx)) require.Equal(t, now.Add(4*time.Hour).Add(5*time.Second), providerKeeper.GetSlashMeterReplenishTimeCandidate(ctx)) // Replenishments should happen if we increment block times past replenishment period ctx = ctx.WithBlockTime(ctx.BlockTime().Add(time.Hour * 1)) providerKeeper.CheckForSlashMeterReplenishment(ctx) - require.Equal(t, sdktypes.NewInt(0), providerKeeper.GetSlashMeter(ctx)) + require.Equal(t, math.NewInt(0), providerKeeper.GetSlashMeter(ctx)) require.Equal(t, now.Add(5*time.Hour).Add(5*time.Second), providerKeeper.GetSlashMeterReplenishTimeCandidate(ctx)) providerKeeper.CheckForSlashMeterReplenishment(ctx) - require.Equal(t, sdktypes.NewInt(0), providerKeeper.GetSlashMeter(ctx)) + require.Equal(t, math.NewInt(0), providerKeeper.GetSlashMeter(ctx)) require.Equal(t, now.Add(5*time.Hour).Add(5*time.Second), providerKeeper.GetSlashMeterReplenishTimeCandidate(ctx)) ctx = ctx.WithBlockTime(ctx.BlockTime().Add(time.Hour * 1)) providerKeeper.CheckForSlashMeterReplenishment(ctx) - require.Equal(t, sdktypes.NewInt(50), providerKeeper.GetSlashMeter(ctx)) + require.Equal(t, math.NewInt(50), providerKeeper.GetSlashMeter(ctx)) require.Equal(t, now.Add(6*time.Hour).Add(5*time.Second), providerKeeper.GetSlashMeterReplenishTimeCandidate(ctx)) } @@ -379,28 +379,28 @@ func TestTotalVotingPowerChanges(t *testing.T) { gomock.InOrder( mocks.MockStakingKeeper.EXPECT().GetLastTotalPower( // Expect two calls, once for initialization, once for allowance check - ctx).Return(sdktypes.NewInt(1000)).Times(2), + ctx).Return(math.NewInt(1000)).Times(2), ) // Initialize the slash meter (this would happen in InitGenesis) providerKeeper.InitializeSlashMeter(ctx) // Confirm slash meter is full, and allowance is expected value via params - require.Equal(t, sdktypes.NewInt(100), providerKeeper.GetSlashMeterAllowance(ctx)) - require.Equal(t, sdktypes.NewInt(100), providerKeeper.GetSlashMeter(ctx)) + require.Equal(t, math.NewInt(100), providerKeeper.GetSlashMeterAllowance(ctx)) + require.Equal(t, math.NewInt(100), providerKeeper.GetSlashMeter(ctx)) // Mutate context so mocked total power is less than before ctx = ctx.WithBlockTime(ctx.BlockTime().Add(time.Microsecond)) // Don't add enough time for replenishment gomock.InOrder( mocks.MockStakingKeeper.EXPECT().GetLastTotalPower( // Expect two calls, once for replenish check, once for allowance check - ctx).Return(sdktypes.NewInt(500)).Times(2), + ctx).Return(math.NewInt(500)).Times(2), ) // Replenishment should not happen here, but slash meter should be decremented to new allowance providerKeeper.CheckForSlashMeterReplenishment(ctx) - require.Equal(t, sdktypes.NewInt(50), providerKeeper.GetSlashMeterAllowance(ctx)) - require.Equal(t, sdktypes.NewInt(50), providerKeeper.GetSlashMeter(ctx)) + require.Equal(t, math.NewInt(50), providerKeeper.GetSlashMeterAllowance(ctx)) + require.Equal(t, math.NewInt(50), providerKeeper.GetSlashMeter(ctx)) // Mutate context so mocked total power is again less than before, // with ctx time set to a time that will replenish meter @@ -409,20 +409,20 @@ func TestTotalVotingPowerChanges(t *testing.T) { mocks.MockStakingKeeper.EXPECT().GetLastTotalPower( // Expect three calls, once for replenish check, // once for replenishment, once for allowance check - ctx).Return(sdktypes.NewInt(100)).Times(3), + ctx).Return(math.NewInt(100)).Times(3), ) // Replenishment should happen here, slash meter should be decremented to new allowance regardless providerKeeper.CheckForSlashMeterReplenishment(ctx) - require.Equal(t, sdktypes.NewInt(10), providerKeeper.GetSlashMeterAllowance(ctx)) - require.Equal(t, sdktypes.NewInt(10), providerKeeper.GetSlashMeter(ctx)) + require.Equal(t, math.NewInt(10), providerKeeper.GetSlashMeterAllowance(ctx)) + require.Equal(t, math.NewInt(10), providerKeeper.GetSlashMeter(ctx)) // Mutate context so mocked total power is now more than before ctx = ctx.WithBlockTime(ctx.BlockTime().Add(time.Microsecond)) // Don't add enough time for replenishment gomock.InOrder( mocks.MockStakingKeeper.EXPECT().GetLastTotalPower( // Expect two calls, once for replenish check, once for allowance check - ctx).Return(sdktypes.NewInt(5000)).Times(2), + ctx).Return(math.NewInt(5000)).Times(2), ) // @@ -431,8 +431,8 @@ func TestTotalVotingPowerChanges(t *testing.T) { // Replenishment should not happen here, slash meter should remain at previous value providerKeeper.CheckForSlashMeterReplenishment(ctx) - require.Equal(t, sdktypes.NewInt(500), providerKeeper.GetSlashMeterAllowance(ctx)) - require.Equal(t, sdktypes.NewInt(10), providerKeeper.GetSlashMeter(ctx)) + require.Equal(t, math.NewInt(500), providerKeeper.GetSlashMeterAllowance(ctx)) + require.Equal(t, math.NewInt(10), providerKeeper.GetSlashMeter(ctx)) // Mutate context so mocked total power is again more than before, // with ctx time set to a time that will replenish meter @@ -441,13 +441,13 @@ func TestTotalVotingPowerChanges(t *testing.T) { mocks.MockStakingKeeper.EXPECT().GetLastTotalPower( // Expect three calls, once for replenish check, // once for replenishment, once for allowance check - ctx).Return(sdktypes.NewInt(10000)).Times(3), + ctx).Return(math.NewInt(10000)).Times(3), ) // Replenishment should happen here, slash meter should be set to new allowance providerKeeper.CheckForSlashMeterReplenishment(ctx) - require.Equal(t, sdktypes.NewInt(1000), providerKeeper.GetSlashMeterAllowance(ctx)) - require.Equal(t, sdktypes.NewInt(1000), providerKeeper.GetSlashMeter(ctx)) + require.Equal(t, math.NewInt(1000), providerKeeper.GetSlashMeterAllowance(ctx)) + require.Equal(t, math.NewInt(1000), providerKeeper.GetSlashMeter(ctx)) } // TestNegativeSlashMeter tests behavior of the slash meter when it goes negative, @@ -466,33 +466,33 @@ func TestNegativeSlashMeter(t *testing.T) { // Slashing 100 of voting power makes total voting power = 900, and meter = -90. // Expected replenish allowance is then 9, meaning it'd take 10 replenishes // for meter to reach 0 in value, and 11 replenishes for meter to reach a value of 9. - slashedPower: sdktypes.NewInt(100), - totalPower: sdktypes.NewInt(1000), + slashedPower: math.NewInt(100), + totalPower: math.NewInt(1000), replenishFraction: "0.01", numReplenishesTillFull: 11, - finalMeterValue: sdktypes.NewInt(9), + finalMeterValue: math.NewInt(9), }, { // Meter is initialized to a value of: 0.1*100 = 10. // Slashing 30 of voting power makes total voting power = 70, and meter = -20. // Expected replenish allowance is then 7, meaning it'd take 3 replenishes // for meter to reach 1 in value, and 4 replenishes for meter to reach a value of 7. - slashedPower: sdktypes.NewInt(30), - totalPower: sdktypes.NewInt(100), + slashedPower: math.NewInt(30), + totalPower: math.NewInt(100), replenishFraction: "0.1", numReplenishesTillFull: 4, - finalMeterValue: sdktypes.NewInt(7), + finalMeterValue: math.NewInt(7), }, { // Meter is initialized to a value of 1, since replenish fraction is too low, and min allowance is 1. // Slashing 5 of voting power makes total voting power = 995, and meter = -4. // Expected replenish allowance is then 1 (still minimum amount), meaning it'd take 4 replenishes // for meter to reach 0 in value, and 5 replenishes for meter to reach a value of 1. - slashedPower: sdktypes.NewInt(5), - totalPower: sdktypes.NewInt(1000), + slashedPower: math.NewInt(5), + totalPower: math.NewInt(1000), replenishFraction: "0.0000001", numReplenishesTillFull: 5, - finalMeterValue: sdktypes.NewInt(1), + finalMeterValue: math.NewInt(1), }, } @@ -520,11 +520,11 @@ func TestNegativeSlashMeter(t *testing.T) { // remaining calls to GetLastTotalPower should return the second mocked value. // Confirm that meter is initialized to expected initial allowance - decFrac, err := sdktypes.NewDecFromStr(tc.replenishFraction) + decFrac, err := math.LegacyNewDecFromStr(tc.replenishFraction) require.NoError(t, err) - expectedInitAllowance := sdktypes.NewInt(decFrac.MulInt(tc.totalPower).RoundInt64()) + expectedInitAllowance := math.NewInt(decFrac.MulInt(tc.totalPower).RoundInt64()) if expectedInitAllowance.IsZero() { // Allowances have a minimum of 1. - expectedInitAllowance = sdktypes.NewInt(1) + expectedInitAllowance = math.NewInt(1) } require.Equal(t, expectedInitAllowance, providerKeeper.GetSlashMeter(ctx)) @@ -534,9 +534,9 @@ func TestNegativeSlashMeter(t *testing.T) { require.True(t, providerKeeper.GetSlashMeter(ctx).LT(before)) // New expected allowance is replenish fraction * (total power - slashed power) - expectedNewAllowance := sdktypes.NewInt(decFrac.MulInt(tc.totalPower.Sub(tc.slashedPower)).RoundInt64()) + expectedNewAllowance := math.NewInt(decFrac.MulInt(tc.totalPower.Sub(tc.slashedPower)).RoundInt64()) if expectedNewAllowance.IsZero() { - expectedNewAllowance = sdktypes.NewInt(1) + expectedNewAllowance = math.NewInt(1) } require.Equal(t, expectedNewAllowance, providerKeeper.GetSlashMeterAllowance(ctx)) @@ -576,33 +576,33 @@ func TestGetSlashMeterAllowance(t *testing.T) { }{ { replenishFraction: "0.00", - totalPower: sdktypes.NewInt(100), - expectedAllowance: sdktypes.NewInt(1), // 0.0 * 100 = 0, 1 is returned + totalPower: math.NewInt(100), + expectedAllowance: math.NewInt(1), // 0.0 * 100 = 0, 1 is returned }, { replenishFraction: "0.00000000001", - totalPower: sdktypes.NewInt(100), - expectedAllowance: sdktypes.NewInt(1), // 0.00000000001 * 100 = 0 (bankers rounding), 1 is returned + totalPower: math.NewInt(100), + expectedAllowance: math.NewInt(1), // 0.00000000001 * 100 = 0 (bankers rounding), 1 is returned }, { replenishFraction: "0.01", - totalPower: sdktypes.NewInt(100), - expectedAllowance: sdktypes.NewInt(1), // 0.00000000001 * 100 = 0 (bankers rounding), 1 is returned + totalPower: math.NewInt(100), + expectedAllowance: math.NewInt(1), // 0.00000000001 * 100 = 0 (bankers rounding), 1 is returned }, { replenishFraction: "0.015", - totalPower: sdktypes.NewInt(100), - expectedAllowance: sdktypes.NewInt(2), // 0.015 * 10 = 2 (bankers rounding) + totalPower: math.NewInt(100), + expectedAllowance: math.NewInt(2), // 0.015 * 10 = 2 (bankers rounding) }, { replenishFraction: "0.27", - totalPower: sdktypes.NewInt(100), - expectedAllowance: sdktypes.NewInt(27), + totalPower: math.NewInt(100), + expectedAllowance: math.NewInt(27), }, { replenishFraction: "0.34", - totalPower: sdktypes.NewInt(10000000), - expectedAllowance: sdktypes.NewInt(3400000), + totalPower: math.NewInt(10000000), + expectedAllowance: math.NewInt(3400000), }, } for _, tc := range testCases { @@ -1255,18 +1255,18 @@ func TestSlashMeter(t *testing.T) { meterValue math.Int shouldPanic bool }{ - {meterValue: sdktypes.NewInt(-7999999999999999999), shouldPanic: true}, - {meterValue: sdktypes.NewInt(-tmtypes.MaxTotalVotingPower - 1), shouldPanic: true}, - {meterValue: sdktypes.NewInt(-tmtypes.MaxTotalVotingPower), shouldPanic: false}, - {meterValue: sdktypes.NewInt(-50000000078987), shouldPanic: false}, - {meterValue: sdktypes.NewInt(-4237), shouldPanic: false}, - {meterValue: sdktypes.NewInt(0), shouldPanic: false}, - {meterValue: sdktypes.NewInt(1), shouldPanic: false}, - {meterValue: sdktypes.NewInt(4237897), shouldPanic: false}, - {meterValue: sdktypes.NewInt(500078078987), shouldPanic: false}, - {meterValue: sdktypes.NewInt(tmtypes.MaxTotalVotingPower), shouldPanic: false}, - {meterValue: sdktypes.NewInt(tmtypes.MaxTotalVotingPower + 1), shouldPanic: true}, - {meterValue: sdktypes.NewInt(7999974823991111199), shouldPanic: true}, + {meterValue: math.NewInt(-7999999999999999999), shouldPanic: true}, + {meterValue: math.NewInt(-tmtypes.MaxTotalVotingPower - 1), shouldPanic: true}, + {meterValue: math.NewInt(-tmtypes.MaxTotalVotingPower), shouldPanic: false}, + {meterValue: math.NewInt(-50000000078987), shouldPanic: false}, + {meterValue: math.NewInt(-4237), shouldPanic: false}, + {meterValue: math.NewInt(0), shouldPanic: false}, + {meterValue: math.NewInt(1), shouldPanic: false}, + {meterValue: math.NewInt(4237897), shouldPanic: false}, + {meterValue: math.NewInt(500078078987), shouldPanic: false}, + {meterValue: math.NewInt(tmtypes.MaxTotalVotingPower), shouldPanic: false}, + {meterValue: math.NewInt(tmtypes.MaxTotalVotingPower + 1), shouldPanic: true}, + {meterValue: math.NewInt(7999974823991111199), shouldPanic: true}, } for _, tc := range testCases { diff --git a/x/ccv/provider/module_test.go b/x/ccv/provider/module_test.go index 6a22e9e09a..63a6fc8076 100644 --- a/x/ccv/provider/module_test.go +++ b/x/ccv/provider/module_test.go @@ -3,12 +3,12 @@ package provider_test import ( "testing" + "cosmossdk.io/math" host "github.com/cosmos/ibc-go/v8/modules/core/24-host" "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - sdk "github.com/cosmos/cosmos-sdk/types" capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" testkeeper "github.com/cosmos/interchain-security/v3/testutil/keeper" @@ -143,7 +143,7 @@ func TestInitGenesis(t *testing.T) { if !tc.expPanic { orderedCalls = append(orderedCalls, mocks.MockStakingKeeper.EXPECT().GetLastTotalPower( - ctx).Return(sdk.NewInt(100)).Times(1), // Return total voting power as 100 + ctx).Return(math.NewInt(100)).Times(1), // Return total voting power as 100 ) } @@ -179,9 +179,9 @@ func TestInitGenesis(t *testing.T) { // Expect slash meter to be initialized to it's allowance value // (replenish fraction * mocked value defined above) slashMeter := providerKeeper.GetSlashMeter(ctx) - replenishFraction, err := sdk.NewDecFromStr(providerKeeper.GetParams(ctx).SlashMeterReplenishFraction) + replenishFraction, err := math.LegacyNewDecFromStr(providerKeeper.GetParams(ctx).SlashMeterReplenishFraction) require.NoError(t, err) - expectedSlashMeterValue := sdk.NewInt(replenishFraction.MulInt(sdk.NewInt(100)).RoundInt64()) + expectedSlashMeterValue := math.NewInt(replenishFraction.MulInt(math.NewInt(100)).RoundInt64()) require.Equal(t, expectedSlashMeterValue, slashMeter) // Expect slash meter replenishment time candidate to be set to the current block time + replenish period diff --git a/x/ccv/provider/proposal_handler_test.go b/x/ccv/provider/proposal_handler_test.go index 373a8cc399..fa9bc58c9f 100644 --- a/x/ccv/provider/proposal_handler_test.go +++ b/x/ccv/provider/proposal_handler_test.go @@ -8,6 +8,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" + "cosmossdk.io/math" evidencetypes "cosmossdk.io/x/evidence/types" sdk "github.com/cosmos/cosmos-sdk/types" distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" @@ -93,7 +94,7 @@ func TestProviderProposalHandler(t *testing.T) { Title: "title", Description: "desc", Recipient: "", - Amount: sdk.NewCoins(sdk.NewCoin("communityfunds", sdk.NewInt(10))), + Amount: sdk.NewCoins(sdk.NewCoin("communityfunds", math.NewInt(10))), }, }, } diff --git a/x/ccv/provider/types/genesis_test.go b/x/ccv/provider/types/genesis_test.go index e4aa1f43f0..ed02fff2cc 100644 --- a/x/ccv/provider/types/genesis_test.go +++ b/x/ccv/provider/types/genesis_test.go @@ -4,6 +4,7 @@ import ( "testing" "time" + "cosmossdk.io/math" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types" ibctmtypes "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" @@ -81,7 +82,7 @@ func TestValidateGenesisState(t *testing.T) { nil, types.NewParams(ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0, time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}), - types.DefaultTrustingPeriodFraction, time.Hour, time.Hour, 30*time.Minute, time.Hour, "0.1", 400, sdk.Coin{Denom: "stake", Amount: sdk.NewInt(10000000)}), + types.DefaultTrustingPeriodFraction, time.Hour, time.Hour, 30*time.Minute, time.Hour, "0.1", 400, sdk.Coin{Denom: "stake", Amount: math.NewInt(10000000)}), nil, nil, nil, @@ -102,7 +103,7 @@ func TestValidateGenesisState(t *testing.T) { nil, types.NewParams(ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0, time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}), - types.DefaultTrustingPeriodFraction, time.Hour, time.Hour, 30*time.Minute, time.Hour, "0.1", 400, sdk.Coin{Denom: "stake", Amount: sdk.NewInt(10000000)}), + types.DefaultTrustingPeriodFraction, time.Hour, time.Hour, 30*time.Minute, time.Hour, "0.1", 400, sdk.Coin{Denom: "stake", Amount: math.NewInt(10000000)}), nil, nil, nil, @@ -123,7 +124,7 @@ func TestValidateGenesisState(t *testing.T) { nil, types.NewParams(ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0, time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}), - types.DefaultTrustingPeriodFraction, time.Hour, time.Hour, 30*time.Minute, time.Hour, "0.1", 400, sdk.Coin{Denom: "stake", Amount: sdk.NewInt(10000000)}), + types.DefaultTrustingPeriodFraction, time.Hour, time.Hour, 30*time.Minute, time.Hour, "0.1", 400, sdk.Coin{Denom: "stake", Amount: math.NewInt(10000000)}), nil, nil, nil, @@ -144,7 +145,7 @@ func TestValidateGenesisState(t *testing.T) { nil, types.NewParams(ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0, time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}), - types.DefaultTrustingPeriodFraction, time.Hour, time.Hour, 30*time.Minute, time.Hour, "0.1", 400, sdk.Coin{Denom: "stake", Amount: sdk.NewInt(10000000)}), + types.DefaultTrustingPeriodFraction, time.Hour, time.Hour, 30*time.Minute, time.Hour, "0.1", 400, sdk.Coin{Denom: "stake", Amount: math.NewInt(10000000)}), nil, nil, nil, @@ -171,7 +172,7 @@ func TestValidateGenesisState(t *testing.T) { types.DefaultVscTimeoutPeriod, types.DefaultSlashMeterReplenishPeriod, types.DefaultSlashMeterReplenishFraction, - types.DefaultMaxThrottledPackets, sdk.Coin{Denom: "stake", Amount: sdk.NewInt(10000000)}), + types.DefaultMaxThrottledPackets, sdk.Coin{Denom: "stake", Amount: math.NewInt(10000000)}), nil, nil, nil, @@ -198,7 +199,7 @@ func TestValidateGenesisState(t *testing.T) { types.DefaultVscTimeoutPeriod, types.DefaultSlashMeterReplenishPeriod, types.DefaultSlashMeterReplenishFraction, - types.DefaultMaxThrottledPackets, sdk.Coin{Denom: "stake", Amount: sdk.NewInt(10000000)}), + types.DefaultMaxThrottledPackets, sdk.Coin{Denom: "stake", Amount: math.NewInt(10000000)}), nil, nil, nil, @@ -225,7 +226,7 @@ func TestValidateGenesisState(t *testing.T) { types.DefaultVscTimeoutPeriod, types.DefaultSlashMeterReplenishPeriod, types.DefaultSlashMeterReplenishFraction, - types.DefaultMaxThrottledPackets, sdk.Coin{Denom: "stake", Amount: sdk.NewInt(1000000)}), + types.DefaultMaxThrottledPackets, sdk.Coin{Denom: "stake", Amount: math.NewInt(1000000)}), nil, nil, nil, @@ -252,7 +253,7 @@ func TestValidateGenesisState(t *testing.T) { types.DefaultVscTimeoutPeriod, types.DefaultSlashMeterReplenishPeriod, types.DefaultSlashMeterReplenishFraction, - types.DefaultMaxThrottledPackets, sdk.Coin{Denom: "stake", Amount: sdk.NewInt(10000000)}), + types.DefaultMaxThrottledPackets, sdk.Coin{Denom: "stake", Amount: math.NewInt(10000000)}), nil, nil, nil, @@ -279,7 +280,7 @@ func TestValidateGenesisState(t *testing.T) { 0, // 0 vsc timeout here types.DefaultSlashMeterReplenishPeriod, types.DefaultSlashMeterReplenishFraction, - types.DefaultMaxThrottledPackets, sdk.Coin{Denom: "stake", Amount: sdk.NewInt(10000000)}), + types.DefaultMaxThrottledPackets, sdk.Coin{Denom: "stake", Amount: math.NewInt(10000000)}), nil, nil, nil, @@ -306,7 +307,7 @@ func TestValidateGenesisState(t *testing.T) { types.DefaultVscTimeoutPeriod, 0, // 0 slash meter replenish period here types.DefaultSlashMeterReplenishFraction, - types.DefaultMaxThrottledPackets, sdk.Coin{Denom: "stake", Amount: sdk.NewInt(10000000)}), + types.DefaultMaxThrottledPackets, sdk.Coin{Denom: "stake", Amount: math.NewInt(10000000)}), nil, nil, nil, @@ -333,7 +334,7 @@ func TestValidateGenesisState(t *testing.T) { types.DefaultVscTimeoutPeriod, types.DefaultSlashMeterReplenishPeriod, "1.15", - types.DefaultMaxThrottledPackets, sdk.Coin{Denom: "stake", Amount: sdk.NewInt(10000000)}), + types.DefaultMaxThrottledPackets, sdk.Coin{Denom: "stake", Amount: math.NewInt(10000000)}), nil, nil, nil, @@ -360,7 +361,7 @@ func TestValidateGenesisState(t *testing.T) { types.DefaultVscTimeoutPeriod, types.DefaultSlashMeterReplenishPeriod, "1.15", - -1, sdk.Coin{Denom: "stake", Amount: sdk.NewInt(10000000)}), + -1, sdk.Coin{Denom: "stake", Amount: math.NewInt(10000000)}), nil, nil, nil, @@ -712,7 +713,7 @@ func TestValidateGenesisState(t *testing.T) { nil, types.NewParams(ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0, time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}), - types.DefaultTrustingPeriodFraction, time.Hour, time.Hour, 30*time.Minute, time.Hour, "0.1", 400, sdk.Coin{Denom: "st", Amount: sdk.NewInt(10000000)}), + types.DefaultTrustingPeriodFraction, time.Hour, time.Hour, 30*time.Minute, time.Hour, "0.1", 400, sdk.Coin{Denom: "st", Amount: math.NewInt(10000000)}), nil, nil, nil, @@ -733,7 +734,7 @@ func TestValidateGenesisState(t *testing.T) { nil, types.NewParams(ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0, time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}), - types.DefaultTrustingPeriodFraction, time.Hour, time.Hour, 30*time.Minute, time.Hour, "0.1", 400, sdk.Coin{Denom: "stake", Amount: sdk.NewInt(-1000000)}), + types.DefaultTrustingPeriodFraction, time.Hour, time.Hour, 30*time.Minute, time.Hour, "0.1", 400, sdk.Coin{Denom: "stake", Amount: math.NewInt(-1000000)}), nil, nil, nil, diff --git a/x/ccv/provider/types/params.go b/x/ccv/provider/types/params.go index 0bdd9c7c26..9a4cbdb149 100644 --- a/x/ccv/provider/types/params.go +++ b/x/ccv/provider/types/params.go @@ -4,6 +4,7 @@ import ( "fmt" "time" + "cosmossdk.io/math" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types" ibctmtypes "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" @@ -110,7 +111,7 @@ func DefaultParams() Params { // Following the pattern from cosmos-sdk/staking/types/params.go sdk.Coin{ Denom: sdk.DefaultBondDenom, - Amount: sdk.NewInt(10000000), + Amount: math.NewInt(10000000), }, ) } diff --git a/x/ccv/provider/types/params_test.go b/x/ccv/provider/types/params_test.go index 4721f118ea..81b769072e 100644 --- a/x/ccv/provider/types/params_test.go +++ b/x/ccv/provider/types/params_test.go @@ -4,6 +4,7 @@ import ( "testing" "time" + "cosmossdk.io/math" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types" ibctmtypes "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" @@ -24,42 +25,42 @@ func TestValidateParams(t *testing.T) { {"custom valid params", types.NewParams( ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0, time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}), - "0.33", time.Hour, time.Hour, time.Hour, 30*time.Minute, "0.1", 100, sdk.Coin{Denom: "stake", Amount: sdk.NewInt(10000000)}), true}, + "0.33", time.Hour, time.Hour, time.Hour, 30*time.Minute, "0.1", 100, sdk.Coin{Denom: "stake", Amount: math.NewInt(10000000)}), true}, {"custom invalid params", types.NewParams( ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0, 0, clienttypes.Height{}, nil, []string{"ibc", "upgradedIBCState"}), - "0.33", time.Hour, time.Hour, time.Hour, 30*time.Minute, "0.1", 100, sdk.Coin{Denom: "stake", Amount: sdk.NewInt(10000000)}), false}, + "0.33", time.Hour, time.Hour, time.Hour, 30*time.Minute, "0.1", 100, sdk.Coin{Denom: "stake", Amount: math.NewInt(10000000)}), false}, {"blank client", types.NewParams(&ibctmtypes.ClientState{}, - "0.33", time.Hour, time.Hour, time.Hour, 30*time.Minute, "0.1", 100, sdk.Coin{Denom: "stake", Amount: sdk.NewInt(10000000)}), false}, - {"nil client", types.NewParams(nil, "0.33", time.Hour, time.Hour, time.Hour, 30*time.Minute, "0.1", 100, sdk.Coin{Denom: "stake", Amount: sdk.NewInt(10000000)}), false}, + "0.33", time.Hour, time.Hour, time.Hour, 30*time.Minute, "0.1", 100, sdk.Coin{Denom: "stake", Amount: math.NewInt(10000000)}), false}, + {"nil client", types.NewParams(nil, "0.33", time.Hour, time.Hour, time.Hour, 30*time.Minute, "0.1", 100, sdk.Coin{Denom: "stake", Amount: math.NewInt(10000000)}), false}, // Check if "0.00" is valid or if a zero dec TrustFraction needs to return an error {"0 trusting period fraction", types.NewParams(ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0, time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}), - "0.00", time.Hour, time.Hour, time.Hour, 30*time.Minute, "0.1", 100, sdk.Coin{Denom: "stake", Amount: sdk.NewInt(10000000)}), true}, + "0.00", time.Hour, time.Hour, time.Hour, 30*time.Minute, "0.1", 100, sdk.Coin{Denom: "stake", Amount: math.NewInt(10000000)}), true}, {"0 ccv timeout period", types.NewParams(ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0, time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}), - "0.33", 0, time.Hour, time.Hour, 30*time.Minute, "0.1", 100, sdk.Coin{Denom: "stake", Amount: sdk.NewInt(10000000)}), false}, + "0.33", 0, time.Hour, time.Hour, 30*time.Minute, "0.1", 100, sdk.Coin{Denom: "stake", Amount: math.NewInt(10000000)}), false}, {"0 init timeout period", types.NewParams(ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0, time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}), - "0.33", time.Hour, 0, time.Hour, 30*time.Minute, "0.1", 100, sdk.Coin{Denom: "stake", Amount: sdk.NewInt(10000000)}), false}, + "0.33", time.Hour, 0, time.Hour, 30*time.Minute, "0.1", 100, sdk.Coin{Denom: "stake", Amount: math.NewInt(10000000)}), false}, {"0 vsc timeout period", types.NewParams(ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0, time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}), - "0.33", time.Hour, time.Hour, 0, 30*time.Minute, "0.1", 100, sdk.Coin{Denom: "stake", Amount: sdk.NewInt(10000000)}), false}, + "0.33", time.Hour, time.Hour, 0, 30*time.Minute, "0.1", 100, sdk.Coin{Denom: "stake", Amount: math.NewInt(10000000)}), false}, {"0 slash meter replenish period", types.NewParams(ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0, time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}), - "0.33", time.Hour, time.Hour, 24*time.Hour, 0, "0.1", 100, sdk.Coin{Denom: "stake", Amount: sdk.NewInt(10000000)}), false}, + "0.33", time.Hour, time.Hour, 24*time.Hour, 0, "0.1", 100, sdk.Coin{Denom: "stake", Amount: math.NewInt(10000000)}), false}, {"slash meter replenish fraction over 1", types.NewParams(ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0, time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}), - "0.33", time.Hour, time.Hour, 24*time.Hour, time.Hour, "1.5", 100, sdk.Coin{Denom: "stake", Amount: sdk.NewInt(10000000)}), false}, + "0.33", time.Hour, time.Hour, 24*time.Hour, time.Hour, "1.5", 100, sdk.Coin{Denom: "stake", Amount: math.NewInt(10000000)}), false}, {"negative max pending slash packets", types.NewParams(ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0, time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}), - "0.33", time.Hour, time.Hour, 24*time.Hour, time.Hour, "0.1", -100, sdk.Coin{Denom: "stake", Amount: sdk.NewInt(10000000)}), false}, + "0.33", time.Hour, time.Hour, 24*time.Hour, time.Hour, "0.1", -100, sdk.Coin{Denom: "stake", Amount: math.NewInt(10000000)}), false}, {"invalid consumer reward denom registration fee denom", types.NewParams(ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0, time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}), - "0.33", time.Hour, time.Hour, 24*time.Hour, time.Hour, "0.1", -100, sdk.Coin{Denom: "st", Amount: sdk.NewInt(10000000)}), false}, + "0.33", time.Hour, time.Hour, 24*time.Hour, time.Hour, "0.1", -100, sdk.Coin{Denom: "st", Amount: math.NewInt(10000000)}), false}, {"invalid consumer reward denom registration fee amount", types.NewParams(ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0, time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}), - "0.33", time.Hour, time.Hour, 24*time.Hour, time.Hour, "0.1", -100, sdk.Coin{Denom: "stake", Amount: sdk.NewInt(-10000000)}), false}, + "0.33", time.Hour, time.Hour, 24*time.Hour, time.Hour, "0.1", -100, sdk.Coin{Denom: "stake", Amount: math.NewInt(-10000000)}), false}, } for _, tc := range testCases { diff --git a/x/ccv/provider/types/proposal.go b/x/ccv/provider/types/proposal.go index bd5f7f9a55..7e16dab871 100644 --- a/x/ccv/provider/types/proposal.go +++ b/x/ccv/provider/types/proposal.go @@ -9,6 +9,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" errorsmod "cosmossdk.io/errors" + "cosmossdk.io/math" evidencetypes "cosmossdk.io/x/evidence/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -277,12 +278,12 @@ func (crdp *ChangeRewardDenomsProposal) ValidateBasic() error { // Return error if any denom is "invalid" for _, denom := range crdp.DenomsToAdd { - if !sdk.NewCoin(denom, sdk.NewInt(1)).IsValid() { + if !sdk.NewCoin(denom, math.NewInt(1)).IsValid() { return fmt.Errorf("invalid change reward denoms proposal: %s is not a valid denom", denom) } } for _, denom := range crdp.DenomsToRemove { - if !sdk.NewCoin(denom, sdk.NewInt(1)).IsValid() { + if !sdk.NewCoin(denom, math.NewInt(1)).IsValid() { return fmt.Errorf("invalid change reward denoms proposal: %s is not a valid denom", denom) } } diff --git a/x/ccv/types/expected_keepers.go b/x/ccv/types/expected_keepers.go index d8ae5fc546..85998f8e0a 100644 --- a/x/ccv/types/expected_keepers.go +++ b/x/ccv/types/expected_keepers.go @@ -33,8 +33,8 @@ type StakingKeeper interface { GetLastValidatorPower(ctx sdk.Context, operator sdk.ValAddress) (power int64) // slash the validator and delegators of the validator, specifying offence height, offence power, and slash fraction Jail(sdk.Context, sdk.ConsAddress) // jail a validator - Slash(sdk.Context, sdk.ConsAddress, int64, int64, sdk.Dec) math.Int - SlashWithInfractionReason(sdk.Context, sdk.ConsAddress, int64, int64, sdk.Dec, stakingtypes.Infraction) math.Int + Slash(sdk.Context, sdk.ConsAddress, int64, int64, math.LegacyDec) math.Int + SlashWithInfractionReason(sdk.Context, sdk.ConsAddress, int64, int64, math.LegacyDec, stakingtypes.Infraction) math.Int Unjail(ctx sdk.Context, addr sdk.ConsAddress) GetValidator(ctx sdk.Context, addr sdk.ValAddress) (validator stakingtypes.Validator, found bool) IterateLastValidatorPowers(ctx sdk.Context, cb func(addr sdk.ValAddress, power int64) (stop bool)) @@ -61,8 +61,8 @@ type SlashingKeeper interface { JailUntil(sdk.Context, sdk.ConsAddress, time.Time) // called from provider keeper only GetValidatorSigningInfo(ctx sdk.Context, address sdk.ConsAddress) (info slashingtypes.ValidatorSigningInfo, found bool) DowntimeJailDuration(sdk.Context) time.Duration - SlashFractionDowntime(sdk.Context) sdk.Dec - SlashFractionDoubleSign(ctx sdk.Context) (res sdk.Dec) + SlashFractionDowntime(sdk.Context) math.LegacyDec + SlashFractionDoubleSign(ctx sdk.Context) (res math.LegacyDec) Tombstone(sdk.Context, sdk.ConsAddress) IsTombstoned(sdk.Context, sdk.ConsAddress) bool } diff --git a/x/ccv/types/params.go b/x/ccv/types/params.go index 6a903c0d8f..d44ec68c80 100644 --- a/x/ccv/types/params.go +++ b/x/ccv/types/params.go @@ -4,6 +4,7 @@ import ( fmt "fmt" time "time" + "cosmossdk.io/math" sdktypes "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -188,14 +189,14 @@ func ValidateSoftOptOutThreshold(i interface{}) error { if !ok { return fmt.Errorf("invalid parameter type: %T", i) } - dec, err := sdktypes.NewDecFromStr(str) + dec, err := math.LegacyNewDecFromStr(str) if err != nil { return err } if dec.IsNegative() { return fmt.Errorf("soft opt out threshold cannot be negative, got %s", str) } - if !dec.Sub(sdktypes.MustNewDecFromStr("0.2")).IsNegative() { + if !dec.Sub(math.LegacyMustNewDecFromStr("0.2")).IsNegative() { return fmt.Errorf("soft opt out threshold cannot be greater than 0.2, got %s", str) } return nil @@ -211,7 +212,7 @@ func ValidateDenoms(i interface{}) error { for _, denom := range v { coin := sdktypes.Coin{ Denom: denom, - Amount: sdktypes.NewInt(0), + Amount: math.NewInt(0), } if err := coin.Validate(); err != nil { diff --git a/x/ccv/types/shared_params.go b/x/ccv/types/shared_params.go index 104097b762..fa2e28c81c 100644 --- a/x/ccv/types/shared_params.go +++ b/x/ccv/types/shared_params.go @@ -4,6 +4,7 @@ import ( fmt "fmt" "time" + "cosmossdk.io/math" ibchost "github.com/cosmos/ibc-go/v8/modules/core/24-host" sdktypes "github.com/cosmos/cosmos-sdk/types" @@ -90,21 +91,21 @@ func ValidateStringFraction(i interface{}) error { if !ok { return fmt.Errorf("invalid parameter type: %T", i) } - dec, err := sdktypes.NewDecFromStr(str) + dec, err := math.LegacyNewDecFromStr(str) if err != nil { return err } if dec.IsNegative() { return fmt.Errorf("param cannot be negative, got %s", str) } - if dec.Sub(sdktypes.NewDec(1)).IsPositive() { + if dec.Sub(math.LegacyNewDec(1)).IsPositive() { return fmt.Errorf("param cannot be greater than 1, got %s", str) } return nil } func CalculateTrustPeriod(unbondingPeriod time.Duration, defaultTrustPeriodFraction string) (time.Duration, error) { - trustDec, err := sdktypes.NewDecFromStr(defaultTrustPeriodFraction) + trustDec, err := math.LegacyNewDecFromStr(defaultTrustPeriodFraction) if err != nil { return time.Duration(0), err }