2020-11-05 12:44:20 +00:00
|
|
|
import {evmRevert, evmSnapshot, DRE} from '../../helpers/misc-utils';
|
2020-07-13 08:54:08 +00:00
|
|
|
import {Signer} from 'ethers';
|
2020-06-10 15:01:32 +00:00
|
|
|
import {
|
|
|
|
getLendingPool,
|
|
|
|
getLendingPoolAddressesProvider,
|
2020-11-10 14:19:47 +00:00
|
|
|
getAaveProtocolDataProvider,
|
2020-06-10 15:01:32 +00:00
|
|
|
getAToken,
|
|
|
|
getMintableErc20,
|
2020-07-13 08:54:08 +00:00
|
|
|
getLendingPoolConfiguratorProxy,
|
|
|
|
getPriceOracle,
|
2020-10-08 13:41:48 +00:00
|
|
|
getLendingPoolAddressesProviderRegistry,
|
2020-10-29 11:44:21 +00:00
|
|
|
getWETHMocked,
|
|
|
|
getWETHGateway,
|
2020-10-15 17:19:02 +00:00
|
|
|
} from '../../helpers/contracts-getters';
|
2020-07-13 08:54:08 +00:00
|
|
|
import {tEthereumAddress} from '../../helpers/types';
|
|
|
|
import {LendingPool} from '../../types/LendingPool';
|
2020-11-10 14:19:47 +00:00
|
|
|
import {AaveProtocolDataProvider} from '../../types/AaveProtocolDataProvider';
|
2020-08-25 15:15:27 +00:00
|
|
|
import {MintableErc20 as MintableERC20} from '../../types/MintableErc20';
|
2020-07-13 08:54:08 +00:00
|
|
|
import {AToken} from '../../types/AToken';
|
|
|
|
import {LendingPoolConfigurator} from '../../types/LendingPoolConfigurator';
|
2020-06-12 07:41:30 +00:00
|
|
|
|
2020-07-13 08:54:08 +00:00
|
|
|
import chai from 'chai';
|
2020-06-12 07:41:30 +00:00
|
|
|
// @ts-ignore
|
2020-07-13 08:54:08 +00:00
|
|
|
import bignumberChai from 'chai-bignumber';
|
2020-08-21 10:38:08 +00:00
|
|
|
import {almostEqual} from './almost-equal';
|
2020-07-13 08:54:08 +00:00
|
|
|
import {PriceOracle} from '../../types/PriceOracle';
|
|
|
|
import {LendingPoolAddressesProvider} from '../../types/LendingPoolAddressesProvider';
|
2020-10-08 13:41:48 +00:00
|
|
|
import {LendingPoolAddressesProviderRegistry} from '../../types/LendingPoolAddressesProviderRegistry';
|
2020-10-15 17:19:02 +00:00
|
|
|
import {getEthersSigners} from '../../helpers/contracts-helpers';
|
2020-10-29 11:44:21 +00:00
|
|
|
import {Weth9Mocked} from '../../types/Weth9Mocked';
|
|
|
|
import {WethGateway} from '../../types/WethGateway';
|
2020-10-29 14:50:32 +00:00
|
|
|
import {solidity} from 'ethereum-waffle';
|
|
|
|
|
2020-06-12 07:41:30 +00:00
|
|
|
chai.use(bignumberChai());
|
2020-08-21 10:38:08 +00:00
|
|
|
chai.use(almostEqual());
|
2020-10-29 14:50:32 +00:00
|
|
|
chai.use(solidity);
|
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-11-10 14:19:47 +00:00
|
|
|
helpersContract: AaveProtocolDataProvider;
|
2020-10-29 11:44:21 +00:00
|
|
|
weth: Weth9Mocked;
|
2020-10-28 14:49:50 +00:00
|
|
|
aWETH: AToken;
|
2020-08-25 15:15:27 +00:00
|
|
|
dai: MintableERC20;
|
2020-06-12 07:41:30 +00:00
|
|
|
aDai: AToken;
|
2020-08-25 15:15:27 +00:00
|
|
|
usdc: MintableERC20;
|
2020-11-02 11:37:57 +00:00
|
|
|
aave: MintableERC20;
|
2020-07-13 08:54:08 +00:00
|
|
|
addressesProvider: LendingPoolAddressesProvider;
|
2020-09-23 09:21:49 +00:00
|
|
|
registry: LendingPoolAddressesProviderRegistry;
|
2020-10-29 11:44:21 +00:00
|
|
|
wethGateway: WethGateway;
|
2020-06-12 07:41:30 +00:00
|
|
|
}
|
2020-06-10 15:01:32 +00:00
|
|
|
|
2020-07-13 08:54:08 +00:00
|
|
|
let buidlerevmSnapshotId: string = '0x1';
|
2020-06-12 13:41:52 +00:00
|
|
|
const setBuidlerevmSnapshotId = (id: string) => {
|
2020-11-05 12:44:20 +00:00
|
|
|
if (DRE.network.name === 'hardhat') {
|
2020-06-12 13:41:52 +00:00
|
|
|
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,
|
2020-11-10 14:19:47 +00:00
|
|
|
helpersContract: {} as AaveProtocolDataProvider,
|
2020-06-18 14:36:37 +00:00
|
|
|
oracle: {} as PriceOracle,
|
2020-10-29 11:44:21 +00:00
|
|
|
weth: {} as Weth9Mocked,
|
2020-10-28 14:49:50 +00:00
|
|
|
aWETH: {} as AToken,
|
2020-08-25 15:15:27 +00:00
|
|
|
dai: {} as MintableERC20,
|
2020-06-18 14:36:37 +00:00
|
|
|
aDai: {} as AToken,
|
2020-08-25 15:15:27 +00:00
|
|
|
usdc: {} as MintableERC20,
|
2020-11-02 11:37:57 +00:00
|
|
|
aave: {} as MintableERC20,
|
2020-07-13 08:54:08 +00:00
|
|
|
addressesProvider: {} as LendingPoolAddressesProvider,
|
2020-10-08 13:41:48 +00:00
|
|
|
registry: {} as LendingPoolAddressesProviderRegistry,
|
2020-10-29 11:44:21 +00:00
|
|
|
wethGateway: {} as WethGateway,
|
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();
|
2020-06-26 12:34:44 +00:00
|
|
|
|
2020-06-18 14:36:37 +00:00
|
|
|
testEnv.configurator = await getLendingPoolConfiguratorProxy();
|
2020-07-13 08:54:08 +00:00
|
|
|
|
2020-06-18 14:36:37 +00:00
|
|
|
testEnv.oracle = await getPriceOracle();
|
|
|
|
testEnv.addressesProvider = await getLendingPoolAddressesProvider();
|
2020-09-23 09:21:49 +00:00
|
|
|
testEnv.registry = await getLendingPoolAddressesProviderRegistry();
|
2020-07-13 08:54:08 +00:00
|
|
|
|
2020-11-10 14:19:47 +00:00
|
|
|
testEnv.helpersContract = await getAaveProtocolDataProvider();
|
2020-07-13 08:54:08 +00:00
|
|
|
|
2020-10-23 16:38:27 +00:00
|
|
|
const allTokens = await testEnv.helpersContract.getAllATokens();
|
|
|
|
const aDaiAddress = allTokens.find((aToken) => aToken.symbol === 'aDAI')?.tokenAddress;
|
2020-08-13 11:06:23 +00:00
|
|
|
|
2020-10-28 14:49:50 +00:00
|
|
|
const aWEthAddress = allTokens.find((aToken) => aToken.symbol === 'aWETH')?.tokenAddress;
|
2020-06-18 14:36:37 +00:00
|
|
|
|
|
|
|
const reservesTokens = await testEnv.helpersContract.getAllReservesTokens();
|
2020-06-26 12:34:44 +00:00
|
|
|
|
2020-07-13 08:54:08 +00:00
|
|
|
const daiAddress = reservesTokens.find((token) => token.symbol === 'DAI')?.tokenAddress;
|
|
|
|
const usdcAddress = reservesTokens.find((token) => token.symbol === 'USDC')?.tokenAddress;
|
2020-11-02 11:37:57 +00:00
|
|
|
const aaveAddress = reservesTokens.find((token) => token.symbol === 'AAVE')?.tokenAddress;
|
2020-08-13 11:06:23 +00:00
|
|
|
const wethAddress = reservesTokens.find((token) => token.symbol === 'WETH')?.tokenAddress;
|
2020-07-13 08:54:08 +00:00
|
|
|
|
2020-10-28 14:49:50 +00:00
|
|
|
if (!aDaiAddress || !aWEthAddress) {
|
2020-06-18 14:36:37 +00:00
|
|
|
process.exit(1);
|
|
|
|
}
|
2020-11-02 11:37:57 +00:00
|
|
|
if (!daiAddress || !usdcAddress || !aaveAddress || !wethAddress) {
|
2020-06-18 14:36:37 +00:00
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
testEnv.aDai = await getAToken(aDaiAddress);
|
2020-10-28 14:49:50 +00:00
|
|
|
testEnv.aWETH = await getAToken(aWEthAddress);
|
2020-08-13 11:06:23 +00:00
|
|
|
|
2020-06-18 14:36:37 +00:00
|
|
|
testEnv.dai = await getMintableErc20(daiAddress);
|
|
|
|
testEnv.usdc = await getMintableErc20(usdcAddress);
|
2020-11-02 11:37:57 +00:00
|
|
|
testEnv.aave = await getMintableErc20(aaveAddress);
|
2020-10-29 11:44:21 +00:00
|
|
|
testEnv.weth = await getWETHMocked(wethAddress);
|
|
|
|
testEnv.wethGateway = await getWETHGateway();
|
2020-06-18 14:36:37 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|