Skip to content

Commit 7cf6075

Browse files
committed
feat: initial integration tests
1 parent 287ec00 commit 7cf6075

File tree

4 files changed

+130
-3
lines changed

4 files changed

+130
-3
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
"lint:fix": "biome check --write",
2020
"new:package": "NODE_OPTIONS='--import tsx' plop --plopfile=plopfile.ts",
2121
"prepublish": "pnpm run build",
22+
"test:client": "vitest --project client",
2223
"test:react": "vitest --project react",
23-
"test": "vitest --passWithNoTests"
24+
"test": "test:react"
2425
},
2526
"license": "MIT",
2627
"devDependencies": {
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import { assertOk } from '@aave/client';
2+
import { chains } from '@aave/client/actions';
3+
import { client } from '@aave/client/test-utils';
4+
import { describe, expect, it } from 'vitest';
5+
6+
describe('Given the Aave client', () => {
7+
describe(`when using the 'chains(client)' action`, () => {
8+
it('then it should return the supported chains', async () => {
9+
const result = await chains(client);
10+
assertOk(result);
11+
expect(result.value).toMatchInlineSnapshot(`
12+
[
13+
{
14+
"__typename": "Chain",
15+
"chainId": 1,
16+
"icon": "https://statics.aave.com/ethereum.svg",
17+
"name": "Ethereum",
18+
},
19+
{
20+
"__typename": "Chain",
21+
"chainId": 42161,
22+
"icon": "https://statics.aave.com/arbitrum.svg",
23+
"name": "Arbitrum",
24+
},
25+
{
26+
"__typename": "Chain",
27+
"chainId": 43114,
28+
"icon": "https://statics.aave.com/avalanche.svg",
29+
"name": "Avalanche",
30+
},
31+
{
32+
"__typename": "Chain",
33+
"chainId": 8453,
34+
"icon": "https://statics.aave.com/base.svg",
35+
"name": "Base",
36+
},
37+
{
38+
"__typename": "Chain",
39+
"chainId": 56,
40+
"icon": "https://statics.aave.com/bnbchain.svg",
41+
"name": "BSC",
42+
},
43+
{
44+
"__typename": "Chain",
45+
"chainId": 42220,
46+
"icon": "https://statics.aave.com/celo.svg",
47+
"name": "Celo",
48+
},
49+
{
50+
"__typename": "Chain",
51+
"chainId": 100,
52+
"icon": "https://statics.aave.com/Gnosis.svg",
53+
"name": "Gnosis",
54+
},
55+
{
56+
"__typename": "Chain",
57+
"chainId": 59144,
58+
"icon": "https://statics.aave.com/linea.svg",
59+
"name": "Linea",
60+
},
61+
{
62+
"__typename": "Chain",
63+
"chainId": 1088,
64+
"icon": "https://statics.aave.com/Metis.svg",
65+
"name": "Metis",
66+
},
67+
{
68+
"__typename": "Chain",
69+
"chainId": 10,
70+
"icon": "https://statics.aave.com/optimism.svg",
71+
"name": "Optimism",
72+
},
73+
{
74+
"__typename": "Chain",
75+
"chainId": 137,
76+
"icon": "https://statics.aave.com/polygon.svg",
77+
"name": "Polygon",
78+
},
79+
{
80+
"__typename": "Chain",
81+
"chainId": 534352,
82+
"icon": "https://statics.aave.com/scroll-network.svg",
83+
"name": "Scroll",
84+
},
85+
{
86+
"__typename": "Chain",
87+
"chainId": 1946,
88+
"icon": "https://statics.aave.com/soneium.svg",
89+
"name": "Soneium",
90+
},
91+
{
92+
"__typename": "Chain",
93+
"chainId": 146,
94+
"icon": "https://statics.aave.com/sonic.svg",
95+
"name": "Sonic",
96+
},
97+
{
98+
"__typename": "Chain",
99+
"chainId": 324,
100+
"icon": "https://statics.aave.com/zksync-era-light.svg",
101+
"name": "zkSync",
102+
},
103+
]
104+
`);
105+
});
106+
});
107+
});

packages/client/src/actions/markets.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@ import {
44
type MarketReservesRequestOrderBy,
55
MarketsQuery,
66
type MarketUserState,
7+
OrderDirection,
78
UserMarketStateQuery,
89
type UserMarketStateRequest,
910
} from '@aave/graphql';
1011
import type { ChainId, EvmAddress, ResultAsync } from '@aave/types';
1112
import type { AaveClient } from '../client';
1213
import type { UnexpectedError } from '../errors';
1314

15+
const defaultMarketReservesRequestOrderBy: MarketReservesRequestOrderBy = {
16+
tokenName: OrderDirection.Asc,
17+
};
18+
1419
export type MarketsRequest = {
1520
/**
1621
* The markets you want to see based on the chain ids.
@@ -51,7 +56,12 @@ export type MarketsRequest = {
5156
*/
5257
export function markets(
5358
client: AaveClient,
54-
{ chainIds, borrowsOrderBy, suppliesOrderBy, user }: MarketsRequest,
59+
{
60+
chainIds,
61+
borrowsOrderBy = defaultMarketReservesRequestOrderBy,
62+
suppliesOrderBy = defaultMarketReservesRequestOrderBy,
63+
user,
64+
}: MarketsRequest,
5565
): ResultAsync<Market[], UnexpectedError> {
5666
return client.query(MarketsQuery, {
5767
request: { chainIds, user },
@@ -106,7 +116,13 @@ export type MarketRequest = {
106116
*/
107117
export function market(
108118
client: AaveClient,
109-
{ address, chainId, user, borrowsOrderBy, suppliesOrderBy }: MarketRequest,
119+
{
120+
address,
121+
chainId,
122+
user,
123+
borrowsOrderBy = defaultMarketReservesRequestOrderBy,
124+
suppliesOrderBy = defaultMarketReservesRequestOrderBy,
125+
}: MarketRequest,
110126
): ResultAsync<Market | null, UnexpectedError> {
111127
return client.query(MarketQuery, {
112128
request: { address, chainId, user },

packages/client/src/test-utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { local, staging } from '@aave/env';
44
import type { AnyVariables } from '@aave/graphql';
55
import { schema } from '@aave/graphql/test-utils';
6+
import { chainId } from '@aave/types';
67
import type { TypedDocumentNode } from '@urql/core';
78
import { validate } from 'graphql';
89
import type { ValidationRule } from 'graphql/validation/ValidationContext';
@@ -17,6 +18,8 @@ export const signer = privateKeyToAccount(import.meta.env.PRIVATE_KEY);
1718
export const environment =
1819
import.meta.env.ENVIRONMENT === 'local' ? local : staging;
1920

21+
export const tenderlyFork = chainId(99999999);
22+
2023
export const client = AaveClient.create({
2124
environment,
2225
});

0 commit comments

Comments
 (0)