From 6a65b9ea5564101894255a0dee65445636a0c31d Mon Sep 17 00:00:00 2001
From: Mat <63294765+matstyler@users.noreply.github.com>
Date: Sun, 25 Feb 2024 01:44:24 +0100
Subject: [PATCH] :sparkles: feat: Get account address helper with missing
token transfers (#1107)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
## Motivation and context
Missing e2e tests for token transfers with a function to get account address.
## Quality checklist
- [x] I have performed a self-review of my code.
- [x] If it is a core feature, I have added thorough e2e tests.
**⚠️👆 Delete any section you see irrelevant before submitting the pull request 👆⚠️**
---
Generated summary
> ## TL;DR
> This pull request introduces a new feature to the MetaMask wallet that allows users to retrieve the current account address. This is achieved by adding a new method `getAccountAddress` to the `MetaMask` class and the corresponding action in the `HomePage` class.
>
> ## What changed
> - A new method `getAccountAddress` was added to the `MetaMask` class.
> - A new action `getAccountAddress` was added to the `HomePage` class.
> - The `HomePage` class was updated to include the new `getAccountAddress` action.
> - The `HomePage` selectors were updated to include the selectors needed for the new action.
> - The e2e tests were updated to include tests for the new feature.
>
> ## How to test
> 1. Pull the changes from this branch to your local environment.
> 2. Run the e2e tests using the command `npm run test:e2e`.
> 3. All tests should pass, including the new tests for the `getAccountAddress` feature.
>
> ## Why make this change
> This change is necessary to allow users to retrieve their current account address from the MetaMask wallet. This is a common requirement for many dApps and will improve the usability of the wallet.
---
wallets/metamask/src/metamask.ts | 7 +++++
.../HomePage/actions/getAccountAddress.ts | 13 +++++++++
.../src/pages/HomePage/actions/index.ts | 1 +
wallets/metamask/src/pages/HomePage/page.ts | 5 ++++
.../src/pages/HomePage/selectors/index.ts | 4 ++-
.../e2e/metamask/confirmTransaction.spec.ts | 29 +++++++++++++++++++
6 files changed, 58 insertions(+), 1 deletion(-)
create mode 100644 wallets/metamask/src/pages/HomePage/actions/getAccountAddress.ts
diff --git a/wallets/metamask/src/metamask.ts b/wallets/metamask/src/metamask.ts
index 87f6dc19d..7268c0304 100644
--- a/wallets/metamask/src/metamask.ts
+++ b/wallets/metamask/src/metamask.ts
@@ -130,6 +130,13 @@ export class MetaMask {
await this.homePage.addNetwork(network)
}
+ /**
+ * Retrieves the current account address.
+ */
+ async getAccountAddress() {
+ return await this.homePage.getAccountAddress()
+ }
+
/**
* Switches to the network with the given name.
*
diff --git a/wallets/metamask/src/pages/HomePage/actions/getAccountAddress.ts b/wallets/metamask/src/pages/HomePage/actions/getAccountAddress.ts
new file mode 100644
index 000000000..5cb5e942d
--- /dev/null
+++ b/wallets/metamask/src/pages/HomePage/actions/getAccountAddress.ts
@@ -0,0 +1,13 @@
+import type { Page } from '@playwright/test'
+import Selectors from '../selectors'
+
+export default async function getAccountAddress(page: Page): Promise {
+ await page.locator(Selectors.threeDotsMenu.threeDotsButton).click()
+ await page.locator(Selectors.threeDotsMenu.accountDetailsButton).click()
+
+ const account = await page.locator(Selectors.copyAccountAddressButton).last().innerText()
+
+ await page.locator(Selectors.threeDotsMenu.accountDetailsCloseButton).click()
+
+ return account
+}
diff --git a/wallets/metamask/src/pages/HomePage/actions/index.ts b/wallets/metamask/src/pages/HomePage/actions/index.ts
index e6ad8e1f8..e802877ad 100644
--- a/wallets/metamask/src/pages/HomePage/actions/index.ts
+++ b/wallets/metamask/src/pages/HomePage/actions/index.ts
@@ -8,3 +8,4 @@ export * from './addNetwork'
export * from './toggleShowTestNetworks'
export * from './addNewAccount'
export * from './transactionDetails'
+export { default as getAccountAddress } from './getAccountAddress'
diff --git a/wallets/metamask/src/pages/HomePage/page.ts b/wallets/metamask/src/pages/HomePage/page.ts
index 9d349812b..16333b4ae 100644
--- a/wallets/metamask/src/pages/HomePage/page.ts
+++ b/wallets/metamask/src/pages/HomePage/page.ts
@@ -2,6 +2,7 @@ import type { Page } from '@playwright/test'
import {
addNetwork,
addNewAccount,
+ getAccountAddress,
importWalletFromPrivateKey,
lock,
settings,
@@ -36,6 +37,10 @@ export class HomePage {
await addNewAccount(this.page, accountName)
}
+ async getAccountAddress() {
+ return await getAccountAddress(this.page)
+ }
+
async importWalletFromPrivateKey(privateKey: string) {
await importWalletFromPrivateKey(this.page, privateKey)
}
diff --git a/wallets/metamask/src/pages/HomePage/selectors/index.ts b/wallets/metamask/src/pages/HomePage/selectors/index.ts
index 184533692..ab24e2ec7 100644
--- a/wallets/metamask/src/pages/HomePage/selectors/index.ts
+++ b/wallets/metamask/src/pages/HomePage/selectors/index.ts
@@ -35,7 +35,9 @@ const accountMenu = {
const threeDotsMenu = {
threeDotsButton: createDataTestSelector('account-options-menu-button'),
settingsButton: createDataTestSelector('global-menu-settings'),
- lockButton: createDataTestSelector('global-menu-lock')
+ lockButton: createDataTestSelector('global-menu-lock'),
+ accountDetailsButton: createDataTestSelector('account-list-menu-details'),
+ accountDetailsCloseButton: '.mm-modal-content .mm-modal-header button.mm-button-icon.mm-button-icon--size-sm'
}
const popoverContainer = '.popover-container'
diff --git a/wallets/metamask/test/e2e/metamask/confirmTransaction.spec.ts b/wallets/metamask/test/e2e/metamask/confirmTransaction.spec.ts
index b000a0403..30d59dc76 100644
--- a/wallets/metamask/test/e2e/metamask/confirmTransaction.spec.ts
+++ b/wallets/metamask/test/e2e/metamask/confirmTransaction.spec.ts
@@ -250,3 +250,32 @@ describe('with custom gas setting', () => {
})
})
})
+
+describe('with `from` and `to` specified', () => {
+ test('should confirm from/to transfer', async ({ page, metamask, deployToken }) => {
+ await deployToken()
+
+ const accountAddress = await metamask.getAccountAddress()
+ await page.locator('#transferFromSenderInput').fill(accountAddress)
+ await page.locator('#transferFromRecipientInput').fill('0x70997970C51812dc3A010C7d01b50e0d17dc79C8')
+
+ await page.locator('#transferFromTokens').click()
+ await metamask.confirmTransaction()
+ })
+})
+
+describe('without gas limit', () => {
+ test('should approve tokens', async ({ page, metamask, deployToken }) => {
+ await deployToken()
+
+ await page.locator('#approveTokensWithoutGas').click()
+ await metamask.approveTokenPermission()
+ })
+
+ test('should transfer tokens', async ({ page, metamask, deployToken }) => {
+ await deployToken()
+
+ await page.locator('#transferTokensWithoutGas').click()
+ await metamask.confirmTransaction()
+ })
+})