diff --git a/wallets/keplr/src/fixtureActions/getExtensionId.ts b/wallets/keplr/src/fixtureActions/getExtensionId.ts new file mode 100644 index 000000000..530ab8937 --- /dev/null +++ b/wallets/keplr/src/fixtureActions/getExtensionId.ts @@ -0,0 +1,46 @@ +import type { BrowserContext } from '@playwright/test' +import { z } from 'zod' + +const Extension = z.object({ + id: z.string(), + name: z.string() +}) + +const Extensions = z.array(Extension) + +/** + * Returns the extension ID for the given extension name. The ID is fetched from the `chrome://extensions` page. + * + * ::: tip + * This function soon will be removed to improve the developer experience! 😇 + * ::: + * + * @param context - The browser context. + * @param extensionName - The name of the extension, e.g., `Keplr`. + * + * @returns The extension ID. + */ +export async function getExtensionId(context: BrowserContext, extensionName: string) { + const page = await context.newPage() + await page.goto('chrome://extensions') + + const unparsedExtensions = await page.evaluate('chrome.management.getAll()') + + const allExtensions = Extensions.parse(unparsedExtensions) + const targetExtension = allExtensions.find( + (extension) => extension.name.toLowerCase() === extensionName.toLowerCase() + ) + + if (!targetExtension) { + throw new Error( + [ + `[GetExtensionId] Extension with name ${extensionName} not found.`, + `Available extensions: ${allExtensions.map((extension) => extension.name).join(', ')}` + ].join('\n') + ) + } + + await page.close() + + return targetExtension.id +} diff --git a/wallets/keplr/src/fixtureActions/prepareExtension.ts b/wallets/keplr/src/fixtureActions/prepareExtension.ts new file mode 100644 index 000000000..ff8526305 --- /dev/null +++ b/wallets/keplr/src/fixtureActions/prepareExtension.ts @@ -0,0 +1,19 @@ +import { downloadFile, ensureCacheDirExists, unzipArchive } from '@synthetixio/synpress-cache' + +export const DEFAULT_KEPLR_VERSION = '0.12.101' +export const EXTENSION_DOWNLOAD_URL = `https://github.com/chainapsis/keplr-wallet/releases/download/v${DEFAULT_KEPLR_VERSION}/keplr-extension-manifest-v2-v${DEFAULT_KEPLR_VERSION}.zip`; +export async function prepareExtension() { + const cacheDirPath = ensureCacheDirExists() + + const downloadResult = await downloadFile({ + url: EXTENSION_DOWNLOAD_URL, + outputDir: cacheDirPath, + fileName: `keplr-extension-manifest-v2-v${DEFAULT_KEPLR_VERSION}.zip` + }) + + const unzipResult = await unzipArchive({ + archivePath: downloadResult.filePath + }) + + return unzipResult.outputPath +}