Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/integration tests #1103

Merged
merged 30 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0aa864c
Remove `2F. change delegation` test dependency with 2A
NabinKawan May 23, 2024
83e48c4
refactor: Move 'DRep register and delegation' to beforeAll
NabinKawan May 23, 2024
812dabd
fix: Make 2I and 2J tests dRep dependent
NabinKawan May 23, 2024
e8c2c40
fix: Test 3F_ DRep_registration request
NabinKawan May 23, 2024
f33ec25
test: Update DRep data
NabinKawan May 23, 2024
2900ff5
Verify voting power in DRep retired state
NabinKawan May 23, 2024
8d9ffee
fix: Test 3L_Invalid_url
kneerose May 24, 2024
1ff8cf6
fix: Test 2A and 2F timeout issue
kneerose May 24, 2024
f72befe
Handle waitForTXConfirmation with a try-catch block.
kneerose May 24, 2024
dfdfe8a
Remove the balance check from the fund faucet wallet
kneerose May 24, 2024
d5276ed
Add the missing allure story categorized.
kneerose May 24, 2024
3516142
Add adaHolder for multiple delegation
kneerose May 24, 2024
033efc6
Remove logged in project for mobile
kneerose May 24, 2024
5d4f83e
Change test 1D reject wallet connection logic
kneerose May 24, 2024
ac0f08f
Remove unwanted tests (6B and 6D)
NabinKawan May 24, 2024
649159e
fix: Test 4F_ DRep functionality on governance_actions page
NabinKawan May 24, 2024
dca8a4e
Mark test 3E_DRep form validation as slow
NabinKawan May 24, 2024
ac2ccfd
Remove tests walletConnect and proposalSubmissionVisibility from mobile
NabinKawan May 24, 2024
3986402
Upload lock logs to artifact
NabinKawan May 24, 2024
efa3562
Refactor: Replace DRep automatic delegations with AdaHolder
NabinKawan May 24, 2024
f574f81
Add walletManager & Refactor lockInterceptor
NabinKawan May 27, 2024
49d34a6
Optimize test to reduce execution time
NabinKawan May 27, 2024
3ddfbab
Move faucet setup into global setup
NabinKawan May 28, 2024
0cb9e04
Create Adaholder 05 auth for multiple delegation
kneerose May 28, 2024
8004452
Refactor test 2C, 2S and 3H
kneerose May 28, 2024
9933bf0
test: Add check vote count
kneerose May 28, 2024
ad0abcb
fix: Flaky tests (proposal visibility)
NabinKawan May 28, 2024
20c4174
fix: Environments and path issue
NabinKawan May 28, 2024
a4c9986
Register static DReps in single tx
NabinKawan May 28, 2024
011b95b
Handle proper error for delegation & stake registration
NabinKawan May 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/test_integration_playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ jobs:
name: allure-results
path: tests/govtool-frontend/playwright/allure-results

- name: Upload lock logs
uses: actions/upload-artifact@v3
if: always()
with:
name: lock-logs
path: tests/govtool-frontend/playwright/lock_logs.txt

env:
HOST_URL: https://${{inputs.deployment || 'govtool.cardanoapi.io' }}
API_URL: https://${{inputs.deployment || 'govtool.cardanoapi.io' }}/api
Expand Down
4 changes: 3 additions & 1 deletion tests/govtool-frontend/playwright/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ allure-report/
.vars
.lock-pool/
.logs/
lib/_mock/wallets.json
lib/_mock/*.json

./lock_logs.txt
49 changes: 49 additions & 0 deletions tests/govtool-frontend/playwright/global-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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(5);

// 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;
24 changes: 24 additions & 0 deletions tests/govtool-frontend/playwright/lib/_mock/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,30 @@ export const invalid = {
return `${scheme}://${randomDomain}`;
},

name: () => {
const choice = faker.number.int({ min: 1, max: 3 });
if (choice === 1) {
// space invalid
return faker.lorem.word() + " " + faker.lorem.word();
} else if (choice === 2) {
// maximum 80 words invalid
return faker.lorem.paragraphs().replace(/\s+/g, "");
}
// empty invalid
return " ";
},

email: () => {
const choice = faker.number.int({ min: 1, max: 3 });

if (choice === 1) {
return faker.lorem.word() + faker.number + "@invalid.com";
} else if (choice == 2) {
return faker.lorem.word() + "@";
}
return faker.lorem.word() + "@gmail_com";
},

proposalTitle: () => {
const choice = faker.number.int({ min: 1, max: 2 });
if (choice === 1) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { config } from "dotenv";
config();

const CARDANO_API_METADATA_HOST_URL =
process.env.CARDANOAPI_METADATA_URL ||
"https://metadata-govtool.cardanoapi.io";
Expand All @@ -21,6 +24,7 @@ const environments = {
txTimeOut: parseInt(process.env.TX_TIMEOUT) || 240000,
metadataBucketUrl: `${CARDANO_API_METADATA_HOST_URL}/data`,
lockInterceptorUrl: `${CARDANO_API_METADATA_HOST_URL}/lock`,
ci: process.env.CI,
};

export default environments;
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const adaHolder01Wallet = staticWallets[3];
export const adaHolder02Wallet = staticWallets[4];
export const adaHolder03Wallet = staticWallets[6];
export const adaHolder04Wallet = staticWallets[7];
export const adaHolder05Wallet = staticWallets[8];

// Does not takes part in transaction
export const user01Wallet: StaticWallet = staticWallets[5];
Expand All @@ -19,6 +20,7 @@ export const adaHolderWallets = [
adaHolder02Wallet,
adaHolder03Wallet,
adaHolder04Wallet,
adaHolder05Wallet,
];

export const userWallets = [user01Wallet];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import { importWallet } from "@fixtures/importWallet";
import { ShelleyWallet } from "@helpers/crypto";
import LoginPage from "@pages/loginPage";
import { Page } from "@playwright/test";
import { StaticWallet } from "@types";

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());
export async function createTempDRepAuth(page: Page, wallet: StaticWallet) {
await importWallet(page, wallet);

const loginPage = new LoginPage(page);
await loginPage.login();
Expand Down
13 changes: 13 additions & 0 deletions tests/govtool-frontend/playwright/lib/helpers/crypto.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import environments from "../constants/environments";
import { ed25519 as ed } from "@noble/curves/ed25519";
import { bech32 } from "bech32";
import * as blake from "blakejs";
Expand Down Expand Up @@ -130,10 +131,22 @@ export class ShelleyWallet {
200
);
}

dRepIdBech32() {
const stakePubKey = Buffer.from(this.stakeKey.public).toString("hex");
const dRepKeyBytes = Buffer.from(stakePubKey, "hex");
const dRepId = blake.blake2bHex(dRepKeyBytes, undefined, 28);
const words = bech32.toWords(Buffer.from(dRepId, "hex"));
const dRepIdBech32 = bech32.encode("drep", words);
return dRepIdBech32;
}

public json() {
return {
payment: this.paymentKey.json(),
stake: this.stakeKey.json(),
dRepId: this.dRepIdBech32(),
address: this.addressBech32(environments.networkId),
};
}

Expand Down
8 changes: 4 additions & 4 deletions tests/govtool-frontend/playwright/lib/helpers/page.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { importWallet } from "@fixtures/importWallet";
import loadDemosExtension from "@fixtures/loadExtension";
import { Browser, Page, expect } from "@playwright/test";
import { ShelleyWallet } from "./crypto";
import { Browser, Page } from "@playwright/test";
import { StaticWallet } from "@types";

interface BrowserConfig {
storageState: string;
wallet: ShelleyWallet;
wallet: StaticWallet;
enableStakeSigning?: boolean;
}

Expand All @@ -19,7 +19,7 @@ export async function createNewPageWithWallet(
const newPage = await context.newPage();

await loadDemosExtension(newPage, enableStakeSigning);
await importWallet(newPage, wallet.json());
await importWallet(newPage, wallet);

return newPage;
}
57 changes: 31 additions & 26 deletions tests/govtool-frontend/playwright/lib/helpers/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ export async function pollTransaction(

if (!lockInfo) return;

await LockInterceptor.releaseLockForAddress(
lockInfo.address,
await LockInterceptor.releaseLock(
lockInfo.initiator,
lockInfo.lockId,
`Task completed for:${lockInfo.lockId}`
);
} catch (err) {
if (lockInfo) {
const errorMessage = { lockInfo, error: JSON.stringify(err) };

await LockInterceptor.releaseLockForAddress(
lockInfo.address,
await LockInterceptor.releaseLock(
lockInfo.initiator,
lockInfo.lockId,
`Task failure: \n${JSON.stringify(errorMessage)}`
);
Expand All @@ -58,30 +58,35 @@ export async function waitForTxConfirmation(
triggerCallback?: () => Promise<void>
) {
let transactionHash: string | undefined;
const transactionStatusPromise = page.waitForRequest((request) => {
return request.url().includes("/transaction/status/");
});

await triggerCallback?.call(this);
await expect(
page
.getByTestId("alert-warning")
.getByText("Transaction in progress", { exact: false })
).toBeVisible({
timeout: 10_000,
});
const url = (await transactionStatusPromise).url();
const regex = /\/transaction\/status\/([^\/]+)$/;
const match = url.match(regex);
if (match) {
transactionHash = match[1];
}
try {
await triggerCallback?.call(this);
const transactionStatusPromise = page.waitForRequest((request) => {
return request.url().includes("/transaction/status/");
});

if (transactionHash) {
await pollTransaction(transactionHash);
await expect(
page.getByText("In Progress", { exact: true }).first() //FIXME: Only one element needs to be displayed
).not.toBeVisible({ timeout: 20_000 });
page
.getByTestId("alert-warning")
.getByText("Transaction in progress", { exact: false })
).toBeVisible({
timeout: 10_000,
});
const url = (await transactionStatusPromise).url();
const regex = /\/transaction\/status\/([^\/]+)$/;
const match = url.match(regex);
if (match) {
transactionHash = match[1];
}

if (transactionHash) {
await pollTransaction(transactionHash);
await expect(
page.getByText("In Progress", { exact: true }).first() //FIXME: Only one element needs to be displayed
).not.toBeVisible({ timeout: 20_000 });
}
} catch (error) {
Logger.fail(error.message);
throw new Error(error);
}
}

Expand Down
Loading