Skip to content

Commit 16be6c9

Browse files
authored
Merge pull request #2970 from IntersectMBO/tests/constitution-type-proposal
Tests: constitution type proposal
2 parents 624e32c + 96fcaf8 commit 16be6c9

File tree

13 files changed

+248
-37
lines changed

13 files changed

+248
-37
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ export const invalid = {
8080
return " ";
8181
},
8282

83+
constitutionUrl: () => {
84+
const choice = faker.number.int({ min: 1, max: 2 });
85+
if (choice === 1) {
86+
return invalid.url();
87+
}
88+
// empty invalid
89+
return " ";
90+
},
91+
8392
paragraph: (maxCharacter: number) => {
8493
const choice = faker.number.int({ min: 1, max: 2 });
8594
if (choice === 1) {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,12 @@ export const SECURITY_RELEVANT_PARAMS_MAP: Record<string, string> = {
1010
govActionDeposit: "gov_action_deposit",
1111
minFeeRefScriptCostPerByte: "min_fee_ref_script_cost_per_byte",
1212
};
13+
14+
export const PROPOSAL_TYPE_FILTERS = [
15+
"Info Action",
16+
"Treasury requests",
17+
"Updates to the Constitution",
18+
];
19+
export const BOOTSTRAP_PROPOSAL_TYPE_FILTERS = ["Info Action"];
20+
21+
export const PROPOSAL_STATUS_FILTER = ["Submitted for vote", "Active proposal"];

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const proposal04Wallet: StaticWallet = staticWallets[13];
2424
export const proposal05Wallet: StaticWallet = staticWallets[14];
2525
export const proposal06Wallet: StaticWallet = staticWallets[15];
2626
export const proposal07Wallet: StaticWallet = staticWallets[16];
27+
export const proposal08Wallet: StaticWallet = staticWallets[17];
2728

2829
export const adaHolderWallets = [
2930
adaHolder01Wallet,
@@ -46,6 +47,7 @@ export const proposalWallets = [
4647
proposal05Wallet,
4748
proposal06Wallet,
4849
proposal07Wallet,
50+
proposal08Wallet,
4951
];
5052

5153
export const allStaticWallets = [

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ export async function isBootStrapingPhase() {
2727
return protocolParameterMajorVersion === 9;
2828
}
2929

30-
export async function skipIfTreasuryAndBootstrapping(type: ProposalType) {
30+
export async function skipIfNotInfoAndBootstrapping(type: ProposalType) {
3131
const isBootStraping = await isBootStrapingPhase();
32-
if (type === ProposalType.treasury && isBootStraping) {
32+
if (type !== ProposalType.info && isBootStraping) {
3333
await allure.description(
3434
"This Features will be available only after hardfork."
3535
);

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ export async function downloadMetadata(download: Download): Promise<{
2121
return { name: download.suggestedFilename(), data: jsonData };
2222
}
2323

24+
export function calculateHash(data: string) {
25+
const buffer = Buffer.from(data, "utf8");
26+
const hexDigest = blake.blake2bHex(buffer, null, 32);
27+
return hexDigest;
28+
}
29+
2430
async function calculateMetadataHash() {
2531
try {
2632
const paymentAddress = (await ShelleyWallet.generate()).addressBech32(
@@ -39,8 +45,7 @@ async function calculateMetadataHash() {
3945
2
4046
);
4147

42-
const buffer = Buffer.from(data, "utf8");
43-
const hexDigest = blake.blake2bHex(buffer, null, 32);
48+
const hexDigest = calculateHash(data);
4449

4550
const jsonData = JSON.parse(data);
4651
return { hexDigest, jsonData };

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import { faker } from "@faker-js/faker";
2-
import { generateWalletAddress } from "@helpers/cardano";
3-
import { extractProposalIdFromUrl } from "@helpers/string";
41
import { expect, Locator, Page } from "@playwright/test";
52
import { ProposalCreateRequest, ProposedGovAction } from "@types";
63
import environments from "lib/constants/environments";
74
import ProposalDiscussionDetailsPage from "./proposalDiscussionDetailsPage";
8-
import { isMobile } from "@helpers/mobile";
5+
import { PROPOSAL_TYPE_FILTERS } from "@constants/index";
96

107
export default class ProposalDiscussionPage {
118
// Buttons
@@ -19,8 +16,10 @@ export default class ProposalDiscussionPage {
1916
readonly showAllBtn = this.page.getByTestId("show-all-button").first(); //this.page.getByTestId("show-all-button");
2017
readonly verifyIdentityBtn = this.page.getByTestId("verify-identity-button");
2118
readonly addLinkBtn = this.page.getByTestId("add-link-button");
22-
readonly infoRadio = this.page.getByTestId("Info-radio-wrapper");
23-
readonly treasuryRadio = this.page.getByTestId("Treasury-radio-wrapper");
19+
readonly infoRadio = this.page.getByTestId("info action-radio-wrapper");
20+
readonly treasuryRadio = this.page.getByTestId(
21+
"treasury requests-radio-wrapper"
22+
);
2423
readonly activeProposalWrapper = this.page.getByTestId(
2524
"active-proposal-radio-wrapper"
2625
);
@@ -112,10 +111,10 @@ export default class ProposalDiscussionPage {
112111

113112
async clickRadioButtonsByNames(names: string[]) {
114113
for (const name of names) {
115-
const replaceSpaceWithUnderScore = name.toLowerCase().replace(/ /g, "-");
116-
await this.page
117-
.getByTestId(`${replaceSpaceWithUnderScore}-radio`)
118-
.click();
114+
const testId = PROPOSAL_TYPE_FILTERS.includes(name)
115+
? name.toLowerCase()
116+
: name.toLowerCase().replace(/ /g, "-");
117+
await this.page.getByTestId(`${testId}-radio`).click();
119118
}
120119
}
121120

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

Lines changed: 91 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { faker } from "@faker-js/faker";
44
import { isBootStrapingPhase } from "@helpers/cardano";
55
import { ShelleyWallet } from "@helpers/crypto";
66
import { expectWithInfo } from "@helpers/exceptionHandler";
7-
import { downloadMetadata } from "@helpers/metadata";
7+
import { calculateHash, downloadMetadata } from "@helpers/metadata";
88
import { extractProposalIdFromUrl } from "@helpers/string";
99
import { invalid } from "@mock/index";
1010
import { Download, Locator, Page, expect } from "@playwright/test";
@@ -23,6 +23,8 @@ const formErrors = {
2323
rationale: "rationale-helper-error",
2424
receivingAddress: "receiving-address-0-text-error",
2525
amount: "amount-0-text-error",
26+
constitutionalUrl: "prop=constitution-url-text-error", // BUG wrong test id
27+
guardrailsScriptUrl: "prop-guardrails-script-url-input-error",
2628
link: "link-0-url-input-error",
2729
};
2830

@@ -47,8 +49,11 @@ export default class ProposalSubmissionPage {
4749
readonly addWithdrawalAddressBtn = this.page.getByTestId(
4850
"add-withdrawal-link-button"
4951
);
50-
readonly infoBtn = this.page.getByTestId("info-button");
51-
readonly treasuryBtn = this.page.getByTestId("treasury-button");
52+
readonly infoBtn = this.page.getByTestId("info action-button");
53+
readonly treasuryBtn = this.page.getByTestId("treasury requests-button");
54+
readonly updateTheConstitutionBtn = this.page.getByTestId(
55+
"updates to the constitution-button"
56+
);
5257
readonly editSubmissionButton = this.page.getByTestId(
5358
"edit-submission-button"
5459
);
@@ -61,6 +66,9 @@ export default class ProposalSubmissionPage {
6166
readonly createNewProposalBtn = this.page.getByTestId(
6267
"create-new-proposal-button"
6368
);
69+
readonly guardrailsScriptCheckbox = this.page.getByLabel(
70+
"Do you want to provide new"
71+
); // BUG missing test id
6472

6573
// input fields
6674
readonly titleInput = this.page.getByTestId("title-input");
@@ -72,6 +80,15 @@ export default class ProposalSubmissionPage {
7280
"receiving-address-0-text-input"
7381
);
7482
readonly amountInput = this.page.getByTestId("amount-0-text-input");
83+
readonly constitutionUrlInput = this.page.getByTestId(
84+
"prop_constitution_url"
85+
);
86+
readonly guardrailsScriptUrlInput = this.page.getByTestId(
87+
"prop-guardrails-script-url-input"
88+
);
89+
readonly guardrailsScriptHashInput = this.page.getByTestId(
90+
"prop-guardrails-script-hash-input"
91+
);
7592
readonly closeDraftSuccessModalBtn = this.page.getByTestId("close-button");
7693
readonly linkTextInput = this.page.getByTestId("link-0-text-input");
7794
readonly linkUrlInput = this.page.getByTestId("link-0-url-input");
@@ -88,6 +105,15 @@ export default class ProposalSubmissionPage {
88105
"receiving-address-0-content"
89106
);
90107
readonly amountContent = this.page.getByTestId("amount-0-content");
108+
readonly constitutionUrlContent = this.page.getByTestId(
109+
"new-constitution-url-content"
110+
);
111+
readonly guardrailsScriptUrlContent = this.page.getByTestId(
112+
"guardrails-script-url-content"
113+
);
114+
readonly guardrailsScriptHashContent = this.page.getByTestId(
115+
"guardrails-script-hash-content"
116+
);
91117
readonly linkTextContent = this.page.getByTestId("link-0-text-content");
92118
readonly linkUrlContent = this.page.getByTestId("link-0-url-content");
93119

@@ -128,6 +154,10 @@ export default class ProposalSubmissionPage {
128154
await this.fillTreasuryFields(governanceProposal);
129155
}
130156

157+
if (governanceProposal.gov_action_type_id === 2) {
158+
await this.fillUpdateTheConstitutionFields(governanceProposal);
159+
}
160+
131161
if (governanceProposal.proposal_links != null) {
132162
await this.fillProposalLinks(governanceProposal.proposal_links);
133163
}
@@ -138,9 +168,13 @@ export default class ProposalSubmissionPage {
138168

139169
if (governanceProposal.gov_action_type_id === 0) {
140170
await this.infoBtn.click();
141-
} else {
171+
} else if (governanceProposal.gov_action_type_id === 1) {
142172
await this.treasuryBtn.click();
173+
} else {
174+
await this.updateTheConstitutionBtn.click();
175+
await this.guardrailsScriptCheckbox.click();
143176
}
177+
144178
await this.fillupFormWithTypeSelected(governanceProposal);
145179
}
146180

@@ -158,6 +192,21 @@ export default class ProposalSubmissionPage {
158192
await this.amountInput.fill(governanceProposal.prop_amount);
159193
}
160194

195+
async fillUpdateTheConstitutionFields(
196+
governanceProposal: ProposalCreateRequest
197+
) {
198+
await this.constitutionUrlInput.fill(
199+
governanceProposal.prop_constitution_url
200+
);
201+
202+
await this.guardrailsScriptUrlInput.fill(
203+
governanceProposal.prop_guardrails_script_url
204+
);
205+
await this.guardrailsScriptHashInput.fill(
206+
governanceProposal.prop_guardrails_script_hash
207+
);
208+
}
209+
161210
async fillProposalLinks(proposal_links: Array<ProposalLink>) {
162211
for (let i = 0; i < proposal_links.length; i++) {
163212
if (i > 0) {
@@ -232,6 +281,16 @@ export default class ProposalSubmissionPage {
232281
}
233282
}
234283

284+
if (governanceProposal.gov_action_type_id === 2) {
285+
await expect(
286+
this.page.getByTestId(formErrors.constitutionalUrl)
287+
).toBeHidden();
288+
289+
await expect(
290+
this.page.getByTestId(formErrors.guardrailsScriptUrl)
291+
).toBeHidden();
292+
}
293+
235294
await expect(this.page.getByTestId(formErrors.link)).toBeHidden();
236295

237296
await expect(this.continueBtn).toBeEnabled();
@@ -286,6 +345,16 @@ export default class ProposalSubmissionPage {
286345
await expect(this.page.getByTestId(formErrors.amount)).toBeVisible();
287346
}
288347

348+
if (governanceProposal.gov_action_type_id === 2) {
349+
await expect(
350+
this.page.getByTestId(formErrors.constitutionalUrl)
351+
).toBeVisible();
352+
353+
await expect(
354+
this.page.getByTestId(formErrors.guardrailsScriptUrl)
355+
).toBeVisible();
356+
}
357+
289358
await expect(this.continueBtn).toBeDisabled();
290359
}
291360

@@ -306,7 +375,7 @@ export default class ProposalSubmissionPage {
306375
prop_link_text: faker.internet.domainWord(),
307376
},
308377
],
309-
gov_action_type_id: proposalType === ProposalType.info ? 0 : 1,
378+
gov_action_type_id: Object.values(ProposalType).indexOf(proposalType),
310379
is_draft: !!is_draft,
311380
};
312381

@@ -316,6 +385,13 @@ export default class ProposalSubmissionPage {
316385
.int({ min: 100, max: 1000 })
317386
.toString());
318387
}
388+
if (proposalType === ProposalType.updatesToTheConstitution) {
389+
proposal.prop_constitution_url = faker.internet.url();
390+
proposal.prop_guardrails_script_url = faker.internet.url();
391+
proposal.prop_guardrails_script_hash = calculateHash(
392+
faker.lorem.paragraph()
393+
);
394+
}
319395
return proposal;
320396
}
321397

@@ -332,20 +408,28 @@ export default class ProposalSubmissionPage {
332408
prop_link_text: invalid.name(),
333409
},
334410
],
335-
gov_action_type_id: proposalType === ProposalType.info ? 0 : 1,
411+
gov_action_type_id: Object.values(ProposalType).indexOf(proposalType),
336412
is_draft: false,
337413
};
338414

339415
if (proposalType === ProposalType.treasury) {
340416
(proposal.prop_receiving_address = faker.location.streetAddress()),
341417
(proposal.prop_amount = invalid.amount());
342418
}
419+
420+
if (proposalType === ProposalType.updatesToTheConstitution) {
421+
proposal.prop_constitution_url = invalid.constitutionUrl();
422+
proposal.prop_guardrails_script_url = invalid.url();
423+
proposal.prop_guardrails_script_hash = faker.string.alphanumeric(64);
424+
}
343425
return proposal;
344426
}
345427

346428
async createProposal(
347429
wallet: StaticWallet,
348-
proposalType: ProposalType = ProposalType.treasury
430+
proposalType: ProposalType = Object.values(ProposalType)[
431+
Math.floor(Math.random() * Object.values(ProposalType).length)
432+
]
349433
): Promise<number> {
350434
await this.addLinkBtn.click();
351435
const receivingAddr = ShelleyWallet.fromJson(wallet).rewardAddressBech32(

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ export type LinkType = {
7070
};
7171

7272
export enum ProposalType {
73-
info = "Info",
74-
treasury = "Treasury",
73+
info = "Info Action",
74+
treasury = "Treasury requests",
75+
updatesToTheConstitution = "Updates to the Constitution",
7576
}
7677

7778
export enum BootstrapGovernanceActionType {
@@ -159,6 +160,9 @@ export type ProposalCreateRequest = {
159160
prop_rationale: string;
160161
prop_receiving_address?: string;
161162
prop_amount?: string;
163+
prop_constitution_url?: string;
164+
prop_guardrails_script_url?: string;
165+
prop_guardrails_script_hash?: string;
162166
is_draft: boolean;
163167
};
164168

tests/govtool-frontend/playwright/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"allure:serve": "npx allure serve",
2626
"test": "npx playwright test",
2727
"format": "prettier . --write",
28-
"generate-wallets": "ts-node ./generate_wallets.ts 17"
28+
"generate-wallets": "ts-node ./generate_wallets.ts 18"
2929
},
3030
"dependencies": {
3131
"@cardanoapi/cardano-test-wallet": "^3.0.0",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ test("4A_2. Should access Governance Actions page without connecting wallet", as
2222
await page.goto("/");
2323
await page.getByTestId("move-to-governance-actions-button").click();
2424

25-
await expect(page.getByText(/Governance actions/i)).toHaveCount(2);
25+
await expect(page.getByText(/Governance actions/i)).toHaveCount(1);
2626
});
2727

2828
test("4B_2. Should restrict voting for users who are not registered as DReps (without wallet connected)", async ({

0 commit comments

Comments
 (0)