Skip to content

Commit

Permalink
update e2e test (not confirmed yet)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammed-Mamoun98 committed Dec 2, 2024
1 parent 76c4c10 commit 3e77d9b
Show file tree
Hide file tree
Showing 4 changed files with 295 additions and 276 deletions.
55 changes: 30 additions & 25 deletions apps/idos-sdk-e2e/tests/01-evm-auth.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { MetaMask, metaMaskFixtures, testWithSynpress } from "@synthetixio/synpress";
import basicSetup from "./wallet-setup/basic.setup";
import { testWithSynpress } from "@synthetixio/synpress";
import { MetaMask, metaMaskFixtures } from "@synthetixio/synpress/playwright";
import basicSetup from "../test/wallet-setup/wallet-setup.setup";

const test = testWithSynpress(metaMaskFixtures(basicSetup));

Expand All @@ -11,37 +12,41 @@ test.beforeEach(async ({ context, page }) => {
await page.evaluate(() => window.localStorage.clear());
});

test("should login successfully with an EVM wallet", async ({
context,
page,
metamaskPage,
extensionId,
}) => {
const metamask = new MetaMask(context, metamaskPage, basicSetup.walletPassword, extensionId);
test("should login successfully with an EVM wallet", async ({ context, page, extensionId }) => {
const metamask = new MetaMask(context, page, basicSetup.walletPassword, extensionId);
await page.goto("/");

await page.getByRole("button", { name: "Connect a wallet" }).click();
await page.getByRole("button", { name: "Metamask" }).click();
await metamask.connectToDapp(["Pristine"]);
await page.getByRole("button", { name: "Metamask" }).first().click();

await metamask.connectToDapp();
await page.waitForTimeout(2000);
await metamask.confirmSignature();

await expect(page.locator("#disconnect-wallet-btn")).toBeVisible();
});

test("should set successfully an EVM signer", async ({
context,
page,
metamaskPage,
extensionId,
}) => {
const metamask = new MetaMask(context, metamaskPage, basicSetup.walletPassword, extensionId);
// @ts-ignore
test("should set successfully an EVM signer", async ({ context, page, extensionId }) => {
const metamask = new MetaMask(context, page, basicSetup.walletPassword, extensionId);

await page.goto("/");
await page.getByRole("button", { name: "Connect a wallet" }).click();
await page.getByRole("button", { name: "Metamask" }).click();
await metamask.switchAccount("Account 1");
await metamask.connectToDapp(["Account 1"]);
await page.getByRole("button", { name: "Metamask" }).first().click();

await metamask.connectToDapp();
await page.waitForTimeout(2000);
await metamask.confirmSignature();

const signer = await page.evaluate(() =>
JSON.parse(window.localStorage.getItem("idOS-signer-address") ?? ""),
const [connectedWallet] = await page.evaluate(() =>
// @ts-ignore for some reason using metamask.getAddress() is not working
ethereum.request({
method: "eth_accounts",
params: [],
}),
);
const idosSigner = await page.evaluate(() =>
JSON.parse(localStorage.getItem("idOS-signer-address")!),
);
const address = await metamask.getAccountAddress();
expect(signer).toEqual(address);
expect(connectedWallet.toLowerCase()).toEqual(idosSigner.toLowerCase());
});
136 changes: 77 additions & 59 deletions apps/idos-sdk-e2e/tests/02-data.spec.ts
Original file line number Diff line number Diff line change
@@ -1,82 +1,100 @@
import { MetaMask, metaMaskFixtures, testWithSynpress } from "@synthetixio/synpress";
import basicSetup from "./wallet-setup/basic.setup";
import { testWithSynpress } from "@synthetixio/synpress";
import { MetaMask, metaMaskFixtures } from "@synthetixio/synpress/playwright";
import basicSetup from "../test/wallet-setup/wallet-setup.setup";

const test = testWithSynpress(metaMaskFixtures(basicSetup));

const { expect } = test;

test.beforeEach(async ({ context, page }) => {
test.setTimeout(120000);

await context.clearCookies();
await page.evaluate(() => window.localStorage.clear());
});

const TEST_WALLET_ADDRESS = "0xB5B3a244943E5A64511673528e003BE79B18901a";
const TEST_WALLET_ADDRESS = "0x8Bf421D4fe039000981ee77163eF777718af68e3";

test("should fetch credentials successfully", async ({ context, page, extensionId }) => {
const metamask = new MetaMask(context, page, basicSetup.walletPassword, extensionId);

test("should fetch credentials successfully", async ({
context,
page,
metamaskPage,
extensionId,
}) => {
const metamask = new MetaMask(context, metamaskPage, basicSetup.walletPassword, extensionId);
await page.goto("/");
await page.getByRole("button", { name: "Connect a wallet" }).click();
await page.getByRole("button", { name: "Metamask" }).click();
await metamask.switchAccount("Account 1");
await metamask.connectToDapp(["Account 1"]);
await page.getByRole("button", { name: "Metamask" }).first().click();

await metamask.connectToDapp();
await page.waitForTimeout(2000);
await metamask.confirmSignature();

const list = page.locator("#credentials-list");
await expect(list.getByRole("listitem")).toHaveCount(2);
await expect(list.getByRole("listitem")).toHaveCount(3);
});

test("should fetch wallets successfully", async ({ context, page, metamaskPage, extensionId }) => {
await page.goto("/wallets");
const metamask = new MetaMask(context, metamaskPage, basicSetup.walletPassword, extensionId);
test("should fetch wallets successfully", async ({ context, page, extensionId }) => {
await page.goto("/");
const metamask = new MetaMask(context, page, basicSetup.walletPassword, extensionId);

await page.getByRole("button", { name: "Connect a wallet" }).click();
await page.getByRole("button", { name: "Metamask" }).click();
await metamask.switchAccount("Account 1");
await metamask.connectToDapp(["Account 1"]);
await page.waitForTimeout(3000);
await page.getByRole("button", { name: "Metamask" }).first().click();

await metamask.connectToDapp();
await page.waitForTimeout(2000);
await metamask.confirmSignature();
const list = page.locator("#wallets-list");
await expect(list.getByRole("listitem")).toHaveCount(1);
const address = await metamask.getAccountAddress();
await expect(list.getByRole("listitem").first().locator("p").last()).toHaveText(
address.toLocaleLowerCase(), // The address is stored in lowercase format in the idOS so we need to normalize the MetaMask address.
);
});

test("should add / delete a wallet successfully", async ({
context,
page,
metamaskPage,
extensionId,
}) => {
await page.goto("/wallets");
const metamask = new MetaMask(context, metamaskPage, basicSetup.walletPassword, extensionId);
await page.getByRole("button", { name: "Connect a wallet" }).click();
await page.getByRole("button", { name: "Metamask" }).click();
await metamask.switchAccount("Account 1");
await metamask.connectToDapp(["Account 1"]);
await page.getByTestId("wallets-link").click();
await page.waitForTimeout(3000);
await metamask.confirmSignature();
// Testing wallet addition
const addWalletButton = page.locator("#add-wallet-button");
await addWalletButton.click();
await page.locator("#address").fill(TEST_WALLET_ADDRESS);
await page.locator("#add-wallet-form-submit").click();
await metamask.confirmSignature();
await page.waitForTimeout(5000);
const list = page.locator("#wallets-list");
await expect(list.getByRole("listitem")).toHaveCount(2);

// Testing wallet deletion
const deleteButton = list.locator(`#delete-wallet-${TEST_WALLET_ADDRESS}`);
await deleteButton.click();
await page.locator(`#confirm-delete-wallet-${TEST_WALLET_ADDRESS}`).click();
await metamask.confirmSignature();
await page.waitForTimeout(5000);
await expect(list.getByRole("listitem")).toHaveCount(1);

const walletListItems = await page.getByTestId("wallet-card");
const walletListItemsCount = await walletListItems.count();

const [connectedWallet] = await page.evaluate(() =>
// @ts-ignore for some reason using metamask.getAddress() is not working
ethereum.request({
method: "eth_accounts",
params: [],
}),
);
await expect(walletListItemsCount).toBeGreaterThanOrEqual(1);
// Check if the connected wallet exists in the list
let walletFound = false;

for (let i = 0; i < walletListItemsCount; i++) {
const walletText = await walletListItems.nth(i).getByTestId("wallet-address").textContent();

if (walletText.toLowerCase() === connectedWallet.toLowerCase()) {
walletFound = true;
break;
}
}
expect(walletFound).toBeTruthy();
});

// test("should add / delete a wallet successfully", async ({
// context,
// page,
// }) => {
// await page.goto("/wallets");
// const metamask = new MetaMask(context, page, basicSetup.walletPassword);
// await page.getByRole("button", { name: "Connect a wallet" }).click();
// await page.getByRole("button", { name: "Metamask" }).first().click();
// await metamask.switchAccount("Account 1");
// await metamask.connectToDapp(["Account 1"]);
// await page.waitForTimeout(3000);
// await metamask.confirmSignature();
// // Testing wallet addition
// const addWalletButton = page.locator("#add-wallet-button");
// await addWalletButton.click();
// await page.locator("#address").fill(TEST_WALLET_ADDRESS);
// await page.locator("#add-wallet-form-submit").click();
// await metamask.confirmSignature();
// await page.waitForTimeout(5000);
// const list = page.locator("#wallets-list");
// await expect(list.getByRole("listitem")).toHaveCount(2);

// // Testing wallet deletion
// const deleteButton = list.locator(`#delete-wallet-${TEST_WALLET_ADDRESS}`);
// await deleteButton.click();
// await page.locator(`#confirm-delete-wallet-${TEST_WALLET_ADDRESS}`).click();
// await metamask.confirmSignature();
// await page.waitForTimeout(5000);
// await expect(list.getByRole("listitem")).toHaveCount(1);
// });
72 changes: 34 additions & 38 deletions apps/idos-sdk-e2e/tests/03-enclave.spec.ts
Original file line number Diff line number Diff line change
@@ -1,72 +1,68 @@
import { MetaMask, metaMaskFixtures, testWithSynpress } from "@synthetixio/synpress";
import basicSetup from "./wallet-setup/basic.setup";

// @todo: This should be created from the sdk instead of relying on hardcoded values.
const credentialContent = process.env.CREDENTIAL_CONTENT as string;
import { testWithSynpress } from "@synthetixio/synpress";
import { MetaMask, metaMaskFixtures } from "@synthetixio/synpress/playwright";
import basicSetup from "../test/wallet-setup/wallet-setup.setup";

const test = testWithSynpress(metaMaskFixtures(basicSetup));
// const credentialContent = process.env.CREDENTIAL_CONTENT as string;

const { expect } = test;

test.beforeEach(async ({ context, page }) => {
test.setTimeout(120000);

await context.clearCookies();
await page.evaluate(() => window.localStorage.clear());
});

test("should decrypt a credential successfully", async ({
context,
page,
metamaskPage,
extensionId,
}) => {
const metamask = new MetaMask(context, metamaskPage, basicSetup.walletPassword, extensionId);
test("should decrypt a credential successfully", async ({ context, page, extensionId }) => {
const metamask = new MetaMask(context, page, basicSetup.walletPassword, extensionId);
await page.getByRole("button", { name: "Connect a wallet" }).click();
await page.getByRole("button", { name: "Metamask" }).click();
await metamask.switchAccount("Account 1");
await metamask.connectToDapp(["Account 1"]);
await page.getByRole("button", { name: "Metamask" }).first().click();

await metamask.connectToDapp();
await page.waitForTimeout(2000);
await metamask.confirmSignature();
const popupPromise = page.waitForEvent("popup");
await page.waitForTimeout(2000);

await page.getByRole("button", { name: "View details" }).first().click();
const idOSButton = page.frameLocator("#idos-enclave-iframe").locator("#unlock");
const idOSButton = page.frameLocator("#idos-enclave-iframe").first().locator("#unlock");
await idOSButton.click();
const idOSPopup = await popupPromise;
const idOSPopup = await page.waitForEvent("popup");
await page.waitForTimeout(2000);
await (await idOSPopup.waitForSelector("#auth-method-password")).click();
const passwordInput = idOSPopup.locator("#idos-password-input");
await passwordInput.fill("qwerty");
// await (await idOSPopup.waitForSelector("#auth-method-password")).click();
await idOSPopup.locator("#auth-method-password").click();

const passwordInput = await idOSPopup.locator("#idos-password-input");
await passwordInput.fill("752@Hi-idos");
await idOSPopup.getByRole("button", { name: "Unlock" }).click();

const code = page.locator("#credential-details");
await expect(code).toHaveText(credentialContent);
const code = await page.locator("#credential-details").textContent();
const parsedContent = JSON.parse(code);
expect(parsedContent).toHaveProperty("@context");
});

test("should filter credentials by country successfully", async ({
context,
page,
metamaskPage,
extensionId,
}) => {
const metamask = new MetaMask(context, metamaskPage, basicSetup.walletPassword, extensionId);
await page.goto("e2e/credential-filtering-by-country");

await page.goto("/e2e/credential-filtering-by-country?country=PS");
const metamask = new MetaMask(context, page, basicSetup.walletPassword, extensionId);
await page.getByRole("button", { name: "Connect a wallet" }).click();
await page.getByRole("button", { name: "Metamask" }).click();
await metamask.switchAccount("Account 1");
await metamask.connectToDapp(["Account 1"]);
await page.getByRole("button", { name: "Metamask" }).first().click();

await metamask.connectToDapp();
await page.waitForTimeout(2000);
await metamask.confirmSignature();
await page.waitForTimeout(2000);

const popupPromise = page.waitForEvent("popup");

const idOSButton = page.frameLocator("#idos-enclave-iframe").locator("#unlock");
const idOSButton = page.frameLocator("#idos-enclave-iframe").first().locator("#unlock");
await idOSButton.click();
const idOSPopup = await popupPromise;
const idOSPopup = await page.waitForEvent("popup");
await page.waitForTimeout(2000);
await (await idOSPopup.waitForSelector("#auth-method-password")).click();
const passwordInput = idOSPopup.locator("#idos-password-input");
await passwordInput.fill("qwerty");
await idOSPopup.locator("#auth-method-password").click();

const passwordInput = await idOSPopup.locator("#idos-password-input");
await passwordInput.fill("752@Hi-idos");
await idOSPopup.getByRole("button", { name: "Unlock" }).click();

const list = page.locator("#credentials-list");
Expand Down
Loading

0 comments on commit 3e77d9b

Please sign in to comment.