From ded08a9e294e8dd8d3977568d51666360c8947c2 Mon Sep 17 00:00:00 2001 From: bluecco Date: Fri, 6 Dec 2024 13:23:43 +0100 Subject: [PATCH 01/18] chore: webwallet e2e test for tx and sign --- e2e/src/webwallet/config.ts | 8 +- e2e/src/webwallet/page-objects/Dapps.ts | 85 ++++++++++++++++--- e2e/src/webwallet/specs/connect.spec.ts | 28 ++++++ e2e/src/webwallet/specs/dapps.spec.ts | 15 ---- e2e/src/webwallet/specs/signMessage.spec.ts | 17 ++++ e2e/src/webwallet/specs/transactions.spec.ts | 32 +++++++ src/components/sections/SignMessage.tsx | 22 ++--- .../sections/Transactions/SendERC20.tsx | 4 +- .../sections/Transactions/SendMulticall.tsx | 4 +- 9 files changed, 173 insertions(+), 42 deletions(-) create mode 100644 e2e/src/webwallet/specs/connect.spec.ts delete mode 100644 e2e/src/webwallet/specs/dapps.spec.ts create mode 100644 e2e/src/webwallet/specs/signMessage.spec.ts create mode 100644 e2e/src/webwallet/specs/transactions.spec.ts diff --git a/e2e/src/webwallet/config.ts b/e2e/src/webwallet/config.ts index 0781b2e..9258436 100644 --- a/e2e/src/webwallet/config.ts +++ b/e2e/src/webwallet/config.ts @@ -14,9 +14,11 @@ const config = { password: process.env.WW_LOGIN_PASSWORD!, }, emailPassword: process.env.EMAIL_PASSWORD!, - acc_destination: commonConfig.destinationAddress! || '', - vw_acc_addr: process.env.VW_ACC_ADDR! || '', - url: "https://web.argent.xyz", + acc_destination: commonConfig.destinationAddress! || "", + vw_acc_addr: process.env.VW_ACC_ADDR! || "", + url: commonConfig.isProdTesting + ? "https://web.argent.xyz" + : "https://web-v2.hydrogen.argent47.net", ...commonConfig, } diff --git a/e2e/src/webwallet/page-objects/Dapps.ts b/e2e/src/webwallet/page-objects/Dapps.ts index af17222..fd74eae 100644 --- a/e2e/src/webwallet/page-objects/Dapps.ts +++ b/e2e/src/webwallet/page-objects/Dapps.ts @@ -5,46 +5,53 @@ import { artifactsDir } from "../../shared/cfg/test" import { randomUUID } from "crypto" import SapoEmailClient from "../../shared/src/SapoEmailClient" import config from "../config" -const dappUrl = 'http://localhost:3000/' +const dappUrl = "http://localhost:3000/" let mailClient: SapoEmailClient export default class Dapps extends Navigation { constructor(page: Page) { super(page) - mailClient = new SapoEmailClient(config.validLogin.email, config.emailPassword); + mailClient = new SapoEmailClient( + config.validLogin.email, + config.emailPassword, + ) } async requestConnectionFromDapp({ dApp, credentials, newAccount = false, - useStarknetKitModal = false + useStarknetKitModal = false, }: { dApp: Page credentials: ICredentials newAccount: boolean useStarknetKitModal?: boolean }) { - await dApp.setViewportSize({ width: 1080, height: 720 }) await dApp.goto(dappUrl) - await dApp.getByRole('button', { name: 'Connection' }).click() + await dApp.getByRole("button", { name: "Connection" }).click() if (useStarknetKitModal) { - await dApp.getByRole('button', { name: 'Starknetkit Modal' }).click() + await dApp.getByRole("button", { name: "Starknetkit Modal" }).click() const popup = await this.handlePopup(dApp, credentials, newAccount) await this.verifyEmailInPopup(popup, credentials.email) await popup.locator('button[type="submit"]').click() } else { - const pagePromise = dApp.context().waitForEvent('page'); - await dApp.locator('button :text-is("Argent Web Wallet")').click(); - const newPage = await pagePromise; + const pagePromise = dApp.context().waitForEvent("page") + await dApp.locator('button :text-is("Argent Web Wallet")').click() + const newPage = await pagePromise await this.fillCredentials(newPage, credentials, newAccount) } + return dApp } - private async fillCredentials(page: Page, credentials: ICredentials, newAccount: boolean) { + private async fillCredentials( + page: Page, + credentials: ICredentials, + newAccount: boolean, + ) { await page.locator("[name=email]").fill(credentials.email) await page.locator('button[type="submit"]').click() const pin = await mailClient.getPin() @@ -57,12 +64,20 @@ export default class Dapps extends Navigation { } else { await page.locator("[name=password]").fill(credentials.password) } + await page.locator('button[type="submit"]').click() await page.waitForLoadState() + + await page.locator('button[type="submit"]').click() + return page } - private async handlePopup(dApp: Page, credentials: ICredentials, newAccount: boolean) { + private async handlePopup( + dApp: Page, + credentials: ICredentials, + newAccount: boolean, + ) { const popupPromise = dApp.waitForEvent("popup") await expect(dApp.locator("p:text-is('Email')")).toBeVisible() await dApp.locator("p:text-is('Email')").click() @@ -80,4 +95,52 @@ export default class Dapps extends Navigation { throw new Error("Email not visible") }) } + + async sendERC20transaction({ + dapp, + type, + }: { + dapp: Page + type: "ERC20" | "Multicall" + }) { + const popupPromise = dapp.waitForEvent("popup") + const dialogPromise = dapp.waitForEvent("dialog") + await dapp.locator('button :text-is("Transactions")').click() + await dapp.locator(`button :text-is("Send ${type}")`).click() + + const popup = await popupPromise + await expect(popup.getByText("Review transaction")).toBeVisible() + await expect(popup.getByText("Confirm")).toBeVisible() + await popup.locator('button[type="submit"]').click() + await popup.waitForEvent("close", { timeout: 10000 }) + + const dialog = await dialogPromise + expect(dialog.message()).toContain("Transaction sent") + await dialog.accept() + + return dapp + } + + async signMessage({ dapp }: { dapp: Page }) { + const popupPromise = dapp.waitForEvent("popup") + await dapp.locator('button :text-is("Signing")').click() + await dapp.locator("[name=short-text]").fill("some message to sign") + await dapp.locator('button[type="submit"]').click() + + const popup = await popupPromise + await expect(popup.getByText("Sign Message")).toBeVisible() + await expect(popup.getByText("Confirm")).toBeVisible() + await popup.locator('button[type="submit"]').click() + await popup.waitForEvent("close", { timeout: 10000 }) + + await expect(dapp.getByText("Signer", { exact: true })).toBeVisible() + await expect(dapp.getByText("Cosigner", { exact: true })).toBeVisible() + + await expect(dapp.locator("[name=signer_r]")).toBeVisible() + await expect(dapp.locator("[name=signer_s]")).toBeVisible() + await expect(dapp.locator("[name=cosigner_r]")).toBeVisible() + await expect(dapp.locator("[name=cosigner_s]")).toBeVisible() + + return dapp + } } diff --git a/e2e/src/webwallet/specs/connect.spec.ts b/e2e/src/webwallet/specs/connect.spec.ts new file mode 100644 index 0000000..1a0fdcd --- /dev/null +++ b/e2e/src/webwallet/specs/connect.spec.ts @@ -0,0 +1,28 @@ +import test from "../test" +import config from "../config" + +test.describe(`Connect`, () => { + test(`connect from testDapp using starknetKitModal`, async ({ + webWallet, + dApp, + }) => { + await webWallet.dapps.requestConnectionFromDapp({ + dApp, + credentials: config.validLogin, + newAccount: false, + useStarknetKitModal: true, + }) + }) + + test(`connect from testDapp using webwallet connector`, async ({ + webWallet, + dApp, + }) => { + await webWallet.dapps.requestConnectionFromDapp({ + dApp, + credentials: config.validLogin, + newAccount: false, + useStarknetKitModal: false, + }) + }) +}) diff --git a/e2e/src/webwallet/specs/dapps.spec.ts b/e2e/src/webwallet/specs/dapps.spec.ts deleted file mode 100644 index faa5b74..0000000 --- a/e2e/src/webwallet/specs/dapps.spec.ts +++ /dev/null @@ -1,15 +0,0 @@ -import test from "../test" -import config from "../config" - -test.describe(`Dapps`, () => { - for (const useStarknetKitModal of [true, false] as const) { - test(`connect from testDapp using starknetKitModal ${useStarknetKitModal}`, async ({ webWallet, dApp }) => { - await webWallet.dapps.requestConnectionFromDapp({ - dApp, - credentials: config.validLogin, - newAccount: false, - useStarknetKitModal - }) - }) - } -}) diff --git a/e2e/src/webwallet/specs/signMessage.spec.ts b/e2e/src/webwallet/specs/signMessage.spec.ts new file mode 100644 index 0000000..66fafa5 --- /dev/null +++ b/e2e/src/webwallet/specs/signMessage.spec.ts @@ -0,0 +1,17 @@ +import test from "../test" +import config from "../config" + +test.describe(`Sign message`, () => { + test(`sign a message from testDapp`, async ({ webWallet, dApp }) => { + const dapp = await webWallet.dapps.requestConnectionFromDapp({ + dApp, + credentials: config.validLogin, + newAccount: false, + useStarknetKitModal: true, + }) + + await webWallet.dapps.signMessage({ + dapp, + }) + }) +}) diff --git a/e2e/src/webwallet/specs/transactions.spec.ts b/e2e/src/webwallet/specs/transactions.spec.ts new file mode 100644 index 0000000..86af5f7 --- /dev/null +++ b/e2e/src/webwallet/specs/transactions.spec.ts @@ -0,0 +1,32 @@ +import test from "../test" +import config from "../config" + +test.describe(`Transactions`, () => { + test(`send an ERC20 from testDapp`, async ({ webWallet, dApp }) => { + const dapp = await webWallet.dapps.requestConnectionFromDapp({ + dApp, + credentials: config.validLogin, + newAccount: false, + useStarknetKitModal: true, + }) + + await webWallet.dapps.sendERC20transaction({ + dapp, + type: "ERC20", + }) + }) + + test(`send an Multicall from testDapp`, async ({ webWallet, dApp }) => { + const dapp = await webWallet.dapps.requestConnectionFromDapp({ + dApp, + credentials: config.validLogin, + newAccount: false, + useStarknetKitModal: true, + }) + + await webWallet.dapps.sendERC20transaction({ + dapp, + type: "Multicall", + }) + }) +}) diff --git a/src/components/sections/SignMessage.tsx b/src/components/sections/SignMessage.tsx index a41feb8..f6ea2bd 100644 --- a/src/components/sections/SignMessage.tsx +++ b/src/components/sections/SignMessage.tsx @@ -129,8 +129,8 @@ const SignMessage = () => {

r