diff --git a/x/inflation/types/inflation_calculation.go b/x/inflation/types/inflation_calculation.go index e1c6d2c38..363e9aec5 100644 --- a/x/inflation/types/inflation_calculation.go +++ b/x/inflation/types/inflation_calculation.go @@ -35,5 +35,6 @@ func polynomial(factors []sdk.Dec, x sdk.Dec) sdk.Dec { } // Multiply by 1 million to get the value in unibi + // 1 unibi = 1e6 nibi and the polynomial was fit on nibi token curve. return result.Mul(sdk.NewDec(1_000_000)) } diff --git a/x/inflation/types/inflation_calculation_test.go b/x/inflation/types/inflation_calculation_test.go index 8d76e6935..092abf003 100644 --- a/x/inflation/types/inflation_calculation_test.go +++ b/x/inflation/types/inflation_calculation_test.go @@ -29,7 +29,8 @@ func TestCalculateEpochMintProvision(t *testing.T) { epochId := uint64(0) totalInflation := sdk.ZeroDec() - // Only the first 8 years have inflation with default params + // Only the first 8 years have inflation with default params but we run + // for 10 years expecting 0 inflation for year := uint64(0); year < 10; year++ { yearlyInflation := sdk.ZeroDec() for month := uint64(0); month < 12; month++ { @@ -41,13 +42,38 @@ func TestCalculateEpochMintProvision(t *testing.T) { } // Should be within 0.0098% if year < uint64(len(ExpectedYearlyInflation)) { - require.NoError(t, withingRange(yearlyInflation, ExpectedYearlyInflation[year])) + require.NoError(t, withinRange(yearlyInflation, ExpectedYearlyInflation[year])) } else { require.Equal(t, yearlyInflation, sdk.ZeroDec()) } totalInflation = totalInflation.Add(yearlyInflation) } - require.NoError(t, withingRange(totalInflation, ExpectedTotalInflation)) + require.NoError(t, withinRange(totalInflation, ExpectedTotalInflation)) +} + +func TestCalculateEpochMintProvisionInflationNotEnabled(t *testing.T) { + params := DefaultParams() + params.InflationEnabled = false + + epochId := uint64(0) + totalInflation := sdk.ZeroDec() + + // Only the first 8 years have inflation with default params but we run + // for 10 years expecting 0 inflation + for year := uint64(0); year < 10; year++ { + yearlyInflation := sdk.ZeroDec() + for month := uint64(0); month < 12; month++ { + for day := uint64(0); day < 30; day++ { + epochMintProvisions := CalculateEpochMintProvision(params, epochId) + yearlyInflation = yearlyInflation.Add(epochMintProvisions) + } + epochId++ + } + + require.Equal(t, yearlyInflation, sdk.ZeroDec()) + totalInflation = totalInflation.Add(yearlyInflation) + } + require.Equal(t, totalInflation, sdk.ZeroDec()) } func TestCalculateEpochMintProvision_ZeroEpochs(t *testing.T) { @@ -58,9 +84,9 @@ func TestCalculateEpochMintProvision_ZeroEpochs(t *testing.T) { require.Equal(t, epochMintProvisions, sdk.ZeroDec()) } -// withingRange returns an error if the actual value is not within the expected value +/- tolerance +// withinRange returns an error if the actual value is not within the expected value +/- tolerance // tolerance is a percentage set to 0.01% by default -func withingRange(expected, actual sdk.Dec) error { +func withinRange(expected, actual sdk.Dec) error { tolerance := sdk.NewDecWithPrec(1, 4) is_within := expected.Sub(actual).Abs().Quo(expected).LTE(tolerance) if !is_within { diff --git a/x/inflation/types/params.go b/x/inflation/types/params.go index 500d672b4..803b433e9 100644 --- a/x/inflation/types/params.go +++ b/x/inflation/types/params.go @@ -55,7 +55,7 @@ func NewParams( } } -// default minting module parameters +// default inflation module parameters func DefaultParams() Params { return Params{ PolynomialFactors: DefaultPolynomialFactors,