Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GSW-1838 fix: pool's scenario test in tests folder #446

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion pool/_helper_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"gno.land/p/demo/uassert"
pusers "gno.land/p/demo/users"
"gno.land/r/demo/users"
"gno.land/r/gnoswap/v1/common"
"gno.land/r/gnoswap/v1/consts"
pn "gno.land/r/gnoswap/v1/position"
)
Expand Down Expand Up @@ -49,13 +50,21 @@ const (
)

var (
admin = pusers.AddressOrName(consts.ADMIN)
fooToken = common.GetToken(fooPath)
barToken = common.GetToken(barPath)
bazToken = common.GetToken(bazPath)
)

var (
adminAddr = consts.ADMIN
admin = pusers.AddressOrName(adminAddr)
alice = pusers.AddressOrName(testutils.TestAddress("alice"))
pool = pusers.AddressOrName(consts.POOL_ADDR)
protocolFee = pusers.AddressOrName(consts.PROTOCOL_FEE_ADDR)
router = pusers.AddressOrName(consts.ROUTER_ADDR)
adminRealm = std.NewUserRealm(users.Resolve(admin))
posRealm = std.NewCodeRealm(consts.POSITION_PATH)
rouRealm = std.NewCodeRealm(consts.ROUTER_PATH)

// addresses used in tests
addrUsedInTest = []std.Address{addr01, addr02}
Expand Down
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
2 changes: 1 addition & 1 deletion pool/position.gno
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func positionUpdate(
if position.liquidity.IsZero() {
panic(addDetailToError(
errZeroLiquidity,
"position.gno__positionUpdate() || both liquidityDelta and current position's liquidity are zero",
"both liquidityDelta and current position's liquidity are zero",
))
}

Expand Down
4 changes: 2 additions & 2 deletions pool/position_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestPositionUpdateWithKey(t *testing.T) {
panicMsg string
expectedLiquidity string
}{
{i256.MustFromDecimal("0"), u256.Zero(), u256.Zero(), true, `[GNOSWAP-POOL-010] zero liquidity || position.gno__positionUpdate() || both liquidityDelta and current position's liquidity are zero`, ""},
{i256.MustFromDecimal("0"), u256.Zero(), u256.Zero(), true, `[GNOSWAP-POOL-010] zero liquidity || both liquidityDelta and current position's liquidity are zero`, ""},
{i256.MustFromDecimal("100000"), u256.Zero(), u256.Zero(), false, "", "100000"},
}

Expand Down Expand Up @@ -109,7 +109,7 @@ func TestPositionUpdate(t *testing.T) {
feeGrowthInside0X128: u256.Zero(),
feeGrowthInside1X128: u256.Zero(),
shouldPanic: true,
panicMsg: `[GNOSWAP-POOL-010] zero liquidity || position.gno__positionUpdate() || both liquidityDelta and current position's liquidity are zero`,
panicMsg: `[GNOSWAP-POOL-010] zero liquidity || both liquidityDelta and current position's liquidity are zero`,
},
{
initialLiquidity: u256.Zero(),
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
Loading
Loading