Skip to content

Commit

Permalink
Merge pull request #1459 from IntersectMBO/bugfix/test-icompatible-wa…
Browse files Browse the repository at this point in the history
…llets

Fix test 1E: Incompatible wallets
  • Loading branch information
NabinKawan authored Jul 3, 2024
2 parents e4eae0b + aeff16d commit 48d871c
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
CardanoTestWallet,
CardanoTestWalletConfig,
CardanoTestWalletJson,
} from "@cardanoapi/cardano-test-wallet/types";
import { ShelleyWallet } from "@helpers/crypto";
import { Page } from "@playwright/test";
Expand All @@ -12,7 +13,7 @@ export default async function createWallet(
const wallet = (await ShelleyWallet.generate()).json();

const initScriptArgs: {
wallet: CardanoTestWallet;
wallet: CardanoTestWalletJson;
config: CardanoTestWalletConfig;
} = {
wallet,
Expand All @@ -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);
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down
24 changes: 16 additions & 8 deletions tests/govtool-frontend/playwright/lib/fixtures/loadExtension.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
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";

import path = require("path");

export default async function loadDemosExtension(
page: Page,
enableStakeSigning = false
enableStakeSigning?: boolean,
supportedExtensions?: Record<string, number>[]
) {
const demosBundleScriptPath = path.resolve(
__dirname,
Expand All @@ -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 });
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@ import loadDemosExtension from "./loadExtension";
type WalletExtensionTestOptions = {
wallet?: StaticWallet;
enableStakeSigning: boolean;
supportedExtensions: Record<string, number>[];
};

export const test = base.extend<WalletExtensionTestOptions>({
wallet: [null, { option: true }],

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);
Expand Down
18 changes: 13 additions & 5 deletions tests/govtool-frontend/playwright/lib/helpers/page.ts
Original file line number Diff line number Diff line change
@@ -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<string, number>[];
}

export async function createNewPageWithWallet(
browser: Browser,
{ storageState, wallet, enableStakeSigning }: BrowserConfig
newPageConfig: NewPageConfig
): Promise<Page> {
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;
Expand Down
4 changes: 2 additions & 2 deletions tests/govtool-frontend/playwright/lib/types.ts
Original file line number Diff line number Diff line change
@@ -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;
};
Expand Down
14 changes: 7 additions & 7 deletions tests/govtool-frontend/playwright/package-lock.json

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

2 changes: 1 addition & 1 deletion tests/govtool-frontend/playwright/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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();
});

0 comments on commit 48d871c

Please sign in to comment.