Skip to content

Commit 5140ff8

Browse files
committed
fix: refactor tests
1 parent 69595cd commit 5140ff8

File tree

7 files changed

+97
-76
lines changed

7 files changed

+97
-76
lines changed

packages/spec/borrow/business.spec.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { assertOk, bigDecimal, evmAddress } from '@aave/client-next';
2-
import { borrow, userBorrows } from '@aave/client-next/actions';
2+
import { borrow, userBorrows, userSupplies } from '@aave/client-next/actions';
33
import {
44
client,
55
createNewWallet,
@@ -22,7 +22,7 @@ describe('Aave V4 Borrow Scenarios', () => {
2222
beforeAll(async () => {
2323
const setup = await fundErc20Address(evmAddress(user.account.address), {
2424
address: ETHEREUM_USDC_ADDRESS,
25-
amount: bigDecimal('100'),
25+
amount: bigDecimal('300'),
2626
decimals: 6,
2727
}).andThen(() =>
2828
supplyToRandomERC20Reserve(client, user, ETHEREUM_USDC_ADDRESS),
@@ -33,7 +33,19 @@ describe('Aave V4 Borrow Scenarios', () => {
3333
});
3434

3535
it(`Then the user's borrow positions are updated`, async () => {
36-
const amountToBorrow = bigDecimal('50');
36+
const position = await userSupplies(client, {
37+
query: {
38+
userChains: {
39+
chainIds: [reserve.chain.chainId],
40+
user: evmAddress(user.account.address),
41+
},
42+
},
43+
});
44+
45+
assertOk(position);
46+
assertSingleElementArray(position.value);
47+
const amountToBorrow =
48+
position.value[0].reserve.userState!.borrowable.value.formatted;
3749

3850
const result = await borrow(client, {
3951
sender: evmAddress(user.account.address),

packages/spec/borrow/helper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function findReserveToSupply(
4343
`No reserves found for the token ${token}`,
4444
);
4545
const reserveToSupply = listReserves.find(
46-
(reserve) => reserve.canSupply === true,
46+
(reserve) => reserve.status.active === true,
4747
);
4848
invariant(
4949
reserveToSupply,
@@ -57,7 +57,7 @@ export function supplyToRandomERC20Reserve(
5757
client: AaveClient,
5858
user: WalletClient<Transport, Chain, Account>,
5959
token: EvmAddress,
60-
amount = bigDecimal('100'),
60+
amount = bigDecimal('200'),
6161
): ResultAsync<Reserve, Error> {
6262
return findReserveToSupply(client, token).andThen((reserve) =>
6363
supplyToReserve(

packages/spec/positions/business.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('Aave V4 Health Factor Positions Scenarios', () => {
3131
beforeAll(async () => {
3232
const setup = await fundErc20Address(evmAddress(user.account.address), {
3333
address: ETHEREUM_USDC_ADDRESS,
34-
amount: bigDecimal('200'),
34+
amount: bigDecimal('300'),
3535
decimals: 6,
3636
}).andThen(() =>
3737
supplyToRandomERC20Reserve(client, user, ETHEREUM_USDC_ADDRESS),

packages/spec/repay/business.spec.ts

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,33 @@ import { permitTypedData, repay, userBorrows } from '@aave/client-next/actions';
33
import {
44
client,
55
createNewWallet,
6+
ETHEREUM_GHO_ADDRESS,
67
ETHEREUM_USDC_ADDRESS,
78
fundErc20Address,
89
} from '@aave/client-next/test-utils';
910
import { sendWith, signERC20PermitWith } from '@aave/client-next/viem';
1011
import type { Reserve } from '@aave/graphql-next';
11-
import { beforeEach, describe, expect, it } from 'vitest';
12+
import { beforeAll, describe, expect, it } from 'vitest';
1213
import { assertSingleElementArray } from '../test-utils';
1314
import { supplyAndBorrow } from './helper';
1415

1516
const user = await createNewWallet();
1617

1718
describe('Aave V4 Repay Scenario', () => {
1819
describe('Given a user with a borrow position', () => {
19-
let reserve: Reserve;
20-
21-
beforeEach(async () => {
22-
const setup = await fundErc20Address(evmAddress(user.account!.address), {
23-
address: ETHEREUM_USDC_ADDRESS,
24-
amount: bigDecimal('300'),
25-
decimals: 6,
26-
}).andThen(() => supplyAndBorrow(client, user, ETHEREUM_USDC_ADDRESS));
20+
describe('When the user repays their loan', () => {
21+
let reserve: Reserve;
2722

28-
assertOk(setup);
29-
reserve = setup.value;
30-
});
23+
beforeAll(async () => {
24+
const setup = await fundErc20Address(evmAddress(user.account.address), {
25+
address: ETHEREUM_USDC_ADDRESS,
26+
amount: bigDecimal('300'),
27+
decimals: 6,
28+
}).andThen(() => supplyAndBorrow(client, user, ETHEREUM_USDC_ADDRESS));
3129

32-
describe('When the user repays their loan', () => {
30+
assertOk(setup);
31+
reserve = setup.value;
32+
});
3333
// TODO: Enable when bug is fixed
3434
it.skip('Then it should be reflected in the user positions', async () => {
3535
const repayResult = await repay(client, {
@@ -68,11 +68,20 @@ describe('Aave V4 Repay Scenario', () => {
6868
});
6969

7070
describe('When the user repays a partial amount of their loan', () => {
71-
it('Then it should be reflected in the user positions', async ({
72-
annotate,
73-
}) => {
74-
annotate(`account address: ${evmAddress(user.account!.address)}`);
75-
annotate(`reserve id: ${reserve.id}`);
71+
let reserve: Reserve;
72+
73+
beforeAll(async () => {
74+
const setup = await fundErc20Address(evmAddress(user.account.address), {
75+
address: ETHEREUM_USDC_ADDRESS,
76+
amount: bigDecimal('300'),
77+
decimals: 6,
78+
}).andThen(() => supplyAndBorrow(client, user, ETHEREUM_USDC_ADDRESS));
79+
80+
assertOk(setup);
81+
reserve = setup.value;
82+
});
83+
84+
it('Then it should be reflected in the user positions', async () => {
7685
const amountToRepay = bigDecimal('25');
7786

7887
const repayResult = await repay(client, {
@@ -114,11 +123,21 @@ describe('Aave V4 Repay Scenario', () => {
114123
});
115124

116125
describe('When the user repays a loan with a permit signature', () => {
126+
let reserve: Reserve;
127+
128+
beforeAll(async () => {
129+
const setup = await fundErc20Address(evmAddress(user.account.address), {
130+
address: ETHEREUM_GHO_ADDRESS,
131+
amount: bigDecimal('300'),
132+
}).andThen(() => supplyAndBorrow(client, user, ETHEREUM_GHO_ADDRESS));
133+
134+
assertOk(setup);
135+
reserve = setup.value;
136+
});
137+
117138
it('Then it should allow to repay their own loan without needing for an ERC20 Approval transaction', async ({
118139
annotate,
119140
}) => {
120-
annotate(`account address: ${evmAddress(user.account!.address)}`);
121-
annotate(`reserve id: ${reserve.id}`);
122141
const amountToRepay = bigDecimal('25');
123142

124143
const signature = await permitTypedData(client, {

packages/spec/repay/helper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function supplyAndBorrow(
1414
client: AaveClient,
1515
user: WalletClient<Transport, Chain, Account>,
1616
token: EvmAddress,
17-
amount = bigDecimal('150'),
17+
amount = bigDecimal('200'),
1818
): ResultAsync<Reserve, Error> {
1919
return findReserveToSupply(client, token).andThen((reserve) =>
2020
supplyToReserve(
@@ -40,7 +40,7 @@ export function supplyAndBorrow(
4040
},
4141
amount: {
4242
erc20: {
43-
value: bigDecimal(Number(amount) / 3),
43+
value: bigDecimal(Number(amount) / 4),
4444
},
4545
},
4646
}),

packages/spec/supply/business.spec.ts

Lines changed: 36 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
createNewWallet,
1515
ETHEREUM_FORK_ID,
1616
ETHEREUM_USDC_ADDRESS,
17+
ETHEREUM_WETH_ADDRESS,
1718
fundErc20Address,
1819
} from '@aave/client-next/test-utils';
1920
import { sendWith, signERC20PermitWith } from '@aave/client-next/viem';
@@ -25,19 +26,21 @@ const user = await createNewWallet();
2526

2627
describe('Aave V4 Supply Scenarios', () => {
2728
describe('Given a user and a Reserve', () => {
28-
describe('When the user supplies tokens', () => {
29-
const amountToSupply = bigDecimal('94');
30-
31-
beforeAll(async () => {
32-
const setup = await fundErc20Address(evmAddress(user.account.address), {
33-
address: ETHEREUM_USDC_ADDRESS,
34-
amount: bigDecimal('100'),
35-
decimals: 6,
36-
});
37-
38-
assertOk(setup);
39-
});
29+
let reserveUSDC: Reserve;
30+
const amountToSupply = bigDecimal('5');
31+
32+
beforeAll(async () => {
33+
const setup = await fundErc20Address(evmAddress(user.account.address), {
34+
address: ETHEREUM_USDC_ADDRESS,
35+
amount: bigDecimal('300'),
36+
decimals: 6,
37+
}).andThen(() => findReserveToSupply(client, ETHEREUM_USDC_ADDRESS));
38+
39+
assertOk(setup);
40+
reserveUSDC = setup.value;
41+
});
4042

43+
describe('When the user supplies tokens', () => {
4144
describe("Then the user's supply positions are updated", async () => {
4245
it('And the supplied tokens are set as collateral by default', async () => {
4346
const reserveToSupply = await findReserveToSupply(
@@ -87,31 +90,31 @@ describe('Aave V4 Supply Scenarios', () => {
8790
});
8891

8992
describe('When the user supplies tokens with collateral disabled', () => {
90-
let reserve: Reserve;
93+
let reserveWETH: Reserve;
9194

9295
beforeAll(async () => {
9396
const setup = await fundErc20Address(evmAddress(user.account.address), {
94-
address: ETHEREUM_USDC_ADDRESS,
95-
amount: bigDecimal('100'),
97+
address: ETHEREUM_WETH_ADDRESS,
98+
amount: bigDecimal('1.0'),
9699
decimals: 6,
97-
}).andThen(() => findReserveToSupply(client, ETHEREUM_USDC_ADDRESS));
100+
}).andThen(() => findReserveToSupply(client, ETHEREUM_WETH_ADDRESS));
98101

99102
assertOk(setup);
100-
reserve = setup.value;
103+
reserveWETH = setup.value;
101104
});
102105

103106
it(`Then the user's supply positions are updated without collateral`, async () => {
104107
const result = await supplyToReserve(
105108
client,
106109
{
107110
reserve: {
108-
spoke: reserve.spoke.address,
109-
reserveId: reserve.id,
110-
chainId: reserve.chain.chainId,
111+
spoke: reserveWETH.spoke.address,
112+
reserveId: reserveWETH.id,
113+
chainId: reserveWETH.chain.chainId,
111114
},
112115
amount: {
113116
erc20: {
114-
value: bigDecimal('50'),
117+
value: bigDecimal('0.1'),
115118
},
116119
},
117120
sender: evmAddress(user.account.address),
@@ -123,8 +126,8 @@ describe('Aave V4 Supply Scenarios', () => {
123126
query: {
124127
userSpoke: {
125128
spoke: {
126-
address: reserve.spoke.address,
127-
chainId: reserve.chain.chainId,
129+
address: reserveWETH.spoke.address,
130+
chainId: reserveWETH.chain.chainId,
128131
},
129132
user: evmAddress(user.account.address),
130133
},
@@ -133,28 +136,15 @@ describe('Aave V4 Supply Scenarios', () => {
133136
);
134137
assertOk(result);
135138
assertSingleElementArray(result.value);
136-
expect(result.value[0].isCollateral).toBe(false);
139+
expect(result.value[0].isCollateral).toEqual(false);
137140
expect(result.value[0].amount.value.formatted).toBeBigDecimalCloseTo(
138-
bigDecimal('50'),
139-
2,
141+
bigDecimal('0.1'),
142+
3,
140143
);
141144
});
142145
});
143146

144147
describe('When the user supplies tokens using a permit signature', () => {
145-
const amountToSupply = bigDecimal('94');
146-
let reserve: Reserve;
147-
148-
beforeAll(async () => {
149-
const setup = await fundErc20Address(evmAddress(user.account.address), {
150-
address: ETHEREUM_USDC_ADDRESS,
151-
amount: bigDecimal('100'),
152-
decimals: 6,
153-
}).andThen(() => findReserveToSupply(client, ETHEREUM_USDC_ADDRESS));
154-
155-
assertOk(setup);
156-
reserve = setup.value;
157-
});
158148
it('Then the supply succeeds without requiring ERC20 approval', async ({
159149
annotate,
160150
}) => {
@@ -164,9 +154,9 @@ describe('Aave V4 Supply Scenarios', () => {
164154
value: amountToSupply,
165155
},
166156
reserve: {
167-
reserveId: reserve.id,
168-
chainId: reserve.chain.chainId,
169-
spoke: reserve.spoke.address,
157+
reserveId: reserveUSDC.id,
158+
chainId: reserveUSDC.chain.chainId,
159+
spoke: reserveUSDC.spoke.address,
170160
},
171161
sender: evmAddress(user.account.address),
172162
},
@@ -175,9 +165,9 @@ describe('Aave V4 Supply Scenarios', () => {
175165

176166
const result = await supply(client, {
177167
reserve: {
178-
reserveId: reserve.id,
168+
reserveId: reserveUSDC.id,
179169
chainId: ETHEREUM_FORK_ID,
180-
spoke: reserve.spoke.address,
170+
spoke: reserveUSDC.spoke.address,
181171
},
182172
amount: {
183173
erc20: {
@@ -198,7 +188,7 @@ describe('Aave V4 Supply Scenarios', () => {
198188
query: {
199189
userSpoke: {
200190
spoke: {
201-
address: reserve.spoke.address,
191+
address: reserveUSDC.spoke.address,
202192
chainId: ETHEREUM_FORK_ID,
203193
},
204194
user: evmAddress(user.account.address),
@@ -211,7 +201,7 @@ describe('Aave V4 Supply Scenarios', () => {
211201
assertSingleElementArray(result.value);
212202
expect(result.value[0].isCollateral).toBe(true);
213203
expect(result.value[0].amount.value.formatted).toBeBigDecimalCloseTo(
214-
amountToSupply,
204+
10,
215205
2,
216206
);
217207
});

packages/spec/withdraw/business.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('Aave V4 Withdraw Scenario', () => {
2222
beforeEach(async () => {
2323
const setup = await fundErc20Address(evmAddress(user.account!.address), {
2424
address: ETHEREUM_USDC_ADDRESS,
25-
amount: bigDecimal('200'),
25+
amount: bigDecimal('300'),
2626
decimals: 6,
2727
}).andThen(() =>
2828
supplyToRandomERC20Reserve(client, user, ETHEREUM_USDC_ADDRESS),
@@ -74,7 +74,7 @@ describe('Aave V4 Withdraw Scenario', () => {
7474
assertSingleElementArray(withdrawResult.value);
7575
expect(
7676
withdrawResult.value[0].amount.value.formatted,
77-
).toBeBigDecimalCloseTo(bigDecimal('75'), 2);
77+
).toBeBigDecimalCloseTo(bigDecimal('175'), 2);
7878

7979
const balanceAfter = await getBalance(
8080
evmAddress(user.account.address),

0 commit comments

Comments
 (0)