From 5430c8998a68a3d43f52a357976a0fcd7f066df0 Mon Sep 17 00:00:00 2001 From: Priya Date: Thu, 28 Nov 2024 13:56:06 +0700 Subject: [PATCH] test: migrate signature redesign tests to page object model (#28538) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **Description** Migrates the existing signature redesign e2e tests to use page object model. Adds the relevant pages and updates the tests using the newly created pages. [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/28538?quickstart=1) ## **Related issues** Fixes: [#28540](https://github.com/MetaMask/metamask-extension/issues/28540) ## **Manual testing steps** 1. Go to this page... 2. 3. ## **Screenshots/Recordings** ### **Before** ### **After** ## **Pre-merge author checklist** - [ ] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --- .../redesign/accountDetailsModal.ts | 42 ++++ .../confirmations/redesign/confirmation.ts | 36 ++++ .../redesign/permit-confirmation.ts | 142 ++++++++++++ .../redesign/personal-sign-confirmation.ts | 34 +++ .../redesign/sign-typed-data-confirmation.ts | 92 ++++++++ .../pages/dialog/confirm-alert.ts | 36 ++++ test/e2e/page-objects/pages/test-dapp.ts | 203 +++++++++++++++++- test/e2e/tests/confirmations/helpers.ts | 6 +- .../signatures/malicious-signatures.spec.ts | 82 +++---- .../signatures/nft-permit.spec.ts | 111 ++++------ .../confirmations/signatures/permit.spec.ts | 109 ++++------ .../signatures/personal-sign.spec.ts | 57 ++--- .../signatures/sign-typed-data-v3.spec.ts | 79 +++---- .../signatures/sign-typed-data-v4.spec.ts | 83 +++---- .../signatures/sign-typed-data.spec.ts | 52 ++--- .../signatures/signature-helpers.ts | 95 +++++--- .../confirmations/signatures/siwe.spec.ts | 52 ++--- 17 files changed, 881 insertions(+), 430 deletions(-) create mode 100644 test/e2e/page-objects/pages/confirmations/redesign/accountDetailsModal.ts create mode 100644 test/e2e/page-objects/pages/confirmations/redesign/permit-confirmation.ts create mode 100644 test/e2e/page-objects/pages/confirmations/redesign/personal-sign-confirmation.ts create mode 100644 test/e2e/page-objects/pages/confirmations/redesign/sign-typed-data-confirmation.ts create mode 100644 test/e2e/page-objects/pages/dialog/confirm-alert.ts diff --git a/test/e2e/page-objects/pages/confirmations/redesign/accountDetailsModal.ts b/test/e2e/page-objects/pages/confirmations/redesign/accountDetailsModal.ts new file mode 100644 index 000000000000..3c10307e8fb4 --- /dev/null +++ b/test/e2e/page-objects/pages/confirmations/redesign/accountDetailsModal.ts @@ -0,0 +1,42 @@ +import { Driver } from '../../../../webdriver/driver'; +import { RawLocator } from '../../../common'; +import Confirmation from './confirmation'; + +class AccountDetailsModal extends Confirmation { + private accountBalanceInfo: RawLocator; + + private addressCopyButton: RawLocator; + + private accountDetailsModalCloseButton: RawLocator; + + constructor(driver: Driver) { + super(driver); + + this.driver = driver; + + this.accountBalanceInfo = + '[data-testid="confirmation-account-details-modal__account-balance"]'; + + this.addressCopyButton = '[data-testid="address-copy-button-text"]'; + + this.accountDetailsModalCloseButton = + '[data-testid="confirmation-account-details-modal__close-button"]'; + } + + async clickAddressCopyButton() { + await this.driver.clickElement(this.addressCopyButton); + } + + async clickAccountDetailsModalCloseButton() { + await this.driver.clickElement(this.accountDetailsModalCloseButton); + } + + async assertHeaderInfoBalance(balance: string) { + await this.driver.waitForSelector({ + css: this.accountBalanceInfo.toString(), + text: `${balance} ETH`, + }); + } +} + +export default AccountDetailsModal; diff --git a/test/e2e/page-objects/pages/confirmations/redesign/confirmation.ts b/test/e2e/page-objects/pages/confirmations/redesign/confirmation.ts index f8fc66c3fc65..1ebaf95b7dcf 100644 --- a/test/e2e/page-objects/pages/confirmations/redesign/confirmation.ts +++ b/test/e2e/page-objects/pages/confirmations/redesign/confirmation.ts @@ -1,3 +1,4 @@ +import { Key } from 'selenium-webdriver'; import { Driver } from '../../../../webdriver/driver'; import { RawLocator } from '../../../common'; @@ -8,11 +9,25 @@ class Confirmation { private footerConfirmButton: RawLocator; + private headerAccountDetailsButton: RawLocator; + + private footerCancelButton: RawLocator; + + private sectionCollapseButton = '[data-testid="sectionCollapseButton"]'; + + private inlineAlertButton = { + css: '[data-testid="inline-alert"]', + text: 'Alert', + }; + constructor(driver: Driver) { this.driver = driver; this.scrollToBottomButton = '.confirm-scroll-to-bottom__button'; this.footerConfirmButton = '[data-testid="confirm-footer-button"]'; + this.headerAccountDetailsButton = + '[data-testid="header-info__account-details-button"]'; + this.footerCancelButton = '[data-testid="confirm-footer-cancel-button"]'; } async clickScrollToBottomButton() { @@ -22,6 +37,27 @@ class Confirmation { async clickFooterConfirmButton() { await this.driver.clickElement(this.footerConfirmButton); } + + async clickHeaderAccountDetailsButton() { + const accountDetailsButton = await this.driver.findElement( + this.headerAccountDetailsButton, + ); + await accountDetailsButton.sendKeys(Key.RETURN); + } + + async clickFooterCancelButtonAndAndWaitForWindowToClose() { + await this.driver.clickElementAndWaitForWindowToClose( + this.footerCancelButton, + ); + } + + async clickCollapseSectionButton() { + await this.driver.clickElement(this.sectionCollapseButton); + } + + async clickInlineAlert() { + await this.driver.clickElement(this.inlineAlertButton); + } } export default Confirmation; diff --git a/test/e2e/page-objects/pages/confirmations/redesign/permit-confirmation.ts b/test/e2e/page-objects/pages/confirmations/redesign/permit-confirmation.ts new file mode 100644 index 000000000000..2fe7b50f2865 --- /dev/null +++ b/test/e2e/page-objects/pages/confirmations/redesign/permit-confirmation.ts @@ -0,0 +1,142 @@ +import { strict as assert } from 'assert'; +import { Driver } from '../../../../webdriver/driver'; +import { DAPP_HOST_ADDRESS } from '../../../../constants'; +import Confirmation from './confirmation'; + +export default class PermitConfirmation extends Confirmation { + constructor(driver: Driver) { + super(driver); + + this.driver = driver; + } + + private originSelector = { text: DAPP_HOST_ADDRESS }; + + private contractPetNameSelector = { + css: '.name__value', + text: '0xCcCCc...ccccC', + }; + + private primaryTypeSelector = { text: 'Permit' }; + + private ownerSelector = { css: '.name__name', text: 'Account 1' }; + + private spenderSelector = { css: '.name__value', text: '0x5B38D...eddC4' }; + + private valueSelector = { text: '3,000' }; + + private nonceSelector = { text: '0' }; + + private deadlineSelector = { text: '09 June 3554, 16:53' }; + + private nftContractPetNameSelector = { + css: '.name__value', + text: '0x581c3...45947', + }; + + private nftTitle = { text: 'Withdrawal request' }; + + private nftDescription = { + text: 'This site wants permission to withdraw your NFTs', + }; + + private nftPrimaryType = { text: 'Permit' }; + + private nftSpender = { css: '.name__value', text: '0x581c3...45947' }; + + private nftTokenId = { text: '3606393' }; + + private nftNonce = { text: '0' }; + + private nftDeadline = { text: '23 December 2024, 23:03' }; + + async verifyOrigin() { + const origin = await this.driver.findElement(this.originSelector); + assert.ok(origin, 'Origin element is missing or incorrect'); + } + + async verifyContractPetName() { + const contractPetName = await this.driver.findElement( + this.contractPetNameSelector, + ); + assert.ok( + contractPetName, + 'Contract Pet Name element is missing or incorrect', + ); + } + + async verifyPrimaryType() { + const primaryType = await this.driver.findElement(this.primaryTypeSelector); + assert.ok(primaryType, 'Primary Type element is missing or incorrect'); + } + + async verifyOwner() { + const owner = await this.driver.findElement(this.ownerSelector); + assert.ok(owner, 'Owner element is missing or incorrect'); + } + + async verifySpender() { + const spender = await this.driver.findElement(this.spenderSelector); + assert.ok(spender, 'Spender element is missing or incorrect'); + } + + async verifyValue() { + const value = await this.driver.findElement(this.valueSelector); + assert.ok(value, 'Value element is missing or incorrect'); + } + + async verifyNonce() { + const nonce = await this.driver.findElement(this.nonceSelector); + assert.ok(nonce, 'Nonce element is missing or incorrect'); + } + + async verifyDeadline() { + const deadline = await this.driver.findElement(this.deadlineSelector); + assert.ok(deadline, 'Deadline element is missing or incorrect'); + } + + async verifyNftContractPetName() { + const nftContractPetName = await this.driver.findElement( + this.nftContractPetNameSelector, + ); + assert.ok( + nftContractPetName, + 'NFT Contract Pet Name element is missing or incorrect', + ); + } + + async verifyNftTitle() { + const element = await this.driver.findElement(this.nftTitle); + assert.ok(element, 'NFT Title element is missing or incorrect'); + } + + async verifyNftDescription() { + const element = await this.driver.findElement(this.nftDescription); + assert.ok(element, 'NFT Description element is missing or incorrect'); + } + + async verifyNftPrimaryType() { + const element = await this.driver.findElement(this.nftPrimaryType); + assert.ok(element, 'NFT PrimaryType element is missing or incorrect'); + } + + async verifyNftSpender() { + const element = await this.driver.findElement(this.nftSpender); + assert.ok(element, 'NFT Spender element is missing or incorrect'); + } + + async verifyNftTokenId() { + const element = await this.driver.findElement(this.nftTokenId); + assert.ok(element, 'NFT TokenId element is missing or incorrect'); + } + + async verifyNftNonce() { + const element = await this.driver.findElement(this.nftNonce); + assert.ok(element, 'NFT Nonce element is missing or incorrect'); + } + + async verifyNftDeadline() { + const element = await this.driver.findElement(this.nftDeadline); + assert.ok(element, 'NFT Deadline element is missing or incorrect'); + } +} diff --git a/test/e2e/page-objects/pages/confirmations/redesign/personal-sign-confirmation.ts b/test/e2e/page-objects/pages/confirmations/redesign/personal-sign-confirmation.ts new file mode 100644 index 000000000000..e2d55a46e1cc --- /dev/null +++ b/test/e2e/page-objects/pages/confirmations/redesign/personal-sign-confirmation.ts @@ -0,0 +1,34 @@ +import { strict as assert } from 'assert'; +import { DAPP_HOST_ADDRESS } from '../../../../constants'; +import { Driver } from '../../../../webdriver/driver'; +import Confirmation from './confirmation'; + +export default class PersonalSignConfirmation extends Confirmation { + constructor(driver: Driver) { + super(driver); + + this.driver = driver; + } + + private originSelector = { text: DAPP_HOST_ADDRESS }; + + private messageSelector = { text: 'Example `personal_sign` message' }; + + private siweMessage = { + text: 'I accept the MetaMask Terms of Service: https://community.metamask.io/tos', + }; + + async verifyOrigin() { + const origin = await this.driver.findElement(this.originSelector); + assert.ok(origin, 'Origin element is missing or incorrect'); + } + + async verifyMessage() { + const message = this.driver.findElement(this.messageSelector); + assert.ok(await message); + } + + async verifySiweMessage() { + this.driver.findElement(this.siweMessage); + } +} diff --git a/test/e2e/page-objects/pages/confirmations/redesign/sign-typed-data-confirmation.ts b/test/e2e/page-objects/pages/confirmations/redesign/sign-typed-data-confirmation.ts new file mode 100644 index 000000000000..6c747912be9d --- /dev/null +++ b/test/e2e/page-objects/pages/confirmations/redesign/sign-typed-data-confirmation.ts @@ -0,0 +1,92 @@ +import { strict as assert } from 'assert'; +import { DAPP_HOST_ADDRESS } from '../../../../constants'; +import { Driver } from '../../../../webdriver/driver'; +import Confirmation from './confirmation'; + +export default class SignTypedData extends Confirmation { + constructor(driver: Driver) { + super(driver); + + this.driver = driver; + } + + private origin = { text: DAPP_HOST_ADDRESS }; + + private signTypedDataMessage = { text: 'Hi, Alice!' }; + + private contract = { css: '.name__value', text: '0xCcCCc...ccccC' }; + + private primaryType = { text: 'Mail' }; + + private fromName = { text: 'Cow' }; + + private fromAddress = { css: '.name__value', text: '0xCD2a3...DD826' }; + + private toName = { text: 'Bob' }; + + private toAddress = { css: '.name__value', text: '0xbBbBB...bBBbB' }; + + private contents = { text: 'Hello, Bob!' }; + + private attachment = { text: '0x' }; + + private toAddressNum2 = { css: '.name__value', text: '0xB0B0b...00000' }; + + async verifyOrigin() { + const origin = await this.driver.findElement(this.origin); + assert.ok(origin, 'Origin element is missing or incorrect'); + } + + async verifySignTypedDataMessage() { + const message = this.driver.findElement(this.signTypedDataMessage); + assert.ok(await message); + } + + async verifyContractPetName() { + const contractPetName = await this.driver.findElement(this.contract); + assert.ok( + contractPetName, + 'Contract pet name element is missing or incorrect', + ); + } + + async verifyPrimaryType() { + const primaryType = await this.driver.findElement(this.primaryType); + assert.ok(primaryType, 'Primary type element is missing or incorrect'); + } + + async verifyFromName() { + const fromName = await this.driver.findElement(this.fromName); + assert.ok(fromName, 'From name element is missing or incorrect'); + } + + async verifyFromAddress() { + const fromAddress = await this.driver.findElement(this.fromAddress); + assert.ok(fromAddress, 'From address element is missing or incorrect'); + } + + async verifyToName() { + const toName = await this.driver.findElement(this.toName); + assert.ok(toName, 'To name element is missing or incorrect'); + } + + async verifyToAddress() { + const toAddress = await this.driver.findElement(this.toAddress); + assert.ok(toAddress, 'To address element is missing or incorrect'); + } + + async verifyContents() { + const contents = await this.driver.findElement(this.contents); + assert.ok(contents, 'Contents element is missing or incorrect'); + } + + async verifyAttachment() { + const attachment = await this.driver.findElement(this.attachment); + assert.ok(attachment, 'Attachment element is missing or incorrect'); + } + + async verifyToAddressNum2() { + const toAddressNum2 = await this.driver.findElement(this.toAddressNum2); + assert.ok(toAddressNum2, 'To Address num2 element is missing or incorrect'); + } +} diff --git a/test/e2e/page-objects/pages/dialog/confirm-alert.ts b/test/e2e/page-objects/pages/dialog/confirm-alert.ts new file mode 100644 index 000000000000..c7bc7b1f7a49 --- /dev/null +++ b/test/e2e/page-objects/pages/dialog/confirm-alert.ts @@ -0,0 +1,36 @@ +import { Driver } from '../../../webdriver/driver'; + +class ConfirmAlertModal { + protected driver: Driver; + + private alertModalAcknowledgeCheckBox = + '[data-testid="alert-modal-acknowledge-checkbox"]'; + + private alertModalButton = '[data-testid="alert-modal-button"]'; + + private alertModalSubmitButton = + '[data-testid="confirm-alert-modal-submit-button"]'; + + private alertModalCancelButton = + '[data-testid="confirm-alert-modal-cancel-button"]'; + + constructor(driver: Driver) { + this.driver = driver; + } + + async rejectFromAlertModal() { + this.driver.clickElement(this.alertModalCancelButton); + } + + async confirmFromAlertModal() { + this.driver.clickElement(this.alertModalAcknowledgeCheckBox); + this.driver.clickElement(this.alertModalSubmitButton); + } + + async acknowledgeAlert() { + this.driver.clickElement(this.alertModalAcknowledgeCheckBox); + this.driver.clickElement(this.alertModalButton); + } +} + +export default ConfirmAlertModal; diff --git a/test/e2e/page-objects/pages/test-dapp.ts b/test/e2e/page-objects/pages/test-dapp.ts index 31e962933e90..c31ee497152e 100644 --- a/test/e2e/page-objects/pages/test-dapp.ts +++ b/test/e2e/page-objects/pages/test-dapp.ts @@ -1,3 +1,4 @@ +import { strict as assert } from 'assert'; import { WINDOW_TITLES } from '../../helpers'; import { Driver } from '../../webdriver/driver'; @@ -73,6 +74,9 @@ class TestDapp { private readonly personalSignVerifyButton = '#personalSignVerify'; + private personalSignSigUtilResultSelector = + '#personalSignVerifySigUtilResult'; + private readonly revokePermissionButton = '#revokeAccountsPermission'; private readonly signPermitButton = '#signPermit'; @@ -88,6 +92,12 @@ class TestDapp { private readonly signPermitVerifyResult = '#signPermitVerifyResult'; + private readonly signPermitResultR = '#signPermitResultR'; + + private readonly signPermitResultS = '#signPermitResultS'; + + private readonly signPermitResultV = '#signPermitResultV'; + private readonly signTypedDataButton = '#signTypedData'; private readonly signTypedDataResult = '#signTypedDataResult'; @@ -122,6 +132,28 @@ class TestDapp { private readonly signTypedDataVerifyResult = '#signTypedDataVerifyResult'; + private readonly signSiweButton = '#siwe'; + + private readonly signSiweVerifyResult = '#siweResult'; + + private readonly signSiweBadDomainButton = '#siweBadDomain'; + + private readonly sign721PermitButton = '#sign721Permit'; + + private sign721PermitVerifyButton = '#sign721PermitVerify'; + + private sign721PermitVerifyResult = '#sign721PermitVerifyResult'; + + private sign721PermitResult = '#sign721PermitResult'; + + private sign721PermitResultR = '#sign721PermitResultR'; + + private sign721PermitResultS = '#sign721PermitResultS'; + + private sign721PermitResultV = '#sign721PermitResultV'; + + private readonly eip747ContractAddressInput = '#eip747ContractAddress'; + private readonly transactionRequestMessage = { text: 'Transaction request', tag: 'h2', @@ -132,6 +164,11 @@ class TestDapp { tag: 'button', }; + private readonly userRejectedRequestMessage = { + tag: 'span', + text: 'Error: User rejected the request.', + }; + private erc20TokenTransferButton = '#transferTokens'; constructor(driver: Driver) { @@ -363,6 +400,17 @@ class TestDapp { }); } + async verifyPersonalSignSigUtilResult(publicKey: string) { + const sigUtilResult = await this.driver.waitForSelector({ + css: this.personalSignSigUtilResultSelector, + text: publicKey, + }); + assert.ok( + sigUtilResult, + `Sig Util result did not match address ${publicKey}`, + ); + } + /** * Verify the successful signPermit signature. * @@ -378,6 +426,72 @@ class TestDapp { }); } + async verifySignPermitResult(expectedSignature: string) { + await this.driver.waitForSelector({ + css: this.signPermitResult, + text: expectedSignature, + }); + } + + async verifySignPermitResultR(expectedR: string) { + await this.driver.waitForSelector({ + css: this.signPermitResultR, + text: `r: ${expectedR}`, + }); + } + + async verifySignPermitResultS(expectedS: string) { + await this.driver.waitForSelector({ + css: this.signPermitResultS, + text: `s: ${expectedS}`, + }); + } + + async verifySignPermitResultV(expectedV: string) { + await this.driver.waitForSelector({ + css: this.signPermitResultV, + text: `v: ${expectedV}`, + }); + } + + async check_successSign721Permit(publicKey: string) { + console.log('Verify successful signPermit signature'); + await this.driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp); + await this.driver.clickElement(this.sign721PermitVerifyButton); + await this.driver.waitForSelector({ + css: this.sign721PermitVerifyResult, + text: publicKey.toLowerCase(), + }); + } + + async verifySign721PermitResult(expectedSignature: string) { + await this.driver.waitForSelector({ + css: this.sign721PermitResult, + text: expectedSignature, + }); + } + + async verifySign721PermitResultR(expectedR: string) { + await this.driver.waitForSelector({ + css: this.sign721PermitResultR, + text: `r: ${expectedR}`, + }); + } + + async verifySign721PermitResultS(expectedS: string) { + await this.driver.waitForSelector({ + css: this.sign721PermitResultS, + text: `s: ${expectedS}`, + }); + } + + async verifySign721PermitResultV(expectedV: string) { + await this.driver.waitForSelector({ + css: this.sign721PermitResultV, + text: `v: ${expectedV}`, + }); + } + /** * Verify the successful signTypedData signature. * @@ -393,6 +507,13 @@ class TestDapp { }); } + async verify_successSignTypedDataResult(result: string) { + await this.driver.waitForSelector({ + css: this.signTypedDataResult, + text: result.toLowerCase(), + }); + } + /** * Verify the successful signTypedDataV3 signature. * @@ -408,6 +529,13 @@ class TestDapp { }); } + async verify_successSignTypedDataV3Result(result: string) { + await this.driver.waitForSelector({ + css: this.signTypedDataV3Result, + text: result.toLowerCase(), + }); + } + /** * Verify the successful signTypedDataV4 signature. * @@ -423,12 +551,59 @@ class TestDapp { }); } + async verify_successSignTypedDataV4Result(result: string) { + await this.driver.waitForSelector({ + css: this.signTypedDataV4Result, + text: result.toLowerCase(), + }); + } + + async check_successSiwe(result: string) { + console.log('Verify successful SIWE signature'); + await this.driver.waitForSelector({ + css: this.signSiweVerifyResult, + text: result.toLowerCase(), + }); + } + + async clickPersonalSign() { + await this.driver.clickElement(this.personalSignButton); + } + + async clickSignTypedData() { + await this.driver.clickElement(this.signTypedDataButton); + } + + async clickSignTypedDatav3() { + await this.driver.clickElement(this.signTypedDataV3Button); + } + + async clickSignTypedDatav4() { + await this.driver.clickElement(this.signTypedDataV4Button); + } + + async clickPermit() { + await this.driver.clickElement(this.signPermitButton); + } + + async clickSiwe() { + await this.driver.clickElement(this.signSiweButton); + } + + async clickSwieBadDomain() { + await this.driver.clickElement(this.signSiweBadDomainButton); + } + + async clickERC721Permit() { + await this.driver.clickElement(this.sign721PermitButton); + } + /** * Sign a message with the personal sign method. */ async personalSign() { console.log('Sign message with personal sign'); - await this.driver.clickElement(this.personalSignButton); + await this.clickPersonalSign(); await this.driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); await this.driver.waitForSelector(this.personalSignSignatureRequestMessage); await this.driver.clickElementAndWaitForWindowToClose( @@ -441,7 +616,7 @@ class TestDapp { */ async signPermit() { console.log('Sign message with signPermit'); - await this.driver.clickElement(this.signPermitButton); + await this.clickPermit(); await this.driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); await this.driver.waitForSelector(this.signPermitSignatureRequestMessage); await this.driver.clickElementAndWaitForWindowToClose( @@ -454,7 +629,7 @@ class TestDapp { */ async signTypedData() { console.log('Sign message with signTypedData'); - await this.driver.clickElement(this.signTypedDataButton); + await this.clickSignTypedData(); await this.driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); await this.driver.waitForSelector( this.signTypedDataSignatureRequestMessage, @@ -469,7 +644,7 @@ class TestDapp { */ async signTypedDataV3() { console.log('Sign message with signTypedDataV3'); - await this.driver.clickElement(this.signTypedDataV3Button); + await this.clickSignTypedDatav3(); await this.driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); await this.driver.waitForSelector( this.signTypedDataV3V4SignatureRequestMessage, @@ -485,7 +660,7 @@ class TestDapp { */ async signTypedDataV4() { console.log('Sign message with signTypedDataV4'); - await this.driver.clickElement(this.signTypedDataV4Button); + await this.clickSignTypedDatav4(); await this.driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); await this.driver.waitForSelector( this.signTypedDataV3V4SignatureRequestMessage, @@ -495,5 +670,23 @@ class TestDapp { this.confirmSignatureButton, ); } + + async pasteIntoEip747ContractAddressInput() { + await this.driver.findElement(this.eip747ContractAddressInput); + await this.driver.pasteFromClipboardIntoField( + this.eip747ContractAddressInput, + ); + } + + async assertEip747ContractAddressInputValue(expectedValue: string) { + const formFieldEl = await this.driver.findElement( + this.eip747ContractAddressInput, + ); + assert.equal(await formFieldEl.getAttribute('value'), expectedValue); + } + + async assertUserRejectedRequest() { + await this.driver.waitForSelector(this.userRejectedRequestMessage); + } } export default TestDapp; diff --git a/test/e2e/tests/confirmations/helpers.ts b/test/e2e/tests/confirmations/helpers.ts index 2b1078549c5b..d1c665241f5a 100644 --- a/test/e2e/tests/confirmations/helpers.ts +++ b/test/e2e/tests/confirmations/helpers.ts @@ -8,10 +8,12 @@ import { import { MockedEndpoint, Mockttp } from '../../mock-e2e'; import { SMART_CONTRACTS } from '../../seeder/smart-contracts'; import { Driver } from '../../webdriver/driver'; +import Confirmation from '../../page-objects/pages/confirmations/redesign/confirmation'; export async function scrollAndConfirmAndAssertConfirm(driver: Driver) { - await driver.clickElementSafe('.confirm-scroll-to-bottom__button'); - await driver.clickElement('[data-testid="confirm-footer-button"]'); + const confirmation = new Confirmation(driver); + await confirmation.clickScrollToBottomButton(); + await confirmation.clickFooterConfirmButton(); } export function withTransactionEnvelopeTypeFixtures( diff --git a/test/e2e/tests/confirmations/signatures/malicious-signatures.spec.ts b/test/e2e/tests/confirmations/signatures/malicious-signatures.spec.ts index 5876a4d5e17f..fb01aa7267c8 100644 --- a/test/e2e/tests/confirmations/signatures/malicious-signatures.spec.ts +++ b/test/e2e/tests/confirmations/signatures/malicious-signatures.spec.ts @@ -1,21 +1,24 @@ -import { strict as assert } from 'assert'; import { TransactionEnvelopeType } from '@metamask/transaction-controller'; import { Suite } from 'mocha'; import { MockedEndpoint } from 'mockttp'; import { WINDOW_TITLES } from '../../../helpers'; -import { Driver } from '../../../webdriver/driver'; import { mockSignatureRejected, scrollAndConfirmAndAssertConfirm, withTransactionEnvelopeTypeFixtures, } from '../helpers'; import { TestSuiteArguments } from '../transactions/shared'; +import Confirmation from '../../../page-objects/pages/confirmations/redesign/confirmation'; +import ConfirmAlertModal from '../../../page-objects/pages/dialog/confirm-alert'; import { BlockaidReason, BlockaidResultType, } from '../../../../../shared/constants/security-provider'; import { + assertRejectedSignature, assertSignatureRejectedMetrics, + assertVerifiedSiweMessage, + initializePages, openDappAndTriggerSignature, SignatureType, } from './signature-helpers'; @@ -26,17 +29,22 @@ describe('Malicious Confirmation Signature - Bad Domain @no-mmi', function (this this.test?.fullTitle(), TransactionEnvelopeType.legacy, async ({ driver }: TestSuiteArguments) => { + await initializePages(driver); + const confirmation = new Confirmation(driver); + const alertModal = new ConfirmAlertModal(driver); + await openDappAndTriggerSignature(driver, SignatureType.SIWE_BadDomain); - await verifyAlertIsDisplayed(driver); + await confirmation.clickScrollToBottomButton(); + await confirmation.clickInlineAlert(); - await acknowledgeAlert(driver); + await alertModal.acknowledgeAlert(); await scrollAndConfirmAndAssertConfirm(driver); - await confirmFromAlertModal(driver); + await alertModal.confirmFromAlertModal(); - await assertVerifiedMessage( + await assertVerifiedSiweMessage( driver, '0x24e559452c37827008633f9ae50c68cdb28e33f547f795af687839b520b022e4093c38bf1dfebda875ded715f2754d458ed62a19248e5a9bd2205bd1cb66f9b51b', ); @@ -52,19 +60,16 @@ describe('Malicious Confirmation Signature - Bad Domain @no-mmi', function (this driver, mockedEndpoint: mockedEndpoints, }: TestSuiteArguments) => { - await openDappAndTriggerSignature(driver, SignatureType.SIWE_BadDomain); + await initializePages(driver); + const confirmation = new Confirmation(driver); - await driver.clickElementAndWaitForWindowToClose( - '[data-testid="confirm-footer-cancel-button"]', - ); + await openDappAndTriggerSignature(driver, SignatureType.SIWE_BadDomain); + await confirmation.clickFooterCancelButtonAndAndWaitForWindowToClose(); await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp); - const rejectionResult = await driver.waitForSelector({ - css: '#siweResult', - text: 'Error: User rejected the request.', - }); - assert.ok(rejectionResult); + await assertRejectedSignature(); + await assertSignatureRejectedMetrics({ driver, mockedEndpoints: mockedEndpoints as MockedEndpoint[], @@ -100,23 +105,21 @@ describe('Malicious Confirmation Signature - Bad Domain @no-mmi', function (this driver, mockedEndpoint: mockedEndpoints, }: TestSuiteArguments) => { + await initializePages(driver); + const alertModal = new ConfirmAlertModal(driver); + await openDappAndTriggerSignature(driver, SignatureType.SIWE_BadDomain); await scrollAndConfirmAndAssertConfirm(driver); - await acknowledgeAlert(driver); + await alertModal.acknowledgeAlert(); + + await alertModal.rejectFromAlertModal(); - await driver.clickElement( - '[data-testid="confirm-alert-modal-cancel-button"]', - ); await driver.waitUntilXWindowHandles(2); await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp); - const rejectionResult = await driver.waitForSelector({ - css: '#siweResult', - text: 'Error: User rejected the request.', - }); - assert.ok(rejectionResult); + await assertRejectedSignature(); await assertSignatureRejectedMetrics({ driver, mockedEndpoints: mockedEndpoints as MockedEndpoint[], @@ -144,34 +147,3 @@ describe('Malicious Confirmation Signature - Bad Domain @no-mmi', function (this ); }); }); - -async function confirmFromAlertModal(driver: Driver) { - await driver.clickElement('[data-testid="alert-modal-acknowledge-checkbox"]'); - await driver.clickElement( - '[data-testid="confirm-alert-modal-submit-button"]', - ); -} - -async function acknowledgeAlert(driver: Driver) { - await driver.clickElement('[data-testid="alert-modal-acknowledge-checkbox"]'); - await driver.clickElement('[data-testid="alert-modal-button"]'); -} - -async function verifyAlertIsDisplayed(driver: Driver) { - await driver.clickElementSafe('.confirm-scroll-to-bottom__button'); - await driver.waitForSelector({ - css: '[data-testid="inline-alert"]', - text: 'Alert', - }); - await driver.clickElement('[data-testid="inline-alert"]'); -} - -async function assertVerifiedMessage(driver: Driver, message: string) { - await driver.waitUntilXWindowHandles(2); - await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp); - - await driver.waitForSelector({ - css: '#siweResult', - text: message, - }); -} diff --git a/test/e2e/tests/confirmations/signatures/nft-permit.spec.ts b/test/e2e/tests/confirmations/signatures/nft-permit.spec.ts index de70d25b359b..8f67fb7607ce 100644 --- a/test/e2e/tests/confirmations/signatures/nft-permit.spec.ts +++ b/test/e2e/tests/confirmations/signatures/nft-permit.spec.ts @@ -1,8 +1,7 @@ -import { strict as assert } from 'assert'; import { TransactionEnvelopeType } from '@metamask/transaction-controller'; import { Suite } from 'mocha'; import { MockedEndpoint } from 'mockttp'; -import { DAPP_HOST_ADDRESS, WINDOW_TITLES } from '../../../helpers'; +import { WINDOW_TITLES } from '../../../helpers'; import { Ganache } from '../../../seeder/ganache'; import { Driver } from '../../../webdriver/driver'; import { @@ -12,13 +11,17 @@ import { withTransactionEnvelopeTypeFixtures, } from '../helpers'; import { TestSuiteArguments } from '../transactions/shared'; +import PermitConfirmation from '../../../page-objects/pages/confirmations/redesign/permit-confirmation'; +import TestDapp from '../../../page-objects/pages/test-dapp'; import { assertAccountDetailsMetrics, assertPastedAddress, + assertRejectedSignature, assertSignatureConfirmedMetrics, assertSignatureRejectedMetrics, clickHeaderInfoBtn, copyAddressAndPasteWalletAddress, + initializePages, openDappAndTriggerDeploy, SignatureType, triggerSignature, @@ -36,20 +39,21 @@ describe('Confirmation Signature - NFT Permit @no-mmi', function (this: Suite) { }: TestSuiteArguments) => { const addresses = await (ganacheServer as Ganache).getAccounts(); const publicAddress = addresses?.[0] as string; + await initializePages(driver); await openDappAndTriggerDeploy(driver); await driver.delay(1000); await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); - await driver.clickElement('[data-testid="confirm-footer-button"]'); + await scrollAndConfirmAndAssertConfirm(driver); await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp); await driver.delay(1000); - await triggerSignature(driver, SignatureType.NFTPermit); + await triggerSignature(SignatureType.NFTPermit); await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); await clickHeaderInfoBtn(driver); await copyAddressAndPasteWalletAddress(driver); - await assertPastedAddress(driver); + await assertPastedAddress(); await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); await assertInfoValues(driver); @@ -84,6 +88,8 @@ describe('Confirmation Signature - NFT Permit @no-mmi', function (this: Suite) { driver, mockedEndpoint: mockedEndpoints, }: TestSuiteArguments) => { + await initializePages(driver); + const confirmation = new PermitConfirmation(driver); await openDappAndTriggerDeploy(driver); await driver.delay(1000); await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); @@ -91,18 +97,14 @@ describe('Confirmation Signature - NFT Permit @no-mmi', function (this: Suite) { await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp); await driver.delay(1000); - await triggerSignature(driver, SignatureType.NFTPermit); + await triggerSignature(SignatureType.NFTPermit); + await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); - await driver.clickElementAndWaitForWindowToClose( - '[data-testid="confirm-footer-cancel-button"]', - ); + await confirmation.clickFooterCancelButtonAndAndWaitForWindowToClose(); await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp); - await driver.waitForSelector({ - tag: 'span', - text: 'Error: User rejected the request.', - }); + await assertRejectedSignature(); await assertSignatureRejectedMetrics({ driver, @@ -119,69 +121,34 @@ describe('Confirmation Signature - NFT Permit @no-mmi', function (this: Suite) { }); async function assertInfoValues(driver: Driver) { - await driver.clickElement('[data-testid="sectionCollapseButton"]'); - const origin = driver.findElement({ text: DAPP_HOST_ADDRESS }); - const contractPetName = driver.findElement({ - css: '.name__value', - text: '0x581c3...45947', - }); - - const title = driver.findElement({ text: 'Withdrawal request' }); - const description = driver.findElement({ - text: 'This site wants permission to withdraw your NFTs', - }); - const primaryType = driver.findElement({ text: 'Permit' }); - const spender = driver.findElement({ - css: '.name__value', - text: '0x581c3...45947', - }); - const tokenId = driver.findElement({ text: '3606393' }); - const nonce = driver.findElement({ text: '0' }); - const deadline = driver.findElement({ text: '23 December 2024, 23:03' }); - - assert.ok(await origin, 'origin'); - assert.ok(await contractPetName, 'contractPetName'); - assert.ok(await title, 'title'); - assert.ok(await description, 'description'); - assert.ok(await primaryType, 'primaryType'); - assert.ok(await spender, 'spender'); - assert.ok(await tokenId, 'tokenId'); - assert.ok(await nonce, 'nonce'); - assert.ok(await deadline, 'deadline'); + const confirmation = new PermitConfirmation(driver); + await confirmation.clickCollapseSectionButton(); + await confirmation.verifyOrigin(); + await confirmation.verifyNftContractPetName(); + await confirmation.verifyNftTitle(); + await confirmation.verifyNftDescription(); + await confirmation.verifyNftPrimaryType(); + await confirmation.verifyNftSpender(); + await confirmation.verifyNftTokenId(); + await confirmation.verifyNftNonce(); + await confirmation.verifyNftDeadline(); } async function assertVerifiedResults(driver: Driver, publicAddress: string) { + const testDapp = new TestDapp(driver); await driver.waitUntilXWindowHandles(2); await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp); - await driver.clickElement('#sign721PermitVerify'); - - await driver.waitForSelector({ - css: '#sign721PermitVerifyResult', - text: publicAddress, - }); - - await driver.waitForSelector({ - css: '#sign721PermitResult', - text: '0x572bc6300f6aa669e85e0a7792bc0b0803fb70c3c492226b30007ff7030b03600e390ef295a5a525d19f444943ae82697f0e5b5b0d77cc382cb2ea9486ec27801c', - }); - await driver.waitForSelector({ - css: '#sign721PermitResultR', - text: 'r: 0x572bc6300f6aa669e85e0a7792bc0b0803fb70c3c492226b30007ff7030b0360', - }); - - await driver.waitForSelector({ - css: '#sign721PermitResultS', - text: 's: 0x0e390ef295a5a525d19f444943ae82697f0e5b5b0d77cc382cb2ea9486ec2780', - }); - - await driver.waitForSelector({ - css: '#sign721PermitResultV', - text: 'v: 28', - }); - - await driver.waitForSelector({ - css: '#sign721PermitVerifyResult', - text: publicAddress, - }); + await testDapp.check_successSign721Permit(publicAddress); + await testDapp.verifySign721PermitResult( + '0x572bc6300f6aa669e85e0a7792bc0b0803fb70c3c492226b30007ff7030b03600e390ef295a5a525d19f444943ae82697f0e5b5b0d77cc382cb2ea9486ec27801c', + ); + await testDapp.verifySign721PermitResultR( + '0x572bc6300f6aa669e85e0a7792bc0b0803fb70c3c492226b30007ff7030b0360', + ); + await testDapp.verifySign721PermitResultS( + '0x0e390ef295a5a525d19f444943ae82697f0e5b5b0d77cc382cb2ea9486ec2780', + ); + await testDapp.verifySign721PermitResultV('28'); + await driver.clickElement('#sign721PermitVerify'); } diff --git a/test/e2e/tests/confirmations/signatures/permit.spec.ts b/test/e2e/tests/confirmations/signatures/permit.spec.ts index f6c8fc972b5f..0385f0a23af5 100644 --- a/test/e2e/tests/confirmations/signatures/permit.spec.ts +++ b/test/e2e/tests/confirmations/signatures/permit.spec.ts @@ -1,13 +1,7 @@ -import { strict as assert } from 'assert'; import { TransactionEnvelopeType } from '@metamask/transaction-controller'; import { Suite } from 'mocha'; import { MockedEndpoint } from 'mockttp'; -import { - DAPP_HOST_ADDRESS, - openDapp, - unlockWallet, - WINDOW_TITLES, -} from '../../../helpers'; +import { openDapp, unlockWallet, WINDOW_TITLES } from '../../../helpers'; import { Ganache } from '../../../seeder/ganache'; import { Driver } from '../../../webdriver/driver'; import { @@ -17,14 +11,19 @@ import { withTransactionEnvelopeTypeFixtures, } from '../helpers'; import { TestSuiteArguments } from '../transactions/shared'; +import TestDapp from '../../../page-objects/pages/test-dapp'; +import Confirmation from '../../../page-objects/pages/confirmations/redesign/confirmation'; +import PermitConfirmation from '../../../page-objects/pages/confirmations/redesign/permit-confirmation'; import { assertAccountDetailsMetrics, assertHeaderInfoBalance, assertPastedAddress, + assertRejectedSignature, assertSignatureConfirmedMetrics, assertSignatureRejectedMetrics, clickHeaderInfoBtn, copyAddressAndPasteWalletAddress, + initializePages, openDappAndTriggerSignature, SignatureType, } from './signature-helpers'; @@ -41,14 +40,15 @@ describe('Confirmation Signature - Permit @no-mmi', function (this: Suite) { }: TestSuiteArguments) => { const addresses = await (ganacheServer as Ganache).getAccounts(); const publicAddress = addresses?.[0] as string; + await initializePages(driver); await openDappAndTriggerSignature(driver, SignatureType.Permit); await clickHeaderInfoBtn(driver); - await assertHeaderInfoBalance(driver); + await assertHeaderInfoBalance(); await copyAddressAndPasteWalletAddress(driver); - await assertPastedAddress(driver); + await assertPastedAddress(); await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); await assertInfoValues(driver); @@ -83,21 +83,18 @@ describe('Confirmation Signature - Permit @no-mmi', function (this: Suite) { driver, mockedEndpoint: mockedEndpoints, }: TestSuiteArguments) => { + const testDapp = new TestDapp(driver); + const confirmation = new Confirmation(driver); await unlockWallet(driver); await openDapp(driver); - await driver.clickElement('#signPermit'); + await testDapp.clickPermit(); await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); - await driver.clickElementAndWaitForWindowToClose( - '[data-testid="confirm-footer-cancel-button"]', - ); + await confirmation.clickFooterCancelButtonAndAndWaitForWindowToClose(); await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp); - await driver.waitForSelector({ - tag: 'span', - text: 'Error: User rejected the request.', - }); + await assertRejectedSignature(); await assertSignatureRejectedMetrics({ driver, @@ -114,64 +111,34 @@ describe('Confirmation Signature - Permit @no-mmi', function (this: Suite) { }); async function assertInfoValues(driver: Driver) { - await driver.clickElement('[data-testid="sectionCollapseButton"]'); - const origin = driver.findElement({ text: DAPP_HOST_ADDRESS }); - const contractPetName = driver.findElement({ - css: '.name__value', - text: '0xCcCCc...ccccC', - }); - - const primaryType = driver.findElement({ text: 'Permit' }); - const owner = driver.findElement({ css: '.name__name', text: 'Account 1' }); - const spender = driver.findElement({ - css: '.name__value', - text: '0x5B38D...eddC4', - }); - const value = driver.findElement({ text: '3,000' }); - const nonce = driver.findElement({ text: '0' }); - const deadline = driver.findElement({ text: '09 June 3554, 16:53' }); - - assert.ok(await origin, 'origin'); - assert.ok(await contractPetName, 'contractPetName'); - assert.ok(await primaryType, 'primaryType'); - assert.ok(await owner, 'owner'); - assert.ok(await spender, 'spender'); - assert.ok(await value, 'value'); - assert.ok(await nonce, 'nonce'); - assert.ok(await deadline, 'deadline'); + const permitConfirmation = new PermitConfirmation(driver); + await permitConfirmation.clickCollapseSectionButton(); + await permitConfirmation.verifyOrigin(); + await permitConfirmation.verifyContractPetName(); + await permitConfirmation.verifyPrimaryType(); + await permitConfirmation.verifyOwner(); + await permitConfirmation.verifySpender(); + await permitConfirmation.verifyValue(); + await permitConfirmation.verifyNonce(); + await permitConfirmation.verifyDeadline(); } async function assertVerifiedResults(driver: Driver, publicAddress: string) { + const testDapp = new TestDapp(driver); + const expectedSignature = + '0xf6555e4cc39bdec3397c357af876f87de00667c942f22dec555c28d290ed7d730103fe85c9d7c66d808a0a972f69ae00741a11df449475280772e7d9a232ea491b'; + const expectedR = + '0xf6555e4cc39bdec3397c357af876f87de00667c942f22dec555c28d290ed7d73'; + const expectedS = + '0x0103fe85c9d7c66d808a0a972f69ae00741a11df449475280772e7d9a232ea49'; + const expectedV = '27'; + await driver.waitUntilXWindowHandles(2); await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp); - await driver.clickElement('#signPermitVerify'); - - await driver.waitForSelector({ - css: '#signPermitVerifyResult', - text: publicAddress, - }); - await driver.waitForSelector({ - css: '#signPermitResult', - text: '0xf6555e4cc39bdec3397c357af876f87de00667c942f22dec555c28d290ed7d730103fe85c9d7c66d808a0a972f69ae00741a11df449475280772e7d9a232ea491b', - }); - - await driver.waitForSelector({ - css: '#signPermitResultR', - text: 'r: 0xf6555e4cc39bdec3397c357af876f87de00667c942f22dec555c28d290ed7d73', - }); - - await driver.waitForSelector({ - css: '#signPermitResultS', - text: 's: 0x0103fe85c9d7c66d808a0a972f69ae00741a11df449475280772e7d9a232ea49', - }); - - await driver.waitForSelector({ - css: '#signPermitResultV', - text: 'v: 27', - }); - await driver.waitForSelector({ - css: '#signPermitVerifyResult', - text: publicAddress, - }); + await testDapp.check_successSignPermit(publicAddress); + await testDapp.verifySignPermitResult(expectedSignature); + await testDapp.verifySignPermitResultR(expectedR); + await testDapp.verifySignPermitResultS(expectedS); + await testDapp.verifySignPermitResultV(expectedV); } diff --git a/test/e2e/tests/confirmations/signatures/personal-sign.spec.ts b/test/e2e/tests/confirmations/signatures/personal-sign.spec.ts index 5f87c2d6b6e8..2bb67736df12 100644 --- a/test/e2e/tests/confirmations/signatures/personal-sign.spec.ts +++ b/test/e2e/tests/confirmations/signatures/personal-sign.spec.ts @@ -1,24 +1,28 @@ -import { strict as assert } from 'assert'; import { TransactionEnvelopeType } from '@metamask/transaction-controller'; import { Suite } from 'mocha'; import { MockedEndpoint } from 'mockttp'; -import { DAPP_HOST_ADDRESS, WINDOW_TITLES } from '../../../helpers'; +import { WINDOW_TITLES } from '../../../helpers'; import { Ganache } from '../../../seeder/ganache'; import { Driver } from '../../../webdriver/driver'; import { mockSignatureApproved, mockSignatureRejected, + scrollAndConfirmAndAssertConfirm, withTransactionEnvelopeTypeFixtures, } from '../helpers'; import { TestSuiteArguments } from '../transactions/shared'; +import TestDapp from '../../../page-objects/pages/test-dapp'; +import PersonalSignConfirmation from '../../../page-objects/pages/confirmations/redesign/personal-sign-confirmation'; import { assertAccountDetailsMetrics, assertHeaderInfoBalance, assertPastedAddress, + assertRejectedSignature, assertSignatureConfirmedMetrics, assertSignatureRejectedMetrics, clickHeaderInfoBtn, copyAddressAndPasteWalletAddress, + initializePages, openDappAndTriggerSignature, SignatureType, } from './signature-helpers'; @@ -35,18 +39,19 @@ describe('Confirmation Signature - Personal Sign @no-mmi', function (this: Suite }: TestSuiteArguments) => { const addresses = await (ganacheServer as Ganache).getAccounts(); const publicAddress = addresses?.[0] as string; + await initializePages(driver); await openDappAndTriggerSignature(driver, SignatureType.PersonalSign); await clickHeaderInfoBtn(driver); - await assertHeaderInfoBalance(driver); + await assertHeaderInfoBalance(); await copyAddressAndPasteWalletAddress(driver); - await assertPastedAddress(driver); + await assertPastedAddress(); await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); await assertInfoValues(driver); - await driver.clickElement('[data-testid="confirm-footer-button"]'); + await scrollAndConfirmAndAssertConfirm(driver); await assertVerifiedPersonalMessage(driver, publicAddress); @@ -73,19 +78,17 @@ describe('Confirmation Signature - Personal Sign @no-mmi', function (this: Suite driver, mockedEndpoint: mockedEndpoints, }: TestSuiteArguments) => { + const confirmation = new PersonalSignConfirmation(driver); + + await initializePages(driver); await openDappAndTriggerSignature(driver, SignatureType.PersonalSign); - await driver.clickElementAndWaitForWindowToClose( - '[data-testid="confirm-footer-cancel-button"]', - ); + await confirmation.clickFooterCancelButtonAndAndWaitForWindowToClose(); await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp); - const rejectionResult = await driver.waitForSelector({ - css: '#personalSign', - text: 'Error: User rejected the request.', - }); - assert.ok(rejectionResult); + await assertRejectedSignature(); + await assertSignatureRejectedMetrics({ driver, mockedEndpoints: mockedEndpoints as MockedEndpoint[], @@ -99,35 +102,19 @@ describe('Confirmation Signature - Personal Sign @no-mmi', function (this: Suite }); async function assertInfoValues(driver: Driver) { - const origin = driver.findElement({ text: DAPP_HOST_ADDRESS }); - const message = driver.findElement({ - text: 'Example `personal_sign` message', - }); - - assert.ok(await origin); - assert.ok(await message); + const personalSignConfirmation = new PersonalSignConfirmation(driver); + personalSignConfirmation.verifyOrigin(); + personalSignConfirmation.verifyMessage(); } async function assertVerifiedPersonalMessage( driver: Driver, publicAddress: string, ) { + const testDapp = new TestDapp(driver); await driver.waitUntilXWindowHandles(2); await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp); - await driver.clickElement('#personalSignVerify'); - await driver.waitForSelector({ - css: '#personalSignVerifyECRecoverResult', - text: publicAddress, - }); - - await driver.waitForSelector({ - css: '#personalSignVerifySigUtilResult', - text: publicAddress, - }); - - await driver.waitForSelector({ - css: '#personalSignVerifyECRecoverResult', - text: publicAddress, - }); + await testDapp.check_successPersonalSign(publicAddress); + await testDapp.verifyPersonalSignSigUtilResult(publicAddress); } 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 7ea7f0879279..949d79dd97a3 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 @@ -1,8 +1,7 @@ -import { strict as assert } from 'assert'; import { TransactionEnvelopeType } from '@metamask/transaction-controller'; import { Suite } from 'mocha'; import { MockedEndpoint } from 'mockttp'; -import { DAPP_HOST_ADDRESS, WINDOW_TITLES } from '../../../helpers'; +import { WINDOW_TITLES } from '../../../helpers'; import { Ganache } from '../../../seeder/ganache'; import { Driver } from '../../../webdriver/driver'; import { @@ -12,14 +11,18 @@ import { withTransactionEnvelopeTypeFixtures, } from '../helpers'; import { TestSuiteArguments } from '../transactions/shared'; +import SignTypedData from '../../../page-objects/pages/confirmations/redesign/sign-typed-data-confirmation'; +import TestDapp from '../../../page-objects/pages/test-dapp'; import { assertAccountDetailsMetrics, assertHeaderInfoBalance, assertPastedAddress, + assertRejectedSignature, assertSignatureConfirmedMetrics, assertSignatureRejectedMetrics, clickHeaderInfoBtn, copyAddressAndPasteWalletAddress, + initializePages, openDappAndTriggerSignature, SignatureType, } from './signature-helpers'; @@ -36,6 +39,7 @@ describe('Confirmation Signature - Sign Typed Data V3 @no-mmi', function (this: }: TestSuiteArguments) => { const addresses = await (ganacheServer as Ganache).getAccounts(); const publicAddress = addresses?.[0] as string; + await initializePages(driver); await openDappAndTriggerSignature( driver, @@ -43,12 +47,12 @@ describe('Confirmation Signature - Sign Typed Data V3 @no-mmi', function (this: ); await clickHeaderInfoBtn(driver); - await assertHeaderInfoBalance(driver); + await assertHeaderInfoBalance(); await copyAddressAndPasteWalletAddress(driver); - await assertPastedAddress(driver); + await assertPastedAddress(); + await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); - await driver.delay(1000); await assertInfoValues(driver); await scrollAndConfirmAndAssertConfirm(driver); @@ -77,14 +81,15 @@ describe('Confirmation Signature - Sign Typed Data V3 @no-mmi', function (this: driver, mockedEndpoint: mockedEndpoints, }: TestSuiteArguments) => { + await initializePages(driver); + const confirmation = new SignTypedData(driver); + await openDappAndTriggerSignature( driver, SignatureType.SignTypedDataV3, ); - await driver.clickElementAndWaitForWindowToClose( - '[data-testid="confirm-footer-cancel-button"]', - ); + await confirmation.clickFooterCancelButtonAndAndWaitForWindowToClose(); await assertSignatureRejectedMetrics({ driver, @@ -93,13 +98,9 @@ describe('Confirmation Signature - Sign Typed Data V3 @no-mmi', function (this: location: 'confirmation', }); - await driver.waitUntilXWindowHandles(2); await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp); - await driver.waitForSelector({ - css: '#signTypedDataV3Result', - text: 'Error: User rejected the request.', - }); + await assertRejectedSignature(); }, mockSignatureRejected, ); @@ -107,47 +108,23 @@ describe('Confirmation Signature - Sign Typed Data V3 @no-mmi', function (this: }); async function assertInfoValues(driver: Driver) { + const signTypedData = new SignTypedData(driver); await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); - const origin = driver.findElement({ text: DAPP_HOST_ADDRESS }); - const contractPetName = driver.findElement({ - css: '.name__value', - text: '0xCcCCc...ccccC', - }); - - const primaryType = driver.findElement({ text: 'Mail' }); - const fromName = driver.findElement({ text: 'Cow' }); - const fromAddress = driver.findElement({ - css: '.name__value', - text: '0xCD2a3...DD826', - }); - const toName = driver.findElement({ text: 'Bob' }); - const toAddress = driver.findElement({ - css: '.name__value', - text: '0xbBbBB...bBBbB', - }); - const contents = driver.findElement({ text: 'Hello, Bob!' }); - - assert.ok(await origin, 'origin'); - assert.ok(await contractPetName, 'contractPetName'); - assert.ok(await primaryType, 'primaryType'); - assert.ok(await fromName, 'fromName'); - assert.ok(await fromAddress, 'fromAddress'); - assert.ok(await toName, 'toName'); - assert.ok(await toAddress, 'toAddress'); - assert.ok(await contents, 'contents'); + await signTypedData.verifyOrigin(); + await signTypedData.verifyContractPetName(); + await signTypedData.verifyPrimaryType(); + await signTypedData.verifyFromName(); + await signTypedData.verifyFromAddress(); + await signTypedData.verifyToName(); + await signTypedData.verifyToAddress(); + await signTypedData.verifyContents(); } async function assertVerifiedResults(driver: Driver, publicAddress: string) { + const testDapp = new TestDapp(driver); await driver.waitUntilXWindowHandles(2); - await driver.switchToWindowWithTitle('E2E Test Dapp'); - await driver.clickElement('#signTypedDataV3Verify'); - await driver.waitForSelector({ - css: '#signTypedDataV3Result', - text: '0x0a22f7796a2a70c8dc918e7e6eb8452c8f2999d1a1eb5ad714473d36270a40d6724472e5609948c778a07216bd082b60b6f6853d6354c731fd8ccdd3a2f4af261b', - }); - - await driver.waitForSelector({ - css: '#signTypedDataV3VerifyResult', - text: publicAddress, - }); + await testDapp.check_successSignTypedDataV3(publicAddress); + await testDapp.verify_successSignTypedDataV3Result( + '0x0a22f7796a2a70c8dc918e7e6eb8452c8f2999d1a1eb5ad714473d36270a40d6724472e5609948c778a07216bd082b60b6f6853d6354c731fd8ccdd3a2f4af261b', + ); } 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 4dfe9f04972f..ccb30ef3ad3e 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,8 +1,7 @@ -import { strict as assert } from 'assert'; import { TransactionEnvelopeType } from '@metamask/transaction-controller'; import { Suite } from 'mocha'; import { MockedEndpoint } from 'mockttp'; -import { DAPP_HOST_ADDRESS, WINDOW_TITLES } from '../../../helpers'; +import { WINDOW_TITLES } from '../../../helpers'; import { Ganache } from '../../../seeder/ganache'; import { Driver } from '../../../webdriver/driver'; import { @@ -12,14 +11,18 @@ import { withTransactionEnvelopeTypeFixtures, } from '../helpers'; import { TestSuiteArguments } from '../transactions/shared'; +import SignTypedData from '../../../page-objects/pages/confirmations/redesign/sign-typed-data-confirmation'; +import TestDapp from '../../../page-objects/pages/test-dapp'; import { assertAccountDetailsMetrics, assertHeaderInfoBalance, assertPastedAddress, + assertRejectedSignature, assertSignatureConfirmedMetrics, assertSignatureRejectedMetrics, clickHeaderInfoBtn, copyAddressAndPasteWalletAddress, + initializePages, openDappAndTriggerSignature, SignatureType, } from './signature-helpers'; @@ -36,6 +39,7 @@ describe('Confirmation Signature - Sign Typed Data V4 @no-mmi', function (this: }: TestSuiteArguments) => { const addresses = await (ganacheServer as Ganache).getAccounts(); const publicAddress = addresses?.[0] as string; + await initializePages(driver); await openDappAndTriggerSignature( driver, @@ -43,10 +47,10 @@ describe('Confirmation Signature - Sign Typed Data V4 @no-mmi', function (this: ); await clickHeaderInfoBtn(driver); - await assertHeaderInfoBalance(driver); + await assertHeaderInfoBalance(); await copyAddressAndPasteWalletAddress(driver); - await assertPastedAddress(driver); + await assertPastedAddress(); await assertInfoValues(driver); await scrollAndConfirmAndAssertConfirm(driver); @@ -81,14 +85,15 @@ describe('Confirmation Signature - Sign Typed Data V4 @no-mmi', function (this: driver, mockedEndpoint: mockedEndpoints, }: TestSuiteArguments) => { + await initializePages(driver); + const confirmation = new SignTypedData(driver); + await openDappAndTriggerSignature( driver, SignatureType.SignTypedDataV4, ); - await driver.clickElementAndWaitForWindowToClose( - '[data-testid="confirm-footer-cancel-button"]', - ); + await confirmation.clickFooterCancelButtonAndAndWaitForWindowToClose(); await assertSignatureRejectedMetrics({ driver, @@ -98,14 +103,9 @@ describe('Confirmation Signature - Sign Typed Data V4 @no-mmi', function (this: location: 'confirmation', }); - await driver.waitUntilXWindowHandles(2); await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp); - const rejectionResult = await driver.waitForSelector({ - css: '#signTypedDataV4Result', - text: 'Error: User rejected the request.', - }); - assert.ok(rejectionResult); + await assertRejectedSignature(); }, async (mockServer) => { return await mockSignatureRejected(mockServer, true); @@ -115,50 +115,25 @@ describe('Confirmation Signature - Sign Typed Data V4 @no-mmi', function (this: }); async function assertInfoValues(driver: Driver) { + const signTypedData = new SignTypedData(driver); await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); - const origin = driver.findElement({ text: DAPP_HOST_ADDRESS }); - const contractPetName = driver.findElement({ - css: '.name__value', - text: '0xCcCCc...ccccC', - }); - - const primaryType = driver.findElement({ text: 'Mail' }); - const contents = driver.findElement({ text: 'Hello, Bob!' }); - const fromName = driver.findElement({ text: 'Cow' }); - const fromAddressNum0 = driver.findElement({ - css: '.name__value', - text: '0xCD2a3...DD826', - }); - const toName = driver.findElement({ text: 'Bob' }); - const toAddressNum2 = driver.findElement({ - css: '.name__value', - text: '0xB0B0b...00000', - }); - const attachment = driver.findElement({ text: '0x' }); - - assert.ok(await origin, 'origin'); - assert.ok(await contractPetName, 'contractPetName'); - assert.ok(await primaryType, 'primaryType'); - assert.ok(await contents, 'contents'); - assert.ok(await fromName, 'fromName'); - assert.ok(await fromAddressNum0, 'fromAddressNum0'); - assert.ok(await toName, 'toName'); - assert.ok(await toAddressNum2, 'toAddressNum2'); - assert.ok(await attachment, 'attachment'); + await signTypedData.verifyOrigin(); + await signTypedData.verifyContractPetName(); + await signTypedData.verifyPrimaryType(); + await signTypedData.verifyFromName(); + await signTypedData.verifyFromAddress(); + await signTypedData.verifyToName(); + await signTypedData.verifyToAddress(); + await signTypedData.verifyContents(); + await signTypedData.verifyAttachment(); + await signTypedData.verifyToAddressNum2(); } async function assertVerifiedResults(driver: Driver, publicAddress: string) { + const testDapp = new TestDapp(driver); await driver.waitUntilXWindowHandles(2); - await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp); - await driver.clickElement('#signTypedDataV4Verify'); - - await driver.waitForSelector({ - css: '#signTypedDataV4Result', - text: '0xcd2f9c55840f5e1bcf61812e93c1932485b524ca673b36355482a4fbdf52f692684f92b4f4ab6f6c8572dacce46bd107da154be1c06939b855ecce57a1616ba71b', - }); - - await driver.waitForSelector({ - css: '#signTypedDataV4VerifyResult', - text: publicAddress, - }); + await testDapp.check_successSignTypedDataV4(publicAddress); + await testDapp.verify_successSignTypedDataV4Result( + '0xcd2f9c55840f5e1bcf61812e93c1932485b524ca673b36355482a4fbdf52f692684f92b4f4ab6f6c8572dacce46bd107da154be1c06939b855ecce57a1616ba71b', + ); } 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 e7f8e1446f5c..3c1e9abc24bc 100644 --- a/test/e2e/tests/confirmations/signatures/sign-typed-data.spec.ts +++ b/test/e2e/tests/confirmations/signatures/sign-typed-data.spec.ts @@ -1,8 +1,7 @@ -import { strict as assert } from 'assert'; import { TransactionEnvelopeType } from '@metamask/transaction-controller'; import { Suite } from 'mocha'; import { MockedEndpoint } from 'mockttp'; -import { DAPP_HOST_ADDRESS, WINDOW_TITLES } from '../../../helpers'; +import { WINDOW_TITLES } from '../../../helpers'; import { Ganache } from '../../../seeder/ganache'; import { Driver } from '../../../webdriver/driver'; import { @@ -11,14 +10,18 @@ import { withTransactionEnvelopeTypeFixtures, } from '../helpers'; import { TestSuiteArguments } from '../transactions/shared'; +import SignTypedData from '../../../page-objects/pages/confirmations/redesign/sign-typed-data-confirmation'; +import TestDapp from '../../../page-objects/pages/test-dapp'; import { assertAccountDetailsMetrics, assertHeaderInfoBalance, assertPastedAddress, + assertRejectedSignature, assertSignatureConfirmedMetrics, assertSignatureRejectedMetrics, clickHeaderInfoBtn, copyAddressAndPasteWalletAddress, + initializePages, openDappAndTriggerSignature, SignatureType, } from './signature-helpers'; @@ -35,14 +38,16 @@ describe('Confirmation Signature - Sign Typed Data @no-mmi', function (this: Sui }: TestSuiteArguments) => { const addresses = await (ganacheServer as Ganache).getAccounts(); const publicAddress = addresses?.[0] as string; + await initializePages(driver); await openDappAndTriggerSignature(driver, SignatureType.SignTypedData); await clickHeaderInfoBtn(driver); - await assertHeaderInfoBalance(driver); + await assertHeaderInfoBalance(); await copyAddressAndPasteWalletAddress(driver); - await assertPastedAddress(driver); + await assertPastedAddress(); + await assertInfoValues(driver); await driver.clickElement('[data-testid="confirm-footer-button"]'); @@ -53,6 +58,7 @@ describe('Confirmation Signature - Sign Typed Data @no-mmi', function (this: Sui mockedEndpoints as MockedEndpoint[], 'eth_signTypedData', ); + await assertSignatureConfirmedMetrics({ driver, mockedEndpoints: mockedEndpoints as MockedEndpoint[], @@ -73,11 +79,12 @@ describe('Confirmation Signature - Sign Typed Data @no-mmi', function (this: Sui driver, mockedEndpoint: mockedEndpoints, }: TestSuiteArguments) => { + await initializePages(driver); + const confirmation = new SignTypedData(driver); + await openDappAndTriggerSignature(driver, SignatureType.SignTypedData); - await driver.clickElementAndWaitForWindowToClose( - '[data-testid="confirm-footer-cancel-button"]', - ); + await confirmation.clickFooterCancelButtonAndAndWaitForWindowToClose(); await assertSignatureRejectedMetrics({ driver, @@ -89,11 +96,7 @@ describe('Confirmation Signature - Sign Typed Data @no-mmi', function (this: Sui await driver.waitUntilXWindowHandles(2); await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp); - const rejectionResult = await driver.waitForSelector({ - css: '#signTypedDataResult', - text: 'Error: User rejected the request.', - }); - assert.ok(rejectionResult); + await assertRejectedSignature(); }, mockSignatureRejected, ); @@ -101,26 +104,17 @@ describe('Confirmation Signature - Sign Typed Data @no-mmi', function (this: Sui }); async function assertInfoValues(driver: Driver) { + const signTypedData = new SignTypedData(driver); await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); - const origin = driver.findElement({ text: DAPP_HOST_ADDRESS }); - const message = driver.findElement({ text: 'Hi, Alice!' }); - - assert.ok(await origin); - assert.ok(await message); + signTypedData.verifySignTypedDataMessage(); + signTypedData.verifyOrigin(); } async function assertVerifiedResults(driver: Driver, publicAddress: string) { await driver.waitUntilXWindowHandles(2); - await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp); - await driver.clickElement('#signTypedDataVerify'); - - await driver.waitForSelector({ - css: '#signTypedDataResult', - text: '0x32791e3c41d40dd5bbfb42e66cf80ca354b0869ae503ad61cd19ba68e11d4f0d2e42a5835b0bfd633596b6a7834ef7d36033633a2479dacfdb96bda360d51f451b', - }); - - await driver.waitForSelector({ - css: '#signTypedDataVerifyResult', - text: publicAddress, - }); + const testDapp = new TestDapp(driver); + testDapp.check_successSignTypedData(publicAddress); + testDapp.verify_successSignTypedDataResult( + '0x32791e3c41d40dd5bbfb42e66cf80ca354b0869ae503ad61cd19ba68e11d4f0d2e42a5835b0bfd633596b6a7834ef7d36033633a2479dacfdb96bda360d51f451b', + ); } diff --git a/test/e2e/tests/confirmations/signatures/signature-helpers.ts b/test/e2e/tests/confirmations/signatures/signature-helpers.ts index d360c46cf921..fd07c35fab19 100644 --- a/test/e2e/tests/confirmations/signatures/signature-helpers.ts +++ b/test/e2e/tests/confirmations/signatures/signature-helpers.ts @@ -1,13 +1,15 @@ import { strict as assert } from 'assert'; import { MockedEndpoint } from 'mockttp'; -import { Key } from 'selenium-webdriver/lib/input'; import { WINDOW_TITLES, getEventPayloads, - openDapp, unlockWallet, } from '../../../helpers'; import { Driver } from '../../../webdriver/driver'; +import TestDapp from '../../../page-objects/pages/test-dapp'; +import { DAPP_URL } from '../../../constants'; +import Confirmation from '../../../page-objects/pages/confirmations/redesign/confirmation'; +import AccountDetailsModal from '../../../page-objects/pages/confirmations/redesign/accountDetailsModal'; import { BlockaidReason, BlockaidResultType, @@ -63,6 +65,14 @@ const signatureAnonProperties = { eip712_domain_name: 'Ether Mail', }; +let testDapp: TestDapp; +let accountDetailsModal: AccountDetailsModal; + +export async function initializePages(driver: Driver) { + testDapp = new TestDapp(driver); + accountDetailsModal = new AccountDetailsModal(driver); +} + /** * Generates expected signature metric properties * @@ -278,40 +288,29 @@ function compareSecurityAlertResponse( } export async function clickHeaderInfoBtn(driver: Driver) { + const confirmation = new Confirmation(driver); await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); - - const accountDetailsButton = await driver.findElement( - '[data-testid="header-info__account-details-button"]', - ); - await accountDetailsButton.sendKeys(Key.RETURN); + confirmation.clickHeaderAccountDetailsButton(); } -export async function assertHeaderInfoBalance(driver: Driver) { - await driver.waitForSelector({ - css: '[data-testid="confirmation-account-details-modal__account-balance"]', - text: `${WALLET_ETH_BALANCE} ETH`, - }); +export async function assertHeaderInfoBalance() { + accountDetailsModal.assertHeaderInfoBalance(WALLET_ETH_BALANCE); } export async function copyAddressAndPasteWalletAddress(driver: Driver) { - await driver.clickElement('[data-testid="address-copy-button-text"]'); + await accountDetailsModal.clickAddressCopyButton(); await driver.delay(500); // Added delay to avoid error Element is not clickable at point (x,y) because another element obscures it, happens as soon as the mouse hovers over the close button - await driver.clickElement( - '[data-testid="confirmation-account-details-modal__close-button"]', - ); + await accountDetailsModal.clickAccountDetailsModalCloseButton(); await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp); - await driver.findElement('#eip747ContractAddress'); - await driver.pasteFromClipboardIntoField('#eip747ContractAddress'); + await testDapp.pasteIntoEip747ContractAddressInput(); } -export async function assertPastedAddress(driver: Driver) { - const formFieldEl = await driver.findElement('#eip747ContractAddress'); - assert.equal(await formFieldEl.getAttribute('value'), WALLET_ADDRESS); +export async function assertPastedAddress() { + await testDapp.assertEip747ContractAddressInputValue(WALLET_ADDRESS); } -export async function triggerSignature(driver: Driver, type: string) { - await driver.clickElement(type); - await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); +export async function assertRejectedSignature() { + testDapp.assertUserRejectedRequest(); } export async function openDappAndTriggerSignature( @@ -319,13 +318,55 @@ export async function openDappAndTriggerSignature( type: string, ) { await unlockWallet(driver); - await openDapp(driver); - await triggerSignature(driver, type); + await testDapp.openTestDappPage({ url: DAPP_URL }); + await triggerSignature(type); + await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); } export async function openDappAndTriggerDeploy(driver: Driver) { await unlockWallet(driver); - await openDapp(driver); + await testDapp.openTestDappPage({ url: DAPP_URL }); await driver.clickElement('#deployNFTsButton'); await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); } + +export async function triggerSignature(type: string) { + switch (type) { + case SignatureType.PersonalSign: + await testDapp.clickPersonalSign(); + break; + case SignatureType.Permit: + await testDapp.clickPermit(); + break; + case SignatureType.SignTypedData: + await testDapp.clickSignTypedData(); + break; + case SignatureType.SignTypedDataV3: + await testDapp.clickSignTypedDatav3(); + break; + case SignatureType.SignTypedDataV4: + await testDapp.clickSignTypedDatav4(); + break; + case SignatureType.SIWE: + await testDapp.clickSiwe(); + break; + case SignatureType.SIWE_BadDomain: + await testDapp.clickSwieBadDomain(); + break; + case SignatureType.NFTPermit: + await testDapp.clickERC721Permit(); + break; + default: + throw new Error('Invalid signature type'); + } +} + +export async function assertVerifiedSiweMessage( + driver: Driver, + message: string, +) { + await driver.waitUntilXWindowHandles(2); + await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp); + + await testDapp.check_successSiwe(message); +} diff --git a/test/e2e/tests/confirmations/signatures/siwe.spec.ts b/test/e2e/tests/confirmations/signatures/siwe.spec.ts index 4c7bec0ae121..4e90ac788a08 100644 --- a/test/e2e/tests/confirmations/signatures/siwe.spec.ts +++ b/test/e2e/tests/confirmations/signatures/siwe.spec.ts @@ -1,8 +1,7 @@ -import { strict as assert } from 'assert'; import { TransactionEnvelopeType } from '@metamask/transaction-controller'; import { Suite } from 'mocha'; import { MockedEndpoint } from 'mockttp'; -import { DAPP_HOST_ADDRESS, WINDOW_TITLES } from '../../../helpers'; +import { WINDOW_TITLES } from '../../../helpers'; import { Driver } from '../../../webdriver/driver'; import { mockSignatureApproved, @@ -11,6 +10,7 @@ import { withTransactionEnvelopeTypeFixtures, } from '../helpers'; import { TestSuiteArguments } from '../transactions/shared'; +import PersonalSignConfirmation from '../../../page-objects/pages/confirmations/redesign/personal-sign-confirmation'; import { BlockaidReason, BlockaidResultType, @@ -19,10 +19,13 @@ import { assertAccountDetailsMetrics, assertHeaderInfoBalance, assertPastedAddress, + assertRejectedSignature, assertSignatureConfirmedMetrics, assertSignatureRejectedMetrics, + assertVerifiedSiweMessage, clickHeaderInfoBtn, copyAddressAndPasteWalletAddress, + initializePages, openDappAndTriggerSignature, SignatureType, } from './signature-helpers'; @@ -36,13 +39,15 @@ describe('Confirmation Signature - SIWE @no-mmi', function (this: Suite) { driver, mockedEndpoint: mockedEndpoints, }: TestSuiteArguments) => { + await initializePages(driver); await openDappAndTriggerSignature(driver, SignatureType.SIWE); await clickHeaderInfoBtn(driver); - await assertHeaderInfoBalance(driver); + await assertHeaderInfoBalance(); await copyAddressAndPasteWalletAddress(driver); - await assertPastedAddress(driver); + await assertPastedAddress(); + await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); await assertInfoValues(driver); await scrollAndConfirmAndAssertConfirm(driver); @@ -52,6 +57,12 @@ describe('Confirmation Signature - SIWE @no-mmi', function (this: Suite) { '0xef8674a92d62a1876624547bdccaef6c67014ae821de18fa910fbff56577a65830f68848585b33d1f4b9ea1c3da1c1b11553b6aabe8446717daf7cd1e38a68271c', ); + await assertAccountDetailsMetrics( + driver, + mockedEndpoints as MockedEndpoint[], + 'personal_sign', + ); + await assertAccountDetailsMetrics( driver, mockedEndpoints as MockedEndpoint[], @@ -81,18 +92,15 @@ describe('Confirmation Signature - SIWE @no-mmi', function (this: Suite) { driver, mockedEndpoint: mockedEndpoints, }: TestSuiteArguments) => { + await initializePages(driver); + const confirmation = new PersonalSignConfirmation(driver); await openDappAndTriggerSignature(driver, SignatureType.SIWE); - await driver.clickElementAndWaitForWindowToClose( - '[data-testid="confirm-footer-cancel-button"]', - ); + await confirmation.clickFooterCancelButtonAndAndWaitForWindowToClose(); await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp); - await driver.waitForSelector({ - css: '#siweResult', - text: 'Error: User rejected the request.', - }); + await assertRejectedSignature(); await assertSignatureRejectedMetrics({ driver, mockedEndpoints: mockedEndpoints as MockedEndpoint[], @@ -112,22 +120,8 @@ describe('Confirmation Signature - SIWE @no-mmi', function (this: Suite) { }); async function assertInfoValues(driver: Driver) { - await driver.clickElement('[data-testid="sectionCollapseButton"]'); - const origin = driver.findElement({ text: DAPP_HOST_ADDRESS }); - const message = driver.findElement({ - text: 'I accept the MetaMask Terms of Service: https://community.metamask.io/tos', - }); - - assert.ok(await origin); - assert.ok(await message); -} - -async function assertVerifiedSiweMessage(driver: Driver, message: string) { - await driver.waitUntilXWindowHandles(2); - await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp); - - await driver.waitForSelector({ - css: '#siweResult', - text: message, - }); + const confirmation = new PersonalSignConfirmation(driver); + await confirmation.clickCollapseSectionButton(); + await confirmation.verifyOrigin(); + await confirmation.verifySiweMessage(); }