Skip to content

Commit

Permalink
fix fuzz boundaries
Browse files Browse the repository at this point in the history
  • Loading branch information
snreynolds committed Nov 17, 2023
1 parent ef0f11b commit d893478
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fs_permissions = [{ access = "read-write", path = ".forge-snapshots/"}, { access
cancun = true

[profile.default.fuzz]
runs = 100
runs = 1000
seed = "0x4444"

[profile.ci.fuzz]
Expand Down
4 changes: 4 additions & 0 deletions src/test/AccessLockHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {CurrencyLibrary, Currency} from "../types/Currency.sol";
import {Hooks} from "../libraries/Hooks.sol";
import {TickMath} from "../libraries/TickMath.sol";

import "forge-std/console2.sol";

contract AccessLockHook is BaseTestHooks {
using CurrencyLibrary for Currency;

Expand Down Expand Up @@ -65,6 +67,8 @@ contract AccessLockHook is BaseTestHooks {
if (action == LockAction.Mint) {
manager.mint(key.currency1, address(this), amount);
} else if (action == LockAction.Take) {
console2.log("TAKE");
console2.log(key.currency1.balanceOf(address(manager)));
manager.take(key.currency1, address(this), amount);
} else if (action == LockAction.Donate) {
manager.donate(key, amount, amount, new bytes(0));
Expand Down
24 changes: 15 additions & 9 deletions test/AccessLock.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {BalanceDelta} from "../src/types/BalanceDelta.sol";
import {Pool} from "../src/libraries/Pool.sol";
import {TickMath} from "../src/libraries/TickMath.sol";

import "forge-std/console2.sol";

contract AccessLockTest is Test, Deployers {
using Pool for Pool.State;
using CurrencyLibrary for Currency;
Expand Down Expand Up @@ -106,14 +108,14 @@ contract AccessLockTest is Test, Deployers {
}

function test_beforeModifyPosition_take_succeedsWithAccessLock(uint128 amount) public {
vm.assume(amount < 10 * 10 ** 18); // We only have 100 * 10e18 liq in the pool so we must limit how much we can take.

// Add liquidity so there is something to take.
modifyPositionRouter.modifyPosition(
key,
IPoolManager.ModifyPositionParams({tickLower: -120, tickUpper: 120, liquidityDelta: 100 * 10e18}),
ZERO_BYTES
);
// Can't take more than the manager has.
vm.assume(amount < key.currency1.balanceOf(address(manager)));

uint256 balanceOfBefore1 = MockERC20(Currency.unwrap(currency1)).balanceOf(address(this));
uint256 balanceOfBefore0 = MockERC20(Currency.unwrap(currency0)).balanceOf(address(this));
Expand Down Expand Up @@ -241,15 +243,16 @@ contract AccessLockTest is Test, Deployers {
}

function test_beforeSwap_take_succeedsWithAccessLock(uint128 amount) public {
vm.assume(amount < 10 * 10 ** 18); // We only have 100 * 10e18 liq in the pool so we must limit how much we can take.

// Add liquidity so there is something to take.
modifyPositionRouter.modifyPosition(
key,
IPoolManager.ModifyPositionParams({tickLower: -120, tickUpper: 120, liquidityDelta: 100 * 10e18}),
ZERO_BYTES
);

// Can't take more than the manager has.
vm.assume(amount < key.currency1.balanceOf(address(manager)));

uint256 balanceOfBefore1 = MockERC20(Currency.unwrap(currency1)).balanceOf(address(this));
uint256 balanceOfBefore0 = MockERC20(Currency.unwrap(currency0)).balanceOf(address(this));

Expand Down Expand Up @@ -389,22 +392,24 @@ contract AccessLockTest is Test, Deployers {
}

function test_beforeDonate_take_succeedsWithAccessLock(uint128 amount) public {
vm.assume(amount < 10 * 10 ** 18); // We only have 100 * 10e18 liq in the pool so we must limit how much we can take.

// Add liquidity so there is something to take.
modifyPositionRouter.modifyPosition(
key,
IPoolManager.ModifyPositionParams({tickLower: -120, tickUpper: 120, liquidityDelta: 100 * 10e18}),
ZERO_BYTES
);

// Can't take more than the manager has.
vm.assume(amount < key.currency1.balanceOf(address(manager)));

uint256 balanceOfBefore1 = MockERC20(Currency.unwrap(currency1)).balanceOf(address(this));
uint256 balanceOfBefore0 = MockERC20(Currency.unwrap(currency0)).balanceOf(address(this));

// Hook only takes currency 1 rn.
BalanceDelta delta =
donateRouter.donate(key, 1 * 10 ** 18, 1 * 10 ** 18, abi.encode(amount, AccessLockHook.LockAction.Take));

// Take applies a positive delta in currency1.
// Donate applies a positive delta in currency0 and currency1.
uint256 balanceOfAfter0 = MockERC20(Currency.unwrap(currency0)).balanceOf(address(this));
uint256 balanceOfAfter1 = MockERC20(Currency.unwrap(currency1)).balanceOf(address(this));

Expand All @@ -415,15 +420,16 @@ contract AccessLockTest is Test, Deployers {
}

function test_beforeDonate_swap_succeedsWithAccessLock(uint128 amount) public {
vm.assume(amount != 0 && amount > 10 && amount < 10 * 10 ** 18); // precision, and limit swap size. need liquidity still in the pool.

// Add liquidity so there is something to swap over.
modifyPositionRouter.modifyPosition(
key,
IPoolManager.ModifyPositionParams({tickLower: -120, tickUpper: 120, liquidityDelta: 100 * 10e18}),
ZERO_BYTES
);

// greater than 10 for precision, less than currency1 balance so that we still have liquidity we can donate to
vm.assume(amount != 0 && amount > 10 && amount < currency1.balanceOf(address(manager)));

uint256 balanceOfBefore1 = MockERC20(Currency.unwrap(currency1)).balanceOf(address(this));
uint256 balanceOfBefore0 = MockERC20(Currency.unwrap(currency0)).balanceOf(address(this));

Expand Down

0 comments on commit d893478

Please sign in to comment.