Skip to content

Commit 5cf383a

Browse files
committed
add skipSpamGaugeDistribute test
1 parent 424c6f5 commit 5cf383a

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

x/incentives/keeper/distribute_test.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2406,3 +2406,93 @@ func (s *KeeperTestSuite) TestHandleGroupPostDistribute() {
24062406
validateLastEpochNonPerpetualPruning(currentGauge.Id, currentGauge.DistributedCoins.Add(defaultCoins...), initialDistributionCoins, s.App.BankKeeper.GetAllBalances(s.Ctx, s.App.AccountKeeper.GetModuleAddress(types.ModuleName)))
24072407
})
24082408
}
2409+
2410+
func (s *KeeperTestSuite) TestSkipSpamGaugeDistribute() {
2411+
defaultGauge := perpGaugeDesc{
2412+
lockDenom: defaultLPDenom,
2413+
lockDuration: defaultLockDuration,
2414+
rewardAmount: sdk.Coins{sdk.NewInt64Coin(defaultRewardDenom, 3000)},
2415+
}
2416+
2417+
tenCoins := sdk.Coins{sdk.NewInt64Coin(defaultRewardDenom, 10)}
2418+
oneKCoins := sdk.Coins{sdk.NewInt64Coin(defaultRewardDenom, 1000)}
2419+
twoCoinsOneK := sdk.Coins{sdk.NewInt64Coin(defaultRewardDenom, 1000), sdk.NewInt64Coin("uosmo", 1000)}
2420+
tests := []struct {
2421+
name string
2422+
locks []*lockuptypes.PeriodLock
2423+
gauge perpGaugeDesc
2424+
totalDistrCoins sdk.Coins
2425+
remainCoins sdk.Coins
2426+
expectedToSkip bool
2427+
expectedTotalDistrCoins sdk.Coins
2428+
expectedGaugeUpdated bool
2429+
}{
2430+
{
2431+
name: "Lock length of 0, should be skipped",
2432+
locks: []*lockuptypes.PeriodLock{},
2433+
gauge: defaultGauge,
2434+
totalDistrCoins: oneKCoins,
2435+
remainCoins: sdk.Coins{},
2436+
expectedToSkip: true,
2437+
expectedTotalDistrCoins: nil,
2438+
expectedGaugeUpdated: false,
2439+
},
2440+
{
2441+
name: "Empty remainCoins, should be skipped",
2442+
locks: []*lockuptypes.PeriodLock{
2443+
{ID: 1, Owner: string(s.TestAccs[0]), Coins: oneKCoins, Duration: defaultLockDuration},
2444+
},
2445+
gauge: defaultGauge,
2446+
totalDistrCoins: oneKCoins,
2447+
remainCoins: sdk.Coins{},
2448+
expectedToSkip: true,
2449+
expectedTotalDistrCoins: oneKCoins,
2450+
expectedGaugeUpdated: true,
2451+
},
2452+
{
2453+
name: "Remain coins len == 1 and value less than 100 threshold, should be skipped",
2454+
locks: []*lockuptypes.PeriodLock{
2455+
{ID: 1, Owner: string(s.TestAccs[0]), Coins: oneKCoins, Duration: defaultLockDuration},
2456+
},
2457+
gauge: defaultGauge,
2458+
totalDistrCoins: oneKCoins,
2459+
remainCoins: tenCoins,
2460+
expectedToSkip: true,
2461+
expectedTotalDistrCoins: oneKCoins,
2462+
expectedGaugeUpdated: true,
2463+
},
2464+
{
2465+
name: "Lock length > 0, gauge value greater than 100 threshold, and remain coins len != 1, should not be skipped",
2466+
locks: []*lockuptypes.PeriodLock{
2467+
{ID: 1, Owner: string(s.TestAccs[0]), Coins: oneKCoins, Duration: defaultLockDuration},
2468+
},
2469+
gauge: defaultGauge,
2470+
totalDistrCoins: oneKCoins,
2471+
remainCoins: twoCoinsOneK,
2472+
expectedToSkip: false,
2473+
expectedTotalDistrCoins: oneKCoins,
2474+
expectedGaugeUpdated: false,
2475+
},
2476+
}
2477+
for _, tc := range tests {
2478+
s.SetupTest()
2479+
// setup gauge defined in test case
2480+
gauges := s.SetupGauges([]perpGaugeDesc{tc.gauge}, defaultLPDenom)
2481+
2482+
shouldBeSkipped, distrCoins, err := s.App.IncentivesKeeper.SkipSpamGaugeDistribute(s.Ctx, tc.locks, gauges[0], tc.totalDistrCoins, tc.remainCoins)
2483+
s.Require().NoError(err)
2484+
s.Require().Equal(tc.expectedToSkip, shouldBeSkipped)
2485+
s.Require().Equal(tc.expectedTotalDistrCoins, distrCoins)
2486+
2487+
// Retrieve gauge
2488+
gauge, err := s.App.IncentivesKeeper.GetGaugeByID(s.Ctx, gauges[0].Id)
2489+
s.Require().NoError(err)
2490+
2491+
expectedGauge := gauges[0]
2492+
if tc.expectedGaugeUpdated {
2493+
expectedGauge.FilledEpochs++
2494+
expectedGauge.DistributedCoins = expectedGauge.DistributedCoins.Add(distrCoins...)
2495+
}
2496+
s.Require().Equal(expectedGauge, *gauge)
2497+
}
2498+
}

x/incentives/keeper/export_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/osmosis-labs/osmosis/osmomath"
99
"github.com/osmosis-labs/osmosis/v21/x/incentives/types"
10+
lockuptypes "github.com/osmosis-labs/osmosis/v21/x/lockup/types"
1011
)
1112

1213
var ByGroupQueryCondition = byGroupQueryCondition
@@ -97,3 +98,7 @@ func (k Keeper) CreateGroupInternal(ctx sdk.Context, coins sdk.Coins, numEpochPa
9798
func (k Keeper) CalculateGroupWeights(ctx sdk.Context, group types.Group) (types.Group, error) {
9899
return k.calculateGroupWeights(ctx, group)
99100
}
101+
102+
func (k Keeper) SkipSpamGaugeDistribute(ctx sdk.Context, locks []*lockuptypes.PeriodLock, gauge types.Gauge, totalDistrCoins sdk.Coins, remainCoins sdk.Coins) (bool, sdk.Coins, error) {
103+
return k.skipSpamGaugeDistribute(ctx, locks, gauge, totalDistrCoins, remainCoins)
104+
}

0 commit comments

Comments
 (0)