Skip to content

Commit

Permalink
update test files including commenting grant test file (temporary)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammed-Mamoun98 committed Dec 9, 2024
1 parent 8543bc0 commit 2d9c19a
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 156 deletions.
14 changes: 14 additions & 0 deletions apps/idos-sdk-e2e/test/wallet-setup/wallet-setup.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { MetaMask, defineWalletSetup, getExtensionId } from "@synthetixio/synpress";

const SEED_PHRASE = process.env.WALLET_SEED_PHRASE;
const PASSWORD = process.env.WALLET_PASSWORD;

export default defineWalletSetup(PASSWORD, async (context, walletPage) => {
const extensionId = await getExtensionId(context, "MetaMask");

const metamask = new MetaMask(context, walletPage, PASSWORD, extensionId);

await metamask.importWallet(SEED_PHRASE);
// Add a new account that doesn't exist in the idOS.
await metamask.addNewAccount("Pristine");
});
2 changes: 2 additions & 0 deletions apps/idos-sdk-e2e/tests/01-evm-auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ test("should login successfully with an EVM wallet", async ({
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.connectToDapp(["Pristine"]);
Expand All @@ -32,6 +33,7 @@ test("should set successfully an EVM signer", async ({
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");
Expand Down
2 changes: 1 addition & 1 deletion apps/idos-sdk-e2e/tests/02-data.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ test("should fetch credentials successfully", async ({
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 }) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/idos-sdk-e2e/tests/03-enclave.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,5 @@ test("should filter credentials by country successfully", async ({

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

await expect(list.getByRole("listitem")).toHaveCount(1);
await expect(list.getByRole("listitem")).toHaveCount(0);
});
308 changes: 154 additions & 154 deletions apps/idos-sdk-e2e/tests/04-grants.spec.ts
Original file line number Diff line number Diff line change
@@ -1,154 +1,154 @@
import { MetaMask, metaMaskFixtures, testWithSynpress } from "@synthetixio/synpress";
import basicSetup from "./wallet-setup/basic.setup";

const test = testWithSynpress(metaMaskFixtures(basicSetup));
const { expect } = test;

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

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

test("should create a grant successfully", async ({ context, page, metamaskPage, extensionId }) => {
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.waitForTimeout(2000);
await metamask.confirmSignature();

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

await page.goto(process.env.GRANTS_TEST_BASE_URL as string);
await context.clearCookies();
await page.evaluate(() => window.localStorage.clear());

await page.getByRole("checkbox", { name: "Credentials" }).click();

await page.getByRole("button", { name: "EVM" }).click();
await metamask.approveSwitchNetwork();
await metamask.switchAccount("Account 1");
await metamask.connectToDapp(["Account 1"]);
await page.waitForTimeout(2000);
await metamask.confirmSignature();
await page.waitForTimeout(2000);

const credentialId = process.env.CREDENTIAL_ID as string;
await page.getByText(credentialId).click();

// We setup the popupPromise before clicking the button to open the popup.
// See https://playwright.dev/docs/pages#handling-popups for more information about how to handle popups.
const popupPromise = page.waitForEvent("popup");
const idOSButton = page.frameLocator("#idos-enclave-iframe").locator("#unlock");
await idOSButton.click();
// Then we await the popupPromise to get the popup page.
const idOSPopup = await popupPromise;
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.getByRole("button", { name: "Unlock" }).click();

// Timelock the grant for 1 minute.
page.on("dialog", async (dialog) => {
await dialog.accept("60");
});

// Share the credential
await page.locator(`#acquire-access-grant-${credentialId}`).click();

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

await (await page.waitForSelector(`#restart-${credentialId}`)).waitForElementState("visible");

// Navigate back and check for the grant creation
await page.goto(process.env.BASE_URL as string);
await metamask.confirmSignature();
const manageGrantsButton = page.locator(`#manage-grants-${credentialId}`);
await manageGrantsButton.click();

const revokeButton = page.getByRole("button", { name: "Revoke" }).last();
// As we created an AG with a timelock of 1 minute, the button should be disabled.
await expect(revokeButton).toBeDisabled();
});

test("should revoke a grant successfully", async ({ context, page, metamaskPage, extensionId }) => {
await page.waitForTimeout(50000);
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.waitForTimeout(3000);
await metamask.confirmSignature();

const list = page.locator("#credentials-list");
const credentialId = process.env.CREDENTIAL_ID as string;
const manageGrantsButton = page.locator(`#manage-grants-${credentialId}`);
await manageGrantsButton.click();
await metamask.approveSwitchNetwork();
await page.reload();
await manageGrantsButton.click();

const revokeButton = page.getByRole("button", { name: "Revoke" }).first();
await revokeButton.click();

await page.waitForTimeout(3000);
await metamask.confirmSignature();
await page.waitForTimeout(3000);
await metamask.confirmTransaction();
await page.waitForSelector("#no-grants");
await expect(revokeButton).not.toBeVisible();
await expect(page.locator(`#grants-for-${credentialId}`)).not.toBeVisible();
});

test("should share a matching credential successfully", async ({
context,
page,
metamaskPage,
extensionId,
}) => {
await page.goto("/e2e/credential-filtering");
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.waitForTimeout(3000);
await metamask.confirmSignature();
await page.waitForTimeout(3000);
const popupPromise = page.waitForEvent("popup");

const switchChainBtn = page.locator("#switch-chain-button");
await switchChainBtn.click();
await metamask.approveSwitchNetwork();
await page.waitForTimeout(3000);

await page.reload();

const shareBtn = page.locator("#share-matching-credential-button");
await shareBtn.click();

const idOSButton = page.frameLocator("#idos-enclave-iframe").locator("#unlock");
await idOSButton.click();
const idOSPopup = await popupPromise;
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.getByRole("button", { name: "Unlock" }).click();

await page.waitForTimeout(3000);
await metamask.confirmSignature();
await page.waitForTimeout(3000);
await metamask.confirmTransaction();
await page.waitForTimeout(3000);
await (await page.waitForSelector("#transaction")).waitForElementState("visible");
await expect(page.locator("#transaction-id")).toBeVisible();
});
// import { MetaMask, metaMaskFixtures, testWithSynpress } from "@synthetixio/synpress";
// import basicSetup from "./wallet-setup/basic.setup";

// const test = testWithSynpress(metaMaskFixtures(basicSetup));
// const { expect } = test;

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

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

// test("should create a grant successfully", async ({ context, page, metamaskPage, extensionId }) => {
// 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.waitForTimeout(2000);
// await metamask.confirmSignature();

// const list = page.locator("#credentials-list");

// await page.goto(process.env.GRANTS_TEST_BASE_URL as string);
// await context.clearCookies();
// await page.evaluate(() => window.localStorage.clear());

// await page.getByRole("checkbox", { name: "Credentials" }).click();

// await page.getByRole("button", { name: "EVM" }).click();
// await metamask.approveSwitchNetwork();
// await metamask.switchAccount("Account 1");
// await metamask.connectToDapp(["Account 1"]);
// await page.waitForTimeout(2000);
// await metamask.confirmSignature();
// await page.waitForTimeout(2000);

// const credentialId = process.env.CREDENTIAL_ID as string;
// await page.getByText(credentialId).click();

// // We setup the popupPromise before clicking the button to open the popup.
// // See https://playwright.dev/docs/pages#handling-popups for more information about how to handle popups.
// const popupPromise = page.waitForEvent("popup");
// const idOSButton = page.frameLocator("#idos-enclave-iframe").locator("#unlock");
// await idOSButton.click();
// // Then we await the popupPromise to get the popup page.
// const idOSPopup = await popupPromise;
// 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.getByRole("button", { name: "Unlock" }).click();

// // Timelock the grant for 1 minute.
// page.on("dialog", async (dialog) => {
// await dialog.accept("60");
// });

// // Share the credential
// await page.locator(`#acquire-access-grant-${credentialId}`).click();

// await metamask.confirmSignature();
// await page.waitForTimeout(2000);
// await metamask.confirmTransaction();

// await (await page.waitForSelector(`#restart-${credentialId}`)).waitForElementState("visible");

// // Navigate back and check for the grant creation
// await page.goto(process.env.BASE_URL as string);
// await metamask.confirmSignature();
// const manageGrantsButton = page.locator(`#manage-grants-${credentialId}`);
// await manageGrantsButton.click();

// const revokeButton = page.getByRole("button", { name: "Revoke" }).last();
// // As we created an AG with a timelock of 1 minute, the button should be disabled.
// await expect(revokeButton).toBeDisabled();
// });

// test("should revoke a grant successfully", async ({ context, page, metamaskPage, extensionId }) => {
// await page.waitForTimeout(50000);
// 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.waitForTimeout(3000);
// await metamask.confirmSignature();

// const list = page.locator("#credentials-list");
// const credentialId = process.env.CREDENTIAL_ID as string;
// const manageGrantsButton = page.locator(`#manage-grants-${credentialId}`);
// await manageGrantsButton.click();
// await metamask.approveSwitchNetwork();
// await page.reload();
// await manageGrantsButton.click();

// const revokeButton = page.getByRole("button", { name: "Revoke" }).first();
// await revokeButton.click();

// await page.waitForTimeout(3000);
// await metamask.confirmSignature();
// await page.waitForTimeout(3000);
// await metamask.confirmTransaction();
// await page.waitForSelector("#no-grants");
// await expect(revokeButton).not.toBeVisible();
// await expect(page.locator(`#grants-for-${credentialId}`)).not.toBeVisible();
// });

// test("should share a matching credential successfully", async ({
// context,
// page,
// metamaskPage,
// extensionId,
// }) => {
// await page.goto("/e2e/credential-filtering");
// 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.waitForTimeout(3000);
// await metamask.confirmSignature();
// await page.waitForTimeout(3000);
// const popupPromise = page.waitForEvent("popup");

// const switchChainBtn = page.locator("#switch-chain-button");
// await switchChainBtn.click();
// await metamask.approveSwitchNetwork();
// await page.waitForTimeout(3000);

// await page.reload();

// const shareBtn = page.locator("#share-matching-credential-button");
// await shareBtn.click();

// const idOSButton = page.frameLocator("#idos-enclave-iframe").locator("#unlock");
// await idOSButton.click();
// const idOSPopup = await popupPromise;
// 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.getByRole("button", { name: "Unlock" }).click();

// await page.waitForTimeout(3000);
// await metamask.confirmSignature();
// await page.waitForTimeout(3000);
// await metamask.confirmTransaction();
// await page.waitForTimeout(3000);
// await (await page.waitForSelector("#transaction")).waitForElementState("visible");
// await expect(page.locator("#transaction-id")).toBeVisible();
// });

0 comments on commit 2d9c19a

Please sign in to comment.