Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test fixes post Aave3.2 #880

Merged
merged 55 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
db1c408
test: quick fixes to run v3.2 tests
QGarchery Oct 9, 2024
c270f26
fix: deal AAVE
QGarchery Oct 10, 2024
da7cd2f
chore: re-add AAVE
QGarchery Oct 10, 2024
f55417a
fix: changes to pool configurator
QGarchery Oct 10, 2024
f13147c
fix: bound in deposit correct amount
QGarchery Oct 10, 2024
2bde7ef
test: passing at 17M
MathisGD Oct 10, 2024
69db311
test: fix max aave balance
MathisGD Oct 12, 2024
a8c9ca4
test: don't call stableDebtToken
MathisGD Oct 12, 2024
ba92e8d
test: fix some more tests
MathisGD Oct 12, 2024
7094ffd
test: fix liquidity rounding issue
MathisGD Oct 13, 2024
616086b
fix: deal AAVE
QGarchery Oct 13, 2024
0c6d3ed
fix: warnings on pure/view functions
QGarchery Oct 13, 2024
952e646
fix: all view/pure visibility
QGarchery Oct 13, 2024
2c4fc43
chore: revert workflow change
QGarchery Oct 13, 2024
cc750d8
test: fix 2 rewards tests
MathisGD Oct 13, 2024
83f3fdf
test: remove aave token
MathisGD Oct 14, 2024
dfc02f2
test: higher rounding tolerance in testShouldWithdrawAllCollateral
MathisGD Oct 14, 2024
2754f2e
fix: bound deal for AAVE token
QGarchery Oct 14, 2024
c4d5bbc
chore: add back AAVE
QGarchery Oct 14, 2024
36700ce
test: fix invariantBalanceOf, morpho receiver of borrow
MathisGD Oct 14, 2024
be7d1f9
fix: underflow rewards computation
QGarchery Oct 14, 2024
b57d0f8
refactor: show failures in integration tests
QGarchery Oct 14, 2024
1520745
fix: end distribution, and reward list increase
QGarchery Oct 14, 2024
0d88a9a
fix: indexes in the unclaimed array
QGarchery Oct 14, 2024
dbce870
test: fix invariantCannotBorrowOverLtv
MathisGD Oct 14, 2024
c2a345e
Merge remote-tracking branch 'origin/test/aave-v3.2' into test/aave-v3.2
MathisGD Oct 14, 2024
af1a74c
chore: bump action versions
QGarchery Oct 14, 2024
e84eb4a
Merge pull request #885 from morpho-org/test/update-ci-dependencies
QGarchery Oct 14, 2024
4388b5b
fix: diminish block bounds
QGarchery Oct 14, 2024
9573434
fix: reduce timestamp in testSupplyWithPermit2
QGarchery Oct 14, 2024
4bf072c
fix: don't use USDT blacklisted addresses
QGarchery Oct 14, 2024
81fd1a5
chore: reduce number of fuzz runs
QGarchery Oct 15, 2024
0bcfdd7
chore: update CI to avoid cache failures
QGarchery Oct 15, 2024
30a9f53
chore: bump storage check version
QGarchery Oct 15, 2024
ef92f6e
chore: reduce runs on CI too
QGarchery Oct 15, 2024
e090c05
chore: really reduce runs on CI too
QGarchery Oct 15, 2024
7c1da30
chore: move IPoolConfigurator for now
QGarchery Oct 15, 2024
df5f6c9
fix: promote routine can round at every step
QGarchery Oct 15, 2024
6199e7f
test: change naming reward token
MathisGD Oct 15, 2024
7dbda1f
test: fix config issue
MathisGD Oct 16, 2024
b067cfe
fix: gas-report should be integration
QGarchery Oct 16, 2024
26139db
feat: revert fixes on source
MathisGD Oct 16, 2024
d180882
Merge remote-tracking branch 'origin/test/aave-v3.2' into test/aave-v3.2
MathisGD Oct 16, 2024
def2b56
refactor: only test added rewards
QGarchery Oct 16, 2024
ea781de
test: testShouldWithdrawAllP2PSupplyWhenDemotedZero
MathisGD Oct 16, 2024
18eedaf
Merge remote-tracking branch 'origin/test/aave-v3.2' into test/aave-v3.2
MathisGD Oct 16, 2024
39dc3a2
test: fix testShouldWithdrawP2PSupplyWhenBorrowCapExceededWithIdleSupply
MathisGD Oct 16, 2024
991e055
test: fuzz amount in testShouldWithdrawP2PSupplyWhenBorrowCapExceeded…
MathisGD Oct 17, 2024
4682aab
fix: assert promoter balances
QGarchery Oct 17, 2024
d8e86e9
fix: test withdraw idle amount
QGarchery Oct 17, 2024
adbad34
chore: evm build version paris
QGarchery Oct 17, 2024
dde9f1d
refactor: more view functions
QGarchery Oct 17, 2024
4b95237
test: bounds on WETH gateway
QGarchery Oct 17, 2024
fb7a3ba
chore: remove useless test struct
QGarchery Oct 17, 2024
f1fe940
chore: config change now triggers a CI run
QGarchery Oct 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/ethereum-mainnet.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"chainId": 1,
"rpcAlias": "mainnet",
"forkBlockNumber": 16841312,
QGarchery marked this conversation as resolved.
Show resolved Hide resolved
"forkBlockNumber": 0,
"addressesProvider": "0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e",
"morphoDao": "0xcBa28b38103307Ec8dA98377ffF9816C164f9AFa",
"morphoEth": "0x33333aea097c193e66081E930c33020272b33333",
Expand Down
2 changes: 2 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ names = true
sizes = true
libs = ["node_modules", "lib"]
fs_permissions = [{ access = "read", path = "./config/"}]
gas_limit = "18446744073709551615" # 2^64 - 1, to remove the gas limit
evm_version = "shanghai"
QGarchery marked this conversation as resolved.
Show resolved Hide resolved

[fuzz]
runs = 32
Expand Down
411 changes: 411 additions & 0 deletions src/interfaces/aave/IPoolConfigurator.sol
MathisGD marked this conversation as resolved.
Show resolved Hide resolved
MathisGD marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

42 changes: 23 additions & 19 deletions test/helpers/ForkTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {IAToken} from "src/interfaces/aave/IAToken.sol";
import {IAaveOracle} from "@aave-v3-core/interfaces/IAaveOracle.sol";
import {IPriceOracleGetter} from "@aave-v3-core/interfaces/IPriceOracleGetter.sol";
import {IACLManager} from "@aave-v3-core/interfaces/IACLManager.sol";
import {IPoolConfigurator} from "@aave-v3-core/interfaces/IPoolConfigurator.sol";
import {IPoolConfigurator} from "src/interfaces/aave/IPoolConfigurator.sol";
import {IPoolDataProvider} from "@aave-v3-core/interfaces/IPoolDataProvider.sol";
import {IPool, IPoolAddressesProvider} from "@aave-v3-core/interfaces/IPool.sol";
import {IStableDebtToken} from "@aave-v3-core/interfaces/IStableDebtToken.sol";
Expand Down Expand Up @@ -99,6 +99,7 @@ contract ForkTest is BaseTest, Configured {

forkId = forkBlockNumber == 0 ? vm.createSelectFork(rpcUrl) : vm.createSelectFork(rpcUrl, forkBlockNumber);
vm.chainId(config.getChainId());
console.log("fork block number", block.number);
MathisGD marked this conversation as resolved.
Show resolved Hide resolved
}

function _loadConfig() internal virtual override {
Expand Down Expand Up @@ -180,24 +181,31 @@ contract ForkTest is BaseTest, Configured {
}

/// @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 underlying, address user, uint256 amount) internal {
function deal(address underlying, address user, uint256 amount) internal override {
if (amount == 0) return;

if (underlying == weth) deal(weth, weth.balance + amount); // Refill wrapped Ether.

// Needed because AAVE packs the balance struct.
if (underlying == aave) {
uint256 balance = ERC20(underlying).balanceOf(user);

if (amount > balance) ERC20(underlying).safeTransfer(user, amount - balance);
if (amount < balance) {
vm.prank(user);
ERC20(underlying).safeTransfer(address(this), balance - amount);
}
QGarchery marked this conversation as resolved.
Show resolved Hide resolved
// The slot of the balance struct "_balances" is 0.
bytes32 balanceSlot = keccak256(abi.encode(user, uint256(0)));
bytes32 initialValue = vm.load(aave, balanceSlot);
// The balance is stored in the first 104 bits.
bytes32 finalValue = ((initialValue >> 104) << 104) | bytes32(uint256(amount));
vm.store(aave, balanceSlot, finalValue);
require(ERC20(aave).balanceOf(user) == uint256(amount));

uint256 totalSupplyBefore = ERC20(aave).totalSupply();
// The slot of the balance struct "totalSupply" is 2.
bytes32 totalSupplySlot = bytes32(uint256(2));
vm.store(aave, totalSupplySlot, bytes32(totalSupplyBefore + amount));
require(ERC20(aave).totalSupply() == totalSupplyBefore + amount);

return;
}

deal(underlying, user, amount);
if (underlying == weth) super.deal(weth, weth.balance + amount); // Refill wrapped Ether.

super.deal(underlying, user, amount);
}

/// @dev Reverts the fork to its initial fork state.
Expand Down Expand Up @@ -244,14 +252,10 @@ contract ForkTest is BaseTest, Configured {
uint8 eModeCategoryId
) internal {
poolAdmin.setEModeCategory(
eModeCategoryId,
eModeCategory.ltv,
eModeCategory.liquidationThreshold,
eModeCategory.liquidationBonus,
address(1),
""
eModeCategoryId, eModeCategory.ltv, eModeCategory.liquidationThreshold, eModeCategory.liquidationBonus, ""
);
poolAdmin.setAssetEModeCategory(underlying, eModeCategoryId);
poolAdmin.setAssetBorrowableInEMode(underlying, eModeCategoryId, true);
poolAdmin.setAssetCollateralInEMode(underlying, eModeCategoryId, true);
}

function _assumeNotUnderlying(address input) internal view {
Expand Down
4 changes: 2 additions & 2 deletions test/helpers/IntegrationTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ contract IntegrationTest is ForkTest {
internal
bypassSupplyCap(underlying, amount)
{
_deal(underlying, address(this), amount);
deal(underlying, address(this), amount);
ERC20(underlying).safeApprove(address(pool), amount);
pool.deposit(underlying, amount, onBehalf, 0);
}
Expand Down Expand Up @@ -307,7 +307,7 @@ contract IntegrationTest is ForkTest {
uint256 maxIterations
) internal returns (uint256 collateral, uint256 borrowed) {
collateral = collateralMarket.minBorrowCollateral(borrowedMarket, amount, eModeCategoryId);
_deal(collateralMarket.underlying, borrower, collateral);
deal(collateralMarket.underlying, borrower, collateral);

vm.startPrank(borrower);
ERC20(collateralMarket.underlying).safeApprove(address(morpho), collateral);
Expand Down
1 change: 0 additions & 1 deletion test/integration/TestIntegrationBorrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,6 @@ contract TestIntegrationBorrow is IntegrationTest {

TestMarket storage market = testMarkets[_randomUnderlying(seed)];

poolAdmin.setReserveStableRateBorrowing(market.underlying, false);
poolAdmin.setReserveBorrowing(market.underlying, false);

vm.expectRevert(Errors.BorrowNotEnabled.selector);
Expand Down
18 changes: 9 additions & 9 deletions test/integration/TestIntegrationPermit2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ contract TestIntegrationPermit2 is IntegrationTest {
timestamp = bound(timestamp, 0, Math.min(deadline, type(uint48).max) - block.timestamp);
vm.warp(block.timestamp + timestamp);

_deal(market.underlying, delegator, amount);
deal(market.underlying, delegator, amount);

uint256 balanceBefore = ERC20(market.underlying).balanceOf(delegator);
uint256 balanceSupplyBefore = morpho.supplyBalance(market.underlying, delegator);
Expand Down Expand Up @@ -105,7 +105,7 @@ contract TestIntegrationPermit2 is IntegrationTest {
timestamp = bound(timestamp, 0, Math.min(deadline, type(uint48).max) - block.timestamp);
vm.warp(block.timestamp + timestamp);

_deal(market.underlying, delegator, amount);
deal(market.underlying, delegator, amount);

uint256 balanceBefore = ERC20(market.underlying).balanceOf(delegator);
uint256 balanceSupplyBefore = morpho.supplyBalance(market.underlying, delegator);
Expand Down Expand Up @@ -158,7 +158,7 @@ contract TestIntegrationPermit2 is IntegrationTest {
amount = morpho.borrowBalance(market.underlying, onBehalf) - 1;
Types.Signature memory sig = _signPermit2(market.underlying, delegator, spender, amount, deadline, privateKey);

_deal(market.underlying, delegator, amount);
deal(market.underlying, delegator, amount);

uint256 balanceBefore = ERC20(market.underlying).balanceOf(delegator);

Expand Down Expand Up @@ -200,7 +200,7 @@ contract TestIntegrationPermit2 is IntegrationTest {
Types.Signature memory sig =
_signPermit2(market.underlying, delegator, spender, type(uint160).max, deadline, privateKey);

_deal(market.underlying, delegator, type(uint160).max);
deal(market.underlying, delegator, type(uint160).max);

vm.prank(delegator);
morpho.repayWithPermit(market.underlying, type(uint160).max, onBehalf, deadline, sig);
Expand Down Expand Up @@ -232,7 +232,7 @@ contract TestIntegrationPermit2 is IntegrationTest {
vm.prank(delegator);
ERC20(market.underlying).safeApprove(address(PERMIT2), type(uint256).max);

_deal(market.underlying, delegator, amount);
deal(market.underlying, delegator, amount);

timestamp = bound(timestamp, deadline + 1, type(uint256).max);
vm.warp(timestamp);
Expand Down Expand Up @@ -267,7 +267,7 @@ contract TestIntegrationPermit2 is IntegrationTest {
vm.prank(delegator);
ERC20(market.underlying).safeApprove(address(PERMIT2), type(uint256).max);

_deal(market.underlying, delegator, 2 * amount);
deal(market.underlying, delegator, 2 * amount);

timestamp = bound(timestamp, 0, Math.min(deadline, type(uint48).max) - block.timestamp);
vm.warp(block.timestamp + timestamp);
Expand Down Expand Up @@ -305,7 +305,7 @@ contract TestIntegrationPermit2 is IntegrationTest {
vm.prank(delegator);
ERC20(market.underlying).safeApprove(address(PERMIT2), type(uint256).max);

_deal(market.underlying, delegator, amount);
deal(market.underlying, delegator, amount);

timestamp = bound(timestamp, 0, Math.min(deadline, type(uint48).max) - block.timestamp);
vm.warp(block.timestamp + timestamp);
Expand Down Expand Up @@ -339,7 +339,7 @@ contract TestIntegrationPermit2 is IntegrationTest {
vm.prank(delegator);
ERC20(market.underlying).safeApprove(address(PERMIT2), type(uint256).max);

_deal(market.underlying, delegator, amount);
deal(market.underlying, delegator, amount);

timestamp = bound(timestamp, 0, Math.min(deadline, type(uint48).max) - block.timestamp);
vm.warp(block.timestamp + timestamp);
Expand Down Expand Up @@ -376,7 +376,7 @@ contract TestIntegrationPermit2 is IntegrationTest {
vm.prank(delegator);
ERC20(market.underlying).safeApprove(address(PERMIT2), type(uint256).max);

_deal(market.underlying, delegator, amount);
deal(market.underlying, delegator, amount);

timestamp = bound(timestamp, 0, Math.min(deadline, type(uint48).max) - block.timestamp);
vm.warp(block.timestamp + timestamp);
Expand Down
2 changes: 0 additions & 2 deletions test/internal/TestInternalEMode.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ contract TestInternalEMode is InternalTest, PositionsManagerInternal {
_createMarket(usdc, 0, 3_333);
_createMarket(wNative, 0, 3_333);

_setBalances(address(this), type(uint256).max);

QGarchery marked this conversation as resolved.
Show resolved Hide resolved
ERC20(dai).approve(address(_pool), type(uint256).max);
ERC20(wbtc).approve(address(_pool), type(uint256).max);
ERC20(usdc).approve(address(_pool), type(uint256).max);
Expand Down
4 changes: 2 additions & 2 deletions test/invariant/TestInvariantAccessControl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ contract TestInvariantAccessControl is InvariantTest {
onBehalf = _randomSender(onBehalf);
maxIterations = _boundMaxIterations(maxIterations);

_deal(market.underlying, msg.sender, amount);
deal(market.underlying, msg.sender, amount);

vm.prank(msg.sender); // Cannot startPrank because `morpho.supply` may revert and not call stopPrank.
ERC20(market.underlying).safeApprove(address(morpho), amount);
Expand All @@ -64,7 +64,7 @@ contract TestInvariantAccessControl is InvariantTest {
amount = _boundSupply(market, amount);
onBehalf = _randomSender(onBehalf);

_deal(market.underlying, msg.sender, amount);
deal(market.underlying, msg.sender, amount);

vm.prank(msg.sender); // Cannot startPrank because `morpho.supplyCollateral` may revert and not call stopPrank.
ERC20(market.underlying).safeApprove(address(morpho), amount);
Expand Down
4 changes: 2 additions & 2 deletions test/invariant/TestInvariantMorpho.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ contract TestInvariantMorpho is InvariantTest {
onBehalf = _randomSender(onBehalf);
maxIterations = _boundMaxIterations(maxIterations);

_deal(market.underlying, msg.sender, amount);
deal(market.underlying, msg.sender, amount);

vm.prank(msg.sender); // Cannot startPrank because `morpho.supply` may revert and not call stopPrank.
ERC20(market.underlying).safeApprove(address(morpho), amount);
Expand Down Expand Up @@ -106,7 +106,7 @@ contract TestInvariantMorpho is InvariantTest {
amount = _boundNotZero(amount);
onBehalf = _randomSender(onBehalf);

_deal(market.underlying, msg.sender, amount);
deal(market.underlying, msg.sender, amount);

vm.prank(msg.sender); // Cannot startPrank because `morpho.repay` may revert and not call stopPrank.
ERC20(market.underlying).safeApprove(address(morpho), amount);
Expand Down
19 changes: 8 additions & 11 deletions test/mocks/PoolAdminMock.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.0;

import {IPoolConfigurator} from "@aave-v3-core/interfaces/IPoolConfigurator.sol";
import {IPoolConfigurator} from "src/interfaces/aave/IPoolConfigurator.sol";

contract PoolAdminMock {
IPoolConfigurator internal immutable _POOL_CONFIGURATOR;
Expand All @@ -23,23 +23,20 @@ contract PoolAdminMock {
uint16 ltv,
uint16 liquidationThreshold,
uint16 liquidationBonus,
address priceSourceEMode,
string memory label
) external {
_POOL_CONFIGURATOR.setEModeCategory(
eModeCategoryId, ltv, liquidationThreshold, liquidationBonus, priceSourceEMode, label
);
_POOL_CONFIGURATOR.setEModeCategory(eModeCategoryId, ltv, liquidationThreshold, liquidationBonus, label);
}

function setAssetEModeCategory(address asset, uint8 eModeCategoryId) external {
_POOL_CONFIGURATOR.setAssetEModeCategory(asset, eModeCategoryId);
function setAssetBorrowableInEMode(address asset, uint8 eModeCategoryId, bool borrowable) external {
_POOL_CONFIGURATOR.setAssetBorrowableInEMode(asset, eModeCategoryId, borrowable);
}

function setReserveBorrowing(address asset, bool enabled) external {
_POOL_CONFIGURATOR.setReserveBorrowing(asset, enabled);
function setAssetCollateralInEMode(address asset, uint8 eModeCategoryId, bool collateral) external {
_POOL_CONFIGURATOR.setAssetCollateralInEMode(asset, eModeCategoryId, collateral);
}

function setReserveStableRateBorrowing(address asset, bool enabled) external {
_POOL_CONFIGURATOR.setReserveStableRateBorrowing(asset, enabled);
function setReserveBorrowing(address asset, bool enabled) external {
_POOL_CONFIGURATOR.setReserveBorrowing(asset, enabled);
}
}
Loading