Skip to content

Commit

Permalink
Fix eslint and biome errors
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarvu committed Dec 16, 2024
1 parent e1be216 commit 8baab05
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 47 deletions.
10 changes: 8 additions & 2 deletions packages/app/src/features/actions/ActionsContainer.PageObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ export class ActionsPageObject extends BasePageObject {
}

// #region actions
async acceptAllActionsAction(expectedNumberOfActions: number, updateBrowserAndNextBlockTime: (seconds: number) => Promise<void>): Promise<void> {
async acceptAllActionsAction(
expectedNumberOfActions: number,
updateBrowserAndNextBlockTime: (seconds: number) => Promise<void>,
): Promise<void> {
for (let index = 0; index < expectedNumberOfActions; index++) {
const row = this.region.getByTestId(testIds.actions.row(index))

Expand All @@ -37,7 +40,10 @@ export class ActionsPageObject extends BasePageObject {
}
}

async acceptActionAtIndex(index: number, updateBrowserAndNextBlockTime: (seconds: number) => Promise<void>): Promise<void> {
async acceptActionAtIndex(
index: number,
updateBrowserAndNextBlockTime: (seconds: number) => Promise<void>,
): Promise<void> {
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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ export class CollateralDialogPageObject extends DialogPageObject {
}

// #region actions
async setUseAsCollateralAction({assetName, setting, updateBrowserAndNextBlockTime}: {assetName: string; setting: CollateralSetting, updateBrowserAndNextBlockTime: () => Promise<void>}): Promise<void> {
async setUseAsCollateralAction({
assetName,
setting,
updateBrowserAndNextBlockTime,
}: {
assetName: string
setting: CollateralSetting
updateBrowserAndNextBlockTime: () => Promise<void>
}): Promise<void> {
const actionsContainer = new ActionsPageObject(this.locatePanelByHeader('Actions'))
await actionsContainer.acceptAllActionsAction(1, updateBrowserAndNextBlockTime)

Expand Down
8 changes: 4 additions & 4 deletions packages/app/src/features/dialogs/common/Dialog.PageObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -58,9 +58,9 @@ export class DialogPageObject extends BasePageObject {
testnetClient,
assetWorthOverrides,
}: {
tokenWithValue: TestTokenWithValue[],
testnetClient: TestnetClient,
assetWorthOverrides?: Record<string, number>,
tokenWithValue: TestTokenWithValue[]
testnetClient: TestnetClient
assetWorthOverrides?: Record<string, number>
}): Promise<void> {
await expect(this.region.getByText('Congrats, all done!')).toBeVisible()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export class EModeDialogPageObject extends DialogPageObject {
await this.locateEModeCategoryTile(eModeCategoryName).click()
}

async setEModeAction({ eModeCategoryName, updateBrowserAndNextBlockTime }: { eModeCategoryName: EModeCategoryName, updateBrowserAndNextBlockTime: () => Promise<void> }): Promise<void> {
async setEModeAction({
eModeCategoryName,
updateBrowserAndNextBlockTime,
}: { eModeCategoryName: EModeCategoryName; updateBrowserAndNextBlockTime: () => Promise<void> }): Promise<void> {
await this.clickEModeCategoryTileAction(eModeCategoryName)
await this.acknowledgeIfRiskIsPresent()
await this.actionsContainer.acceptAllActionsAction(1, updateBrowserAndNextBlockTime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
31 changes: 21 additions & 10 deletions packages/app/src/pages/Borrow.PageObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -51,15 +51,26 @@ export class BorrowPageObject extends BasePageObject {
await this.page.getByRole('link', { name: 'View in Savings' }).click()
}

async depositAssetsActions({ assetsToDeposit, daiToBorrow, updateBrowserAndNextBlockTime }: { assetsToDeposit: Record<string, number>, daiToBorrow: number, updateBrowserAndNextBlockTime: () => Promise<void> }): Promise<void> {
async depositAssetsActions({
assetsToDeposit,
daiToBorrow,
updateBrowserAndNextBlockTime,
}: {
assetsToDeposit: Record<string, number>
daiToBorrow: number
updateBrowserAndNextBlockTime: () => Promise<void>
}): Promise<void> {
const actionsContainer = new ActionsPageObject(this.locatePanelByHeader('Actions'))
await this.depositWithoutBorrowActions({
assetsToDeposit,
daiToBorrow,
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({
Expand All @@ -68,9 +79,9 @@ export class BorrowPageObject extends BasePageObject {
actionsContainer: _actionsContainer,
updateBrowserAndNextBlockTime,
}: {
assetsToDeposit: Record<string, number>,
daiToBorrow?: number,
actionsContainer?: ActionsPageObject,
assetsToDeposit: Record<string, number>
daiToBorrow?: number
actionsContainer?: ActionsPageObject
updateBrowserAndNextBlockTime: () => Promise<void>
}): Promise<void> {
const actionsContainer = _actionsContainer ?? new ActionsPageObject(this.locatePanelByHeader('Actions'))
Expand Down Expand Up @@ -132,10 +143,10 @@ export class BorrowPageObject extends BasePageObject {
testnetClient,
assetsWorthOverride,
}: {
deposited: TestTokenWithValue[],
borrowed: TestTokenWithValue,
testnetClient: TestnetClient,
assetsWorthOverride?: Record<string, number>,
deposited: TestTokenWithValue[]
borrowed: TestTokenWithValue
testnetClient: TestnetClient
assetsWorthOverride?: Record<string, number>
}): Promise<void> {
await expect(this.page.getByText('Congrats, all done!')).toBeVisible()

Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/test/e2e/injectSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
await page.addInitScript(
Expand Down
28 changes: 16 additions & 12 deletions packages/app/src/test/e2e/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down Expand Up @@ -42,7 +48,6 @@ export type AccountOptions<T extends ConnectionType> = T extends 'not-connected'
}
: never


export interface BlockchainOptions {
chainId: number
blockNumber: bigint
Expand All @@ -55,13 +60,12 @@ export interface SetupOptions<K extends Path, T extends ConnectionType> {
skipInjectingNetwork?: boolean
}

export type SetupReturn<T extends ConnectionType> = (T extends 'not-connected'
? {} : { account: Address }) & {
getLogs: () => string[],
testnetClient: TestnetClient,
updateBrowserAndNextBlockTime: (seconds: number) => Promise<void>,
incrementTime: (seconds: number) => Promise<void>,
}
export type SetupReturn<T extends ConnectionType> = (T extends 'not-connected' ? {} : { account: Address }) & {
getLogs: () => string[]
testnetClient: TestnetClient
updateBrowserAndNextBlockTime: (seconds: number) => Promise<void>
incrementTime: (seconds: number) => Promise<void>
}

// should be called at the beginning of any test
export async function setup<K extends Path, T extends ConnectionType>(
Expand Down Expand Up @@ -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') {
Expand Down
25 changes: 13 additions & 12 deletions packages/app/src/test/e2e/testnet-cache.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,19 +9,21 @@ interface TestnetContext {
}

const testnetCache = new Map<string, TestnetContext>()

;([`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<TestnetContext> {
const key = `${chainId}-${blockNumber.toString()}`
if (testnetCache.has(key)) {
return testnetCache.get(key)!
Expand Down Expand Up @@ -55,4 +57,3 @@ export async function getTestnetContext({ chainId, blockNumber }: { chainId: num

return context
}

0 comments on commit 8baab05

Please sign in to comment.