mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Added a new test to check an invalid interest rate mode
This commit is contained in:
parent
1486cee774
commit
48438f59f5
|
@ -435,9 +435,10 @@ contract LendingPool is VersionedInitializable, ILendingPool {
|
||||||
|
|
||||||
vars.premium = amount.mul(FLASHLOAN_PREMIUM_TOTAL).div(10000);
|
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);
|
vars.receiver = IFlashLoanReceiver(receiverAddress);
|
||||||
|
|
||||||
|
|
|
@ -322,11 +322,11 @@ library ValidationLogic {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev validates a flashloan action
|
* @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
|
* @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(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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,6 +99,7 @@ export enum ProtocolErrors {
|
||||||
SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER = '40', // 'User did not borrow the specified currency'
|
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"
|
NOT_ENOUGH_LIQUIDITY_TO_LIQUIDATE = '41', // "There isn't enough liquidity available to liquidate"
|
||||||
NO_ERRORS = '42', // 'No errors'
|
NO_ERRORS = '42', // 'No errors'
|
||||||
|
INVALID_FLASHLOAN_MODE = '43', //Invalid flashloan mode
|
||||||
|
|
||||||
// old
|
// old
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,8 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
|
||||||
const {
|
const {
|
||||||
COLLATERAL_BALANCE_IS_0,
|
COLLATERAL_BALANCE_IS_0,
|
||||||
REQUESTED_AMOUNT_TOO_SMALL,
|
REQUESTED_AMOUNT_TOO_SMALL,
|
||||||
TRANSFER_AMOUNT_EXCEEDS_BALANCE
|
TRANSFER_AMOUNT_EXCEEDS_BALANCE,
|
||||||
|
INVALID_FLASHLOAN_MODE
|
||||||
} = ProtocolErrors;
|
} = ProtocolErrors;
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
|
@ -110,6 +111,25 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
|
||||||
).to.be.revertedWith(TRANSFER_AMOUNT_EXCEEDS_BALANCE);
|
).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 () => {
|
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;
|
const {dai, pool, weth, users} = testEnv;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user