Skip to content

Commit

Permalink
test: fix scenario gnoA tests
Browse files Browse the repository at this point in the history
  • Loading branch information
r3v4s committed Dec 21, 2024
1 parent 2a7ffe3 commit e5dbf00
Show file tree
Hide file tree
Showing 21 changed files with 376 additions and 454 deletions.
2 changes: 1 addition & 1 deletion pool/pool_transfer.gno
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (p *Pool) safeTransfer(
amount *i256.Int,
isToken0 bool,
) {
if amount.Sign() != -1 {
if amount.Gt(i256.Zero()) {
panic(ufmt.Sprintf(
"%v. got: %s", errMustBeNegative, amount.ToString(),
))
Expand Down
51 changes: 0 additions & 51 deletions pool/tests/__TEST_0_INIT_VARIABLE_AND_HELPER_test.gnoA

This file was deleted.

56 changes: 28 additions & 28 deletions pool/tests/__TEST_pool_burn_test.gnoA
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,30 @@ func TestDoesNotClear(t *testing.T) {
-887160,
887160,
test_liquidityExpectStr,
admin,
adminAddr,
)

std.TestSetRealm(rouRealm)
Swap(
barPath,
fooPath,
fee500,
admin,
adminAddr,
true,
"10000",
consts.MIN_PRICE,
admin,
adminAddr,
)

Swap(
barPath,
fooPath,
fee500,
admin,
adminAddr,
false,
"10000",
consts.MAX_PRICE,
admin,
adminAddr,
)
// did swap t0 => t1 and t1 => t0

Expand All @@ -82,7 +82,7 @@ func TestDoesNotClear(t *testing.T) {

// tokensOwed
thisPositionKey := getPositionKey(consts.POSITION_ADDR, -887160, 887160)
thisPosition := thisPool.positions[thisPositionKey]
thisPosition := thisPool.mustGetPosition(thisPositionKey)

tokensOwed0 := thisPosition.tokensOwed0
tokensOwed1 := thisPosition.tokensOwed1
Expand Down Expand Up @@ -113,7 +113,7 @@ func TestClearOnlyLowTick(t *testing.T) {
-887160,
887160,
"1",
admin,
adminAddr,
)

Mint(
Expand All @@ -124,19 +124,19 @@ func TestClearOnlyLowTick(t *testing.T) {
-887100,
887160,
"1",
admin,
adminAddr,
)

std.TestSetRealm(rouRealm)
Swap(
barPath,
fooPath,
fee3000,
admin,
adminAddr,
true,
"10000",
consts.MIN_PRICE,
admin,
adminAddr,
)

std.TestSetRealm(posRealm)
Expand All @@ -150,13 +150,13 @@ func TestClearOnlyLowTick(t *testing.T) {
)

thisPool := GetPool(barPath, fooPath, fee3000)
lowerInfo := thisPool.ticks[-887160]
uassert.Equal(t, lowerInfo.liquidityGross.ToString(), "")
uassert.Equal(t, lowerInfo.feeGrowthOutside0X128.ToString(), "")
uassert.Equal(t, lowerInfo.feeGrowthOutside1X128.ToString(), "")
// uassert.Equal(t, lowerInfo.liquidityNet.ToString(), "") // i256 nil check
lowerInfo := thisPool.getTick(-887160)
uassert.Equal(t, lowerInfo.liquidityGross.ToString(), "0")
uassert.Equal(t, lowerInfo.feeGrowthOutside0X128.ToString(), "0")
uassert.Equal(t, lowerInfo.feeGrowthOutside1X128.ToString(), "0")
uassert.Equal(t, lowerInfo.liquidityNet.ToString(), "0")

upperInfo := thisPool.ticks[887160]
upperInfo := thisPool.getTick(887160)
uassert.NotEqual(t, upperInfo.liquidityGross.ToString(), "")
}

Expand All @@ -177,7 +177,7 @@ func TestClearOnlyUpperTick(t *testing.T) {
-887160,
887160,
"1",
admin,
adminAddr,
)

Mint(
Expand All @@ -188,19 +188,19 @@ func TestClearOnlyUpperTick(t *testing.T) {
-887160,
887100,
"1",
admin,
adminAddr,
)

std.TestSetRealm(rouRealm)
Swap(
barPath,
fooPath,
fee100,
admin,
adminAddr,
true,
"10000",
consts.MIN_PRICE,
admin,
adminAddr,
)

std.TestSetRealm(posRealm)
Expand All @@ -214,12 +214,12 @@ func TestClearOnlyUpperTick(t *testing.T) {
)

thisPool := GetPool(barPath, fooPath, fee100)
lowerInfo := thisPool.ticks[-887160]
uassert.NotEqual(t, lowerInfo.liquidityGross.ToString(), "")

upperInfo := thisPool.ticks[887160]
uassert.Equal(t, upperInfo.liquidityGross.ToString(), "")
uassert.Equal(t, upperInfo.feeGrowthOutside0X128.ToString(), "")
uassert.Equal(t, upperInfo.feeGrowthOutside1X128.ToString(), "")
// uassert.Equal(t, upperInfo.liquidityNet.ToString(), "") // i256 nil check
lowerInfo := thisPool.getTick(-887160)
uassert.NotEqual(t, lowerInfo.liquidityGross.ToString(), "0")

upperInfo := thisPool.getTick(887160)
uassert.Equal(t, upperInfo.liquidityGross.ToString(), "0")
uassert.Equal(t, upperInfo.feeGrowthOutside0X128.ToString(), "0")
uassert.Equal(t, upperInfo.feeGrowthOutside1X128.ToString(), "0")
uassert.Equal(t, upperInfo.liquidityNet.ToString(), "0")
}
4 changes: 2 additions & 2 deletions pool/tests/__TEST_pool_dryswap_and_swap_test.gnoA
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestCreatePool(t *testing.T) {

gns.Approve(a2u(consts.POOL_ADDR), poolCreationFee)
CreatePool(barPath, fooPath, fee500, common.TickMathGetSqrtRatioAtTick(-10000).ToString()) // tick -10000
uassert.Equal(t, len(pools), 1)
uassert.Equal(t, pools.Size(), 1)
}

func TestDrySwap_ZeroForOneTrue_AmountSpecified_Positive_16000(t *testing.T) {
Expand All @@ -52,7 +52,7 @@ func TestDrySwap_ZeroForOneTrue_AmountSpecified_Positive_16000(t *testing.T) {
std.TestSetRealm(adminRealm)

std.TestSetRealm(posRealm)
Mint(fooPath, barPath, fee500, consts.POSITION_ADDR, -tickUpper, -tickLower, liquidityExpect, admin) // -11000 ~ -9000
Mint(fooPath, barPath, fee500, consts.POSITION_ADDR, -tickUpper, -tickLower, liquidityExpect, adminAddr) // -11000 ~ -9000

// zeroForOne true
// amountSpecified 16000
Expand Down
12 changes: 6 additions & 6 deletions pool/tests/__TEST_pool_fee_protocol_test.gnoA
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,37 @@ func TestProtocolFee(t *testing.T) {
t.Run("fails if fee is lt 4 or gt 10", func(t *testing.T) {
uassert.PanicsWithMessage(
t,
`[GNOSWAP-POOL-015] invalid protocol fee percentage || pool.gno__setFeeProtocol() || expected (feeProtocol0(3) == 0 || (feeProtocol0(3) >= 4 && feeProtocol0(3) <= 10)) && (feeProtocol1(3) == 0 || (feeProtocol1(3) >= 4 && feeProtocol1(3) <= 10))`,
`[GNOSWAP-POOL-015] invalid protocol fee percentage || expected (feeProtocol0(3) == 0 || (feeProtocol0(3) >= 4 && feeProtocol0(3) <= 10)) && (feeProtocol1(3) == 0 || (feeProtocol1(3) >= 4 && feeProtocol1(3) <= 10))`,
func() { setFeeProtocol(3, 3) },
)

uassert.PanicsWithMessage(
t,
`[GNOSWAP-POOL-015] invalid protocol fee percentage || pool.gno__setFeeProtocol() || expected (feeProtocol0(6) == 0 || (feeProtocol0(6) >= 4 && feeProtocol0(6) <= 10)) && (feeProtocol1(3) == 0 || (feeProtocol1(3) >= 4 && feeProtocol1(3) <= 10))`,
`[GNOSWAP-POOL-015] invalid protocol fee percentage || expected (feeProtocol0(6) == 0 || (feeProtocol0(6) >= 4 && feeProtocol0(6) <= 10)) && (feeProtocol1(3) == 0 || (feeProtocol1(3) >= 4 && feeProtocol1(3) <= 10))`,
func() { setFeeProtocol(6, 3) },
)

uassert.PanicsWithMessage(
t,
`[GNOSWAP-POOL-015] invalid protocol fee percentage || pool.gno__setFeeProtocol() || expected (feeProtocol0(3) == 0 || (feeProtocol0(3) >= 4 && feeProtocol0(3) <= 10)) && (feeProtocol1(6) == 0 || (feeProtocol1(6) >= 4 && feeProtocol1(6) <= 10))`,
`[GNOSWAP-POOL-015] invalid protocol fee percentage || expected (feeProtocol0(3) == 0 || (feeProtocol0(3) >= 4 && feeProtocol0(3) <= 10)) && (feeProtocol1(6) == 0 || (feeProtocol1(6) >= 4 && feeProtocol1(6) <= 10))`,
func() { setFeeProtocol(3, 6) },
)

uassert.PanicsWithMessage(
t,
`[GNOSWAP-POOL-015] invalid protocol fee percentage || pool.gno__setFeeProtocol() || expected (feeProtocol0(11) == 0 || (feeProtocol0(11) >= 4 && feeProtocol0(11) <= 10)) && (feeProtocol1(11) == 0 || (feeProtocol1(11) >= 4 && feeProtocol1(11) <= 10))`,
`[GNOSWAP-POOL-015] invalid protocol fee percentage || expected (feeProtocol0(11) == 0 || (feeProtocol0(11) >= 4 && feeProtocol0(11) <= 10)) && (feeProtocol1(11) == 0 || (feeProtocol1(11) >= 4 && feeProtocol1(11) <= 10))`,
func() { setFeeProtocol(11, 11) },
)

uassert.PanicsWithMessage(
t,
`[GNOSWAP-POOL-015] invalid protocol fee percentage || pool.gno__setFeeProtocol() || expected (feeProtocol0(6) == 0 || (feeProtocol0(6) >= 4 && feeProtocol0(6) <= 10)) && (feeProtocol1(11) == 0 || (feeProtocol1(11) >= 4 && feeProtocol1(11) <= 10))`,
`[GNOSWAP-POOL-015] invalid protocol fee percentage || expected (feeProtocol0(6) == 0 || (feeProtocol0(6) >= 4 && feeProtocol0(6) <= 10)) && (feeProtocol1(11) == 0 || (feeProtocol1(11) >= 4 && feeProtocol1(11) <= 10))`,
func() { setFeeProtocol(6, 11) },
)

uassert.PanicsWithMessage(
t,
`[GNOSWAP-POOL-015] invalid protocol fee percentage || pool.gno__setFeeProtocol() || expected (feeProtocol0(11) == 0 || (feeProtocol0(11) >= 4 && feeProtocol0(11) <= 10)) && (feeProtocol1(6) == 0 || (feeProtocol1(6) >= 4 && feeProtocol1(6) <= 10))`,
`[GNOSWAP-POOL-015] invalid protocol fee percentage || expected (feeProtocol0(11) == 0 || (feeProtocol0(11) >= 4 && feeProtocol0(11) <= 10)) && (feeProtocol1(6) == 0 || (feeProtocol1(6) >= 4 && feeProtocol1(6) <= 10))`,
func() { setFeeProtocol(11, 6) },
)
})
Expand Down
18 changes: 9 additions & 9 deletions pool/tests/__TEST_pool_init_test.gnoA
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestMintPostInit(t *testing.T) {
-1000,
1000,
test_liquidityExpectStr,
admin,
adminAddr,
)
})
currentLiq := thisPool.liquidity.ToString()
Expand All @@ -56,7 +56,7 @@ func TestMintPostInit(t *testing.T) {
-2000,
-1000,
test_liquidityExpectStr,
admin,
adminAddr,
)

nowLiq := thisPool.liquidity.ToString()
Expand All @@ -73,7 +73,7 @@ func TestMintPostInit(t *testing.T) {
1000,
2000,
test_liquidityExpectStr,
admin,
adminAddr,
)

nowLiq := thisPool.liquidity.ToString()
Expand All @@ -92,7 +92,7 @@ func TestMintPostInit(t *testing.T) {
0,
10,
test_liquidityExpectStr,
admin,
adminAddr,
)
nowLiq := thisPool.liquidity.ToString()

Expand All @@ -101,11 +101,11 @@ func TestMintPostInit(t *testing.T) {
barPath,
fooPath,
fee500,
admin,
adminAddr,
true,
"1",
consts.MIN_PRICE,
admin,
adminAddr,
)

poolTick := thisPool.slot0.tick
Expand All @@ -124,7 +124,7 @@ func TestMintPostInit(t *testing.T) {
-10,
0,
test_liquidityExpectStr,
admin,
adminAddr,
)
nowLiq := thisPool.liquidity.ToString()

Expand All @@ -133,11 +133,11 @@ func TestMintPostInit(t *testing.T) {
barPath,
fooPath,
fee500,
admin,
adminAddr,
true,
"1",
consts.MIN_PRICE,
admin,
adminAddr,
)

poolTick := thisPool.slot0.tick
Expand Down
Loading

0 comments on commit e5dbf00

Please sign in to comment.