From 4050632f8397edaa21697e31cf4aa7d5ba26dfd3 Mon Sep 17 00:00:00 2001 From: Niraj Date: Tue, 10 Sep 2024 19:26:06 +0545 Subject: [PATCH 1/7] feat: add teardown to refund remaining balance to faucet --- .../playwright/lib/constants/environments.ts | 1 + .../playwright/playwright.config.ts | 5 +++ .../playwright/tests/faucet.teardown.ts | 34 +++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 tests/govtool-frontend/playwright/tests/faucet.teardown.ts diff --git a/tests/govtool-frontend/playwright/lib/constants/environments.ts b/tests/govtool-frontend/playwright/lib/constants/environments.ts index ed801fc0a..d7c021ea8 100644 --- a/tests/govtool-frontend/playwright/lib/constants/environments.ts +++ b/tests/govtool-frontend/playwright/lib/constants/environments.ts @@ -17,6 +17,7 @@ const environments = { process.env.FAUCET_API_URL || "https://faucet.sanchonet.world.dev.cardano.org", apiKey: process.env.FAUCET_API_KEY || "", + address: process.env.FAUCET_ADDRESS || "addr_test1vz0ua2vyk7r4vufmpqh5v44awg8xff26hxlwyrt3uc67maqtql3kl", }, kuber: { apiUrl: process.env.KUBER_API_URL || "https://kuber-govtool.cardanoapi.io", diff --git a/tests/govtool-frontend/playwright/playwright.config.ts b/tests/govtool-frontend/playwright/playwright.config.ts index de0939e99..941cccab5 100644 --- a/tests/govtool-frontend/playwright/playwright.config.ts +++ b/tests/govtool-frontend/playwright/playwright.config.ts @@ -50,6 +50,7 @@ export default defineConfig({ { name: "faucet setup", testMatch: "**/faucet.setup.ts", + teardown: environments.ci && "cleanup faucet" }, { name: "dRep setup", @@ -128,5 +129,9 @@ export default defineConfig({ name: "cleanup delegation", testMatch: "delegation.teardown.ts", }, + { + name: "cleanup faucet", + testMatch: "faucet.teardown.ts", + }, ], }); diff --git a/tests/govtool-frontend/playwright/tests/faucet.teardown.ts b/tests/govtool-frontend/playwright/tests/faucet.teardown.ts new file mode 100644 index 000000000..b32425873 --- /dev/null +++ b/tests/govtool-frontend/playwright/tests/faucet.teardown.ts @@ -0,0 +1,34 @@ +import environments from "@constants/environments"; +import { faucetWallet } from "@constants/staticWallets"; +import { setAllureEpic, setAllureStory } from "@helpers/allure"; +import { pollTransaction } from "@helpers/transaction"; +import { test as cleanup, expect } from "@playwright/test"; +import kuberService from "@services/kuberService"; + +cleanup.describe.configure({ timeout: environments.txTimeOut }); +cleanup.beforeEach(async () => { + await setAllureEpic("Setup"); + await setAllureStory("Cleanup"); +}); + +cleanup("Refund faucet", async () => { + try { + const faucetRemainingBalance = await kuberService.getBalance( + faucetWallet.address + ); + + const transferBalance = Math.floor(faucetRemainingBalance) - 3; + const { txId, lockInfo } = await kuberService.transferADA( + [environments.faucet.address], + transferBalance + ); + await pollTransaction(txId, lockInfo); + } catch (err) { + console.log(err); + if (err.status === 400) { + expect(true, "Failed to trasfer Ada").toBeTruthy(); + } else { + throw Error(err); + } + } +}); From b09b954177f5b567e51968fc40b22069800cbf75 Mon Sep 17 00:00:00 2001 From: Niraj Date: Tue, 10 Sep 2024 19:26:21 +0545 Subject: [PATCH 2/7] chore: add multiple dRepDeRegistration on kuber service --- .../playwright/lib/services/kuberService.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/govtool-frontend/playwright/lib/services/kuberService.ts b/tests/govtool-frontend/playwright/lib/services/kuberService.ts index 6ddc81a43..d88164466 100644 --- a/tests/govtool-frontend/playwright/lib/services/kuberService.ts +++ b/tests/govtool-frontend/playwright/lib/services/kuberService.ts @@ -248,6 +248,24 @@ const kuberService = { return kuber.signAndSubmitTx(req); }, + multipleDRepDeRegistration: (wallets: StaticWallet[]) => { + const kuber = new Kuber(faucetWallet.address, faucetWallet.payment.private); + const req = { + certificates: wallets.map((wallet) => + Kuber.generateCert("deregisterdrep", wallet.stake.pkh) + ), + selections: wallets.map((wallet) => { + return { + type: "PaymentSigningKeyShelley_ed25519", + description: "Stake Signing Key", + cborHex: `5820${wallet.stake.private}`, + }; + }), + inputs: faucetWallet.address, + }; + return kuber.signAndSubmitTx(req); + }, + stakeDelegation: ( addr: string, signingKey: string, From b50f5242dfc57c53d176097d306e7c166bcc2090 Mon Sep 17 00:00:00 2001 From: Niraj Date: Tue, 10 Sep 2024 19:27:06 +0545 Subject: [PATCH 3/7] feat: add dRep deRegestration teardown --- .../playwright/lib/walletManager.ts | 15 +++++++- .../playwright/playwright.config.ts | 5 +++ .../dRepRegistration.dRep.spec.ts | 2 + .../playwright/tests/dRep.setup.ts | 2 + .../playwright/tests/dRep.teardown.ts | 37 +++++++++++++++++++ 5 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 tests/govtool-frontend/playwright/tests/dRep.teardown.ts diff --git a/tests/govtool-frontend/playwright/lib/walletManager.ts b/tests/govtool-frontend/playwright/lib/walletManager.ts index cd9183269..94020e063 100644 --- a/tests/govtool-frontend/playwright/lib/walletManager.ts +++ b/tests/govtool-frontend/playwright/lib/walletManager.ts @@ -5,7 +5,12 @@ const path = require("path"); const baseFilePath = path.resolve(__dirname, "./_mock"); -export type Purpose = "registerDRep" | "registeredDRep" | "proposalSubmission"; +export type Purpose = + | "registerDRep" + | "registeredDRep" + | "proposalSubmission" + | "registerDRepCopy" + | "registeredDRepCopy"; /** * WalletManager class is responsible for managing a list of temporary wallets. @@ -54,6 +59,14 @@ class WalletManager { return JSON.parse(data); } + async removeCopyWallet(walletToRemove: StaticWallet, purpose: Purpose) { + const currentWallets = await this.readWallets(purpose); + const updatedWallets = currentWallets.filter( + (wallet) => wallet.address !== walletToRemove.address + ); + await this.writeWallets(updatedWallets, purpose); + } + async popWallet(purpose: Purpose): Promise { const popCb = async () => { const wallets = await this.readWallets(purpose); diff --git a/tests/govtool-frontend/playwright/playwright.config.ts b/tests/govtool-frontend/playwright/playwright.config.ts index 941cccab5..5e5e0be4e 100644 --- a/tests/govtool-frontend/playwright/playwright.config.ts +++ b/tests/govtool-frontend/playwright/playwright.config.ts @@ -92,6 +92,7 @@ export default defineConfig({ use: { ...devices["Desktop Chrome"] }, testMatch: "**/*.dRep.spec.ts", dependencies: environments.ci ? ["auth setup", "dRep setup","wallet bootstrap"] : [], + teardown: environments.ci && "cleanup dRep" }, { name: "delegation", @@ -129,6 +130,10 @@ export default defineConfig({ name: "cleanup delegation", testMatch: "delegation.teardown.ts", }, + { + name: "cleanup dRep", + testMatch: "dRep.teardown.ts", + }, { name: "cleanup faucet", testMatch: "faucet.teardown.ts", diff --git a/tests/govtool-frontend/playwright/tests/3-drep-registration/dRepRegistration.dRep.spec.ts b/tests/govtool-frontend/playwright/tests/3-drep-registration/dRepRegistration.dRep.spec.ts index 619befc5d..56cabc18b 100644 --- a/tests/govtool-frontend/playwright/tests/3-drep-registration/dRepRegistration.dRep.spec.ts +++ b/tests/govtool-frontend/playwright/tests/3-drep-registration/dRepRegistration.dRep.spec.ts @@ -144,6 +144,7 @@ test.describe("Temporary DReps", () => { test.slow(); // Due to queue in pop wallets const wallet = await walletManager.popWallet("registeredDRep"); + await walletManager.removeCopyWallet(wallet, "registeredDRepCopy"); const tempDRepAuth = await createTempDRepAuth(page, wallet); const dRepPage = await createNewPageWithWallet(browser, { @@ -168,6 +169,7 @@ test.describe("Temporary DReps", () => { test.setTimeout(testInfo.timeout + environments.txTimeOut); const wallet = await walletManager.popWallet("registeredDRep"); + await walletManager.removeCopyWallet(wallet, "registeredDRepCopy"); const dRepAuth = await createTempDRepAuth(page, wallet); const dRepPage = await createNewPageWithWallet(browser, { diff --git a/tests/govtool-frontend/playwright/tests/dRep.setup.ts b/tests/govtool-frontend/playwright/tests/dRep.setup.ts index bba1f7dcb..319f00ec7 100644 --- a/tests/govtool-frontend/playwright/tests/dRep.setup.ts +++ b/tests/govtool-frontend/playwright/tests/dRep.setup.ts @@ -97,4 +97,6 @@ setup("Setup temporary DRep wallets", async () => { // save to file await walletManager.writeWallets(dRepWallets, "registeredDRep"); await walletManager.writeWallets(registerDRepWallets, "registerDRep"); + await walletManager.writeWallets(dRepWallets, "registeredDRepCopy"); + await walletManager.writeWallets(registerDRepWallets, "registerDRepCopy"); }); diff --git a/tests/govtool-frontend/playwright/tests/dRep.teardown.ts b/tests/govtool-frontend/playwright/tests/dRep.teardown.ts new file mode 100644 index 000000000..407b74767 --- /dev/null +++ b/tests/govtool-frontend/playwright/tests/dRep.teardown.ts @@ -0,0 +1,37 @@ +import environments from "@constants/environments"; +import { dRepWallets } from "@constants/staticWallets"; +import { setAllureEpic, setAllureStory } from "@helpers/allure"; +import { pollTransaction } from "@helpers/transaction"; +import { test as cleanup, expect } from "@playwright/test"; +import kuberService from "@services/kuberService"; +import { StaticWallet } from "@types"; + +cleanup.describe.configure({ timeout: environments.txTimeOut }); +cleanup.beforeEach(async () => { + await setAllureEpic("Setup"); + await setAllureStory("Cleanup"); +}); + +const registerDRep: StaticWallet[] = require("../lib/_mock/registerDRepCopyWallets.json"); +const registeredDRep: StaticWallet[] = require("../lib/_mock/registeredDRepCopyWallets.json"); + +cleanup("DRep de-registration", async () => { + const registeredDRepWallets = [ + ...dRepWallets, + ...registerDRep, + ...registeredDRep, + ]; + try { + const { txId, lockInfo } = await kuberService.multipleDRepDeRegistration( + registeredDRepWallets + ); + await pollTransaction(txId, lockInfo); + } catch (err) { + console.log(err); + if (err.status === 400) { + expect(true, "DRep not registered").toBeTruthy(); + } else { + throw Error(err); + } + } +}); From 821f20a0b5969178a4dcb1a23f19576ff0cc4954 Mon Sep 17 00:00:00 2001 From: Niraj Date: Mon, 16 Sep 2024 21:05:07 +0545 Subject: [PATCH 4/7] chore: remove copy register drep wallet used for direct voter --- .../2-delegation/delegationFunctionality.delegation.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/govtool-frontend/playwright/tests/2-delegation/delegationFunctionality.delegation.spec.ts b/tests/govtool-frontend/playwright/tests/2-delegation/delegationFunctionality.delegation.spec.ts index 4090e3894..ed98314d0 100644 --- a/tests/govtool-frontend/playwright/tests/2-delegation/delegationFunctionality.delegation.spec.ts +++ b/tests/govtool-frontend/playwright/tests/2-delegation/delegationFunctionality.delegation.spec.ts @@ -140,6 +140,7 @@ test.describe("Register DRep state", () => { test.beforeEach(async ({ page, browser }) => { wallet = await walletManager.popWallet("registerDRep"); + await walletManager.removeCopyWallet(wallet, "registerDRepCopy"); const dRepAuth = await createTempDRepAuth(page, wallet); dRepPage = await createNewPageWithWallet(browser, { From 8ab38c015451d53bf10a98476ddb7e4954c39024 Mon Sep 17 00:00:00 2001 From: Niraj Date: Tue, 17 Sep 2024 08:02:28 +0545 Subject: [PATCH 5/7] chore: remove copy registered DRep wallet for dRep retirement --- .../5-proposal-functionality/proposalFunctionality.dRep.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/govtool-frontend/playwright/tests/5-proposal-functionality/proposalFunctionality.dRep.spec.ts b/tests/govtool-frontend/playwright/tests/5-proposal-functionality/proposalFunctionality.dRep.spec.ts index 7c7282427..2383fbc61 100644 --- a/tests/govtool-frontend/playwright/tests/5-proposal-functionality/proposalFunctionality.dRep.spec.ts +++ b/tests/govtool-frontend/playwright/tests/5-proposal-functionality/proposalFunctionality.dRep.spec.ts @@ -225,6 +225,7 @@ test.describe("Check voting power", () => { test.setTimeout(testInfo.timeout + environments.txTimeOut); const wallet = await walletManager.popWallet("registeredDRep"); + await walletManager.removeCopyWallet(wallet,"registeredDRepCopy"); const tempDRepAuth = await createTempDRepAuth(page, wallet); From 00a176fb5848d44ccc7618a9611bd9ee0a708e16 Mon Sep 17 00:00:00 2001 From: Niraj Date: Tue, 17 Sep 2024 09:38:42 +0545 Subject: [PATCH 6/7] chore: replace file path with read wallets for registerDRep and registeredDRep copy file --- tests/govtool-frontend/playwright/lib/walletManager.ts | 2 +- tests/govtool-frontend/playwright/tests/dRep.teardown.ts | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/govtool-frontend/playwright/lib/walletManager.ts b/tests/govtool-frontend/playwright/lib/walletManager.ts index 94020e063..f9558e9e3 100644 --- a/tests/govtool-frontend/playwright/lib/walletManager.ts +++ b/tests/govtool-frontend/playwright/lib/walletManager.ts @@ -42,7 +42,7 @@ class WalletManager { ); } - private async readWallets(purpose: Purpose): Promise { + async readWallets(purpose: Purpose): Promise { const data: string = await new Promise((resolve, reject) => fs.readFile( `${baseFilePath}/${purpose}Wallets.json`, diff --git a/tests/govtool-frontend/playwright/tests/dRep.teardown.ts b/tests/govtool-frontend/playwright/tests/dRep.teardown.ts index 407b74767..402d9a48b 100644 --- a/tests/govtool-frontend/playwright/tests/dRep.teardown.ts +++ b/tests/govtool-frontend/playwright/tests/dRep.teardown.ts @@ -5,6 +5,7 @@ import { pollTransaction } from "@helpers/transaction"; import { test as cleanup, expect } from "@playwright/test"; import kuberService from "@services/kuberService"; import { StaticWallet } from "@types"; +import walletManager from "lib/walletManager"; cleanup.describe.configure({ timeout: environments.txTimeOut }); cleanup.beforeEach(async () => { @@ -12,10 +13,12 @@ cleanup.beforeEach(async () => { await setAllureStory("Cleanup"); }); -const registerDRep: StaticWallet[] = require("../lib/_mock/registerDRepCopyWallets.json"); -const registeredDRep: StaticWallet[] = require("../lib/_mock/registeredDRepCopyWallets.json"); - cleanup("DRep de-registration", async () => { + const registerDRep: StaticWallet[] = + await walletManager.readWallets("registerDRepCopy"); + const registeredDRep: StaticWallet[] = + await walletManager.readWallets("registeredDRepCopy"); + const registeredDRepWallets = [ ...dRepWallets, ...registerDRep, From d74fbe2604ed590d09d1ac51d65daa3c5d6ad737 Mon Sep 17 00:00:00 2001 From: Niraj Date: Tue, 24 Sep 2024 10:42:13 +0545 Subject: [PATCH 7/7] chore: update temporary proposal wallets message --- .../playwright/tests/governance-action.setup.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/govtool-frontend/playwright/tests/governance-action.setup.ts b/tests/govtool-frontend/playwright/tests/governance-action.setup.ts index 3a8aed8f4..634372c5c 100644 --- a/tests/govtool-frontend/playwright/tests/governance-action.setup.ts +++ b/tests/govtool-frontend/playwright/tests/governance-action.setup.ts @@ -36,7 +36,7 @@ setup("Setup temporary proposal wallets", async () => { ]); await pollTransaction(initializeRes.txId, initializeRes.lockInfo); - // transfer 51_000 ADA for dRep registration + // transfer 51_000 ADA for proposal submission const amountOutputs = proposalSubmissionsWallets.map((wallet) => { return { address: wallet.address, value: `${51_000}A` }; });