mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 18:15:19 +00:00
cf009647e6
* Add accumulators * Move accumulator back to keeper package * Add earn specific accumulators * Move store methods to sub-package * Move earn accumulator * Rename accumulator files * Add store doc comment * Add earn accumulator tests, panic if accumulator not used with earn claim type * Update earn accumulator tests to use new methods * Add staking test for earn accumulator * Add test for accumulator proportional rewards * Remove old copy of GetProportionalRewardsPerSecond * Add test for basic accumulator * Fix AddIncentiveMultiRewardPeriod replacement * Deduplicate base earn reward accumulator * Check errors in tests * Validate RewardPeriods in Params.Validate() * Use adapter to fetch earn total shares
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package accumulators_test
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/kava-labs/kava/x/incentive/keeper/accumulators"
|
|
"github.com/kava-labs/kava/x/incentive/types"
|
|
)
|
|
|
|
func (suite *AccumulateEarnRewardsIntegrationTests) TestEarnAccumulator_OnlyEarnClaimType() {
|
|
period := types.NewMultiRewardPeriod(
|
|
true,
|
|
"bkava",
|
|
time.Unix(0, 0), // ensure the test is within start and end times
|
|
distantFuture,
|
|
cs(c("earn", 2000), c("ukava", 1000)), // same denoms as in global indexes
|
|
)
|
|
|
|
earnKeeper := suite.App.GetEarnKeeper()
|
|
|
|
for _, claimTypeValue := range types.ClaimType_value {
|
|
claimType := types.ClaimType(claimTypeValue)
|
|
|
|
if claimType == types.CLAIM_TYPE_EARN {
|
|
suite.NotPanics(func() {
|
|
err := accumulators.
|
|
NewEarnAccumulator(suite.keeper.Store, suite.App.GetLiquidKeeper(), &earnKeeper, suite.keeper.Adapters).
|
|
AccumulateRewards(suite.Ctx, claimType, period)
|
|
suite.NoError(err)
|
|
})
|
|
|
|
continue
|
|
}
|
|
|
|
suite.PanicsWithValue(
|
|
fmt.Sprintf(
|
|
"invalid claim type for earn accumulator, expected %s but got %s",
|
|
types.CLAIM_TYPE_EARN,
|
|
claimType,
|
|
),
|
|
func() {
|
|
err := accumulators.
|
|
NewEarnAccumulator(suite.keeper.Store, suite.App.GetLiquidKeeper(), &earnKeeper, suite.keeper.Adapters).
|
|
AccumulateRewards(suite.Ctx, claimType, period)
|
|
suite.NoError(err)
|
|
},
|
|
)
|
|
}
|
|
}
|