From a07e85c9159b17b929fe582cb52b0e652abb2eb6 Mon Sep 17 00:00:00 2001 From: juan-langa Date: Wed, 11 Dec 2024 20:13:00 +0100 Subject: [PATCH] Phantom support - getAccountAddress --- wallets/phantom/src/cypress/Phantom.ts | 11 ++++------ .../phantom/src/cypress/configureSynpress.ts | 5 +++-- wallets/phantom/src/playwright/Phantom.ts | 5 +++-- .../HomePage/actions/getAccountAddress.ts | 5 +++-- .../actions/importWalletFromPrivateKey.ts | 3 ++- .../src/playwright/pages/HomePage/page.ts | 5 +++-- .../src/selectors/pages/HomePage/index.ts | 4 ++++ wallets/phantom/src/type/Networks.ts | 1 + wallets/phantom/src/type/PhantomAbstract.ts | 9 +++----- .../playwright/e2e/getAccountAddress.spec.ts | 21 ++++++++++++------- 10 files changed, 39 insertions(+), 30 deletions(-) create mode 100644 wallets/phantom/src/type/Networks.ts diff --git a/wallets/phantom/src/cypress/Phantom.ts b/wallets/phantom/src/cypress/Phantom.ts index 5123aae4..a3714d7a 100644 --- a/wallets/phantom/src/cypress/Phantom.ts +++ b/wallets/phantom/src/cypress/Phantom.ts @@ -6,6 +6,7 @@ import Selectors from '../selectors/pages/HomePage' import type { SettingsSidebarMenus } from '../selectors/pages/HomePage/settings' import TransactionPage from '../selectors/pages/NotificationPage/transactionPage' import type { GasSettings } from '../type/GasSettings' +import type { Networks } from '../type/Networks' import getPlaywrightPhantom from './getPlaywrightPhantom' /** @@ -42,8 +43,8 @@ export default class Phantom { * Gets the current account address. * @returns The current account address */ - async getAccountAddress(): Promise { - return await this.phantomPlaywright.getAccountAddress() + async getAccountAddress(network: Networks): Promise { + return await this.phantomPlaywright.getAccountAddress(network) } /** @@ -79,11 +80,7 @@ export default class Phantom { * @param privateKey - The private key to import * @returns True if the import was successful */ - async importWalletFromPrivateKey( - network: 'solana' | 'ethereum' | 'base' | 'polygon' | 'bitcoin', - privateKey: string, - walletName?: string - ): Promise { + async importWalletFromPrivateKey(network: Networks, privateKey: string, walletName?: string): Promise { await this.phantomPlaywright.importWalletFromPrivateKey(network, privateKey, walletName) return true } diff --git a/wallets/phantom/src/cypress/configureSynpress.ts b/wallets/phantom/src/cypress/configureSynpress.ts index 58bc4533..2a0a2697 100644 --- a/wallets/phantom/src/cypress/configureSynpress.ts +++ b/wallets/phantom/src/cypress/configureSynpress.ts @@ -2,6 +2,7 @@ import type { BrowserContext, Page } from '@playwright/test' import { ensureRdpPort } from '@synthetixio/synpress-core' import type { SettingsSidebarMenus } from '../selectors/pages/HomePage/settings' import type { GasSettings } from '../type/GasSettings' +import type { Networks } from '../type/Networks' import Phantom from './Phantom' import importPhantomWallet from './support/importPhantomWallet' import { initPhantom } from './support/initPhantom' @@ -106,14 +107,14 @@ export default function configureSynpress( privateKey, walletName }: { - network: 'solana' | 'ethereum' | 'base' | 'polygon' | 'bitcoin' + network: Networks privateKey: string walletName?: string }) => phantom?.importWalletFromPrivateKey(network, privateKey, walletName), // Account getAccount: () => phantom?.getAccount(), - getAccountAddress: () => phantom?.getAccountAddress(), + getAccountAddress: (network: Networks) => phantom?.getAccountAddress(network), addNewAccount: (accountName: string) => phantom?.addNewAccount(accountName), switchAccount: (accountName: string) => phantom?.switchAccount(accountName), renameAccount: ({ diff --git a/wallets/phantom/src/playwright/Phantom.ts b/wallets/phantom/src/playwright/Phantom.ts index 7000238b..15070441 100644 --- a/wallets/phantom/src/playwright/Phantom.ts +++ b/wallets/phantom/src/playwright/Phantom.ts @@ -1,6 +1,7 @@ import type { BrowserContext, Page } from '@playwright/test' import { SettingsSidebarMenus } from '../selectors/pages/HomePage/settings' import type { GasSettings } from '../type/GasSettings' +import type { Networks } from '../type/Networks' import { PhantomAbstract } from '../type/PhantomAbstract' import { CrashPage, HomePage, LockPage, NotificationPage, OnboardingPage } from './pages' import { SettingsPage } from './pages/SettingsPage/page' @@ -144,8 +145,8 @@ export class Phantom extends PhantomAbstract { * * @returns The account address. */ - async getAccountAddress(): Promise { - return await this.homePage.getAccountAddress() + async getAccountAddress(network: Networks): Promise { + return await this.homePage.getAccountAddress(network) } /** diff --git a/wallets/phantom/src/playwright/pages/HomePage/actions/getAccountAddress.ts b/wallets/phantom/src/playwright/pages/HomePage/actions/getAccountAddress.ts index 276eb572..827cd60d 100644 --- a/wallets/phantom/src/playwright/pages/HomePage/actions/getAccountAddress.ts +++ b/wallets/phantom/src/playwright/pages/HomePage/actions/getAccountAddress.ts @@ -1,11 +1,12 @@ import type { Page } from '@playwright/test' import Selectors from '../../../../selectors/pages/HomePage' +import type { Networks } from '../../../../type/Networks' // TODO - .getAccountAddress() to be updated for all networks -export default async function getAccountAddress(page: Page): Promise { +export default async function getAccountAddress(network: Networks, page: Page): Promise { // Copy account address to clipboard await page.locator(Selectors.accountMenu.accountName).hover() - await page.locator(Selectors.ethereumWalletAddress).click() + await page.locator(Selectors[`${network}WalletAddress`]).click() // Get clipboard content const handle = await page.evaluateHandle(() => navigator.clipboard.readText()) diff --git a/wallets/phantom/src/playwright/pages/HomePage/actions/importWalletFromPrivateKey.ts b/wallets/phantom/src/playwright/pages/HomePage/actions/importWalletFromPrivateKey.ts index 4febda63..29791735 100644 --- a/wallets/phantom/src/playwright/pages/HomePage/actions/importWalletFromPrivateKey.ts +++ b/wallets/phantom/src/playwright/pages/HomePage/actions/importWalletFromPrivateKey.ts @@ -1,10 +1,11 @@ import type { Page } from '@playwright/test' import Selectors from '../../../../selectors/pages/HomePage' +import type { Networks } from '../../../../type/Networks' import { waitFor } from '../../../utils/waitFor' export async function importWalletFromPrivateKey( page: Page, - network: 'solana' | 'ethereum' | 'base' | 'polygon' | 'bitcoin', + network: Networks, privateKey: string, walletName?: string ) { diff --git a/wallets/phantom/src/playwright/pages/HomePage/page.ts b/wallets/phantom/src/playwright/pages/HomePage/page.ts index ce99f390..79567530 100644 --- a/wallets/phantom/src/playwright/pages/HomePage/page.ts +++ b/wallets/phantom/src/playwright/pages/HomePage/page.ts @@ -1,6 +1,7 @@ import type { Page } from '@playwright/test' import Selectors from '../../../selectors/pages/HomePage' import type { SettingsSidebarMenus } from '../../../selectors/pages/HomePage/settings' +import type { Networks } from '../../../type/Networks' import { addNewAccount, getAccountAddress, @@ -40,8 +41,8 @@ export class HomePage { await renameAccount(this.page, currentAccountName, newAccountName) } - async getAccountAddress() { - return await getAccountAddress(this.page) + async getAccountAddress(network: Networks) { + return await getAccountAddress(network, this.page) } async importWalletFromPrivateKey( diff --git a/wallets/phantom/src/selectors/pages/HomePage/index.ts b/wallets/phantom/src/selectors/pages/HomePage/index.ts index 9b8233ba..31621624 100644 --- a/wallets/phantom/src/selectors/pages/HomePage/index.ts +++ b/wallets/phantom/src/selectors/pages/HomePage/index.ts @@ -91,7 +91,11 @@ const activityTab = { const singleToken = '.multichain-token-list-item' export default { + solanaWalletAddress: createDataTestSelector('account-header-chain-solana:101'), ethereumWalletAddress: createDataTestSelector('account-header-chain-eip155:1'), + baseWalletAddress: createDataTestSelector('account-header-chain-eip155:8453'), + polygonWalletAddress: createDataTestSelector('account-header-chain-eip155:137'), + bitcoinWalletAddress: createDataTestSelector('account-header-chain-bip122:000000000019d6689c085ae165831e93'), logo: `button${createDataTestSelector('app-header-logo')}`, copyAccountAddressButton: createDataTestSelector('address-copy-button-text'), currentNetwork: `${createDataTestSelector('network-display')} span:nth-of-type(1)`, diff --git a/wallets/phantom/src/type/Networks.ts b/wallets/phantom/src/type/Networks.ts new file mode 100644 index 00000000..372d8e67 --- /dev/null +++ b/wallets/phantom/src/type/Networks.ts @@ -0,0 +1 @@ +export type Networks = 'solana' | 'ethereum' | 'base' | 'polygon' | 'bitcoin' diff --git a/wallets/phantom/src/type/PhantomAbstract.ts b/wallets/phantom/src/type/PhantomAbstract.ts index a079c262..9ce46bf7 100644 --- a/wallets/phantom/src/type/PhantomAbstract.ts +++ b/wallets/phantom/src/type/PhantomAbstract.ts @@ -1,5 +1,6 @@ import { SettingsSidebarMenus } from '../selectors/pages/HomePage/settings' import type { GasSettings } from './GasSettings' +import type { Networks } from './Networks' export abstract class PhantomAbstract { /** @@ -41,11 +42,7 @@ export abstract class PhantomAbstract { * * @param privateKey - The private key to import. */ - abstract importWalletFromPrivateKey( - network: 'solana' | 'ethereum' | 'base' | 'polygon' | 'bitcoin', - privateKey: string, - walletName?: string - ): void + abstract importWalletFromPrivateKey(network: Networks, privateKey: string, walletName?: string): void /** * Switches to the account with the given name. @@ -57,7 +54,7 @@ export abstract class PhantomAbstract { /** * Retrieves the current account address. */ - abstract getAccountAddress(): void + abstract getAccountAddress(network: Networks): void /** * Switches to the network with the given name. diff --git a/wallets/phantom/test/playwright/e2e/getAccountAddress.spec.ts b/wallets/phantom/test/playwright/e2e/getAccountAddress.spec.ts index dab5fa89..289e45b8 100644 --- a/wallets/phantom/test/playwright/e2e/getAccountAddress.spec.ts +++ b/wallets/phantom/test/playwright/e2e/getAccountAddress.spec.ts @@ -7,16 +7,21 @@ const test = testWithSynpress(phantomFixtures(basicSetup)) const { expect } = test -// TODO - .getAccountAddress() and Tests to be updated for all networks -test('should get account address', async ({ context, phantomPage }) => { +test('should get account address for all available networks', async ({ context, phantomPage }) => { const phantom = new Phantom(context, phantomPage, basicSetup.walletPassword) - await phantom.importWalletFromPrivateKey( - 'ethereum', - 'ea084c575a01e2bbefcca3db101eaeab1d8af15554640a510c73692db24d0a6a' - ) + const solanaAccountAddress = await phantom.getAccountAddress('solana') + expect(solanaAccountAddress).toEqual('oeYf6KAJkLYhBuR8CiGc6L4D4Xtfepr85fuDgA9kq96') - const accountAddress = await phantom.getAccountAddress() + const ethereumAccountAddress = await phantom.getAccountAddress('ethereum') + expect(ethereumAccountAddress).toEqual('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266') - expect(accountAddress).toEqual('0xa2ce797cA71d0EaE1be5a7EffD27Fd6C38126801') + const baseAccountAddress = await phantom.getAccountAddress('base') + expect(baseAccountAddress).toEqual('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266') + + const polygonAccountAddress = await phantom.getAccountAddress('polygon') + expect(polygonAccountAddress).toEqual('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266') + + const bitcoinAccountAddress = await phantom.getAccountAddress('bitcoin') + expect(bitcoinAccountAddress).toEqual('bc1q4qw42stdzjqs59xvlrlxr8526e3nunw7mp73te') })