Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move gas snapshots to snapLastCall and forge test --isolate #131

Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeAddInitialLiquidity.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
311181
351599
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeAddLiquidity.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
122990
160908
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeFirstSwap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
80220
140744
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeInitialize.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1015181
1032313
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeRemoveLiquidity.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
110566
145773
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeRemoveLiquidityAndRebalance.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
240044
281063
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeSecondSwap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
45930
114959
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeSwap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
79351
141889
2 changes: 1 addition & 1 deletion .forge-snapshots/OracleGrow10Slots.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
232960
249167
2 changes: 1 addition & 1 deletion .forge-snapshots/OracleGrow10SlotsCardinalityGreater.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
223649
249167
2 changes: 1 addition & 1 deletion .forge-snapshots/OracleGrow1Slot.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
32845
49052
2 changes: 1 addition & 1 deletion .forge-snapshots/OracleGrow1SlotCardinalityGreater.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
23545
49052
2 changes: 1 addition & 1 deletion .forge-snapshots/OracleInitialize.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
51310
67610
2 changes: 1 addition & 1 deletion .forge-snapshots/TWAMMSubmitOrder.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
122336
155811
24 changes: 8 additions & 16 deletions test/FullRange.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,8 @@ contract TestFullRange is Test, Deployers, GasSnapshot {
vm.expectEmit(true, true, true, true);
emit Initialize(id, testKey.currency0, testKey.currency1, testKey.fee, testKey.tickSpacing, testKey.hooks);

snapStart("FullRangeInitialize");
manager.initialize(testKey, SQRT_PRICE_1_1, ZERO_BYTES);
snapEnd();
snapLastCall("FullRangeInitialize");

(, address liquidityToken) = fullRange.poolInfo(id);

Expand All @@ -154,9 +153,8 @@ contract TestFullRange is Test, Deployers, GasSnapshot {
key.currency0, key.currency1, 3000, 10 ether, 10 ether, 9 ether, 9 ether, address(this), MAX_DEADLINE
);

snapStart("FullRangeAddInitialLiquidity");
fullRange.addLiquidity(addLiquidityParams);
snapEnd();
snapLastCall("FullRangeAddInitialLiquidity");

(bool hasAccruedFees, address liquidityToken) = fullRange.poolInfo(id);
uint256 liquidityTokenBal = UniswapV4ERC20(liquidityToken).balanceOf(address(this));
Expand Down Expand Up @@ -220,9 +218,8 @@ contract TestFullRange is Test, Deployers, GasSnapshot {
MAX_DEADLINE
);

snapStart("FullRangeAddLiquidity");
fullRange.addLiquidity(addLiquidityParams);
snapEnd();
snapLastCall("FullRangeAddLiquidity");

(bool hasAccruedFees,) = fullRange.poolInfo(idWithLiq);
uint256 liquidityTokenBal = UniswapV4ERC20(liquidityToken).balanceOf(address(this));
Expand Down Expand Up @@ -275,9 +272,8 @@ contract TestFullRange is Test, Deployers, GasSnapshot {
HookEnabledSwapRouter.TestSettings memory settings =
HookEnabledSwapRouter.TestSettings({takeClaims: false, settleUsingBurn: false});

snapStart("FullRangeSwap");
router.swap(key, params, settings, ZERO_BYTES);
snapEnd();
snapLastCall("FullRangeSwap");

(bool hasAccruedFees,) = fullRange.poolInfo(id);

Expand Down Expand Up @@ -338,16 +334,14 @@ contract TestFullRange is Test, Deployers, GasSnapshot {
HookEnabledSwapRouter.TestSettings memory settings =
HookEnabledSwapRouter.TestSettings({takeClaims: false, settleUsingBurn: false});

snapStart("FullRangeFirstSwap");
router.swap(testKey, params, settings, ZERO_BYTES);
snapEnd();
snapLastCall("FullRangeFirstSwap");

(bool hasAccruedFees,) = fullRange.poolInfo(id);
assertEq(hasAccruedFees, true);

snapStart("FullRangeSecondSwap");
router.swap(testKey, params, settings, ZERO_BYTES);
snapEnd();
snapLastCall("FullRangeSecondSwap");

(hasAccruedFees,) = fullRange.poolInfo(id);
assertEq(hasAccruedFees, true);
Expand Down Expand Up @@ -395,9 +389,8 @@ contract TestFullRange is Test, Deployers, GasSnapshot {
FullRange.RemoveLiquidityParams memory removeLiquidityParams =
FullRange.RemoveLiquidityParams(keyWithLiq.currency0, keyWithLiq.currency1, 3000, 1 ether, MAX_DEADLINE);

snapStart("FullRangeRemoveLiquidity");
fullRange.removeLiquidity(removeLiquidityParams);
snapEnd();
snapLastCall("FullRangeRemoveLiquidity");

(bool hasAccruedFees,) = fullRange.poolInfo(idWithLiq);
uint256 liquidityTokenBal = UniswapV4ERC20(liquidityToken).balanceOf(address(this));
Expand Down Expand Up @@ -564,9 +557,8 @@ contract TestFullRange is Test, Deployers, GasSnapshot {
FullRange.RemoveLiquidityParams memory removeLiquidityParams =
FullRange.RemoveLiquidityParams(keyWithLiq.currency0, keyWithLiq.currency1, 3000, 5 ether, MAX_DEADLINE);

snapStart("FullRangeRemoveLiquidityAndRebalance");
fullRange.removeLiquidity(removeLiquidityParams);
snapEnd();
snapLastCall("FullRangeRemoveLiquidityAndRebalance");

(bool hasAccruedFees,) = fullRange.poolInfo(idWithLiq);
assertEq(hasAccruedFees, false);
Expand Down
15 changes: 5 additions & 10 deletions test/Oracle.t.sol
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at the branch locally, theres still some snapEnd(); calls in this file -- any reason why we arent changing those?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i noticed it as a pattern in v4-core where single tests would still use snapEnd
i wasn't sure, but is there a reason for that?

Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ contract TestOracle is Test, GasSnapshot {
}

function testInitialize() public {
snapStart("OracleInitialize");
oracle.initialize(OracleImplementation.InitializeParams({time: 1, tick: 1, liquidity: 1}));
snapEnd();
snapLastCall("OracleInitialize");

assertEq(oracle.index(), 0);
assertEq(oracle.cardinality(), 1);
Expand Down Expand Up @@ -90,29 +89,25 @@ contract TestOracle is Test, GasSnapshot {
}

function testGas1Slot() public {
snapStart("OracleGrow1Slot");
initializedOracle.grow(2);
snapEnd();
snapLastCall("OracleGrow1Slot");
}

function testGas10Slots() public {
snapStart("OracleGrow10Slots");
initializedOracle.grow(11);
snapEnd();
snapLastCall("OracleGrow10Slots");
}

function testGas1SlotCardinalityGreater() public {
initializedOracle.grow(2);
snapStart("OracleGrow1SlotCardinalityGreater");
initializedOracle.grow(3);
snapEnd();
snapLastCall("OracleGrow1SlotCardinalityGreater");
}

function testGas10SlotCardinalityGreater() public {
initializedOracle.grow(2);
snapStart("OracleGrow10SlotsCardinalityGreater");
initializedOracle.grow(12);
snapEnd();
snapLastCall("OracleGrow10SlotsCardinalityGreater");
}

function testWrite() public {
Expand Down
3 changes: 1 addition & 2 deletions test/TWAMM.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,8 @@ contract TWAMMTest is Test, Deployers, GasSnapshot {

vm.warp(10000);
token0.approve(address(twamm), 100 ether);
snapStart("TWAMMSubmitOrder");
twamm.submitOrder(poolKey, orderKey, 1 ether);
snapEnd();
snapLastCall("TWAMMSubmitOrder");

ITWAMM.Order memory submittedOrder = twamm.getOrder(poolKey, orderKey);
(uint256 sellRateCurrent0For1, uint256 earningsFactorCurrent0For1) = twamm.getOrderPool(poolKey, true);
Expand Down
Loading