Skip to content

Commit

Permalink
Handle known addresses correctly in confirmTransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
duckception committed Sep 6, 2023
1 parent 0c52460 commit 54002fe
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 12 deletions.
36 changes: 26 additions & 10 deletions commands/metamask.js
Original file line number Diff line number Diff line change
Expand Up @@ -1088,18 +1088,34 @@ const metamask = {
.count()) > 0
) {
log('[confirmTransaction] Getting recipient address..');
await playwright.waitAndClick(
confirmPageElements.recipientButton,
notificationPage,
);
txData.recipientPublicAddress = await playwright.waitAndGetValue(
recipientPopupElements.recipientPublicAddress,
notificationPage,
);
await playwright.waitAndClick(
recipientPopupElements.popupCloseButton,

const tooltip = await playwright.waitAndGetAttributeValue(
confirmPageElements.recipientAddressTooltipContainerButton,
'aria-describedby',
notificationPage,
true,
);

// Handles the case where the recipient address is saved and has a "nickname".
if (tooltip === 'tippy-tooltip-2') {
txData.recipientPublicAddress = await playwright.waitAndGetValue(
confirmPageElements.recipientButton,
notificationPage,
);
} else {
await playwright.waitAndClick(
confirmPageElements.recipientButton,
notificationPage,
);
txData.recipientPublicAddress = await playwright.waitAndGetValue(
recipientPopupElements.recipientPublicAddress,
notificationPage,
);
await playwright.waitAndClick(
recipientPopupElements.popupCloseButton,
notificationPage,
);
}
}
log('[confirmTransaction] Checking if network name is present..');
if (
Expand Down
11 changes: 9 additions & 2 deletions commands/playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,19 @@ module.exports = {
const value = await element.inputValue();
return value;
},
async waitAndGetAttributeValue(selector, attribute, page = metamaskWindow) {
async waitAndGetAttributeValue(
selector,
attribute,
page = metamaskWindow,
skipValidation = false,
) {
const expect = expectInstance
? expectInstance
: require('@playwright/test').expect;
const element = await module.exports.waitFor(selector, page);
await expect(element).toHaveAttribute(attribute, /[a-zA-Z0-9]/);
if (!skipValidation) {
await expect(element).toHaveAttribute(attribute, /[a-zA-Z0-9]/);
}
const attrValue = await element.getAttribute(attribute);
return attrValue;
},
Expand Down
2 changes: 2 additions & 0 deletions pages/metamask/notification-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const confirmPageContent = `${notificationPage} .confirm-page-container-content`
const networkLabel = `${confirmPageHeader} .network-display`;
const senderButton = `${confirmPageHeader} .sender-to-recipient__party--sender`;
const recipientButton = `${confirmPageHeader} .sender-to-recipient__party--recipient-with-address`;
const recipientAddressTooltipContainerButton = `${confirmPageHeader} .sender-to-recipient__party--recipient .sender-to-recipient__tooltip-container`;
const editGasFeeLegacyButton = `${notificationPage} .transaction-detail-edit button`;
const editGasFeeLegacyOverrideAckButton = `${notificationPage} .edit-gas-display .edit-gas-display__dapp-acknowledgement-button`;
const editGasLegacyPopup = `${notificationPage} .edit-gas-popover__wrapper`;
Expand Down Expand Up @@ -102,6 +103,7 @@ module.exports.confirmPageElements = {
networkLabel,
senderButton,
recipientButton,
recipientAddressTooltipContainerButton,
editGasFeeLegacyButton,
editGasFeeLegacyOverrideAckButton,
editGasLegacyPopup,
Expand Down
7 changes: 7 additions & 0 deletions tests/e2e/specs/metamask-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,13 @@ describe('Metamask', () => {
expect(txData.confirmed).to.be.true;
});
});
it(`confirmMetamaskTransaction should confirm legacy ETH transfer to yourself`, () => {
cy.get('#fromInput').type('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266')
cy.get('#toInput').type('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266')
cy.get('#amountInput').type('0x38D7EA4C68000') // 0.001 ETH
cy.get("#submitForm").click();
cy.confirmMetamaskTransaction()
});
it(`confirmMetamaskTransaction should confirm eip-1559 transaction using default settings`, () => {
cy.get('#sendEIP1559Button').click();
cy.confirmMetamaskTransaction().then(txData => {
Expand Down

0 comments on commit 54002fe

Please sign in to comment.