Skip to content

Commit a6ca482

Browse files
committed
chore: change convertDRepToCIP129 to convertDRep and use for both conversion
1 parent d84a986 commit a6ca482

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

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}` }

0 commit comments

Comments
 (0)