Files
tycho-execution/foundry/test/TychoRouterTestSetup.sol
TAMARA LIPOWSKI fb9f340cb7 refactor: Move contract code-checking logic to SwapExecutionDispatcher
I was inspired to do this because, when disabling the slither check for the delegatecall when calling the swap executor, I realized it's not clear from the same contract that we have already checked for contract code existence when setting the executor. This made me feel uneasy, as this contract can then not stand alone and must rely on the higher level contract to safely check for code existence, otherwise the delegatecall is unsafe. Keeping this logic in a separate contract seems error-prone to me, as we may remove the check for code existence without immediately realizing the implications of doing so.

For this reason I have organized it as follows:
- Logic/tests relating to proper roles/access control in the main TychoRouter.
- Lower-level logic/tests that checks contract validity before setting the executor in the SwapExecutionDispatcher
2025-01-23 15:40:24 -05:00

43 lines
1.4 KiB
Solidity

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import "@src/TychoRouter.sol";
import "./Constants.sol";
import "./mock/MockERC20.sol";
contract TychoRouterTestSetup is Test, Constants {
TychoRouter tychoRouter;
address executorSetter;
address permit2Address = address(0x000000000022D473030F116dDEE9F6B43aC78BA3);
MockERC20[] tokens;
function setUp() public {
vm.startPrank(ADMIN);
tychoRouter = new TychoRouter(permit2Address);
tychoRouter.grantRole(keccak256("EXECUTOR_SETTER_ROLE"), BOB);
tychoRouter.grantRole(keccak256("FUND_RESCUER_ROLE"), FUND_RESCUER);
tychoRouter.grantRole(keccak256("FEE_SETTER_ROLE"), FEE_SETTER);
executorSetter = BOB;
deployDummyContract();
vm.stopPrank();
vm.startPrank(BOB);
tokens.push(new MockERC20("Token A", "A"));
tokens.push(new MockERC20("Token B", "B"));
tokens.push(new MockERC20("Token C", "C"));
vm.stopPrank();
}
/**
* @dev Mints tokens to the given address
* @param amount The amount of tokens to mint
* @param to The address to mint tokens to
*/
function mintTokens(uint256 amount, address to) internal {
for (uint256 i = 0; i < tokens.length; i++) {
// slither-disable-next-line calls-loop
tokens[i].mint(to, amount);
}
}
}