Skip to content
Draft
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
6d0ca8f
Phantom support for Playwright
zgz2020 Dec 9, 2024
ce2a2d8
Update typedoc-sidebar.json
zgz2020 Feb 19, 2025
2d251fe
Update typedoc-sidebar.json
zgz2020 Feb 19, 2025
b20c248
Merge branch 'dev' into phantom-playwright
zgz2020 Feb 19, 2025
91125ab
Phantom support for Playwright
zgz2020 Feb 19, 2025
a6201ea
Merge branch 'dev' into phantom-playwright
zgz2020 Feb 20, 2025
61e12e6
chore: build:cache:metamask and build:cache:phantom
drptbl Feb 22, 2025
bff85a1
fix: lint errors
drptbl Feb 22, 2025
1cf492c
chore: add playwright-report to gitignore
drptbl Feb 23, 2025
f531f45
Fix for Sui and Monad screens
zgz2020 Feb 23, 2025
aa88ce5
Removing waitForPhantomLoad
zgz2020 Feb 23, 2025
9661bed
Removing waitForLoadState-networkidle
zgz2020 Feb 23, 2025
c4f747b
Removing some cleanup
zgz2020 Feb 23, 2025
93e1c37
Delay for random fail
zgz2020 Feb 23, 2025
204338c
Close Sui and Monad screens if present
zgz2020 Feb 23, 2025
1f0232b
Adding some delays to avoid random fails
zgz2020 Feb 23, 2025
b8d2928
Adding some delays to avoid random fails
zgz2020 Feb 23, 2025
ae75b3f
Adding some delays to avoid random fails
zgz2020 Feb 23, 2025
5d4dadf
Updating workflow
zgz2020 Feb 23, 2025
19ee365
Adding some delays to avoid random fails
zgz2020 Feb 23, 2025
d6169ed
Adding some delays to avoid random fails
zgz2020 Feb 23, 2025
84c59c0
Adding some delays to avoid random fails
zgz2020 Feb 23, 2025
6de8284
Skipping test
zgz2020 Feb 23, 2025
214a4fe
ncreasing timeout for phantom notification page
zgz2020 Feb 24, 2025
7a418c9
Increasing timeout for phantom notification page
zgz2020 Feb 24, 2025
dc7856b
Trigger Phantom CI e2e tests manually
zgz2020 Feb 25, 2025
89fc35a
Trigger Phantom CI e2e tests manually
zgz2020 Feb 25, 2025
f61f031
Trigger Phantom CI e2e tests manually
zgz2020 Feb 25, 2025
b4d20d1
Testing phantom tests 2
zgz2020 Feb 25, 2025
73aa383
Testing phantom tests 3
zgz2020 Feb 25, 2025
d8f7d6e
Testing phantom tests 4
zgz2020 Feb 25, 2025
fcc4a6f
Increase test timeout
zgz2020 Feb 25, 2025
2757cfd
Sui and Monad
zgz2020 Feb 25, 2025
5b675ce
Merge branch 'dev' into phantom-e2e-tests
zgz2020 Feb 26, 2025
9a29264
Sui and Monad
zgz2020 Feb 26, 2025
2975510
Improvements
zgz2020 Feb 27, 2025
3c46af9
Improvements
zgz2020 Feb 27, 2025
ccfa5e5
Testing tests
zgz2020 Feb 28, 2025
6cd3641
Merge branch 'dev' into phantom-e2e-tests
zgz2020 Feb 28, 2025
31b965d
Extend timeout
zgz2020 Feb 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,13 @@ jobs:
run: |
pnpm run serve:test-dapp &

- name: Build cache
- name: Build cache (metamask)
run: |
xvfb-run pnpm run build:cache
xvfb-run pnpm run build:cache:metamask

- name: Build cache (phantom)
run: |
xvfb-run pnpm run build:cache:phantom

- name: Run E2E tests (headful)
run: |
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ playwright/.cache
output

synpress-source.txt

playwright-report*
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"license": "MIT",
"scripts": {
"build": "turbo build",
"build:cache": "turbo build:cache --filter=@synthetixio/synpress-metamask",
"docs:build": "turbo docs:build --filter=docs",
"build:cache:metamask": "turbo build:cache --filter=@synthetixio/synpress-metamask",
"build:cache:phantom": "turbo build:cache --filter=@synthetixio/synpress-phantom",
"format": "biome format . --write",
"format:check": "biome format . --error-on-warnings",
"preinstall": "npx only-allow pnpm",
Expand All @@ -21,8 +21,8 @@
"sort-package-json": "sort-package-json 'package.json' '{packages,wallets,examples}/*/package.json'",
"sort-package-json:check": "sort-package-json 'package.json' '{packages,wallets,examples}/*/package.json' --check",
"test": "turbo test",
"test:playwright:headful": "turbo test:playwright:headful --filter=@synthetixio/synpress-metamask --filter=@synthetixio/ethereum-wallet-mock",
"test:playwright:headless": "turbo test:playwright:headless --filter=@synthetixio/synpress-metamask --filter=@synthetixio/ethereum-wallet-mock",
"test:playwright:headful": "turbo test:playwright:headful --filter=@synthetixio/synpress-metamask --filter=@synthetixio/ethereum-wallet-mock --filter=@synthetixio/synpress-phantom",
"test:playwright:headless": "turbo test:playwright:headless --filter=@synthetixio/synpress-metamask --filter=@synthetixio/ethereum-wallet-mock --filter=@synthetixio/synpress-phantom",
"update:deps": "ncu -u -ws --root"
},
"lint-staged": {
Expand Down
1 change: 1 addition & 0 deletions packages/cache/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"gradient-string": "2.0.2",
"progress": "2.0.3",
"tsup": "8.0.2",
"unzip-crx-3": "0.2.0",
"unzipper": "0.10.14",
"zod": "3.22.4"
},
Expand Down
11 changes: 9 additions & 2 deletions packages/cache/src/cli/cliEntrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import { rimraf } from 'rimraf'
import { WALLET_SETUP_DIR_NAME } from '../constants'
import { createCache } from '../createCache'
import { prepareExtension } from '../prepareExtension'
import { prepareExtensionPhantom } from '../prepareExtensionPhantom'
import { compileWalletSetupFunctions } from './compileWalletSetupFunctions'
import { footer } from './footer'

interface CliFlags {
headless: boolean
force: boolean
debug: boolean
phantom: boolean
}

// TODO: Add unit tests for the CLI!
Expand All @@ -30,6 +32,7 @@ export const cliEntrypoint = async () => {
)
.option('-f, --force', 'Force the creation of cache even if it already exists', false)
.option('-d, --debug', 'If this flag is present, the compilation files are not going to be deleted', false)
.option('-p, --phantom', 'If this flag is present, Phantom extension will be installed instead of Metamask', false)
.helpOption(undefined, 'Display help for command')
.addHelpText('afterAll', `\n${footer}\n`)
.parse(process.argv)
Expand Down Expand Up @@ -77,8 +80,12 @@ export const cliEntrypoint = async () => {
flags.debug
)

// TODO: We should be using `prepareExtension` function from the wallet itself!
await createCache(compiledWalletSetupDirPath, setupFunctionHashes, prepareExtension, flags.force)
// TODO: We should be using `prepareExtension` functions from the wallet itself!
if (flags.phantom) {
await createCache(compiledWalletSetupDirPath, setupFunctionHashes, prepareExtensionPhantom, flags.force)
} else {
await createCache(compiledWalletSetupDirPath, setupFunctionHashes, prepareExtension, flags.force)
}

if (!flags.debug) {
await rimraf(compiledWalletSetupDirPath)
Expand Down
1 change: 1 addition & 0 deletions packages/cache/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from './utils/createTempContextDir'
export * from './utils/removeTempContextDir'
export * from './prepareExtension'
export * from './cli/cliEntrypoint'
export * from './prepareExtensionPhantom'
21 changes: 21 additions & 0 deletions packages/cache/src/prepareExtensionPhantom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { downloadFile, ensureCacheDirExists, unzipArchivePhantom } from '.'

export const DEFAULT_PHANTOM_VERSION = 'latest'
export const PHANTOM_EXTENSION_DOWNLOAD_URL = 'https://crx-backup.phantom.dev/latest.crx'

// NOTE: This function is copied from `wallets/phantom/src/prepareExtensionPhantom.ts` only TEMPORARILY!
export async function prepareExtensionPhantom() {
const cacheDirPath = ensureCacheDirExists()

const downloadResult = await downloadFile({
url: PHANTOM_EXTENSION_DOWNLOAD_URL,
outputDir: cacheDirPath,
fileName: 'phantom-chrome-latest.crx'
})

const unzipResult = await unzipArchivePhantom({
archivePath: downloadResult.filePath
})

return unzipResult.outputPath
}
25 changes: 25 additions & 0 deletions packages/cache/src/unzipArchive.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'node:path'
import fs from 'fs-extra'
import unzipCrx from 'unzip-crx-3'
import unzippper from 'unzipper'

type UnzipArchiveOptions = {
Expand Down Expand Up @@ -73,3 +74,27 @@ export async function unzipArchive(options: UnzipArchiveOptions) {
throw new Error(`[UnzipFile] Error unzipping the file - ${error.message}`)
})
}

export async function unzipArchivePhantom(options: UnzipArchiveOptions) {
const { archivePath, overwrite } = options

const archiveFileExtension = archivePath.split('.').slice(-1)
const outputPath = archivePath.replace(`.${archiveFileExtension}`, '')

const fileExists = fs.existsSync(outputPath)
if (fileExists && !overwrite) {
return {
outputPath,
unzipSkipped: true
}
}

// Creates the output directory
fs.mkdirSync(outputPath, { recursive: true })

await unzipCrx(archivePath, outputPath)

// TODO: Handle errors

return { outputPath }
}
2 changes: 1 addition & 1 deletion packages/cache/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"declarationMap": true
},
"include": ["src"],
"files": ["environment.d.ts"]
"files": ["environment.d.ts", "unzip-crx-3.d.ts"]
}
7 changes: 2 additions & 5 deletions packages/cache/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
"rootDir": ".",
"lib": ["DOM"]
},
"include": [
"src",
"test"
],
"files": ["environment.d.ts"]
"include": ["src", "test"],
"files": ["environment.d.ts", "unzip-crx-3.d.ts"]
}
1 change: 1 addition & 0 deletions packages/cache/unzip-crx-3.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'unzip-crx-3'
98 changes: 98 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading