Skip to content

Commit ddd3064

Browse files
authored
Merge pull request #22 from aave/juan/reserve-test
test: reserve, borrowAPY, supplyAP
2 parents 0aae67f + 179c5dd commit ddd3064

File tree

8 files changed

+185
-6
lines changed

8 files changed

+185
-6
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`Given an Aave Market reserve > When fetching the reserve data > Then it should return the expected reserve details 1`] = `
4+
{
5+
"__typename": "Reserve",
6+
"aToken": Any<Object>,
7+
"acceptsNative": Any<Object>,
8+
"borrowInfo": Any<Object>,
9+
"eModeInfo": Any<Array>,
10+
"flashLoanEnabled": true,
11+
"isFrozen": false,
12+
"isPaused": false,
13+
"isolationModeConfig": null,
14+
"market": Any<Object>,
15+
"size": Any<Object>,
16+
"supplyInfo": Any<Object>,
17+
"underlyingToken": {
18+
"__typename": "Currency",
19+
"address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
20+
"chainId": 99999999,
21+
"decimals": 18,
22+
"imageUrl": "https://token-logos.family.co/asset?id=99999999:0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2&token=WETH",
23+
"name": "Wrapped Ether",
24+
"symbol": "WETH",
25+
},
26+
"usdExchangeRate": "3682.78",
27+
"usdOracleAddress": "0x5424384B256154046E9667dDFaaa5e550145215e",
28+
"userState": Any<Object>,
29+
"vToken": Any<Object>,
30+
}
31+
`;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ describe('Given an Aave Market', () => {
110110
})
111111
.andThen(sendWith(wallet))
112112
.andTee((tx) => console.log(`tx to borrow: ${tx}`))
113-
.andTee(() => wait(5000))
113+
.andTee(() => wait(1000)) //TODO: improve the wait time
114114
.andThen(() =>
115115
userBorrows(client, {
116116
markets: [
@@ -173,7 +173,7 @@ describe('Given an Aave Market', () => {
173173
})
174174
.andThen(sendWith(wallet))
175175
.andTee((tx) => console.log(`tx to borrow: ${tx}`))
176-
.andTee(() => wait(5000))
176+
.andTee(() => wait(1000)) //TODO: improve the wait time
177177
.andThen(() =>
178178
userBorrows(client, {
179179
markets: [
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import { assertOk, chainId, evmAddress } from '@aave/client';
2+
import { TimeWindow } from '@aave/graphql';
3+
import { describe, expect, it } from 'vitest';
4+
import {
5+
client,
6+
createNewWallet,
7+
ETHEREUM_FORK_ID,
8+
ETHEREUM_MARKET_ADDRESS,
9+
WETH_ADDRESS,
10+
} from '../test-utils';
11+
import { borrowAPYHistory, reserve, supplyAPYHistory } from './reserve';
12+
13+
function windowToDate(window: TimeWindow): Date {
14+
switch (window) {
15+
case TimeWindow.LastDay:
16+
return new Date(Date.now() - 1000 * 60 * 60 * 24);
17+
case TimeWindow.LastWeek:
18+
return new Date(Date.now() - 1000 * 60 * 60 * 24 * 7);
19+
case TimeWindow.LastMonth:
20+
return new Date(Date.now() - 1000 * 60 * 60 * 24 * 30);
21+
case TimeWindow.LastYear:
22+
return new Date(Date.now() - 1000 * 60 * 60 * 24 * 365);
23+
default:
24+
throw new Error(`Unknown window: ${window}`);
25+
}
26+
}
27+
28+
describe('Given an Aave Market reserve', () => {
29+
const wallet = createNewWallet();
30+
const windowEnum = Object.values(TimeWindow);
31+
32+
describe('When fetching the reserve data', () => {
33+
it('Then it should return the expected reserve details', async () => {
34+
const result = await reserve(client, {
35+
market: ETHEREUM_MARKET_ADDRESS,
36+
chainId: ETHEREUM_FORK_ID,
37+
underlyingToken: WETH_ADDRESS,
38+
user: evmAddress(wallet.account!.address),
39+
});
40+
assertOk(result);
41+
expect(result.value).toMatchSnapshot({
42+
aToken: expect.any(Object),
43+
underlyingToken: {
44+
address: WETH_ADDRESS,
45+
},
46+
vToken: expect.any(Object),
47+
supplyInfo: expect.any(Object),
48+
borrowInfo: expect.any(Object),
49+
eModeInfo: expect.any(Array),
50+
market: expect.any(Object),
51+
acceptsNative: expect.any(Object),
52+
size: expect.any(Object),
53+
userState: expect.any(Object),
54+
});
55+
});
56+
});
57+
58+
describe('When fetching the borrow APY history for it', () => {
59+
it.each(windowEnum)(
60+
'Then it should return a time series for the specified window %s',
61+
async (window) => {
62+
const result = await borrowAPYHistory(client, {
63+
market: ETHEREUM_MARKET_ADDRESS,
64+
chainId: chainId(1),
65+
underlyingToken: WETH_ADDRESS,
66+
window,
67+
});
68+
assertOk(result);
69+
expect(result.value?.length).toBeGreaterThan(0);
70+
expect(result.value).toEqual(
71+
result.value?.map(() =>
72+
expect.objectContaining({
73+
avgRate: expect.any(Object),
74+
date: expect.toBeBetween(windowToDate(window), new Date()),
75+
}),
76+
),
77+
);
78+
},
79+
);
80+
});
81+
82+
describe('When fetching the supply APY history for it', () => {
83+
it.each(windowEnum)(
84+
'Then it should return a time series for the specified window %s',
85+
async (window) => {
86+
const result = await supplyAPYHistory(client, {
87+
market: ETHEREUM_MARKET_ADDRESS,
88+
chainId: chainId(1),
89+
underlyingToken: WETH_ADDRESS,
90+
window,
91+
});
92+
assertOk(result);
93+
expect(result.value?.length).toBeGreaterThan(0);
94+
expect(result.value).toEqual(
95+
result.value?.map(() =>
96+
expect.objectContaining({
97+
avgRate: expect.any(Object),
98+
date: expect.toBeBetween(windowToDate(window), new Date()),
99+
}),
100+
),
101+
);
102+
},
103+
);
104+
});
105+
});

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,19 @@ describe('Given the Aave Protocol v3', () => {
3737
shareSymbol: 'avWETH',
3838
underlyingToken: reserve.underlyingToken.address,
3939
})
40-
.andTee((result) =>
41-
console.log(`result: ${JSON.stringify(result, null, 2)}`),
42-
)
4340
.andThen(sendWith(wallet))
4441
.andTee((tx) => console.log(`transaction: ${tx}`));
4542
assertOk(result);
46-
await wait(5000);
43+
await wait(1000); //TODO: improve the wait time
4744
const vaultInfo = await vaults(client, {
4845
criteria: {
4946
ownedBy: [evmAddress(wallet.account!.address)],
5047
},
5148
});
5249
assertOk(vaultInfo);
5350
expect(vaultInfo.value.items.length).toBe(1);
51+
console.log(`Vault with address ${vaultInfo.value.items[0]?.address}`);
52+
expect(vaultInfo.value.items[0]?.owner).toEqual(wallet.account!.address);
5453
}, 25_000);
5554
});
5655
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { describe, expect, it } from 'vitest';
2+
3+
describe('Given the Aave v3 Vaults', () => {
4+
describe('When depositing into a vault', () => {
5+
it("Then it should be available in the user's vault positions", async () => {
6+
expect(true).toBe(true);
7+
});
8+
});
9+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { describe, expect, it } from 'vitest';
2+
3+
describe('Given the Aave v3 Vaults', () => {
4+
describe('And a user has deposited assets into a vault', () => {
5+
describe('When the user mints shares', () => {
6+
it("Then it should be available in the user's vault positions", async () => {
7+
expect(true).toBe(true);
8+
});
9+
});
10+
});
11+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { describe, expect, it } from 'vitest';
2+
3+
describe('Given the Aave v3 Vaults', () => {
4+
describe('And a user has deposited assets into a vault', () => {
5+
describe('And the user has minted shares', () => {
6+
describe('When the user redeems shares', () => {
7+
it('Then previously deposited assets should be available in the vault', async () => {
8+
expect(true).toBe(true);
9+
});
10+
});
11+
});
12+
});
13+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { describe, expect, it } from 'vitest';
2+
3+
describe('Given the Aave v3 Vaults', () => {
4+
describe('And a user has deposited assets into a vault', () => {
5+
describe('When the user withdraws assets from the vault', () => {
6+
it("Then it should be available in the user's wallet", async () => {
7+
expect(true).toBe(true);
8+
});
9+
});
10+
});
11+
});

0 commit comments

Comments
 (0)