-
Notifications
You must be signed in to change notification settings - Fork 15
/
logic.deposit.test.ts
99 lines (93 loc) · 3.62 KB
/
logic.deposit.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { DepositLogic, DepositLogicFields } from './logic.deposit';
import { LendingPool__factory } from './contracts';
import { LogicTestCase } from 'test/types';
import { Service } from './service';
import * as common from '@protocolink/common';
import { constants, utils } from 'ethers';
import * as core from '@protocolink/core';
import { expect } from 'chai';
import { mainnetTokens } from './tokens';
describe('AaveV2 DepositLogic', function () {
context('Test getTokenList', async function () {
DepositLogic.supportedChainIds.forEach((chainId) => {
it(`network: ${common.toNetworkId(chainId)}`, async function () {
const logic = new DepositLogic(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 DepositLogic(chainId);
let lendingPoolAddress: string;
const iface = LendingPool__factory.createInterface();
const account = '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa';
before(async function () {
const service = new Service(chainId);
lendingPoolAddress = await service.getLendingPoolAddress();
});
const testCases: LogicTestCase<DepositLogicFields>[] = [
{
fields: {
input: new common.TokenAmount(mainnetTokens.ETH, '1'),
output: new common.TokenAmount(mainnetTokens.aWETH, '1'),
},
},
{
fields: {
input: new common.TokenAmount(mainnetTokens.WETH, '1'),
output: new common.TokenAmount(mainnetTokens.aWETH, '1'),
},
},
{
fields: {
input: new common.TokenAmount(mainnetTokens.USDC, '1'),
output: new common.TokenAmount(mainnetTokens.aUSDC, '1'),
},
},
{
fields: {
input: new common.TokenAmount(mainnetTokens.ETH, '1'),
output: new common.TokenAmount(mainnetTokens.aWETH, '1'),
balanceBps: 5000,
},
},
{
fields: {
input: new common.TokenAmount(mainnetTokens.WETH, '1'),
output: new common.TokenAmount(mainnetTokens.aWETH, '1'),
balanceBps: 5000,
},
},
{
fields: {
input: new common.TokenAmount(mainnetTokens.USDC, '1'),
output: new common.TokenAmount(mainnetTokens.aUSDC, '1'),
balanceBps: 5000,
},
},
];
testCases.forEach(({ fields }) => {
it(`deposit ${fields.input.token.symbol}${fields.balanceBps ? ' with balanceBps' : ''}`, async function () {
const routerLogic = await logic.build(fields, { account });
const sig = routerLogic.data.substring(0, 10);
const { input, balanceBps } = fields;
expect(routerLogic.to).to.eq(lendingPoolAddress);
expect(utils.isBytesLike(routerLogic.data)).to.be.true;
expect(sig).to.eq(iface.getSighash('deposit'));
expect(routerLogic.inputs[0].token).to.eq(input.token.wrapped.address);
if (balanceBps) {
expect(routerLogic.inputs[0].balanceBps).to.eq(balanceBps);
expect(routerLogic.inputs[0].amountOrOffset).to.eq(common.getParamOffset(1));
} else {
expect(routerLogic.inputs[0].balanceBps).to.eq(core.BPS_NOT_USED);
expect(routerLogic.inputs[0].amountOrOffset).eq(input.amountWei);
}
expect(routerLogic.wrapMode).to.eq(input.token.isNative ? core.WrapMode.wrapBefore : core.WrapMode.none);
expect(routerLogic.approveTo).to.eq(constants.AddressZero);
expect(routerLogic.callback).to.eq(constants.AddressZero);
});
});
});
});