From aa834ee9041f6032bf84d03cf12863940ecdd516 Mon Sep 17 00:00:00 2001 From: David Racero Date: Tue, 15 Sep 2020 13:13:28 +0200 Subject: [PATCH] Added missing whenNotPaused to new functions. Changed IS_PAUSED error code to 58 to prevent error collision. Added new pausable tests. --- contracts/lendingpool/LendingPool.sol | 3 +- contracts/libraries/helpers/Errors.sol | 2 +- helpers/types.ts | 3 +- test/pausable-functions.spec.ts | 118 +++++++++++++++---------- 4 files changed, 74 insertions(+), 52 deletions(-) diff --git a/contracts/lendingpool/LendingPool.sol b/contracts/lendingpool/LendingPool.sol index 7c259051..2f35fa4c 100644 --- a/contracts/lendingpool/LendingPool.sol +++ b/contracts/lendingpool/LendingPool.sol @@ -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 diff --git a/contracts/libraries/helpers/Errors.sol b/contracts/libraries/helpers/Errors.sol index 0fd71e4c..48c53ba6 100644 --- a/contracts/libraries/helpers/Errors.sol +++ b/contracts/libraries/helpers/Errors.sol @@ -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, diff --git a/helpers/types.ts b/helpers/types.ts index f0a78ed0..966180d4 100644 --- a/helpers/types.ts +++ b/helpers/types.ts @@ -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 diff --git a/test/pausable-functions.spec.ts b/test/pausable-functions.spec.ts index bf6fc05e..d63ab1e2 100644 --- a/test/pausable-functions.spec.ts +++ b/test/pausable-functions.spec.ts @@ -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];