2020-06-12 13:41:52 +00:00
|
|
|
import {evmRevert, evmSnapshot, BRE} from "../../helpers/misc-utils";
|
2020-06-10 15:01:32 +00:00
|
|
|
import {Signer} from "ethers";
|
|
|
|
import {
|
|
|
|
getEthersSigners,
|
|
|
|
getLendingPool,
|
|
|
|
getLendingPoolAddressesProvider,
|
|
|
|
getAaveProtocolTestHelpers,
|
|
|
|
getAToken,
|
|
|
|
getMintableErc20,
|
2020-06-18 14:36:37 +00:00
|
|
|
getLendingPoolConfiguratorProxy, getPriceOracle,
|
|
|
|
} from '../../helpers/contracts-helpers';
|
2020-06-10 15:01:32 +00:00
|
|
|
import {tEthereumAddress} from "../../helpers/types";
|
|
|
|
import {LendingPool} from "../../types/LendingPool";
|
|
|
|
import {AaveProtocolTestHelpers} from "../../types/AaveProtocolTestHelpers";
|
|
|
|
import {MintableErc20} from "../../types/MintableErc20";
|
|
|
|
import {AToken} from "../../types/AToken";
|
2020-06-12 07:41:30 +00:00
|
|
|
import {LendingPoolConfigurator} from "../../types/LendingPoolConfigurator";
|
|
|
|
|
|
|
|
import chai from "chai";
|
|
|
|
// @ts-ignore
|
|
|
|
import bignumberChai from "chai-bignumber";
|
2020-06-18 14:36:37 +00:00
|
|
|
import { PriceOracle } from '../../types/PriceOracle';
|
2020-06-20 23:40:03 +00:00
|
|
|
import { LendingPoolAddressesProvider } from "../../types/LendingPoolAddressesProvider";
|
2020-06-12 07:41:30 +00:00
|
|
|
chai.use(bignumberChai());
|
2020-06-10 12:47:39 +00:00
|
|
|
|
2020-06-10 15:01:32 +00:00
|
|
|
export interface SignerWithAddress {
|
|
|
|
signer: Signer;
|
|
|
|
address: tEthereumAddress;
|
|
|
|
}
|
2020-06-12 07:41:30 +00:00
|
|
|
export interface TestEnv {
|
2020-06-10 15:01:32 +00:00
|
|
|
deployer: SignerWithAddress;
|
|
|
|
users: SignerWithAddress[];
|
|
|
|
pool: LendingPool;
|
2020-06-12 07:41:30 +00:00
|
|
|
configurator: LendingPoolConfigurator;
|
2020-06-18 14:36:37 +00:00
|
|
|
oracle: PriceOracle;
|
2020-06-10 15:01:32 +00:00
|
|
|
helpersContract: AaveProtocolTestHelpers;
|
2020-06-12 07:41:30 +00:00
|
|
|
dai: MintableErc20;
|
|
|
|
aDai: AToken;
|
2020-06-18 14:36:37 +00:00
|
|
|
usdc: MintableErc20;
|
2020-06-20 23:40:03 +00:00
|
|
|
addressesProvider: LendingPoolAddressesProvider
|
2020-06-12 07:41:30 +00:00
|
|
|
}
|
2020-06-10 15:01:32 +00:00
|
|
|
|
2020-06-12 13:41:52 +00:00
|
|
|
let buidlerevmSnapshotId: string = "0x1";
|
|
|
|
const setBuidlerevmSnapshotId = (id: string) => {
|
|
|
|
if (BRE.network.name === "buidlerevm") {
|
|
|
|
buidlerevmSnapshotId = id;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-06-18 14:36:37 +00:00
|
|
|
const testEnv: TestEnv = {
|
|
|
|
deployer: {} as SignerWithAddress,
|
|
|
|
users: [] as SignerWithAddress[],
|
|
|
|
pool: {} as LendingPool,
|
|
|
|
configurator: {} as LendingPoolConfigurator,
|
|
|
|
helpersContract: {} as AaveProtocolTestHelpers,
|
|
|
|
oracle: {} as PriceOracle,
|
|
|
|
dai: {} as MintableErc20,
|
|
|
|
aDai: {} as AToken,
|
|
|
|
usdc: {} as MintableErc20,
|
2020-06-20 23:40:03 +00:00
|
|
|
addressesProvider: {} as LendingPoolAddressesProvider
|
2020-06-18 14:36:37 +00:00
|
|
|
} as TestEnv;
|
|
|
|
|
|
|
|
export async function initializeMakeSuite() {
|
|
|
|
const [_deployer, ...restSigners] = await getEthersSigners();
|
|
|
|
const deployer: SignerWithAddress = {
|
|
|
|
address: await _deployer.getAddress(),
|
|
|
|
signer: _deployer,
|
|
|
|
};
|
|
|
|
|
|
|
|
for (const signer of restSigners) {
|
|
|
|
testEnv.users.push({
|
|
|
|
signer,
|
|
|
|
address: await signer.getAddress(),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
testEnv.deployer = deployer;
|
|
|
|
testEnv.pool = await getLendingPool();
|
|
|
|
testEnv.configurator = await getLendingPoolConfiguratorProxy();
|
|
|
|
testEnv.oracle = await getPriceOracle();
|
|
|
|
testEnv.addressesProvider = await getLendingPoolAddressesProvider();
|
|
|
|
testEnv.helpersContract = await getAaveProtocolTestHelpers();
|
|
|
|
const aDaiAddress = (await testEnv.helpersContract.getAllATokens()).find(
|
|
|
|
(aToken) => aToken.symbol === "aDAI"
|
|
|
|
)?.tokenAddress;
|
|
|
|
|
|
|
|
const reservesTokens = await testEnv.helpersContract.getAllReservesTokens();
|
|
|
|
const daiAddress = reservesTokens.find(token => token.symbol === "DAI")?.tokenAddress;
|
|
|
|
const usdcAddress = reservesTokens.find(token => token.symbol === "USDC")?.tokenAddress;
|
|
|
|
if (!aDaiAddress) {
|
|
|
|
console.log(`atoken-modifiers.spec: aDAI not correctly initialized`);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
if (!daiAddress || !usdcAddress) {
|
|
|
|
console.log(`atoken-modifiers.spec: USDC or DAI not correctly initialized`);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
testEnv.aDai = await getAToken(aDaiAddress);
|
|
|
|
testEnv.dai = await getMintableErc20(daiAddress);
|
|
|
|
testEnv.usdc = await getMintableErc20(usdcAddress);
|
|
|
|
}
|
|
|
|
|
2020-06-10 15:01:32 +00:00
|
|
|
export function makeSuite(name: string, tests: (testEnv: TestEnv) => void) {
|
|
|
|
describe(name, () => {
|
2020-06-10 12:47:39 +00:00
|
|
|
before(async () => {
|
2020-06-12 13:41:52 +00:00
|
|
|
setBuidlerevmSnapshotId(await evmSnapshot());
|
2020-06-10 12:47:39 +00:00
|
|
|
});
|
2020-06-10 15:01:32 +00:00
|
|
|
tests(testEnv);
|
2020-06-10 12:47:39 +00:00
|
|
|
after(async () => {
|
2020-06-12 13:41:52 +00:00
|
|
|
await evmRevert(buidlerevmSnapshotId);
|
2020-06-10 12:47:39 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|