diff --git a/contracts/misc/AaveProtocolTestHelpers.sol b/contracts/misc/AaveProtocolTestHelpers.sol index 602679ca..89fba761 100644 --- a/contracts/misc/AaveProtocolTestHelpers.sol +++ b/contracts/misc/AaveProtocolTestHelpers.sol @@ -1,5 +1,6 @@ pragma solidity ^0.6.8; pragma experimental ABIEncoderV2; + import {ILendingPoolAddressesProvider} from "../interfaces/ILendingPoolAddressesProvider.sol"; import {LendingPoolCore} from "../lendingpool/LendingPool.sol"; import {AToken} from "../tokenization/AToken.sol"; @@ -19,7 +20,7 @@ contract AaveProtocolTestHelpers { function getAllATokens() external view returns(ATokenData[] memory) { LendingPoolCore core = LendingPoolCore(ADDRESSES_PROVIDER.getLendingPoolCore()); address[] memory reserves = core.getReserves(); - ATokenData[] memory aTokens; + ATokenData[] memory aTokens = new ATokenData[](reserves.length); for (uint256 i = 0; i < reserves.length; i++) { address aTokenAddress = core.getReserveATokenAddress(reserves[i]); aTokens[i] = ATokenData({ diff --git a/helpers/constants.ts b/helpers/constants.ts index d51891e7..b8c1c20e 100644 --- a/helpers/constants.ts +++ b/helpers/constants.ts @@ -12,6 +12,8 @@ import { import BigNumber from "bignumber.js"; import {getParamPerPool} from "./contracts-helpers"; +export const TEST_SNAPSHOT_ID = "0x1"; + // ---------------- // MATH // ---------------- diff --git a/test/__setup.spec.ts b/test/__setup.spec.ts index c2d9ce27..e977aa52 100644 --- a/test/__setup.spec.ts +++ b/test/__setup.spec.ts @@ -614,16 +614,6 @@ const buildTestEnv = async (deployer: Wallet, secondaryWallet: Wallet) => { const testHelpers = await deployAaveProtocolTestHelpers( addressesProvider.address ); - console.log(testHelpers.address); - console.log( - "Addresses provider on test helpers: ", - await testHelpers.ADDRESSES_PROVIDER() - ); - try { - console.log(await testHelpers.getAllATokens()); - } catch (error) { - console.log(error); - } await insertContractAddressInDb( eContractid.AaveProtocolTestHelpers, diff --git a/test/atoken-modifiers.spec.ts b/test/atoken-modifiers.spec.ts index a3bac18e..df0226e1 100644 --- a/test/atoken-modifiers.spec.ts +++ b/test/atoken-modifiers.spec.ts @@ -1,46 +1,48 @@ -import rawBRE from "@nomiclabs/buidler"; import {expect} from "chai"; import {MockProvider} from "ethereum-waffle"; -import {BuidlerRuntimeEnvironment} from "@nomiclabs/buidler/types"; -import {LendingPoolAddressesProvider} from "../types/LendingPoolAddressesProvider"; import { - getLendingPoolAddressesProvider, - getLendingPoolProxy, getAToken, getAaveProtocolTestHelpers, } from "../helpers/contracts-helpers"; import {evmRevert} from "../helpers/misc-utils"; +import {AToken} from "../types/AToken"; +import {TEST_SNAPSHOT_ID} from "../helpers/constants"; describe("AToken: Modifiers", () => { - const wallets = new MockProvider().getWallets(); - let BRE: BuidlerRuntimeEnvironment; + const [deployer, ...restWallets] = new MockProvider().getWallets(); + let _aDAI = {} as AToken; + const NOT_LENDING_POOL_MSG = + "The caller of this function must be a lending pool"; before(async () => { - await evmRevert("0x1"); - }); - - it("Tries to invoke mintOnDeposit", async () => { + await evmRevert(TEST_SNAPSHOT_ID); const testHelpers = await getAaveProtocolTestHelpers(); - console.log(await testHelpers.ADDRESSES_PROVIDER()); - console.log(await testHelpers.getAllATokens()) - // const aDAI = await getAToken(await lendingPool.getReserveConfigurationData()) - // await expectRevert( - // _aDAI.mintOnDeposit(deployer, "1"), - // "The caller of this function must be a lending pool" - // ); + + const aDAIAddress = (await testHelpers.getAllATokens()).find( + (aToken) => aToken.symbol === "aDAI" + )?.aTokenAddress; + if (!aDAIAddress) { + console.log(`atoken-modifiers.spec: aDAI not correctly initialized`); + process.exit(1); + } + _aDAI = await getAToken(aDAIAddress); }); - // it("Tries to invoke burnOnLiquidation", async () => { - // await expectRevert( - // _aDAI.burnOnLiquidation(deployer, "1"), - // "The caller of this function must be a lending pool" - // ); - // }); + it("Tries to invoke mintOnDeposit not being the LendingPool", async () => { + await expect(_aDAI.mintOnDeposit(deployer.address, "1")).to.be.revertedWith( + NOT_LENDING_POOL_MSG + ); + }); - // it("Tries to invoke transferOnLiquidation", async () => { - // await expectRevert( - // _aDAI.transferOnLiquidation(deployer, users[1], "1"), - // "The caller of this function must be a lending pool" - // ); - // }); + it("Tries to invoke burnOnLiquidation not being the LendingPool", async () => { + await expect( + _aDAI.burnOnLiquidation(deployer.address, "1") + ).to.be.revertedWith(NOT_LENDING_POOL_MSG); + }); + + it("Tries to invoke transferOnLiquidation not being the LendingPool", async () => { + await expect( + _aDAI.transferOnLiquidation(deployer.address, restWallets[0].address, "1") + ).to.be.revertedWith(NOT_LENDING_POOL_MSG); + }); }); diff --git a/test/lending-pool-addresses-provider.spec.ts b/test/lending-pool-addresses-provider.spec.ts index f364aaf9..0371426e 100644 --- a/test/lending-pool-addresses-provider.spec.ts +++ b/test/lending-pool-addresses-provider.spec.ts @@ -1,14 +1,14 @@ import {expect} from "chai"; import {MockProvider} from "ethereum-waffle"; -import {BuidlerRuntimeEnvironment} from "@nomiclabs/buidler/types"; import {getLendingPoolAddressesProvider} from "../helpers/contracts-helpers"; import {createRandomAddress, evmRevert} from "../helpers/misc-utils"; +import {TEST_SNAPSHOT_ID} from "../helpers/constants"; describe("LendingPoolAddressesProvider", () => { const wallets = new MockProvider().getWallets(); before(async () => { - await evmRevert("0x1"); + await evmRevert(TEST_SNAPSHOT_ID); }); it("Test the accessibility of the LendingPoolAddressesProvider", async () => {