-
Notifications
You must be signed in to change notification settings - Fork 15
/
logic.flash-loan.test.ts
56 lines (50 loc) · 2.03 KB
/
logic.flash-loan.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { FlashLoanLogic, FlashLoanLogicFields } from './logic.flash-loan';
import { LogicTestCase } from 'test/types';
import { Pool__factory } from './contracts';
import { Service } from './service';
import * as common from '@protocolink/common';
import { constants, utils } from 'ethers';
import { expect } from 'chai';
import { getContractAddress } from './configs';
import { mainnetTokens } from './tokens';
describe('AaveV3 FlashLoanLogic', function () {
context('Test getTokenList', async function () {
FlashLoanLogic.supportedChainIds.forEach((chainId) => {
it(`network: ${common.toNetworkId(chainId)}`, async function () {
const logic = new FlashLoanLogic(chainId);
const tokenList = await logic.getTokenList();
expect(tokenList).to.have.lengthOf.above(0);
});
});
});
context('Test build', function () {
const chainId = common.ChainId.mainnet;
const logic = new FlashLoanLogic(chainId);
let poolAddress: string;
const iface = Pool__factory.createInterface();
before(async function () {
const service = new Service(chainId);
poolAddress = await service.getPoolAddress();
});
const testCases: LogicTestCase<FlashLoanLogicFields>[] = [
{
fields: {
loans: new common.TokenAmounts([mainnetTokens.WETH, '1'], [mainnetTokens.USDC, '1']),
params: '0x',
},
},
];
testCases.forEach(({ fields }) => {
it(`flash loan ${fields.loans.map((loan) => loan.token.symbol).join(',')}`, async function () {
const routerLogic = await logic.build(fields);
const sig = routerLogic.data.substring(0, 10);
expect(routerLogic.to).to.eq(poolAddress);
expect(utils.isBytesLike(routerLogic.data)).to.be.true;
expect(sig).to.eq(iface.getSighash('flashLoan'));
expect(routerLogic.inputs).to.deep.eq([]);
expect(routerLogic.approveTo).to.eq(constants.AddressZero);
expect(routerLogic.callback).to.eq(getContractAddress(chainId, 'AaveV3FlashLoanCallback'));
});
});
});
});