feat: Set swap executors and verifiers
- Moved the deployment method into a test template for organization - Created skeletons of dispatcher contracts - Added all possible test cases for thoroughness
This commit is contained in:
10
foundry/test/Constants.sol
Normal file
10
foundry/test/Constants.sol
Normal file
@@ -0,0 +1,10 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.13;
|
||||
|
||||
contract Constants {
|
||||
address ADMIN = address(12395012351212343412541234); //admin=us
|
||||
address BOB = address(123); //bob=someone!=us
|
||||
|
||||
// dummy contracts
|
||||
address DUMMY = address(0x1234);
|
||||
}
|
||||
33
foundry/test/TestTemplate.sol
Normal file
33
foundry/test/TestTemplate.sol
Normal file
@@ -0,0 +1,33 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.13;
|
||||
|
||||
import "forge-std/Test.sol";
|
||||
import "@src/TychoRouter.sol";
|
||||
import "./Constants.sol";
|
||||
|
||||
contract TychoRouterTestTemplate is Test, Constants {
|
||||
TychoRouter tychoRouter;
|
||||
address tychoRouterAddress;
|
||||
address executorSetter;
|
||||
|
||||
function deployTychoRouter() internal {
|
||||
vm.startPrank(ADMIN);
|
||||
|
||||
address permit2Address =
|
||||
address(0x000000000022D473030F116dDEE9F6B43aC78BA3);
|
||||
tychoRouter = new TychoRouter(permit2Address);
|
||||
tychoRouterAddress = address(tychoRouter);
|
||||
tychoRouter.grantRole(keccak256("EXECUTOR_SETTER_ROLE"), BOB);
|
||||
executorSetter = BOB;
|
||||
|
||||
vm.stopPrank();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Deploys a dummy contract with non-empty bytecode
|
||||
*/
|
||||
function deployDummyContract() internal {
|
||||
bytes memory minimalBytecode = hex"01"; // Single-byte bytecode
|
||||
vm.etch(DUMMY, minimalBytecode); // Deploy minimal bytecode
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,138 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.28;
|
||||
|
||||
import {Test, console} from "forge-std/Test.sol";
|
||||
import {TychoRouter} from "@src/TychoRouter.sol";
|
||||
import "./TestTemplate.sol";
|
||||
|
||||
contract TychoRouterTest is Test {
|
||||
TychoRouter public tychoRouter;
|
||||
contract TychoRouterTest is TychoRouterTestTemplate {
|
||||
bytes32 public constant EXECUTOR_SETTER_ROLE =
|
||||
0x6a1dd52dcad5bd732e45b6af4e7344fa284e2d7d4b23b5b09cb55d36b0685c87;
|
||||
bytes32 public constant FEE_SETTER_ROLE =
|
||||
0xe6ad9a47fbda1dc18de1eb5eeb7d935e5e81b4748f3cfc61e233e64f88182060;
|
||||
bytes32 public constant PAUSER_ROLE =
|
||||
0x65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a;
|
||||
bytes32 public constant FUND_RESCUER_ROLE =
|
||||
0x912e45d663a6f4cc1d0491d8f046e06c616f40352565ea1cdb86a0e1aaefa41b;
|
||||
|
||||
function setupTychoRouter() public {
|
||||
address permit2Address =
|
||||
address(0x000000000022D473030F116dDEE9F6B43aC78BA3);
|
||||
tychoRouter = new TychoRouter(permit2Address);
|
||||
deployTychoRouter();
|
||||
}
|
||||
|
||||
function testSetupTychoRouter() public {
|
||||
function testSetValidExecutor() public {
|
||||
setupTychoRouter();
|
||||
deployDummyContract();
|
||||
|
||||
vm.startPrank(executorSetter);
|
||||
tychoRouter.setSwapExecutor(DUMMY);
|
||||
vm.stopPrank();
|
||||
|
||||
assert(tychoRouter.swapExecutors(DUMMY) == true);
|
||||
}
|
||||
|
||||
function testRemoveExecutor() public {
|
||||
setupTychoRouter();
|
||||
deployDummyContract();
|
||||
|
||||
vm.startPrank(executorSetter);
|
||||
tychoRouter.setSwapExecutor(DUMMY);
|
||||
tychoRouter.removeSwapExecutor(DUMMY);
|
||||
vm.stopPrank();
|
||||
assert(tychoRouter.swapExecutors(DUMMY) == false);
|
||||
}
|
||||
|
||||
function testRemoveUnSetExecutor() public {
|
||||
setupTychoRouter();
|
||||
deployDummyContract();
|
||||
|
||||
vm.startPrank(executorSetter);
|
||||
tychoRouter.removeSwapExecutor(BOB);
|
||||
vm.stopPrank();
|
||||
assert(tychoRouter.swapExecutors(BOB) == false);
|
||||
}
|
||||
|
||||
function testRemoveExecutorMissingSetterRole() public {
|
||||
setupTychoRouter();
|
||||
deployDummyContract();
|
||||
vm.expectRevert();
|
||||
tychoRouter.removeSwapExecutor(BOB);
|
||||
}
|
||||
|
||||
function testSetExecutorMissingSetterRole() public {
|
||||
setupTychoRouter();
|
||||
deployDummyContract();
|
||||
|
||||
vm.expectRevert();
|
||||
tychoRouter.setSwapExecutor(DUMMY);
|
||||
}
|
||||
|
||||
function testSetExecutorNonContract() public {
|
||||
setupTychoRouter();
|
||||
deployDummyContract();
|
||||
|
||||
vm.startPrank(executorSetter);
|
||||
vm.expectRevert(
|
||||
abi.encodeWithSelector(TychoRouter__NonContractExecutor.selector)
|
||||
);
|
||||
tychoRouter.setSwapExecutor(BOB);
|
||||
vm.stopPrank();
|
||||
}
|
||||
|
||||
function testSetValidVerifier() public {
|
||||
setupTychoRouter();
|
||||
deployDummyContract();
|
||||
|
||||
vm.startPrank(executorSetter);
|
||||
tychoRouter.setCallbackVerifier(DUMMY);
|
||||
vm.stopPrank();
|
||||
|
||||
assert(tychoRouter.callbackVerifiers(DUMMY) == true);
|
||||
}
|
||||
|
||||
function testRemoveVerifier() public {
|
||||
setupTychoRouter();
|
||||
deployDummyContract();
|
||||
|
||||
vm.startPrank(executorSetter);
|
||||
tychoRouter.setCallbackVerifier(DUMMY);
|
||||
tychoRouter.removeCallbackVerifier(DUMMY);
|
||||
vm.stopPrank();
|
||||
assert(tychoRouter.callbackVerifiers(DUMMY) == false);
|
||||
}
|
||||
|
||||
function testRemoveUnSetVerifier() public {
|
||||
setupTychoRouter();
|
||||
deployDummyContract();
|
||||
|
||||
vm.startPrank(executorSetter);
|
||||
tychoRouter.removeCallbackVerifier(BOB);
|
||||
vm.stopPrank();
|
||||
assert(tychoRouter.callbackVerifiers(BOB) == false);
|
||||
}
|
||||
|
||||
function testRemoveVerifierMissingSetterRole() public {
|
||||
setupTychoRouter();
|
||||
deployDummyContract();
|
||||
vm.expectRevert();
|
||||
tychoRouter.removeCallbackVerifier(BOB);
|
||||
}
|
||||
|
||||
function testSetVerifierMissingSetterRole() public {
|
||||
setupTychoRouter();
|
||||
deployDummyContract();
|
||||
|
||||
vm.expectRevert();
|
||||
tychoRouter.setCallbackVerifier(DUMMY);
|
||||
}
|
||||
|
||||
function testSetVerifierNonContract() public {
|
||||
setupTychoRouter();
|
||||
deployDummyContract();
|
||||
|
||||
vm.startPrank(executorSetter);
|
||||
vm.expectRevert(
|
||||
abi.encodeWithSelector(TychoRouter__NonContractVerifier.selector)
|
||||
);
|
||||
tychoRouter.setCallbackVerifier(BOB);
|
||||
vm.stopPrank();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user