Skip to content

Commit 376c95e

Browse files
authored
Merge pull request #3152 from IntersectMBO/tests/invalid-metadata
Add proposal metadata error behaviour test for both live voting and outcomes
2 parents cf25453 + bb9c693 commit 376c95e

File tree

5 files changed

+152
-2
lines changed

5 files changed

+152
-2
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
[
2+
{
3+
"id": "320",
4+
"tx_hash": "833382b22ebd07bb7dee60001cfdce78ede3b8397b1027daeb7996f61c072bde",
5+
"index": "0",
6+
"type": "InfoAction",
7+
"description": {
8+
"data": {
9+
"tag": "InfoAction"
10+
}
11+
},
12+
"expiry_date": "2025-02-27T00:01:04.000Z",
13+
"expiration": 856,
14+
"time": "2025-01-27T16:15:21.000Z",
15+
"epoch_no": 825,
16+
"url": "https://bit.ly/3zCH2HL",
17+
"data_hash": "99a19b124ceb89bbd92354e8d11f913d1aec7280ce19ac4c1c6cc72f0ea91884",
18+
"proposal_params": null,
19+
"title": null,
20+
"abstract": null,
21+
"motivation": null,
22+
"rationale": null,
23+
"yes_votes": "0",
24+
"no_votes": "14333625476330",
25+
"abstain_votes": "0",
26+
"pool_yes_votes": "0",
27+
"pool_no_votes": "0",
28+
"pool_abstain_votes": "0",
29+
"cc_yes_votes": "0",
30+
"cc_no_votes": "0",
31+
"cc_abstain_votes": "0",
32+
"prev_gov_action_index": null,
33+
"prev_gov_action_tx_hash": null,
34+
"status": {
35+
"ratified_epoch": null,
36+
"enacted_epoch": null,
37+
"dropped_epoch": 857,
38+
"expired_epoch": 856
39+
}
40+
}
41+
]

tests/govtool-frontend/playwright/lib/constants/index.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { faker } from "@faker-js/faker";
2+
import { InvalidMetadataType } from "@types";
3+
14
export const SECURITY_RELEVANT_PARAMS_MAP: Record<string, string> = {
25
maxBlockBodySize: "max_block_size",
36
maxTxSize: "max_tx_size",
@@ -31,3 +34,30 @@ export const outcomeStatusType = [
3134
"Enacted",
3235
"Live",
3336
];
37+
38+
export const InvalidMetadata: InvalidMetadataType[] = [
39+
{
40+
type: "Data Formatted Incorrectly",
41+
reason: "hash is valid but incorrect metadata format.",
42+
url: "https://metadata-govtool.cardanoapi.io/data/Lolita",
43+
hash: "62a37df07103f0a69690c8975700e06b7c3c3069cb3d105abec00e820e831dda",
44+
},
45+
{
46+
type: "Data Missing",
47+
reason: "metadata URL could not be found.",
48+
url: faker.internet.url() + "/test.jsonld",
49+
hash: "99a19b124ceb89bbd92354e8d11f913d1aec7280ce19ac4c1c6cc72f0ea91884",
50+
},
51+
{
52+
type: "Data Not Verifiable",
53+
reason: "metadata hash and URL do not match.",
54+
url: "https://metadata-govtool.cardanoapi.io/data/data.jsonld",
55+
hash: "e71bf6171adda3754a87fff5c2d8d9e404eb3366428a5be13f7e76357a39004f",
56+
},
57+
{
58+
type: "Data Not Verifiable",
59+
reason: "metadata hash and URL do not match and is incorrect ga format",
60+
url: "https://metadata-govtool.cardanoapi.io/data/Lolita",
61+
hash: "e71bf6171adda3754a87fff5c2d8d9e404eb3366428a5be13f7e76357a39004f",
62+
},
63+
];

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ export type KuberValue = {
99
[policyId: string]: Record<string, BigInt | number> | BigInt | number;
1010
};
1111

12+
export interface PaginatedLiveProposal {
13+
page: number;
14+
pageSize: number;
15+
total: number;
16+
elements: IProposal[];
17+
}
18+
1219
export interface IProposal {
1320
id: string;
1421
txHash: string;
@@ -302,3 +309,10 @@ interface outcomeMetadataBody {
302309
rationale: string;
303310
title: string;
304311
}
312+
313+
export interface InvalidMetadataType {
314+
type: string;
315+
reason: string;
316+
url: string;
317+
hash: string;
318+
}

tests/govtool-frontend/playwright/tests/4-proposal-visibility/proposalVisibility.spec.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,19 @@ import GovernanceActionDetailsPage from "@pages/governanceActionDetailsPage";
1010
import GovernanceActionsPage from "@pages/governanceActionsPage";
1111
import { expect } from "@playwright/test";
1212
import { test } from "@fixtures/walletExtension";
13-
import { GovernanceActionType, IProposal } from "@types";
13+
import { GovernanceActionType, IProposal, PaginatedLiveProposal } from "@types";
1414
import { injectLogger } from "@helpers/page";
1515
import removeAllSpaces from "@helpers/removeAllSpaces";
1616
import { functionWaitedAssert } from "@helpers/waitedLoop";
1717
import extractExpiryDateFromText from "@helpers/extractExpiryDateFromText";
18+
import { InvalidMetadata } from "@constants/index";
1819

1920
test.beforeEach(async () => {
2021
await setAllureEpic("4. Proposal visibility");
2122
await skipIfNotHardFork();
2223
});
2324

24-
const infoTypeProposal = require("../../lib/_mock/infoTypeProposal.json");
25+
const infoTypeProposal: PaginatedLiveProposal = require("../../lib/_mock/infoTypeProposal.json");
2526

2627
const filterOptionNames = [
2728
"Protocol Parameter Change",
@@ -298,3 +299,37 @@ test("4K. Should display correct vote counts on governance details page for disc
298299
})
299300
);
300301
});
302+
303+
test.describe("Invalid Live voting Metadata", () => {
304+
InvalidMetadata.forEach(({ type, reason, url, hash }, index) => {
305+
test(`4P_${index + 1}: Should display ${type} message in live voting when ${reason}`, async ({
306+
page,
307+
}) => {
308+
const proposal: IProposal = {
309+
...infoTypeProposal.elements[0],
310+
url,
311+
metadataHash: hash,
312+
};
313+
const liveProposalResponse: PaginatedLiveProposal = {
314+
...infoTypeProposal,
315+
elements: [proposal],
316+
};
317+
318+
await page.route("**/proposal/list?**", async (route) =>
319+
route.fulfill({
320+
body: JSON.stringify(liveProposalResponse),
321+
})
322+
);
323+
324+
const governanceActionPage = new GovernanceActionsPage(page);
325+
await governanceActionPage.goto();
326+
await governanceActionPage.viewFirstProposal();
327+
328+
await expect(page.getByRole("heading", { name: type })).toBeVisible({
329+
timeout: 60_000,
330+
});
331+
await expect(page.getByText("Learn more")).toBeVisible();
332+
await expect(page.getByTestId("external-modal-button")).toBeVisible();
333+
});
334+
});
335+
});

tests/govtool-frontend/playwright/tests/9-outcomes/outcomes.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { InvalidMetadata } from "@constants/index";
12
import { test } from "@fixtures/walletExtension";
23
import { correctVoteAdaFormat } from "@helpers/adaFormat";
34
import { setAllureEpic } from "@helpers/allure";
@@ -15,6 +16,8 @@ import OutComesPage from "@pages/outcomesPage";
1516
import { expect, Page } from "@playwright/test";
1617
import { outcomeMetadata, outcomeProposal, outcomeType } from "@types";
1718

19+
const invalidOutcomeProposals = require("../../lib/_mock/outcome.json");
20+
1821
test.beforeEach(async () => {
1922
await setAllureEpic("9. Outcomes");
2023
await skipIfNotHardFork();
@@ -413,3 +416,30 @@ test("9G. Should display correct vote counts on outcome details page", async ({
413416
})
414417
);
415418
});
419+
420+
test.describe("Invalid Outcome Metadata", () => {
421+
InvalidMetadata.forEach(({ type, reason, url, hash }, index) => {
422+
test(`9H_${index + 1}: Should display "${type}" message in outcomes when ${reason}`, async ({
423+
page,
424+
}) => {
425+
const outcomeResponse = {
426+
...invalidOutcomeProposals[0],
427+
url,
428+
data_hash: hash,
429+
};
430+
431+
await page.route(/.*\/governance-actions\/[a-f0-9]{64}\?.*/, (route) =>
432+
route.fulfill({ body: JSON.stringify([outcomeResponse]) })
433+
);
434+
435+
const outcomePage = new OutComesPage(page);
436+
await outcomePage.goto();
437+
await outcomePage.viewFirstOutcomes();
438+
439+
await expect(page.getByRole("heading", { name: type })).toBeVisible({
440+
timeout: 60_000,
441+
});
442+
await expect(page.getByText("Learn more")).toBeVisible();
443+
});
444+
});
445+
});

0 commit comments

Comments
 (0)