Skip to content

Commit

Permalink
refactor: gnoA test code modified
Browse files Browse the repository at this point in the history
  • Loading branch information
onlyhyde committed Jan 4, 2025
1 parent 3704dd1 commit 4323657
Show file tree
Hide file tree
Showing 20 changed files with 194 additions and 106 deletions.
27 changes: 27 additions & 0 deletions router/_helper_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ func CreatePoolWithoutFee(t *testing.T) {
CreatePool(t, barPath, fooPath, fee500, common.TickMathGetSqrtRatioAtTick(0).ToString(), users.Resolve(admin))
CreatePool(t, bazPath, fooPath, fee3000, common.TickMathGetSqrtRatioAtTick(0).ToString(), users.Resolve(admin))
CreatePool(t, barPath, bazPath, fee3000, common.TickMathGetSqrtRatioAtTick(0).ToString(), users.Resolve(admin))
CreatePool(t, barPath, bazPath, fee500, common.TickMathGetSqrtRatioAtTick(0).ToString(), users.Resolve(admin))
}

func CreateSecondPoolWithoutFee(t *testing.T) {
Expand Down Expand Up @@ -460,3 +461,29 @@ func MakeThirdMintPositionWithoutFee(t *testing.T) (uint64, string, string, stri
users.Resolve(admin),
)
}

func MakeForthMintPositionWithoutFee(t *testing.T) (uint64, string, string, string) {
t.Helper()

// make actual data to test resetting not only position's state but also pool's state
std.TestSetRealm(adminRealm)

TokenApprove(t, barPath, admin, pool, consts.UINT64_MAX)
TokenApprove(t, bazPath, admin, pool, consts.UINT64_MAX)

// mint position
return pn.Mint(
barPath,
bazPath,
fee500,
-887220,
887220,
"50000",
"50000",
"0",
"0",
max_timeout,
users.Resolve(admin),
users.Resolve(admin),
)
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package router
package tests

import (
"std"
"testing"
"time"

"gno.land/p/demo/uassert"

Expand Down Expand Up @@ -83,6 +84,7 @@ func testDrySwapRouteBarQuxExactIn(t *testing.T) {
"EXACT_IN", // swapType
"gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:500*POOL*gno.land/r/onbloc/baz:gno.land/r/onbloc/qux:500,gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:500*POOL*gno.land/r/onbloc/baz:gno.land/r/onbloc/qux:500", // strRouteArr
"50,50", // quoteArr
"1",
)

uassert.Equal(t, dryResult, "7346")
Expand All @@ -97,12 +99,13 @@ func testSwapRouteBarQuxExactIn(t *testing.T) {
qux.Approve(a2u(consts.ROUTER_ADDR), 10000)

amountIn, amountOut := ExactInSwapRoute(
barPath, // inputToken
quxPath, // outputToken
"1000", // amountSpecified
barPath, // inputToken
quxPath, // outputToken
"1000", // amountSpecified
"gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:500*POOL*gno.land/r/onbloc/baz:gno.land/r/onbloc/qux:500,gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:500*POOL*gno.land/r/onbloc/baz:gno.land/r/onbloc/qux:500", // strRouteArr
"50,50", // quoteArr
"1", // tokenAmountLimit
time.Now().Add(time.Hour).Unix(),
)
std.TestSkipHeights(1)

Expand All @@ -127,6 +130,7 @@ func testDrySwapRouteBarQuxExactOut(t *testing.T) {
"EXACT_OUT", // swapType
"gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:500*POOL*gno.land/r/onbloc/baz:gno.land/r/onbloc/qux:500,gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:500*POOL*gno.land/r/onbloc/baz:gno.land/r/onbloc/qux:500", // strRouteArr
"50,50", // quoteArr
"100000",
)

uassert.Equal(t, dryResult, "140")
Expand All @@ -138,12 +142,13 @@ func testSwapRouteBarQuxExactOut(t *testing.T) {
std.TestSetRealm(adminRealm)

amountIn, amountOut := ExactOutSwapRoute(
barPath, // inputToken
quxPath, // outputToken
"1000", // amountSpecified
barPath, // inputToken
quxPath, // outputToken
"1000", // amountSpecified
"gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:500*POOL*gno.land/r/onbloc/baz:gno.land/r/onbloc/qux:500,gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:500*POOL*gno.land/r/onbloc/baz:gno.land/r/onbloc/qux:500", // strRouteArr
"50,50", // quoteArr
"99999", // tokenAmountLimit
time.Now().Add(time.Hour).Unix(),
)
std.TestSkipHeights(1)

Expand All @@ -168,6 +173,7 @@ func testDrySwapRouteQuxBarExactIn(t *testing.T) {
"EXACT_IN", // swapType
"gno.land/r/onbloc/qux:gno.land/r/onbloc/baz:500*POOL*gno.land/r/onbloc/baz:gno.land/r/onbloc/bar:500,gno.land/r/onbloc/qux:gno.land/r/onbloc/baz:500*POOL*gno.land/r/onbloc/baz:gno.land/r/onbloc/bar:500", // strRouteArr
"30,70", // quoteArr
"1",
)

uassert.Equal(t, dryResult, "135")
Expand All @@ -179,12 +185,13 @@ func testSwapRouteQuxBarExactIn(t *testing.T) {
std.TestSetRealm(adminRealm)

amountIn, amountOut := ExactInSwapRoute(
quxPath, // inputToken
barPath, // outputToken
"1000", // amountSpecified
quxPath, // inputToken
barPath, // outputToken
"1000", // amountSpecified
"gno.land/r/onbloc/qux:gno.land/r/onbloc/baz:500*POOL*gno.land/r/onbloc/baz:gno.land/r/onbloc/bar:500,gno.land/r/onbloc/qux:gno.land/r/onbloc/baz:500*POOL*gno.land/r/onbloc/baz:gno.land/r/onbloc/bar:500", // strRouteArr
"30,70", // quoteArr
"1", // tokenAmountLimit
time.Now().Add(time.Hour).Unix(),
)
std.TestSkipHeights(1)

Expand All @@ -209,6 +216,7 @@ func testDrySwapRouteQuxBarExactOut(t *testing.T) {
"EXACT_OUT", // swapType
"gno.land/r/onbloc/qux:gno.land/r/onbloc/baz:500*POOL*gno.land/r/onbloc/baz:gno.land/r/onbloc/bar:500,gno.land/r/onbloc/qux:gno.land/r/onbloc/baz:500*POOL*gno.land/r/onbloc/baz:gno.land/r/onbloc/bar:500", // strRouteArr
"30,70", // quoteArr
"100000",
)

uassert.Equal(t, dryResult, "7351")
Expand All @@ -223,12 +231,13 @@ func testSwapRouteQuxBarExactOut(t *testing.T) {
bar.Approve(a2u(consts.ROUTER_ADDR), 10000)

amountIn, amountOut := ExactOutSwapRoute(
quxPath, // inputToken
barPath, // outputToken
"1000", // amountSpecified
quxPath, // inputToken
barPath, // outputToken
"1000", // amountSpecified
"gno.land/r/onbloc/qux:gno.land/r/onbloc/baz:500*POOL*gno.land/r/onbloc/baz:gno.land/r/onbloc/bar:500,gno.land/r/onbloc/qux:gno.land/r/onbloc/baz:500*POOL*gno.land/r/onbloc/baz:gno.land/r/onbloc/bar:500", // strRouteArr
"30,70", // quoteArr
"99999", // tokenAmountLimit
time.Now().Add(time.Hour).Unix(),
)
std.TestSkipHeights(1)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package router
package tests

import (
"std"
"testing"
"time"

"gno.land/p/demo/json"
"gno.land/p/demo/uassert"
Expand Down Expand Up @@ -59,6 +60,7 @@ func TestSwapRouteWugnotquxExactIn(t *testing.T) {
"gno.land/r/demo/wugnot:gno.land/r/onbloc/qux:500", // strRouteArr
"100", // quoteArr
"1", // tokenAmountLimit
time.Now().Add(time.Hour).Unix(),
)
},
)
Expand Down
16 changes: 9 additions & 7 deletions router/tests/__TEST_router_spec_#1_ExactIn_test.gnoA
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package router
package tests

import (
"std"
"testing"
"time"

"gno.land/p/demo/uassert"

Expand Down Expand Up @@ -71,12 +72,13 @@ func TestExactInputSinglePool(t *testing.T) {
swapFee = uint64(0)

amountIn, amountOut := ExactInSwapRoute(
barPath, // inputToken
bazPath, // outputToken
"3", // amountSpecified
poolPath, // strRouteArr
"100", // quoteArr
"1", // tokenAmountLimit
barPath, // inputToken
bazPath, // outputToken
"3", // amountSpecified
poolPath, // strRouteArr
"100", // quoteArr
"1", // tokenAmountLimit
time.Now().Add(time.Hour).Unix(),
)

uassert.Equal(t, amountIn, "3")
Expand Down
10 changes: 6 additions & 4 deletions router/tests/__TEST_router_spec_#2_ExactIn_test.gnoA
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package router
package tests

import (
"std"
"testing"
"time"

"gno.land/p/demo/uassert"

Expand Down Expand Up @@ -48,12 +49,13 @@ func TestExactInputSinglePool1_to_0(t *testing.T) {
user1Token1Before := foo.BalanceOf(a2u(consts.ADMIN))

amountIn, amountOut := ExactInSwapRoute(
barPath, // inputToken
fooPath, // outputToken
"3", // amountSpecified
barPath, // inputToken
fooPath, // outputToken
"3", // amountSpecified
"gno.land/r/onbloc/foo:gno.land/r/onbloc/bar:3000", // strRouteArr
"100", // quoteArr
"1", // tokenAmountLimit
time.Now().Add(time.Hour).Unix(),
)

uassert.Equal(t, amountIn, "3")
Expand Down
10 changes: 6 additions & 4 deletions router/tests/__TEST_router_spec_#3_ExactIn_test.gnoA
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package router
package tests

import (
"std"
"testing"
"time"

"gno.land/p/demo/uassert"

Expand Down Expand Up @@ -57,12 +58,13 @@ func TestSwapRouteFooBarExactIn(t *testing.T) {
token2Before := foo.BalanceOf(a2u(consts.ADMIN))

amountIn, amountOut := ExactInSwapRoute(
fooPath, // inputToken
barPath, // outputToken
"5", // amountSpecified
fooPath, // inputToken
barPath, // outputToken
"5", // amountSpecified
"gno.land/r/onbloc/foo:gno.land/r/onbloc/baz:3000*POOL*gno.land/r/onbloc/baz:gno.land/r/onbloc/bar:3000", // strRouteArr
"100", // quoteArr
"1", // tokenAmountLimit
time.Now().Add(time.Hour).Unix(),
)

token0After := bar.BalanceOf(a2u(consts.ADMIN))
Expand Down
10 changes: 6 additions & 4 deletions router/tests/__TEST_router_spec_#4_ExactIn_test.gnoA
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package router
package tests

import (
"std"
"testing"
"time"

"gno.land/p/demo/uassert"

Expand Down Expand Up @@ -57,12 +58,13 @@ func TestSwapRouteBarfooExactIn(t *testing.T) {
token2Before := foo.BalanceOf(a2u(consts.ADMIN))

amountIn, amountOut := ExactInSwapRoute(
barPath, // inputToken
fooPath, // outputToken
"5", // amountSpecified
barPath, // inputToken
fooPath, // outputToken
"5", // amountSpecified
"gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:3000*POOL*gno.land/r/onbloc/baz:gno.land/r/onbloc/foo:3000", // strRouteArr
"100", // quoteArr
"1", // tokenAmountLimit
time.Now().Add(time.Hour).Unix(),
)

token0After := bar.BalanceOf(a2u(consts.ADMIN))
Expand Down
13 changes: 8 additions & 5 deletions router/tests/__TEST_router_spec_#5_ExactOut_test.gnoA
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package router
package tests

import (
"std"
"testing"
"time"

"gno.land/p/demo/uassert"

Expand Down Expand Up @@ -48,12 +49,13 @@ func TestSwapRouteBarBazExactOut(t *testing.T) {
token1Before := baz.BalanceOf(a2u(consts.ADMIN))

amountIn, amountOut := ExactOutSwapRoute(
barPath, // inputToken
bazPath, // outputToken
"1", // amountSpecified
barPath, // inputToken
bazPath, // outputToken
"1", // amountSpecified
"gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:3000", // strRouteArr
"100", // quoteArr
"3", // tokenAmountLimit
time.Now().Add(time.Hour).Unix(),
)

token0After := bar.BalanceOf(a2u(consts.ADMIN))
Expand Down Expand Up @@ -89,7 +91,7 @@ func TestSwapRouteWugnotquxExactInDifferentAmountCoinShouldPanic(t *testing.T) {

uassert.PanicsWithMessage(
t,
`[GNOSWAP-ROUTER-005] invalid input || router.gno__SwapRoute() || ugnot sent by user(12345) is not equal to amountSpecified(3)`,
`[GNOSWAP-POOL-008] requested data not found || expected poolPath(gno.land/r/demo/wugnot:gno.land/r/onbloc/qux:3000) to exist`,
func() {
ExactOutSwapRoute(
consts.GNOT, // inputToken
Expand All @@ -98,6 +100,7 @@ func TestSwapRouteWugnotquxExactInDifferentAmountCoinShouldPanic(t *testing.T) {
"gno.land/r/demo/wugnot:gno.land/r/onbloc/qux:3000", // strRouteArr
"100", // quoteArr
"1", // tokenAmountLimit
time.Now().Add(time.Hour).Unix(),
)
},
)
Expand Down
10 changes: 6 additions & 4 deletions router/tests/__TEST_router_spec_#6_ExactOut_test.gnoA
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package router
package tests

import (
"std"
"testing"
"time"

"gno.land/p/demo/uassert"

Expand Down Expand Up @@ -46,12 +47,13 @@ func TestSwapRouteBazBarExactOut(t *testing.T) {
token1Before := baz.BalanceOf(a2u(consts.ADMIN))

amountIn, amountOut := ExactOutSwapRoute(
bazPath, // inputToken
barPath, // outputToken
"1", // amountSpecified
bazPath, // inputToken
barPath, // outputToken
"1", // amountSpecified
"gno.land/r/onbloc/baz:gno.land/r/onbloc/bar:3000", // strRouteArr
"100", // quoteArr
"3", // tokenAmountLimit
time.Now().Add(time.Hour).Unix(),
)

token0After := bar.BalanceOf(a2u(consts.ADMIN))
Expand Down
10 changes: 6 additions & 4 deletions router/tests/__TEST_router_spec_#7_ExactOut_test.gnoA
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package router
package tests

import (
"std"
"testing"
"time"

"gno.land/p/demo/uassert"

Expand Down Expand Up @@ -55,12 +56,13 @@ func TestSwapRouteBarfooExactOut(t *testing.T) {
token2Before := foo.BalanceOf(a2u(consts.ADMIN))

amountIn, amountOut := ExactOutSwapRoute(
barPath, // inputToken
fooPath, // outputToken
"1", // amountSpecified
barPath, // inputToken
fooPath, // outputToken
"1", // amountSpecified
"gno.land/r/onbloc/bar:gno.land/r/onbloc/baz:3000*POOL*gno.land/r/onbloc/baz:gno.land/r/onbloc/foo:3000", // strRouteArr
"100", // quoteArr
"5", // tokenAmountLimit
time.Now().Add(time.Hour).Unix(),
)

token0After := bar.BalanceOf(a2u(consts.ADMIN))
Expand Down
Loading

0 comments on commit 4323657

Please sign in to comment.