mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Added missing whenNotPaused to new functions. Changed IS_PAUSED error code to 58 to prevent error collision. Added new pausable tests.
This commit is contained in:
parent
41978a9ee5
commit
aa834ee904
|
@ -69,7 +69,7 @@ contract LendingPool is VersionedInitializable, ILendingPool {
|
|||
}
|
||||
|
||||
/**
|
||||
* @dev Modifier to make a function callable only when the contract is not paused.
|
||||
* @dev Function to make a function callable only when the contract is not paused.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
|
@ -618,6 +618,7 @@ contract LendingPool is VersionedInitializable, ILendingPool {
|
|||
uint256 amountToSwap,
|
||||
bytes calldata params
|
||||
) external override {
|
||||
whenNotPaused();
|
||||
address liquidationManager = _addressesProvider.getLendingPoolLiquidationManager();
|
||||
|
||||
//solium-disable-next-line
|
||||
|
|
|
@ -78,7 +78,7 @@ library Errors {
|
|||
string public constant DIVISION_BY_ZERO = '46';
|
||||
|
||||
// pausable error message
|
||||
string public constant IS_PAUSED = '54'; // 'Pool is paused'
|
||||
string public constant IS_PAUSED = '58'; // 'Pool is paused'
|
||||
enum LiquidationErrors {
|
||||
NO_ERROR,
|
||||
NO_COLLATERAL_AVAILABLE,
|
||||
|
|
|
@ -100,8 +100,7 @@ export enum ProtocolErrors {
|
|||
NO_ERRORS = '42', // 'No errors'
|
||||
INVALID_FLASHLOAN_MODE = '43', //Invalid flashloan mode
|
||||
|
||||
IS_PAUSED = '54', // Pool is paused
|
||||
NOT_PAUSED = '55', // Pool is not paused
|
||||
IS_PAUSED = '58', // Pool is paused
|
||||
|
||||
// old
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
|
|||
TRANSFER_NOT_ALLOWED,
|
||||
INVALID_FROM_BALANCE_AFTER_TRANSFER,
|
||||
INVALID_TO_BALANCE_AFTER_TRANSFER,
|
||||
INVALID_HF,
|
||||
} = ProtocolErrors;
|
||||
|
||||
before(async () => {
|
||||
|
@ -78,7 +77,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
|
|||
);
|
||||
});
|
||||
|
||||
it('User 0 deposits 1000 DAI but reverts due pool is paused', async () => {
|
||||
it('Deposit', async () => {
|
||||
const {users, pool, dai, aDai, configurator} = testEnv;
|
||||
|
||||
const amountDAItoDeposit = await convertToCurrencyDecimals(dai.address, '1000');
|
||||
|
@ -98,7 +97,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
|
|||
await configurator.setPoolPause(false);
|
||||
});
|
||||
|
||||
it('User 0 burns 1000 aDAI but reverts due pool is paused', async () => {
|
||||
it('Withdraw', async () => {
|
||||
const {users, pool, dai, aDai, configurator} = testEnv;
|
||||
|
||||
const amountDAItoDeposit = await convertToCurrencyDecimals(dai.address, '1000');
|
||||
|
@ -123,6 +122,71 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
|
|||
await configurator.setPoolPause(false);
|
||||
});
|
||||
|
||||
it('DelegateBorrowAllowance', async () => {
|
||||
const {pool, dai, users, configurator} = testEnv;
|
||||
|
||||
const user = users[1];
|
||||
const toUser = users[2];
|
||||
// Pause the pool
|
||||
await configurator.setPoolPause(true);
|
||||
|
||||
// Try to execute liquidation
|
||||
await expect(
|
||||
pool.connect(user.signer).delegateBorrowAllowance(dai.address, toUser.address, '1', '1')
|
||||
).revertedWith(IS_PAUSED);
|
||||
|
||||
// Unpause the pool
|
||||
await configurator.setPoolPause(false);
|
||||
});
|
||||
|
||||
it('Borrow', async () => {
|
||||
const {pool, dai, users, configurator} = testEnv;
|
||||
|
||||
const user = users[1];
|
||||
// Pause the pool
|
||||
await configurator.setPoolPause(true);
|
||||
|
||||
// Try to execute liquidation
|
||||
await expect(
|
||||
pool.connect(user.signer).borrow(dai.address, '1', '1', '0', user.address)
|
||||
).revertedWith(IS_PAUSED);
|
||||
|
||||
// Unpause the pool
|
||||
await configurator.setPoolPause(false);
|
||||
});
|
||||
|
||||
it('Swap liquidity', async () => {
|
||||
const {pool, dai, weth, users, configurator} = testEnv;
|
||||
|
||||
const user = users[1];
|
||||
// Pause the pool
|
||||
await configurator.setPoolPause(true);
|
||||
|
||||
// Try to execute liquidation
|
||||
await expect(
|
||||
pool.connect(user.signer).swapLiquidity(user.address, dai.address, weth.address, '1', '0x')
|
||||
).revertedWith(IS_PAUSED);
|
||||
|
||||
// Unpause the pool
|
||||
await configurator.setPoolPause(false);
|
||||
});
|
||||
|
||||
it('Repay', async () => {
|
||||
const {pool, dai, users, configurator} = testEnv;
|
||||
|
||||
const user = users[1];
|
||||
// Pause the pool
|
||||
await configurator.setPoolPause(true);
|
||||
|
||||
// Try to execute liquidation
|
||||
await expect(pool.connect(user.signer).repay(dai.address, '1', '1', user.address)).revertedWith(
|
||||
IS_PAUSED
|
||||
);
|
||||
|
||||
// Unpause the pool
|
||||
await configurator.setPoolPause(false);
|
||||
});
|
||||
|
||||
it('Repay with collateral', async () => {
|
||||
const {pool, weth, dai, usdc, users, mockSwapAdapter, oracle, configurator} = testEnv;
|
||||
const user = users[6];
|
||||
|
@ -249,49 +313,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
|
|||
await configurator.setPoolPause(false);
|
||||
});
|
||||
|
||||
it('User 6 deposits WETH and DAI, then borrows USDC at Variable', async () => {
|
||||
const {pool, weth, dai, usdc, users, configurator, mockSwapAdapter} = testEnv;
|
||||
const user = users[5];
|
||||
const amountWETHToDeposit = parseEther('10');
|
||||
const amountDAIToDeposit = parseEther('120');
|
||||
const amountToBorrow = parseUnits('65', 6);
|
||||
|
||||
await weth.connect(user.signer).mint(amountWETHToDeposit);
|
||||
await weth.connect(user.signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
|
||||
await pool.connect(user.signer).deposit(weth.address, amountWETHToDeposit, user.address, '0');
|
||||
|
||||
await dai.connect(user.signer).mint(amountDAIToDeposit);
|
||||
await dai.connect(user.signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
|
||||
await pool.connect(user.signer).deposit(dai.address, amountDAIToDeposit, user.address, '0');
|
||||
|
||||
await pool.connect(user.signer).borrow(usdc.address, amountToBorrow, 2, 0, user.address);
|
||||
|
||||
const amountToRepay = parseUnits('65', 6);
|
||||
|
||||
await mockSwapAdapter.setAmountToReturn(amountToRepay);
|
||||
|
||||
// Pause pool
|
||||
await configurator.setPoolPause(true);
|
||||
|
||||
// Try to repay
|
||||
await expect(
|
||||
pool
|
||||
.connect(user.signer)
|
||||
.repayWithCollateral(
|
||||
weth.address,
|
||||
usdc.address,
|
||||
user.address,
|
||||
amountToRepay,
|
||||
mockSwapAdapter.address,
|
||||
'0x'
|
||||
)
|
||||
).revertedWith(IS_PAUSED);
|
||||
|
||||
// Unpause pool
|
||||
await configurator.setPoolPause(false);
|
||||
});
|
||||
|
||||
it('User 2 deposits WETH and DAI, then borrows USDC at Variable, then tries to swap to stable but pool is paused', async () => {
|
||||
it('SwapBorrowRateMode', async () => {
|
||||
const {pool, weth, dai, usdc, users, configurator, mockSwapAdapter} = testEnv;
|
||||
const user = users[1];
|
||||
const amountWETHToDeposit = parseEther('10');
|
||||
|
@ -320,7 +342,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
|
|||
await configurator.setPoolPause(false);
|
||||
});
|
||||
|
||||
it('User 2 tries to rebalance stable borrow rate', async () => {
|
||||
it('RebalanceStableBorrowRate', async () => {
|
||||
const {pool, dai, users, configurator} = testEnv;
|
||||
const user = users[1];
|
||||
// Pause pool
|
||||
|
@ -334,7 +356,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
|
|||
await configurator.setPoolPause(false);
|
||||
});
|
||||
|
||||
it('User 2 tries to rebalance stable borrow rate', async () => {
|
||||
it('setUserUseReserveAsCollateral', async () => {
|
||||
const {pool, weth, users, configurator} = testEnv;
|
||||
const user = users[1];
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user