Skip to content

Commit

Permalink
Add playwright tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NabinKawan committed May 8, 2024
1 parent b919a42 commit 36ca534
Show file tree
Hide file tree
Showing 52 changed files with 8,005 additions and 14 deletions.
18 changes: 12 additions & 6 deletions tests/govtool-frontend/playwright/.env.example
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
FRONTEND_URL=http://localhost:8080
API_URL=http://localhost:8080/api
FRONTEND_URL=http://localhost:3000
API_URL=http://localhost:3000/api

DOCS_URL=https://docs.sanchogov.tools

# 1 for testnet, 0 for mainnet
NETWORK_ID=1,
# 0 for testnet, 1 for mainnet
NETWORK_ID=0

# Create mock wallets if true
ONE_TIME_WALLET_SETUP=false,
ONE_TIME_WALLET_SETUP=false

# Faucet
FAUCET_API_URL=https://faucet.sanchonet.world.dev.cardano.org
FAUCET_API_KEY=

# Kuber
KUBER_API_URL=https://sanchonet.kuber.cardanoapi.io
KUBER_API_KEY=
KUBER_API_KEY=

# Transaction timeout
TX_TIMEOUT=120000 # milliseconds

# Metadata Bucket
METADATA_BUCKET_URL=https://metadata.cardanoapi.io/data
16 changes: 16 additions & 0 deletions tests/govtool-frontend/playwright/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
.env
tests-out/
.auth/
.download/
lib/_mock/
allure-results/
allure-report/
.secrets
.vars
.lock-pool/
.logs/
6 changes: 6 additions & 0 deletions tests/govtool-frontend/playwright/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Ignore artifacts:
.github
node_modules
playwright-report
test-results
playwright.config.ts
23 changes: 23 additions & 0 deletions tests/govtool-frontend/playwright/lib/constants/environments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const environments = {
frontendUrl: process.env.HOST_URL || "http://localhost:5173",
apiUrl: `${process.env.HOST_URL}/api` || "http://localhost:9999",
docsUrl: process.env.DOCS_URL || "https://docs.sanchogov.tools",
networkId: parseInt(process.env.NETWORK_ID) || 0,
oneTimeWalletSetup: process.env.ONE_TIME_WALLET_SETUP === "true" || false,
faucet: {
apiUrl:
process.env.FAUCET_API_URL ||
"https://faucet.sanchonet.world.dev.cardano.org",
apiKey: process.env.FAUCET_API_KEY || "",
},
kuber: {
apiUrl:
process.env.KUBER_API_URL || "https://sanchonet.kuber.cardanoapi.io",
apiKey: process.env.KUBER_API_KEY || "",
},
txTimeOut: parseInt(process.env.TX_TIMEOUT) || 120000,
metadataBucketUrl:
process.env.METADATA_BUCKET_URL || "https://metadata.cardanoapi.io/data",
};

export default environments;
122 changes: 122 additions & 0 deletions tests/govtool-frontend/playwright/lib/constants/staticWallets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import { StaticWallet } from "@types";

export const faucetWallet: StaticWallet = {
payment: {
pkh: "b5187cdefbc5b49ddc17b423c079f0717721a03882a3b265bd4c12e0",
private: "11abec096ef0ea7edbeeee01a1a3f0e9f24a7225c2ee99687fb328146fe85ba6",
public: "b6a42d4ccc4d26adaec67e8578bf31f13b1b7e640527356248f2ec547f9de6e4",
},
stake: {
pkh: "80f326af300273d19d5a541d45baa42ebc04265816735b026b5f34a4",
private: "283fd7625ef596f04f21b50ee14a9f4b49f8b1a6f17773cd2e1e69841a111bc1",
public: "86b08ee3d86cb72d026197a5a710e248d66f28fcff21b4467b75f876b4e6d050",
},
dRepId: "drep1zg6zq3ku422ppvfm835rnvzf9ckxtzmy3ayjwylck6s4q9zr5ve",
address:
"addr_test1qz63slx7l0zmf8wuz76z8sre7pchwgdq8zp28vn9h4xp9cyq7vn27vqzw0ge6kj5r4zm4fpwhszzvkqkwddsy66lxjjqxnc9zk",
};

export const dRep01Wallet: StaticWallet = {
payment: {
private: "2f1053f22707b9881ea6112024027a660bd5508e22081cf5e4e95cc663802dd9",
public: "891ed5096ee248bc7f31a3094ea90f34485483eb1050c7ee368e64d04b90a009",
pkh: "5775ad2fb14ca1b45381a40e40f0c06081edaf2261e02bbcebcf8dc3",
},
stake: {
private: "39db531b1ba6d659f0e09ed609e86a080ba2a5629dc5fad3b29890bdba64a014",
public: "45a35ffab6c467531ee528fbdbe1a629de806c7af19dcb5aacb70e4286fd6b9a",
pkh: "46a95c1337b27332131f3c1b9d8e7689edd2f593e7e69bf5dcf0c278",
},
address:
"addr_test1qpthttf0k9x2rdznsxjqus8scpsgrmd0yfs7q2aua08cms6x49wpxdajwvepx8eurwwcua5fahf0tyl8u6dlth8scfuqk8r352",
dRepId: "drep1g654cyehkfenyycl8sdemrnk38ka9avnulnfhawu7rp8skl824l",
};

// export const dRep02Wallet: StaticWallet = {
// payment: {
// private: "71120ea01dc0c367da113a7ee7b3744a46f793edb4f30a06b46d800324b2c999",
// public: "66724455eaacb6dea6686ba09bc159d5deef3d82ebf9c6a60d61748b59e32627",
// pkh: "363547ffb44d337f8055515e75e8af516e557b3270bfa4d9198e7195",
// },
// stake: {
// private: "4dfc89a9d680b237146dde69282c709e93ba91ac0b028e980bc40ec573c77f0f",
// public: "009c10056aff887d66135886d1fb9f046190bdf1d90a3f9cff954386f7cf37fb",
// pkh: "4d52d1d178157ab4c5ab6f8cb109ff91f750b367830463ef8344007e",
// },
// address:
// "addr_test1qqmr23llk3xnxluq24g4ua0g4agku4tmxfctlfxerx88r92d2tgaz7q4026vt2m03jcsnlu37agtxeurq337lq6yqplqftpnqu",
// dRepId: "drep1f4fdr5tcz4atf3dtd7xtzz0lj8m4pvm8svzx8murgsq8u6dkmf4",
// };

export const adaHolder01Wallet: StaticWallet = {
payment: {
private: "63be29a8c8a73571ab410062f4555998c45a61f96a9bf1c5308c4f3eb7e4453f",
public: "dd1e7ca0deb26499a1336fbe2a5169ba3043a27763bb9e600625a95728be6167",
pkh: "daa1dd48181133eb21a376da773a1d31f72281008d790ecac885ff97",
},
stake: {
private: "13e9e60b51768367c0d4c07a9f02b90d6511a9d7f7215b465fd87488171c687f",
public: "2819c4d6a988746ac7f5be3edc93c86d4cd0e3fae9c23a6ceeb23e6d0b207ad0",
pkh: "56ffa2a26e57c5b14c7c8d58455ebc24ce628f1c456be7e2e7448c8f",
},
address:
"addr_test1qrd2rh2grqgn86ep5dmd5ae6r5clwg5pqzxhjrk2ezzll96kl732ymjhckc5clydtpz4a0pyee3g78z9d0n79e6y3j8smc7gzu",
dRepId: "drep12ml69gnw2lzmznru34vy2h4uyn8x9rcug4470ch8gjxg74htere",
};

export const adaHolder02Wallet: StaticWallet = {
payment: {
private: "6794cee96fd24aa68ae6e7df8548c15c6faf0373fc53c9714517b7c09b2ba6c0",
public: "58df2c02b5a2af09b51d5357f675b4f13ee019db57686adaab7536f6a3b8c29f",
pkh: "aec3d01a7fa061d027e945aedcfcb8e32eab0390063d19ef8ab89a88",
},
stake: {
private: "cb4fa9d68add76c15b2b16b4bb7aeab043d95f42f4adec3d9d50396e6d1760e4",
public: "45dec9c5c130c23b1b9fedda680bdf1658e918087bd0f51c5548c471ca7d2991",
pkh: "49da6cb42b23f1c1f25f85e91dd325414b154f036bbf43a69dea27ee",
},
address:
"addr_test1qzhv85q607sxr5p8a9z6ah8uhr3ja2crjqrr6x0032uf4zzfmfktg2er78qlyhu9aywaxf2pfv257qmthap6d802ylhqvz8qsf",
dRepId: "drep1f8dxedpty0curujlsh53m5e9g9932ncrdwl58f5aagn7u9psjya",
};

// export const soleVoterWallet: StaticWallet = {
// payment: {
// private: "98d35ef14dedc4520ed0153bc41e4db884deb0390f659ee1e28bb52da6045d4e",
// public: "5206735d1a1a1ac4ac625c973581ed97daec145d2e47a5c9bb14754527929f78",
// pkh: "0b5aa57cfd8010b00c649bf281520514de4efd952eba9c31eb7db187",
// },
// stake: {
// private: "95ae1de1c2984c18207b8f57c450f1fbc54c2f0f1b878d3b24df11157277e1d1",
// public: "3bca5cb3599020808f69df269eb42b0e66ecf7455fb969e90c46ae0ac55e6572",
// pkh: "97265a1e13717c04a85e7d6dc156ba38340645b1e812a935823092f9",
// },
// address:
// "addr_test1qq944ftulkqppvqvvjdl9q2jq52dunhaj5ht48p3ad7mrpuhyedpuym30sz2shnadhq4dw3cxsrytv0gz25ntq3sjtusesfzgd",
// dRepId: "drep1jun958snw97qf2z704kuz4468q6qv3d3aqf2jdvzxzf0jtlmwlf",
// };

// Does not takes part in transaction
export const user01Wallet: StaticWallet = {
payment: {
private: "a84d81412e41b55f9a484ce2cb5849660c7a8874df7ea11cb48120ec8efd2911",
public: "18cc2696ff588c19789f908df838fc58dd58986ebf6191b7b63d310c997f968b",
pkh: "56a6427fa7f8599d1e49271eb8123d0e02bc06bd44fc2d988e25455a",
},
stake: {
private: "c3d9fde8d81c1533ab9a1e6fdbaddd792dfba8f58656c95e83f5e967087f4605",
public: "dd50a02daa77061ecd2d43d6fa1049e3db0192b94112ffc4f4e48975362987ff",
pkh: "cac600470e3b3027bf3ad3c363c35c690a54308bd001120194c1ba0b",
},
address:
"addr_test1qpt2vsnl5lu9n8g7fyn3awqj858q90qxh4z0ctvc3cj52kk2ccqywr3mxqnm7wkncd3uxhrfpf2rpz7sqyfqr9xphg9s77zxlg",
dRepId: "drep1etrqq3cw8vcz00e660pk8s6udy99gvyt6qq3yqv5cxaqkuupyzg",
};

export const adaHolderWallets = [adaHolder01Wallet, adaHolder02Wallet];

export const userWallets = [user01Wallet];

export const dRepWallets = [dRep01Wallet];

// export const soleVoterWallets = [soleVoterWallet];
44 changes: 44 additions & 0 deletions tests/govtool-frontend/playwright/lib/datafactory/createAuth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Saves storage state to a file in the .auth directory

import { importWallet } from "@fixtures/importWallet";
import { ShelleyWallet } from "@helpers/crypto";
import LoginPage from "@pages/loginPage";
import { Page, expect } from "@playwright/test";

const tempDRepAuth = ".auth/tempDRepAuth.json";
const tempUserAuth = ".auth/tempUserAuth.json";
const tempAdaHolderAuth = ".auth/tempAdaHolderAuth.json";

export async function createTempDRepAuth(page: Page, wallet: ShelleyWallet) {
await importWallet(page, wallet.json());

const loginPage = new LoginPage(page);
await loginPage.login();
await expect(page.getByTestId("disconnect-button")).toBeVisible();

await page.context().storageState({ path: tempDRepAuth });
return tempDRepAuth;
}

export async function createTempAdaHolderAuth(
page: Page,
wallet: ShelleyWallet
) {
await importWallet(page, wallet.json());

const loginPage = new LoginPage(page);
await loginPage.login();
await expect(page.getByTestId("disconnect-button")).toBeVisible();

await page.context().storageState({ path: tempAdaHolderAuth });
return tempAdaHolderAuth;
}

export async function createTempUserAuth(page: Page) {
const loginPage = new LoginPage(page);
await loginPage.login();
await expect(page.getByTestId("disconnect-button")).toBeVisible();

await page.context().storageState({ path: tempUserAuth });
return tempUserAuth;
}
34 changes: 34 additions & 0 deletions tests/govtool-frontend/playwright/lib/fixtures/createWallet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {
CardanoTestWallet,
CardanoTestWalletConfig,
} from "@cardanoapi/cardano-test-wallet/types";
import { ShelleyWallet } from "@helpers/crypto";
import { Page } from "@playwright/test";

export default async function createWallet(
page: Page,
config?: CardanoTestWalletConfig
) {
const wallet = (await ShelleyWallet.generate()).json();

const initScriptArgs: {
wallet: CardanoTestWallet;
config: CardanoTestWalletConfig;
} = {
wallet,
config: config,
};

await page.addInitScript(({ wallet, config }) => {
window["cardanoTestWallet"] = {
...window["cardanoTestWallet"],
wallet: wallet,
};
if (config) {
window["cardanoTestWallet"]["config"] = {
...window["cardanoTestWallet"]["config"],
...config,
};
}
}, initScriptArgs);
}
14 changes: 14 additions & 0 deletions tests/govtool-frontend/playwright/lib/fixtures/importWallet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { CardanoTestWallet } from "@cardanoapi/cardano-test-wallet/types";
import { Page } from "@playwright/test";
import { StaticWallet } from "@types";

export async function importWallet(
page: Page,
wallet: StaticWallet | CardanoTestWallet
) {
await page.addInitScript((wallet) => {
// @ts-ignore
window.cardanoTestWallet.wallet = wallet;
//@ts-ignore
}, wallet);
}
28 changes: 28 additions & 0 deletions tests/govtool-frontend/playwright/lib/fixtures/loadExtension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { CardanoTestWalletConfig } from "@cardanoapi/cardano-test-wallet/types";
import environments from "@constants/environments";
import { Page } from "@playwright/test";

import path = require("path");

export default async function loadDemosExtension(
page: Page,
enableStakeSigning = false
) {
const demosBundleScriptPath = path.resolve(
__dirname,
"../../node_modules/@cardanoapi/cardano-test-wallet/script.js"
);
let walletConfig: CardanoTestWalletConfig = {
enableStakeSigning,
kuberApiUrl: environments.kuber.apiUrl,
kuberApiKey: environments.kuber.apiKey,
};
await page.addInitScript((walletConfig) => {
window["cardanoTestWallet"] = {
walletName: "demos",
config: walletConfig,
};
}, walletConfig);

await page.addInitScript({ path: demosBundleScriptPath });
}
25 changes: 25 additions & 0 deletions tests/govtool-frontend/playwright/lib/fixtures/walletExtension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { test as base } from "@playwright/test";
import { StaticWallet } from "@types";
import { importWallet } from "./importWallet";
import loadDemosExtension from "./loadExtension";

type WalletExtensionTestOptions = {
wallet?: StaticWallet;
enableStakeSigning: boolean;
};

export const test = base.extend<WalletExtensionTestOptions>({
wallet: [null, { option: true }],

enableStakeSigning: [true, { option: true }],

page: async ({ page, wallet, enableStakeSigning }, use) => {
await loadDemosExtension(page, enableStakeSigning);

if (wallet) {
await importWallet(page, wallet);
}

await use(page);
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Decoder, Encoder } from "cbor-x";

export const cborxEncoder = new Encoder({
mapsAsObjects: false,
useRecords: false,
});
export const cborxDecoder = new Decoder({ mapsAsObjects: false });
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { blake2bHex } from "blakejs";
import { cborxDecoder, cborxEncoder } from "./cborEncodeDecode";

export default function computeTxHash(tx: string) {
let decodedTx = cborxDecoder.decode(Buffer.from(tx, "hex"));
const txBody = Uint8Array.from(cborxEncoder.encode(decodedTx[0]));
return blake2bHex(txBody, undefined, 32);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function convertBufferToHex(buffer: Uint8Array) {
return Buffer.from(buffer).toString("hex");
}

0 comments on commit 36ca534

Please sign in to comment.