From 2f9f4926b5c5f11ae69fc0143db246db734c53ec Mon Sep 17 00:00:00 2001 From: Jean-Grimal Date: Mon, 23 Oct 2023 17:22:43 +0200 Subject: [PATCH] test(initiated): add onlyInitiated test --- test/forge/ERC4626BundlerLocalTest.sol | 10 ++++++ test/forge/MorphoBundlerLocalTest.sol | 15 ++++++++ test/forge/PermitBundlerLocalTest.sol | 7 ++++ test/forge/TransferBundlerLocalTest.sol | 7 ++++ .../EthereumPermitBundlerEthereumTest.sol | 7 ++++ .../ethereum/Permit2BundlerEthereumTest.sol | 8 +++++ .../ethereum/WNativeBundlerEthereumTest.sol | 14 ++++++++ ...V2EthereumMigrationBundlerEthereumTest.sol | 7 ++++ .../AaveV3MigrationBundlerEthereumTest.sol | 7 ++++ ...3OptimizerMigrationBundlerEthereumTest.sol | 36 +++++++++++++++++++ ...BorrowableMigrationBundlerEthereumTest.sol | 7 ++++ ...CompoundV3MigrationBundlerEthereumTest.sol | 21 +++++++++++ 12 files changed, 146 insertions(+) diff --git a/test/forge/ERC4626BundlerLocalTest.sol b/test/forge/ERC4626BundlerLocalTest.sol index 2b05fc5e..8299c38a 100644 --- a/test/forge/ERC4626BundlerLocalTest.sol +++ b/test/forge/ERC4626BundlerLocalTest.sol @@ -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)); @@ -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)); diff --git a/test/forge/MorphoBundlerLocalTest.sol b/test/forge/MorphoBundlerLocalTest.sol index 4a652e9e..c5109a24 100644 --- a/test/forge/MorphoBundlerLocalTest.sol +++ b/test/forge/MorphoBundlerLocalTest.sol @@ -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); @@ -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)"); @@ -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)"); diff --git a/test/forge/PermitBundlerLocalTest.sol b/test/forge/PermitBundlerLocalTest.sol index b3722cf6..fdce7bd1 100644 --- a/test/forge/PermitBundlerLocalTest.sol +++ b/test/forge/PermitBundlerLocalTest.sol @@ -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); diff --git a/test/forge/TransferBundlerLocalTest.sol b/test/forge/TransferBundlerLocalTest.sol index 3b3d0dbf..683d86d2 100644 --- a/test/forge/TransferBundlerLocalTest.sol +++ b/test/forge/TransferBundlerLocalTest.sol @@ -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); diff --git a/test/forge/ethereum/EthereumPermitBundlerEthereumTest.sol b/test/forge/ethereum/EthereumPermitBundlerEthereumTest.sol index 30fde51e..97384f01 100644 --- a/test/forge/ethereum/EthereumPermitBundlerEthereumTest.sol +++ b/test/forge/ethereum/EthereumPermitBundlerEthereumTest.sol @@ -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"; @@ -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); diff --git a/test/forge/ethereum/Permit2BundlerEthereumTest.sol b/test/forge/ethereum/Permit2BundlerEthereumTest.sol index 659951d4..bd9641d2 100644 --- a/test/forge/ethereum/Permit2BundlerEthereumTest.sol +++ b/test/forge/ethereum/Permit2BundlerEthereumTest.sol @@ -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); diff --git a/test/forge/ethereum/WNativeBundlerEthereumTest.sol b/test/forge/ethereum/WNativeBundlerEthereumTest.sol index 2b3bc7c0..1a19157f 100644 --- a/test/forge/ethereum/WNativeBundlerEthereumTest.sol +++ b/test/forge/ethereum/WNativeBundlerEthereumTest.sol @@ -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))); @@ -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))); diff --git a/test/forge/ethereum/migration/AaveV2EthereumMigrationBundlerEthereumTest.sol b/test/forge/ethereum/migration/AaveV2EthereumMigrationBundlerEthereumTest.sol index 7b11204d..b2586530 100644 --- a/test/forge/ethereum/migration/AaveV2EthereumMigrationBundlerEthereumTest.sol +++ b/test/forge/ethereum/migration/AaveV2EthereumMigrationBundlerEthereumTest.sol @@ -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)); diff --git a/test/forge/ethereum/migration/AaveV3MigrationBundlerEthereumTest.sol b/test/forge/ethereum/migration/AaveV3MigrationBundlerEthereumTest.sol index b8632637..c4154d53 100644 --- a/test/forge/ethereum/migration/AaveV3MigrationBundlerEthereumTest.sol +++ b/test/forge/ethereum/migration/AaveV3MigrationBundlerEthereumTest.sol @@ -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)); diff --git a/test/forge/ethereum/migration/AaveV3OptimizerMigrationBundlerEthereumTest.sol b/test/forge/ethereum/migration/AaveV3OptimizerMigrationBundlerEthereumTest.sol index 2d6eb90d..d863e3c5 100644 --- a/test/forge/ethereum/migration/AaveV3OptimizerMigrationBundlerEthereumTest.sol +++ b/test/forge/ethereum/migration/AaveV3OptimizerMigrationBundlerEthereumTest.sol @@ -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)); @@ -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 @@ -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 @@ -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 diff --git a/test/forge/ethereum/migration/CompoundV2EthBorrowableMigrationBundlerEthereumTest.sol b/test/forge/ethereum/migration/CompoundV2EthBorrowableMigrationBundlerEthereumTest.sol index cc697ca9..a26a73c9 100644 --- a/test/forge/ethereum/migration/CompoundV2EthBorrowableMigrationBundlerEthereumTest.sol +++ b/test/forge/ethereum/migration/CompoundV2EthBorrowableMigrationBundlerEthereumTest.sol @@ -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)); diff --git a/test/forge/ethereum/migration/CompoundV3MigrationBundlerEthereumTest.sol b/test/forge/ethereum/migration/CompoundV3MigrationBundlerEthereumTest.sol index ecb7930e..6aacf04a 100644 --- a/test/forge/ethereum/migration/CompoundV3MigrationBundlerEthereumTest.sol +++ b/test/forge/ethereum/migration/CompoundV3MigrationBundlerEthereumTest.sol @@ -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)); @@ -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 @@ -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