Skip to content

Commit

Permalink
test: make tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
MathisGD committed May 7, 2024
1 parent 03c63b0 commit 7a711c1
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 50 deletions.
6 changes: 3 additions & 3 deletions config/base.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"chainId": 8453,
"forkBlockNumber": 13000000,
"forkBlockNumber": 14000000,
"markets": [
{
"loanToken": "WETH",
"collateralToken": "DAI",
"loanToken": "USDC",
"collateralToken": "USDC",
"lltv": 800000000000000000
}
],
Expand Down
9 changes: 7 additions & 2 deletions test/forge/ethereum/EthereumBundlerEthereumTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ pragma solidity ^0.8.0;

import {IAllowanceTransfer} from "../../../lib/permit2/src/interfaces/IAllowanceTransfer.sol";

import "../../../src/ethereum/EthereumBundlerV2.sol";
import {EthereumBundlerV2} from "../../../src/ethereum/EthereumBundlerV2.sol";
import {BaseBundlerV2} from "../../../src/base/BaseBundlerV2.sol";

import "./helpers/EthereumTest.sol";

Expand All @@ -17,7 +18,11 @@ contract EthereumBundlerEthereumTest is EthereumTest {
function setUp() public override {
super.setUp();

bundler = new EthereumBundlerV2(address(morpho));
if (block.chainid == 1) {
bundler = new EthereumBundlerV2(address(morpho));
} else if (block.chainid == 8453) {
bundler = new BaseBundlerV2(address(morpho));
}

vm.prank(USER);
morpho.setAuthorization(address(bundler), true);
Expand Down
6 changes: 3 additions & 3 deletions test/forge/ethereum/EthereumPermitBundlerEthereumTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ contract EthereumPermitBundlerEthereumTest is EthereumTest {
bundler = new EthereumPermitBundlerMock();
}

function testPermitDai(uint256 privateKey, uint256 expiry) public {
function testPermitDai(uint256 privateKey, uint256 expiry) public onlyEthereum {
expiry = bound(expiry, block.timestamp, type(uint48).max);
privateKey = bound(privateKey, 1, type(uint160).max);

Expand All @@ -34,12 +34,12 @@ contract EthereumPermitBundlerEthereumTest is EthereumTest {
assertEq(ERC20(DAI).allowance(user, address(bundler)), type(uint256).max, "allowance(user, bundler)");
}

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

function testPermitDaiRevert(uint256 privateKey, uint256 expiry) public {
function testPermitDaiRevert(uint256 privateKey, uint256 expiry) public onlyEthereum {
expiry = bound(expiry, block.timestamp, type(uint48).max);
privateKey = bound(privateKey, 1, type(uint160).max);

Expand Down
18 changes: 10 additions & 8 deletions test/forge/ethereum/EthereumStEthBundlerEthereumTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,22 @@ contract EthereumStEthBundlerEthereumTest is EthereumTest {
using SafeTransferLib for ERC20;

function setUp() public override {
if (block.chainid != 1) return;

super.setUp();

bundler = new EthereumStEthBundlerMock();
}

function testStakeEthZeroAmount() public {
function testStakeEthZeroAmount() public onlyEthereum {
bundle.push(abi.encodeCall(StEthBundler.stakeEth, (0, 0, address(0))));

vm.expectRevert(bytes(ErrorsLib.ZERO_AMOUNT));
vm.prank(USER);
bundler.multicall(bundle);
}

function testStakeEth(uint256 amount) public {
function testStakeEth(uint256 amount) public onlyEthereum {
amount = bound(amount, MIN_AMOUNT, 10_000 ether);

uint256 shares = IStEth(ST_ETH).getSharesByPooledEth(amount);
Expand All @@ -49,7 +51,7 @@ contract EthereumStEthBundlerEthereumTest is EthereumTest {
assertApproxEqAbs(ERC20(ST_ETH).balanceOf(RECEIVER), amount, 3, "balanceOf(RECEIVER)");
}

function testStakeEthSlippageAdapts(uint256 amount) public {
function testStakeEthSlippageAdapts(uint256 amount) public onlyEthereum {
amount = bound(amount, MIN_AMOUNT, 10_000 ether);

uint256 shares = IStEth(ST_ETH).getSharesByPooledEth(amount);
Expand All @@ -66,7 +68,7 @@ contract EthereumStEthBundlerEthereumTest is EthereumTest {
assertApproxEqAbs(IStEth(ST_ETH).sharesOf(USER), shares / 2, 2, "shares");
}

function testStakeEthSlippageExceeded(uint256 amount) public {
function testStakeEthSlippageExceeded(uint256 amount) public onlyEthereum {
amount = bound(amount, MIN_AMOUNT, 10_000 ether);

uint256 shares = IStEth(ST_ETH).getSharesByPooledEth(amount);
Expand All @@ -82,15 +84,15 @@ contract EthereumStEthBundlerEthereumTest is EthereumTest {
bundler.multicall{value: amount}(bundle);
}

function testWrapZeroAmount() public {
function testWrapZeroAmount() public onlyEthereum {
bundle.push(abi.encodeCall(StEthBundler.wrapStEth, (0)));

vm.expectRevert(bytes(ErrorsLib.ZERO_AMOUNT));
vm.prank(USER);
bundler.multicall(bundle);
}

function testWrapStEth(uint256 privateKey, uint256 amount) public {
function testWrapStEth(uint256 privateKey, uint256 amount) public onlyEthereum {
address user;
(privateKey, user) = _boundPrivateKey(privateKey);
amount = bound(amount, MIN_AMOUNT, MAX_AMOUNT);
Expand Down Expand Up @@ -121,15 +123,15 @@ contract EthereumStEthBundlerEthereumTest is EthereumTest {
assertEq(ERC20(ST_ETH).balanceOf(RECEIVER), 0, "wstEth.balanceOf(RECEIVER)");
}

function testUnwrapZeroAmount() public {
function testUnwrapZeroAmount() public onlyEthereum {
bundle.push(_unwrapStEth(0));

vm.expectRevert(bytes(ErrorsLib.ZERO_AMOUNT));
vm.prank(USER);
bundler.multicall(bundle);
}

function testUnwrapWstEth(uint256 privateKey, uint256 amount) public {
function testUnwrapWstEth(uint256 privateKey, uint256 amount) public onlyEthereum {
address user;
(privateKey, user) = _boundPrivateKey(privateKey);
amount = bound(amount, MIN_AMOUNT, MAX_AMOUNT);
Expand Down
5 changes: 5 additions & 0 deletions test/forge/ethereum/helpers/EthereumTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import "../../../../config/Configured.sol";
import "../../helpers/ForkTest.sol";

contract EthereumTest is Configured, ForkTest {
modifier onlyEthereum() {
vm.skip(block.chainid != 1);
_;
}

function deal(address asset, address recipient, uint256 amount) internal virtual override {
if (asset == ST_ETH) {
if (amount == 0) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ contract AaveV2MigrationBundlerEthereumTest is EthereumMigrationTest {
uint256 borrowed = 1 ether;

function setUp() public override {
if (block.chainid != 1) return;

super.setUp();

_initMarket(DAI, WETH);
Expand All @@ -30,28 +32,28 @@ contract AaveV2MigrationBundlerEthereumTest is EthereumMigrationTest {
bundler = new AaveV2MigrationBundlerV2(address(morpho), AAVE_V2_POOL, WST_ETH);
}

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

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

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

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

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

vm.expectRevert(bytes(ErrorsLib.ZERO_AMOUNT));
bundler.multicall(bundle);
}

function testMigrateBorrowerWithPermit2(uint256 privateKey) public {
function testMigrateBorrowerWithPermit2(uint256 privateKey) public onlyEthereum {
address user;
(privateKey, user) = _boundPrivateKey(privateKey);

Expand Down Expand Up @@ -88,7 +90,7 @@ contract AaveV2MigrationBundlerEthereumTest is EthereumMigrationTest {
_assertBorrowerPosition(collateralSupplied, borrowed, user, address(bundler));
}

function testMigrateBorrowerDaiToSDaiWithPermit2(uint256 privateKey) public {
function testMigrateBorrowerDaiToSDaiWithPermit2(uint256 privateKey) public onlyEthereum {
address user;
(privateKey, user) = _boundPrivateKey(privateKey);

Expand Down Expand Up @@ -129,7 +131,7 @@ contract AaveV2MigrationBundlerEthereumTest is EthereumMigrationTest {
_assertBorrowerPosition(sDaiAmount, borrowed, user, address(bundler));
}

function testMigrateStEthPositionWithPermit2(uint256 privateKey) public {
function testMigrateStEthPositionWithPermit2(uint256 privateKey) public onlyEthereum {
address user;
(privateKey, user) = _boundPrivateKey(privateKey);

Expand Down Expand Up @@ -175,7 +177,7 @@ contract AaveV2MigrationBundlerEthereumTest is EthereumMigrationTest {
_assertBorrowerPosition(wstEthAmount, borrowed, user, address(bundler));
}

function testMigrateSupplierWithPermit2(uint256 privateKey, uint256 supplied) public {
function testMigrateSupplierWithPermit2(uint256 privateKey, uint256 supplied) public onlyEthereum {
address user;
(privateKey, user) = _boundPrivateKey(privateKey);
supplied = bound(supplied, 100, 100 ether);
Expand Down Expand Up @@ -204,7 +206,7 @@ contract AaveV2MigrationBundlerEthereumTest is EthereumMigrationTest {
_assertSupplierPosition(supplied, user, address(bundler));
}

function testMigrateSupplierToVaultWithPermit2(uint256 privateKey, uint256 supplied) public {
function testMigrateSupplierToVaultWithPermit2(uint256 privateKey, uint256 supplied) public onlyEthereum {
address user;
(privateKey, user) = _boundPrivateKey(privateKey);
supplied = bound(supplied, 100, 100 ether);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ contract AaveV3MigrationBundlerEthereumTest is EthereumMigrationTest {
bundler.multicall(bundle);
}

function testMigrateBorrowerWithATokenPermit(uint256 privateKey) public {
function testMigrateBorrowerWithATokenPermit(uint256 privateKey) public onlyEthereum {
address user;
(privateKey, user) = _boundPrivateKey(privateKey);

Expand Down Expand Up @@ -79,7 +79,7 @@ contract AaveV3MigrationBundlerEthereumTest is EthereumMigrationTest {
_assertBorrowerPosition(collateralSupplied, borrowed, user, address(bundler));
}

function testMigrateBorrowerWithPermit2(uint256 privateKey) public {
function testMigrateBorrowerWithPermit2(uint256 privateKey) public onlyEthereum {
address user;
(privateKey, user) = _boundPrivateKey(privateKey);

Expand Down Expand Up @@ -116,7 +116,7 @@ contract AaveV3MigrationBundlerEthereumTest is EthereumMigrationTest {
_assertBorrowerPosition(collateralSupplied, borrowed, user, address(bundler));
}

function testMigrateUSDTPositionWithPermit2(uint256 privateKey) public {
function testMigrateUSDTPositionWithPermit2(uint256 privateKey) public onlyEthereum {
address user;
(privateKey, user) = _boundPrivateKey(privateKey);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ contract AaveV3OptimizerMigrationBundlerEthereumTest is EthereumMigrationTest {
uint256 borrowed = 1 ether;

function setUp() public override {
if (block.chainid != 1) return;

super.setUp();

_initMarket(DAI, WETH);
Expand All @@ -28,21 +30,21 @@ contract AaveV3OptimizerMigrationBundlerEthereumTest is EthereumMigrationTest {
bundler = new AaveV3OptimizerMigrationBundlerV2(address(morpho), address(AAVE_V3_OPTIMIZER));
}

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

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

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

vm.expectRevert(bytes(ErrorsLib.ZERO_AMOUNT));
bundler.multicall(bundle);
}

function testAaveV3OtimizerAuthorizationWithSigRevert(uint256 privateKey, address owner) public {
function testAaveV3OtimizerAuthorizationWithSigRevert(uint256 privateKey, address owner) public onlyEthereum {
address user;
(privateKey, user) = _boundPrivateKey(privateKey);

Expand All @@ -68,7 +70,7 @@ contract AaveV3OptimizerMigrationBundlerEthereumTest is EthereumMigrationTest {
bundler.multicall(bundle);
}

function testMigrateBorrowerWithOptimizerPermit(uint256 privateKey) public {
function testMigrateBorrowerWithOptimizerPermit(uint256 privateKey) public onlyEthereum {
address user;
(privateKey, user) = _boundPrivateKey(privateKey);

Expand Down Expand Up @@ -99,7 +101,7 @@ contract AaveV3OptimizerMigrationBundlerEthereumTest is EthereumMigrationTest {
_assertBorrowerPosition(collateralSupplied, borrowed, user, address(bundler));
}

function testMigrateUSDTBorrowerWithOptimizerPermit(uint256 privateKey) public {
function testMigrateUSDTBorrowerWithOptimizerPermit(uint256 privateKey) public onlyEthereum {
address user;
(privateKey, user) = _boundPrivateKey(privateKey);

Expand Down Expand Up @@ -135,7 +137,7 @@ contract AaveV3OptimizerMigrationBundlerEthereumTest is EthereumMigrationTest {
_assertBorrowerPosition(amountUsdt, borrowed, user, address(bundler));
}

function testMigrateSupplierWithOptimizerPermit(uint256 privateKey, uint256 supplied) public {
function testMigrateSupplierWithOptimizerPermit(uint256 privateKey, uint256 supplied) public onlyEthereum {
address user;
(privateKey, user) = _boundPrivateKey(privateKey);
supplied = bound(supplied, 100, 100 ether);
Expand All @@ -158,7 +160,7 @@ contract AaveV3OptimizerMigrationBundlerEthereumTest is EthereumMigrationTest {
_assertSupplierPosition(supplied, user, address(bundler));
}

function testMigrateSupplierToVaultWithOptimizerPermit(uint256 privateKey, uint256 supplied) public {
function testMigrateSupplierToVaultWithOptimizerPermit(uint256 privateKey, uint256 supplied) public onlyEthereum {
address user;
(privateKey, user) = _boundPrivateKey(privateKey);
supplied = bound(supplied, 100, 100 ether);
Expand All @@ -181,7 +183,7 @@ contract AaveV3OptimizerMigrationBundlerEthereumTest is EthereumMigrationTest {
_assertVaultSupplierPosition(supplied, user, address(bundler));
}

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

Signature memory sig;
Expand All @@ -192,7 +194,7 @@ contract AaveV3OptimizerMigrationBundlerEthereumTest is EthereumMigrationTest {
);
}

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

vm.expectRevert(bytes(ErrorsLib.UNINITIATED));
Expand All @@ -201,7 +203,7 @@ contract AaveV3OptimizerMigrationBundlerEthereumTest is EthereumMigrationTest {
);
}

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

vm.expectRevert(bytes(ErrorsLib.UNINITIATED));
Expand Down
Loading

0 comments on commit 7a711c1

Please sign in to comment.