Skip to content

Commit

Permalink
driveby test cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
AlpinYukseloglu committed Mar 20, 2024
1 parent 01e266e commit b1952b9
Showing 1 changed file with 45 additions and 46 deletions.
91 changes: 45 additions & 46 deletions x/concentrated-liquidity/position_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2393,66 +2393,65 @@ func (s *KeeperTestSuite) TestTransferPositions() {
if tc.expectedError != nil {
s.Require().Error(err)
s.Require().ErrorIs(err, tc.expectedError)
} else {
s.Require().NoError(err)
}
s.Require().NoError(err)

// Check that the positions we wanted transferred were modified appropriately
for _, positionId := range tc.positionsToTransfer {
newPosition, err := s.App.ConcentratedLiquidityKeeper.GetPosition(s.Ctx, positionId)
s.Require().NoError(err)
// Check that the old owner's balance did not change due to the transfer
postTransferOriginalOwnerFunds := s.App.BankKeeper.GetAllBalances(s.Ctx, oldOwner)
s.Require().Equal(preTransferOwnerFunds.String(), postTransferOriginalOwnerFunds.String())

oldPosition := model.Position{}
for _, initialPosition := range initialUserPositions {
if initialPosition.PositionId == newPosition.PositionId {
oldPosition = initialPosition
break
}
}
// Check that the new owner's balance did not change due to the transfer
postTransferNewOwnerFunds := s.App.BankKeeper.GetAllBalances(s.Ctx, newOwner)
s.Require().Equal(preTransferNewOwnerFunds, postTransferNewOwnerFunds)

// All position values except the owner should be the same in the new position as it was in the old one.
s.Require().Equal(oldPosition.UpperTick, newPosition.UpperTick)
s.Require().Equal(oldPosition.LowerTick, newPosition.LowerTick)
s.Require().Equal(oldPosition.PoolId, newPosition.PoolId)
s.Require().Equal(oldPosition.JoinTime, newPosition.JoinTime)
s.Require().Equal(oldPosition.Liquidity, newPosition.Liquidity)
// Check that the positions we wanted transferred were modified appropriately
for _, positionId := range tc.positionsToTransfer {
newPosition, err := s.App.ConcentratedLiquidityKeeper.GetPosition(s.Ctx, positionId)
s.Require().NoError(err)

// The new position should have the new owner
s.Require().Equal(newOwner.String(), newPosition.Address)
oldPosition := model.Position{}
for _, initialPosition := range initialUserPositions {
if initialPosition.PositionId == newPosition.PositionId {
oldPosition = initialPosition
break
}
}

allPositions := append(tc.inRangePositions, tc.outOfRangePositions...)
positionsNotTransfered := osmoutils.DisjointArrays(allPositions, tc.positionsToTransfer)
// All position values except the owner should be the same in the new position as it was in the old one.
s.Require().Equal(oldPosition.UpperTick, newPosition.UpperTick)
s.Require().Equal(oldPosition.LowerTick, newPosition.LowerTick)
s.Require().Equal(oldPosition.PoolId, newPosition.PoolId)
s.Require().Equal(oldPosition.JoinTime, newPosition.JoinTime)
s.Require().Equal(oldPosition.Liquidity, newPosition.Liquidity)

// Check that the positions not transferred were not modified
for _, positionId := range positionsNotTransfered {
oldPosition, err := s.App.ConcentratedLiquidityKeeper.GetPosition(s.Ctx, positionId)
s.Require().NoError(err)
// The new position should have the new owner
s.Require().Equal(newOwner.String(), newPosition.Address)
}

newPosition := model.Position{}
for _, initialPosition := range initialUserPositions {
if initialPosition.PositionId == oldPosition.PositionId {
newPosition = initialPosition
break
}
}
allPositions := append(tc.inRangePositions, tc.outOfRangePositions...)
positionsNotTransfered := osmoutils.DisjointArrays(allPositions, tc.positionsToTransfer)

// All position values should be the same in the new position as it was in the old one.
s.Require().Equal(oldPosition, newPosition)
}
// Check that the positions not transferred were not modified
for _, positionId := range positionsNotTransfered {
oldPosition, err := s.App.ConcentratedLiquidityKeeper.GetPosition(s.Ctx, positionId)
s.Require().NoError(err)

// Check that the old owner's balance did not change due to the transfer
postTransferOriginalOwnerFunds := s.App.BankKeeper.GetAllBalances(s.Ctx, oldOwner)
s.Require().Equal(preTransferOwnerFunds.String(), postTransferOriginalOwnerFunds.String())
newPosition := model.Position{}
for _, initialPosition := range initialUserPositions {
if initialPosition.PositionId == oldPosition.PositionId {
newPosition = initialPosition
break
}
}

// Check that the new owner's balance did not change due to the transfer
postTransferNewOwnerFunds := s.App.BankKeeper.GetAllBalances(s.Ctx, newOwner)
s.Require().Equal(preTransferNewOwnerFunds, postTransferNewOwnerFunds)
// All position values should be the same in the new position as it was in the old one.
s.Require().Equal(oldPosition, newPosition)

// Claim rewards and ensure that previously accrued incentives and spread rewards go to the new owner
for _, positionID := range tc.positionsToTransfer {
_, err = s.App.ConcentratedLiquidityKeeper.CollectSpreadRewards(s.Ctx, newOwner, positionID)
for _, positionId := range tc.positionsToTransfer {
_, _, err := s.App.ConcentratedLiquidityKeeper.CollectIncentives(s.Ctx, newOwner, positionId)
s.Require().NoError(err)
_, _, err := s.App.ConcentratedLiquidityKeeper.CollectIncentives(s.Ctx, newOwner, positionID)
_, err = s.App.ConcentratedLiquidityKeeper.CollectSpreadRewards(s.Ctx, newOwner, positionId)
s.Require().NoError(err)
}

Expand Down

0 comments on commit b1952b9

Please sign in to comment.