Skip to content

Commit

Permalink
Merge pull request #1592 from morpho-dao/fix/prod-tests-pause-status
Browse files Browse the repository at this point in the history
Add pause status checks in production tests
  • Loading branch information
MerlinEgalite committed Dec 17, 2022
2 parents b50f38e + 00b0e2b commit a8ab4ef
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 12 deletions.
1 change: 1 addition & 0 deletions config/eth-mainnet/aave-v2/Config.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {IEntryPositionsManager} from "src/aave-v2/interfaces/IEntryPositionsMana
import {IExitPositionsManager} from "src/aave-v2/interfaces/IExitPositionsManager.sol";
import {IInterestRatesManager} from "src/aave-v2/interfaces/IInterestRatesManager.sol";
import {ILendingPoolConfigurator} from "../../../test/aave-v2/helpers/ILendingPoolConfigurator.sol";
import {IMorpho} from "src/aave-v2/interfaces/IMorpho.sol";

import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import {ProxyAdmin} from "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
Expand Down
1 change: 1 addition & 0 deletions config/eth-mainnet/compound/Config.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "src/compound/interfaces/compound/ICompound.sol";
import {IIncentivesVault} from "src/compound/interfaces/IIncentivesVault.sol";
import {IPositionsManager} from "src/compound/interfaces/IPositionsManager.sol";
import {IInterestRatesManager} from "src/compound/interfaces/IInterestRatesManager.sol";
import {IMorpho} from "src/compound/interfaces/IMorpho.sol";

import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import {ProxyAdmin} from "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
Expand Down
72 changes: 67 additions & 5 deletions test/prod/aave-v2/TestLifecycle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ contract TestLifecycle is TestSetup {
TestMarket memory supplyMarket = collateralMarkets[supplyMarketIndex];
TestMarket memory borrowMarket = borrowableMarkets[borrowMarketIndex];

if (supplyMarket.status.isSupplyPaused) continue;

uint256 borrowAmount = _boundBorrowAmount(
borrowMarket,
_amount,
Expand All @@ -384,11 +386,17 @@ contract TestLifecycle is TestSetup {
MarketSideTest memory supply = _supply(supplyMarket, supplyAmount);
_testSupply(supply);

MarketSideTest memory borrow = _borrow(borrowMarket, borrowAmount);
_testBorrow(borrow);
if (!borrowMarket.status.isBorrowPaused) {
MarketSideTest memory borrow = _borrow(borrowMarket, borrowAmount);
_testBorrow(borrow);

if (!borrowMarket.status.isRepayPaused) {
_repay(borrow);
_testRepay(borrow);
}
}

_repay(borrow);
_testRepay(borrow);
if (supplyMarket.status.isWithdrawPaused) continue;

_withdraw(supply);
_testWithdraw(supply);
Expand All @@ -412,6 +420,9 @@ contract TestLifecycle is TestSetup {
TestMarket memory supplyMarket = collateralMarkets[supplyMarketIndex];
TestMarket memory borrowMarket = borrowableMarkets[borrowMarketIndex];

if (supplyMarket.status.isSupplyPaused || borrowMarket.status.isBorrowPaused)
continue;

uint256 borrowAmount = _boundBorrowAmount(
borrowMarket,
_amount,
Expand Down Expand Up @@ -475,8 +486,59 @@ contract TestLifecycle is TestSetup {
vm.assume(_amount > 0);

for (uint256 marketIndex; marketIndex < activeMarkets.length; ++marketIndex) {
TestMarket memory market = activeMarkets[marketIndex];
if (market.status.isWithdrawPaused) continue; // isWithdrawPaused check is before user-market membership check

vm.expectRevert(ExitPositionsManager.UserNotMemberOfMarket.selector);
user.withdraw(activeMarkets[marketIndex].poolToken, _amount);
user.withdraw(market.poolToken, _amount);
}
}

function testShouldNotSupplyWhenPaused(uint96 _amount) public {
vm.assume(_amount > 0);

for (uint256 marketIndex; marketIndex < activeMarkets.length; ++marketIndex) {
TestMarket memory market = activeMarkets[marketIndex];
if (!market.status.isSupplyPaused) continue;

vm.expectRevert(EntryPositionsManager.SupplyIsPaused.selector);
user.supply(market.poolToken, _amount);
}
}

function testShouldNotBorrowWhenPaused(uint96 _amount) public {
vm.assume(_amount > 0);

for (uint256 marketIndex; marketIndex < activeMarkets.length; ++marketIndex) {
TestMarket memory market = activeMarkets[marketIndex];
if (!market.status.isBorrowPaused) continue;

vm.expectRevert(EntryPositionsManager.BorrowIsPaused.selector);
user.borrow(market.poolToken, _amount);
}
}

function testShouldNotRepayWhenPaused(uint96 _amount) public {
vm.assume(_amount > 0);

for (uint256 marketIndex; marketIndex < activeMarkets.length; ++marketIndex) {
TestMarket memory market = activeMarkets[marketIndex];
if (!market.status.isRepayPaused) continue;

vm.expectRevert(ExitPositionsManager.RepayIsPaused.selector);
user.repay(market.poolToken, type(uint256).max);
}
}

function testShouldNotWithdrawWhenPaused(uint96 _amount) public {
vm.assume(_amount > 0);

for (uint256 marketIndex; marketIndex < activeMarkets.length; ++marketIndex) {
TestMarket memory market = activeMarkets[marketIndex];
if (!market.status.isWithdrawPaused) continue;

vm.expectRevert(ExitPositionsManager.WithdrawIsPaused.selector);
user.withdraw(market.poolToken, type(uint256).max);
}
}
}
5 changes: 4 additions & 1 deletion test/prod/aave-v2/setup/TestSetup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ contract TestSetup is Config, Test {
//
bool isActive;
bool isFrozen;
//
Types.MarketPauseStatus status;
}

TestMarket[] public markets;
Expand Down Expand Up @@ -181,7 +183,8 @@ contract TestSetup is Config, Test {
decimals: 0,
config: marketConfig,
isActive: false,
isFrozen: false
isFrozen: false,
status: IMorpho(address(morpho)).marketPauseStatus(poolToken)
});

DataTypes.ReserveConfigurationMap memory config = pool.getConfiguration(underlying);
Expand Down
72 changes: 67 additions & 5 deletions test/prod/compound/TestLifecycle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@ contract TestLifecycle is TestSetup {
TestMarket memory supplyMarket = collateralMarkets[supplyMarketIndex];
TestMarket memory borrowMarket = borrowableMarkets[borrowMarketIndex];

if (supplyMarket.status.isSupplyPaused) continue;

uint256 borrowAmount = _boundBorrowAmount(
borrowMarket,
_amount,
Expand All @@ -406,11 +408,17 @@ contract TestLifecycle is TestSetup {
MarketSideTest memory supply = _supply(supplyMarket, supplyAmount);
_testSupply(supply);

MarketSideTest memory borrow = _borrow(borrowMarket, borrowAmount);
_testBorrow(borrow);
if (!borrowMarket.status.isBorrowPaused) {
MarketSideTest memory borrow = _borrow(borrowMarket, borrowAmount);
_testBorrow(borrow);

if (!borrowMarket.status.isRepayPaused) {
_repay(borrow);
_testRepay(borrow);
}
}

_repay(borrow);
_testRepay(borrow);
if (supplyMarket.status.isWithdrawPaused) continue;

_withdraw(supply);
_testWithdraw(supply);
Expand All @@ -434,6 +442,9 @@ contract TestLifecycle is TestSetup {
TestMarket memory supplyMarket = collateralMarkets[supplyMarketIndex];
TestMarket memory borrowMarket = borrowableMarkets[borrowMarketIndex];

if (supplyMarket.status.isSupplyPaused || borrowMarket.status.isBorrowPaused)
continue;

uint256 borrowAmount = _boundBorrowAmount(
borrowMarket,
_amount,
Expand Down Expand Up @@ -495,8 +506,59 @@ contract TestLifecycle is TestSetup {
vm.assume(_amount > 0);

for (uint256 marketIndex; marketIndex < activeMarkets.length; ++marketIndex) {
TestMarket memory market = activeMarkets[marketIndex];
if (market.status.isWithdrawPaused) continue; // isWithdrawPaused check is before user-market membership check

vm.expectRevert(PositionsManager.UserNotMemberOfMarket.selector);
user.withdraw(activeMarkets[marketIndex].poolToken, _amount);
user.withdraw(market.poolToken, _amount);
}
}

function testShouldNotSupplyWhenPaused(uint96 _amount) public {
vm.assume(_amount > 0);

for (uint256 marketIndex; marketIndex < activeMarkets.length; ++marketIndex) {
TestMarket memory market = activeMarkets[marketIndex];
if (!market.status.isSupplyPaused) continue;

vm.expectRevert(PositionsManager.SupplyIsPaused.selector);
user.supply(market.poolToken, _amount);
}
}

function testShouldNotBorrowWhenPaused(uint96 _amount) public {
vm.assume(_amount > 0);

for (uint256 marketIndex; marketIndex < activeMarkets.length; ++marketIndex) {
TestMarket memory market = activeMarkets[marketIndex];
if (!market.status.isBorrowPaused) continue;

vm.expectRevert(PositionsManager.BorrowIsPaused.selector);
user.borrow(market.poolToken, _amount);
}
}

function testShouldNotRepayWhenPaused(uint96 _amount) public {
vm.assume(_amount > 0);

for (uint256 marketIndex; marketIndex < activeMarkets.length; ++marketIndex) {
TestMarket memory market = activeMarkets[marketIndex];
if (!market.status.isRepayPaused) continue;

vm.expectRevert(PositionsManager.RepayIsPaused.selector);
user.repay(market.poolToken, type(uint256).max);
}
}

function testShouldNotWithdrawWhenPaused(uint96 _amount) public {
vm.assume(_amount > 0);

for (uint256 marketIndex; marketIndex < activeMarkets.length; ++marketIndex) {
TestMarket memory market = activeMarkets[marketIndex];
if (!market.status.isWithdrawPaused) continue;

vm.expectRevert(PositionsManager.WithdrawIsPaused.selector);
user.withdraw(market.poolToken, type(uint256).max);
}
}
}
5 changes: 4 additions & 1 deletion test/prod/compound/setup/TestSetup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ contract TestSetup is Config, Test {
//
bool mintGuardianPaused;
bool borrowGuardianPaused;
//
Types.MarketPauseStatus status;
}

TestMarket[] public markets;
Expand Down Expand Up @@ -155,7 +157,8 @@ contract TestSetup is Config, Test {
maxBorrows: comptroller.borrowCaps(poolToken),
totalBorrows: ICToken(poolToken).totalBorrows(),
mintGuardianPaused: comptroller.mintGuardianPaused(poolToken),
borrowGuardianPaused: comptroller.borrowGuardianPaused(poolToken)
borrowGuardianPaused: comptroller.borrowGuardianPaused(poolToken),
status: IMorpho(address(morpho)).marketPauseStatus(poolToken)
});

(, bool isPaused, bool isPartiallyPaused) = morpho.marketStatus(poolToken);
Expand Down

0 comments on commit a8ab4ef

Please sign in to comment.