Skip to content

Commit

Permalink
clean up and solve most other text
Browse files Browse the repository at this point in the history
  • Loading branch information
Seroxdesign committed Jun 27, 2024
1 parent f8f353b commit f31b14a
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 37 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/testWithSynpress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ export default function testWithSynpress<CustomFixtures extends Fixtures>(
customFixtures: TestType<CustomFixtures, object>
) {
return mergeTests(base, customFixtures)
}
}
2 changes: 1 addition & 1 deletion wallets/metamask/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default defineConfig({

// We're increasing the timeout to 60 seconds to allow all traces to be recorded.
// Sometimes it threw an error saying that traces were not recorded in the 30 seconds timeout limit.
timeout: 60_000,
timeout: 90_000,

// Run all tests in parallel.
fullyParallel: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
import type { Page } from '@playwright/test'
import { MetaMask } from '..'

export async function importAndConnectForFixtures(page: Page, seedPhrase: string, password: string, extensionId: string) {
import { retryIfMetaMaskCrashAfterUnlock } from '..'
import { closePopover } from '../pages/HomePage/actions'

export async function importAndConnectForFixtures(
page: Page,
seedPhrase: string,
password: string,
extensionId: string
) {
const metamask = new MetaMask(page.context(), page, password, extensionId)

await metamask.importWallet(seedPhrase)

await metamask.openSettings()

const SidebarMenus = metamask.homePage.selectors.settings.SettingsSidebarMenus

await metamask.openSidebarMenu(SidebarMenus.Advanced)

await metamask.toggleDismissSecretRecoveryPhraseReminder()

await page.goto(`chrome-extension://${extensionId}/home.html`)

await retryIfMetaMaskCrashAfterUnlock(page)

await closePopover(page)

const newPage = await page.context().newPage()

await newPage.goto('http://localhost:9999')
Expand Down
31 changes: 17 additions & 14 deletions wallets/metamask/src/fixture-actions/noCachMetaMaskSetup.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import path from 'node:path'
import { DEFAULT_METAMASK_VERSION, EXTENSION_DOWNLOAD_URL } from '../utils/constants'
import { type BrowserContext, chromium } from '@playwright/test'
import appRoot from 'app-root-path'
import axios from 'axios'
import fs from 'fs-extra'
import unzipper from 'unzipper'
import { DEFAULT_METAMASK_VERSION, EXTENSION_DOWNLOAD_URL } from '../utils/constants'

async function prepareMetaMask(version: string = DEFAULT_METAMASK_VERSION): Promise<string> {
let downloadsDirectory
Expand Down Expand Up @@ -46,28 +46,31 @@ async function unzipArchive(archivePath: string): Promise<void> {
try {
await new Promise<void>((resolve, reject) => {
const stream = fs.createReadStream(archivePath).pipe(unzipper.Parse())
stream.on('entry', async (entry: { path: string; type: string; pipe: (arg: unknown) => void, autodrain: () => void }) => {
stream.on(
'entry',
async (entry: { path: string; type: string; pipe: (arg: unknown) => void; autodrain: () => void }) => {
const fileName = entry.path

Check failure

Code scanning / CodeQL

Arbitrary file access during archive extraction ("Zip Slip") High

Unsanitized archive entry, which may contain '..', is used in a
file system operation
.
const type = entry.type as 'Directory' | 'File'

if (type === 'Directory') {
await fs.mkdir(path.join(outputPath, fileName), { recursive: true });
entry.autodrain();
return;
await fs.mkdir(path.join(outputPath, fileName), { recursive: true })
entry.autodrain()
return
}

if (type === 'File') {
const writeStream = fs.createWriteStream(path.join(outputPath, fileName));
entry.pipe(writeStream);
const writeStream = fs.createWriteStream(path.join(outputPath, fileName))
entry.pipe(writeStream)

await new Promise<void>((res, rej) => {
writeStream.on('finish', res);
writeStream.on('error', rej);
});
writeStream.on('finish', res)
writeStream.on('error', rej)
})
}
})
stream.on('finish', resolve);
stream.on('error', reject);
}
)
stream.on('finish', resolve)
stream.on('error', reject)
})
} catch (error: unknown) {
console.error(`[unzipArchive] Error unzipping archive: ${(error as { message: string }).message}`)
Expand Down
2 changes: 1 addition & 1 deletion wallets/metamask/src/fixture-actions/unlockForFixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async function unlockWalletButReloadIfSpinnerDoesNotVanish(metamask: MetaMask) {
}
}

async function retryIfMetaMaskCrashAfterUnlock(page: Page) {
export async function retryIfMetaMaskCrashAfterUnlock(page: Page) {
const homePageLogoLocator = page.locator(HomePage.selectors.logo)

const isHomePageLogoVisible = await homePageLogoLocator.isVisible()
Expand Down
7 changes: 4 additions & 3 deletions wallets/metamask/src/fixtures/metaMaskFixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import {
} from '@synthetixio/synpress-cache'
import { type Anvil, type CreateAnvilOptions, createPool } from '@viem/anvil'
import fs from 'fs-extra'
import { SEED_PHRASE } from '../utils/constants'
import { importAndConnectForFixtures } from '../fixture-actions/importAndConnectForFixtures'
import { cachelessSetupMetaMask } from '../fixture-actions/noCachMetaMaskSetup'
import { persistLocalStorage } from '../fixture-actions/persistLocalStorage'
import { SEED_PHRASE } from '../utils/constants'

// console.log(process.env.SYNPRESS_USE_CACHE, process.platform)
const USECACHE = (false || process.platform === 'win32');
const USECACHE = false || process.platform === 'win32'

type MetaMaskFixtures = {
_contextPath: string
Expand Down Expand Up @@ -100,7 +100,8 @@ export const metaMaskFixtures = (walletSetup: ReturnType<typeof defineWalletSetu
_metamaskPage = context.pages()[0] as Page

await _metamaskPage.goto(`chrome-extension://${extensionId}/home.html`)
if (!USECACHE) await importAndConnectForFixtures(_metamaskPage, SEED_PHRASE, walletSetup.walletPassword, extensionId)
if (!USECACHE)
await importAndConnectForFixtures(_metamaskPage, SEED_PHRASE, walletSetup.walletPassword, extensionId)
if (USECACHE) await unlockForFixture(_metamaskPage, walletSetup.walletPassword)

await use(context)
Expand Down
2 changes: 1 addition & 1 deletion wallets/metamask/src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const SEED_PHRASE = "test test test test test test test test test test test junk"
export const SEED_PHRASE = 'test test test test test test test test test test test junk'
export const DEFAULT_METAMASK_VERSION = '11.9.1'
export const EXTENSION_DOWNLOAD_URL = `https://github.com/MetaMask/metamask-extension/releases/download/v${DEFAULT_METAMASK_VERSION}/metamask-chrome-${DEFAULT_METAMASK_VERSION}.zip`
6 changes: 2 additions & 4 deletions wallets/metamask/src/utils/toggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ export async function toggle(toggleLocator: Locator) {

const isOn = classes.includes('toggle-button--on')

await toggleLocator.click()

const waitForAction = async () => {
const classes = await toggleLocator.getAttribute('class')

if (!classes) {
throw new Error('[ToggleShowTestNetworks] Toggle class returned null inside waitFor')
}

if (isOn) {
return classes.includes('toggle-button--off')
if (!isOn) {
await toggleLocator.click()
}

return classes.includes('toggle-button--on')
Expand Down
8 changes: 6 additions & 2 deletions wallets/metamask/test/e2e/connectToDapp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ test('should connect wallet to dapp', async ({ context, page, extensionId }) =>

await page.goto('/')

await page.locator('#connectButton').click()
const disabled = await page.locator('#connectButton').isDisabled()

await metamask.connectToDapp()
if (!disabled) {
await page.locator('#connectButton').click()
await metamask.connectToDapp()
}

await expect(page.locator('#accounts')).toHaveText('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266')
})
Expand All @@ -26,6 +29,7 @@ test('should connect multiple wallets to dapp', async ({ context, page, metamask
await metamask.addNewAccount('Account x3')

await page.goto('/')

await page.locator('#connectButton').click()

// "accounts" param is order agnostic
Expand Down
16 changes: 8 additions & 8 deletions wallets/metamask/test/wallet-setup/basic.setup.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export declare const SEED_PHRASE = "test test test test test test test test test test test junk";
export declare const PASSWORD = "Tester@1234";
export declare const SEED_PHRASE = 'test test test test test test test test test test test junk'
export declare const PASSWORD = 'Tester@1234'
declare const _default: {
hash: string;
fn: import("@synthetixio/synpress-cache").WalletSetupFunction;
walletPassword: string;
};
export default _default;
//# sourceMappingURL=basic.setup.d.ts.map
hash: string
fn: import('@synthetixio/synpress-cache').WalletSetupFunction
walletPassword: string
}
export default _default
//# sourceMappingURL=basic.setup.d.ts.map

0 comments on commit f31b14a

Please sign in to comment.