diff --git a/packages/app/src/features/actions/ActionsContainer.PageObject.ts b/packages/app/src/features/actions/ActionsContainer.PageObject.ts index fdefd612a..c153359a6 100644 --- a/packages/app/src/features/actions/ActionsContainer.PageObject.ts +++ b/packages/app/src/features/actions/ActionsContainer.PageObject.ts @@ -26,7 +26,10 @@ export class ActionsPageObject extends BasePageObject { } // #region actions - async acceptAllActionsAction(expectedNumberOfActions: number, updateBrowserAndNextBlockTime: (seconds: number) => Promise): Promise { + async acceptAllActionsAction( + expectedNumberOfActions: number, + updateBrowserAndNextBlockTime: (seconds: number) => Promise, + ): Promise { for (let index = 0; index < expectedNumberOfActions; index++) { const row = this.region.getByTestId(testIds.actions.row(index)) @@ -37,7 +40,10 @@ export class ActionsPageObject extends BasePageObject { } } - async acceptActionAtIndex(index: number, updateBrowserAndNextBlockTime: (seconds: number) => Promise): Promise { + async acceptActionAtIndex( + index: number, + updateBrowserAndNextBlockTime: (seconds: number) => Promise, + ): Promise { const row = this.region.getByTestId(testIds.actions.row(index)) await row.getByRole('button', { name: actionButtonRegex }).click() await expect(row.getByRole('button', { name: actionButtonRegex })).not.toBeVisible() diff --git a/packages/app/src/features/dialogs/collateral/CollateralDialog.PageObject.ts b/packages/app/src/features/dialogs/collateral/CollateralDialog.PageObject.ts index 76017af9a..001997a65 100644 --- a/packages/app/src/features/dialogs/collateral/CollateralDialog.PageObject.ts +++ b/packages/app/src/features/dialogs/collateral/CollateralDialog.PageObject.ts @@ -13,7 +13,15 @@ export class CollateralDialogPageObject extends DialogPageObject { } // #region actions - async setUseAsCollateralAction({assetName, setting, updateBrowserAndNextBlockTime}: {assetName: string; setting: CollateralSetting, updateBrowserAndNextBlockTime: () => Promise}): Promise { + async setUseAsCollateralAction({ + assetName, + setting, + updateBrowserAndNextBlockTime, + }: { + assetName: string + setting: CollateralSetting + updateBrowserAndNextBlockTime: () => Promise + }): Promise { const actionsContainer = new ActionsPageObject(this.locatePanelByHeader('Actions')) await actionsContainer.acceptAllActionsAction(1, updateBrowserAndNextBlockTime) diff --git a/packages/app/src/features/dialogs/common/Dialog.PageObject.ts b/packages/app/src/features/dialogs/common/Dialog.PageObject.ts index 06a51161c..ce5749236 100644 --- a/packages/app/src/features/dialogs/common/Dialog.PageObject.ts +++ b/packages/app/src/features/dialogs/common/Dialog.PageObject.ts @@ -5,7 +5,7 @@ import { BasePageObject } from '@/test/e2e/BasePageObject' import { TestTokenWithValue, expectAssets } from '@/test/e2e/assertions' import { calculateAssetsWorth, isPage } from '@/test/e2e/utils' import { testIds } from '@/ui/utils/testIds' -import { getUrlFromClient, TestnetClient } from '@marsfoundation/common-testnets' +import { TestnetClient, getUrlFromClient } from '@marsfoundation/common-testnets' export class DialogPageObject extends BasePageObject { public readonly actionsContainer: ActionsPageObject @@ -58,9 +58,9 @@ export class DialogPageObject extends BasePageObject { testnetClient, assetWorthOverrides, }: { - tokenWithValue: TestTokenWithValue[], - testnetClient: TestnetClient, - assetWorthOverrides?: Record, + tokenWithValue: TestTokenWithValue[] + testnetClient: TestnetClient + assetWorthOverrides?: Record }): Promise { await expect(this.region.getByText('Congrats, all done!')).toBeVisible() diff --git a/packages/app/src/features/dialogs/e-mode/EModeDialog.PageObject.ts b/packages/app/src/features/dialogs/e-mode/EModeDialog.PageObject.ts index 9cfff046a..f6d3cd130 100644 --- a/packages/app/src/features/dialogs/e-mode/EModeDialog.PageObject.ts +++ b/packages/app/src/features/dialogs/e-mode/EModeDialog.PageObject.ts @@ -20,7 +20,10 @@ export class EModeDialogPageObject extends DialogPageObject { await this.locateEModeCategoryTile(eModeCategoryName).click() } - async setEModeAction({ eModeCategoryName, updateBrowserAndNextBlockTime }: { eModeCategoryName: EModeCategoryName, updateBrowserAndNextBlockTime: () => Promise }): Promise { + async setEModeAction({ + eModeCategoryName, + updateBrowserAndNextBlockTime, + }: { eModeCategoryName: EModeCategoryName; updateBrowserAndNextBlockTime: () => Promise }): Promise { await this.clickEModeCategoryTileAction(eModeCategoryName) await this.acknowledgeIfRiskIsPresent() await this.actionsContainer.acceptAllActionsAction(1, updateBrowserAndNextBlockTime) diff --git a/packages/app/src/features/farm-details/FarmDetails.PageObject.ts b/packages/app/src/features/farm-details/FarmDetails.PageObject.ts index 965cfdf4a..ba03b6ba1 100644 --- a/packages/app/src/features/farm-details/FarmDetails.PageObject.ts +++ b/packages/app/src/features/farm-details/FarmDetails.PageObject.ts @@ -2,7 +2,7 @@ import { BasePageObject } from '@/test/e2e/BasePageObject' import { AssetsInTests, TOKENS_ON_FORK } from '@/test/e2e/constants' import { getTokenBalance } from '@/test/e2e/utils' import { testIds } from '@/ui/utils/testIds' -import { getUrlFromClient, TestnetClient } from '@marsfoundation/common-testnets' +import { TestnetClient, getUrlFromClient } from '@marsfoundation/common-testnets' import { Locator, expect } from '@playwright/test' import { Address } from 'viem' diff --git a/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts b/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts index eabc75b14..bd03e8eeb 100644 --- a/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts +++ b/packages/app/src/features/farm-details/dialogs/claim/e2e/mainnet/ClaimSKY.test-e2e.ts @@ -3,11 +3,11 @@ import { StakeDialogPageObject } from '@/features/farm-details/dialogs/stake/Sta import { USDS_ACTIVATED_BLOCK_NUMBER } from '@/test/e2e/constants' import { overrideInfoSkyRouteWithHAR } from '@/test/e2e/info-sky' import { setup } from '@/test/e2e/setup' -import { Address } from 'viem' +import { TestnetClient } from '@marsfoundation/common-testnets' import { test } from '@playwright/test' +import { Address } from 'viem' import { mainnet } from 'viem/chains' import { ClaimDialogPageObject } from '../../ClaimDialog.PageObject' -import { TestnetClient } from '@marsfoundation/common-testnets' test.describe('Claim SKY rewards', () => { let farmDetailsPage: FarmDetailsPageObject @@ -66,7 +66,7 @@ test.describe('Claim SKY rewards', () => { }) test('executes transaction', async () => { - await claimDialog.actionsContainer.acceptAllActionsAction(1, updateBrowserAndNextBlockTime ) + await claimDialog.actionsContainer.acceptAllActionsAction(1, updateBrowserAndNextBlockTime) await claimDialog.expectSuccessPage() await claimDialog.clickBackToFarmAction() diff --git a/packages/app/src/pages/Borrow.PageObject.ts b/packages/app/src/pages/Borrow.PageObject.ts index 57b376f35..f5ea41c2b 100644 --- a/packages/app/src/pages/Borrow.PageObject.ts +++ b/packages/app/src/pages/Borrow.PageObject.ts @@ -6,7 +6,7 @@ import { TestTokenWithValue, expectAssets } from '@/test/e2e/assertions' import { buildUrl } from '@/test/e2e/setup' import { calculateAssetsWorth } from '@/test/e2e/utils' import { testIds } from '@/ui/utils/testIds' -import { getUrlFromClient, TestnetClient } from '@marsfoundation/common-testnets' +import { TestnetClient, getUrlFromClient } from '@marsfoundation/common-testnets' export class BorrowPageObject extends BasePageObject { // #region actions @@ -51,7 +51,15 @@ export class BorrowPageObject extends BasePageObject { await this.page.getByRole('link', { name: 'View in Savings' }).click() } - async depositAssetsActions({ assetsToDeposit, daiToBorrow, updateBrowserAndNextBlockTime }: { assetsToDeposit: Record, daiToBorrow: number, updateBrowserAndNextBlockTime: () => Promise }): Promise { + async depositAssetsActions({ + assetsToDeposit, + daiToBorrow, + updateBrowserAndNextBlockTime, + }: { + assetsToDeposit: Record + daiToBorrow: number + updateBrowserAndNextBlockTime: () => Promise + }): Promise { const actionsContainer = new ActionsPageObject(this.locatePanelByHeader('Actions')) await this.depositWithoutBorrowActions({ assetsToDeposit, @@ -59,7 +67,10 @@ export class BorrowPageObject extends BasePageObject { actionsContainer, updateBrowserAndNextBlockTime, }) - await actionsContainer.acceptActionAtIndex(Object.entries(assetsToDeposit).length * 2, updateBrowserAndNextBlockTime) // accept final borrow action + await actionsContainer.acceptActionAtIndex( + Object.entries(assetsToDeposit).length * 2, + updateBrowserAndNextBlockTime, + ) // accept final borrow action } async depositWithoutBorrowActions({ @@ -68,9 +79,9 @@ export class BorrowPageObject extends BasePageObject { actionsContainer: _actionsContainer, updateBrowserAndNextBlockTime, }: { - assetsToDeposit: Record, - daiToBorrow?: number, - actionsContainer?: ActionsPageObject, + assetsToDeposit: Record + daiToBorrow?: number + actionsContainer?: ActionsPageObject updateBrowserAndNextBlockTime: () => Promise }): Promise { const actionsContainer = _actionsContainer ?? new ActionsPageObject(this.locatePanelByHeader('Actions')) @@ -132,10 +143,10 @@ export class BorrowPageObject extends BasePageObject { testnetClient, assetsWorthOverride, }: { - deposited: TestTokenWithValue[], - borrowed: TestTokenWithValue, - testnetClient: TestnetClient, - assetsWorthOverride?: Record, + deposited: TestTokenWithValue[] + borrowed: TestTokenWithValue + testnetClient: TestnetClient + assetsWorthOverride?: Record }): Promise { await expect(this.page.getByText('Congrats, all done!')).toBeVisible() diff --git a/packages/app/src/test/e2e/injectSetup.ts b/packages/app/src/test/e2e/injectSetup.ts index 3ca85a714..9c7ef61ba 100644 --- a/packages/app/src/test/e2e/injectSetup.ts +++ b/packages/app/src/test/e2e/injectSetup.ts @@ -8,10 +8,10 @@ import { PLAYWRIGHT_WALLET_PRIVATE_KEY_KEY, } from '@/config/wagmi/config.e2e' +import { TestnetClient } from '@marsfoundation/common-testnets' import { zeroAddress } from 'viem' import { base, mainnet } from 'viem/chains' import { InjectableWallet } from './setup' -import { TestnetClient } from '@marsfoundation/common-testnets' export async function injectWalletConfiguration(page: Page, wallet: InjectableWallet): Promise { await page.addInitScript( diff --git a/packages/app/src/test/e2e/setup.ts b/packages/app/src/test/e2e/setup.ts index 0819cc841..8868a8285 100644 --- a/packages/app/src/test/e2e/setup.ts +++ b/packages/app/src/test/e2e/setup.ts @@ -3,12 +3,18 @@ import { generatePath } from 'react-router-dom' import { Address, Hash, parseEther, parseUnits } from 'viem' import { Path, paths } from '@/config/paths' +import { TestnetClient, getUrlFromClient } from '@marsfoundation/common-testnets' import { AssetsInTests, TOKENS_ON_FORK } from './constants' -import { injectFixedDate, injectFlags, injectNetworkConfiguration, injectUpdatedDate, injectWalletConfiguration } from './injectSetup' -import { generateAccount } from './utils' -import { getUrlFromClient, TestnetClient } from '@marsfoundation/common-testnets' +import { + injectFixedDate, + injectFlags, + injectNetworkConfiguration, + injectUpdatedDate, + injectWalletConfiguration, +} from './injectSetup' import { getTestnetContext } from './testnet-cache' +import { generateAccount } from './utils' export type InjectableWallet = { address: Address } | { privateKey: string } @@ -42,7 +48,6 @@ export type AccountOptions = T extends 'not-connected' } : never - export interface BlockchainOptions { chainId: number blockNumber: bigint @@ -55,13 +60,12 @@ export interface SetupOptions { skipInjectingNetwork?: boolean } -export type SetupReturn = (T extends 'not-connected' - ? {} : { account: Address }) & { - getLogs: () => string[], - testnetClient: TestnetClient, - updateBrowserAndNextBlockTime: (seconds: number) => Promise, - incrementTime: (seconds: number) => Promise, - } +export type SetupReturn = (T extends 'not-connected' ? {} : { account: Address }) & { + getLogs: () => string[] + testnetClient: TestnetClient + updateBrowserAndNextBlockTime: (seconds: number) => Promise + incrementTime: (seconds: number) => Promise +} // should be called at the beginning of any test export async function setup( @@ -149,7 +153,7 @@ export async function injectFunds( } const chainId = await testnetClient.getChainId() - for(const [tokenName, balance] of Object.entries(assetBalances)) { + for (const [tokenName, balance] of Object.entries(assetBalances)) { const { timestamp } = await testnetClient.getBlock() await testnetClient.setNextBlockTimestamp(timestamp + 1n) if (tokenName === 'ETH' || tokenName === 'XDAI') { diff --git a/packages/app/src/test/e2e/testnet-cache.ts b/packages/app/src/test/e2e/testnet-cache.ts index 25d1732f4..1648e61e8 100644 --- a/packages/app/src/test/e2e/testnet-cache.ts +++ b/packages/app/src/test/e2e/testnet-cache.ts @@ -1,6 +1,6 @@ -import { randomHexId } from "@/utils/random" -import { TenderlyTestnetFactory, TestnetClient } from "@marsfoundation/common-testnets" -import { getEnv } from "@marsfoundation/common-nodejs/env" +import { randomHexId } from '@/utils/random' +import { getEnv } from '@marsfoundation/common-nodejs/env' +import { TenderlyTestnetFactory, TestnetClient } from '@marsfoundation/common-testnets' interface TestnetContext { client: TestnetClient @@ -9,19 +9,21 @@ interface TestnetContext { } const testnetCache = new Map() - -;([`exit`, `SIGINT`, `SIGUSR1`, `SIGUSR2`, `uncaughtException`, `SIGTERM`].forEach((eventType) => { +for (const eventType of ['exit', 'SIGINT', 'SIGUSR1', 'SIGUSR2', 'uncaughtException', 'SIGTERM']) { process.on(eventType, () => { const keys = Array.from(testnetCache.keys()) - keys.forEach(key => { + for (const key of keys) { const context = testnetCache.get(key)! testnetCache.delete(key) - context.cleanup() - }) - }); -})) + return context.cleanup() + } + }) +} -export async function getTestnetContext({ chainId, blockNumber }: { chainId: number, blockNumber: bigint }) { +export async function getTestnetContext({ + chainId, + blockNumber, +}: { chainId: number; blockNumber: bigint }): Promise { const key = `${chainId}-${blockNumber.toString()}` if (testnetCache.has(key)) { return testnetCache.get(key)! @@ -55,4 +57,3 @@ export async function getTestnetContext({ chainId, blockNumber }: { chainId: num return context } -