diff --git a/.vscode/cspell.json b/.vscode/cspell.json index 24e3747bfa9b..51c7db9f6211 100644 --- a/.vscode/cspell.json +++ b/.vscode/cspell.json @@ -70,6 +70,7 @@ "quickstart", "recompiles", "shellcheck", + "SIWE", "sourcemaps", "sprintf", "testcase", diff --git a/test/e2e/tests/confirmations/signatures/siwe.spec.ts b/test/e2e/tests/confirmations/signatures/siwe.spec.ts new file mode 100644 index 000000000000..51f6dd544901 --- /dev/null +++ b/test/e2e/tests/confirmations/signatures/siwe.spec.ts @@ -0,0 +1,161 @@ +import { strict as assert } from 'assert'; +import { Suite } from 'mocha'; +import { + scrollAndConfirmAndAssertConfirm, + withRedesignConfirmationFixtures, +} from '../helpers'; +import { + DAPP_HOST_ADDRESS, + WINDOW_TITLES, + openDapp, + switchToNotificationWindow, + unlockWallet, +} from '../../../helpers'; +import { Driver } from '../../../webdriver/driver'; +import { Mockttp } from '../../../mock-e2e'; +import { + assertHeaderInfoBalance, + assertPastedAddress, + clickHeaderInfoBtn, + copyAddressAndPasteWalletAddress, + assertSignatureMetrics, + assertAccountDetailsMetrics, +} from './signature-helpers'; + +describe('Confirmation Signature - SIWE @no-mmi', function (this: Suite) { + it('initiates and confirms', async function () { + await withRedesignConfirmationFixtures( + this.test?.fullTitle(), + async ({ + driver, + mockedEndpoint: mockedEndpoints, + }: { + driver: Driver; + mockedEndpoint: Mockttp; + }) => { + await unlockWallet(driver); + await openDapp(driver); + await driver.clickElement('#siwe'); + await switchToNotificationWindow(driver); + + await clickHeaderInfoBtn(driver); + await assertHeaderInfoBalance(driver); + + await copyAddressAndPasteWalletAddress(driver); + await assertPastedAddress(driver); + await assertAccountDetailsMetrics( + driver, + mockedEndpoints, + 'personal_sign', + ); + await switchToNotificationWindow(driver); + await assertInfoValues(driver); + await scrollAndConfirmAndAssertConfirm(driver); + await driver.delay(1000); + + await assertVerifiedSiweMessage( + driver, + '0xef8674a92d62a1876624547bdccaef6c67014ae821de18fa910fbff56577a65830f68848585b33d1f4b9ea1c3da1c1b11553b6aabe8446717daf7cd1e38a68271c', + ); + await assertSignatureMetrics( + driver, + mockedEndpoints, + 'personal_sign', + '', + ['redesigned_confirmation', 'sign_in_with_ethereum'], + ); + }, + ); + }); + + it('initiates and rejects', async function () { + await withRedesignConfirmationFixtures( + this.test?.fullTitle(), + async ({ + driver, + mockedEndpoint: mockedEndpoints, + }: { + driver: Driver; + mockedEndpoint: Mockttp; + }) => { + await unlockWallet(driver); + await openDapp(driver); + await driver.clickElement('#siwe'); + await switchToNotificationWindow(driver); + + await driver.clickElement( + '[data-testid="confirm-footer-cancel-button"]', + ); + + await driver.waitUntilXWindowHandles(2); + await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp); + + const rejectionResult = await driver.findElement('#siweResult'); + assert.equal( + await rejectionResult.getText(), + 'Error: User rejected the request.', + ); + await assertSignatureMetrics( + driver, + mockedEndpoints, + 'personal_sign', + '', + ['redesigned_confirmation', 'sign_in_with_ethereum'], + ); + }, + ); + }); + + it('displays alert for domain binding and confirms', async function () { + await withRedesignConfirmationFixtures( + this.test?.fullTitle(), + async ({ driver }: { driver: Driver; mockedEndpoint: Mockttp }) => { + await unlockWallet(driver); + await openDapp(driver); + await driver.clickElement('#siweBadDomain'); + await switchToNotificationWindow(driver); + + const alert = await driver.findElement('[data-testid="inline-alert"]'); + assert.equal(await alert.getText(), 'Alert'); + await driver.clickElement('[data-testid="inline-alert"]'); + + await driver.clickElement( + '[data-testid="alert-modal-acknowledge-checkbox"]', + ); + await driver.clickElement('[data-testid="alert-modal-button"]'); + + await scrollAndConfirmAndAssertConfirm(driver); + + await driver.clickElement( + '[data-testid="alert-modal-acknowledge-checkbox"]', + ); + await driver.clickElement( + '[data-testid="confirm-alert-modal-submit-button"]', + ); + + await assertVerifiedSiweMessage( + driver, + '0x24e559452c37827008633f9ae50c68cdb28e33f547f795af687839b520b022e4093c38bf1dfebda875ded715f2754d458ed62a19248e5a9bd2205bd1cb66f9b51b', + ); + }, + ); + }); +}); + +async function assertInfoValues(driver: Driver) { + 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); + + const verifySigUtil = await driver.findElement('#siweResult'); + assert.equal(await verifySigUtil.getText(), message); +} diff --git a/ui/pages/confirmations/hooks/useCurrentConfirmation.test.ts b/ui/pages/confirmations/hooks/useCurrentConfirmation.test.ts index e4fe793a45af..aa9d020465a0 100644 --- a/ui/pages/confirmations/hooks/useCurrentConfirmation.test.ts +++ b/ui/pages/confirmations/hooks/useCurrentConfirmation.test.ts @@ -204,7 +204,7 @@ describe('useCurrentConfirmation', () => { expect(currentConfirmation).toBeUndefined(); }); - it('returns undefined if message is SIWE', () => { + it('returns if message is SIWE', () => { const currentConfirmation = runHook({ message: { ...MESSAGE_MOCK, @@ -214,7 +214,10 @@ describe('useCurrentConfirmation', () => { redesignedConfirmationsEnabled: true, }); - expect(currentConfirmation).toBeUndefined(); + expect(currentConfirmation).toStrictEqual({ + id: APPROVAL_MOCK.id, + msgParams: { siwe: { isSIWEMessage: true } }, + }); }); it('returns undefined if developer and user settings are enabled and transaction has incorrect type', () => { diff --git a/ui/pages/confirmations/hooks/useCurrentConfirmation.ts b/ui/pages/confirmations/hooks/useCurrentConfirmation.ts index f4b2001a4b5b..44de32136a7d 100644 --- a/ui/pages/confirmations/hooks/useCurrentConfirmation.ts +++ b/ui/pages/confirmations/hooks/useCurrentConfirmation.ts @@ -65,15 +65,9 @@ const useCurrentConfirmation = () => { pendingApproval?.type as ApprovalType, ); - const isSIWE = - pendingApproval?.type === TransactionType.personalSign && - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (signatureMessage?.msgParams as any)?.siwe?.isSIWEMessage; - const shouldUseRedesign = isRedesignedConfirmationsUserSettingEnabled && - (isCorrectApprovalType || isCorrectTransactionType) && - !isSIWE; + (isCorrectApprovalType || isCorrectTransactionType); return useMemo(() => { if (!shouldUseRedesign) {