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

test SafeCallback #220

Merged
merged 5 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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 {
Copy link
Member

Choose a reason for hiding this comment

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

can we also just add an assert that the pool manager in SafeCallback is the address we expect/the pool manager address we initialized it with

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();
Comment on lines +28 to +31
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is pretty neat from foundry, when fuzzing for addresses the fuzzer includes deployed contracts from setup! 😲

}
}
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;
}
}
Loading