Skip to content

Commit

Permalink
Merge branch 'main' into Vvaradinov/store-migration-epochmintprovision
Browse files Browse the repository at this point in the history
  • Loading branch information
fedekunze committed Jan 5, 2023
2 parents a183e20 + 985d0d4 commit 0938737
Showing 1 changed file with 125 additions and 1 deletion.
126 changes: 125 additions & 1 deletion x/inflation/keeper/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper_test

import (
"fmt"
"github.com/evmos/evmos/v10/x/inflation/types"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -24,9 +25,132 @@ var _ = Describe("Inflation", Ordered, func() {
s.SetupTest()
})

Describe("Commiting a block", func() {
Describe("Committing a block", func() {
addr := s.app.AccountKeeper.GetModuleAddress(incentivestypes.ModuleName)

Context("with inflation param enabled and exponential calculation params changed", func() {
BeforeEach(func() {
params := s.app.InflationKeeper.GetParams(s.ctx)
params.EnableInflation = true
params.ExponentialCalculation = types.ExponentialCalculation{
A: sdk.NewDec(int64(300_000_000)),
R: sdk.NewDecWithPrec(60, 2), // 60%
C: sdk.NewDec(int64(6_375_000)),
BondingTarget: sdk.NewDecWithPrec(66, 2), // 66%
MaxVariance: sdk.ZeroDec(), // 0%
}
s.app.InflationKeeper.SetParams(s.ctx, params)
})

Context("before an epoch ends", func() {
BeforeEach(func() {
s.CommitAfter(time.Minute) // Start Epoch
s.CommitAfter(time.Hour * 23) // End Epoch
})

It("should not allocate funds to usage incentives", func() {
balance := s.app.BankKeeper.GetBalance(s.ctx, addr, denomMint)
Expect(balance.IsZero()).To(BeTrue())
})
It("should not allocate funds to the community pool", func() {
balance := s.app.DistrKeeper.GetFeePoolCommunityCoins(s.ctx)
Expect(balance.IsZero()).To(BeTrue())
})
})

Context("after an epoch ends", func() {
BeforeEach(func() {
s.CommitAfter(time.Minute) // Start Epoch
s.CommitAfter(time.Hour * 25) // End Epoch
})

It("should allocate funds to usage incentives", func() {
actual := s.app.BankKeeper.GetBalance(s.ctx, addr, denomMint)

provision := s.app.InflationKeeper.GetEpochMintProvision(s.ctx)
params := s.app.InflationKeeper.GetParams(s.ctx)
distribution := params.InflationDistribution.UsageIncentives
expected := (provision.Mul(distribution)).TruncateInt()

Expect(actual.IsZero()).ToNot(BeTrue())
Expect(actual.Amount).To(Equal(expected))
})

It("should allocate funds to the community pool", func() {
balanceCommunityPool := s.app.DistrKeeper.GetFeePoolCommunityCoins(s.ctx)

provision := s.app.InflationKeeper.GetEpochMintProvision(s.ctx)
params := s.app.InflationKeeper.GetParams(s.ctx)
distribution := params.InflationDistribution.CommunityPool
expected := provision.Mul(distribution)

Expect(balanceCommunityPool.IsZero()).ToNot(BeTrue())
Expect(balanceCommunityPool.AmountOf(denomMint).GT(expected)).To(BeTrue())
})
})
})

Context("with inflation param enabled and distribution params changed", func() {
BeforeEach(func() {
params := s.app.InflationKeeper.GetParams(s.ctx)
params.EnableInflation = true
params.InflationDistribution = types.InflationDistribution{
UsageIncentives: sdk.NewDecWithPrec(533333334, 9), // 0.53 = 40% / (1 - 25%)
StakingRewards: sdk.NewDecWithPrec(333333333, 9), // 0.33 = 25% / (1 - 25%)
CommunityPool: sdk.NewDecWithPrec(133333333, 9), // 0.13 = 10% / (1 - 25%)
}
s.app.InflationKeeper.SetParams(s.ctx, params)
})

Context("before an epoch ends", func() {
BeforeEach(func() {
s.CommitAfter(time.Minute) // Start Epoch
s.CommitAfter(time.Hour * 23) // End Epoch
})

It("should not allocate funds to usage incentives", func() {
balance := s.app.BankKeeper.GetBalance(s.ctx, addr, denomMint)
Expect(balance.IsZero()).To(BeTrue())
})

It("should not allocate funds to the community pool", func() {
balance := s.app.DistrKeeper.GetFeePoolCommunityCoins(s.ctx)
Expect(balance.IsZero()).To(BeTrue())
})
})

Context("after an epoch ends", func() {
BeforeEach(func() {
s.CommitAfter(time.Minute) // Start Epoch
s.CommitAfter(time.Hour * 25) // End Epoch
})

It("should allocate funds to usage incentives", func() {
actual := s.app.BankKeeper.GetBalance(s.ctx, addr, denomMint)

provision := s.app.InflationKeeper.GetEpochMintProvision(s.ctx)
params := s.app.InflationKeeper.GetParams(s.ctx)
distribution := params.InflationDistribution.UsageIncentives
expected := (provision.Mul(distribution)).TruncateInt()

Expect(actual.IsZero()).ToNot(BeTrue())
Expect(actual.Amount).To(Equal(expected))
})

It("should allocate funds to the community pool", func() {
balanceCommunityPool := s.app.DistrKeeper.GetFeePoolCommunityCoins(s.ctx)

provision := s.app.InflationKeeper.GetEpochMintProvision(s.ctx)
params := s.app.InflationKeeper.GetParams(s.ctx)
distribution := params.InflationDistribution.CommunityPool
expected := provision.Mul(distribution)

Expect(balanceCommunityPool.IsZero()).ToNot(BeTrue())
Expect(balanceCommunityPool.AmountOf(denomMint).GT(expected)).To(BeTrue())
})
})
})

Context("with inflation param enabled", func() {
BeforeEach(func() {
params := s.app.InflationKeeper.GetParams(s.ctx)
Expand Down

0 comments on commit 0938737

Please sign in to comment.