Skip to content

Commit

Permalink
test(cat-voices): adding NuFi and Yoroi
Browse files Browse the repository at this point in the history
  • Loading branch information
emiride committed Dec 16, 2024
1 parent f20fea9 commit 04701d5
Show file tree
Hide file tree
Showing 12 changed files with 723 additions and 129 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ export class HomePage {
}

async getPublicDRepKey(): Promise<string> {
await this.page.waitForTimeout(2000);
const isVisible = await this.publicDRepKeyLabel.isVisible();
if (!isVisible) {
throw new Error("Public DRep Key label is not visible");
Expand Down Expand Up @@ -341,7 +342,7 @@ export class HomePage {
expect(actualWalletCipData.networkId).not.toBeNaN();
expect(actualWalletCipData.changeAddress).not.toBeNaN();
expect(actualWalletCipData.rewardAddresses.length).toBeGreaterThan(0);
expect(actualWalletCipData.unusedAddresses.length).toBeGreaterThan(0);
//expect(actualWalletCipData.unusedAddresses.length).toBeGreaterThan(0);
expect(actualWalletCipData.usedAddresses.length).toBeGreaterThan(0);
expect(actualWalletCipData.utxos.length).toBeGreaterThan(0);
expect(actualWalletCipData.publicDRepKey).not.toBeNaN();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { expect, Locator, Page } from "@playwright/test";

export enum ModalName {
SignData = 'SignData',
SignAndSubmitTx = 'SignAndSubmitTx',
SignAndSubmitRBACTx = 'SignAndSubmitRBACTx',
SignDataUserDeclined = 'UserDeclined',
SignTxUserDeclined = 'SignTxUserDeclined',
SignRBACTxUserDeclined = 'SignRBACTxUserDeclined',
SignData = "SignData",
SignAndSubmitTx = "SignAndSubmitTx",
SignAndSubmitRBACTx = "SignAndSubmitRBACTx",
SignDataUserDeclined = "UserDeclined",
SignTxUserDeclined = "SignTxUserDeclined",
SignRBACTxUserDeclined = "SignRBACTxUserDeclined",
}

export interface ModalContent {
Expand All @@ -16,28 +16,28 @@ export interface ModalContent {

export const modalContents: { [key in ModalName]: ModalContent } = {
[ModalName.SignData]: {
header: 'Sign data',
unchangingText: 'Signature:',
header: "Sign data",
unchangingText: "Signature:",
},
[ModalName.SignAndSubmitTx]: {
header: 'Sign & submit tx',
unchangingText: 'Tx hash:',
header: "Sign & submit tx",
unchangingText: "Tx hash:",
},
[ModalName.SignAndSubmitRBACTx]: {
header: 'Sign & submit RBAC tx',
unchangingText: 'Tx hash:',
header: "Sign & submit RBAC tx",
unchangingText: "Tx hash:",
},
[ModalName.SignDataUserDeclined]: {
header: 'Sign data',
unchangingText: 'user declined sign data',
header: "Sign data",
unchangingText: "WalletApiException",
},
[ModalName.SignTxUserDeclined]: {
header: 'Sign & submit tx',
unchangingText: 'user declined sign tx',
header: "Sign & submit tx",
unchangingText: "WalletApiException",
},
[ModalName.SignRBACTxUserDeclined]: {
header: 'Sign & submit RBAC tx',
unchangingText: 'user declined sign tx',
header: "Sign & submit RBAC tx",
unchangingText: "WalletApiException",
},
};

Expand All @@ -50,12 +50,15 @@ export class Modal {
constructor(page: Page, modalName: ModalName) {
this.page = page;
this.content = modalContents[modalName];
this.modalHeader = this.page.getByText(this.content.header, { exact: true });
this.modalBody = this.page.getByText(this.content.unchangingText)
this.modalHeader = this.page.getByText(this.content.header, {
exact: true,
});
this.modalBody = this.page.getByText(this.content.unchangingText);
}

async assertModalIsVisible() {
await this.page.waitForTimeout(2000);
await expect(this.modalHeader).toBeVisible();
await expect(this.modalBody).toBeVisible();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Locator, Page } from '@playwright/test';
import { BrowserExtensionName } from '../utils/extensions';

import { Page } from "@playwright/test";
import { BrowserExtensionName } from "../utils/extensions";

export class WalletListPage {
readonly page: Page;
Expand All @@ -9,10 +8,15 @@ export class WalletListPage {
this.page = page;
}
async clickEnableWallet(walletName: BrowserExtensionName): Promise<void> {
const enableButton = (walletName: BrowserExtensionName) => this.page.locator(
`flt-semantics:has(flt-semantics-img[aria-label*="Name: ${walletName.toLowerCase()}"]) ` +
`flt-semantics[role="button"]:has-text("Enable wallet")`
);
await enableButton(walletName).click();
if (walletName === BrowserExtensionName.Nufi) {
const [walletPopup] = await Promise.all([
this.page.context().waitForEvent("page"),
await this.page.locator('//*[text()="Enable wallet"]').first().click(),
]);
await walletPopup.locator("button:has-text('Connect')").click();
} else {
await this.page.locator('//*[text()="Enable wallet"]').first().click();
}
await this.page.waitForTimeout(2000);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@ export const enableWallet = async (
browser: BrowserContext
) => {
const page = browser.pages()[0];
await page.reload();
await page.goto("/");
await page.waitForTimeout(4000);
const [walletPopup] = await Promise.all([
browser.waitForEvent("page"),
page.locator('//*[text()="Enable wallet"]').click(),
page.locator('//*[text()="Enable wallet"]').first().click(),
]);
await walletPopup.waitForTimeout(2000);
await allowExtension(walletPopup, walletConfig.extension.Name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ walletConfigs.forEach((walletConfig) => {
walletConfig.extension.Name === "Typhon",
"https://github.com/input-output-hk/catalyst-voices/issues/753"
);
test.skip(
walletConfig.extension.Name === "Yoroi",
"https://github.com/input-output-hk/catalyst-voices/issues/753"
);
test.skip(
walletConfig.extension.Name === "Lace",
"https://github.com/input-output-hk/catalyst-voices/issues/1190"
Expand Down Expand Up @@ -40,11 +44,7 @@ walletConfigs.forEach((walletConfig) => {
walletConfig.extension.Name
);
const homePage = new HomePage(page);
const [walletPopup] = await Promise.all([
browser.waitForEvent("page"),
homePage.signDataButton.click(),
]);
await signWalletPopup(walletPopup, walletConfig);
await signWalletPopup(browser, walletConfig, homePage.signDataButton);
await homePage.assertModal(ModalName.SignData);
});

Expand All @@ -56,11 +56,11 @@ walletConfigs.forEach((walletConfig) => {
walletConfig.extension.Name
);
const homePage = new HomePage(page);
const [walletPopup] = await Promise.all([
browser.waitForEvent("page"),
homePage.signAndSubmitTxButton.click(),
]);
await signWalletPopup(walletPopup, walletConfig);
await signWalletPopup(
browser,
walletConfig,
homePage.signAndSubmitTxButton
);
await homePage.assertModal(ModalName.SignAndSubmitTx);
});

Expand All @@ -74,11 +74,11 @@ walletConfigs.forEach((walletConfig) => {
walletConfig.extension.Name
);
const homePage = new HomePage(page);
const [walletPopup] = await Promise.all([
browser.waitForEvent("page"),
homePage.signAndSubmitRBACTxButton.click(),
]);
await signWalletPopup(walletPopup, walletConfig);
await signWalletPopup(
browser,
walletConfig,
homePage.signAndSubmitRBACTxButton
);
await homePage.assertModal(ModalName.SignAndSubmitRBACTx);
}
);
Expand All @@ -94,13 +94,14 @@ walletConfigs.forEach((walletConfig) => {
walletConfig.extension.Name
);
const homePage = new HomePage(page);
const [walletPopup] = await Promise.all([
browser.waitForEvent("page"),
homePage.signDataButton.click(),
]);
const walletConfigClone = structuredClone(walletConfig);
walletConfigClone.password = "BadPassword";
await signWalletPopup(walletPopup, walletConfigClone, false);
await signWalletPopup(
browser,
walletConfigClone,
homePage.signDataButton,
false
);
await homePage.assertModal(ModalName.SignDataUserDeclined);
}
);
Expand All @@ -116,13 +117,14 @@ walletConfigs.forEach((walletConfig) => {
walletConfig.extension.Name
);
const homePage = new HomePage(page);
const [walletPopup] = await Promise.all([
browser.waitForEvent("page"),
homePage.signAndSubmitTxButton.click(),
]);
const walletConfigClone = structuredClone(walletConfig);
walletConfigClone.password = "BadPassword";
await signWalletPopup(walletPopup, walletConfigClone, false);
await signWalletPopup(
browser,
walletConfigClone,
homePage.signAndSubmitTxButton,
false
);
await homePage.assertModal(ModalName.SignTxUserDeclined);
}
);
Expand All @@ -138,13 +140,14 @@ walletConfigs.forEach((walletConfig) => {
walletConfig.extension.Name
);
const homePage = new HomePage(page);
const [walletPopup] = await Promise.all([
browser.waitForEvent("page"),
homePage.signAndSubmitRBACTxButton.click(),
]);
const walletConfigClone = structuredClone(walletConfig);
walletConfigClone.password = "BadPassword";
await signWalletPopup(walletPopup, walletConfigClone, false);
await signWalletPopup(
browser,
walletConfigClone,
homePage.signAndSubmitRBACTxButton,
false
);
await homePage.assertModal(ModalName.SignRBACTxUserDeclined);
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,43 @@ export class ExtensionDownloader {
}

// Download the extension
const crxPath = await this.downloadExtension(extensionName);

if (extensionName === BrowserExtensionName.Nufi) {
const zipPath = await this.downloadNufiExtension();
await this.extractExtension(zipPath, extensionPath);
} else {
const crxPath = await this.downloadExtension(extensionName);
await this.extractExtension(crxPath, extensionPath);
}
// Extract the extension
await this.extractExtension(crxPath, extensionPath);

return extensionPath;
}

private async downloadNufiExtension(): Promise<string> {
const url =
"https://assets.nu.fi/extension/testnet/nufi-cwe-testnet-latest.zip";
const filePath = path.join(
this.extensionsDir,
"nufi-cwe-testnet-latest.zip"
);

// Ensure the download directory exists
await fsPromises.mkdir(this.extensionsDir, { recursive: true });

// Fetch the extension
const res = await nodeFetch(url);
if (!res.ok) {
throw new Error(`Failed to download extension: ${res.statusText}`);
}

// Stream the response directly to a file
const fileStream = fs.createWriteStream(filePath);
await pipeline(res.body, fileStream);

console.log(`Extension has been downloaded to: ${filePath}`);
return filePath;
}

private async extractExtension(
extensionPath: string,
extractPath: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export enum BrowserExtensionName {
Lace = "Lace",
Typhon = "Typhon",
Eternl = "Eternl",
Yoroi = "Yoroi",
Nufi = "Nufi",
}
/* cspell: disable */
export const browserExtensions: BrowserExtension[] = [
Expand All @@ -26,6 +28,16 @@ export const browserExtensions: BrowserExtension[] = [
Id: "kmhcihpebfmpgmihbkipmjlmmioameka",
HomeUrl: "index.html#/app/preprod/welcome",
},
{
Name: BrowserExtensionName.Yoroi,
Id: "poonlenmfdfbjfeeballhiibknlknepo",
HomeUrl: "main_window.html#",
},
{
Name: BrowserExtensionName.Nufi,
Id: "hbklpdnlgiadjhdadfnfmemmklbopbcm",
HomeUrl: "/index.html#",
},
];
/* cspell: enable */

Expand Down
Loading

0 comments on commit 04701d5

Please sign in to comment.