diff --git a/tests/govtool-frontend/playwright/lib/helpers/dRep.ts b/tests/govtool-frontend/playwright/lib/helpers/dRep.ts index eab856f71..2304c5188 100644 --- a/tests/govtool-frontend/playwright/lib/helpers/dRep.ts +++ b/tests/govtool-frontend/playwright/lib/helpers/dRep.ts @@ -1,5 +1,6 @@ import DRepDirectoryPage from "@pages/dRepDirectoryPage"; import { Page } from "@playwright/test"; +import { bech32 } from "bech32"; export async function fetchFirstActiveDRepDetails(page: Page) { let dRepGivenName: string; @@ -60,3 +61,44 @@ export async function calculateImageSHA256(imageUrl: string) { return null; } } + +export function fromHex(prefix: string, hex: string) { + return bech32.encode(prefix, bech32.toWords(Buffer.from(hex, "hex"))); +} + +export function tohex(drepId: string) { + return Buffer.from( + bech32.fromWords(bech32.decode(drepId, 100).words) + ).toString("hex"); +} + +export function convertDRepToCIP129(drepId: string, script = false): string { + const hexPattern = /^[0-9a-fA-F]+$/; + let cip129DRep: string; + let cip129DrepHex: string; + const prefix = script ? "23" : "22"; + const addPrefix = (hex: string) => { + if (hex.length === 56) { + return prefix + hex; + } else if (hex.length === 58) { + return hex; + } else { + throw new Error("Invalid DRep hex length"); + } + }; + const drepIdFromHex = (hex: string) => { + return fromHex("drep", hex); + }; + if (hexPattern.test(drepId)) { + cip129DrepHex = addPrefix(drepId); + } else { + try { + const decodedHex = tohex(drepId); + cip129DrepHex = addPrefix(decodedHex); + } catch (error: any) { + throw new Error("Invalid DRep Bech32 format"); + } + } + cip129DRep = drepIdFromHex(cip129DrepHex); + return cip129DRep; +} diff --git a/tests/govtool-frontend/playwright/lib/pages/dRepDirectoryPage.ts b/tests/govtool-frontend/playwright/lib/pages/dRepDirectoryPage.ts index 535f55a52..6fba05584 100644 --- a/tests/govtool-frontend/playwright/lib/pages/dRepDirectoryPage.ts +++ b/tests/govtool-frontend/playwright/lib/pages/dRepDirectoryPage.ts @@ -1,3 +1,4 @@ +import { convertDRepToCIP129 } from "@helpers/dRep"; import { Locator, Page, expect } from "@playwright/test"; import { IDRep } from "@types"; import environments from "lib/constants/environments"; @@ -127,23 +128,42 @@ export default class DRepDirectoryPage { } // Frontend validation - const dRepListFE = await this.getAllListedDRepIds(); + const cip105DRepListFE = await this.getAllListedCIP105DRepIds(); + const cip129DRepListFE = await this.getAllListedCIP129DRepIds(); - for (let i = 0; i <= dRepListFE.length - 1; i++) { - await expect(dRepListFE[i]).toHaveText(dRepList[i].view); + const cip129DRepListApi = dRepList.map((dRep) => + convertDRepToCIP129(dRep.drepId, dRep.isScriptBased) + ); + + for (let i = 0; i <= cip105DRepListFE.length - 1; i++) { + await expect(cip105DRepListFE[i]).toHaveText(dRepList[i].view); + await expect(cip129DRepListFE[i]).toHaveText( + `(CIP-129) ${cip129DRepListApi[i]}` + ); } } getDRepCard(dRepId: string) { return this.page.getByTestId(`${dRepId}-drep-card`); } - async getAllListedDRepIds() { + async getAllListedCIP105DRepIds() { await this.page.waitForTimeout(2_000); - return await this.page - .getByRole("list") - .locator('[data-testid$="-copy-id-button"]') - .all(); + const dRepCards = await this.getAllListedDReps(); + + return dRepCards.map((dRep) => + dRep.locator('[data-testid$="-copy-id-button"]').first() + ); + } + + async getAllListedCIP129DRepIds() { + await this.page.waitForTimeout(2_000); + + const dRepCards = await this.getAllListedDReps(); + + return dRepCards.map((dRep) => + dRep.locator('[data-testid$="-copy-id-button"]').last() + ); } async getAllListedDReps() { diff --git a/tests/govtool-frontend/playwright/lib/types.ts b/tests/govtool-frontend/playwright/lib/types.ts index ed1c6b8bf..434971811 100644 --- a/tests/govtool-frontend/playwright/lib/types.ts +++ b/tests/govtool-frontend/playwright/lib/types.ts @@ -100,6 +100,7 @@ export enum FullGovernanceDRepVoteActionsType { export type DRepStatus = "Active" | "Inactive" | "Retired"; export type IDRep = { + isScriptBased: boolean; drepId: string; view: string; url: string; diff --git a/tests/govtool-frontend/playwright/tests/2-delegation/delegation.spec.ts b/tests/govtool-frontend/playwright/tests/2-delegation/delegation.spec.ts index ddd37c318..ec62b3ad1 100644 --- a/tests/govtool-frontend/playwright/tests/2-delegation/delegation.spec.ts +++ b/tests/govtool-frontend/playwright/tests/2-delegation/delegation.spec.ts @@ -84,10 +84,10 @@ test("2O. Should load more DReps on show more", async ({ page }) => { const dRepDirectory = new DRepDirectoryPage(page); await dRepDirectory.goto(); - const dRepIdsBefore = await dRepDirectory.getAllListedDRepIds(); + const dRepIdsBefore = await dRepDirectory.getAllListedCIP105DRepIds(); await dRepDirectory.showMoreBtn.click(); - const dRepIdsAfter = await dRepDirectory.getAllListedDRepIds(); + const dRepIdsAfter = await dRepDirectory.getAllListedCIP105DRepIds(); expect(dRepIdsAfter.length).toBeGreaterThanOrEqual(dRepIdsBefore.length); if (dRepIdsAfter.length > dRepIdsBefore.length) { diff --git a/tests/govtool-frontend/playwright/tests/4-proposal-visibility/proposalVisibility.loggedin.spec.ts b/tests/govtool-frontend/playwright/tests/4-proposal-visibility/proposalVisibility.loggedin.spec.ts index bf80f2929..cfcb6a675 100644 --- a/tests/govtool-frontend/playwright/tests/4-proposal-visibility/proposalVisibility.loggedin.spec.ts +++ b/tests/govtool-frontend/playwright/tests/4-proposal-visibility/proposalVisibility.loggedin.spec.ts @@ -131,15 +131,15 @@ test("4C_3. Should filter and sort Governance Action Type on governance actions }); test("4L. Should search governance actions", async ({ page }) => { - let governanceActionTitle = "TreasuryTitle"; + let governanceActionId: string; await page.route("**/proposal/list?**", async (route) => { const response = await route.fetch(); const data = await response.json(); - const elementsWithTitle = data["elements"].filter( - (element) => element["title"] + const elementsWithIds = data["elements"].map( + (element) => element["txHash"] + "#" + element["index"] ); - if (elementsWithTitle.length !== 0) { - governanceActionTitle = elementsWithTitle[0]["title"]; + if (elementsWithIds.length !== 0) { + governanceActionId = elementsWithIds[0]; } await route.fulfill({ status: 200, @@ -154,14 +154,14 @@ test("4L. Should search governance actions", async ({ page }) => { await responsePromise; - await governanceActionPage.searchInput.fill(governanceActionTitle); + await governanceActionPage.searchInput.fill(governanceActionId); const proposalCards = await governanceActionPage.getAllProposals(); for (const proposalCard of proposalCards) { - expect( - (await proposalCard.textContent()).includes(`${governanceActionTitle}`) - ).toBeTruthy(); + await expect( + proposalCard.getByTestId(`${governanceActionId}-id`) + ).toBeVisible(); } });