From f7a804429c2211401819dec3db3c31815b44be88 Mon Sep 17 00:00:00 2001 From: Nabin Kawan Date: Wed, 3 Jul 2024 13:06:11 +0545 Subject: [PATCH 1/2] chore: Update wallet (fixtures, helper) to support cardano-test-wallet version 2.0.0 --- .../playwright/lib/fixtures/createWallet.ts | 7 +++--- .../playwright/lib/fixtures/importWallet.ts | 4 ++-- .../playwright/lib/fixtures/loadExtension.ts | 24 ++++++++++++------- .../lib/fixtures/walletExtension.ts | 10 ++++++-- .../playwright/lib/helpers/page.ts | 18 ++++++++++---- .../govtool-frontend/playwright/lib/types.ts | 4 ++-- .../playwright/package-lock.json | 14 +++++------ .../govtool-frontend/playwright/package.json | 2 +- 8 files changed, 53 insertions(+), 30 deletions(-) diff --git a/tests/govtool-frontend/playwright/lib/fixtures/createWallet.ts b/tests/govtool-frontend/playwright/lib/fixtures/createWallet.ts index 0ab7f1c04..c9d2dc6e7 100644 --- a/tests/govtool-frontend/playwright/lib/fixtures/createWallet.ts +++ b/tests/govtool-frontend/playwright/lib/fixtures/createWallet.ts @@ -1,6 +1,7 @@ import { CardanoTestWallet, CardanoTestWalletConfig, + CardanoTestWalletJson, } from "@cardanoapi/cardano-test-wallet/types"; import { ShelleyWallet } from "@helpers/crypto"; import { Page } from "@playwright/test"; @@ -12,7 +13,7 @@ export default async function createWallet( const wallet = (await ShelleyWallet.generate()).json(); const initScriptArgs: { - wallet: CardanoTestWallet; + wallet: CardanoTestWalletJson; config: CardanoTestWalletConfig; } = { wallet, @@ -23,12 +24,12 @@ export default async function createWallet( window["cardanoTestWallet"] = { ...window["cardanoTestWallet"], wallet: wallet, - }; + } as CardanoTestWallet; if (config) { window["cardanoTestWallet"]["config"] = { ...window["cardanoTestWallet"]["config"], ...config, - }; + } as CardanoTestWallet; } }, initScriptArgs); } diff --git a/tests/govtool-frontend/playwright/lib/fixtures/importWallet.ts b/tests/govtool-frontend/playwright/lib/fixtures/importWallet.ts index d825f8cf9..e9e79dea5 100644 --- a/tests/govtool-frontend/playwright/lib/fixtures/importWallet.ts +++ b/tests/govtool-frontend/playwright/lib/fixtures/importWallet.ts @@ -1,10 +1,10 @@ -import { CardanoTestWallet } from "@cardanoapi/cardano-test-wallet/types"; +import { CardanoTestWalletJson } from "@cardanoapi/cardano-test-wallet/types"; import { Page } from "@playwright/test"; import { StaticWallet } from "@types"; export async function importWallet( page: Page, - wallet: StaticWallet | CardanoTestWallet + wallet: StaticWallet | CardanoTestWalletJson ) { await page.addInitScript((wallet) => { // @ts-ignore diff --git a/tests/govtool-frontend/playwright/lib/fixtures/loadExtension.ts b/tests/govtool-frontend/playwright/lib/fixtures/loadExtension.ts index 44cea5367..41ed3e722 100644 --- a/tests/govtool-frontend/playwright/lib/fixtures/loadExtension.ts +++ b/tests/govtool-frontend/playwright/lib/fixtures/loadExtension.ts @@ -1,4 +1,7 @@ -import { CardanoTestWalletConfig } from "@cardanoapi/cardano-test-wallet/types"; +import { + CardanoTestWallet, + CardanoTestWalletConfig, +} from "@cardanoapi/cardano-test-wallet/types"; import environments from "@constants/environments"; import { Page } from "@playwright/test"; @@ -6,7 +9,8 @@ import path = require("path"); export default async function loadDemosExtension( page: Page, - enableStakeSigning = false + enableStakeSigning?: boolean, + supportedExtensions?: Record[] ) { const demosBundleScriptPath = path.resolve( __dirname, @@ -17,12 +21,16 @@ export default async function loadDemosExtension( kuberApiUrl: environments.kuber.apiUrl, kuberApiKey: environments.kuber.apiKey, }; - await page.addInitScript((walletConfig) => { - window["cardanoTestWallet"] = { - walletName: "demos", - config: walletConfig, - }; - }, walletConfig); + await page.addInitScript( + ({ walletConfig, supportedExtensions }) => { + window["cardanoTestWallet"] = { + walletName: "demos", + supportedExtensions, + config: walletConfig, + } as CardanoTestWallet; + }, + { walletConfig, supportedExtensions } + ); await page.addInitScript({ path: demosBundleScriptPath }); } diff --git a/tests/govtool-frontend/playwright/lib/fixtures/walletExtension.ts b/tests/govtool-frontend/playwright/lib/fixtures/walletExtension.ts index 5f1fa6e7c..e6d7ea1da 100644 --- a/tests/govtool-frontend/playwright/lib/fixtures/walletExtension.ts +++ b/tests/govtool-frontend/playwright/lib/fixtures/walletExtension.ts @@ -6,6 +6,7 @@ import loadDemosExtension from "./loadExtension"; type WalletExtensionTestOptions = { wallet?: StaticWallet; enableStakeSigning: boolean; + supportedExtensions: Record[]; }; export const test = base.extend({ @@ -13,8 +14,13 @@ export const test = base.extend({ enableStakeSigning: [true, { option: true }], - page: async ({ page, wallet, enableStakeSigning }, use) => { - await loadDemosExtension(page, enableStakeSigning); + supportedExtensions: [[{ cip: 95 }], { option: true }], + + page: async ( + { page, wallet, enableStakeSigning, supportedExtensions }, + use + ) => { + await loadDemosExtension(page, enableStakeSigning, supportedExtensions); if (wallet) { await importWallet(page, wallet); diff --git a/tests/govtool-frontend/playwright/lib/helpers/page.ts b/tests/govtool-frontend/playwright/lib/helpers/page.ts index 56dc3c348..276401b7e 100644 --- a/tests/govtool-frontend/playwright/lib/helpers/page.ts +++ b/tests/govtool-frontend/playwright/lib/helpers/page.ts @@ -1,24 +1,32 @@ +import { CardanoTestWallet } from "@cardanoapi/cardano-test-wallet/types"; import { importWallet } from "@fixtures/importWallet"; import loadDemosExtension from "@fixtures/loadExtension"; import { Browser, Page } from "@playwright/test"; import { StaticWallet } from "@types"; -interface BrowserConfig { - storageState: string; +interface NewPageConfig { + storageState?: string; wallet: StaticWallet; enableStakeSigning?: boolean; + supportedExtensions?: Record[]; } export async function createNewPageWithWallet( browser: Browser, - { storageState, wallet, enableStakeSigning }: BrowserConfig + newPageConfig: NewPageConfig ): Promise { + const { storageState, wallet, ...extensionConfig } = newPageConfig; + const context = await browser.newContext({ - storageState: storageState, + storageState, }); const newPage = await context.newPage(); - await loadDemosExtension(newPage, enableStakeSigning); + await loadDemosExtension( + newPage, + extensionConfig.enableStakeSigning, + extensionConfig.supportedExtensions + ); await importWallet(newPage, wallet); return newPage; diff --git a/tests/govtool-frontend/playwright/lib/types.ts b/tests/govtool-frontend/playwright/lib/types.ts index ea587206c..37e6fd9f5 100644 --- a/tests/govtool-frontend/playwright/lib/types.ts +++ b/tests/govtool-frontend/playwright/lib/types.ts @@ -1,6 +1,6 @@ -import { CardanoTestWallet } from "@cardanoapi/cardano-test-wallet/types"; +import { CardanoTestWalletJson } from "@cardanoapi/cardano-test-wallet/types"; -export type StaticWallet = CardanoTestWallet & { +export type StaticWallet = CardanoTestWalletJson & { dRepId: string; address: string; }; diff --git a/tests/govtool-frontend/playwright/package-lock.json b/tests/govtool-frontend/playwright/package-lock.json index 5af5d05e3..5771210af 100644 --- a/tests/govtool-frontend/playwright/package-lock.json +++ b/tests/govtool-frontend/playwright/package-lock.json @@ -9,7 +9,7 @@ "version": "1.0.0", "license": "MIT", "dependencies": { - "@cardanoapi/cardano-test-wallet": "^1.2.0", + "@cardanoapi/cardano-test-wallet": "^2.0.0", "@faker-js/faker": "^8.4.1", "@noble/curves": "^1.3.0", "@noble/ed25519": "^2.0.0", @@ -87,9 +87,9 @@ } }, "node_modules/@cardanoapi/cardano-test-wallet": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@cardanoapi/cardano-test-wallet/-/cardano-test-wallet-1.2.0.tgz", - "integrity": "sha512-5fuJIVWP2dOryqt95JRSn5kzG1MOmoVHw+KcV6WrvUGYfiAQIDarhcUBnjVEjxxqVxzHaKuI6OepL0w6QDZ3EA==" + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@cardanoapi/cardano-test-wallet/-/cardano-test-wallet-2.0.0.tgz", + "integrity": "sha512-/8n83MzYgZnPv6ODYBGGwgnl9FPT1DU9BXfXeIicJQNhtWbL+QQWVa3cAvTiY3so3BfH5IaLjSnkaQRP4tBiSA==" }, "node_modules/@cbor-extract/cbor-extract-linux-x64": { "version": "2.2.0", @@ -3347,9 +3347,9 @@ "dev": true }, "@cardanoapi/cardano-test-wallet": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@cardanoapi/cardano-test-wallet/-/cardano-test-wallet-1.2.0.tgz", - "integrity": "sha512-5fuJIVWP2dOryqt95JRSn5kzG1MOmoVHw+KcV6WrvUGYfiAQIDarhcUBnjVEjxxqVxzHaKuI6OepL0w6QDZ3EA==" + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@cardanoapi/cardano-test-wallet/-/cardano-test-wallet-2.0.0.tgz", + "integrity": "sha512-/8n83MzYgZnPv6ODYBGGwgnl9FPT1DU9BXfXeIicJQNhtWbL+QQWVa3cAvTiY3so3BfH5IaLjSnkaQRP4tBiSA==" }, "@cbor-extract/cbor-extract-linux-x64": { "version": "2.2.0", diff --git a/tests/govtool-frontend/playwright/package.json b/tests/govtool-frontend/playwright/package.json index a1089be00..a225ba91c 100644 --- a/tests/govtool-frontend/playwright/package.json +++ b/tests/govtool-frontend/playwright/package.json @@ -28,7 +28,7 @@ "generate-wallets": "ts-node ./generate_wallets.ts 11" }, "dependencies": { - "@cardanoapi/cardano-test-wallet": "^1.2.0", + "@cardanoapi/cardano-test-wallet": "^2.0.0", "@faker-js/faker": "^8.4.1", "@noble/curves": "^1.3.0", "@noble/ed25519": "^2.0.0", From aeff16ddcf3a9a76dc6b5a64f0dae132ede14b92 Mon Sep 17 00:00:00 2001 From: Nabin Kawan Date: Wed, 3 Jul 2024 13:11:57 +0545 Subject: [PATCH 2/2] fix: Test(1E) incompatible wallets --- .../tests/1-wallet-connect/walletConnect.spec.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/govtool-frontend/playwright/tests/1-wallet-connect/walletConnect.spec.ts b/tests/govtool-frontend/playwright/tests/1-wallet-connect/walletConnect.spec.ts index 5e0149494..1361de324 100644 --- a/tests/govtool-frontend/playwright/tests/1-wallet-connect/walletConnect.spec.ts +++ b/tests/govtool-frontend/playwright/tests/1-wallet-connect/walletConnect.spec.ts @@ -3,6 +3,7 @@ import { test } from "@fixtures/walletExtension"; import { setAllureEpic } from "@helpers/allure"; import convertBufferToHex from "@helpers/convertBufferToHex"; import { ShelleyWallet } from "@helpers/crypto"; +import { createNewPageWithWallet } from "@helpers/page"; import LoginPage from "@pages/loginPage"; import { expect } from "@playwright/test"; @@ -54,13 +55,16 @@ test("1D. Should reject wallet connection in mainnet", async ({ page }) => { }); test("1E. Should hide incompatible wallets when connecting", async ({ - page, + browser, }) => { - // Disabling cip95 support for wallet - await createWallet(page, { supportedExtensions: [] }); + const wallet = (await ShelleyWallet.generate()).json(); + const newPage = await createNewPageWithWallet(browser, { + wallet, + supportedExtensions: [], + }); - await page.goto("/"); - await page.getByTestId("connect-wallet-button").click(); + await newPage.goto("/"); + await newPage.getByTestId("connect-wallet-button").click(); - await expect(page.getByTestId("demos-wallet-button")).not.toBeVisible(); + await expect(newPage.getByTestId("demos-wallet-button")).not.toBeVisible(); });