-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package pool | ||
|
||
import ( | ||
"testing" | ||
|
||
"std" | ||
|
||
"gno.land/p/demo/uassert" | ||
|
||
"gno.land/r/gnoswap/v1/consts" | ||
i256 "gno.land/p/gnoswap/int256" | ||
u256 "gno.land/p/gnoswap/uint256" | ||
) | ||
|
||
func TestUpdatePosition(t *testing.T) { | ||
poolParams := &createPoolParams{ | ||
token0Path: "token0", | ||
token1Path: "token1", | ||
fee: 500, | ||
tickSpacing: 10, | ||
sqrtPriceX96: u256.MustFromDecimal("1000000000000000000"), // 1.0 | ||
} | ||
p := newPool(poolParams) | ||
|
||
tests := []struct { | ||
name string | ||
positionParams ModifyPositionParams | ||
expectLiquidity *u256.Uint | ||
}{ | ||
{ | ||
name: "add new position", | ||
positionParams: ModifyPositionParams{ | ||
owner: consts.POSITION_ADDR, | ||
tickLower: -100, | ||
tickUpper: 100, | ||
liquidityDelta: i256.MustFromDecimal("1000000"), | ||
}, | ||
expectLiquidity: u256.MustFromDecimal("1000000"), | ||
}, | ||
{ | ||
name: "add liquidity to existing position", | ||
positionParams: ModifyPositionParams{ | ||
owner: consts.POSITION_ADDR, | ||
tickLower: -100, | ||
tickUpper: 100, | ||
liquidityDelta: i256.MustFromDecimal("500000"), | ||
}, | ||
expectLiquidity: u256.MustFromDecimal("1500000"), | ||
}, | ||
{ | ||
name: "remove liquidity from position", | ||
positionParams: ModifyPositionParams{ | ||
owner: consts.POSITION_ADDR, | ||
tickLower: -100, | ||
tickUpper: 100, | ||
liquidityDelta: i256.MustFromDecimal("-500000"), | ||
}, | ||
expectLiquidity: u256.MustFromDecimal("1000000"), | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
position := p.updatePosition(tt.positionParams) | ||
|
||
if !position.liquidity.Eq(tt.expectLiquidity) { | ||
t.Errorf("liquidity mismatch: expected %s, got %s", | ||
tt.expectLiquidity.ToString(), | ||
position.liquidity.ToString()) | ||
} | ||
|
||
if !tt.positionParams.liquidityDelta.IsZero() { | ||
lowerTick := p.ticks[tt.positionParams.tickLower] | ||
upperTick := p.ticks[tt.positionParams.tickUpper] | ||
|
||
if !lowerTick.initialized { | ||
t.Error("lower tick not initialized") | ||
} | ||
if !upperTick.initialized { | ||
t.Error("upper tick not initialized") | ||
} | ||
} | ||
}) | ||
} | ||
} |