From 7bb0847ce5f6d9fe7704bbddc77c021db96e4c9d Mon Sep 17 00:00:00 2001 From: Nabin Kawan Date: Mon, 3 Jun 2024 11:38:55 +0545 Subject: [PATCH] Enhance flexibility for local development --- .../playwright/global-setup.ts | 49 ------------------- .../playwright/playwright.config.ts | 6 ++- .../playwright/tests/dRep.setup.ts | 45 ++++++++++++++++- .../playwright/tests/faucet.setup.ts | 22 +++++++++ .../playwright/tests/wallet.bootstrap.ts | 3 +- 5 files changed, 73 insertions(+), 52 deletions(-) delete mode 100644 tests/govtool-frontend/playwright/global-setup.ts create mode 100644 tests/govtool-frontend/playwright/tests/faucet.setup.ts diff --git a/tests/govtool-frontend/playwright/global-setup.ts b/tests/govtool-frontend/playwright/global-setup.ts deleted file mode 100644 index d08dc0bfd..000000000 --- a/tests/govtool-frontend/playwright/global-setup.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { faucetWallet } from "@constants/staticWallets"; -import { ShelleyWallet } from "@helpers/crypto"; -import { pollTransaction } from "@helpers/transaction"; -import { loadAmountFromFaucet } from "@services/faucetService"; -import kuberService from "@services/kuberService"; -import walletManager from "lib/walletManager"; - -async function generateWallets(num: number) { - return await Promise.all( - Array.from({ length: num }, () => - ShelleyWallet.generate().then((wallet) => wallet.json()) - ) - ); -} - -async function globalSetup() { - const registeredDRepWallets = await generateWallets(9); - const registerDRepWallets = await generateWallets(9); - - // faucet setup - const res = await loadAmountFromFaucet(faucetWallet.address); - await pollTransaction(res.txid); - - // initialize wallets - const initializeRes = await kuberService.initializeWallets([ - ...registeredDRepWallets, - ...registerDRepWallets, - ]); - await pollTransaction(initializeRes.txId, initializeRes.lockInfo); - - // register dRep - const registrationRes = await kuberService.multipleDRepRegistration( - registeredDRepWallets - ); - await pollTransaction(registrationRes.txId, registrationRes.lockInfo); - - // transfer 600 ADA for dRep registration - const amountOutputs = registerDRepWallets.map((wallet) => { - return { address: wallet.address, value: `${600}A` }; - }); - const transferRes = await kuberService.multipleTransferADA(amountOutputs); - await pollTransaction(transferRes.txId, transferRes.lockInfo); - - // save to file - await walletManager.writeWallets(registeredDRepWallets, "registeredDRep"); - await walletManager.writeWallets(registerDRepWallets, "registerDRep"); -} - -export default globalSetup; diff --git a/tests/govtool-frontend/playwright/playwright.config.ts b/tests/govtool-frontend/playwright/playwright.config.ts index 1ab319893..c69694efc 100644 --- a/tests/govtool-frontend/playwright/playwright.config.ts +++ b/tests/govtool-frontend/playwright/playwright.config.ts @@ -11,7 +11,6 @@ import environments from "lib/constants/environments"; * See https://playwright.dev/docs/test-configuration. */ export default defineConfig({ - globalSetup: environments.ci ? require.resolve("./global-setup.ts") : "", testDir: "./tests", /* Run tests in files in parallel */ fullyParallel: true, @@ -44,6 +43,10 @@ export default defineConfig({ name: "auth setup", testMatch: "**/auth.setup.ts", }, + { + name: "faucet setup", + testMatch: "**/faucet.setup.ts", + }, { name: "dRep setup", testMatch: "**/dRep.setup.ts", @@ -51,6 +54,7 @@ export default defineConfig({ { name: "wallet bootstrap", testMatch: "**/wallet.bootstrap.ts", + dependencies: !environments.ci ? ["faucet setup"] : [], }, { name: "transaction", diff --git a/tests/govtool-frontend/playwright/tests/dRep.setup.ts b/tests/govtool-frontend/playwright/tests/dRep.setup.ts index 6c600d025..49fcef51c 100644 --- a/tests/govtool-frontend/playwright/tests/dRep.setup.ts +++ b/tests/govtool-frontend/playwright/tests/dRep.setup.ts @@ -1,18 +1,31 @@ import environments from "@constants/environments"; import { dRepWallets } from "@constants/staticWallets"; import { setAllureEpic, setAllureStory } from "@helpers/allure"; +import { ShelleyWallet } from "@helpers/crypto"; import { pollTransaction } from "@helpers/transaction"; import { expect, test as setup } from "@playwright/test"; import kuberService from "@services/kuberService"; +import walletManager from "lib/walletManager"; -setup.describe.configure({ timeout: environments.txTimeOut }); +const REGISTER_DREP_WALLETS = 9; +const DREP_WALLETS = 9; setup.beforeEach(async () => { await setAllureEpic("Setup"); await setAllureStory("Register DRep"); }); +async function generateWallets(num: number) { + return await Promise.all( + Array.from({ length: num }, () => + ShelleyWallet.generate().then((wallet) => wallet.json()) + ) + ); +} + setup("Register DRep of static wallets", async () => { + setup.setTimeout(environments.txTimeOut); + try { const res = await kuberService.multipleDRepRegistration(dRepWallets); @@ -28,3 +41,33 @@ setup("Register DRep of static wallets", async () => { } } }); + +setup("Setup temporary DRep wallets", async () => { + setup.setTimeout(3 * environments.txTimeOut); + + const dRepWallets = await generateWallets(DREP_WALLETS); + const registerDRepWallets = await generateWallets(REGISTER_DREP_WALLETS); + + // initialize wallets + const initializeRes = await kuberService.initializeWallets([ + ...dRepWallets, + ...registerDRepWallets, + ]); + await pollTransaction(initializeRes.txId, initializeRes.lockInfo); + + // register dRep + const registrationRes = + await kuberService.multipleDRepRegistration(dRepWallets); + await pollTransaction(registrationRes.txId, registrationRes.lockInfo); + + // transfer 600 ADA for dRep registration + const amountOutputs = registerDRepWallets.map((wallet) => { + return { address: wallet.address, value: `${600}A` }; + }); + const transferRes = await kuberService.multipleTransferADA(amountOutputs); + await pollTransaction(transferRes.txId, transferRes.lockInfo); + + // save to file + await walletManager.writeWallets(dRepWallets, "registeredDRep"); + await walletManager.writeWallets(registerDRepWallets, "registerDRep"); +}); diff --git a/tests/govtool-frontend/playwright/tests/faucet.setup.ts b/tests/govtool-frontend/playwright/tests/faucet.setup.ts new file mode 100644 index 000000000..6cfceccfd --- /dev/null +++ b/tests/govtool-frontend/playwright/tests/faucet.setup.ts @@ -0,0 +1,22 @@ +import environments from "@constants/environments"; +import { faucetWallet } from "@constants/staticWallets"; +import { setAllureEpic, setAllureStory } from "@helpers/allure"; +import { pollTransaction } from "@helpers/transaction"; +import { test as setup } from "@playwright/test"; +import { loadAmountFromFaucet } from "@services/faucetService"; +import kuberService from "@services/kuberService"; + +setup.describe.configure({ timeout: environments.txTimeOut }); + +setup.beforeEach(async () => { + await setAllureEpic("Setup"); + await setAllureStory("Faucet"); +}); + +setup("Faucet setup", async () => { + const balance = await kuberService.getBalance(faucetWallet.address); + if (balance > 10000) return; + + const res = await loadAmountFromFaucet(faucetWallet.address); + await pollTransaction(res.txid); +}); diff --git a/tests/govtool-frontend/playwright/tests/wallet.bootstrap.ts b/tests/govtool-frontend/playwright/tests/wallet.bootstrap.ts index acd11a7d4..1a4b6500d 100644 --- a/tests/govtool-frontend/playwright/tests/wallet.bootstrap.ts +++ b/tests/govtool-frontend/playwright/tests/wallet.bootstrap.ts @@ -1,5 +1,5 @@ import { adaHolderWallets, dRepWallets } from "@constants/staticWallets"; -import { setAllureEpic } from "@helpers/allure"; +import { setAllureEpic, setAllureStory } from "@helpers/allure"; import { pollTransaction } from "@helpers/transaction"; import { expect, test as setup } from "@playwright/test"; import kuberService from "@services/kuberService"; @@ -9,6 +9,7 @@ setup.describe.configure({ mode: "serial", timeout: environments.txTimeOut }); setup.beforeEach(async () => { await setAllureEpic("Setup"); + await setAllureStory("Wallet bootstrap"); }); setup("Initialize static wallets", async () => {