Skip to content

Commit a6b19cd

Browse files
authored
Merge pull request #14 from aave/feat/emode-tests
feat: emode test coverage
2 parents afd196d + b5e2e1c commit a6b19cd

File tree

6 files changed

+119
-15
lines changed

6 files changed

+119
-15
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
"test:client": "vitest --project client",
2323
"test:client:local": "ENVIRONMENT=local vitest --project client",
2424
"test:react": "vitest --project react",
25-
"test:withdraw": "vitest --project client packages/client/src/actions/withdraw.test.ts",
2625
"test:borrow": "vitest --project client packages/client/src/actions/borrow.test.ts",
26+
"test:856": "vitest --project client packages/client/src/actions/eMode.test.ts -t 'Then they should be able to disable it at any time'",
27+
"test:857": "vitest --project client packages/client/src/actions/eMode.test.ts -t \"Then the market's reserves should have user state that reflects the selected E-Mode category settings\"",
28+
"test:withdraw": "vitest --project client packages/client/src/actions/withdraw.test.ts",
2729
"test": "vitest"
2830
},
2931
"license": "MIT",

packages/client/src/actions/__snapshots__/markets.test.ts.snap

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,28 @@ exports[`Given the Aave Protocol v3 > When fetching a market data for a given ad
2222
}
2323
`;
2424
25+
exports[`Given the Aave Protocol v3 > When fetching a market data for a given address > Then it should be possible to fetch market data for a given market address and chain ID 1`] = `
26+
{
27+
"__typename": "Market",
28+
"address": "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2",
29+
"borrowReserves": Any<Array>,
30+
"chain": {
31+
"__typename": "Chain",
32+
"chainId": 99999999,
33+
"explorerUrl": "https://dashboard.tenderly.co/explorer/vnet/27ff3c60-0e2c-4d46-8190-f5170dc7da8c",
34+
"icon": "https://statics.aave.com/ethereum.svg",
35+
"name": "Forked Ethereum",
36+
},
37+
"eModeCategories": Any<Array>,
38+
"icon": "https://statics.aave.com/ethereum.svg",
39+
"name": "AaveV3ForkedEthereum",
40+
"supplyReserves": Any<Array>,
41+
"totalAvailableLiquidity": Any<String>,
42+
"totalMarketSize": Any<String>,
43+
"userState": null,
44+
}
45+
`;
46+
2547
exports[`Given the Aave Protocol v3 > When fetching markets data > Then it should be possible to fetch markets for a given chain ID 1`] = `
2648
{
2749
"__typename": "Market",
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import { assertOk, evmAddress, never, nonNullable } from '@aave/types';
2+
import { beforeAll, describe, expect, it } from 'vitest';
3+
import {
4+
client,
5+
createNewWallet,
6+
DEFAULT_MARKET_ADDRESS,
7+
DEFAULT_MARKET_EMODE_CATEGORY,
8+
ETHEREUM_FORK_ID,
9+
} from '../test-utils';
10+
import { sendWith } from '../viem';
11+
import { market, userMarketState } from './markets';
12+
import { userSetEmode } from './transactions';
13+
14+
describe('Given an Aave Market', () => {
15+
const wallet = createNewWallet();
16+
17+
describe('When a user enables an E-Mode category for the given market', () => {
18+
beforeAll(async () => {
19+
const result = await userSetEmode(client, {
20+
chainId: ETHEREUM_FORK_ID,
21+
market: DEFAULT_MARKET_ADDRESS,
22+
categoryId: DEFAULT_MARKET_EMODE_CATEGORY,
23+
user: evmAddress(wallet.account!.address),
24+
}).andThen(sendWith(wallet));
25+
assertOk(result);
26+
});
27+
28+
it('Then it should be reflected in their market user state', async () => {
29+
const result = await userMarketState(client, {
30+
market: DEFAULT_MARKET_ADDRESS,
31+
chainId: ETHEREUM_FORK_ID,
32+
user: evmAddress(wallet.account!.address),
33+
});
34+
assertOk(result);
35+
36+
expect(result.value).toMatchObject({
37+
eModeEnabled: true,
38+
});
39+
});
40+
41+
it("Then the market's reserves should have user state that reflects the selected E-Mode category settings", async () => {
42+
const result = await market(client, {
43+
address: DEFAULT_MARKET_ADDRESS,
44+
chainId: ETHEREUM_FORK_ID,
45+
user: evmAddress(wallet.account!.address),
46+
}).map(nonNullable);
47+
assertOk(result);
48+
49+
const eModeCategory =
50+
result.value?.eModeCategories.find(
51+
(category) => category.id === DEFAULT_MARKET_EMODE_CATEGORY,
52+
) ?? never('No eMode category found');
53+
for (let i = 0; i < result.value.supplyReserves.length; i++) {
54+
const reserve = result.value.supplyReserves[i] ?? never();
55+
const eModeCategoryReserve = eModeCategory.reserves.find(
56+
(r) => r.underlyingToken.address === reserve.underlyingToken.address,
57+
);
58+
59+
expect(reserve).toMatchObject({
60+
userState: expect.objectContaining({
61+
canBeCollateral: eModeCategoryReserve?.canBeCollateral ?? false,
62+
canBeBorrowed: eModeCategoryReserve?.canBeBorrowed ?? false,
63+
}),
64+
});
65+
}
66+
});
67+
68+
it('Then they should be able to disable it at any time', async () => {
69+
const result = await userSetEmode(client, {
70+
chainId: ETHEREUM_FORK_ID,
71+
market: DEFAULT_MARKET_ADDRESS,
72+
categoryId: null,
73+
user: evmAddress(wallet.account!.address),
74+
})
75+
.andThen(sendWith(wallet))
76+
.andThen(() =>
77+
userMarketState(client, {
78+
market: DEFAULT_MARKET_ADDRESS,
79+
chainId: ETHEREUM_FORK_ID,
80+
user: evmAddress(wallet.account!.address),
81+
}),
82+
);
83+
assertOk(result);
84+
85+
expect(result.value).toMatchObject({
86+
eModeEnabled: true,
87+
});
88+
});
89+
});
90+
});

packages/client/src/actions/eMode.todo.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

packages/client/src/actions/markets.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import { assertOk, chainId, evmAddress } from '@aave/types';
22
import { describe, expect, it } from 'vitest';
33
import {
44
client,
5+
createNewWallet,
56
DEFAULT_MARKET_ADDRESS,
67
ETHEREUM_FORK_ID,
7-
wallet,
88
} from '../test-utils';
99
import { market, markets, userMarketState } from './markets';
1010

1111
describe('Given the Aave Protocol v3', () => {
12+
const wallet = createNewWallet();
13+
1214
describe('When fetching markets data', () => {
1315
it('Then it should be possible to fetch markets for a given chain ID', async () => {
1416
const result = await markets(client, {

packages/client/src/test-utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export const USDC_ADDRESS = evmAddress(
4646
export const DEFAULT_MARKET_ADDRESS = evmAddress(
4747
'0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2',
4848
);
49+
export const DEFAULT_MARKET_EMODE_CATEGORY = 1;
4950

5051
export const ETHEREUM_FORK_RPC_URL =
5152
'https://virtual.mainnet.rpc.tenderly.co/27ff3c60-0e2c-4d46-8190-f5170dc7da8c';

0 commit comments

Comments
 (0)