Skip to content

Commit

Permalink
remove function prefix from error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
notJoon committed Dec 18, 2024
1 parent 2e26e0b commit 609d58a
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 32 deletions.
6 changes: 3 additions & 3 deletions pool/position.gno
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ func positionGetKey(
if !owner.IsValid() {
panic(addDetailToError(
errInvalidAddress,
ufmt.Sprintf("position.gno__positionGetKey() || invalid owner address %s", owner.String()),
ufmt.Sprintf("invalid owner address %s", owner.String()),
))
}

if tickLower > tickUpper {
panic(addDetailToError(
errInvalidTickRange,
ufmt.Sprintf("position.gno__positionGetKey() || tickLower(%d) is greater than tickUpper(%d)", tickLower, tickUpper),
ufmt.Sprintf("tickLower(%d) is greater than tickUpper(%d)", tickLower, tickUpper),
))
}

Expand Down Expand Up @@ -74,7 +74,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
10 changes: 5 additions & 5 deletions pool/position_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ func TestPositionGetKey(t *testing.T) {
panicMsg string
expectedKey string
}{
{invalidAddr, 100, 200, true, `[GNOSWAP-POOL-023] invalid address || position.gno__positionGetKey() || invalid owner address invalidAddr`, ""}, // invalid address
{validAddr, 200, 100, true, `[GNOSWAP-POOL-024] tickLower is greater than tickUpper || position.gno__positionGetKey() || tickLower(200) is greater than tickUpper(100)`, ""}, // tickLower > tickUpper
{validAddr, -100, -200, true, `[GNOSWAP-POOL-024] tickLower is greater than tickUpper || position.gno__positionGetKey() || tickLower(-100) is greater than tickUpper(-200)`, ""}, // tickLower > tickUpper
{invalidAddr, 100, 200, true, `[GNOSWAP-POOL-023] invalid address || invalid owner address invalidAddr`, ""}, // invalid address
{validAddr, 200, 100, true, `[GNOSWAP-POOL-024] tickLower is greater than tickUpper || tickLower(200) is greater than tickUpper(100)`, ""}, // tickLower > tickUpper
{validAddr, -100, -200, true, `[GNOSWAP-POOL-024] tickLower is greater than tickUpper || tickLower(-100) is greater than tickUpper(-200)`, ""}, // tickLower > tickUpper
{validAddr, 100, 100, false, "", "ZzF3ZXNrYzZ0eWc5anhndWpsdGEwNDdoNmx0YTA0N2g2bGRqbHVkdV9fMTAwX18xMDA="}, // tickLower == tickUpper
{validAddr, 100, 200, false, "", "ZzF3ZXNrYzZ0eWc5anhndWpsdGEwNDdoNmx0YTA0N2g2bGRqbHVkdV9fMTAwX18yMDA="}, // tickLower < tickUpper
}
Expand Down Expand Up @@ -70,7 +70,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 @@ -104,7 +104,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
2 changes: 1 addition & 1 deletion pool/tests/__TEST_pool_spec_#6_test.gnoA
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestPokeIsNotAllowedOnUninitilaizedPosition(t *testing.T) {
std.TestSetRealm(posRealm)
uassert.PanicsWithMessage(
t,
`[GNOSWAP-POOL-010] zero liquidity || position.gno__positionUpdate() || both liquidityDelta and (self)liquidity are zero`,
`[GNOSWAP-POOL-010] zero liquidity || both liquidityDelta and (self)liquidity are zero`,
func() {
Burn(
barPath,
Expand Down
39 changes: 20 additions & 19 deletions position/position.gno
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
)

var (
// TODO: use avl
positions map[uint64]Position = make(map[uint64]Position) // tokenId -> Position
nextId uint64 = 1 // lp token id
)
Expand Down Expand Up @@ -51,7 +52,7 @@ func Mint(
if !(isUserCalled || isStakerCalled) {
panic(addDetailToError(
errNoPermission,
ufmt.Sprintf("position.gno__Mint() || only user or staker can call isUserCalled(%t) || isStakerCalled(%t), but called from %s", isUserCalled, isStakerCalled, prev.Addr().String()),
ufmt.Sprintf("only user or staker can call isUserCalled(%t) || isStakerCalled(%t), but called from %s", isUserCalled, isStakerCalled, prev.Addr().String()),
))
}
}
Expand Down Expand Up @@ -150,7 +151,7 @@ func handleNativeToken(token0IsNative, token1IsNative bool, caller std.Address)
if (newUserWugnotBalance - oldUserWugnotBalance) != ugnotSent {
panic(addDetailToError(
errWrapUnwrap,
ufmt.Sprintf("position.gno__Mint() || ugnot sent(%d) != wugnot received(%d)", ugnotSent, newUserWugnotBalance-oldUserWugnotBalance),
ufmt.Sprintf("ugnot sent(%d) != wugnot received(%d)", ugnotSent, newUserWugnotBalance-oldUserWugnotBalance),
))
}
}
Expand Down Expand Up @@ -287,7 +288,7 @@ func increaseLiquidity(params IncreaseLiquidityParams) (uint64, *u256.Uint, *u25
if !exists(params.tokenId) {
panic(addDetailToError(
errDataNotFound,
ufmt.Sprintf("position.gno__increaseLiquidity() || tokenId(%d) doesn't exist", params.tokenId),
ufmt.Sprintf("tokenId(%d) doesn't exist", params.tokenId),
))
}

Expand All @@ -298,7 +299,7 @@ func increaseLiquidity(params IncreaseLiquidityParams) (uint64, *u256.Uint, *u25
if owner != caller {
panic(addDetailToError(
errNoPermission,
ufmt.Sprintf("position.gno__increaseLiquidity() || only owner(%s) can increase liquidity for tokenId(%d), but called from %s", owner, params.tokenId, caller),
ufmt.Sprintf("only owner(%s) can increase liquidity for tokenId(%d), but called from %s", owner, params.tokenId, caller),
))
}

Expand Down Expand Up @@ -367,7 +368,7 @@ func DecreaseLiquidity(
if !isNormalRange {
panic(addDetailToError(
errOutOfRange,
ufmt.Sprintf("position.gno__decreaseLiquidity() || liquidityRatio(%d) should be in range 1 ~ 100", liquidityRatio),
ufmt.Sprintf("liquidityRatio(%d) should be in range 1 ~ 100", liquidityRatio),
))
}

Expand Down Expand Up @@ -428,7 +429,7 @@ func decreaseLiquidity(params DecreaseLiquidityParams) (uint64, *u256.Uint, *u25
if positionLiquidity.IsZero() {
panic(addDetailToError(
errZeroLiquidity,
ufmt.Sprintf("position.gno__decreaseLiquidity() || position(tokenId:%d) has 0 liquidity", params.tokenId),
ufmt.Sprintf("position(tokenId:%d) has 0 liquidity", params.tokenId),
))
}

Expand Down Expand Up @@ -531,7 +532,7 @@ func Reposition(
if !exists(tokenId) {
panic(addDetailToError(
errDataNotFound,
ufmt.Sprintf("position.gno__Reposition() || tokenId(%d) doesn't exist", tokenId),
ufmt.Sprintf("tokenId(%d) doesn't exist", tokenId),
))
}

Expand All @@ -542,7 +543,7 @@ func Reposition(
if owner != caller {
panic(addDetailToError(
errNoPermission,
ufmt.Sprintf("position.gno__Reposition() || only owner(%s) can reposition for tokenId(%d), but called from %s", owner, tokenId, caller),
ufmt.Sprintf("only owner(%s) can reposition for tokenId(%d), but called from %s", owner, tokenId, caller),
))
}

Expand All @@ -554,7 +555,7 @@ func Reposition(
if !(position.isClear()) {
panic(addDetailToError(
errNotClear,
ufmt.Sprintf("position.gno__Reposition() || position(%d) isn't clear(liquidity:%s, tokensOwed0:%s, tokensOwed1:%s)", tokenId, position.liquidity.ToString(), position.tokensOwed0.ToString(), position.tokensOwed1.ToString()),
ufmt.Sprintf("position(%d) isn't clear(liquidity:%s, tokensOwed0:%s, tokensOwed1:%s)", tokenId, position.liquidity.ToString(), position.tokensOwed0.ToString(), position.tokensOwed1.ToString()),
))
}

Expand Down Expand Up @@ -647,7 +648,7 @@ func CollectFee(tokenId uint64, unwrapResult bool) (uint64, string, string, stri
if !exists(tokenId) {
panic(addDetailToError(
errDataNotFound,
ufmt.Sprintf("position.gno__CollectFee() || tokenId(%d) doesn't exist", tokenId),
ufmt.Sprintf("tokenId(%d) doesn't exist", tokenId),
))
}

Expand All @@ -659,7 +660,7 @@ func CollectFee(tokenId uint64, unwrapResult bool) (uint64, string, string, stri
if !exist {
panic(addDetailToError(
errDataNotFound,
ufmt.Sprintf("position.gno__CollectFee() || position(%d) doesn't exist", tokenId),
ufmt.Sprintf("position(%d) doesn't exist", tokenId),
))
}

Expand Down Expand Up @@ -781,7 +782,7 @@ func burnNFT(tokenId uint64) {
if !(position.isClear()) {
panic(addDetailToError(
errNotClear,
ufmt.Sprintf("position.gno__burnNFT() || position(%d) isn't clear(liquidity:%s, tokensOwed0:%s, tokensOwed1:%s)", tokenId, position.liquidity.ToString(), position.tokensOwed0.ToString(), position.tokensOwed1.ToString()),
ufmt.Sprintf("position(%d) isn't clear(liquidity:%s, tokensOwed0:%s, tokensOwed1:%s)", tokenId, position.liquidity.ToString(), position.tokensOwed0.ToString(), position.tokensOwed1.ToString()),
))
}
delete(positions, tokenId)
Expand All @@ -793,7 +794,7 @@ func burnPosition(tokenId uint64) {
if !(position.isClear()) {
panic(addDetailToError(
errNotClear,
ufmt.Sprintf("position.gno__burnPosition() || position(%d) isn't clear(liquidity:%s, tokensOwed0:%s, tokensOwed1:%s)", tokenId, position.liquidity.ToString(), position.tokensOwed0.ToString(), position.tokensOwed1.ToString()),
ufmt.Sprintf("position(%d) isn't clear(liquidity:%s, tokensOwed0:%s, tokensOwed1:%s)", tokenId, position.liquidity.ToString(), position.tokensOwed0.ToString(), position.tokensOwed1.ToString()),
))
}

Expand All @@ -805,7 +806,7 @@ func isAuthorizedForToken(tokenId uint64) {
if !(isOwnerOrOperator(std.PrevRealm().Addr(), tokenId)) {
panic(addDetailToError(
errNoPermission,
ufmt.Sprintf("position.gno__isAuthorizedForToken() || caller(%s) is not approved or owner of tokenId(%d)", std.PrevRealm().Addr(), tokenId),
ufmt.Sprintf("caller(%s) is not approved or owner of tokenId(%d)", std.PrevRealm().Addr(), tokenId),
))
}
}
Expand All @@ -814,7 +815,7 @@ func verifyTokenIdAndOwnership(tokenId uint64) {
if !exists(tokenId) {
panic(addDetailToError(
errDataNotFound,
ufmt.Sprintf("position.gno__verifyTokenIdAndOwnership() || tokenId(%d) doesn't exist", tokenId),
ufmt.Sprintf("tokenId(%d) doesn't exist", tokenId),
))
}

Expand All @@ -823,7 +824,7 @@ func verifyTokenIdAndOwnership(tokenId uint64) {
if owner != caller {
panic(addDetailToError(
errNoPermission,
ufmt.Sprintf("position.gno__verifyTokenIdAndOwnership() || only owner(%s) can decrease liquidity(tokenId:%d), but called from %s", owner, tokenId, caller),
ufmt.Sprintf("only owner(%s) can decrease liquidity(tokenId:%d), but called from %s", owner, tokenId, caller),
))
}
}
Expand All @@ -841,7 +842,7 @@ func verifyBurnedAmounts(burnedAmount0, burnedAmount1, amount0Min, amount1Min *u
if !(burnedAmount0.Gte(amount0Min) && burnedAmount1.Gte(amount1Min)) {
panic(addDetailToError(
errSlippage,
ufmt.Sprintf("position.gno__verifyBurnedAmounts() || burnedAmount0(%s) >= amount0Min(%s) && burnedAmount1(%s) >= amount1Min(%s)", burnedAmount0.ToString(), amount0Min.ToString(), burnedAmount1.ToString(), amount1Min.ToString()),
ufmt.Sprintf("burnedAmount0(%s) >= amount0Min(%s) && burnedAmount1(%s) >= amount1Min(%s)", burnedAmount0.ToString(), amount0Min.ToString(), burnedAmount1.ToString(), amount1Min.ToString()),
))
}
}
Expand All @@ -859,15 +860,15 @@ func SetPositionOperator(tokenId uint64, operator std.Address) {
if caller != consts.STAKER_PATH {
panic(addDetailToError(
errNoPermission,
ufmt.Sprintf("position.gno__SetPositionOperator() || caller(%s) is not staker", caller),
ufmt.Sprintf("caller(%s) is not staker", caller),
))
}

position, exist := positions[tokenId]
if !exist {
panic(addDetailToError(
errDataNotFound,
ufmt.Sprintf("position.gno__SetPositionOperator() || position(%d) doesn't exist", tokenId),
ufmt.Sprintf("position(%d) doesn't exist", tokenId),
))
}

Expand Down
2 changes: 1 addition & 1 deletion position/tests/__TEST_position_increase_decrease_test.gnoA
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func TestDecreaseLiquidityAllThenAgainShouldPanic(t *testing.T) {
// decreasing position(with 0 liquidity) should panic
uassert.PanicsWithMessage(
t,
`[GNOSWAP-POOL-010] zero liquidity || position.gno__positionUpdate() || both liquidityDelta and (self)liquidity are zero`,
`[GNOSWAP-POOL-010] zero liquidity || both liquidityDelta and (self)liquidity are zero`,
func() {
DecreaseLiquidity(
uint64(1), // tokenId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func TestRepositionNotOwner(t *testing.T) {
std.TestSetRealm(std.NewUserRealm(test1))
uassert.PanicsWithMessage(
t,
`[GNOSWAP-POSITION-001] caller has no permission || position.gno__Reposition() || only owner(g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d) can reposition for tokenId(1), but called from g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5`,
`[GNOSWAP-POSITION-001] caller has no permission || only owner(g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d) can reposition for tokenId(1), but called from g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5`,
func() {
Reposition(uint64(1), -1000, 1000, "500", "500", "0", "0")
})
Expand All @@ -236,7 +236,7 @@ func TestRepositionOwnerButNowBurned(t *testing.T) {
std.TestSetRealm(adminRealm)
uassert.PanicsWithMessage(
t,
`[GNOSWAP-POSITION-009] position is not clear || position.gno__Reposition() || position(2) isn't clear(liquidity:341464938, tokensOwed0:0, tokensOwed1:0)`,
`[GNOSWAP-POSITION-009] position is not clear || position(2) isn't clear(liquidity:341464938, tokensOwed0:0, tokensOwed1:0)`,
func() {
Reposition(uint64(2), -1000, 1000, "500", "500", "0", "0")
})
Expand Down
2 changes: 1 addition & 1 deletion position/wrap_unwrap.gno
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func wrap(ugnotAmount uint64, to std.Address) {
if ugnotAmount < consts.UGNOT_MIN_DEPOSIT_TO_WRAP {
panic(addDetailToError(
errWugnotMinimum,
ufmt.Sprintf("wrap.gno__wrap() || amount(%d) < minimum(%d)", ugnotAmount, consts.UGNOT_MIN_DEPOSIT_TO_WRAP),
ufmt.Sprintf("amount(%d) < minimum(%d)", ugnotAmount, consts.UGNOT_MIN_DEPOSIT_TO_WRAP),
))
}

Expand Down

0 comments on commit 609d58a

Please sign in to comment.