diff --git a/packages/app/src/pages/Savings.test-e2e.ts b/packages/app/src/pages/Savings.test-e2e.ts index 297ebe6d2..e27a8b5f2 100644 --- a/packages/app/src/pages/Savings.test-e2e.ts +++ b/packages/app/src/pages/Savings.test-e2e.ts @@ -182,7 +182,7 @@ test.describe('Savings Base', () => { await savingsPage.expectSavingsUsdsBalance({ susdsBalance: '100.00', - estimatedUsdsValue: '101.28654787', + estimatedUsdsValue: '101.28654604', }) }) diff --git a/packages/app/src/test/e2e/setup.ts b/packages/app/src/test/e2e/setup.ts index 8cc92ea19..6decb3a2c 100644 --- a/packages/app/src/test/e2e/setup.ts +++ b/packages/app/src/test/e2e/setup.ts @@ -7,7 +7,6 @@ import { Address, Hash, parseEther, parseUnits } from 'viem' import { AssetsInTests, TOKENS_ON_FORK } from './constants' import { getTestnetContext } from './getTestnetContext' import { injectNetworkConfiguration, injectWalletConfiguration } from './injectSetup' -import { syncBrowserTime } from './syncBrowserTime' import { generateAccount } from './utils' export type InjectableWallet = { address: Address } | { privateKey: string } @@ -83,7 +82,7 @@ export async function setup( const progressedTimestamp = currentTimestamp + BigInt(seconds) await testnetClient.setNextBlockTimestamp(progressedTimestamp) - await page.evaluate(syncBrowserTime, { rpcUrl: getUrlFromClient(testnetClient) }) + await page.clock.setFixedTime(Number(currentTimestamp) * 1000) } async function progressSimulationAndMine(seconds: number): Promise { @@ -188,5 +187,6 @@ async function injectPageSetup({ await injectNetworkConfiguration(page, getUrlFromClient(testnetClient), options.blockchain.chainId) } - await page.addInitScript(syncBrowserTime, { rpcUrl: getUrlFromClient(testnetClient) }) + const { timestamp } = await testnetClient.getBlock() + await page.clock.setFixedTime(Number(timestamp) * 1000) } diff --git a/packages/app/src/test/e2e/syncBrowserTime.ts b/packages/app/src/test/e2e/syncBrowserTime.ts deleted file mode 100644 index ab59239c0..000000000 --- a/packages/app/src/test/e2e/syncBrowserTime.ts +++ /dev/null @@ -1,74 +0,0 @@ -export async function syncBrowserTime({ rpcUrl }: { rpcUrl: string }): Promise { - interface FetchRetryOptions { - retries?: number - baseDelay?: number // delay in ms between retries - } - - async function sleep(ms: number): Promise { - return new Promise((resolve) => setTimeout(resolve, ms)) - } - - async function fetchWithRetry( - input: RequestInfo | URL, - init?: RequestInit, - options?: FetchRetryOptions, - ): Promise { - const { retries = 3, baseDelay = 150 } = options || {} - - let attempt = 0 - let lastError: any - - while (attempt < retries) { - try { - const response = await fetch(input, init) - if (!response.ok) { - throw new Error(`Fetch error: ${response.status} ${response.statusText}`) - } - return response - } catch (error) { - lastError = error - attempt++ - if (attempt < retries) { - // Exponential backoff: delay = baseDelay * 2^(attempt-1) - const waitTime = baseDelay * 2 ** (attempt - 1) - await sleep(waitTime) - } - } - } - - throw lastError - } - - const response = await fetchWithRetry(rpcUrl, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - jsonrpc: '2.0', - method: 'eth_getBlockByNumber', - params: ['latest', false], - id: 1, - }), - }) - const { result } = (await response.json()) as { result: any } - const date = new Date(Number(result.timestamp) * 1000) - - const fakeNow = date.valueOf() - - // biome-ignore lint/suspicious/noGlobalAssign: - // @ts-ignore - Date = class extends Date { - // @ts-ignore - constructor(...args) { - if (args.length === 0) { - super(fakeNow) - } else { - // @ts-ignore - super(...args) - } - } - } - - Date.now = () => fakeNow -}