Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
"test:client": "vitest --project client",
"test:client:local": "ENVIRONMENT=local vitest --project client",
"test:react": "vitest --project react",
"test:withdraw": "vitest --project client packages/client/src/actions/withdraw.test.ts",
"test:borrow": "vitest --project client packages/client/src/actions/borrow.test.ts",
"test:856": "vitest --project client packages/client/src/actions/eMode.test.ts -t 'Then they should be able to disable it at any time'",
"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\"",
"test:withdraw": "vitest --project client packages/client/src/actions/withdraw.test.ts",
"test": "vitest"
},
"license": "MIT",
Expand Down
22 changes: 22 additions & 0 deletions packages/client/src/actions/__snapshots__/markets.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,28 @@ exports[`Given the Aave Protocol v3 > When fetching a market data for a given ad
}
`;

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`] = `
{
"__typename": "Market",
"address": "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2",
"borrowReserves": Any<Array>,
"chain": {
"__typename": "Chain",
"chainId": 99999999,
"explorerUrl": "https://dashboard.tenderly.co/explorer/vnet/27ff3c60-0e2c-4d46-8190-f5170dc7da8c",
"icon": "https://statics.aave.com/ethereum.svg",
"name": "Forked Ethereum",
},
"eModeCategories": Any<Array>,
"icon": "https://statics.aave.com/ethereum.svg",
"name": "AaveV3ForkedEthereum",
"supplyReserves": Any<Array>,
"totalAvailableLiquidity": Any<String>,
"totalMarketSize": Any<String>,
"userState": null,
}
`;

exports[`Given the Aave Protocol v3 > When fetching markets data > Then it should be possible to fetch markets for a given chain ID 1`] = `
{
"__typename": "Market",
Expand Down
90 changes: 90 additions & 0 deletions packages/client/src/actions/eMode.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { assertOk, evmAddress, never, nonNullable } from '@aave/types';
import { beforeAll, describe, expect, it } from 'vitest';
import {
client,
createNewWallet,
DEFAULT_MARKET_ADDRESS,
DEFAULT_MARKET_EMODE_CATEGORY,
ETHEREUM_FORK_ID,
} from '../test-utils';
import { sendWith } from '../viem';
import { market, userMarketState } from './markets';
import { userSetEmode } from './transactions';

describe('Given an Aave Market', () => {
const wallet = createNewWallet();

describe('When a user enables an E-Mode category for the given market', () => {
beforeAll(async () => {
const result = await userSetEmode(client, {
chainId: ETHEREUM_FORK_ID,
market: DEFAULT_MARKET_ADDRESS,
categoryId: DEFAULT_MARKET_EMODE_CATEGORY,
user: evmAddress(wallet.account!.address),
}).andThen(sendWith(wallet));
assertOk(result);
});

it('Then it should be reflected in their market user state', async () => {
const result = await userMarketState(client, {
market: DEFAULT_MARKET_ADDRESS,
chainId: ETHEREUM_FORK_ID,
user: evmAddress(wallet.account!.address),
});
assertOk(result);

expect(result.value).toMatchObject({
eModeEnabled: true,
});
});

it("Then the market's reserves should have user state that reflects the selected E-Mode category settings", async () => {
const result = await market(client, {
address: DEFAULT_MARKET_ADDRESS,
chainId: ETHEREUM_FORK_ID,
user: evmAddress(wallet.account!.address),
}).map(nonNullable);
assertOk(result);

const eModeCategory =
result.value?.eModeCategories.find(
(category) => category.id === DEFAULT_MARKET_EMODE_CATEGORY,
) ?? never('No eMode category found');
for (let i = 0; i < result.value.supplyReserves.length; i++) {
const reserve = result.value.supplyReserves[i] ?? never();
const eModeCategoryReserve = eModeCategory.reserves.find(
(r) => r.underlyingToken.address === reserve.underlyingToken.address,
);

expect(reserve).toMatchObject({
userState: expect.objectContaining({
canBeCollateral: eModeCategoryReserve?.canBeCollateral ?? false,
canBeBorrowed: eModeCategoryReserve?.canBeBorrowed ?? false,
}),
});
}
});

it('Then they should be able to disable it at any time', async () => {
const result = await userSetEmode(client, {
chainId: ETHEREUM_FORK_ID,
market: DEFAULT_MARKET_ADDRESS,
categoryId: null,
user: evmAddress(wallet.account!.address),
})
.andThen(sendWith(wallet))
.andThen(() =>
userMarketState(client, {
market: DEFAULT_MARKET_ADDRESS,
chainId: ETHEREUM_FORK_ID,
user: evmAddress(wallet.account!.address),
}),
);
assertOk(result);

expect(result.value).toMatchObject({
eModeEnabled: true,
});
});
});
});
13 changes: 0 additions & 13 deletions packages/client/src/actions/eMode.todo.ts

This file was deleted.

4 changes: 3 additions & 1 deletion packages/client/src/actions/markets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import { assertOk, chainId, evmAddress } from '@aave/types';
import { describe, expect, it } from 'vitest';
import {
client,
createNewWallet,
DEFAULT_MARKET_ADDRESS,
ETHEREUM_FORK_ID,
wallet,
} from '../test-utils';
import { market, markets, userMarketState } from './markets';

describe('Given the Aave Protocol v3', () => {
const wallet = createNewWallet();

describe('When fetching markets data', () => {
it('Then it should be possible to fetch markets for a given chain ID', async () => {
const result = await markets(client, {
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const USDC_ADDRESS = evmAddress(
export const DEFAULT_MARKET_ADDRESS = evmAddress(
'0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2',
);
export const DEFAULT_MARKET_EMODE_CATEGORY = 1;

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