Skip to content

Commit

Permalink
test: update to current contract
Browse files Browse the repository at this point in the history
  • Loading branch information
r3v4s committed Apr 9, 2024
1 parent 0805dd3 commit 8bba9a3
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 35 deletions.
2 changes: 0 additions & 2 deletions pool/_TEST_/z1_single_lp_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ func init() {
pl.RegisterGRC20Interface("gno.land/r/demo/obl", OBLToken{})
pl.RegisterGRC20Interface("gno.land/r/demo/wugnot", WugnotToken{})
pl.RegisterGRC20Interface("gno.land/r/demo/gns", GNSToken{})

}

/* START TEST */
Expand Down Expand Up @@ -221,7 +220,6 @@ func createBarFooPool() {
std.TestSkipHeights(1)
}
func mint() {
panic("TEST")
std.TestSetPrevAddr(test1)

bar.Approve(a2u(consts.POOL_ADDR), consts.UINT64_MAX)
Expand Down
2 changes: 1 addition & 1 deletion position/_TEST_/_TEST_position_increase_decrease_test.gn
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestIncreaseLiquidity(t *testing.T) {
pool := getPoolFromLpTokenId(uint64(1))
oldLiquidity := pool.PoolGetLiquidity()

_, _, m0, m1 := IncreaseLiquidity(
_, _, m0, m1, _ := IncreaseLiquidity(
uint64(1), // tokenId
"10000000", // amount0Desired
"10000000", // amount1Desired
Expand Down
6 changes: 3 additions & 3 deletions router/_TEST_/_TEST_router_ratio_test.gn
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ func TestApiGetRatiosFromBase(t *testing.T) {
shouldEQ(t, token0.String(), "{\"token\":\"gno.land/r/demo/wugnot\",\"ratio\":\"79228162514264337593543950336\"}")
shouldEQ(t, token1.String(), "{\"token\":\"gno.land/r/demo/bar\",\"ratio\":\"19935653721785907863909200771\"}")
shouldEQ(t, token2.String(), "{\"token\":\"gno.land/r/demo/qux\",\"ratio\":\"79228162514264337593543950338\"}")
shouldEQ(t, token3.String(), "{\"token\":\"gno.land/r/demo/foo\",\"ratio\":\"21827358772679825007021358318119\"}")
shouldEQ(t, token3.String(), "{\"token\":\"gno.land/r/demo/foo\",\"ratio\":\"10796452559328726350\"}")
shouldEQ(t, token4.String(), "{\"token\":\"gno.land/r/demo/baz\",\"ratio\":\"158459202898910110285447649633\"}")
shouldEQ(t, token5.String(), "{\"token\":\"gno.land/r/demo/obl\",\"ratio\":\"316918405797820220570895299266\"}")
shouldEQ(t, token6.String(), "{\"token\":\"gno.land/r/demo/gns\",\"ratio\":\"633836811595640441141790598532\"}")
shouldEQ(t, token5.String(), "{\"token\":\"gno.land/r/demo/obl\",\"ratio\":\"6102283613564175414\"}")
shouldEQ(t, token6.String(), "{\"token\":\"gno.land/r/demo/gns\",\"ratio\":\"12204788885446722546\"}")
}
41 changes: 22 additions & 19 deletions router/_TEST_/_TEST_router_swap_route_1route_1hop_test.gn
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package router

import (
// @notJoon JSON
"std"
"testing"

Expand Down Expand Up @@ -64,7 +63,7 @@ func TestSwapRouteBarBazExactIn(t *testing.T) {
bar.Approve(a2u(consts.POOL_ADDR), uint64(1000))
baz.Approve(a2u(consts.ROUTER_ADDR), consts.UINT64_MAX) // ITS FOR 0.15% fee

swapResult := SwapRoute(
amountIn, amountOut := SwapRoute(
barPath, // inputToken
bazPath, // outputToken
"1000", // amountSpecified
Expand All @@ -73,7 +72,8 @@ func TestSwapRouteBarBazExactIn(t *testing.T) {
"100", // quoteArr
"2700", // tokenAmountLimit
)
shouldEQ(t, swapResult, "2707")
shouldEQ(t, amountIn, "1000")
shouldEQ(t, amountOut, "-2707")
}

func TestDrySwapRouteBarBazExactOut(t *testing.T) {
Expand All @@ -97,7 +97,7 @@ func TestSwapRouteBarBazExactOut(t *testing.T) {
bar.Approve(a2u(consts.POOL_ADDR), uint64(1000))
baz.Approve(a2u(consts.ROUTER_ADDR), consts.UINT64_MAX) // ITS FOR 0.15% fee

swapResult := SwapRoute(
amountIn, amountOut := SwapRoute(
barPath, // inputToken
bazPath, // outputToken
"1000", // amountSpecified
Expand All @@ -107,7 +107,8 @@ func TestSwapRouteBarBazExactOut(t *testing.T) {
"370", // tokenAmountLimit
)

shouldEQ(t, swapResult, "370")
shouldEQ(t, amountIn, "370")
shouldEQ(t, amountOut, "-999")
}

func TestDrySwapRouteBazBarExactIn(t *testing.T) {
Expand All @@ -131,7 +132,7 @@ func TestSwapRouteBazBarExactIn(t *testing.T) {
baz.Approve(a2u(consts.POOL_ADDR), consts.UINT64_MAX)
bar.Approve(a2u(consts.ROUTER_ADDR), consts.UINT64_MAX) // ITS FOR 0.15% fee

swapResult := SwapRoute(
amountIn, amountOut := SwapRoute(
bazPath, // inputToken
barPath, // outputToken
"1000", // amountSpecified
Expand All @@ -141,37 +142,39 @@ func TestSwapRouteBazBarExactIn(t *testing.T) {
"360", // tokenAmountLimit
)

shouldEQ(t, swapResult, "368")
shouldEQ(t, amountIn, "1000")
shouldEQ(t, amountOut, "-368")
}

func TestDrySwapRouteBazBarExactOut(t *testing.T) {
std.TestSetPrevAddr(test1)

dryResult := DrySwapRoute(
bazPath, // inputToken
barPath, // outputToken
"3000", // amountSpecified
"EXACT_IN", // swapType
bazPath, // inputToken
barPath, // outputToken
"3000", // amountSpecified
"EXACT_OUT", // swapType
"gno.land/r/demo/baz:gno.land/r/demo/bar:500", // strRouteArr
"100", // quoteArr
)

shouldEQ(t, dryResult, "1104")
shouldEQ(t, dryResult, "8169")
}

func TestSwapRouteBazBarExactOut(t *testing.T) {
std.TestSetPrevAddr(test1)
bar.Approve(a2u(consts.ROUTER_ADDR), consts.UINT64_MAX)

swapResult := SwapRoute(
bazPath, // inputToken
barPath, // outputToken
"3000", // amountSpecified
"EXACT_IN", // swapType
amountIn, amountOut := SwapRoute(
bazPath, // inputToken
barPath, // outputToken
"3000", // amountSpecified
"EXACT_OUT", // swapType
"gno.land/r/demo/baz:gno.land/r/demo/bar:500", // strRouteArr
"100", // quoteArr
"1100", // tokenAmountLimit
"8200", // tokenAmountLimit
)

shouldEQ(t, swapResult, "1103")
shouldEQ(t, amountIn, "8169")
shouldEQ(t, amountOut, "-2996")
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func TestSwapRouteGnsBarExactIn(t *testing.T) {
gns.Approve(a2u(consts.POOL_ADDR), 1000) // swap input amount
bar.Approve(a2u(consts.ROUTER_ADDR), 7328) // 0.15% fee

swapResult := SwapRoute(
amountIn, amountOut := SwapRoute(
consts.GNS_PATH, // inputToken
barPath, // outputToken
"1000", // amountSpecified
Expand All @@ -107,5 +107,6 @@ func TestSwapRouteGnsBarExactIn(t *testing.T) {
"100", // quoteArr
"0", // tokenAmountLimit
)
shouldEQ(t, swapResult, "7328")
shouldEQ(t, amountIn, "1000")
shouldEQ(t, amountOut, "-7328")
}
20 changes: 12 additions & 8 deletions router/_TEST_/_TEST_router_swap_route_2route_2hop_test.gn
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestSwapRouteBarQuxExactIn(t *testing.T) {
bar.Approve(a2u(consts.POOL_ADDR), 10000)
qux.Approve(a2u(consts.ROUTER_ADDR), 10000)

swapResult := SwapRoute(
amountIn, amountOut := SwapRoute(
barPath, // inputToken
quxPath, // outputToken
"1000", // amountSpecified
Expand All @@ -75,7 +75,8 @@ func TestSwapRouteBarQuxExactIn(t *testing.T) {
"1", // tokenAmountLimit
)

shouldEQ(t, swapResult, "7318")
shouldEQ(t, amountIn, "1000")
shouldEQ(t, amountOut, "-7318")
}

func TestDrySwapRouteBarQuxExactOut(t *testing.T) {
Expand All @@ -96,7 +97,7 @@ func TestDrySwapRouteBarQuxExactOut(t *testing.T) {
func TestSwapRouteBarQuxExactOut(t *testing.T) {
std.TestSetPrevAddr(test1)

swapResult := SwapRoute(
amountIn, amountOut := SwapRoute(
barPath, // inputToken
quxPath, // outputToken
"1000", // amountSpecified
Expand All @@ -106,7 +107,8 @@ func TestSwapRouteBarQuxExactOut(t *testing.T) {
"99999", // tokenAmountLimit
)

shouldEQ(t, swapResult, "138")
shouldEQ(t, amountIn, "138")
shouldEQ(t, amountOut, "-996")
}

func TestDrySwapRouteQuxBarExactIn(t *testing.T) {
Expand All @@ -127,7 +129,7 @@ func TestDrySwapRouteQuxBarExactIn(t *testing.T) {
func TestSwapRouteQuxBarExactIn(t *testing.T) {
std.TestSetPrevAddr(test1)

swapResult := SwapRoute(
amountIn, amountOut := SwapRoute(
quxPath, // inputToken
barPath, // outputToken
"1000", // amountSpecified
Expand All @@ -137,7 +139,8 @@ func TestSwapRouteQuxBarExactIn(t *testing.T) {
"1", // tokenAmountLimit
)

shouldEQ(t, swapResult, "135")
shouldEQ(t, amountIn, "1000")
shouldEQ(t, amountOut, "-135")
}

func TestDrySwapRouteQuxBarExactOut(t *testing.T) {
Expand All @@ -161,7 +164,7 @@ func TestwapRouteQuxBarExactOut(t *testing.T) {
qux.Approve(a2u(consts.POOL_ADDR), 10000)
bar.Approve(a2u(consts.ROUTER_ADDR), 10000)

swapResult := SwapRoute(
amountIn, amountOut := SwapRoute(
quxPath, // inputToken
barPath, // outputToken
"1000", // amountSpecified
Expand All @@ -171,5 +174,6 @@ func TestwapRouteQuxBarExactOut(t *testing.T) {
"99999", // tokenAmountLimit
)

shouldEQ(t, swapResult, "7350")
shouldEQ(t, amountIn, "7350")
shouldEQ(t, amountOut, "-997")
}

0 comments on commit 8bba9a3

Please sign in to comment.