diff --git a/apps/idos-sdk-e2e/test/wallet-setup/wallet-setup.setup.ts b/apps/idos-sdk-e2e/test/wallet-setup/wallet-setup.setup.ts new file mode 100644 index 000000000..15585ef74 --- /dev/null +++ b/apps/idos-sdk-e2e/test/wallet-setup/wallet-setup.setup.ts @@ -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"); +}); diff --git a/apps/idos-sdk-e2e/tests/01-evm-auth.spec.ts b/apps/idos-sdk-e2e/tests/01-evm-auth.spec.ts index e907cffa3..017443230 100644 --- a/apps/idos-sdk-e2e/tests/01-evm-auth.spec.ts +++ b/apps/idos-sdk-e2e/tests/01-evm-auth.spec.ts @@ -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"]); @@ -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"); diff --git a/apps/idos-sdk-e2e/tests/02-data.spec.ts b/apps/idos-sdk-e2e/tests/02-data.spec.ts index fb1dfbae0..1ffbcbd57 100644 --- a/apps/idos-sdk-e2e/tests/02-data.spec.ts +++ b/apps/idos-sdk-e2e/tests/02-data.spec.ts @@ -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 }) => { diff --git a/apps/idos-sdk-e2e/tests/03-enclave.spec.ts b/apps/idos-sdk-e2e/tests/03-enclave.spec.ts index af2ff3829..7c4413c0c 100644 --- a/apps/idos-sdk-e2e/tests/03-enclave.spec.ts +++ b/apps/idos-sdk-e2e/tests/03-enclave.spec.ts @@ -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); }); diff --git a/apps/idos-sdk-e2e/tests/04-grants.spec.ts b/apps/idos-sdk-e2e/tests/04-grants.spec.ts index 3c782abcb..74fdf7b97 100644 --- a/apps/idos-sdk-e2e/tests/04-grants.spec.ts +++ b/apps/idos-sdk-e2e/tests/04-grants.spec.ts @@ -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(); +// });