chore: math lib update and type fixes (#12791)
## Description Upgrades the math library in the repo root and find/replaces many usages of sdk.Dec, sdk.ZeroDec, sdk.OneDec, sdk.NewDec with their legacy-ified-math-lib replacements. Note for review: I assume that I did not find 100% of usages --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
This commit is contained in:
@@ -4,9 +4,9 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/kv"
|
||||
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
|
||||
"github.com/cosmos/cosmos-sdk/x/mint"
|
||||
@@ -19,7 +19,7 @@ func TestDecodeStore(t *testing.T) {
|
||||
|
||||
dec := simulation.NewDecodeStore(encCfg.Codec)
|
||||
|
||||
minter := types.NewMinter(sdk.OneDec(), sdk.NewDec(15))
|
||||
minter := types.NewMinter(math.LegacyOneDec(), math.LegacyNewDec(15))
|
||||
|
||||
kvPairs := kv.Pairs{
|
||||
Pairs: []kv.Pair{
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/module"
|
||||
"github.com/cosmos/cosmos-sdk/x/mint/types"
|
||||
@@ -22,27 +23,27 @@ const (
|
||||
)
|
||||
|
||||
// GenInflation randomized Inflation
|
||||
func GenInflation(r *rand.Rand) sdk.Dec {
|
||||
func GenInflation(r *rand.Rand) math.LegacyDec {
|
||||
return sdk.NewDecWithPrec(int64(r.Intn(99)), 2)
|
||||
}
|
||||
|
||||
// GenInflationRateChange randomized InflationRateChange
|
||||
func GenInflationRateChange(r *rand.Rand) sdk.Dec {
|
||||
func GenInflationRateChange(r *rand.Rand) math.LegacyDec {
|
||||
return sdk.NewDecWithPrec(int64(r.Intn(99)), 2)
|
||||
}
|
||||
|
||||
// GenInflationMax randomized InflationMax
|
||||
func GenInflationMax(r *rand.Rand) sdk.Dec {
|
||||
func GenInflationMax(r *rand.Rand) math.LegacyDec {
|
||||
return sdk.NewDecWithPrec(20, 2)
|
||||
}
|
||||
|
||||
// GenInflationMin randomized InflationMin
|
||||
func GenInflationMin(r *rand.Rand) sdk.Dec {
|
||||
func GenInflationMin(r *rand.Rand) math.LegacyDec {
|
||||
return sdk.NewDecWithPrec(7, 2)
|
||||
}
|
||||
|
||||
// GenGoalBonded randomized GoalBonded
|
||||
func GenGoalBonded(r *rand.Rand) sdk.Dec {
|
||||
func GenGoalBonded(r *rand.Rand) math.LegacyDec {
|
||||
return sdk.NewDecWithPrec(67, 2)
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ func TestRandomizedGenState(t *testing.T) {
|
||||
require.Equal(t, "stake", mintGenesis.Params.MintDenom)
|
||||
require.Equal(t, "0stake", mintGenesis.Minter.BlockProvision(mintGenesis.Params).String())
|
||||
require.Equal(t, "0.170000000000000000", mintGenesis.Minter.NextAnnualProvisions(mintGenesis.Params, math.OneInt()).String())
|
||||
require.Equal(t, "0.169999926644441493", mintGenesis.Minter.NextInflationRate(mintGenesis.Params, sdk.OneDec()).String())
|
||||
require.Equal(t, "0.169999926644441493", mintGenesis.Minter.NextInflationRate(mintGenesis.Params, math.LegacyOneDec()).String())
|
||||
require.Equal(t, "0.170000000000000000", mintGenesis.Minter.Inflation.String())
|
||||
require.Equal(t, "0.000000000000000000", mintGenesis.Minter.AnnualProvisions.String())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user