|
| 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 | +}); |
0 commit comments