-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: Adding e2e for SIWE and re-enabling redesign for SIWE #25831
Changes from all commits
b40abd8
ee15f06
b0dd8b0
42a02ad
9199ebe
a12218b
e3cb93b
152c9f3
05fffd5
37c3b65
d5e9479
b603beb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,7 @@ | |
"quickstart", | ||
"recompiles", | ||
"shellcheck", | ||
"SIWE", | ||
"sourcemaps", | ||
"sprintf", | ||
"testcase", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Info: Test for initiating and confirming a SIWE request. |
||
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 () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Info: Test for initiating and rejecting a SIWE request. |
||
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 () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Info: Test for handling domain mismatch alerts and confirming a SIWE request. |
||
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); | ||
} | ||
Comment on lines
+145
to
+153
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Info: Helper function to assert information values in the SIWE request. |
||
|
||
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); | ||
} | ||
Comment on lines
+155
to
+161
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Info: Helper function to assert the verified SIWE message. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -204,7 +204,7 @@ describe('useCurrentConfirmation', () => { | |
expect(currentConfirmation).toBeUndefined(); | ||
}); | ||
|
||
it('returns undefined if message is SIWE', () => { | ||
it('returns if message is SIWE', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Info: Updated test description to reflect the new expected behavior for SIWE messages. |
||
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 } }, | ||
}); | ||
Comment on lines
+217
to
+220
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Info: Updated expectation to check for the correct structure of the returned SIWE message. |
||
}); | ||
|
||
it('returns undefined if developer and user settings are enabled and transaction has incorrect type', () => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
Comment on lines
68
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Info: Removed |
||
|
||
return useMemo(() => { | ||
if (!shouldUseRedesign) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Info: Imported necessary modules and helper functions for the tests.