-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |