From 55e90b5022858a22dcea8f7d05015d44065e2e2d Mon Sep 17 00:00:00 2001 From: Nishim Goyal <115455855+nishim3@users.noreply.github.com> Date: Tue, 19 Mar 2024 04:12:19 +0530 Subject: [PATCH] make PoolTestBase.sol foundry independent --- .../addLiquidity with empty hook.snap | 2 +- .../addLiquidity with native token.snap | 2 +- .forge-snapshots/addLiquidity.snap | 2 +- .forge-snapshots/donate gas with 1 token.snap | 2 +- .../donate gas with 2 tokens.snap | 2 +- .../removeLiquidity with empty hook.snap | 2 +- .../removeLiquidity with native token.snap | 2 +- .forge-snapshots/removeLiquidity.snap | 2 +- .forge-snapshots/simple swap with native.snap | 2 +- .forge-snapshots/simple swap.snap | 2 +- ...p against liquidity with native token.snap | 2 +- .forge-snapshots/swap against liquidity.snap | 2 +- .../swap burn 6909 for input.snap | 2 +- .../swap burn native 6909 for input.snap | 2 +- .../swap mint native output as 6909.snap | 2 +- .../swap mint output as 6909.snap | 2 +- .forge-snapshots/swap with dynamic fee.snap | 2 +- .forge-snapshots/swap with hooks.snap | 2 +- .../update dynamic fee in before swap.snap | 2 +- src/test/PoolClaimsTest.sol | 1 - src/test/PoolDonateTest.sol | 12 ++++----- src/test/PoolModifyLiquidityTest.sol | 3 +-- src/test/PoolSwapTest.sol | 27 +++++++++---------- src/test/PoolTakeTest.sol | 15 +++++------ src/test/PoolTestBase.sol | 6 ++--- 25 files changed, 49 insertions(+), 53 deletions(-) diff --git a/.forge-snapshots/addLiquidity with empty hook.snap b/.forge-snapshots/addLiquidity with empty hook.snap index caf0d7b91..78823d578 100644 --- a/.forge-snapshots/addLiquidity with empty hook.snap +++ b/.forge-snapshots/addLiquidity with empty hook.snap @@ -1 +1 @@ -311367 \ No newline at end of file +311243 \ No newline at end of file diff --git a/.forge-snapshots/addLiquidity with native token.snap b/.forge-snapshots/addLiquidity with native token.snap index 007677cf1..4384742c0 100644 --- a/.forge-snapshots/addLiquidity with native token.snap +++ b/.forge-snapshots/addLiquidity with native token.snap @@ -1 +1 @@ -191546 \ No newline at end of file +191422 \ No newline at end of file diff --git a/.forge-snapshots/addLiquidity.snap b/.forge-snapshots/addLiquidity.snap index faf67d4ed..2d6d2a2e1 100644 --- a/.forge-snapshots/addLiquidity.snap +++ b/.forge-snapshots/addLiquidity.snap @@ -1 +1 @@ -191527 \ No newline at end of file +191403 \ No newline at end of file diff --git a/.forge-snapshots/donate gas with 1 token.snap b/.forge-snapshots/donate gas with 1 token.snap index 2b3ce9fcb..096d7a870 100644 --- a/.forge-snapshots/donate gas with 1 token.snap +++ b/.forge-snapshots/donate gas with 1 token.snap @@ -1 +1 @@ -131501 \ No newline at end of file +131137 \ No newline at end of file diff --git a/.forge-snapshots/donate gas with 2 tokens.snap b/.forge-snapshots/donate gas with 2 tokens.snap index 6b97692bd..55a003e41 100644 --- a/.forge-snapshots/donate gas with 2 tokens.snap +++ b/.forge-snapshots/donate gas with 2 tokens.snap @@ -1 +1 @@ -176358 \ No newline at end of file +175960 \ No newline at end of file diff --git a/.forge-snapshots/removeLiquidity with empty hook.snap b/.forge-snapshots/removeLiquidity with empty hook.snap index 567aaa069..5e6d40424 100644 --- a/.forge-snapshots/removeLiquidity with empty hook.snap +++ b/.forge-snapshots/removeLiquidity with empty hook.snap @@ -1 +1 @@ -98144 \ No newline at end of file +98020 \ No newline at end of file diff --git a/.forge-snapshots/removeLiquidity with native token.snap b/.forge-snapshots/removeLiquidity with native token.snap index 8af1adb3f..757d8894e 100644 --- a/.forge-snapshots/removeLiquidity with native token.snap +++ b/.forge-snapshots/removeLiquidity with native token.snap @@ -1 +1 @@ -199517 \ No newline at end of file +199393 \ No newline at end of file diff --git a/.forge-snapshots/removeLiquidity.snap b/.forge-snapshots/removeLiquidity.snap index 938503ee8..0078e7b7a 100644 --- a/.forge-snapshots/removeLiquidity.snap +++ b/.forge-snapshots/removeLiquidity.snap @@ -1 +1 @@ -195794 \ No newline at end of file +195670 \ No newline at end of file diff --git a/.forge-snapshots/simple swap with native.snap b/.forge-snapshots/simple swap with native.snap index 17807dd0c..c60cc6bde 100644 --- a/.forge-snapshots/simple swap with native.snap +++ b/.forge-snapshots/simple swap with native.snap @@ -1 +1 @@ -186425 \ No newline at end of file +186039 \ No newline at end of file diff --git a/.forge-snapshots/simple swap.snap b/.forge-snapshots/simple swap.snap index d4eaface7..1c82c162a 100644 --- a/.forge-snapshots/simple swap.snap +++ b/.forge-snapshots/simple swap.snap @@ -1 +1 @@ -194965 \ No newline at end of file +194579 \ No newline at end of file diff --git a/.forge-snapshots/swap against liquidity with native token.snap b/.forge-snapshots/swap against liquidity with native token.snap index 9fefc9c73..664591efc 100644 --- a/.forge-snapshots/swap against liquidity with native token.snap +++ b/.forge-snapshots/swap against liquidity with native token.snap @@ -1 +1 @@ -117084 \ No newline at end of file +116698 \ No newline at end of file diff --git a/.forge-snapshots/swap against liquidity.snap b/.forge-snapshots/swap against liquidity.snap index a6a9ecdea..ccdbe7bf7 100644 --- a/.forge-snapshots/swap against liquidity.snap +++ b/.forge-snapshots/swap against liquidity.snap @@ -1 +1 @@ -104551 \ No newline at end of file +104165 \ No newline at end of file diff --git a/.forge-snapshots/swap burn 6909 for input.snap b/.forge-snapshots/swap burn 6909 for input.snap index 9299b9916..257986fcc 100644 --- a/.forge-snapshots/swap burn 6909 for input.snap +++ b/.forge-snapshots/swap burn 6909 for input.snap @@ -1 +1 @@ -124700 \ No newline at end of file +124314 \ No newline at end of file diff --git a/.forge-snapshots/swap burn native 6909 for input.snap b/.forge-snapshots/swap burn native 6909 for input.snap index cae64dd9d..0919ffcf8 100644 --- a/.forge-snapshots/swap burn native 6909 for input.snap +++ b/.forge-snapshots/swap burn native 6909 for input.snap @@ -1 +1 @@ -120653 \ No newline at end of file +120267 \ No newline at end of file diff --git a/.forge-snapshots/swap mint native output as 6909.snap b/.forge-snapshots/swap mint native output as 6909.snap index bdca85fac..889661be8 100644 --- a/.forge-snapshots/swap mint native output as 6909.snap +++ b/.forge-snapshots/swap mint native output as 6909.snap @@ -1 +1 @@ -188983 \ No newline at end of file +188597 \ No newline at end of file diff --git a/.forge-snapshots/swap mint output as 6909.snap b/.forge-snapshots/swap mint output as 6909.snap index 5a70b50cb..c8ad7df14 100644 --- a/.forge-snapshots/swap mint output as 6909.snap +++ b/.forge-snapshots/swap mint output as 6909.snap @@ -1 +1 @@ -205792 \ No newline at end of file +205406 \ No newline at end of file diff --git a/.forge-snapshots/swap with dynamic fee.snap b/.forge-snapshots/swap with dynamic fee.snap index 14a7f184d..c6fb77548 100644 --- a/.forge-snapshots/swap with dynamic fee.snap +++ b/.forge-snapshots/swap with dynamic fee.snap @@ -1 +1 @@ -137856 \ No newline at end of file +137470 \ No newline at end of file diff --git a/.forge-snapshots/swap with hooks.snap b/.forge-snapshots/swap with hooks.snap index 7064547cd..19e726ff9 100644 --- a/.forge-snapshots/swap with hooks.snap +++ b/.forge-snapshots/swap with hooks.snap @@ -1 +1 @@ -104529 \ No newline at end of file +104143 \ No newline at end of file diff --git a/.forge-snapshots/update dynamic fee in before swap.snap b/.forge-snapshots/update dynamic fee in before swap.snap index ea9b6e4ad..19afe1c9c 100644 --- a/.forge-snapshots/update dynamic fee in before swap.snap +++ b/.forge-snapshots/update dynamic fee in before swap.snap @@ -1 +1 @@ -188858 \ No newline at end of file +188472 \ No newline at end of file diff --git a/src/test/PoolClaimsTest.sol b/src/test/PoolClaimsTest.sol index 531541ca4..b5af6b763 100644 --- a/src/test/PoolClaimsTest.sol +++ b/src/test/PoolClaimsTest.sol @@ -7,7 +7,6 @@ import {IPoolManager} from "../interfaces/IPoolManager.sol"; import {PoolKey} from "../types/PoolKey.sol"; import {PoolTestBase} from "./PoolTestBase.sol"; import {SafeCast} from "../libraries/SafeCast.sol"; -import {Test} from "forge-std/Test.sol"; contract PoolClaimsTest is PoolTestBase { using CurrencyLibrary for Currency; diff --git a/src/test/PoolDonateTest.sol b/src/test/PoolDonateTest.sol index 13f76944d..30e6e9c51 100644 --- a/src/test/PoolDonateTest.sol +++ b/src/test/PoolDonateTest.sol @@ -48,18 +48,18 @@ contract PoolDonateTest is PoolTestBase { (,, uint256 reserveBefore1, int256 deltaBefore1) = _fetchBalances(data.key.currency1, data.sender, address(this)); - assertEq(deltaBefore0, 0); - assertEq(deltaBefore1, 0); + require(deltaBefore0 == 0); + require(deltaBefore1 == 0); BalanceDelta delta = manager.donate(data.key, data.amount0, data.amount1, data.hookData); (,, uint256 reserveAfter0, int256 deltaAfter0) = _fetchBalances(data.key.currency0, data.sender, address(this)); (,, uint256 reserveAfter1, int256 deltaAfter1) = _fetchBalances(data.key.currency1, data.sender, address(this)); - assertEq(reserveBefore0, reserveAfter0); - assertEq(reserveBefore1, reserveAfter1); - assertEq(deltaAfter0, -int256(data.amount0)); - assertEq(deltaAfter1, -int256(data.amount1)); + require(reserveBefore0 == reserveAfter0); + require(reserveBefore1 == reserveAfter1); + require(deltaAfter0 == -int256(data.amount0)); + require(deltaAfter1 == -int256(data.amount1)); if (deltaAfter0 < 0) _settle(data.key.currency0, data.sender, int128(deltaAfter0), true); if (deltaAfter1 < 0) _settle(data.key.currency1, data.sender, int128(deltaAfter1), true); diff --git a/src/test/PoolModifyLiquidityTest.sol b/src/test/PoolModifyLiquidityTest.sol index bd57ae592..90d9ba1ca 100644 --- a/src/test/PoolModifyLiquidityTest.sol +++ b/src/test/PoolModifyLiquidityTest.sol @@ -8,10 +8,9 @@ import {PoolKey} from "../types/PoolKey.sol"; import {PoolTestBase} from "./PoolTestBase.sol"; import {IHooks} from "../interfaces/IHooks.sol"; import {Hooks} from "../libraries/Hooks.sol"; -import {Test} from "forge-std/Test.sol"; import {SwapFeeLibrary} from "../libraries/SwapFeeLibrary.sol"; -contract PoolModifyLiquidityTest is Test, PoolTestBase { +contract PoolModifyLiquidityTest is PoolTestBase { using CurrencyLibrary for Currency; using Hooks for IHooks; using SwapFeeLibrary for uint24; diff --git a/src/test/PoolSwapTest.sol b/src/test/PoolSwapTest.sol index b673be883..5c62517a2 100644 --- a/src/test/PoolSwapTest.sol +++ b/src/test/PoolSwapTest.sol @@ -8,11 +8,10 @@ import {PoolKey} from "../types/PoolKey.sol"; import {IHooks} from "../interfaces/IHooks.sol"; import {Hooks} from "../libraries/Hooks.sol"; import {PoolTestBase} from "./PoolTestBase.sol"; -import {Test} from "forge-std/Test.sol"; import {Hooks} from "../libraries/Hooks.sol"; import {IHooks} from "../interfaces/IHooks.sol"; -contract PoolSwapTest is Test, PoolTestBase { +contract PoolSwapTest is PoolTestBase { using CurrencyLibrary for Currency; using Hooks for IHooks; @@ -58,36 +57,36 @@ contract PoolSwapTest is Test, PoolTestBase { (,, uint256 reserveBefore1, int256 deltaBefore1) = _fetchBalances(data.key.currency1, data.sender, address(this)); - assertEq(deltaBefore0, 0); - assertEq(deltaBefore1, 0); + require(deltaBefore0 == 0); + require(deltaBefore1 == 0); BalanceDelta delta = manager.swap(data.key, data.params, data.hookData); (,, uint256 reserveAfter0, int256 deltaAfter0) = _fetchBalances(data.key.currency0, data.sender, address(this)); (,, uint256 reserveAfter1, int256 deltaAfter1) = _fetchBalances(data.key.currency1, data.sender, address(this)); - assertEq(reserveBefore0, reserveAfter0); - assertEq(reserveBefore1, reserveAfter1); + require(reserveBefore0 == reserveAfter0); + require(reserveBefore1 == reserveAfter1); if (data.params.zeroForOne) { if (data.params.amountSpecified < 0) { // exact input, 0 for 1 - assertEq(deltaAfter0, data.params.amountSpecified); - assertGt(deltaAfter1, 0); + require(deltaAfter0 == data.params.amountSpecified); + require(deltaAfter1 > 0); } else { // exact output, 0 for 1 - assertLt(deltaAfter0, 0); - assertEq(deltaAfter1, data.params.amountSpecified); + require(deltaAfter0 < 0); + require(deltaAfter1 == data.params.amountSpecified); } } else { if (data.params.amountSpecified < 0) { // exact input, 1 for 0 - assertEq(deltaAfter1, data.params.amountSpecified); - assertGt(deltaAfter0, 0); + require(deltaAfter1 == data.params.amountSpecified); + require(deltaAfter0 > 0); } else { // exact output, 1 for 0 - assertLt(deltaAfter1, 0); - assertEq(deltaAfter0, data.params.amountSpecified); + require(deltaAfter1 < 0); + require(deltaAfter0 == data.params.amountSpecified); } } diff --git a/src/test/PoolTakeTest.sol b/src/test/PoolTakeTest.sol index b6ad94c57..4abdb869f 100644 --- a/src/test/PoolTakeTest.sol +++ b/src/test/PoolTakeTest.sol @@ -6,9 +6,8 @@ import {IPoolManager} from "../interfaces/IPoolManager.sol"; import {PoolKey} from "../types/PoolKey.sol"; import {PoolTestBase} from "./PoolTestBase.sol"; import {SafeCast} from "../libraries/SafeCast.sol"; -import {Test} from "forge-std/Test.sol"; -contract PoolTakeTest is Test, PoolTestBase { +contract PoolTakeTest is PoolTestBase { using CurrencyLibrary for Currency; using SafeCast for uint256; @@ -39,18 +38,18 @@ contract PoolTakeTest is Test, PoolTestBase { function _testTake(Currency currency, address sender, uint256 amount) internal { (uint256 userBalBefore, uint256 pmBalBefore, uint256 reserveBefore, int256 deltaBefore) = _fetchBalances(currency, sender, address(this)); - assertEq(deltaBefore, 0); + require(deltaBefore == 0); _take(currency, sender, amount.toInt128(), true); (uint256 userBalAfter, uint256 pmBalAfter, uint256 reserveAfter, int256 deltaAfter) = _fetchBalances(currency, sender, address(this)); - assertEq(deltaAfter, -amount.toInt128()); + require(deltaAfter == -amount.toInt128()); - assertEq(userBalAfter - userBalBefore, amount); - assertEq(pmBalBefore - pmBalAfter, amount); - assertEq(reserveBefore - reserveAfter, amount); - assertEq(reserveBefore - reserveAfter, amount); + require(userBalAfter - userBalBefore == amount); + require(pmBalBefore - pmBalAfter == amount); + require(reserveBefore - reserveAfter == amount); + require(reserveBefore - reserveAfter == amount); _settle(currency, sender, -amount.toInt128(), true); } diff --git a/src/test/PoolTestBase.sol b/src/test/PoolTestBase.sol index 53bfa8b66..215a88fd5 100644 --- a/src/test/PoolTestBase.sol +++ b/src/test/PoolTestBase.sol @@ -8,7 +8,7 @@ import {IERC20Minimal} from "../interfaces/external/IERC20Minimal.sol"; import {IUnlockCallback} from "../interfaces/callback/IUnlockCallback.sol"; import {IPoolManager} from "../interfaces/IPoolManager.sol"; -abstract contract PoolTestBase is Test, IUnlockCallback { +abstract contract PoolTestBase is IUnlockCallback { using CurrencyLibrary for Currency; IPoolManager public immutable manager; @@ -18,7 +18,7 @@ abstract contract PoolTestBase is Test, IUnlockCallback { } function _take(Currency currency, address recipient, int128 amount, bool withdrawTokens) internal { - assertGt(amount, 0); + require(amount > 0); if (withdrawTokens) { manager.take(currency, recipient, uint128(amount)); } else { @@ -27,7 +27,7 @@ abstract contract PoolTestBase is Test, IUnlockCallback { } function _settle(Currency currency, address payer, int128 amount, bool settleUsingTransfer) internal { - assertLt(amount, 0); + require(amount < 0); if (settleUsingTransfer) { if (currency.isNative()) { manager.settle{value: uint128(-amount)}(currency);