Skip to content
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
28 changes: 28 additions & 0 deletions tests/govtool-frontend/playwright/lib/_mock/scriptDRep.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"page": 0,
"pageSize": 10,
"total": 1,
"elements": [
{
"isScriptBased": true,
"drepId": "429b12461640cefd3a4a192f7c531d8f6c6d33610b727f481eb22d39",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have similar test for keyDrep? If not let's add it too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can review this update -https://github.com/IntersectMBO/govtool/pull/3224/files#:~:text=.isScriptBased)-,const%20cip129DRepListApi%20%3D%20dRepList.map(,)%3B,-for%20(let. This is the only test where the conversion of a dRep takes place, whether it's script-based or a normal dRep.

"view": "drep1g2d3y3skgr806wj2ryhhc5ca3akx6vmppde87jq7kgknjmv589e",
"url": null,
"metadataHash": null,
"deposit": 500000000,
"votingPower": 83414740266257,
"status": "Active",
"type": "SoleVoter",
"latestTxHash": "8de2a5f9074679de947549ea36c3980496503ffc40f0cbce5ce1ee3df66306e9",
"latestRegistrationDate": "2024-11-20T01:59:20Z",
"metadataError": null,
"paymentAddress": null,
"givenName": null,
"objectives": null,
"motivations": null,
"qualifications": null,
"imageUrl": null,
"imageHash": null
}
]
}
18 changes: 13 additions & 5 deletions tests/govtool-frontend/playwright/lib/helpers/dRep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,14 @@ export function tohex(drepId: string) {
).toString("hex");
}

export function convertDRepToCIP129(drepId: string, script = false): string {
export function convertDRep(
drepId: string,
script = false
): { cip129: string; cip105: string } {
const hexPattern = /^[0-9a-fA-F]+$/;
let cip129DRep: string;
let cip129DrepHex: string;
let cip105DRep: string;
const prefix = script ? "23" : "22";
const addPrefix = (hex: string) => {
if (hex.length === 56) {
Expand All @@ -102,8 +106,8 @@ export function convertDRepToCIP129(drepId: string, script = false): string {
throw new Error("Invalid DRep hex length");
}
};
const drepIdFromHex = (hex: string) => {
return fromHex("drep", hex);
const drepIdFromHex = (prefix: string, hex: string) => {
return fromHex(prefix, hex);
};
if (hexPattern.test(drepId)) {
cip129DrepHex = addPrefix(drepId);
Expand All @@ -115,6 +119,10 @@ export function convertDRepToCIP129(drepId: string, script = false): string {
throw new Error("Invalid DRep Bech32 format");
}
}
cip129DRep = drepIdFromHex(cip129DrepHex);
return cip129DRep;
cip105DRep = drepIdFromHex(
cip129DrepHex.slice(0, 2) == "22" ? "drep" : "drep_script",
cip129DrepHex.slice(-56)
);
cip129DRep = drepIdFromHex("drep", cip129DrepHex);
return { cip129: cip129DRep, cip105: cip105DRep };
}
14 changes: 9 additions & 5 deletions tests/govtool-frontend/playwright/lib/pages/dRepDirectoryPage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { convertDRepToCIP129 } from "@helpers/dRep";
import { convertDRep } from "@helpers/dRep";
import { functionWaitedAssert, waitedLoop } from "@helpers/waitedLoop";
import { Locator, Page, expect } from "@playwright/test";
import { IDRep } from "@types";
Expand Down Expand Up @@ -156,17 +156,21 @@ export default class DRepDirectoryPage {
const cip105DRepListFE = await this.getAllListedCIP105DRepIds();
const cip129DRepListFE = await this.getAllListedCIP129DRepIds();

const cip129DRepListApi = dRepList.map((dRep) =>
convertDRepToCIP129(dRep.drepId, dRep.isScriptBased)
const cip129DRepListApi = dRepList.map(
(dRep) => convertDRep(dRep.drepId, dRep.isScriptBased).cip129
);

const cip105DRepListApi = dRepList.map(
(dRep) => convertDRep(dRep.drepId, dRep.isScriptBased).cip105
);

for (let i = 0; i <= cip105DRepListFE.length - 1; i++) {
await expect(cip129DRepListFE[i], {
message: `Cip129 dRep Id from Api:${cip129DRepListApi[i]} is not equal to ${await cip129DRepListFE[i].textContent()} on sort ${option}`,
}).toHaveText(cip129DRepListApi[i]);
await expect(cip105DRepListFE[i], {
message: `Cip105 dRep Id from Api:${dRepList[i].view} is not equal to ${await cip105DRepListFE[i].textContent()} on sort ${option}`,
}).toHaveText(`(CIP-105) ${dRepList[i].view}`);
message: `Cip105 dRep Id from Api:${cip105DRepListApi} is not equal to ${await cip105DRepListFE[i].textContent()} on sort ${option}`,
}).toHaveText(`(CIP-105) ${cip105DRepListApi[i]}`);
}
},
{ name: `frontend sort validation of ${option}` }
Expand Down
7 changes: 7 additions & 0 deletions tests/govtool-frontend/playwright/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ export enum FullGovernanceDRepVoteActionsType {

export type DRepStatus = "Active" | "Inactive" | "Retired";

export interface PaginatedDRepResponse {
page: number;
pageSize: number;
total: number;
elements: IDRep[];
}

export type IDRep = {
isScriptBased: boolean;
drepId: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import environments from "@constants/environments";
import { setAllureEpic } from "@helpers/allure";
import { skipIfNotHardFork } from "@helpers/cardano";
import { fetchFirstActiveDRepDetails } from "@helpers/dRep";
import { convertDRep, fetchFirstActiveDRepDetails } from "@helpers/dRep";
import { functionWaitedAssert } from "@helpers/waitedLoop";
import DRepDetailsPage from "@pages/dRepDetailsPage";
import DRepDirectoryPage from "@pages/dRepDirectoryPage";
import { expect, Locator } from "@playwright/test";
import { test } from "@fixtures/walletExtension";
import { DRepStatus, IDRep } from "@types";
import { DRepStatus, IDRep, PaginatedDRepResponse } from "@types";

test.beforeEach(async () => {
await setAllureEpic("2. Delegation");
Expand All @@ -27,6 +27,8 @@ const statusRank: Record<DRepStatus, number> = {
Retired: 3,
};

const scripDRepId: PaginatedDRepResponse = require("../../lib/_mock/scriptDRep.json");

test("2K_2. Should sort DReps", async ({ page }) => {
test.slow();

Expand Down Expand Up @@ -223,3 +225,41 @@ test.describe("DRep dependent tests", () => {
expect(copiedTextDRepDirectory).toEqual(dRepId);
});
});

Object.values(["script drep", "drep"]).forEach((type, index) => {
test(`2Y_${index + 1}. Should correctly convert CIP-129/CIP-105 ${type}`, async ({
page,
}) => {
const dRepId = scripDRepId.elements[0]["drepId"];
const dRepResponse = {
...scripDRepId,
elements: [{ ...scripDRepId.elements[0], isScriptBased: false }],
};
await page.route("**/drep/list?page=0&pageSize=10&**", async (route) => {
await route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify(type === "drep" ? dRepResponse : scripDRepId),
});
});

const responsePromise = page.waitForResponse(
"**/drep/list?page=0&pageSize=10&**"
);

const { cip129, cip105 } = convertDRep(
dRepId,
type === "drep" ? false : true
);

await page.goto(`/drep_directory/${dRepId}`);
await responsePromise;

await expect(
page.getByTestId("cip-129-drep-id-info-item-description")
).toHaveText(cip129, { timeout: 60_000 });
await expect(
page.getByTestId("cip-105-drep-id-info-item-description")
).toHaveText(cip105);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ test.describe("Perform voting", () => {
window.scrollTo(0, 500)
);
await expect(
govActionDetailsPage.currentPage.getByTestId("my-vote").getByText("No"),
govActionDetailsPage.currentPage.getByTestId("my-vote").getByText("Yes"),
{
message:
!isYesVoteVisible &&
Expand Down