diff --git a/test/prod/ProdTest.sol b/test/prod/ProdTest.sol new file mode 100644 index 000000000..136ecc1da --- /dev/null +++ b/test/prod/ProdTest.sol @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: AGPL-3.0-only +pragma solidity ^0.8.0; + +import {SafeTransferLib, ERC20} from "@rari-capital/solmate/src/utils/SafeTransferLib.sol"; + +import {PercentageMath} from "@morpho-dao/morpho-utils/math/PercentageMath.sol"; +import {Math} from "@morpho-dao/morpho-utils/math/Math.sol"; +import {WadRayMath} from "@morpho-dao/morpho-utils/math/WadRayMath.sol"; + +import {BaseConfig} from "config/BaseConfig.sol"; +import "@forge-std/console.sol"; +import "@forge-std/Test.sol"; + +contract ProdTest is Test, BaseConfig { + // Needed because AAVE packs the balance struct. + function dealAave(address who, uint104 amount) public { + // The slot of the balance struct "_balances" is 0. + bytes32 slot = keccak256(abi.encode(who, uint256(0))); + bytes32 initialValue = vm.load(aave, slot); + // The balance is stored in the first 104 bits. + bytes32 finalValue = ((initialValue >> 104) << 104) | bytes32(uint256(amount)); + vm.store(aave, slot, finalValue); + require(ERC20(aave).balanceOf(who) == uint256(amount)); + } +} diff --git a/test/prod/aave-v2/setup/TestSetup.sol b/test/prod/aave-v2/setup/TestSetup.sol index 3cb76d36c..2c3294ace 100644 --- a/test/prod/aave-v2/setup/TestSetup.sol +++ b/test/prod/aave-v2/setup/TestSetup.sol @@ -1,15 +1,13 @@ // SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; +import "../../ProdTest.sol"; + import "src/aave-v2/interfaces/aave/IVariableDebtToken.sol"; import "src/aave-v2/interfaces/aave/IAToken.sol"; import "src/aave-v2/interfaces/lido/ILido.sol"; import {ReserveConfiguration} from "src/aave-v2/libraries/aave/ReserveConfiguration.sol"; -import "@morpho-dao/morpho-utils/math/WadRayMath.sol"; -import "@morpho-dao/morpho-utils/math/PercentageMath.sol"; -import "@rari-capital/solmate/src/utils/SafeTransferLib.sol"; -import "@morpho-dao/morpho-utils/math/Math.sol"; import {InterestRatesManager} from "src/aave-v2/InterestRatesManager.sol"; import {MatchingEngine} from "src/aave-v2/MatchingEngine.sol"; @@ -20,10 +18,8 @@ import "src/aave-v2/Morpho.sol"; import {User} from "../../../aave-v2/helpers/User.sol"; import "config/aave-v2/Config.sol"; -import "@forge-std/console.sol"; -import "@forge-std/Test.sol"; -contract TestSetup is Config, Test { +contract TestSetup is Config, ProdTest { using ReserveConfiguration for DataTypes.ReserveConfigurationMap; using WadRayMath for uint256; using PercentageMath for uint256; @@ -76,17 +72,6 @@ contract TestSetup is Config, Test { interestRatesManager = morpho.interestRatesManager(); } - // Needed because AAVE packs the balance struct. - function dealAave(address who, uint104 amount) public { - // The slot of the balance struct "_balances" is 0. - bytes32 slot = keccak256(abi.encode(who, uint256(0))); - bytes32 initialValue = vm.load(aave, slot); - // The balance is stored in the first 104 bits. - bytes32 finalValue = initialValue | bytes32(uint256(amount)); - vm.store(aave, slot, finalValue); - require(IERC20(aave).balanceOf(who) == uint256(amount)); - } - function initUsers() internal { user = new User(morpho); diff --git a/test/prod/compound/setup/TestSetup.sol b/test/prod/compound/setup/TestSetup.sol index cc9323398..07bd1ca39 100644 --- a/test/prod/compound/setup/TestSetup.sol +++ b/test/prod/compound/setup/TestSetup.sol @@ -1,12 +1,10 @@ // SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; -import {IERC20} from "src/aave-v2/interfaces/aave/IERC20.sol"; +import "../../ProdTest.sol"; import {CompoundMath} from "@morpho-dao/morpho-utils/math/CompoundMath.sol"; -import {PercentageMath} from "@morpho-dao/morpho-utils/math/PercentageMath.sol"; -import {SafeTransferLib, ERC20} from "@rari-capital/solmate/src/utils/SafeTransferLib.sol"; -import {Math} from "@morpho-dao/morpho-utils/math/Math.sol"; +import {SafeTransferLib} from "@rari-capital/solmate/src/utils/SafeTransferLib.sol"; import {Types} from "src/compound/libraries/Types.sol"; import {PositionsManager} from "src/compound/PositionsManager.sol"; @@ -14,10 +12,8 @@ import {InterestRatesManager} from "src/compound/InterestRatesManager.sol"; import {User} from "../../../compound/helpers/User.sol"; import "config/compound/Config.sol"; -import "@forge-std/console.sol"; -import "@forge-std/Test.sol"; -contract TestSetup is Config, Test { +contract TestSetup is Config, ProdTest { using CompoundMath for uint256; using PercentageMath for uint256; using SafeTransferLib for ERC20; @@ -69,17 +65,6 @@ contract TestSetup is Config, Test { rewardsManagerProxy = TransparentUpgradeableProxy(payable(address(rewardsManager))); } - // Needed because AAVE packs the balance struct. - function dealAave(address who, uint104 amount) public { - // The slot of the balance struct "_balances" is 0. - bytes32 slot = keccak256(abi.encode(who, uint256(0))); - bytes32 initialValue = vm.load(aave, slot); - // The balance is stored in the first 104 bits. - bytes32 finalValue = initialValue | bytes32(uint256(amount)); - vm.store(aave, slot, finalValue); - require(IERC20(aave).balanceOf(who) == uint256(amount)); - } - function initUsers() internal { user = new User(morpho);