From 50975127b2b49ee0631abef36759cb72ca7d1113 Mon Sep 17 00:00:00 2001 From: matstyler Date: Sat, 24 Feb 2024 15:55:44 +0100 Subject: [PATCH] :sparkles: feat: Get account token helper with token transfers --- 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 3f8c9d883..dd302b629 100644 --- a/wallets/metamask/src/metamask.ts +++ b/wallets/metamask/src/metamask.ts @@ -127,6 +127,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() + }) +})