Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test 1E: Incompatible wallets #1459

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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();
});