From bfac707ef0b6b01ee5fad64cc030d31e13b46f5c Mon Sep 17 00:00:00 2001 From: Sero <69639595+Seroxdesign@users.noreply.github.com> Date: Wed, 26 Jun 2024 06:37:55 -0400 Subject: [PATCH] done --- wallets/metamask/package.json | 1 + .../src/fixture-actions/importForFixtures.ts | 9 ++++ .../metamask/src/fixtures/metaMaskFixtures.ts | 7 ++-- .../src/fixtures/noCacheMetaMaskFixtures.ts | 42 ++++++------------- 4 files changed, 27 insertions(+), 32 deletions(-) create mode 100644 wallets/metamask/src/fixture-actions/importForFixtures.ts diff --git a/wallets/metamask/package.json b/wallets/metamask/package.json index 6bb0a5276..d0e1c3786 100644 --- a/wallets/metamask/package.json +++ b/wallets/metamask/package.json @@ -42,6 +42,7 @@ "@synthetixio/synpress-tsconfig": "0.0.1-alpha.7", "@types/fs-extra": "11.0.4", "@types/node": "20.11.17", + "@types/unzipper": "0.10.9", "@vitest/coverage-v8": "1.2.2", "rimraf": "5.0.5", "tsup": "8.0.2", diff --git a/wallets/metamask/src/fixture-actions/importForFixtures.ts b/wallets/metamask/src/fixture-actions/importForFixtures.ts new file mode 100644 index 000000000..99000244f --- /dev/null +++ b/wallets/metamask/src/fixture-actions/importForFixtures.ts @@ -0,0 +1,9 @@ +import type { Page } from '@playwright/test' +import { MetaMask } from '..' + +export async function importForFixtures(page: Page, seedPhrase: string, password: string, extensionId: string) { + const metamask = new MetaMask(page.context(), page, password, extensionId) + + await metamask.importWallet(seedPhrase) + +} \ No newline at end of file diff --git a/wallets/metamask/src/fixtures/metaMaskFixtures.ts b/wallets/metamask/src/fixtures/metaMaskFixtures.ts index 9b388d527..f519b70fc 100644 --- a/wallets/metamask/src/fixtures/metaMaskFixtures.ts +++ b/wallets/metamask/src/fixtures/metaMaskFixtures.ts @@ -13,6 +13,7 @@ import { type Anvil, type CreateAnvilOptions, createPool } from '@viem/anvil' import fs from 'fs-extra' import { cachelessSetupMetaMask } from './noCacheMetaMaskFixtures' import { persistLocalStorage } from '../fixture-actions/persistLocalStorage' +import { importForFixtures } from '../fixture-actions/importForFixtures' import { SEED_PHRASE } from '../../test/wallet-setup/basic.setup' const USECACHE = false; @@ -87,7 +88,7 @@ export const metaMaskFixtures = (walletSetup: ReturnType { const response = await axios.get(url, { responseType: 'stream' }); const writer = fs.createWriteStream(destination); @@ -37,7 +32,6 @@ async function downloadAndExtract(url: string, destination: string): Promise { const archiveFileExtension = path.extname(archivePath); const outputPath = archivePath.replace(archiveFileExtension, ''); @@ -45,53 +39,43 @@ async function unzipArchive(archivePath: string): Promise { await fs.ensureDir(outputPath); try { - await new Promise((resolve, reject) => { + await new Promise((resolve, reject) => { fs.createReadStream(archivePath) .pipe(unzipper.Parse()) .on('entry', (entry: any) => { const fileName = entry.path; const type = entry.type as 'Directory' | 'File'; - + if (type === 'Directory') { fs.mkdirSync(path.join(outputPath, fileName), { recursive: true }); return; } - + if (type === 'File') { entry.pipe(fs.createWriteStream(path.join(outputPath, fileName))); } }) - .on('finish', () => resolve()) + .on('finish', () => resolve(void 0)) .on('error', (error: Error) => reject(error)); }); } catch (error: any) { - // Handle errors here console.error(`[unzipArchive] Error unzipping archive: ${error.message}`); - // You might want to implement retries or other error handling logic - throw error; // Re-throw the error to stop execution + throw error; } } -// The main function to set up MetaMask without caching + export async function cachelessSetupMetaMask( - // seedPhrase: string, - // password: string, metamaskVersion?: string ): Promise { const metamaskPath = await prepareMetaMask(metamaskVersion || DEFAULT_METAMASK_VERSION); + const browserArgs = [`--load-extension=${metamaskPath}`, `--disable-extensions-except=${metamaskPath}`]; console.log(metamaskPath) + if (process.env.HEADLESS) { + browserArgs.push('--headless=new') + } const context = await chromium.launchPersistentContext('', { - args: [`--load-extension=${metamaskPath}`, `--disable-extensions-except=${metamaskPath}`] + headless: false, + args: browserArgs, }); - - // const extensionId = await getExtensionId(context, 'MetaMask'); - - // console.log(`[MetaMask] Extension ID: ${extensionId}`); - // const metamaskPage = await context.newPage(); - // await metamaskPage.goto(`chrome-extension://${extensionId}/home.html`, { waitUntil: 'networkidle' }); - - // const metamask = new MetaMask(context, metamaskPage, password); - // await metamask.importWallet(seedPhrase); - // await unlockForFixture(metamaskPage, password); - return context; } \ No newline at end of file