Skip to content

Commit

Permalink
test : Add missing test code
Browse files Browse the repository at this point in the history
  • Loading branch information
onlyhyde committed Dec 24, 2024
1 parent 2dcf834 commit 8c6a5ce
Show file tree
Hide file tree
Showing 7 changed files with 908 additions and 70 deletions.
7 changes: 7 additions & 0 deletions position/_helper_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,13 @@ func MintPositionAll(t *testing.T, caller std.Address) {

}

func CreatePoolWithoutFee(t *testing.T) {
std.TestSetRealm(adminRealm)
// set pool create fee to 0 for testing
pl.SetPoolCreationFeeByAdmin(0)
CreatePool(t, barPath, fooPath, fee500, common.TickMathGetSqrtRatioAtTick(0).ToString(), users.Resolve(admin))
}

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

Expand Down
5 changes: 0 additions & 5 deletions position/liquidity_management_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,3 @@ func TestAddLiquidity(t *testing.T) {
})
}
}

func TestSplitOf(t *testing.T) {
// TODO:

}
40 changes: 39 additions & 1 deletion position/native_token_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,45 @@ func TestIsNative(t *testing.T) {
}

func TestIsWrappedToken(t *testing.T) {
// TODO:
tests := []struct {
name string
tokenPath string
expected bool
}{
{
name: "Success - Token is Wrapped WUGNOT",
tokenPath: consts.WRAPPED_WUGNOT,
expected: true,
},
{
name: "Fail - Token is not Wrapped WUGNOT",
tokenPath: "gno.land/r/demo/ugnot",
expected: false,
},
{
name: "Fail - Empty tokenPath",
tokenPath: "",
expected: false,
},
{
name: "Fail - Similar but Different Token Path",
tokenPath: "gno.land/r/demo/Wugnot",
expected: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := isWrappedToken(tt.tokenPath)
if result != tt.expected {
t.Errorf(
"expected %s but got %s",
strconv.FormatBool(tt.expected),
strconv.FormatBool(result),
)
}
})
}
}

func TestSafeWrapNativeToken(t *testing.T) {
Expand Down
21 changes: 0 additions & 21 deletions position/position.gno
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ func Mint(

mintParams := newMintParams(processedInput, mintInput)
tokenId, liquidity, amount0, amount1 := mint(mintParams)

if processedInput.tokenPair.token0IsNative && processedInput.tokenPair.wrappedAmount > amount0.Uint64() {
// unwrap leftover wugnot
err = unwrap(processedInput.tokenPair.wrappedAmount-amount0.Uint64(), caller)
Expand All @@ -231,11 +230,9 @@ func Mint(
panic(newErrorWithDetail(errWrapUnwrap, err.Error()))
}
}

poolSqrtPriceX96 := pl.PoolGetSlot0SqrtPriceX96(processedInput.poolPath)

prevAddr, prevPkgPath := getPrevAsString()

std.Emit(
"Mint",
"prevAddr", prevAddr,
Expand Down Expand Up @@ -1091,24 +1088,6 @@ func Reposition(
position.burned = false
mustUpdatePosition(tokenId, position)

// // WIP
// pl.Burn(
// token0,
// token1,
// fee,
// tickLower,
// tickUpper,
// ZERO_LIQUIDITY_FOR_FEE_COLLECTION,
// )
// currentFeeGrowth, err = getCurrentFeeGrowth(position, token0, token1, fee)
// if err != nil {
// panic(newErrorWithDetail(err, "failed to get current fee growth"))
// }
// tokensOwed0, tokensOwed1 := calculateFees(position, currentFeeGrowth)
// position.feeGrowthInside0LastX128 = new(u256.Uint).Set(currentFeeGrowth.feeGrowthInside0LastX128)
// position.feeGrowthInside1LastX128 = new(u256.Uint).Set(currentFeeGrowth.feeGrowthInside1LastX128)
// mustUpdatePosition(tokenId, position)

poolSqrtPriceX96 := pl.PoolGetSlot0SqrtPriceX96(position.poolKey)
prevAddr, prevPkgPath := getPrevAsString()

Expand Down
Loading

0 comments on commit 8c6a5ce

Please sign in to comment.