diff --git a/test/e2e/tests/confirmations/signatures/permit.spec.ts b/test/e2e/tests/confirmations/signatures/permit.spec.ts index ded693a94aa3..b2df0486aef7 100644 --- a/test/e2e/tests/confirmations/signatures/permit.spec.ts +++ b/test/e2e/tests/confirmations/signatures/permit.spec.ts @@ -21,6 +21,8 @@ import { assertSignatureMetrics, clickHeaderInfoBtn, copyAddressAndPasteWalletAddress, + openDappAndTriggerSignature, + SignatureType, } from './signature-helpers'; describe('Confirmation Signature - Permit @no-mmi', function (this: Suite) { @@ -35,10 +37,7 @@ describe('Confirmation Signature - Permit @no-mmi', function (this: Suite) { const addresses = await (ganacheServer as Ganache).getAccounts(); const publicAddress = addresses?.[0] as string; - await unlockWallet(driver); - await openDapp(driver); - await driver.clickElement('#signPermit'); - await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); + await openDappAndTriggerSignature(driver, SignatureType.Permit); await clickHeaderInfoBtn(driver); await assertHeaderInfoBalance(driver); diff --git a/test/e2e/tests/confirmations/signatures/personal-sign.spec.ts b/test/e2e/tests/confirmations/signatures/personal-sign.spec.ts index fed1e097d76c..5740eedbc276 100644 --- a/test/e2e/tests/confirmations/signatures/personal-sign.spec.ts +++ b/test/e2e/tests/confirmations/signatures/personal-sign.spec.ts @@ -4,9 +4,7 @@ import { MockedEndpoint } from 'mockttp'; import { DAPP_HOST_ADDRESS, WINDOW_TITLES, - openDapp, switchToNotificationWindow, - unlockWallet, } from '../../../helpers'; import { Ganache } from '../../../seeder/ganache'; import { Driver } from '../../../webdriver/driver'; @@ -19,6 +17,8 @@ import { assertSignatureMetrics, clickHeaderInfoBtn, copyAddressAndPasteWalletAddress, + openDappAndTriggerSignature, + SignatureType, } from './signature-helpers'; describe('Confirmation Signature - Personal Sign @no-mmi', function (this: Suite) { @@ -33,10 +33,7 @@ describe('Confirmation Signature - Personal Sign @no-mmi', function (this: Suite const addresses = await (ganacheServer as Ganache).getAccounts(); const publicAddress = addresses?.[0] as string; - await unlockWallet(driver); - await openDapp(driver); - await driver.clickElement('#personalSign'); - await switchToNotificationWindow(driver); + await openDappAndTriggerSignature(driver, SignatureType.PersonalSign); await clickHeaderInfoBtn(driver); await assertHeaderInfoBalance(driver); @@ -70,10 +67,7 @@ describe('Confirmation Signature - Personal Sign @no-mmi', function (this: Suite driver, mockedEndpoint: mockedEndpoints, }: TestSuiteArguments) => { - await unlockWallet(driver); - await openDapp(driver); - await driver.clickElement('#personalSign'); - await switchToNotificationWindow(driver); + await openDappAndTriggerSignature(driver, SignatureType.PersonalSign); await driver.clickElement( '[data-testid="confirm-footer-cancel-button"]', diff --git a/test/e2e/tests/confirmations/signatures/sign-typed-data-v3.spec.ts b/test/e2e/tests/confirmations/signatures/sign-typed-data-v3.spec.ts index 097acfbbb2d4..6562c0351231 100644 --- a/test/e2e/tests/confirmations/signatures/sign-typed-data-v3.spec.ts +++ b/test/e2e/tests/confirmations/signatures/sign-typed-data-v3.spec.ts @@ -4,9 +4,7 @@ import { MockedEndpoint } from 'mockttp'; import { DAPP_HOST_ADDRESS, WINDOW_TITLES, - openDapp, switchToNotificationWindow, - unlockWallet, } from '../../../helpers'; import { Ganache } from '../../../seeder/ganache'; import { Driver } from '../../../webdriver/driver'; @@ -22,6 +20,8 @@ import { assertSignatureMetrics, clickHeaderInfoBtn, copyAddressAndPasteWalletAddress, + openDappAndTriggerSignature, + SignatureType, } from './signature-helpers'; describe('Confirmation Signature - Sign Typed Data V3 @no-mmi', function (this: Suite) { @@ -36,10 +36,10 @@ describe('Confirmation Signature - Sign Typed Data V3 @no-mmi', function (this: const addresses = await (ganacheServer as Ganache).getAccounts(); const publicAddress = addresses?.[0] as string; - await unlockWallet(driver); - await openDapp(driver); - await driver.clickElement('#signTypedDataV3'); - await switchToNotificationWindow(driver); + await openDappAndTriggerSignature( + driver, + SignatureType.SignTypedDataV3, + ); await clickHeaderInfoBtn(driver); await assertHeaderInfoBalance(driver); @@ -73,10 +73,10 @@ describe('Confirmation Signature - Sign Typed Data V3 @no-mmi', function (this: driver, mockedEndpoint: mockedEndpoints, }: TestSuiteArguments) => { - await unlockWallet(driver); - await openDapp(driver); - await driver.clickElement('#signTypedDataV3'); - await switchToNotificationWindow(driver); + await openDappAndTriggerSignature( + driver, + SignatureType.SignTypedDataV3, + ); await driver.clickElement( '[data-testid="confirm-footer-cancel-button"]', diff --git a/test/e2e/tests/confirmations/signatures/sign-typed-data-v4.spec.ts b/test/e2e/tests/confirmations/signatures/sign-typed-data-v4.spec.ts index d539e12afbdb..7994c3873409 100644 --- a/test/e2e/tests/confirmations/signatures/sign-typed-data-v4.spec.ts +++ b/test/e2e/tests/confirmations/signatures/sign-typed-data-v4.spec.ts @@ -1,13 +1,7 @@ import { strict as assert } from 'assert'; import { Suite } from 'mocha'; import { MockedEndpoint } from 'mockttp'; -import { - DAPP_HOST_ADDRESS, - WINDOW_TITLES, - openDapp, - switchToNotificationWindow, - unlockWallet, -} from '../../../helpers'; +import { DAPP_HOST_ADDRESS, WINDOW_TITLES } from '../../../helpers'; import { Ganache } from '../../../seeder/ganache'; import { Driver } from '../../../webdriver/driver'; import { @@ -22,6 +16,8 @@ import { assertSignatureMetrics, clickHeaderInfoBtn, copyAddressAndPasteWalletAddress, + openDappAndTriggerSignature, + SignatureType, } from './signature-helpers'; describe('Confirmation Signature - Sign Typed Data V4 @no-mmi', function (this: Suite) { @@ -36,10 +32,10 @@ describe('Confirmation Signature - Sign Typed Data V4 @no-mmi', function (this: const addresses = await (ganacheServer as Ganache).getAccounts(); const publicAddress = addresses?.[0] as string; - await unlockWallet(driver); - await openDapp(driver); - await driver.clickElement('#signTypedDataV4'); - await switchToNotificationWindow(driver); + await openDappAndTriggerSignature( + driver, + SignatureType.SignTypedDataV4, + ); await clickHeaderInfoBtn(driver); await assertHeaderInfoBalance(driver); @@ -74,10 +70,10 @@ describe('Confirmation Signature - Sign Typed Data V4 @no-mmi', function (this: driver, mockedEndpoint: mockedEndpoints, }: TestSuiteArguments) => { - await unlockWallet(driver); - await openDapp(driver); - await driver.clickElement('#signTypedDataV4'); - await switchToNotificationWindow(driver); + await openDappAndTriggerSignature( + driver, + SignatureType.SignTypedDataV4, + ); await driver.clickElement( '[data-testid="confirm-footer-cancel-button"]', diff --git a/test/e2e/tests/confirmations/signatures/sign-typed-data.spec.ts b/test/e2e/tests/confirmations/signatures/sign-typed-data.spec.ts index 2baae49c6690..48e9ce5f0919 100644 --- a/test/e2e/tests/confirmations/signatures/sign-typed-data.spec.ts +++ b/test/e2e/tests/confirmations/signatures/sign-typed-data.spec.ts @@ -1,13 +1,7 @@ import { strict as assert } from 'assert'; import { Suite } from 'mocha'; import { MockedEndpoint } from 'mockttp'; -import { - DAPP_HOST_ADDRESS, - WINDOW_TITLES, - openDapp, - switchToNotificationWindow, - unlockWallet, -} from '../../../helpers'; +import { DAPP_HOST_ADDRESS, WINDOW_TITLES } from '../../../helpers'; import { Ganache } from '../../../seeder/ganache'; import { Driver } from '../../../webdriver/driver'; import { withRedesignConfirmationFixtures } from '../helpers'; @@ -19,6 +13,8 @@ import { assertSignatureMetrics, clickHeaderInfoBtn, copyAddressAndPasteWalletAddress, + openDappAndTriggerSignature, + SignatureType, } from './signature-helpers'; describe('Confirmation Signature - Sign Typed Data @no-mmi', function (this: Suite) { @@ -33,10 +29,7 @@ describe('Confirmation Signature - Sign Typed Data @no-mmi', function (this: Sui const addresses = await (ganacheServer as Ganache).getAccounts(); const publicAddress = addresses?.[0] as string; - await unlockWallet(driver); - await openDapp(driver); - await driver.clickElement('#signTypedData'); - await switchToNotificationWindow(driver); + await openDappAndTriggerSignature(driver, SignatureType.SignTypedData); await clickHeaderInfoBtn(driver); await assertHeaderInfoBalance(driver); @@ -72,10 +65,7 @@ describe('Confirmation Signature - Sign Typed Data @no-mmi', function (this: Sui driver, mockedEndpoint: mockedEndpoints, }: TestSuiteArguments) => { - await unlockWallet(driver); - await openDapp(driver); - await driver.clickElement('#signTypedData'); - await switchToNotificationWindow(driver); + await openDappAndTriggerSignature(driver, SignatureType.SignTypedData); await driver.clickElement( '[data-testid="confirm-footer-cancel-button"]', diff --git a/test/e2e/tests/confirmations/signatures/signature-helpers.ts b/test/e2e/tests/confirmations/signatures/signature-helpers.ts index c2f1cb02fd9b..c59aa692c37a 100644 --- a/test/e2e/tests/confirmations/signatures/signature-helpers.ts +++ b/test/e2e/tests/confirmations/signatures/signature-helpers.ts @@ -1,10 +1,24 @@ import { strict as assert } from 'assert'; import { MockedEndpoint } from 'mockttp'; -import { WINDOW_TITLES, getEventPayloads } from '../../../helpers'; +import { + WINDOW_TITLES, + getEventPayloads, + openDapp, + unlockWallet, +} from '../../../helpers'; import { Driver } from '../../../webdriver/driver'; export const WALLET_ADDRESS = '0x5CfE73b6021E818B776b421B1c4Db2474086a7e1'; export const WALLET_ETH_BALANCE = '25'; +export enum SignatureType { + PersonalSign = '#personalSign', + Permit = '#signPermit', + SignTypedDataV3 = '#signTypedDataV3', + SignTypedDataV4 = '#signTypedDataV4', + SignTypedData = '#signTypedData', + SIWE = '#siwe', + SIWE_BadDomain = '#siweBadDomain', +} export async function assertSignatureMetrics( driver: Driver, @@ -99,3 +113,13 @@ export async function assertPastedAddress(driver: Driver) { const formFieldEl = await driver.findElement('#eip747ContractAddress'); assert.equal(await formFieldEl.getAttribute('value'), WALLET_ADDRESS); } + +export async function openDappAndTriggerSignature( + driver: Driver, + type: string, +) { + await unlockWallet(driver); + await openDapp(driver); + await driver.clickElement(type); + await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); +} diff --git a/test/e2e/tests/confirmations/signatures/siwe.spec.ts b/test/e2e/tests/confirmations/signatures/siwe.spec.ts index fcb7cc71eddd..b30aa9f28b8b 100644 --- a/test/e2e/tests/confirmations/signatures/siwe.spec.ts +++ b/test/e2e/tests/confirmations/signatures/siwe.spec.ts @@ -4,9 +4,7 @@ import { MockedEndpoint } from 'mockttp'; import { DAPP_HOST_ADDRESS, WINDOW_TITLES, - openDapp, switchToNotificationWindow, - unlockWallet, } from '../../../helpers'; import { Driver } from '../../../webdriver/driver'; import { @@ -21,6 +19,8 @@ import { assertSignatureMetrics, clickHeaderInfoBtn, copyAddressAndPasteWalletAddress, + openDappAndTriggerSignature, + SignatureType, } from './signature-helpers'; describe('Confirmation Signature - SIWE @no-mmi', function (this: Suite) { @@ -31,10 +31,7 @@ describe('Confirmation Signature - SIWE @no-mmi', function (this: Suite) { driver, mockedEndpoint: mockedEndpoints, }: TestSuiteArguments) => { - await unlockWallet(driver); - await openDapp(driver); - await driver.clickElement('#siwe'); - await switchToNotificationWindow(driver); + await openDappAndTriggerSignature(driver, SignatureType.SIWE); await clickHeaderInfoBtn(driver); await assertHeaderInfoBalance(driver); @@ -73,10 +70,7 @@ describe('Confirmation Signature - SIWE @no-mmi', function (this: Suite) { driver, mockedEndpoint: mockedEndpoints, }: TestSuiteArguments) => { - await unlockWallet(driver); - await openDapp(driver); - await driver.clickElement('#siwe'); - await switchToNotificationWindow(driver); + await openDappAndTriggerSignature(driver, SignatureType.SIWE); await driver.clickElement( '[data-testid="confirm-footer-cancel-button"]', @@ -105,11 +99,9 @@ describe('Confirmation Signature - SIWE @no-mmi', function (this: Suite) { await withRedesignConfirmationFixtures( this.test?.fullTitle(), async ({ driver }: TestSuiteArguments) => { - await unlockWallet(driver); - await openDapp(driver); - await driver.clickElement('#siweBadDomain'); - await switchToNotificationWindow(driver); + await openDappAndTriggerSignature(driver, SignatureType.SIWE_BadDomain); + await driver.clickElementSafe('.confirm-scroll-to-bottom__button'); const alert = await driver.findElement('[data-testid="inline-alert"]'); assert.equal(await alert.getText(), 'Alert'); await driver.clickElement('[data-testid="inline-alert"]');