From 70c95d9805d35be4eff0612ba0f54b4f6e1593ce Mon Sep 17 00:00:00 2001 From: Jean-Grimal Date: Thu, 14 Sep 2023 15:16:57 +0200 Subject: [PATCH 1/5] refactor: fork setup --- config/Configured.sol | 7 ---- config/ConfiguredEthereumMainnet.sol | 33 +++++++++++++++++++ config/ethereum-mainnet.json | 6 +--- ...st.sol => EthereumBundlerEthereumTest.sol} | 8 ++--- test/forge/ethereum-mainnet/EthereumTest.sol | 16 +++++++++ ...est.sol => WNativeBundlerEthereumTest.sol} | 8 ++--- .../migration/BaseMigrationTest.sol | 8 ++--- test/forge/helpers/ForkTest.sol | 26 +-------------- 8 files changed, 57 insertions(+), 55 deletions(-) create mode 100644 config/ConfiguredEthereumMainnet.sol rename test/forge/ethereum-mainnet/{EthereumBundlerEthereumEthereumTest.sol => EthereumBundlerEthereumTest.sol} (95%) create mode 100644 test/forge/ethereum-mainnet/EthereumTest.sol rename test/forge/ethereum-mainnet/{WNativeBundlerEthereumEthereumTest.sol => WNativeBundlerEthereumTest.sol} (95%) diff --git a/config/Configured.sol b/config/Configured.sol index 03b894c2..c066a88e 100644 --- a/config/Configured.sol +++ b/config/Configured.sol @@ -18,9 +18,7 @@ abstract contract Configured is StdChains { address internal LINK; address internal WBTC; address internal WETH; - address internal CB_ETH; address internal WNATIVE; - address[] internal lsdNatives; address[] internal allAssets; address internal AAVE_V2_POOL; @@ -58,10 +56,8 @@ abstract contract Configured is StdChains { LINK = CONFIG.getAddress("LINK"); WBTC = CONFIG.getAddress("WBTC"); WETH = CONFIG.getAddress("WETH"); - CB_ETH = CONFIG.getAddress("cbETH"); WNATIVE = CONFIG.getWrappedNative(); - lsdNatives = CONFIG.getLsdNatives(); allAssets = [DAI, USDC, USDT, LINK, WBTC, WETH]; ConfigMarket[] memory allConfigMarkets = CONFIG.getMarkets(); @@ -69,9 +65,6 @@ abstract contract Configured is StdChains { configMarkets.push(allConfigMarkets[i]); } - for (uint256 i; i < lsdNatives.length; ++i) { - allAssets.push(lsdNatives[i]); - } AAVE_V3_POOL = CONFIG.getAddress("aaveV3Pool"); AAVE_V2_POOL = CONFIG.getAddress("aaveV2Pool"); AAVE_V3_OPTIMIZER = CONFIG.getAddress("aaveV3Optimizer"); diff --git a/config/ConfiguredEthereumMainnet.sol b/config/ConfiguredEthereumMainnet.sol new file mode 100644 index 00000000..2fbbc2e4 --- /dev/null +++ b/config/ConfiguredEthereumMainnet.sol @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: AGPL-3.0-only +pragma solidity ^0.8.0; + +import "./Configured.sol"; + +abstract contract ConfiguredEthereumMainnet is Configured { + using ConfigLib for Config; + + address internal ST_ETH; + address internal WST_ETH; + address internal CB_ETH; + address internal R_ETH; + address[] internal allEthereumMainnetAssets; + + function _network() internal view virtual override returns (string memory){ + return "ethereum-mainnet"; + } + + function _loadConfig() internal virtual override { + super._loadConfig(); + + ST_ETH = CONFIG.getAddress("stETH"); + WST_ETH = CONFIG.getAddress("wstETH"); + CB_ETH = CONFIG.getAddress("cbETH"); + R_ETH = CONFIG.getAddress("rETH"); + + allEthereumMainnetAssets = [ST_ETH, WST_ETH, CB_ETH, R_ETH]; + + for (uint256 i; i < allEthereumMainnetAssets.length; ++i) { + allAssets.push(allEthereumMainnetAssets[i]); + } + } +} diff --git a/config/ethereum-mainnet.json b/config/ethereum-mainnet.json index 0daf282a..50df63cc 100644 --- a/config/ethereum-mainnet.json +++ b/config/ethereum-mainnet.json @@ -15,15 +15,11 @@ "LINK": "0x514910771AF9Ca656af840dff83E8264EcF986CA", "WBTC": "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599", "WETH": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", + "stETH": "0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84", "wstETH": "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0", "cbETH": "0xBe9895146f7AF43049ca1c1AE358B0541Ea49704", "rETH": "0xae78736Cd615f374D3085123A210448E74Fc6393", "wrappedNative": "WETH", - "lsdNatives": [ - "wstETH", - "cbETH", - "rETH" - ], "aaveV2Pool": "0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9", "aaveV3Pool": "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2", "aaveV3Optimizer": "0x33333aea097c193e66081E930c33020272b33333", diff --git a/test/forge/ethereum-mainnet/EthereumBundlerEthereumEthereumTest.sol b/test/forge/ethereum-mainnet/EthereumBundlerEthereumTest.sol similarity index 95% rename from test/forge/ethereum-mainnet/EthereumBundlerEthereumEthereumTest.sol rename to test/forge/ethereum-mainnet/EthereumBundlerEthereumTest.sol index 2d31e81f..6c8a66c7 100644 --- a/test/forge/ethereum-mainnet/EthereumBundlerEthereumEthereumTest.sol +++ b/test/forge/ethereum-mainnet/EthereumBundlerEthereumTest.sol @@ -9,9 +9,9 @@ import "contracts/ethereum-mainnet/EthereumBundler.sol"; import {MorphoBundler} from "contracts/MorphoBundler.sol"; import {Permit2Bundler} from "contracts/Permit2Bundler.sol"; -import "../helpers/ForkTest.sol"; +import "./EthereumTest.sol"; -contract EthereumBundlerEthereumTest is ForkTest { +contract EthereumBundlerEthereumTest is EthereumTest { using MathLib for uint256; using MorphoLib for IMorpho; using MorphoBalancesLib for IMorpho; @@ -20,10 +20,6 @@ contract EthereumBundlerEthereumTest is ForkTest { EthereumBundler private bundler; - function _network() internal pure override returns (string memory) { - return "ethereum-mainnet"; - } - function setUp() public override { super.setUp(); diff --git a/test/forge/ethereum-mainnet/EthereumTest.sol b/test/forge/ethereum-mainnet/EthereumTest.sol new file mode 100644 index 00000000..83853a74 --- /dev/null +++ b/test/forge/ethereum-mainnet/EthereumTest.sol @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +pragma solidity ^0.8.0; + +import "../helpers/ForkTest.sol"; +import "config/ConfiguredEthereumMainnet.sol"; + +contract EthereumTest is ConfiguredEthereumMainnet, ForkTest { + + function _network() internal view virtual override(Configured, ConfiguredEthereumMainnet) returns (string memory){ + return ConfiguredEthereumMainnet._network(); + } + + function _loadConfig() internal virtual override(Configured, ConfiguredEthereumMainnet) { + ConfiguredEthereumMainnet._loadConfig(); + } +} diff --git a/test/forge/ethereum-mainnet/WNativeBundlerEthereumEthereumTest.sol b/test/forge/ethereum-mainnet/WNativeBundlerEthereumTest.sol similarity index 95% rename from test/forge/ethereum-mainnet/WNativeBundlerEthereumEthereumTest.sol rename to test/forge/ethereum-mainnet/WNativeBundlerEthereumTest.sol index ab6f03a6..26941771 100644 --- a/test/forge/ethereum-mainnet/WNativeBundlerEthereumEthereumTest.sol +++ b/test/forge/ethereum-mainnet/WNativeBundlerEthereumTest.sol @@ -3,17 +3,13 @@ pragma solidity ^0.8.0; import {ErrorsLib as BulkerErrorsLib} from "contracts/libraries/ErrorsLib.sol"; -import "../helpers/ForkTest.sol"; +import "./EthereumTest.sol"; import "../mocks/WNativeBundlerMock.sol"; -contract WNativeBundlerEthereumTest is ForkTest { +contract WNativeBundlerEthereumTest is EthereumTest { WNativeBundlerMock private bundler; - function _network() internal pure override returns (string memory) { - return "ethereum-mainnet"; - } - function setUp() public override { super.setUp(); diff --git a/test/forge/ethereum-mainnet/migration/BaseMigrationTest.sol b/test/forge/ethereum-mainnet/migration/BaseMigrationTest.sol index 135c75ed..d0633ddc 100644 --- a/test/forge/ethereum-mainnet/migration/BaseMigrationTest.sol +++ b/test/forge/ethereum-mainnet/migration/BaseMigrationTest.sol @@ -9,13 +9,13 @@ import {MarketParamsLib} from "@morpho-blue/libraries/MarketParamsLib.sol"; import {MorphoLib} from "@morpho-blue/libraries/periphery/MorphoLib.sol"; import {MorphoBalancesLib} from "@morpho-blue/libraries/periphery/MorphoBalancesLib.sol"; -import "../../helpers/ForkTest.sol"; +import "../EthereumTest.sol"; import {MorphoBundler} from "contracts/MorphoBundler.sol"; import {ERC4626Bundler} from "contracts/ERC4626Bundler.sol"; import {Permit2Bundler} from "contracts/Permit2Bundler.sol"; import {ERC4626Mock} from "../../mocks/ERC4626Mock.sol"; -contract BaseMigrationTest is ForkTest { +contract BaseMigrationTest is EthereumTest { using SafeTransferLib for ERC20; using MarketParamsLib for MarketParams; using MorphoLib for IMorpho; @@ -49,10 +49,6 @@ contract BaseMigrationTest is ForkTest { return (privateKey, user); } - function _network() internal pure override returns (string memory) { - return "ethereum-mainnet"; - } - function _morphoSetAuthorizationWithSigCall( uint256 privateKey, address authorized, diff --git a/test/forge/helpers/ForkTest.sol b/test/forge/helpers/ForkTest.sol index ecee5120..13346bc6 100644 --- a/test/forge/helpers/ForkTest.sol +++ b/test/forge/helpers/ForkTest.sol @@ -22,7 +22,7 @@ abstract contract ForkTest is BaseTest, Configured { _initConfig(); _loadConfig(); - _setBalances(address(this), type(uint96).max); + _fork(); } function setUp() public virtual override { @@ -58,12 +58,6 @@ abstract contract ForkTest is BaseTest, Configured { vm.chainId(CONFIG.getChainId()); } - function _loadConfig() internal virtual override { - super._loadConfig(); - - _fork(); - } - function _label() internal virtual { for (uint256 i; i < allAssets.length; ++i) { address asset = allAssets[i]; @@ -73,14 +67,6 @@ abstract contract ForkTest is BaseTest, Configured { } } - function _setBalances(address user, uint256 balance) internal { - for (uint256 i; i < allAssets.length; ++i) { - address asset = allAssets[i]; - - deal(asset, user, balance / (10 ** (18 - ERC20(asset).decimals()))); - } - } - /// @dev Avoids to revert because of AAVE token snapshots: /// https://github.com/aave/aave-token-v2/blob/master/contracts/token/base/GovernancePowerDelegationERC20.sol#L174 function _deal(address asset, address user, uint256 amount) internal { @@ -103,20 +89,10 @@ abstract contract ForkTest is BaseTest, Configured { } } - function _assumeNotLsdNative(address input) internal view { - for (uint256 i; i < lsdNatives.length; ++i) { - vm.assume(input != lsdNatives[i]); - } - } - function _randomAsset(uint256 seed) internal view returns (address) { return allAssets[seed % allAssets.length]; } - function _randomLsdNative(uint256 seed) internal view returns (address) { - return lsdNatives[seed % lsdNatives.length]; - } - function _randomMarketParams(uint256 seed) internal view returns (MarketParams memory) { return allMarketParams[seed % allMarketParams.length]; } From a7db1a91e8bded26c76d603fa501967d63164e08 Mon Sep 17 00:00:00 2001 From: Jean-Grimal Date: Thu, 14 Sep 2023 15:19:38 +0200 Subject: [PATCH 2/5] fix: lint --- test/forge/ethereum-mainnet/EthereumTest.sol | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/forge/ethereum-mainnet/EthereumTest.sol b/test/forge/ethereum-mainnet/EthereumTest.sol index 83853a74..58dbfc55 100644 --- a/test/forge/ethereum-mainnet/EthereumTest.sol +++ b/test/forge/ethereum-mainnet/EthereumTest.sol @@ -5,8 +5,7 @@ import "../helpers/ForkTest.sol"; import "config/ConfiguredEthereumMainnet.sol"; contract EthereumTest is ConfiguredEthereumMainnet, ForkTest { - - function _network() internal view virtual override(Configured, ConfiguredEthereumMainnet) returns (string memory){ + function _network() internal view virtual override(Configured, ConfiguredEthereumMainnet) returns (string memory) { return ConfiguredEthereumMainnet._network(); } From bd86e3125672990de380d10b31742964f9f8cbf6 Mon Sep 17 00:00:00 2001 From: Jean-Grimal Date: Fri, 15 Sep 2023 11:09:44 +0200 Subject: [PATCH 3/5] fix: apply suggestions --- ...redEthereumMainnet.sol => ConfiguredEthereum.sol} | 6 ++---- test/forge/ethereum-mainnet/EthereumTest.sol | 12 ++++++------ 2 files changed, 8 insertions(+), 10 deletions(-) rename config/{ConfiguredEthereumMainnet.sol => ConfiguredEthereum.sol} (79%) diff --git a/config/ConfiguredEthereumMainnet.sol b/config/ConfiguredEthereum.sol similarity index 79% rename from config/ConfiguredEthereumMainnet.sol rename to config/ConfiguredEthereum.sol index 2fbbc2e4..ddfcbef8 100644 --- a/config/ConfiguredEthereumMainnet.sol +++ b/config/ConfiguredEthereum.sol @@ -3,13 +3,12 @@ pragma solidity ^0.8.0; import "./Configured.sol"; -abstract contract ConfiguredEthereumMainnet is Configured { +abstract contract ConfiguredEthereum is Configured { using ConfigLib for Config; address internal ST_ETH; address internal WST_ETH; address internal CB_ETH; - address internal R_ETH; address[] internal allEthereumMainnetAssets; function _network() internal view virtual override returns (string memory){ @@ -22,9 +21,8 @@ abstract contract ConfiguredEthereumMainnet is Configured { ST_ETH = CONFIG.getAddress("stETH"); WST_ETH = CONFIG.getAddress("wstETH"); CB_ETH = CONFIG.getAddress("cbETH"); - R_ETH = CONFIG.getAddress("rETH"); - allEthereumMainnetAssets = [ST_ETH, WST_ETH, CB_ETH, R_ETH]; + allEthereumMainnetAssets = [ST_ETH, WST_ETH, CB_ETH]; for (uint256 i; i < allEthereumMainnetAssets.length; ++i) { allAssets.push(allEthereumMainnetAssets[i]); diff --git a/test/forge/ethereum-mainnet/EthereumTest.sol b/test/forge/ethereum-mainnet/EthereumTest.sol index 58dbfc55..1eb4dda0 100644 --- a/test/forge/ethereum-mainnet/EthereumTest.sol +++ b/test/forge/ethereum-mainnet/EthereumTest.sol @@ -2,14 +2,14 @@ pragma solidity ^0.8.0; import "../helpers/ForkTest.sol"; -import "config/ConfiguredEthereumMainnet.sol"; +import "config/ConfiguredEthereum.sol"; -contract EthereumTest is ConfiguredEthereumMainnet, ForkTest { - function _network() internal view virtual override(Configured, ConfiguredEthereumMainnet) returns (string memory) { - return ConfiguredEthereumMainnet._network(); +contract EthereumTest is ConfiguredEthereum, ForkTest { + function _network() internal view virtual override(Configured, ConfiguredEthereum) returns (string memory) { + return ConfiguredEthereum._network(); } - function _loadConfig() internal virtual override(Configured, ConfiguredEthereumMainnet) { - ConfiguredEthereumMainnet._loadConfig(); + function _loadConfig() internal virtual override(Configured, ConfiguredEthereum) { + ConfiguredEthereum._loadConfig(); } } From 82aead03b77f5be644fa6e70d8a6c69c6af94b38 Mon Sep 17 00:00:00 2001 From: Jean-Grimal Date: Fri, 15 Sep 2023 12:32:13 +0200 Subject: [PATCH 4/5] fix: reduce ethereum tests size --- .github/workflows/foundry.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/foundry.yml b/.github/workflows/foundry.yml index 65e92390..28edb198 100644 --- a/.github/workflows/foundry.yml +++ b/.github/workflows/foundry.yml @@ -126,14 +126,14 @@ jobs: type: ["slow", "fast"] include: - type: "slow" - fuzz-runs: 1024 + fuzz-runs: 256 max-test-rejects: 65536 - invariant-runs: 64 + invariant-runs: 16 invariant-depth: 1024 - type: "fast" - fuzz-runs: 256 + fuzz-runs: 64 max-test-rejects: 65536 - invariant-runs: 16 + invariant-runs: 4 invariant-depth: 256 steps: From 8813f56621a3209c6ad341ee925013bc4df87542 Mon Sep 17 00:00:00 2001 From: Jean-Grimal Date: Fri, 15 Sep 2023 13:48:42 +0200 Subject: [PATCH 5/5] fix: reduce ethereum tests size --- .github/workflows/foundry.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/foundry.yml b/.github/workflows/foundry.yml index 28edb198..ab86b0f1 100644 --- a/.github/workflows/foundry.yml +++ b/.github/workflows/foundry.yml @@ -79,8 +79,8 @@ jobs: type: ["slow", "fast"] include: - type: "slow" - fuzz-runs: 100000 - max-test-rejects: 500000 + fuzz-runs: 25000 + max-test-rejects: 10000 invariant-runs: 64 invariant-depth: 1024 - type: "fast" @@ -126,12 +126,12 @@ jobs: type: ["slow", "fast"] include: - type: "slow" - fuzz-runs: 256 + fuzz-runs: 128 max-test-rejects: 65536 invariant-runs: 16 invariant-depth: 1024 - type: "fast" - fuzz-runs: 64 + fuzz-runs: 32 max-test-rejects: 65536 invariant-runs: 4 invariant-depth: 256