- Finished migration of flashloan.spec.ts.

- Fixed issue with buidlerevm snapshotting.
This commit is contained in:
eboado 2020-06-12 15:41:52 +02:00
parent 99cbb5f0a4
commit 0b17abc6eb
8 changed files with 264 additions and 351 deletions

View File

@ -61,7 +61,7 @@ const config: BuidlerConfig = {
url: "https://api-kovan.etherscan.io/api", url: "https://api-kovan.etherscan.io/api",
apiKey: ETHERSCAN_KEY, apiKey: ETHERSCAN_KEY,
}, },
defaultNetwork: "ganache", defaultNetwork: "buidlerevm",
mocha: { mocha: {
timeout: 0, timeout: 0,
}, },

View File

@ -467,6 +467,30 @@ export const getInterestRateStrategy = async (address?: tEthereumAddress) => {
); );
}; };
export const getMockFlashLoanReceiver = async (address?: tEthereumAddress) => {
return await getContract<MockFlashLoanReceiver>(
eContractid.MockFlashLoanReceiver,
address ||
(
await getDb()
.get(`${eContractid.MockFlashLoanReceiver}.${BRE.network.name}`)
.value()
).address
);
};
export const getTokenDistributor = async (address?: tEthereumAddress) => {
return await getContract<TokenDistributor>(
eContractid.TokenDistributor,
address ||
(
await getDb()
.get(`${eContractid.TokenDistributor}.${BRE.network.name}`)
.value()
).address
);
};
const linkBytecode = (artifact: Artifact, libraries: any) => { const linkBytecode = (artifact: Artifact, libraries: any) => {
let bytecode = artifact.bytecode; let bytecode = artifact.bytecode;

View File

@ -27,7 +27,8 @@ export const sleep = (milliseconds: number) => {
export const createRandomAddress = () => Wallet.createRandom().address; export const createRandomAddress = () => Wallet.createRandom().address;
export const evmSnapshot = () => BRE.ethereum.send("evm_snapshot", []); export const evmSnapshot = async () =>
await BRE.ethereum.send("evm_snapshot", []);
export const evmRevert = async (id: string) => export const evmRevert = async (id: string) =>
BRE.ethereum.send("evm_revert", [id]); BRE.ethereum.send("evm_revert", [id]);

View File

@ -55,6 +55,9 @@ export enum ProtocolErrors {
INVALID_REDIRECTION_ADDRESS = "Invalid redirection address", INVALID_REDIRECTION_ADDRESS = "Invalid redirection address",
TRANSFERRED_AMOUNT_GT_ZERO = "Transferred amount needs to be greater than zero", TRANSFERRED_AMOUNT_GT_ZERO = "Transferred amount needs to be greater than zero",
ZERO_COLLATERAL = "The collateral balance is 0", ZERO_COLLATERAL = "The collateral balance is 0",
INCONSISTENT_PROTOCOL_BALANCE = "The actual balance of the protocol is inconsistent",
TOO_SMALL_FLASH_LOAN = "The requested amount is too small for a flashLoan.",
NOT_ENOUGH_LIQUIDITY_TO_BORROW = "There is not enough liquidity available to borrow",
} }
export type tEthereumAddress = string; export type tEthereumAddress = string;

View File

@ -607,7 +607,18 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
await addressesProvider.setTokenDistributor(tokenDistributorProxy.address) await addressesProvider.setTokenDistributor(tokenDistributorProxy.address)
); );
await deployMockFlashLoanReceiver(addressesProvider.address); await insertContractAddressInDb(
eContractid.TokenDistributor,
tokenDistributorProxy.address
);
const mockFlashLoanReceiver = await deployMockFlashLoanReceiver(
addressesProvider.address
);
await insertContractAddressInDb(
eContractid.MockFlashLoanReceiver,
mockFlashLoanReceiver.address
);
await deployWalletBalancerProvider(addressesProvider.address); await deployWalletBalancerProvider(addressesProvider.address);
@ -626,7 +637,7 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
before(async () => { before(async () => {
await rawBRE.run("set-bre"); await rawBRE.run("set-bre");
const [deployer, secondaryWallet] = await getEthersSigners(); const [deployer, secondaryWallet] = await getEthersSigners();
console.log("-> Deploying test environment...") console.log("-> Deploying test environment...");
await buildTestEnv(deployer, secondaryWallet); await buildTestEnv(deployer, secondaryWallet);
console.log("\n***************"); console.log("\n***************");
console.log("Setup and snapshot finished"); console.log("Setup and snapshot finished");

View File

@ -1,111 +0,0 @@
// import { ITestEnv, ContractsInstancesOrigin } from "../utils/types";
// import { LendingPoolCoreInstance, LendingPoolAddressesProviderInstance } from "../utils/typechain-types/truffle-contracts";
// import { testEnvProvider } from "../utils/truffle/dlp-tests-env";
// import { RAY, WAD, ETHEREUM_ADDRESS } from "../utils/constants";
// import BigNumber from "bignumber.js";
// /*contract("LendingPoolCore", async ([deployer, ...users]) => {
// let _testEnvProvider: ITestEnv
// let _addressesProviderInstance: LendingPoolAddressesProviderInstance
// let _lendingPoolCoreInstance: LendingPoolCoreInstance;
// let _lendAddress: string;
// before("Initializing LendingPoolCore test variables", async () => {
// _testEnvProvider = await testEnvProvider(artifacts, [deployer, ...users], ContractsInstancesOrigin.TruffleArtifacts)
// const {
// deployedInstances: {
// lendingPoolAddressesProviderInstance,
// lendingPoolCoreInstance,
// },
// getAllAssetsAddresses
// } = _testEnvProvider
// _addressesProviderInstance = lendingPoolAddressesProviderInstance
// _lendingPoolCoreInstance = lendingPoolCoreInstance
// _lendAddress = (await getAllAssetsAddresses()).LEND
// })
// it("Configure the lending pool address to the owner address to allow invocation of the methods", async () => {
// await _addressesProviderInstance.setLendingPoolConfiguratorImpl(deployer)
// await _addressesProviderInstance.setLendingPoolImpl(deployer)
// await _lendingPoolCoreInstance.refreshConfiguration()
// const providerAddress = await _addressesProviderInstance.getLendingPoolConfigurator()
// expect(providerAddress).to.be.equal(deployer)
// const poolAddress = await _addressesProviderInstance.getLendingPool()
// expect(poolAddress).to.be.equal(deployer)
// })
// it("Increases the stable total borrows of a reserve", async () => {
// await _lendingPoolCoreInstance.increaseReserveTotalBorrowsStableAndUpdateAverageRate(
// ETHEREUM_ADDRESS,
// WAD,
// new BigNumber(RAY).multipliedBy(10).toFixed(),
// ) //10% interest
// const totalBorrows = await _lendingPoolCoreInstance.getReserveTotalBorrowsStable(ETHEREUM_ADDRESS)
// expect(totalBorrows.toString()).to.be.equal(WAD)
// })
// it("Increases the variable total borrows of a reserve", async () => {
// await _lendingPoolCoreInstance.increaseReserveTotalBorrowsVariable(ETHEREUM_ADDRESS, WAD) //10% interest
// const totalBorrows = await _lendingPoolCoreInstance.getReserveTotalBorrowsVariable(ETHEREUM_ADDRESS)
// expect(totalBorrows.toString()).to.be.equal(WAD)
// })
// it("Decreases the stable total borrows of a reserve", async () => {
// await _lendingPoolCoreInstance.decreaseReserveTotalBorrowsStableAndUpdateAverageRate(
// ETHEREUM_ADDRESS,
// WAD,
// new BigNumber(RAY).multipliedBy(10).toFixed(),
// )
// const totalBorrows = await _lendingPoolCoreInstance.getReserveTotalBorrowsStable(ETHEREUM_ADDRESS)
// expect(totalBorrows.toString()).to.be.equal("0")
// })
// it("Decreases the variable total borrows of a reserve", async () => {
// await _lendingPoolCoreInstance.decreaseReserveTotalBorrowsVariable(ETHEREUM_ADDRESS, WAD)
// const totalBorrows = await _lendingPoolCoreInstance.getReserveTotalBorrowsVariable(ETHEREUM_ADDRESS)
// expect(totalBorrows.toString()).to.be.equal("0")
// })
// it("Updates the variable borrow index, checks that is equal to 1 as there are no borrows from the user", async () => {
// await _lendingPoolCoreInstance.updateUserLastVariableBorrowCumulativeIndex(_lendAddress, deployer)
// await _lendingPoolCoreInstance.updateUserLastVariableBorrowCumulativeIndex(ETHEREUM_ADDRESS, deployer)
// const indexLEND = await _lendingPoolCoreInstance.getUserVariableBorrowCumulativeIndex(
// _lendAddress,
// deployer,
// )
// const indexETH = await _lendingPoolCoreInstance.getUserVariableBorrowCumulativeIndex(ETHEREUM_ADDRESS, deployer)
// expect(indexLEND.toString()).to.be.equal(RAY, "Invalid user borrow index for LEND")
// expect(indexETH.toString()).to.be.equal(RAY, "Invalid user borrow index for ETH")
// })
// it("Disables the LEND collateral", async () => {
// await _lendingPoolCoreInstance.disableReserveAsCollateral(_lendAddress)
// const collateralEnabled = await _lendingPoolCoreInstance.isReserveUsageAsCollateralEnabled(
// _lendAddress,
// )
// expect(collateralEnabled).to.be.equal(false)
// })
// it("Deactivates the ETH reserve", async () => {
// await _lendingPoolCoreInstance.disableBorrowingOnReserve(ETHEREUM_ADDRESS)
// const isEnabled = await _lendingPoolCoreInstance.isReserveBorrowingEnabled(ETHEREUM_ADDRESS)
// expect(isEnabled).to.be.equal(false)
// })
// })
// */

View File

@ -1,278 +1,256 @@
// import { import {TestEnv, makeSuite} from "./helpers/make-suite";
// LendingPoolInstance, import {
// LendingPoolCoreInstance, MOCK_ETH_ADDRESS,
// IPriceOracleInstance, APPROVAL_AMOUNT_LENDING_POOL_CORE,
// MockFlashLoanReceiverInstance, oneRay,
// TokenDistributorInstance, } from "../helpers/constants";
// MintableERC20Instance, import {
// ATokenInstance, convertToCurrencyDecimals,
// } from '../utils/typechain-types/truffle-contracts'; getMockFlashLoanReceiver,
// import {iATokenBase, iAssetsWithoutETH, ITestEnvWithoutInstances} from '../utils/types'; getTokenDistributor,
// import BigNumber from 'bignumber.js'; } from "../helpers/contracts-helpers";
// import { import {ethers} from "ethers";
// APPROVAL_AMOUNT_LENDING_POOL_CORE, import {MockFlashLoanReceiver} from "../types/MockFlashLoanReceiver";
// oneEther, import {TokenDistributor} from "../types/TokenDistributor";
// oneRay, import {BRE} from "../helpers/misc-utils";
// ETHEREUM_ADDRESS, import {ProtocolErrors} from "../helpers/types";
// } from '../utils/constants'; import BigNumber from "bignumber.js";
// import {testEnvProviderWithoutInstances} from '../utils/truffle/dlp-tests-env';
// import {convertToCurrencyDecimals} from '../utils/misc-utils';
// const expectRevert = require('@openzeppelin/test-helpers').expectRevert; const {expect} = require("chai");
// const {expect} = require('chai'); makeSuite("LendingPool FlashLoan function", (testEnv: TestEnv) => {
let _mockFlashLoanReceiver = {} as MockFlashLoanReceiver;
let _tokenDistributor = {} as TokenDistributor;
const {
INCONSISTENT_PROTOCOL_BALANCE,
TOO_SMALL_FLASH_LOAN,
NOT_ENOUGH_LIQUIDITY_TO_BORROW,
} = ProtocolErrors;
// contract('LendingPool FlashLoan function', async ([deployer, ...users]) => { before(async () => {
// let _testEnvProvider: ITestEnvWithoutInstances; _mockFlashLoanReceiver = await getMockFlashLoanReceiver();
// let _lendingPoolInstance: LendingPoolInstance; _tokenDistributor = await getTokenDistributor();
// let _lendingPoolCoreInstance: LendingPoolCoreInstance; });
// let _mockFlashLoanReceiverInstance: MockFlashLoanReceiverInstance;
// let _priceOracleInstance: IPriceOracleInstance;
// let _aTokenInstances: iATokenBase<ATokenInstance>;
// let _tokenInstances: iAssetsWithoutETH<MintableERC20Instance>;
// let _tokenDistributor: TokenDistributorInstance;
// let _daiAddress: string;
// let _depositorAddress: string;
// let _web3: Web3;
// let _initialDepositorETHBalance: string;
// before('Initializing LendingPool test variables', async () => { it("Deposits ETH into the reserve", async () => {
// console.time('setup-test'); const {pool} = testEnv;
// _testEnvProvider = await testEnvProviderWithoutInstances(artifacts, [deployer, ...users]); const amountToDeposit = ethers.utils.parseEther("1");
// const { await pool.deposit(MOCK_ETH_ADDRESS, amountToDeposit, "0", {
// getWeb3, value: amountToDeposit,
// getAllAssetsInstances, });
// getFirstDepositorAddressOnTests, });
// getLendingPoolInstance,
// getLendingPoolCoreInstance,
// getPriceOracleInstance,
// getATokenInstances,
// getMockFlashLoanReceiverInstance,
// getTokenDistributorInstance,
// } = _testEnvProvider;
// const instances = await Promise.all([ it("Takes ETH flashloan, returns the funds correctly", async () => {
// getLendingPoolInstance(), const {pool, deployer} = testEnv;
// getLendingPoolCoreInstance(),
// getPriceOracleInstance(),
// getATokenInstances(),
// getMockFlashLoanReceiverInstance(),
// getAllAssetsInstances(),
// getTokenDistributorInstance(),
// ]);
// _lendingPoolInstance = instances[0]; // move funds to the MockFlashLoanReceiver contract to pay the fee
// _lendingPoolCoreInstance = instances[1]; await deployer.signer.sendTransaction({
// _priceOracleInstance = instances[2]; value: ethers.utils.parseEther("0.5"),
// _aTokenInstances = instances[3]; to: _mockFlashLoanReceiver.address,
// _mockFlashLoanReceiverInstance = instances[4]; });
// _tokenInstances = instances[5];
// _daiAddress = _tokenInstances.DAI.address;
// _depositorAddress = await getFirstDepositorAddressOnTests();
// _tokenDistributor = instances[6];
// _web3 = await getWeb3(); await pool.flashLoan(
// _initialDepositorETHBalance = await _web3.eth.getBalance(_depositorAddress); _mockFlashLoanReceiver.address,
MOCK_ETH_ADDRESS,
ethers.utils.parseEther("0.8"),
"0x10"
);
// console.timeEnd('setup-test'); ethers.utils.parseUnits("10000");
// });
// it('Deposits ETH into the reserve', async () => { const reserveData: any = await pool.getReserveData(MOCK_ETH_ADDRESS);
// const amountToDeposit = await convertToCurrencyDecimals(ETHEREUM_ADDRESS, '1'); const tokenDistributorBalance = await BRE.ethers.provider.getBalance(
_tokenDistributor.address
);
// await _lendingPoolInstance.deposit(ETHEREUM_ADDRESS, amountToDeposit, '0', { const currentLiquidityRate = reserveData.liquidityRate;
// from: _depositorAddress, const currentLiquidityIndex = reserveData.liquidityIndex;
// value: amountToDeposit,
// });
// });
// it('Takes ETH flashloan, returns the funds correctly', async () => { expect(reserveData.totalLiquidity).to.be.bignumber.equal(
// //move funds to the MockFlashLoanReceiver contract "1000504000000000000"
);
expect(currentLiquidityRate).to.be.bignumber.equal("0");
expect(currentLiquidityIndex).to.be.bignumber.equal(
"1000504000000000000000000000"
);
expect(tokenDistributorBalance).to.be.bignumber.equal("216000000000000");
});
// let send = web3.eth.sendTransaction({ it("Takes an ETH flashloan as big as the available liquidity", async () => {
// from: deployer, const {pool, deployer} = testEnv;
// to: _mockFlashLoanReceiverInstance.address,
// value: web3.utils.toWei('0.5', 'ether'),
// });
// const txResult = await _lendingPoolInstance.flashLoan( // move funds to the MockFlashLoanReceiver contract to pay the fee
// _mockFlashLoanReceiverInstance.address, await deployer.signer.sendTransaction({
// ETHEREUM_ADDRESS, value: ethers.utils.parseEther("0.5"),
// new BigNumber(0.8).multipliedBy(oneEther), to: _mockFlashLoanReceiver.address,
// '0x10' });
// );
// const reserveData: any = await _lendingPoolInstance.getReserveData(ETHEREUM_ADDRESS); const txResult = await pool.flashLoan(
// const tokenDistributorBalance = await _web3.eth.getBalance(_tokenDistributor.address); _mockFlashLoanReceiver.address,
MOCK_ETH_ADDRESS,
"1000504000000000000",
"0x10"
);
// const currentLiquidityRate = reserveData.liquidityRate; const reserveData: any = await pool.getReserveData(MOCK_ETH_ADDRESS);
// const currentLiquidityIndex = reserveData.liquidityIndex; const tokenDistributorBalance = await BRE.ethers.provider.getBalance(
_tokenDistributor.address
);
// expect(reserveData.totalLiquidity.toString()).to.be.equal('1000504000000000000'); const currentLiqudityRate = reserveData.liquidityRate;
// expect(currentLiquidityRate.toString()).to.be.equal('0'); const currentLiquidityIndex = reserveData.liquidityIndex;
// expect(currentLiquidityIndex.toString()).to.be.equal('1000504000000000000000000000');
// expect(tokenDistributorBalance.toString()).to.be.equal('216000000000000');
// });
// it('Takes an ETH flashloan as big as the available liquidity', async () => { expect(reserveData.totalLiquidity).to.be.bignumber.equal(
// //move funds to the MockFlashLoanReceiver contract "1001134317520000000"
);
expect(currentLiqudityRate).to.be.bignumber.equal("0");
expect(currentLiquidityIndex).to.be.bignumber.equal(
"1001134317520000000000000000"
);
expect(tokenDistributorBalance).to.be.bignumber.equal("486136080000000");
});
// let send = web3.eth.sendTransaction({ it("Takes ETH flashloan, does not return the funds (revert expected)", async () => {
// from: deployer, const {pool, deployer} = testEnv;
// to: _mockFlashLoanReceiverInstance.address,
// value: web3.utils.toWei('0.5', 'ether'),
// });
// const txResult = await _lendingPoolInstance.flashLoan( // move funds to the MockFlashLoanReceiver contract to pay the fee
// _mockFlashLoanReceiverInstance.address, await deployer.signer.sendTransaction({
// ETHEREUM_ADDRESS, value: ethers.utils.parseEther("0.5"),
// '1000504000000000000', to: _mockFlashLoanReceiver.address,
// '0x10' });
// );
// const reserveData: any = await _lendingPoolInstance.getReserveData(ETHEREUM_ADDRESS); await _mockFlashLoanReceiver.setFailExecutionTransfer(true);
// const tokenDistributorBalance = await _web3.eth.getBalance(_tokenDistributor.address);
// const currentLiqudityRate = reserveData.liquidityRate; await expect(
// const currentLiquidityIndex = reserveData.liquidityIndex; pool.flashLoan(
_mockFlashLoanReceiver.address,
MOCK_ETH_ADDRESS,
ethers.utils.parseEther("0.8"),
"0x10"
),
INCONSISTENT_PROTOCOL_BALANCE
).to.be.revertedWith(INCONSISTENT_PROTOCOL_BALANCE);
});
// expect(reserveData.totalLiquidity.toString()).to.be.equal('1001134317520000000'); it("tries to take a very small flashloan, which would result in 0 fees (revert expected)", async () => {
// expect(currentLiqudityRate.toString()).to.be.equal('0'); const {pool} = testEnv;
// expect(currentLiquidityIndex.toString()).to.be.equal('1001134317520000000000000000');
// expect(tokenDistributorBalance.toString()).to.be.equal('486136080000000');
// });
// it('Takes ETH flashloan, does not return the funds (revert expected)', async () => { await expect(
// //move funds to the MockFlashLoanReceiver contract pool.flashLoan(
_mockFlashLoanReceiver.address,
MOCK_ETH_ADDRESS,
"1", //1 wei loan
"0x10"
),
TOO_SMALL_FLASH_LOAN
).to.be.revertedWith(TOO_SMALL_FLASH_LOAN);
});
// let send = web3.eth.sendTransaction({ it("tries to take a flashloan that is bigger than the available liquidity (revert expected)", async () => {
// from: deployer, const {pool} = testEnv;
// to: _mockFlashLoanReceiverInstance.address,
// value: web3.utils.toWei('0.5', 'ether'),
// });
// await _mockFlashLoanReceiverInstance.setFailExecutionTransfer(true); await expect(
pool.flashLoan(
_mockFlashLoanReceiver.address,
MOCK_ETH_ADDRESS,
"1004415000000000000", //slightly higher than the available liquidity
"0x10"
),
NOT_ENOUGH_LIQUIDITY_TO_BORROW
).to.be.revertedWith(NOT_ENOUGH_LIQUIDITY_TO_BORROW);
});
// await expectRevert( it("tries to take a flashloan using a non contract address as receiver (revert expected)", async () => {
// _lendingPoolInstance.flashLoan( const {pool, deployer} = testEnv;
// _mockFlashLoanReceiverInstance.address,
// ETHEREUM_ADDRESS,
// new BigNumber(0.8).multipliedBy(oneEther),
// '0x10'
// ),
// 'The actual balance of the protocol is inconsistent'
// );
// });
// it('tries to take a very small flashloan, which would result in 0 fees (revert expected)', async () => { await expect(
// //move funds to the MockFlashLoanReceiver contract pool.flashLoan(
deployer.address,
MOCK_ETH_ADDRESS,
"1000000000000000000",
"0x10"
)
).to.be.reverted;
});
// await expectRevert( it("Deposits DAI into the reserve", async () => {
// _lendingPoolInstance.flashLoan( const {dai, core, pool} = testEnv;
// _mockFlashLoanReceiverInstance.address,
// ETHEREUM_ADDRESS,
// '1', //1 wei loan
// '0x10'
// ),
// 'The requested amount is too small for a flashLoan.'
// );
// });
// it('tries to take a flashloan that is bigger than the available liquidity (revert expected)', async () => { await dai.mint(await convertToCurrencyDecimals(dai.address, "1000"));
// //move funds to the MockFlashLoanReceiver contract
// await expectRevert( await dai.approve(core.address, APPROVAL_AMOUNT_LENDING_POOL_CORE);
// _lendingPoolInstance.flashLoan(
// _mockFlashLoanReceiverInstance.address,
// ETHEREUM_ADDRESS,
// '1004415000000000000', //slightly higher than the available liquidity
// '0x10'
// ),
// 'There is not enough liquidity available to borrow'
// );
// });
// it('tries to take a flashloan using a non contract address as receiver (revert expected)', async () => { const amountToDeposit = await convertToCurrencyDecimals(
// //move funds to the MockFlashLoanReceiver contract dai.address,
"1000"
);
// await expectRevert( await pool.deposit(dai.address, amountToDeposit, "0");
// _lendingPoolInstance.flashLoan(deployer, ETHEREUM_ADDRESS, '1000000000000000000', '0x10'), });
// 'revert'
// );
// });
// it('Deposits DAI into the reserve', async () => { it("Takes out a 500 DAI flashloan, returns the funds correctly", async () => {
// const {DAI: daiInstance} = _tokenInstances; const {dai, pool, deployer: depositor} = testEnv;
// //mints DAI to depositor await _mockFlashLoanReceiver.setFailExecutionTransfer(false);
// await daiInstance.mint(await convertToCurrencyDecimals(daiInstance.address, '1000'), {
// from: _depositorAddress,
// });
// //approve protocol to access depositor wallet await pool.flashLoan(
// await daiInstance.approve(_lendingPoolCoreInstance.address, APPROVAL_AMOUNT_LENDING_POOL_CORE, { _mockFlashLoanReceiver.address,
// from: _depositorAddress, dai.address,
// }); ethers.utils.parseEther("500"),
"0x10"
);
// const amountToDeposit = await convertToCurrencyDecimals(_daiAddress, '1000'); const reserveData = await pool.getReserveData(dai.address);
const userData = await pool.getUserReserveData(
dai.address,
depositor.address
);
// await _lendingPoolInstance.deposit(daiInstance.address, amountToDeposit, '0', { const totalLiquidity = reserveData.totalLiquidity.toString();
// from: _depositorAddress, const currentLiqudityRate = reserveData.liquidityRate.toString();
// }); const currentLiquidityIndex = reserveData.liquidityIndex.toString();
// }); const currentUserBalance = userData.currentATokenBalance.toString();
// it('Takes out a 500 DAI flashloan, returns the funds correctly', async () => { const expectedLiquidity = ethers.utils.parseEther("1000.315");
// const {DAI: daiInstance} = _tokenInstances;
// await _mockFlashLoanReceiverInstance.setFailExecutionTransfer(false); const tokenDistributorBalance = await dai.balanceOf(
_tokenDistributor.address
);
// await _lendingPoolInstance.flashLoan( expect(totalLiquidity).to.be.equal(
// _mockFlashLoanReceiverInstance.address, expectedLiquidity,
// _daiAddress, "Invalid total liquidity"
// new BigNumber(500).multipliedBy(oneEther), );
// '0x10' expect(currentLiqudityRate).to.be.equal("0", "Invalid liquidity rate");
// ); expect(currentLiquidityIndex).to.be.equal(
new BigNumber("1.000315").multipliedBy(oneRay).toFixed(),
"Invalid liquidity index"
);
expect(currentUserBalance.toString()).to.be.equal(
expectedLiquidity,
"Invalid user balance"
);
// const reserveData: any = await _lendingPoolInstance.getReserveData(_daiAddress); expect(tokenDistributorBalance.toString()).to.be.equal(
// const userData: any = await _lendingPoolInstance.getUserReserveData(_daiAddress, deployer); ethers.utils.parseEther("0.135"),
"Invalid token distributor balance"
);
});
// const totalLiquidity = reserveData.totalLiquidity.toString(); it("Takes out a 500 DAI flashloan, does not return the funds (revert expected)", async () => {
// const currentLiqudityRate = reserveData.liquidityRate.toString(); const {dai, pool} = testEnv;
// const currentLiquidityIndex = reserveData.liquidityIndex.toString();
// const currentUserBalance = userData.currentATokenBalance.toString();
// const expectedLiquidity = new BigNumber('1000.315').multipliedBy(oneEther).toFixed(); await _mockFlashLoanReceiver.setFailExecutionTransfer(true);
// const tokenDistributorBalance = await daiInstance.balanceOf(_tokenDistributor.address); await expect(
pool.flashLoan(
// expect(totalLiquidity).to.be.equal(expectedLiquidity, 'Invalid total liquidity'); _mockFlashLoanReceiver.address,
// expect(currentLiqudityRate).to.be.equal('0', 'Invalid liquidity rate'); dai.address,
// expect(currentLiquidityIndex).to.be.equal( ethers.utils.parseEther("500"),
// new BigNumber('1.000315').multipliedBy(oneRay).toFixed(), "0x10"
// 'Invalid liquidity index' ),
// ); INCONSISTENT_PROTOCOL_BALANCE
// expect(currentUserBalance.toString()).to.be.equal(expectedLiquidity, 'Invalid user balance'); ).to.be.revertedWith(INCONSISTENT_PROTOCOL_BALANCE);
});
// expect(tokenDistributorBalance.toString()).to.be.equal( });
// new BigNumber('0.135').multipliedBy(oneEther).toFixed(),
// 'Invalid token distributor balance'
// );
// });
// it('Takes out a 500 DAI flashloan, does not return the funds (revert expected)', async () => {
// //move funds to the MockFlashLoanReceiver contract
// await _mockFlashLoanReceiverInstance.setFailExecutionTransfer(true);
// await expectRevert(
// _lendingPoolInstance.flashLoan(
// _mockFlashLoanReceiverInstance.address,
// _daiAddress,
// new BigNumber(500).multipliedBy(oneEther),
// '0x10'
// ),
// 'The actual balance of the protocol is inconsistent'
// );
// });
// });

View File

@ -1,4 +1,4 @@
import {evmRevert, evmSnapshot} from "../../helpers/misc-utils"; import {evmRevert, evmSnapshot, BRE} from "../../helpers/misc-utils";
import {TEST_SNAPSHOT_ID} from "../../helpers/constants"; import {TEST_SNAPSHOT_ID} from "../../helpers/constants";
import {Signer} from "ethers"; import {Signer} from "ethers";
import { import {
@ -41,6 +41,13 @@ export interface TestEnv {
aDai: AToken; aDai: AToken;
} }
let buidlerevmSnapshotId: string = "0x1";
const setBuidlerevmSnapshotId = (id: string) => {
if (BRE.network.name === "buidlerevm") {
buidlerevmSnapshotId = id;
}
};
export function makeSuite(name: string, tests: (testEnv: TestEnv) => void) { export function makeSuite(name: string, tests: (testEnv: TestEnv) => void) {
describe(name, () => { describe(name, () => {
const testEnv: TestEnv = { const testEnv: TestEnv = {
@ -56,7 +63,7 @@ export function makeSuite(name: string, tests: (testEnv: TestEnv) => void) {
} as TestEnv; } as TestEnv;
before(async () => { before(async () => {
console.time("makeSuite"); console.time("makeSuite");
await evmSnapshot(); setBuidlerevmSnapshotId(await evmSnapshot());
const [_deployer, ...restSigners] = await getEthersSigners(); const [_deployer, ...restSigners] = await getEthersSigners();
const deployer: SignerWithAddress = { const deployer: SignerWithAddress = {
address: await _deployer.getAddress(), address: await _deployer.getAddress(),
@ -97,7 +104,7 @@ export function makeSuite(name: string, tests: (testEnv: TestEnv) => void) {
}); });
tests(testEnv); tests(testEnv);
after(async () => { after(async () => {
await evmRevert(TEST_SNAPSHOT_ID); await evmRevert(buidlerevmSnapshotId);
}); });
}); });
} }