refactor(genutil,group,mint): remove aliases from types/math.go (#15824)

## Description

Closes part of: https://github.com/cosmos/cosmos-sdk/issues/14405



---

### 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/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:
samricotta 2023-04-13 14:34:47 +02:00 committed by GitHub
parent 42f03c369f
commit e2c91fc1d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 98 additions and 90 deletions

View File

@ -8,6 +8,7 @@ import (
"path/filepath"
"testing"
sdkmath "cosmossdk.io/math"
abci "github.com/cometbft/cometbft/abci/types"
rpcclientmock "github.com/cometbft/cometbft/rpc/client/mock"
"github.com/stretchr/testify/suite"
@ -63,7 +64,7 @@ func (s *CLITestSuite) SetupSuite() {
}
func (s *CLITestSuite) TestGenTxCmd() {
amount := sdk.NewCoin("stake", sdk.NewInt(12))
amount := sdk.NewCoin("stake", sdkmath.NewInt(12))
tests := []struct {
name string

View File

@ -40,8 +40,7 @@ func TestValidateGenesisMultipleMessages(t *testing.T) {
desc := stakingtypes.NewDescription("testname", "", "", "", "")
comm := stakingtypes.CommissionRates{}
msg1, err := stakingtypes.NewMsgCreateValidator(sdk.ValAddress(pk1.Address()), pk1,
sdk.NewInt64Coin(sdk.DefaultBondDenom, 50), desc, comm, math.OneInt())
msg1, err := stakingtypes.NewMsgCreateValidator(sdk.ValAddress(pk1.Address()), pk1, sdk.NewInt64Coin(sdk.DefaultBondDenom, 50), desc, comm, math.OneInt())
require.NoError(t, err)
msg2, err := stakingtypes.NewMsgCreateValidator(sdk.ValAddress(pk2.Address()), pk2,

View File

@ -10,6 +10,7 @@ import (
"strings"
"testing"
sdkmath "cosmossdk.io/math"
abci "github.com/cometbft/cometbft/abci/types"
rpcclientmock "github.com/cometbft/cometbft/rpc/client/mock"
"github.com/cosmos/gogoproto/proto"
@ -63,7 +64,7 @@ func (s *CLITestSuite) SetupSuite() {
s.commonFlags = []string{
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(10))).String()),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(10))).String()),
}
accounts := testutil.CreateKeyringAccounts(s.T(), s.kr, 1)
@ -91,9 +92,9 @@ func (s *CLITestSuite) SetupSuite() {
s.clientCtx,
val.Address,
account,
sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(2000))), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(2000))), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(10))).String()),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(10))).String()),
)
s.Require().NoError(err)

View File

@ -5,6 +5,8 @@ import (
"testing"
"time"
sdkmath "cosmossdk.io/math"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
cmttime "github.com/cometbft/cometbft/types/time"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
@ -53,7 +55,7 @@ func (s *IntegrationTestSuite) SetupTest() {
ctx = ctx.WithBlockHeader(cmtproto.Header{Time: cmttime.Now()})
s.ctx = ctx
s.addrs = simtestutil.AddTestAddrsIncremental(s.bankKeeper, s.stakingKeeper, ctx, 4, sdk.NewInt(30000000))
s.addrs = simtestutil.AddTestAddrsIncremental(s.bankKeeper, s.stakingKeeper, ctx, 4, sdkmath.NewInt(30000000))
}
func (s *IntegrationTestSuite) TestEndBlockerPruning() {

View File

@ -83,7 +83,7 @@ inflation calculation logic is needed, this can be achieved by defining and
passing a function that matches `InflationCalculationFn`'s signature.
```go
type InflationCalculationFn func(ctx sdk.Context, minter Minter, params Params, bondedRatio sdk.Dec) sdk.Dec
type InflationCalculationFn func(ctx sdk.Context, minter Minter, params Params, bondedRatio math.LegacyDec) math.LegacyDec
```
#### NextInflationRate
@ -95,7 +95,7 @@ possible is defined to be 13% per year, however the annual inflation is capped
as between 7% and 20%.
```go
NextInflationRate(params Params, bondedRatio sdk.Dec) (inflation sdk.Dec) {
NextInflationRate(params Params, bondedRatio math.LegacyDec) (inflation math.LegacyDec) {
inflationRateChangePerYear = (1 - bondedRatio/params.GoalBonded) * params.InflationRateChange
inflationRateChange = inflationRateChangePerYear/blocksPerYr
@ -118,7 +118,7 @@ Calculate the annual provisions based on current total supply and inflation
rate. This parameter is calculated once per block.
```go
NextAnnualProvisions(params Params, totalSupply sdk.Dec) (provisions sdk.Dec) {
NextAnnualProvisions(params Params, totalSupply math.LegacyDec) (provisions math.LegacyDec) {
return Inflation * totalSupply
```

View File

@ -59,13 +59,13 @@ func (s *GenesisTestSuite) SetupTest() {
func (s *GenesisTestSuite) TestImportExportGenesis() {
genesisState := types.DefaultGenesisState()
genesisState.Minter = types.NewMinter(sdk.NewDecWithPrec(20, 2), math.LegacyNewDec(1))
genesisState.Minter = types.NewMinter(math.LegacyNewDecWithPrec(20, 2), math.LegacyNewDec(1))
genesisState.Params = types.NewParams(
"testDenom",
sdk.NewDecWithPrec(15, 2),
sdk.NewDecWithPrec(22, 2),
sdk.NewDecWithPrec(9, 2),
sdk.NewDecWithPrec(69, 2),
math.LegacyNewDecWithPrec(15, 2),
math.LegacyNewDecWithPrec(22, 2),
math.LegacyNewDecWithPrec(9, 2),
math.LegacyNewDecWithPrec(69, 2),
uint64(60*60*8766/5),
)

View File

@ -6,6 +6,7 @@ import (
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/suite"
sdkmath "cosmossdk.io/math"
storetypes "cosmossdk.io/store/types"
"github.com/cosmos/cosmos-sdk/testutil"
@ -79,10 +80,10 @@ func (s *IntegrationTestSuite) TestParams() {
name: "set invalid params (⚠️ not validated in keeper)",
input: types.Params{
MintDenom: sdk.DefaultBondDenom,
InflationRateChange: sdk.NewDecWithPrec(-13, 2),
InflationMax: sdk.NewDecWithPrec(20, 2),
InflationMin: sdk.NewDecWithPrec(7, 2),
GoalBonded: sdk.NewDecWithPrec(67, 2),
InflationRateChange: sdkmath.LegacyNewDecWithPrec(-13, 2),
InflationMax: sdkmath.LegacyNewDecWithPrec(20, 2),
InflationMin: sdkmath.LegacyNewDecWithPrec(7, 2),
GoalBonded: sdkmath.LegacyNewDecWithPrec(67, 2),
BlocksPerYear: uint64(60 * 60 * 8766 / 5),
},
expectErr: false,
@ -91,10 +92,10 @@ func (s *IntegrationTestSuite) TestParams() {
name: "set full valid params",
input: types.Params{
MintDenom: sdk.DefaultBondDenom,
InflationRateChange: sdk.NewDecWithPrec(8, 2),
InflationMax: sdk.NewDecWithPrec(20, 2),
InflationMin: sdk.NewDecWithPrec(2, 2),
GoalBonded: sdk.NewDecWithPrec(37, 2),
InflationRateChange: sdkmath.LegacyNewDecWithPrec(8, 2),
InflationMax: sdkmath.LegacyNewDecWithPrec(20, 2),
InflationMin: sdkmath.LegacyNewDecWithPrec(2, 2),
GoalBonded: sdkmath.LegacyNewDecWithPrec(37, 2),
BlocksPerYear: uint64(60 * 60 * 8766 / 5),
},
expectErr: false,
@ -125,16 +126,16 @@ func (s *IntegrationTestSuite) TestAliasFunctions() {
s.stakingKeeper.EXPECT().StakingTokenSupply(s.ctx).Return(stakingTokenSupply)
s.Require().Equal(s.mintKeeper.StakingTokenSupply(s.ctx), stakingTokenSupply)
bondedRatio := sdk.NewDecWithPrec(15, 2)
bondedRatio := sdkmath.LegacyNewDecWithPrec(15, 2)
s.stakingKeeper.EXPECT().BondedRatio(s.ctx).Return(bondedRatio)
s.Require().Equal(s.mintKeeper.BondedRatio(s.ctx), bondedRatio)
coins := sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(1000000)))
coins := sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(1000000)))
s.bankKeeper.EXPECT().MintCoins(s.ctx, types.ModuleName, coins).Return(nil)
s.Require().Equal(s.mintKeeper.MintCoins(s.ctx, sdk.NewCoins()), nil)
s.Require().Nil(s.mintKeeper.MintCoins(s.ctx, coins))
fees := sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(1000)))
fees := sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(1000)))
s.bankKeeper.EXPECT().SendCoinsFromModuleToModule(s.ctx, types.ModuleName, authtypes.FeeCollectorName, fees).Return(nil)
s.Require().Nil(s.mintKeeper.AddCollectedFees(s.ctx, fees))
}

View File

@ -1,6 +1,8 @@
package keeper_test
import (
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/mint/types"
)
@ -31,10 +33,10 @@ func (s *IntegrationTestSuite) TestUpdateParams() {
Authority: s.mintKeeper.GetAuthority(),
Params: types.Params{
MintDenom: sdk.DefaultBondDenom,
InflationRateChange: sdk.NewDecWithPrec(-13, 2),
InflationMax: sdk.NewDecWithPrec(20, 2),
InflationMin: sdk.NewDecWithPrec(7, 2),
GoalBonded: sdk.NewDecWithPrec(67, 2),
InflationRateChange: sdkmath.LegacyNewDecWithPrec(-13, 2),
InflationMax: sdkmath.LegacyNewDecWithPrec(20, 2),
InflationMin: sdkmath.LegacyNewDecWithPrec(7, 2),
GoalBonded: sdkmath.LegacyNewDecWithPrec(67, 2),
BlocksPerYear: uint64(60 * 60 * 8766 / 5),
},
},
@ -46,10 +48,10 @@ func (s *IntegrationTestSuite) TestUpdateParams() {
Authority: s.mintKeeper.GetAuthority(),
Params: types.Params{
MintDenom: sdk.DefaultBondDenom,
InflationRateChange: sdk.NewDecWithPrec(8, 2),
InflationMax: sdk.NewDecWithPrec(20, 2),
InflationMin: sdk.NewDecWithPrec(2, 2),
GoalBonded: sdk.NewDecWithPrec(37, 2),
InflationRateChange: sdkmath.LegacyNewDecWithPrec(8, 2),
InflationMax: sdkmath.LegacyNewDecWithPrec(20, 2),
InflationMin: sdkmath.LegacyNewDecWithPrec(2, 2),
GoalBonded: sdkmath.LegacyNewDecWithPrec(37, 2),
BlocksPerYear: uint64(60 * 60 * 8766 / 5),
},
},

View File

@ -6,7 +6,6 @@ import (
"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,58 +21,58 @@ const (
// GenInflation randomized Inflation
func GenInflation(r *rand.Rand) math.LegacyDec {
return sdk.NewDecWithPrec(int64(r.Intn(99)), 2)
return math.LegacyNewDecWithPrec(int64(r.Intn(99)), 2)
}
// GenInflationRateChange randomized InflationRateChange
func GenInflationRateChange(r *rand.Rand) math.LegacyDec {
return sdk.NewDecWithPrec(int64(r.Intn(99)), 2)
return math.LegacyNewDecWithPrec(int64(r.Intn(99)), 2)
}
// GenInflationMax randomized InflationMax
func GenInflationMax(r *rand.Rand) math.LegacyDec {
return sdk.NewDecWithPrec(20, 2)
return math.LegacyNewDecWithPrec(20, 2)
}
// GenInflationMin randomized InflationMin
func GenInflationMin(r *rand.Rand) math.LegacyDec {
return sdk.NewDecWithPrec(7, 2)
return math.LegacyNewDecWithPrec(7, 2)
}
// GenGoalBonded randomized GoalBonded
func GenGoalBonded(r *rand.Rand) math.LegacyDec {
return sdk.NewDecWithPrec(67, 2)
return math.LegacyNewDecWithPrec(67, 2)
}
// RandomizedGenState generates a random GenesisState for mint
func RandomizedGenState(simState *module.SimulationState) {
// minter
var inflation sdk.Dec
var inflation math.LegacyDec
simState.AppParams.GetOrGenerate(
simState.Cdc, Inflation, &inflation, simState.Rand,
func(r *rand.Rand) { inflation = GenInflation(r) },
)
// params
var inflationRateChange sdk.Dec
var inflationRateChange math.LegacyDec
simState.AppParams.GetOrGenerate(
simState.Cdc, InflationRateChange, &inflationRateChange, simState.Rand,
func(r *rand.Rand) { inflationRateChange = GenInflationRateChange(r) },
)
var inflationMax sdk.Dec
var inflationMax math.LegacyDec
simState.AppParams.GetOrGenerate(
simState.Cdc, InflationMax, &inflationMax, simState.Rand,
func(r *rand.Rand) { inflationMax = GenInflationMax(r) },
)
var inflationMin sdk.Dec
var inflationMin math.LegacyDec
simState.AppParams.GetOrGenerate(
simState.Cdc, InflationMin, &inflationMin, simState.Rand,
func(r *rand.Rand) { inflationMin = GenInflationMin(r) },
)
var goalBonded sdk.Dec
var goalBonded math.LegacyDec
simState.AppParams.GetOrGenerate(
simState.Cdc, GoalBonded, &goalBonded, simState.Rand,
func(r *rand.Rand) { goalBonded = GenGoalBonded(r) },

View File

@ -41,9 +41,9 @@ func TestRandomizedGenState(t *testing.T) {
var mintGenesis types.GenesisState
simState.Cdc.MustUnmarshalJSON(simState.GenState[types.ModuleName], &mintGenesis)
dec1, _ := sdk.NewDecFromStr("0.670000000000000000")
dec2, _ := sdk.NewDecFromStr("0.200000000000000000")
dec3, _ := sdk.NewDecFromStr("0.070000000000000000")
dec1, _ := math.LegacyNewDecFromStr("0.670000000000000000")
dec2, _ := math.LegacyNewDecFromStr("0.200000000000000000")
dec3, _ := math.LegacyNewDecFromStr("0.070000000000000000")
require.Equal(t, uint64(6311520), mintGenesis.Params.BlocksPerYear)
require.Equal(t, dec1, mintGenesis.Params.GoalBonded)

View File

@ -3,6 +3,8 @@ package simulation
import (
"math/rand"
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
@ -35,10 +37,10 @@ func SimulateMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account)
params := types.DefaultParams()
params.BlocksPerYear = uint64(simtypes.RandIntBetween(r, 1, 1000000))
params.GoalBonded = sdk.NewDecWithPrec(int64(simtypes.RandIntBetween(r, 1, 100)), 2)
params.InflationMin = sdk.NewDecWithPrec(int64(simtypes.RandIntBetween(r, 1, 50)), 2)
params.InflationMax = sdk.NewDecWithPrec(int64(simtypes.RandIntBetween(r, 50, 100)), 2)
params.InflationRateChange = sdk.NewDecWithPrec(int64(simtypes.RandIntBetween(r, 1, 100)), 2)
params.GoalBonded = sdkmath.LegacyNewDecWithPrec(int64(simtypes.RandIntBetween(r, 1, 100)), 2)
params.InflationMin = sdkmath.LegacyNewDecWithPrec(int64(simtypes.RandIntBetween(r, 1, 50)), 2)
params.InflationMax = sdkmath.LegacyNewDecWithPrec(int64(simtypes.RandIntBetween(r, 50, 100)), 2)
params.InflationRateChange = sdkmath.LegacyNewDecWithPrec(int64(simtypes.RandIntBetween(r, 1, 100)), 2)
params.MintDenom = simtypes.RandStringOfLength(r, 10)
return &types.MsgUpdateParams{

View File

@ -4,6 +4,7 @@ import (
"math/rand"
"testing"
sdkmath "cosmossdk.io/math"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
"gotest.tools/v3/assert"
@ -38,9 +39,9 @@ func TestProposalMsgs(t *testing.T) {
assert.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateParams.Authority)
assert.Equal(t, uint64(122877), msgUpdateParams.Params.BlocksPerYear)
assert.DeepEqual(t, sdk.NewDecWithPrec(95, 2), msgUpdateParams.Params.GoalBonded)
assert.DeepEqual(t, sdk.NewDecWithPrec(94, 2), msgUpdateParams.Params.InflationMax)
assert.DeepEqual(t, sdk.NewDecWithPrec(23, 2), msgUpdateParams.Params.InflationMin)
assert.DeepEqual(t, sdk.NewDecWithPrec(89, 2), msgUpdateParams.Params.InflationRateChange)
assert.DeepEqual(t, sdkmath.LegacyNewDecWithPrec(95, 2), msgUpdateParams.Params.GoalBonded)
assert.DeepEqual(t, sdkmath.LegacyNewDecWithPrec(94, 2), msgUpdateParams.Params.InflationMax)
assert.DeepEqual(t, sdkmath.LegacyNewDecWithPrec(23, 2), msgUpdateParams.Params.InflationMin)
assert.DeepEqual(t, sdkmath.LegacyNewDecWithPrec(89, 2), msgUpdateParams.Params.InflationRateChange)
assert.Equal(t, "XhhuTSkuxK", msgUpdateParams.Params.MintDenom)
}

View File

@ -11,7 +11,7 @@ import (
// StakingKeeper defines the expected staking keeper
type StakingKeeper interface {
StakingTokenSupply(ctx sdk.Context) math.Int
BondedRatio(ctx sdk.Context) sdk.Dec
BondedRatio(ctx sdk.Context) math.LegacyDec
}
// AccountKeeper defines the contract required for account APIs.

View File

@ -10,10 +10,10 @@ import (
// bondedRatio and returns the newly calculated inflation rate.
// It can be used to specify a custom inflation calculation logic, instead of relying on the
// default logic provided by the sdk.
type InflationCalculationFn func(ctx sdk.Context, minter Minter, params Params, bondedRatio sdk.Dec) sdk.Dec
type InflationCalculationFn func(ctx sdk.Context, minter Minter, params Params, bondedRatio math.LegacyDec) math.LegacyDec
// DefaultInflationCalculationFn is the default function used to calculate inflation.
func DefaultInflationCalculationFn(_ sdk.Context, minter Minter, params Params, bondedRatio sdk.Dec) math.LegacyDec {
func DefaultInflationCalculationFn(_ sdk.Context, minter Minter, params Params, bondedRatio math.LegacyDec) math.LegacyDec {
return minter.NextInflationRate(params, bondedRatio)
}

View File

@ -10,7 +10,7 @@ import (
// NewMinter returns a new Minter object with the given inflation and annual
// provisions values.
func NewMinter(inflation, annualProvisions sdk.Dec) Minter {
func NewMinter(inflation, annualProvisions math.LegacyDec) Minter {
return Minter{
Inflation: inflation,
AnnualProvisions: annualProvisions,
@ -18,7 +18,7 @@ func NewMinter(inflation, annualProvisions sdk.Dec) Minter {
}
// InitialMinter returns an initial Minter object with a given inflation value.
func InitialMinter(inflation sdk.Dec) Minter {
func InitialMinter(inflation math.LegacyDec) Minter {
return NewMinter(
inflation,
math.LegacyNewDec(0),
@ -29,7 +29,7 @@ func InitialMinter(inflation sdk.Dec) Minter {
// which uses an inflation rate of 13%.
func DefaultInitialMinter() Minter {
return InitialMinter(
sdk.NewDecWithPrec(13, 2),
math.LegacyNewDecWithPrec(13, 2),
)
}
@ -43,7 +43,7 @@ func ValidateMinter(minter Minter) error {
}
// NextInflationRate returns the new inflation rate for the next block.
func (m Minter) NextInflationRate(params Params, bondedRatio sdk.Dec) math.LegacyDec {
func (m Minter) NextInflationRate(params Params, bondedRatio math.LegacyDec) math.LegacyDec {
// The target annual inflation rate is recalculated for each block. The inflation
// is also subject to a rate change (positive or negative) depending on the
// distance from the desired ratio (67%). The maximum rate change possible is
@ -77,6 +77,6 @@ func (m Minter) NextAnnualProvisions(_ Params, totalSupply math.Int) math.Legacy
// BlockProvision returns the provisions for a block based on the annual
// provisions rate.
func (m Minter) BlockProvision(params Params) sdk.Coin {
provisionAmt := m.AnnualProvisions.QuoInt(sdk.NewInt(int64(params.BlocksPerYear)))
provisionAmt := m.AnnualProvisions.QuoInt(math.NewInt(int64(params.BlocksPerYear)))
return sdk.NewCoin(params.MintDenom, provisionAmt.TruncateInt())
}

View File

@ -19,34 +19,34 @@ func TestNextInflation(t *testing.T) {
// inflationRateChangePerYear = (1- BondedRatio/ GoalBonded) * MaxInflationRateChange
tests := []struct {
bondedRatio, setInflation, expChange sdk.Dec
bondedRatio, setInflation, expChange math.LegacyDec
}{
// with 0% bonded atom supply the inflation should increase by InflationRateChange
{math.LegacyZeroDec(), sdk.NewDecWithPrec(7, 2), params.InflationRateChange.Quo(blocksPerYr)},
{math.LegacyZeroDec(), math.LegacyNewDecWithPrec(7, 2), params.InflationRateChange.Quo(blocksPerYr)},
// 100% bonded, starting at 20% inflation and being reduced
// (1 - (1/0.67))*(0.13/8667)
{
math.LegacyOneDec(), sdk.NewDecWithPrec(20, 2),
math.LegacyOneDec(), math.LegacyNewDecWithPrec(20, 2),
math.LegacyOneDec().Sub(math.LegacyOneDec().Quo(params.GoalBonded)).Mul(params.InflationRateChange).Quo(blocksPerYr),
},
// 50% bonded, starting at 10% inflation and being increased
{
sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(10, 2),
math.LegacyOneDec().Sub(sdk.NewDecWithPrec(5, 1).Quo(params.GoalBonded)).Mul(params.InflationRateChange).Quo(blocksPerYr),
math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDecWithPrec(10, 2),
math.LegacyOneDec().Sub(math.LegacyNewDecWithPrec(5, 1).Quo(params.GoalBonded)).Mul(params.InflationRateChange).Quo(blocksPerYr),
},
// test 7% minimum stop (testing with 100% bonded)
{math.LegacyOneDec(), sdk.NewDecWithPrec(7, 2), math.LegacyZeroDec()},
{math.LegacyOneDec(), sdk.NewDecWithPrec(700000001, 10), sdk.NewDecWithPrec(-1, 10)},
{math.LegacyOneDec(), math.LegacyNewDecWithPrec(7, 2), math.LegacyZeroDec()},
{math.LegacyOneDec(), math.LegacyNewDecWithPrec(700000001, 10), math.LegacyNewDecWithPrec(-1, 10)},
// test 20% maximum stop (testing with 0% bonded)
{math.LegacyZeroDec(), sdk.NewDecWithPrec(20, 2), math.LegacyZeroDec()},
{math.LegacyZeroDec(), sdk.NewDecWithPrec(1999999999, 10), sdk.NewDecWithPrec(1, 10)},
{math.LegacyZeroDec(), math.LegacyNewDecWithPrec(20, 2), math.LegacyZeroDec()},
{math.LegacyZeroDec(), math.LegacyNewDecWithPrec(1999999999, 10), math.LegacyNewDecWithPrec(1, 10)},
// perfect balance shouldn't change inflation
{sdk.NewDecWithPrec(67, 2), sdk.NewDecWithPrec(15, 2), math.LegacyZeroDec()},
{math.LegacyNewDecWithPrec(67, 2), math.LegacyNewDecWithPrec(15, 2), math.LegacyZeroDec()},
}
for i, tc := range tests {
minter.Inflation = tc.setInflation
@ -60,7 +60,7 @@ func TestNextInflation(t *testing.T) {
}
func TestBlockProvision(t *testing.T) {
minter := InitialMinter(sdk.NewDecWithPrec(1, 1))
minter := InitialMinter(math.LegacyNewDecWithPrec(1, 1))
params := DefaultParams()
secondsPerYear := int64(60 * 60 * 8766)
@ -79,7 +79,7 @@ func TestBlockProvision(t *testing.T) {
provisions := minter.BlockProvision(params)
expProvisions := sdk.NewCoin(params.MintDenom,
sdk.NewInt(tc.expProvisions))
math.NewInt(tc.expProvisions))
require.True(t, expProvisions.IsEqual(provisions),
"test: %v\n\tExp: %v\n\tGot: %v\n",
@ -95,7 +95,7 @@ func TestBlockProvision(t *testing.T) {
// BenchmarkBlockProvision-4 3000000 429 ns/op
func BenchmarkBlockProvision(b *testing.B) {
b.ReportAllocs()
minter := InitialMinter(sdk.NewDecWithPrec(1, 1))
minter := InitialMinter(math.LegacyNewDecWithPrec(1, 1))
params := DefaultParams()
s1 := rand.NewSource(100)
@ -112,9 +112,9 @@ func BenchmarkBlockProvision(b *testing.B) {
// BenchmarkNextInflation-4 1000000 1828 ns/op
func BenchmarkNextInflation(b *testing.B) {
b.ReportAllocs()
minter := InitialMinter(sdk.NewDecWithPrec(1, 1))
minter := InitialMinter(math.LegacyNewDecWithPrec(1, 1))
params := DefaultParams()
bondedRatio := sdk.NewDecWithPrec(1, 1)
bondedRatio := math.LegacyNewDecWithPrec(1, 1)
// run the NextInflationRate function b.N times
for n := 0; n < b.N; n++ {
@ -126,9 +126,9 @@ func BenchmarkNextInflation(b *testing.B) {
// BenchmarkNextAnnualProvisions-4 5000000 251 ns/op
func BenchmarkNextAnnualProvisions(b *testing.B) {
b.ReportAllocs()
minter := InitialMinter(sdk.NewDecWithPrec(1, 1))
minter := InitialMinter(math.LegacyNewDecWithPrec(1, 1))
params := DefaultParams()
totalSupply := sdk.NewInt(100000000000000)
totalSupply := math.NewInt(100000000000000)
// run the NextAnnualProvisions function b.N times
for n := 0; n < b.N; n++ {

View File

@ -11,7 +11,7 @@ import (
)
// NewParams returns Params instance with the given values.
func NewParams(mintDenom string, inflationRateChange, inflationMax, inflationMin, goalBonded sdk.Dec, blocksPerYear uint64) Params {
func NewParams(mintDenom string, inflationRateChange, inflationMax, inflationMin, goalBonded math.LegacyDec, blocksPerYear uint64) Params {
return Params{
MintDenom: mintDenom,
InflationRateChange: inflationRateChange,
@ -26,10 +26,10 @@ func NewParams(mintDenom string, inflationRateChange, inflationMax, inflationMin
func DefaultParams() Params {
return Params{
MintDenom: sdk.DefaultBondDenom,
InflationRateChange: sdk.NewDecWithPrec(13, 2),
InflationMax: sdk.NewDecWithPrec(20, 2),
InflationMin: sdk.NewDecWithPrec(7, 2),
GoalBonded: sdk.NewDecWithPrec(67, 2),
InflationRateChange: math.LegacyNewDecWithPrec(13, 2),
InflationMax: math.LegacyNewDecWithPrec(20, 2),
InflationMin: math.LegacyNewDecWithPrec(7, 2),
GoalBonded: math.LegacyNewDecWithPrec(67, 2),
BlocksPerYear: uint64(60 * 60 * 8766 / 5), // assuming 5 second block times
}
}
@ -81,7 +81,7 @@ func validateMintDenom(i interface{}) error {
}
func validateInflationRateChange(i interface{}) error {
v, ok := i.(sdk.Dec)
v, ok := i.(math.LegacyDec)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
@ -100,7 +100,7 @@ func validateInflationRateChange(i interface{}) error {
}
func validateInflationMax(i interface{}) error {
v, ok := i.(sdk.Dec)
v, ok := i.(math.LegacyDec)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
@ -119,7 +119,7 @@ func validateInflationMax(i interface{}) error {
}
func validateInflationMin(i interface{}) error {
v, ok := i.(sdk.Dec)
v, ok := i.(math.LegacyDec)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
@ -138,7 +138,7 @@ func validateInflationMin(i interface{}) error {
}
func validateGoalBonded(i interface{}) error {
v, ok := i.(sdk.Dec)
v, ok := i.(math.LegacyDec)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}