2020-07-13 08:54:08 +00:00
|
|
|
import {evmRevert, evmSnapshot, BRE} from '../../helpers/misc-utils';
|
|
|
|
import {Signer} from 'ethers';
|
2020-06-10 15:01:32 +00:00
|
|
|
import {
|
|
|
|
getEthersSigners,
|
|
|
|
getLendingPool,
|
|
|
|
getLendingPoolAddressesProvider,
|
|
|
|
getAaveProtocolTestHelpers,
|
|
|
|
getAToken,
|
|
|
|
getMintableErc20,
|
2020-07-13 08:54:08 +00:00
|
|
|
getLendingPoolConfiguratorProxy,
|
|
|
|
getPriceOracle,
|
2020-10-08 13:41:48 +00:00
|
|
|
getLendingPoolAddressesProviderRegistry,
|
2020-10-27 12:18:30 +00:00
|
|
|
getUniswapLiquiditySwapAdapter,
|
|
|
|
getUniswapRepayAdapter,
|
2020-06-18 14:36:37 +00:00
|
|
|
} from '../../helpers/contracts-helpers';
|
2020-07-13 08:54:08 +00:00
|
|
|
import {tEthereumAddress} from '../../helpers/types';
|
|
|
|
import {LendingPool} from '../../types/LendingPool';
|
|
|
|
import {AaveProtocolTestHelpers} from '../../types/AaveProtocolTestHelpers';
|
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-27 12:18:30 +00:00
|
|
|
import {UniswapLiquiditySwapAdapter} from '../../types/UniswapLiquiditySwapAdapter';
|
|
|
|
import {UniswapRepayAdapter} from '../../types/UniswapRepayAdapter';
|
2020-06-12 07:41:30 +00:00
|
|
|
chai.use(bignumberChai());
|
2020-08-21 10:38:08 +00:00
|
|
|
chai.use(almostEqual());
|
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-08-25 15:15:27 +00:00
|
|
|
weth: MintableERC20;
|
2020-08-13 11:06:23 +00:00
|
|
|
aEth: 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;
|
|
|
|
lend: MintableERC20;
|
2020-07-13 08:54:08 +00:00
|
|
|
addressesProvider: LendingPoolAddressesProvider;
|
2020-10-27 12:18:30 +00:00
|
|
|
uniswapLiquiditySwapAdapter: UniswapLiquiditySwapAdapter;
|
|
|
|
uniswapRepayAdapter: UniswapRepayAdapter;
|
2020-09-23 09:21:49 +00:00
|
|
|
registry: LendingPoolAddressesProviderRegistry;
|
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-07-13 08:54:08 +00:00
|
|
|
if (BRE.network.name === 'buidlerevm') {
|
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,
|
|
|
|
helpersContract: {} as AaveProtocolTestHelpers,
|
|
|
|
oracle: {} as PriceOracle,
|
2020-08-25 15:15:27 +00:00
|
|
|
weth: {} as MintableERC20,
|
2020-08-13 11:06:23 +00:00
|
|
|
aEth: {} 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,
|
|
|
|
lend: {} as MintableERC20,
|
2020-07-13 08:54:08 +00:00
|
|
|
addressesProvider: {} as LendingPoolAddressesProvider,
|
2020-10-27 12:18:30 +00:00
|
|
|
uniswapLiquiditySwapAdapter: {} as UniswapLiquiditySwapAdapter,
|
|
|
|
uniswapRepayAdapter: {} as UniswapRepayAdapter,
|
2020-10-08 13:41:48 +00:00
|
|
|
registry: {} as LendingPoolAddressesProviderRegistry,
|
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-07-13 08:54:08 +00:00
|
|
|
console.log('Pool loaded');
|
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
|
|
|
console.log('Configurator loaded');
|
|
|
|
|
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-06-18 14:36:37 +00:00
|
|
|
testEnv.helpersContract = await getAaveProtocolTestHelpers();
|
2020-07-13 08:54:08 +00:00
|
|
|
|
2020-06-18 14:36:37 +00:00
|
|
|
const aDaiAddress = (await testEnv.helpersContract.getAllATokens()).find(
|
2020-07-13 08:54:08 +00:00
|
|
|
(aToken) => aToken.symbol === 'aDAI'
|
2020-06-18 14:36:37 +00:00
|
|
|
)?.tokenAddress;
|
2020-08-13 11:06:23 +00:00
|
|
|
|
|
|
|
const aEthAddress = (await testEnv.helpersContract.getAllATokens()).find(
|
|
|
|
(aToken) => aToken.symbol === 'aETH'
|
|
|
|
)?.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;
|
|
|
|
const lendAddress = reservesTokens.find((token) => token.symbol === 'LEND')?.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-08-13 11:06:23 +00:00
|
|
|
if (!aDaiAddress || !aEthAddress) {
|
|
|
|
console.log(`atoken-modifiers.spec: aTokens not correctly initialized`);
|
2020-06-18 14:36:37 +00:00
|
|
|
process.exit(1);
|
|
|
|
}
|
2020-08-21 10:38:08 +00:00
|
|
|
if (!daiAddress || !usdcAddress || !lendAddress || !wethAddress) {
|
2020-06-18 14:36:37 +00:00
|
|
|
console.log(`atoken-modifiers.spec: USDC or DAI not correctly initialized`);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
testEnv.aDai = await getAToken(aDaiAddress);
|
2020-08-13 11:06:23 +00:00
|
|
|
testEnv.aEth = await getAToken(aEthAddress);
|
|
|
|
|
2020-06-18 14:36:37 +00:00
|
|
|
testEnv.dai = await getMintableErc20(daiAddress);
|
|
|
|
testEnv.usdc = await getMintableErc20(usdcAddress);
|
2020-06-27 02:13:32 +00:00
|
|
|
testEnv.lend = await getMintableErc20(lendAddress);
|
2020-08-13 11:06:23 +00:00
|
|
|
testEnv.weth = await getMintableErc20(wethAddress);
|
2020-09-08 13:05:53 +00:00
|
|
|
|
2020-10-27 12:18:30 +00:00
|
|
|
testEnv.uniswapLiquiditySwapAdapter = await getUniswapLiquiditySwapAdapter();
|
|
|
|
testEnv.uniswapRepayAdapter = await getUniswapRepayAdapter();
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|