Skip to content

Commit

Permalink
test SafeCallback (#220)
Browse files Browse the repository at this point in the history
* test SafeCallback

* assert PM address
  • Loading branch information
saucepoint authored Jul 31, 2024
1 parent db359ca commit 0f03176
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/SafeCallback.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.24;

import "forge-std/Test.sol";
import {Deployers} from "@uniswap/v4-core/test/utils/Deployers.sol";

import {SafeCallback} from "../src/base/SafeCallback.sol";
import {MockSafeCallback} from "./mocks/MockSafeCallback.sol";

contract SafeCallbackTest is Test, Deployers {
MockSafeCallback safeCallback;

function setUp() public {
deployFreshManager();
safeCallback = new MockSafeCallback(manager);
}

function test_poolManagerAddress() public view {
assertEq(address(safeCallback.poolManager()), address(manager));
}

function test_unlock(uint256 num) public {
bytes memory result = safeCallback.unlockManager(num);
assertEq(num, abi.decode(result, (uint256)));
}

function test_unlockRevert(address caller, bytes calldata data) public {
vm.startPrank(caller);
if (caller != address(manager)) vm.expectRevert(SafeCallback.NotPoolManager.selector);
safeCallback.unlockCallback(data);
vm.stopPrank();
}
}
18 changes: 18 additions & 0 deletions test/mocks/MockSafeCallback.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.20;

import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";

import "../../src/base/SafeCallback.sol";

contract MockSafeCallback is SafeCallback {
constructor(IPoolManager _poolManager) SafeCallback(_poolManager) {}

function unlockManager(uint256 num) external returns (bytes memory) {
return poolManager.unlock(abi.encode(num));
}

function _unlockCallback(bytes calldata data) internal pure override returns (bytes memory) {
return data;
}
}

0 comments on commit 0f03176

Please sign in to comment.