Skip to content

Commit 30d2e5c

Browse files
authored
Merge pull request #3224 from IntersectMBO/tests/script-drep-conversion
Tests: script based dRep conversion
2 parents 9e524d3 + c62cf0d commit 30d2e5c

File tree

6 files changed

+100
-13
lines changed

6 files changed

+100
-13
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"page": 0,
3+
"pageSize": 10,
4+
"total": 1,
5+
"elements": [
6+
{
7+
"isScriptBased": true,
8+
"drepId": "429b12461640cefd3a4a192f7c531d8f6c6d33610b727f481eb22d39",
9+
"view": "drep1g2d3y3skgr806wj2ryhhc5ca3akx6vmppde87jq7kgknjmv589e",
10+
"url": null,
11+
"metadataHash": null,
12+
"deposit": 500000000,
13+
"votingPower": 83414740266257,
14+
"status": "Active",
15+
"type": "SoleVoter",
16+
"latestTxHash": "8de2a5f9074679de947549ea36c3980496503ffc40f0cbce5ce1ee3df66306e9",
17+
"latestRegistrationDate": "2024-11-20T01:59:20Z",
18+
"metadataError": null,
19+
"paymentAddress": null,
20+
"givenName": null,
21+
"objectives": null,
22+
"motivations": null,
23+
"qualifications": null,
24+
"imageUrl": null,
25+
"imageHash": null
26+
}
27+
]
28+
}

tests/govtool-frontend/playwright/lib/helpers/dRep.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,14 @@ export function tohex(drepId: string) {
8888
).toString("hex");
8989
}
9090

91-
export function convertDRepToCIP129(drepId: string, script = false): string {
91+
export function convertDRep(
92+
drepId: string,
93+
script = false
94+
): { cip129: string; cip105: string } {
9295
const hexPattern = /^[0-9a-fA-F]+$/;
9396
let cip129DRep: string;
9497
let cip129DrepHex: string;
98+
let cip105DRep: string;
9599
const prefix = script ? "23" : "22";
96100
const addPrefix = (hex: string) => {
97101
if (hex.length === 56) {
@@ -102,8 +106,8 @@ export function convertDRepToCIP129(drepId: string, script = false): string {
102106
throw new Error("Invalid DRep hex length");
103107
}
104108
};
105-
const drepIdFromHex = (hex: string) => {
106-
return fromHex("drep", hex);
109+
const drepIdFromHex = (prefix: string, hex: string) => {
110+
return fromHex(prefix, hex);
107111
};
108112
if (hexPattern.test(drepId)) {
109113
cip129DrepHex = addPrefix(drepId);
@@ -115,6 +119,10 @@ export function convertDRepToCIP129(drepId: string, script = false): string {
115119
throw new Error("Invalid DRep Bech32 format");
116120
}
117121
}
118-
cip129DRep = drepIdFromHex(cip129DrepHex);
119-
return cip129DRep;
122+
cip105DRep = drepIdFromHex(
123+
cip129DrepHex.slice(0, 2) == "22" ? "drep" : "drep_script",
124+
cip129DrepHex.slice(-56)
125+
);
126+
cip129DRep = drepIdFromHex("drep", cip129DrepHex);
127+
return { cip129: cip129DRep, cip105: cip105DRep };
120128
}

tests/govtool-frontend/playwright/lib/pages/dRepDirectoryPage.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { convertDRepToCIP129 } from "@helpers/dRep";
1+
import { convertDRep } from "@helpers/dRep";
22
import { functionWaitedAssert, waitedLoop } from "@helpers/waitedLoop";
33
import { Locator, Page, expect } from "@playwright/test";
44
import { IDRep } from "@types";
@@ -156,17 +156,21 @@ export default class DRepDirectoryPage {
156156
const cip105DRepListFE = await this.getAllListedCIP105DRepIds();
157157
const cip129DRepListFE = await this.getAllListedCIP129DRepIds();
158158

159-
const cip129DRepListApi = dRepList.map((dRep) =>
160-
convertDRepToCIP129(dRep.drepId, dRep.isScriptBased)
159+
const cip129DRepListApi = dRepList.map(
160+
(dRep) => convertDRep(dRep.drepId, dRep.isScriptBased).cip129
161+
);
162+
163+
const cip105DRepListApi = dRepList.map(
164+
(dRep) => convertDRep(dRep.drepId, dRep.isScriptBased).cip105
161165
);
162166

163167
for (let i = 0; i <= cip105DRepListFE.length - 1; i++) {
164168
await expect(cip129DRepListFE[i], {
165169
message: `Cip129 dRep Id from Api:${cip129DRepListApi[i]} is not equal to ${await cip129DRepListFE[i].textContent()} on sort ${option}`,
166170
}).toHaveText(cip129DRepListApi[i]);
167171
await expect(cip105DRepListFE[i], {
168-
message: `Cip105 dRep Id from Api:${dRepList[i].view} is not equal to ${await cip105DRepListFE[i].textContent()} on sort ${option}`,
169-
}).toHaveText(`(CIP-105) ${dRepList[i].view}`);
172+
message: `Cip105 dRep Id from Api:${cip105DRepListApi} is not equal to ${await cip105DRepListFE[i].textContent()} on sort ${option}`,
173+
}).toHaveText(`(CIP-105) ${cip105DRepListApi[i]}`);
170174
}
171175
},
172176
{ name: `frontend sort validation of ${option}` }

tests/govtool-frontend/playwright/lib/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ export enum FullGovernanceDRepVoteActionsType {
118118

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

121+
export interface PaginatedDRepResponse {
122+
page: number;
123+
pageSize: number;
124+
total: number;
125+
elements: IDRep[];
126+
}
127+
121128
export type IDRep = {
122129
isScriptBased: boolean;
123130
drepId: string;

tests/govtool-frontend/playwright/tests/2-delegation/delegation.spec.ts

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import environments from "@constants/environments";
22
import { setAllureEpic } from "@helpers/allure";
33
import { skipIfNotHardFork } from "@helpers/cardano";
4-
import { fetchFirstActiveDRepDetails } from "@helpers/dRep";
4+
import { convertDRep, fetchFirstActiveDRepDetails } from "@helpers/dRep";
55
import { functionWaitedAssert } from "@helpers/waitedLoop";
66
import DRepDetailsPage from "@pages/dRepDetailsPage";
77
import DRepDirectoryPage from "@pages/dRepDirectoryPage";
88
import { expect, Locator } from "@playwright/test";
99
import { test } from "@fixtures/walletExtension";
10-
import { DRepStatus, IDRep } from "@types";
10+
import { DRepStatus, IDRep, PaginatedDRepResponse } from "@types";
1111

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

30+
const scripDRepId: PaginatedDRepResponse = require("../../lib/_mock/scriptDRep.json");
31+
3032
test("2K_2. Should sort DReps", async ({ page }) => {
3133
test.slow();
3234

@@ -223,3 +225,41 @@ test.describe("DRep dependent tests", () => {
223225
expect(copiedTextDRepDirectory).toEqual(dRepId);
224226
});
225227
});
228+
229+
Object.values(["script drep", "drep"]).forEach((type, index) => {
230+
test(`2Y_${index + 1}. Should correctly convert CIP-129/CIP-105 ${type}`, async ({
231+
page,
232+
}) => {
233+
const dRepId = scripDRepId.elements[0]["drepId"];
234+
const dRepResponse = {
235+
...scripDRepId,
236+
elements: [{ ...scripDRepId.elements[0], isScriptBased: false }],
237+
};
238+
await page.route("**/drep/list?page=0&pageSize=10&**", async (route) => {
239+
await route.fulfill({
240+
status: 200,
241+
contentType: "application/json",
242+
body: JSON.stringify(type === "drep" ? dRepResponse : scripDRepId),
243+
});
244+
});
245+
246+
const responsePromise = page.waitForResponse(
247+
"**/drep/list?page=0&pageSize=10&**"
248+
);
249+
250+
const { cip129, cip105 } = convertDRep(
251+
dRepId,
252+
type === "drep" ? false : true
253+
);
254+
255+
await page.goto(`/drep_directory/${dRepId}`);
256+
await responsePromise;
257+
258+
await expect(
259+
page.getByTestId("cip-129-drep-id-info-item-description")
260+
).toHaveText(cip129, { timeout: 60_000 });
261+
await expect(
262+
page.getByTestId("cip-105-drep-id-info-item-description")
263+
).toHaveText(cip105);
264+
});
265+
});

tests/govtool-frontend/playwright/tests/5-proposal-functionality/proposalFunctionality.dRep.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ test.describe("Perform voting", () => {
264264
window.scrollTo(0, 500)
265265
);
266266
await expect(
267-
govActionDetailsPage.currentPage.getByTestId("my-vote").getByText("No"),
267+
govActionDetailsPage.currentPage.getByTestId("my-vote").getByText("Yes"),
268268
{
269269
message:
270270
!isYesVoteVisible &&

0 commit comments

Comments
 (0)