Skip to content

Commit

Permalink
feat: add additional flashloan scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Valeri committed Oct 18, 2022
1 parent 284b492 commit 8888093
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test-suites/pool-flashloan.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ makeSuite('Pool: FlashLoan', (testEnv: TestEnv) => {
ERC20_TRANSFER_AMOUNT_EXCEEDS_BALANCE,
INVALID_FLASHLOAN_EXECUTOR_RETURN,
FLASHLOAN_DISABLED,
BORROWING_NOT_ENABLED,
} = ProtocolErrors;

const TOTAL_PREMIUM = 9;
Expand Down Expand Up @@ -580,6 +581,46 @@ makeSuite('Pool: FlashLoan', (testEnv: TestEnv) => {
expect(callerDebt.toString()).to.be.equal('500000000', 'Invalid user debt');
});

it('Disable USDC borrowing. Caller deposits 5 WETH as collateral, Takes a USDC flashloan with mode = 2, does not return the funds. Revert creating borrow position (revert expected)', async () => {
const {usdc, pool, weth, configurator, users, helpersContract} = testEnv;

const caller = users[2];

expect(await configurator.setReserveStableRateBorrowing(usdc.address, false));
expect(await configurator.setReserveBorrowing(usdc.address, false));

let usdcConfiguration = await helpersContract.getReserveConfigurationData(usdc.address);
expect(usdcConfiguration.borrowingEnabled).to.be.equal(false);

await weth
.connect(caller.signer)
['mint(uint256)'](await convertToCurrencyDecimals(weth.address, '5'));

await weth.connect(caller.signer).approve(pool.address, MAX_UINT_AMOUNT);

const amountToDeposit = await convertToCurrencyDecimals(weth.address, '5');

await pool.connect(caller.signer).deposit(weth.address, amountToDeposit, caller.address, '0');

await _mockFlashLoanReceiver.setFailExecutionTransfer(true);

const flashloanAmount = await convertToCurrencyDecimals(usdc.address, '500');

await expect(
pool
.connect(caller.signer)
.flashLoan(
_mockFlashLoanReceiver.address,
[usdc.address],
[flashloanAmount],
[2],
caller.address,
'0x10',
'0'
)
).to.be.revertedWith(BORROWING_NOT_ENABLED);
});

it('Caller deposits 1000 DAI as collateral, Takes a WETH flashloan with mode = 0, does not approve the transfer of the funds', async () => {
const {dai, pool, weth, users} = testEnv;
const caller = users[3];
Expand Down

0 comments on commit 8888093

Please sign in to comment.