Skip to content

Commit 2aff909

Browse files
authored
refactor: all of gnoa test code modification (#454)
* refactor: gnoa test code modified * refactor: dryswap missing code update * refactor: router bug fix when exactout swap * refactor: gnoA test code modified * fix : remove to use origcaller function
1 parent f2badf4 commit 2aff909

File tree

64 files changed

+1196
-390
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1196
-390
lines changed

pool/pool_manager.gno

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,6 @@ func CreatePool(
137137
sqrtPriceX96 string,
138138
) {
139139
assertOnlyNotHalted()
140-
assertOnlyRegistered(token0Path)
141-
assertOnlyRegistered(token1Path)
142140

143141
poolInfo := newPoolParams(token0Path, token1Path, fee, sqrtPriceX96)
144142
poolInfo = poolInfo.updateWithWrapping()

position/api.gno

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,14 @@ func ApiGetPositions() string {
7373
// RESPONSE (ARRAY) NODE
7474
responses := json.ArrayNode("", []*json.Node{})
7575
for _, position := range r.Response {
76+
owner, err := gnft.OwnerOf(tokenIdFrom(position.LpTokenId))
77+
if err != nil {
78+
owner = consts.ZERO_ADDRESS
79+
}
7680
positionNode := json.ObjectNode("", map[string]*json.Node{
7781
"lpTokenId": json.NumberNode("lpTokenId", float64(position.LpTokenId)),
7882
"burned": json.BoolNode("burned", position.Burned),
79-
"owner": json.StringNode("owner", gnft.OwnerOf(tokenIdFrom(position.LpTokenId)).String()),
83+
"owner": json.StringNode("owner", owner.String()),
8084
"operator": json.StringNode("operator", position.Operator),
8185
"poolKey": json.StringNode("poolKey", position.PoolKey),
8286
"tickLower": json.NumberNode("tickLower", float64(position.TickLower)),
@@ -135,10 +139,14 @@ func ApiGetPosition(lpTokenId uint64) string {
135139
// RESPONSE (ARRAY) NODE
136140
responses := json.ArrayNode("", []*json.Node{})
137141
for _, position := range r.Response {
142+
owner, err := gnft.OwnerOf(tokenIdFrom(position.LpTokenId))
143+
if err != nil {
144+
owner = consts.ZERO_ADDRESS
145+
}
138146
positionNode := json.ObjectNode("", map[string]*json.Node{
139147
"lpTokenId": json.NumberNode("lpTokenId", float64(position.LpTokenId)),
140148
"burned": json.BoolNode("burned", position.Burned),
141-
"owner": json.StringNode("owner", gnft.OwnerOf(tokenIdFrom(position.LpTokenId)).String()),
149+
"owner": json.StringNode("owner", owner.String()),
142150
"operator": json.StringNode("operator", position.Operator),
143151
"poolKey": json.StringNode("poolKey", position.PoolKey),
144152
"tickLower": json.NumberNode("tickLower", float64(position.TickLower)),
@@ -199,10 +207,14 @@ func ApiGetPositionsByPoolPath(poolPath string) string {
199207
// RESPONSE (ARRAY) NODE
200208
responses := json.ArrayNode("", []*json.Node{})
201209
for _, position := range r.Response {
210+
owner, err := gnft.OwnerOf(tokenIdFrom(position.LpTokenId))
211+
if err != nil {
212+
owner = consts.ZERO_ADDRESS
213+
}
202214
positionNode := json.ObjectNode("", map[string]*json.Node{
203215
"lpTokenId": json.NumberNode("lpTokenId", float64(position.LpTokenId)),
204216
"burned": json.BoolNode("burned", position.Burned),
205-
"owner": json.StringNode("owner", gnft.OwnerOf(tokenIdFrom(position.LpTokenId)).String()),
217+
"owner": json.StringNode("owner", owner.String()),
206218
"operator": json.StringNode("operator", position.Operator),
207219
"poolKey": json.StringNode("poolKey", position.PoolKey),
208220
"tickLower": json.NumberNode("tickLower", float64(position.TickLower)),
@@ -237,7 +249,12 @@ func ApiGetPositionsByAddress(address std.Address) string {
237249
rpcPositions := []RpcPosition{}
238250
for lpTokenId := uint64(1); lpTokenId < nextId; lpTokenId++ {
239251
position := MustGetPosition(lpTokenId)
240-
if !(position.operator == address || gnft.OwnerOf(tokenIdFrom(lpTokenId)) == address) {
252+
tokenOwner, err := gnft.OwnerOf(tokenIdFrom(lpTokenId))
253+
if err != nil {
254+
tokenOwner = consts.ZERO_ADDRESS
255+
}
256+
257+
if !(position.operator == address || tokenOwner == address) {
241258
continue
242259
}
243260

@@ -262,10 +279,14 @@ func ApiGetPositionsByAddress(address std.Address) string {
262279
// RESPONSE (ARRAY) NODE
263280
responses := json.ArrayNode("", []*json.Node{})
264281
for _, position := range r.Response {
282+
owner, err := gnft.OwnerOf(tokenIdFrom(position.LpTokenId))
283+
if err != nil {
284+
owner = consts.ZERO_ADDRESS
285+
}
265286
positionNode := json.ObjectNode("", map[string]*json.Node{
266287
"lpTokenId": json.NumberNode("lpTokenId", float64(position.LpTokenId)),
267288
"burned": json.BoolNode("burned", position.Burned),
268-
"owner": json.StringNode("owner", gnft.OwnerOf(tokenIdFrom(position.LpTokenId)).String()),
289+
"owner": json.StringNode("owner", owner.String()),
269290
"operator": json.StringNode("operator", position.Operator),
270291
"poolKey": json.StringNode("poolKey", position.PoolKey),
271292
"tickLower": json.NumberNode("tickLower", float64(position.TickLower)),
@@ -400,10 +421,15 @@ func rpcMakePosition(lpTokenId uint64) RpcPosition {
400421
unclaimedFee0, unclaimedFee1 = unclaimedFee(lpTokenId)
401422
}
402423

424+
owner, err := gnft.OwnerOf(tokenIdFrom(lpTokenId))
425+
if err != nil {
426+
owner = consts.ZERO_ADDRESS
427+
}
428+
403429
return RpcPosition{
404430
LpTokenId: lpTokenId,
405431
Burned: burned,
406-
Owner: gnft.OwnerOf(tokenIdFrom(lpTokenId)).String(),
432+
Owner: owner.String(),
407433
Operator: position.operator.String(),
408434
PoolKey: position.poolKey,
409435
TickLower: position.tickLower,

position/getter.gno

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,12 @@ func PositionIsInRange(tokenId uint64) bool {
8181
}
8282

8383
func PositionGetPositionOwner(tokenId uint64) std.Address {
84-
return gnft.OwnerOf(tokenIdFrom(tokenId))
84+
owner, err := gnft.OwnerOf(tokenIdFrom(tokenId))
85+
if err != nil {
86+
panic(newErrorWithDetail(
87+
errDataNotFound, err.Error()))
88+
}
89+
return owner
8590
}
8691

8792
func PositionGetPositionNonceStr(tokenId uint64) string {

position/position.gno

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ func mint(params MintParams) (uint64, *u256.Uint, *u256.Uint, *u256.Uint) {
520520
}
521521

522522
tokenId := getNextId()
523-
gnft.Mint(a2u(params.mintTo), tokenIdFrom(tokenId)) // owner, tokenId
523+
gnft.Mint(params.mintTo, tokenIdFrom(tokenId)) // owner, tokenId
524524

525525
pool := pl.GetPoolFromPoolPath(poolKey)
526526
positionKey := computePositionKey(GetOrigPkgAddr(), params.tickLower, params.tickUpper)

position/tests/__TEST_fee_collect_with_two_user_test.gnoA

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package position
1+
package tests
22

33
import (
44
"std"

position/tests/__TEST_position_api_test.gnoA

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package position
1+
package tests
22

33
import (
44
"std"

position/tests/__TEST_position_full_test.gnoA

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package position
1+
package tests
22

33
import (
44
"std"
@@ -70,7 +70,7 @@ func TestDecreaseLiquidity(t *testing.T) {
7070

7171
tokenId, liquidity, fee0, fee1, amount0, amount1, poolPath := DecreaseLiquidity(
7272
uint64(1),
73-
uint64(50),
73+
"50",
7474
"0",
7575
"0",
7676
max_timeout,

position/tests/__TEST_position_full_with_emission_test.gnoA

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package position
1+
package tests
22

33
import (
44
"std"
@@ -115,7 +115,7 @@ func testDecreaseLiquidity(t *testing.T) {
115115

116116
tokenId, liquidity, fee0, fee1, amount0, amount1, poolPath := DecreaseLiquidity(
117117
uint64(1),
118-
uint64(50),
118+
"50",
119119
"0",
120120
"0",
121121
max_timeout,

position/tests/__TEST_position_increase_burned_position_test.gnoA

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package position
1+
package tests
22

33
import (
44
"std"
@@ -60,7 +60,7 @@ func TestIncreaseLiquidity(t *testing.T) {
6060
bar.Approve(a2u(consts.POOL_ADDR), 3678979)
6161
foo.Approve(a2u(consts.POOL_ADDR), 10000000)
6262

63-
pool := getPoolFromLpTokenId(t,uint64(1))
63+
pool := getPoolFromLpTokenId(t, uint64(1))
6464
oldLiquidity := pool.Liquidity()
6565

6666
_, _, m0, m1, _ := IncreaseLiquidity(
@@ -82,18 +82,18 @@ func TestIncreaseLiquidity(t *testing.T) {
8282

8383
func TestDecreaseLiquidity(t *testing.T) {
8484
std.TestSetRealm(adminRealm)
85-
oldLiquidity := getPoolFromLpTokenId(t,uint64(1)).Liquidity()
85+
oldLiquidity := getPoolFromLpTokenId(t, uint64(1)).Liquidity()
8686

8787
DecreaseLiquidity(
8888
uint64(1), // tokenId
89-
50, // liquidityRatio
89+
"191222635", // liquidity
9090
"0", // amount0Min
9191
"0", // amount1Min
9292
max_timeout, // deadline
9393
false, // unwrapResult
9494
)
9595

96-
newLiquidity := getPoolFromLpTokenId(t,uint64(1)).Liquidity()
96+
newLiquidity := getPoolFromLpTokenId(t, uint64(1)).Liquidity()
9797
uassert.Equal(t, true, newLiquidity.Lt(oldLiquidity))
9898

9999
// check fee left
@@ -112,8 +112,8 @@ func TestDecreaseLiquidityToBurnPosition(t *testing.T) {
112112

113113
// burn it
114114
DecreaseLiquidity(
115-
uint64(1), // tokenId
116-
100, // liquidityRatio
115+
uint64(1), // tokenId
116+
"191222635",
117117
"0", // amount0Min
118118
"0", // amount1Min
119119
max_timeout, // deadline
@@ -129,7 +129,7 @@ func TestIncreaseLiquidityBurnedPosition(t *testing.T) {
129129
bar.Approve(a2u(consts.POOL_ADDR), consts.UINT64_MAX)
130130
foo.Approve(a2u(consts.POOL_ADDR), consts.UINT64_MAX)
131131

132-
pool := getPoolFromLpTokenId(t,uint64(1))
132+
pool := getPoolFromLpTokenId(t, uint64(1))
133133
oldLiquidity := pool.Liquidity()
134134

135135
position := MustGetPosition(uint64(1))

position/tests/__TEST_position_increase_decrease_test.gnoA

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package position
1+
package tests
22

33
import (
44
"std"
@@ -52,7 +52,7 @@ func TestIncreaseLiquidity(t *testing.T) {
5252
bar.Approve(a2u(consts.POOL_ADDR), 3678979)
5353
foo.Approve(a2u(consts.POOL_ADDR), 10000000)
5454

55-
pool := getPoolFromLpTokenId(t,uint64(1))
55+
pool := getPoolFromLpTokenId(t, uint64(1))
5656
oldLiquidity := pool.Liquidity()
5757

5858
_, _, m0, m1, _ := IncreaseLiquidity(
@@ -158,18 +158,18 @@ func TestSwap2(t *testing.T) {
158158

159159
func TestDecreaseLiquidity(t *testing.T) {
160160
std.TestSetRealm(adminRealm)
161-
oldLiquidity := getPoolFromLpTokenId(t,uint64(1)).Liquidity()
161+
oldLiquidity := getPoolFromLpTokenId(t, uint64(1)).Liquidity()
162162

163163
DecreaseLiquidity(
164164
uint64(1), // tokenId
165-
50, // liquidityRatio
165+
"191222635", // liquidity
166166
"0", // amount0Min
167167
"0", // amount1Min
168168
max_timeout, // deadline
169169
false, // unwrapResult
170170
)
171171

172-
newLiquidity := getPoolFromLpTokenId(t,uint64(1)).Liquidity()
172+
newLiquidity := getPoolFromLpTokenId(t, uint64(1)).Liquidity()
173173
uassert.Equal(t, true, newLiquidity.Lt(oldLiquidity))
174174

175175
// check fee left
@@ -182,18 +182,18 @@ func TestDecreaseLiquidity(t *testing.T) {
182182

183183
func TestDecreaseLiquidityAllThenAgainShouldPanic(t *testing.T) {
184184
std.TestSetRealm(adminRealm)
185-
oldLiquidity := getPoolFromLpTokenId(t,uint64(1)).Liquidity()
185+
oldLiquidity := getPoolFromLpTokenId(t, uint64(1)).Liquidity()
186186

187187
DecreaseLiquidity(
188188
uint64(1), // tokenId
189-
100, // liquidityRatio
189+
"191222635", // liquidity
190190
"0", // amount0Min
191191
"0", // amount1Min
192192
max_timeout, // deadline
193193
false, // unwrapResult
194194
)
195195

196-
newLiquidity := getPoolFromLpTokenId(t,uint64(1)).Liquidity()
196+
newLiquidity := getPoolFromLpTokenId(t, uint64(1)).Liquidity()
197197
uassert.Equal(t, true, newLiquidity.Lt(oldLiquidity))
198198
uassert.Equal(t, newLiquidity.ToString(), "0")
199199

@@ -204,7 +204,7 @@ func TestDecreaseLiquidityAllThenAgainShouldPanic(t *testing.T) {
204204
func() {
205205
DecreaseLiquidity(
206206
uint64(1), // tokenId
207-
100, // liquidityRatio
207+
"100", // liquidity
208208
"0", // amount0Min
209209
"0", // amount1Min
210210
max_timeout, // deadline

position/tests/__TEST_position_mint_gnot_grc20_in-range_out-range_test.gnoA

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package position
1+
package tests
22

33
import (
44
"std"

position/tests/__TEST_position_mint_swap_burn_left_test.gnoA

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package position
1+
package tests
22

33
import (
44
"std"
@@ -235,7 +235,7 @@ func TestDecreaseAllPos01(t *testing.T) {
235235
std.TestSetRealm(adminRealm)
236236
tokenId, liquidity, fee0, fee1, amount0, amount1, poolPath := DecreaseLiquidity(
237237
uint64(1), // tokenId
238-
100, // liquidityRatio
238+
"318704392", // liquidity
239239
"0", // amount0Min
240240
"0", // amount1Min
241241
max_timeout, // deadline
@@ -263,7 +263,7 @@ func TestDecreaseAllPos02(t *testing.T) {
263263
std.TestSetRealm(adminRealm)
264264
tokenId, liquidity, fee0, fee1, amount0, amount1, poolPath := DecreaseLiquidity(
265265
uint64(2), // tokenId
266-
100, // liquidityRatio
266+
"124373229", // liquidityRatio
267267
"0", // amount0Min
268268
"0", // amount1Min
269269
max_timeout, // deadline

position/tests/__TEST_position_native_increase_decrease_test.gnoA

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package position
1+
package tests
22

33
import (
44
"std"
@@ -157,18 +157,18 @@ func testDecreaseLiquidityWrapped(t *testing.T) {
157157

158158
_, _, _, _, a0, a1, _ := DecreaseLiquidity( // tokenId, liquidity, fee0, fee1, amount0, amount1, poolPath
159159
uint64(1), // tokenId
160-
20, // liquidityRatio
160+
"19122263", // liquidityRatio
161161
"0", // amount0Min
162162
"0", // amount1Min
163163
max_timeout, // deadline
164164
false, // unwrapResult
165165
)
166166

167167
userWugnotBalance = wugnot.BalanceOf(admin) // wrapped result, so wunogt increased
168-
uassert.Equal(t, userWugnotBalance, uint64(11999999))
168+
uassert.Equal(t, uint64(2999999), userWugnotBalance)
169169

170170
userUgnotBalance = ugnotBalanceOf(t, adminAddr) // wrapped result, so ugnot didn't change
171-
uassert.Equal(t, userUgnotBalance, uint64(10))
171+
uassert.Equal(t, uint64(10), userUgnotBalance)
172172

173173
newLiquidity := getPoolFromLpTokenId(t, uint64(1)).Liquidity()
174174
uassert.Equal(t, true, newLiquidity.Lt(oldLiquidity))
@@ -187,6 +187,7 @@ func testDecreaseLiquidityUnwrapped(t *testing.T) {
187187
std.TestSetRealm(adminRealm)
188188

189189
oldLiquidity := getPoolFromLpTokenId(t, uint64(1)).Liquidity()
190+
println("oldLiquidity ", oldLiquidity.ToString())
190191

191192
userWugnotBalance := wugnot.BalanceOf(admin)
192193
uassert.Equal(t, userWugnotBalance, uint64(11999999))
@@ -196,7 +197,7 @@ func testDecreaseLiquidityUnwrapped(t *testing.T) {
196197

197198
_, _, _, _, a0, a1, _ := DecreaseLiquidity( // tokenId, liquidity, fee0, fee1, amount0, amount1, poolPath
198199
uint64(1), // tokenId
199-
50, // liquidityRatio
200+
"50", // liquidityRatio
200201
"0", // amount0Min
201202
"0", // amount1Min
202203
max_timeout, // deadline

position/tests/__TEST_position_native_mint_swap_burn_test.gnoA

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package position
1+
package tests
22

33
import (
44
"std"
@@ -171,7 +171,7 @@ func testDecreaseWithNoUnwrap(t *testing.T) {
171171
std.TestSetRealm(adminRealm)
172172
DecreaseLiquidity(
173173
uint64(1),
174-
uint64(10),
174+
"15164540",
175175
"0",
176176
"0",
177177
int64(9999999999),
@@ -198,7 +198,7 @@ func testDecreaseWithUnwrap(t *testing.T) {
198198
std.TestSetRealm(adminRealm)
199199
DecreaseLiquidity(
200200
uint64(1),
201-
uint64(10),
201+
"13648086",
202202
"0",
203203
"0",
204204
int64(9999999999),

0 commit comments

Comments
 (0)