Skip to content

Commit

Permalink
[Internal Review][CL][fungifyChargedPosition] add functional test fun…
Browse files Browse the repository at this point in the history
…gifying in-between swaps (osmosis-labs#5410)

* clean up and deduplicate existing fungify tests

* push negative coin panic repro

* finish robust functional tests

* push incentives fix

* fix conflicts and clean up prints
  • Loading branch information
AlpinYukseloglu authored Jun 5, 2023
1 parent fee377b commit 7eca5ec
Show file tree
Hide file tree
Showing 2 changed files with 308 additions and 111 deletions.
49 changes: 49 additions & 0 deletions x/concentrated-liquidity/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,14 @@ func (s *KeeperTestSuite) validatePositionSpreadRewardGrowth(poolId uint64, posi
}
}

func (s *KeeperTestSuite) SetBlockTime(timeToSet time.Time) {
s.Ctx = s.Ctx.WithBlockTime(timeToSet)
}

func (s *KeeperTestSuite) AddBlockTime(timeToAdd time.Duration) {
s.Ctx = s.Ctx.WithBlockTime(s.Ctx.BlockTime().Add(timeToAdd))
}

func (s *KeeperTestSuite) TestValidatePermissionlessPoolCreationEnabled() {
s.SetupTest()
// Normally, by default, permissionless pool creation is disabled.
Expand All @@ -389,6 +397,47 @@ func (s *KeeperTestSuite) TestValidatePermissionlessPoolCreationEnabled() {
s.Require().Error(s.App.ConcentratedLiquidityKeeper.ValidatePermissionlessPoolCreationEnabled(s.Ctx))
}

// runFungifySetup Sets up a pool with `poolSpreadFactor`, prepares `numPositions` default positions on it (all identical), and sets
// up the passed in incentive records such that they emit on the pool. It also sets the largest authorized uptime to be `fullChargeDuration`.
//
// Returns the pool, expected position ids and the total liquidity created on the pool.
func (s *KeeperTestSuite) runFungifySetup(address sdk.AccAddress, numPositions int, fullChargeDuration time.Duration, poolSpreadFactor sdk.Dec, incentiveRecords []types.IncentiveRecord) (types.ConcentratedPoolExtension, []uint64, sdk.Dec) {
expectedPositionIds := make([]uint64, numPositions)
for i := 0; i < numPositions; i++ {
expectedPositionIds[i] = uint64(i + 1)
}

s.TestAccs = apptesting.CreateRandomAccounts(5)
s.SetBlockTime(defaultBlockTime)
totalPositionsToCreate := sdk.NewInt(int64(numPositions))
requiredBalances := sdk.NewCoins(sdk.NewCoin(ETH, DefaultAmt0.Mul(totalPositionsToCreate)), sdk.NewCoin(USDC, DefaultAmt1.Mul(totalPositionsToCreate)))

// Set test authorized uptime params.
params := s.clk.GetParams(s.Ctx)
params.AuthorizedUptimes = []time.Duration{time.Nanosecond, fullChargeDuration}
s.clk.SetParams(s.Ctx, params)

// Fund account
s.FundAcc(address, requiredBalances)

// Create CL pool
pool := s.PrepareCustomConcentratedPool(s.TestAccs[0], ETH, USDC, DefaultTickSpacing, poolSpreadFactor)

// Set incentives for pool to ensure accumulators work correctly
err := s.clk.SetMultipleIncentiveRecords(s.Ctx, incentiveRecords)
s.Require().NoError(err)

// Set up fully charged positions
totalLiquidity := sdk.ZeroDec()
for i := 0; i < numPositions; i++ {
_, _, _, liquidityCreated, _, _, _, err := s.clk.CreatePosition(s.Ctx, defaultPoolId, address, DefaultCoins, sdk.ZeroInt(), sdk.ZeroInt(), DefaultLowerTick, DefaultUpperTick)
s.Require().NoError(err)
totalLiquidity = totalLiquidity.Add(liquidityCreated)
}

return pool, expectedPositionIds, totalLiquidity
}

func (s *KeeperTestSuite) runMultipleAuthorizedUptimes(tests func()) {
authorizedUptimesTested := [][]time.Duration{
DefaultAuthorizedUptimes,
Expand Down
Loading

0 comments on commit 7eca5ec

Please sign in to comment.