-
-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
147 additions
and
17 deletions.
There are no files selected for viewing
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { type BrowserContext, type Page, chromium } from "@playwright/test"; | ||
import { getExtensionId } from "@synthetixio/synpress-fixtures"; | ||
import { PASSWORD, SEED_PHRASE } from "./constants"; | ||
import { MetaMask } from "./metamask"; | ||
|
||
let context: BrowserContext | undefined; | ||
let extensionId: string | undefined; | ||
let metamask: MetaMask | undefined; | ||
|
||
const isMetaMaskPage = (page: Page) => | ||
page.url().includes(`chrome-extension://${extensionId}`); | ||
|
||
export async function getMetaMaskExtensionId() { | ||
if (extensionId) return extensionId; | ||
|
||
if (!context) { | ||
console.error( | ||
"No browser context found. Connect to Playwright first - connectPlaywright()" | ||
); | ||
return; | ||
} | ||
|
||
if (!extensionId) { | ||
Check warning Code scanning / CodeQL Useless conditional Warning
This negation always evaluates to true.
|
||
extensionId = await getExtensionId(context, "MetaMask"); | ||
} | ||
|
||
return extensionId; | ||
} | ||
|
||
export async function connectPlaywright(port: number) { | ||
const debuggerDetails = await fetch(`http://127.0.0.1:${port}/json/version`); | ||
|
||
const debuggerDetailsConfig = (await debuggerDetails.json()) as { | ||
webSocketDebuggerUrl: string; | ||
}; | ||
const webSocketDebuggerUrl = debuggerDetailsConfig.webSocketDebuggerUrl; | ||
|
||
const browser = await chromium.connectOverCDP(webSocketDebuggerUrl); | ||
|
||
context = browser.contexts()[0]; | ||
|
||
return browser.isConnected(); | ||
} | ||
|
||
export async function initMetamask(port: number) { | ||
await connectPlaywright(port); | ||
const extensionId = await getMetaMaskExtensionId(); | ||
|
||
const isMetaMaskPage = (page: Page) => | ||
page.url().includes(`chrome-extension://${extensionId}`); | ||
|
||
if (!context) { | ||
console.error("No browser context found."); | ||
return; | ||
} | ||
|
||
const metamaskPage = context.pages().find(isMetaMaskPage); | ||
|
||
if (metamaskPage) { | ||
metamask = new MetaMask(context, metamaskPage, PASSWORD); | ||
|
||
await metamask.importWallet(SEED_PHRASE); | ||
|
||
return metamask; | ||
} | ||
return; | ||
} | ||
|
||
export function getMetaMask() { | ||
if (metamask) return metamask; | ||
|
||
if (!context) { | ||
console.error( | ||
"No browser context found. Connect to Playwright first - connectPlaywright()" | ||
); | ||
return; | ||
} | ||
|
||
const metamaskPage = context.pages().find(isMetaMaskPage); | ||
|
||
if (!metamaskPage) { | ||
console.error("No MetaMask page found."); | ||
return; | ||
} | ||
|
||
return new MetaMask(context, metamaskPage, PASSWORD); | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { getMetaMask } from "../initMetaMask"; | ||
|
||
export default function setupTasks( | ||
on: ( | ||
action: "task", | ||
arg: { | ||
// biome-ignore lint/suspicious/noExplicitAny: <explanation> | ||
[key: string]: (...args: any[]) => any; | ||
} | ||
) => void | ||
) { | ||
on("task", { | ||
importWallet: async function (seedPhrase: string) { | ||
const metamask = getMetaMask(); | ||
if (metamask) { | ||
await metamask.importWallet(seedPhrase); | ||
} | ||
return true; | ||
}, | ||
addNewAccount: async function (accountName: string) { | ||
const metamask = getMetaMask(); | ||
if (metamask) { | ||
await metamask.addNewAccount(accountName); | ||
} | ||
return true; | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,5 +15,3 @@ | |
|
||
// Import commands.js using ES2015 syntax: | ||
import './commands' | ||
|
||
// TODO: Add MetaMask initial setup here. |
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
wallets/metamask/test/e2e/cypress/metamask/setupMetaMask.cy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
describe('Playwright', () => { | ||
it('connects to Cypress running browser', () => { | ||
cy.wait(100000000) | ||
// cy.connectPlaywright().then((connected) => { | ||
// expect(connected).to.equal(true); | ||
// }); | ||
}) | ||
it('setup MetaMask wallet', () => { | ||
// cy.initMetamask(); | ||
}) | ||
}) |