Skip to content

Commit

Permalink
chore: remove gas snapshot from fuzz test
Browse files Browse the repository at this point in the history
  • Loading branch information
chefburger committed Jun 12, 2024
1 parent f051737 commit 6477acc
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
32346
32358
Original file line number Diff line number Diff line change
@@ -1 +1 @@
30536
35030
50 changes: 42 additions & 8 deletions test/pool-bin/BinPoolManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,16 @@ contract BinPoolManagerTest is Test, GasSnapshot, BinTestHelper {
function testFuzz_SetMaxBinStep(uint16 binStep) public {
vm.assume(binStep > poolManager.MIN_BIN_STEP());

vm.expectEmit();
emit SetMaxBinStep(binStep);
poolManager.setMaxBinStep(binStep);

assertEq(poolManager.MAX_BIN_STEP(), binStep);
}

function testGas_SetMaxBinStep() public {
uint16 binStep = 10;

vm.expectEmit();
emit SetMaxBinStep(binStep);
snapStart("BinPoolManagerTest#testFuzz_SetMaxBinStep");
Expand Down Expand Up @@ -976,14 +986,38 @@ contract BinPoolManagerTest is Test, GasSnapshot, BinTestHelper {
emit DynamicLPFeeUpdated(key.toId(), _lpFee);

vm.prank(address(binFeeManagerHook));
if (_lpFee != 0) {
// temp fix to only record gas if _lpFee !=0. todo use snapLastCall to make this part of code easier to read
snapStart("BinPoolManagerTest#testFuzzUpdateDynamicLPFee");
poolManager.updateDynamicLPFee(key, _lpFee);
snapEnd();
} else {
poolManager.updateDynamicLPFee(key, _lpFee);
}
poolManager.updateDynamicLPFee(key, _lpFee);

(,, uint24 swapFee) = poolManager.getSlot0(key.toId());
assertEq(swapFee, _lpFee);
}

function testGasUpdateDynamicLPFee() public {
uint24 _lpFee = LPFeeLibrary.TEN_PERCENT_FEE / 2;

uint16 bitMap = 0x0004; // 0000 0000 0000 0100 (before mint call)
BinFeeManagerHook binFeeManagerHook = new BinFeeManagerHook(poolManager);
binFeeManagerHook.setHooksRegistrationBitmap(bitMap);

key = PoolKey({
currency0: currency0,
currency1: currency1,
hooks: IHooks(address(binFeeManagerHook)),
poolManager: IPoolManager(address(poolManager)),
fee: LPFeeLibrary.DYNAMIC_FEE_FLAG,
parameters: bytes32(uint256(bitMap)).setBinStep(10)
});
poolManager.initialize(key, activeId, new bytes(0));

binFeeManagerHook.setFee(_lpFee);

vm.expectEmit();
emit DynamicLPFeeUpdated(key.toId(), _lpFee);

vm.prank(address(binFeeManagerHook));
snapStart("BinPoolManagerTest#testFuzzUpdateDynamicLPFee");
poolManager.updateDynamicLPFee(key, _lpFee);
snapEnd();

(,, uint24 swapFee) = poolManager.getSlot0(key.toId());
assertEq(swapFee, _lpFee);
Expand Down
40 changes: 32 additions & 8 deletions test/pool-cl/CLPoolManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2830,14 +2830,38 @@ contract CLPoolManagerTest is Test, NoIsolate, Deployers, TokenFixture, GasSnaps
emit DynamicLPFeeUpdated(key.toId(), _swapFee);

vm.prank(address(clFeeManagerHook));
if (_swapFee != 0) {
// temp fix to only record gas if _swapFee !=0. todo use snapLastCall to make this part of code easier to read
snapStart("CLPoolManagerTest#testFuzzUpdateDynamicLPFee");
poolManager.updateDynamicLPFee(key, _swapFee);
snapEnd();
} else {
poolManager.updateDynamicLPFee(key, _swapFee);
}
poolManager.updateDynamicLPFee(key, _swapFee);

(,,, uint24 swapFee) = poolManager.getSlot0(key.toId());
assertEq(swapFee, _swapFee);
}

function testGasUpdateDynamicLPFee() public {
uint24 _swapFee = LPFeeLibrary.ONE_HUNDRED_PERCENT_FEE / 2;

uint16 bitMap = 0x0010; // 0000 0000 0001 0000 (before swap call)
clFeeManagerHook.setHooksRegistrationBitmap(bitMap);

PoolKey memory key = PoolKey({
currency0: currency0,
currency1: currency1,
fee: LPFeeLibrary.DYNAMIC_FEE_FLAG,
hooks: IHooks(address(clFeeManagerHook)),
poolManager: poolManager,
parameters: bytes32(uint256((10 << 16) | clFeeManagerHook.getHooksRegistrationBitmap()))
});

poolManager.initialize(key, TickMath.MIN_SQRT_RATIO, new bytes(0));

clFeeManagerHook.setFee(_swapFee);

vm.expectEmit();
emit DynamicLPFeeUpdated(key.toId(), _swapFee);

vm.prank(address(clFeeManagerHook));
snapStart("CLPoolManagerTest#testFuzzUpdateDynamicLPFee");
poolManager.updateDynamicLPFee(key, _swapFee);
snapEnd();

(,,, uint24 swapFee) = poolManager.getSlot0(key.toId());
assertEq(swapFee, _swapFee);
Expand Down

0 comments on commit 6477acc

Please sign in to comment.