Skip to content

Commit

Permalink
test(initiated): add onlyInitiated test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Grimal authored and Rubilmax committed Oct 24, 2023
1 parent ce70e42 commit 2f9f492
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/forge/ERC4626BundlerLocalTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ contract ERC4626BundlerLocalTest is LocalTest {
bundler.multicall(bundle);
}

function test4626DepositUninitiated(uint256 assets) public {
vm.expectRevert(bytes(ErrorsLib.UNINITIATED));
ERC4626BundlerMock(address(bundler)).erc4626Withdraw(address(vault), assets, RECEIVER);
}

function testErc4626WithdrawZeroAdressVault(uint256 assets) public {
bundle.push(_erc4626Withdraw(address(0), assets, RECEIVER));

Expand All @@ -61,6 +66,11 @@ contract ERC4626BundlerLocalTest is LocalTest {
bundler.multicall(bundle);
}

function test4626RedeemUninitiated(uint256 assets) public {
vm.expectRevert(bytes(ErrorsLib.UNINITIATED));
ERC4626BundlerMock(address(bundler)).erc4626Redeem(address(vault), assets, RECEIVER);
}

function testErc4626RedeemZeroAdressVault(uint256 assets) public {
bundle.push(_erc4626Redeem(address(0), assets, RECEIVER));

Expand Down
15 changes: 15 additions & 0 deletions test/forge/MorphoBundlerLocalTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ contract MorphoBundlerLocalTest is LocalTest {
_testSupplyCollateral(amount, onBehalf);
}

function testWithdrawUninitiated(uint256 withdrawnShares) public {
vm.expectRevert(bytes(ErrorsLib.UNINITIATED));
MorphoBundlerMock(address(bundler)).morphoWithdraw(marketParams, 0, withdrawnShares, RECEIVER);
}

function testWithdraw(uint256 privateKey, uint256 amount, uint256 withdrawnShares) public {
address user;
(privateKey, user) = _boundPrivateKey(privateKey);
Expand Down Expand Up @@ -247,6 +252,11 @@ contract MorphoBundlerLocalTest is LocalTest {
assertEq(morpho.borrowShares(id, user), 0, "borrowShares(user)");
}

function testBorrowUnititiated(uint256 borrowedAssets) public {
vm.expectRevert(bytes(ErrorsLib.UNINITIATED));
MorphoBundlerMock(address(bundler)).morphoBorrow(marketParams, borrowedAssets, 0, RECEIVER);
}

function _testSupplyCollateralBorrow(address user, uint256 amount, uint256 collateralAmount) internal {
assertEq(collateralToken.balanceOf(RECEIVER), 0, "collateral.balanceOf(RECEIVER)");
assertEq(loanToken.balanceOf(RECEIVER), amount, "loan.balanceOf(RECEIVER)");
Expand Down Expand Up @@ -316,6 +326,11 @@ contract MorphoBundlerLocalTest is LocalTest {
_testSupplyCollateralBorrow(user, amount, collateralAmount);
}

function testWithdrawCollateralUninitiated(uint256 collateralAmount) public {
vm.expectRevert(bytes(ErrorsLib.UNINITIATED));
MorphoBundlerMock(address(bundler)).morphoWithdrawCollateral(marketParams, collateralAmount, RECEIVER);
}

function _testRepayWithdrawCollateral(address user, uint256 collateralAmount) internal {
assertEq(collateralToken.balanceOf(RECEIVER), collateralAmount, "collateral.balanceOf(RECEIVER)");
assertEq(loanToken.balanceOf(RECEIVER), 0, "loan.balanceOf(RECEIVER)");
Expand Down
7 changes: 7 additions & 0 deletions test/forge/PermitBundlerLocalTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ contract PermitBundlerLocalTest is LocalTest {
assertEq(permitToken.allowance(user, address(bundler)), amount, "allowance(user, bundler)");
}

function testPermitUninitiated(uint256 amount) public {
amount = bound(amount, MIN_AMOUNT, MAX_AMOUNT);

vm.expectRevert(bytes(ErrorsLib.UNINITIATED));
PermitBundlerMock(address(bundler)).permit(address(loanToken), amount, SIGNATURE_DEADLINE, 0, 0, 0, true);
}

function testPermitRevert(uint256 amount, uint256 privateKey, uint256 deadline) public {
amount = bound(amount, MIN_AMOUNT, MAX_AMOUNT);
deadline = bound(deadline, block.timestamp, type(uint48).max);
Expand Down
7 changes: 7 additions & 0 deletions test/forge/TransferBundlerLocalTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ contract TransferBundlerLocalTest is LocalTest {
assertEq(loanToken.balanceOf(USER), 0, "loan.balanceOf(USER)");
}

function testTransferFromUninitiated(uint256 amount) public {
amount = bound(amount, MIN_AMOUNT, MAX_AMOUNT);

vm.expectRevert(bytes(ErrorsLib.UNINITIATED));
TransferBundlerMock(address(bundler)).erc20TransferFrom(address(loanToken), amount);
}

function testTranferFromZeroAddress(uint256 amount) public {
amount = bound(amount, MIN_AMOUNT, MAX_AMOUNT);

Expand Down
7 changes: 7 additions & 0 deletions test/forge/ethereum/EthereumPermitBundlerEthereumTest.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

import {ErrorsLib} from "../../../src/libraries/ErrorsLib.sol";

import {DaiPermit} from "../helpers/SigUtils.sol";

import "../../../src/mocks/bundlers/ethereum/EthereumPermitBundlerMock.sol";
Expand Down Expand Up @@ -32,6 +34,11 @@ contract EthereumPermitBundlerEthereumTest is EthereumTest {
assertEq(ERC20(DAI).allowance(user, address(bundler)), type(uint256).max, "allowance(user, bundler)");
}

function testPermitDaiUninitiated() public {
vm.expectRevert(bytes(ErrorsLib.UNINITIATED));
EthereumPermitBundlerMock(address(bundler)).permitDai(0, SIGNATURE_DEADLINE, true, 0, 0, 0, true);
}

function testPermitDaiRevert(uint256 privateKey, uint256 expiry) public {
expiry = bound(expiry, block.timestamp, type(uint48).max);
privateKey = bound(privateKey, 1, type(uint160).max);
Expand Down
8 changes: 8 additions & 0 deletions test/forge/ethereum/Permit2BundlerEthereumTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ contract Permit2BundlerEthereumTest is EthereumTest {
assertEq(ERC20(marketParams.loanToken).balanceOf(address(bundler)), amount, "loan.balanceOf(bundler)");
}

function testPermtestPermit2TransferFromUninitiated() public {
ISignatureTransfer.PermitTransferFrom memory permit;
bytes memory signature;

vm.expectRevert(bytes(ErrorsLib.UNINITIATED));
Permit2BundlerMock(address(bundler)).permit2TransferFrom(permit, signature);
}

function testPermit2TransferFromZeroAmount(uint256 seed, uint256 privateKey, uint256 amount) public {
privateKey = bound(privateKey, 1, type(uint160).max);
amount = bound(amount, MIN_AMOUNT, MAX_AMOUNT);
Expand Down
14 changes: 14 additions & 0 deletions test/forge/ethereum/WNativeBundlerEthereumTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ contract WNativeBundlerEthereumTest is EthereumTest {
ERC20(WETH).approve(address(bundler), type(uint256).max);
}

function testWrapUninitiated(uint256 amount) public {
amount = bound(amount, MIN_AMOUNT, MAX_AMOUNT);

vm.expectRevert(bytes(ErrorsLib.UNINITIATED));
WNativeBundlerMock(payable(address(bundler))).wrapNative(amount);
}

function testWrapZeroAmount() public {
bundle.push(abi.encodeCall(WNativeBundler.wrapNative, (0)));

Expand Down Expand Up @@ -45,6 +52,13 @@ contract WNativeBundlerEthereumTest is EthereumTest {
assertEq(RECEIVER.balance, 0, "Receiver's native token balance");
}

function testUnwrapUninitiated(uint256 amount) public {
amount = bound(amount, MIN_AMOUNT, MAX_AMOUNT);

vm.expectRevert(bytes(ErrorsLib.UNINITIATED));
WNativeBundlerMock(payable(address(bundler))).unwrapNative(amount);
}

function testUnwrapZeroAmount() public {
bundle.push(abi.encodeCall(WNativeBundler.unwrapNative, (0)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ contract AaveV2EthereumMigrationBundlerEthereumTest is EthereumMigrationTest {
bundler = new AaveV2EthereumMigrationBundler(address(morpho));
}

function testAaveV2RepayUninitiated(uint256 amount) public {
amount = bound(amount, MIN_AMOUNT, MAX_AMOUNT);

vm.expectRevert(bytes(ErrorsLib.UNINITIATED));
AaveV2EthereumMigrationBundler(address(bundler)).aaveV2Repay(marketParams.loanToken, amount, 1);
}

function testAaveV2RepayZeroAmount() public {
bundle.push(_aaveV2Repay(marketParams.loanToken, 0));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ contract AaveV3MigrationBundlerEthereumTest is EthereumMigrationTest {
vm.label(address(bundler), "Aave V3 Migration Bundler");
}

function testAaveV3RepayUninitiated(uint256 amount) public {
amount = bound(amount, MIN_AMOUNT, MAX_AMOUNT);

vm.expectRevert(bytes(ErrorsLib.UNINITIATED));
AaveV3MigrationBundler(address(bundler)).aaveV3Repay(marketParams.loanToken, amount, 1);
}

function testAaveV3RepayZeroAmount() public {
bundle.push(_aaveV3Repay(marketParams.loanToken, 0));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ contract AaveV3OptimizerMigrationBundlerEthereumTest is EthereumMigrationTest {
bundler = new AaveV3OptimizerMigrationBundler(address(morpho), address(AAVE_V3_OPTIMIZER));
}

function testAaveV3OptimizerRepayUninitiated(uint256 amount) public {
amount = bound(amount, MIN_AMOUNT, MAX_AMOUNT);

vm.expectRevert(bytes(ErrorsLib.UNINITIATED));
AaveV3OptimizerMigrationBundler(address(bundler)).aaveV3OptimizerRepay(marketParams.loanToken, amount);
}

function testAaveV3Optimizer3RepayZeroAmount() public {
bundle.push(_aaveV3OptimizerRepay(marketParams.loanToken, 0));

Expand Down Expand Up @@ -153,6 +160,17 @@ contract AaveV3OptimizerMigrationBundlerEthereumTest is EthereumMigrationTest {

/* ACTIONS */

function testAaveV3OptimizerApproveManagerUninitiated(uint256 amount) public {
amount = bound(amount, MIN_AMOUNT, MAX_AMOUNT);

Types.Signature memory sig;

vm.expectRevert(bytes(ErrorsLib.UNINITIATED));
AaveV3OptimizerMigrationBundler(address(bundler)).aaveV3OptimizerApproveManagerWithSig(
true, 0, SIGNATURE_DEADLINE, sig
);
}

function _aaveV3OptimizerApproveManager(uint256 privateKey, address manager, bool isAllowed, uint256 nonce)
internal
view
Expand All @@ -176,6 +194,15 @@ contract AaveV3OptimizerMigrationBundlerEthereumTest is EthereumMigrationTest {
return abi.encodeCall(AaveV3OptimizerMigrationBundler.aaveV3OptimizerRepay, (underlying, amount));
}

function testAaveV3OptimizerWithdrawUninitiated(uint256 amount) public {
amount = bound(amount, MIN_AMOUNT, MAX_AMOUNT);

vm.expectRevert(bytes(ErrorsLib.UNINITIATED));
AaveV3OptimizerMigrationBundler(address(bundler)).aaveV3OptimizerWithdraw(
marketParams.loanToken, amount, RECEIVER, MAX_ITERATIONS
);
}

function _aaveV3OptimizerWithdraw(address underlying, uint256 amount, address receiver)
internal
pure
Expand All @@ -186,6 +213,15 @@ contract AaveV3OptimizerMigrationBundlerEthereumTest is EthereumMigrationTest {
);
}

function testAaveV3OptimizerWithdrawCollateralUninitiated(uint256 amount) public {
amount = bound(amount, MIN_AMOUNT, MAX_AMOUNT);

vm.expectRevert(bytes(ErrorsLib.UNINITIATED));
AaveV3OptimizerMigrationBundler(address(bundler)).aaveV3OptimizerWithdrawCollateral(
marketParams.loanToken, amount, RECEIVER
);
}

function _aaveV3OptimizerWithdrawCollateral(address underlying, uint256 amount, address receiver)
internal
pure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ contract CompoundV2EthLoanMigrationBundlerEthereumTest is EthereumMigrationTest
enteredMarkets.push(C_DAI_V2);
}

function testCompoundV2RepayUninitiated(uint256 amount) public {
amount = bound(amount, MIN_AMOUNT, MAX_AMOUNT);

vm.expectRevert(bytes(ErrorsLib.UNINITIATED));
CompoundV2MigrationBundler(payable(address(bundler))).compoundV2Repay(C_DAI_V2, amount);
}

function testCompoundV2RepayCEthZeroAmount() public {
bundle.push(_compoundV2Repay(C_ETH_V2, 0));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ contract CompoundV3MigrationBundlerEthereumTest is EthereumMigrationTest {
bundler = new CompoundV3MigrationBundler(address(morpho));
}

function testCompoundV3RepayUninitiated(uint256 amount) public {
amount = bound(amount, MIN_AMOUNT, MAX_AMOUNT);

vm.expectRevert(bytes(ErrorsLib.UNINITIATED));
CompoundV3MigrationBundler(address(bundler)).compoundV3Repay(C_WETH_V3, marketParams.loanToken, amount);
}

function testCompoundV3RepayZeroAmount() public {
bundle.push(_compoundV3Repay(C_WETH_V3, marketParams.loanToken, 0));

Expand Down Expand Up @@ -173,6 +180,13 @@ contract CompoundV3MigrationBundlerEthereumTest is EthereumMigrationTest {

/* ACTIONS */

function testCompoundV3AllowUninitiated() public {
vm.expectRevert(bytes(ErrorsLib.UNINITIATED));
CompoundV3MigrationBundler(address(bundler)).compoundV3AllowBySig(
C_WETH_V3, true, 0, SIGNATURE_DEADLINE, 0, 0, 0
);
}

function _compoundV3Allow(uint256 privateKey, address instance, address manager, bool isAllowed, uint256 nonce)
internal
view
Expand Down Expand Up @@ -203,6 +217,13 @@ contract CompoundV3MigrationBundlerEthereumTest is EthereumMigrationTest {
return abi.encodeCall(CompoundV3MigrationBundler.compoundV3Withdraw, (instance, asset, amount));
}

function testCompoundV3WithdrawFromUninitiated(uint256 amount) public {
amount = bound(amount, MIN_AMOUNT, MAX_AMOUNT);

vm.expectRevert(bytes(ErrorsLib.UNINITIATED));
CompoundV3MigrationBundler(address(bundler)).compoundV3WithdrawFrom(C_WETH_V3, marketParams.loanToken, amount);
}

function _compoundV3WithdrawFrom(address instance, address asset, uint256 amount)
internal
pure
Expand Down

0 comments on commit 2f9f492

Please sign in to comment.