Added a new test to check an invalid interest rate mode

This commit is contained in:
emilio 2020-09-03 16:29:14 +02:00
parent 1486cee774
commit 48438f59f5
4 changed files with 28 additions and 6 deletions

View File

@ -435,9 +435,10 @@ contract LendingPool is VersionedInitializable, ILendingPool {
vars.premium = amount.mul(FLASHLOAN_PREMIUM_TOTAL).div(10000);
ReserveLogic.InterestRateMode debtMode = ReserveLogic.InterestRateMode(mode);
ValidationLogic.validateFlashloan(debtMode, vars.premium);
ValidationLogic.validateFlashloan(mode, vars.premium);
ReserveLogic.InterestRateMode debtMode = ReserveLogic.InterestRateMode(mode);
vars.receiver = IFlashLoanReceiver(receiverAddress);

View File

@ -322,11 +322,11 @@ library ValidationLogic {
/**
* @dev validates a flashloan action
* @param mode the flashloan mode (NONE = classic flashloan, STABLE = open a stable rate loan, VARIABLE = open a variable rate loan)
* @param mode the flashloan mode (0 = classic flashloan, 1 = open a stable rate loan, 2 = open a variable rate loan)
* @param premium the premium paid on the flashloan
**/
function validateFlashloan(ReserveLogic.InterestRateMode mode, uint256 premium) internal pure {
function validateFlashloan(uint256 mode, uint256 premium) internal pure {
require(premium > 0, Errors.REQUESTED_AMOUNT_TOO_SMALL);
require(mode <= ReserveLogic.InterestRateMode.VARIABLE, Errors.INVALID_FLASHLOAN_MODE);
require(mode <= uint256(ReserveLogic.InterestRateMode.VARIABLE), Errors.INVALID_FLASHLOAN_MODE);
}
}

View File

@ -99,6 +99,7 @@ export enum ProtocolErrors {
SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER = '40', // 'User did not borrow the specified currency'
NOT_ENOUGH_LIQUIDITY_TO_LIQUIDATE = '41', // "There isn't enough liquidity available to liquidate"
NO_ERRORS = '42', // 'No errors'
INVALID_FLASHLOAN_MODE = '43', //Invalid flashloan mode
// old

View File

@ -18,7 +18,8 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
const {
COLLATERAL_BALANCE_IS_0,
REQUESTED_AMOUNT_TOO_SMALL,
TRANSFER_AMOUNT_EXCEEDS_BALANCE
TRANSFER_AMOUNT_EXCEEDS_BALANCE,
INVALID_FLASHLOAN_MODE
} = ProtocolErrors;
before(async () => {
@ -110,6 +111,25 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
).to.be.revertedWith(TRANSFER_AMOUNT_EXCEEDS_BALANCE);
});
it('Takes a WETH flashloan with an invalid mode. (revert expected)', async () => {
const {pool, weth, users} = testEnv;
const caller = users[1];
await _mockFlashLoanReceiver.setFailExecutionTransfer(true);
await expect(
pool
.connect(caller.signer)
.flashLoan(
_mockFlashLoanReceiver.address,
weth.address,
ethers.utils.parseEther('0.8'),
4,
'0x10',
'0'
)
).to.be.revertedWith(INVALID_FLASHLOAN_MODE);
});
it('Caller deposits 1000 DAI as collateral, Takes WETH flashloan with mode = 2, does not return the funds. A variable loan for caller is created', async () => {
const {dai, pool, weth, users} = testEnv;