diff --git a/foundry/script/Deploy.sol b/foundry/script/Deploy.sol deleted file mode 100644 index 9c4a381..0000000 --- a/foundry/script/Deploy.sol +++ /dev/null @@ -1,8 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.13; - -import {Script, console} from "forge-std/Script.sol"; - -contract DeployScript is Script { -// TODO: implement deploy script -} diff --git a/foundry/test/Constants.sol b/foundry/test/Constants.sol index ec30775..521dff7 100644 --- a/foundry/test/Constants.sol +++ b/foundry/test/Constants.sol @@ -10,4 +10,5 @@ contract Constants is Test { address FEE_SETTER = makeAddr("feeSetter"); // dummy contracts address DUMMY = makeAddr("dummy"); + address FEE_RECEIVER = makeAddr("feeReceiver"); } diff --git a/foundry/test/TychoRouter.t.sol b/foundry/test/TychoRouter.t.sol index cab9a79..fb9ad4b 100644 --- a/foundry/test/TychoRouter.t.sol +++ b/foundry/test/TychoRouter.t.sol @@ -126,7 +126,7 @@ contract TychoRouterTest is TychoRouterTestSetup { vm.stopPrank(); } - function testWithdrawNativeOtherCases() public { + function testWithdrawNativeFailures() public { vm.deal(address(tychoRouter), 100 ether); vm.startPrank(FUND_RESCUER); vm.expectRevert(TychoRouter__AddressZero.selector); @@ -142,21 +142,7 @@ contract TychoRouterTest is TychoRouterTestSetup { function testWithdrawERC20Tokens() public { vm.startPrank(BOB); - // Check balances before minting - for (uint256 i = 0; i < tokens.length; i++) { - // slither-disable-next-line calls-loop - assertEq(tokens[i].balanceOf(address(tychoRouter)), 0); - } - // Mint tokens to tychoRouter - for (uint256 i = 0; i < tokens.length; i++) { - // slither-disable-next-line calls-loop - tokens[i].mint(address(tychoRouter), 100 ether); - } - // Check balances after minting - for (uint256 i = 0; i < tokens.length; i++) { - // slither-disable-next-line calls-loop - assertEq(tokens[i].balanceOf(address(tychoRouter)), 100 ether); - } + mintTokens(100 ether, address(tychoRouter)); vm.stopPrank(); vm.startPrank(FUND_RESCUER); @@ -174,19 +160,28 @@ contract TychoRouterTest is TychoRouterTestSetup { assertEq(tokens[i].balanceOf(FUND_RESCUER), 100 ether); } vm.stopPrank(); + } + + function testWithdrawERC20TokensFailures() public { + mintTokens(100 ether, address(tychoRouter)); + IERC20[] memory tokensArray = new IERC20[](3); + tokensArray[0] = IERC20(address(tokens[0])); + tokensArray[1] = IERC20(address(tokens[1])); + tokensArray[2] = IERC20(address(tokens[2])); vm.startPrank(FUND_RESCUER); - vm.expectRevert(); + vm.expectRevert(TychoRouter__AddressZero.selector); tychoRouter.withdraw(tokensArray, address(0)); vm.stopPrank(); + // Not role FUND_RESCUER vm.startPrank(BOB); vm.expectRevert(); tychoRouter.withdraw(tokensArray, FUND_RESCUER); vm.stopPrank(); } - function testFeeSetterRole() public { + function testFeeSetting() public { vm.startPrank(FEE_SETTER); assertEq(tychoRouter.fee(), 0); tychoRouter.setFee(100); @@ -198,4 +193,17 @@ contract TychoRouterTest is TychoRouterTestSetup { tychoRouter.setFee(200); vm.stopPrank(); } + + function testFeeReceiverSetting() public { + vm.startPrank(FEE_SETTER); + assertEq(tychoRouter.feeReceiver(), address(0)); + tychoRouter.setFeeReceiver(FEE_RECEIVER); + assertEq(tychoRouter.feeReceiver(), FEE_RECEIVER); + vm.stopPrank(); + + vm.startPrank(BOB); + vm.expectRevert(); + tychoRouter.setFeeReceiver(FEE_RECEIVER); + vm.stopPrank(); + } } diff --git a/foundry/test/TychoRouterTestSetup.sol b/foundry/test/TychoRouterTestSetup.sol index 870ebba..9765d76 100644 --- a/foundry/test/TychoRouterTestSetup.sol +++ b/foundry/test/TychoRouterTestSetup.sol @@ -35,4 +35,16 @@ contract TychoRouterTestSetup is Test, Constants { bytes memory minimalBytecode = hex"01"; // Single-byte bytecode vm.etch(DUMMY, minimalBytecode); // Deploy minimal bytecode } + + /** + * @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); + } + } }