Skip to content

Commit

Permalink
Merge pull request #2402 from IntersectMBO/tests/assert-govActionId
Browse files Browse the repository at this point in the history
Assert CIP129 and govActionId on governance action details page
  • Loading branch information
kneerose authored Nov 27, 2024
2 parents 5bffdc7 + 3e12546 commit dd92daa
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 9 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { blake2bHex } from "blakejs";
import { cborxDecoder, cborxEncoder } from "./cborEncodeDecode";
import { cborxDecoder, cborxEncoder } from "./encodeDecode";

export default function computeTxHash(tx: string) {
let decodedTx = cborxDecoder.decode(Buffer.from(tx, "hex"));
Expand Down
22 changes: 22 additions & 0 deletions tests/govtool-frontend/playwright/lib/helpers/encodeDecode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { bech32 } from "bech32";
import { Decoder, Encoder } from "cbor-x";

export const cborxEncoder = new Encoder({
mapsAsObjects: false,
useRecords: false,
});
export const cborxDecoder = new Decoder({ mapsAsObjects: false });

export const encodeCIP129Identifier = ({
txID,
index,
bech32Prefix,
}: {
txID: string;
index?: string;
bech32Prefix: string;
}) => {
const govActionBytes = Buffer.from(index ? txID + index : txID, "hex");
const words = bech32.toWords(govActionBytes);
return bech32.encode(bech32Prefix, words);
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as blake from "blakejs";
import environments from "lib/constants/environments";
import { LockInterceptor, LockInterceptorInfo } from "lib/lockInterceptor";
import fetch, { BodyInit, RequestInit } from "node-fetch";
import { cborxDecoder, cborxEncoder } from "../helpers/cborEncodeDecode";
import { cborxDecoder, cborxEncoder } from "../helpers/encodeDecode";
import { Logger } from "@helpers/logger";

type CertificateType = "registerstake" | "registerdrep" | "deregisterdrep";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { faker } from "@faker-js/faker";
import { test } from "@fixtures/walletExtension";
import { setAllureEpic } from "@helpers/allure";
import { isBootStrapingPhase, skipIfNotHardFork } from "@helpers/cardano";
import { encodeCIP129Identifier } from "@helpers/encodeDecode";
import { createNewPageWithWallet } from "@helpers/page";
import { waitForTxConfirmation } from "@helpers/transaction";
import GovernanceActionDetailsPage from "@pages/governanceActionDetailsPage";
Expand All @@ -25,11 +26,13 @@ test.describe("Proposal checks", () => {
test.use({ storageState: ".auth/dRep01.json", wallet: dRep01Wallet });

let govActionDetailsPage: GovernanceActionDetailsPage;
let currentPage: Page;

test.beforeEach(async ({ page }) => {
const govActionsPage = new GovernanceActionsPage(page);
await govActionsPage.goto();

currentPage = page;
govActionDetailsPage = (await isBootStrapingPhase())
? await govActionsPage.viewFirstProposalByGovernanceAction(
GrovernanceActionType.InfoAction
Expand All @@ -38,9 +41,27 @@ test.describe("Proposal checks", () => {
});

test("5A. Should show relevant details about governance action as DRep", async () => {
const governanceActionIdWithIndex = currentPage.url().split("/").pop();
const governanceActionId = governanceActionIdWithIndex.substring(0, 64);

const cip129GovActionId = encodeCIP129Identifier({
txID: governanceActionId,
index: governanceActionIdWithIndex
.replace(`${governanceActionId}#`, "")
.toString()
.padStart(2, "0"),
bech32Prefix: "gov_action",
});

await expect(govActionDetailsPage.governanceActionType).toBeVisible();
await expect(govActionDetailsPage.submittedDate).toBeVisible();
await expect(govActionDetailsPage.expiryDate).toBeVisible();
await expect(
currentPage.getByTestId(`${governanceActionIdWithIndex}-id`)
).toBeVisible();
await expect(
currentPage.getByTestId(`${cip129GovActionId}-id`)
).toBeVisible();

await expect(govActionDetailsPage.contextBtn).toBeVisible();
await expect(govActionDetailsPage.showVotesBtn).toBeVisible();
Expand Down

0 comments on commit dd92daa

Please sign in to comment.