Skip to content

Commit

Permalink
fix: lint and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasmatt committed Jan 3, 2024
1 parent b986ccf commit 6df7546
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
1 change: 1 addition & 0 deletions x/inflation/types/inflation_calculation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
36 changes: 31 additions & 5 deletions x/inflation/types/inflation_calculation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++ {
Expand All @@ -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) {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion x/inflation/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func NewParams(
}
}

// default minting module parameters
// default inflation module parameters
func DefaultParams() Params {
return Params{
PolynomialFactors: DefaultPolynomialFactors,
Expand Down

0 comments on commit 6df7546

Please sign in to comment.