-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Playwright - switchAccount & getAccountAddress
- Loading branch information
Showing
7 changed files
with
131 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 7 additions & 5 deletions
12
wallets/phantom/src/playwright/pages/HomePage/actions/getAccountAddress.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
import type { Page } from '@playwright/test' | ||
import Selectors from '../../../../selectors/pages/HomePage' | ||
|
||
// TODO - .getAccountAddress() to be updated for all networks | ||
export default async function getAccountAddress(page: Page): Promise<string> { | ||
await page.locator(Selectors.threeDotsMenu.threeDotsButton).click() | ||
await page.locator(Selectors.threeDotsMenu.accountDetailsButton).click() | ||
// Copy account address to clipboard | ||
await page.locator(Selectors.accountMenu.accountName).hover() | ||
await page.locator(Selectors.ethereumWalletAddress).click() | ||
|
||
const account = await page.locator(Selectors.copyAccountAddressButton).last().innerText() | ||
|
||
await page.locator(Selectors.threeDotsMenu.accountDetailsCloseButton).click() | ||
// Get clipboard content | ||
const handle = await page.evaluateHandle(() => navigator.clipboard.readText()) | ||
const account = await handle.jsonValue() | ||
|
||
return account | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
wallets/phantom/test/playwright/e2e/getAccountAddress.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { testWithSynpress } from '@synthetixio/synpress-core' | ||
import { Phantom, phantomFixtures } from '../../../src/playwright' | ||
|
||
import basicSetup from '../wallet-setup/basic.setup' | ||
|
||
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 }) => { | ||
const phantom = new Phantom(context, phantomPage, basicSetup.walletPassword) | ||
|
||
await phantom.importWalletFromPrivateKey( | ||
'ethereum', | ||
'ea084c575a01e2bbefcca3db101eaeab1d8af15554640a510c73692db24d0a6a' | ||
) | ||
|
||
const accountAddress = await phantom.getAccountAddress() | ||
|
||
expect(accountAddress).toEqual('0xa2ce797cA71d0EaE1be5a7EffD27Fd6C38126801') | ||
}) |
44 changes: 44 additions & 0 deletions
44
wallets/phantom/test/playwright/e2e/importWalletFromPrivateKey.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { testWithSynpress } from '@synthetixio/synpress-core' | ||
import { Phantom, phantomFixtures } from '../../../src/playwright' | ||
|
||
import basicSetup from '../wallet-setup/basic.setup' | ||
|
||
const test = testWithSynpress(phantomFixtures(basicSetup)) | ||
|
||
const { expect } = test | ||
|
||
test('should import a new wallet from private key', async ({ context, phantomPage }) => { | ||
const phantom = new Phantom(context, phantomPage, basicSetup.walletPassword) | ||
|
||
await phantom.importWalletFromPrivateKey( | ||
'ethereum', | ||
'ea084c575a01e2bbefcca3db101eaeab1d8af15554640a510c73692db24d0a6a' | ||
) | ||
|
||
await phantomPage.locator(phantom.homePage.selectors.accountMenu.accountName).hover() | ||
await expect(phantomPage.locator(phantom.homePage.selectors.ethereumWalletAddress)).toContainText('0xa2ce...6801') | ||
}) | ||
|
||
test('should throw an error if trying to import private key for the 2nd time', async ({ context, phantomPage }) => { | ||
const phantom = new Phantom(context, phantomPage, basicSetup.walletPassword) | ||
|
||
const privateKey = 'ea084c575a01e2bbefcca3db101eaeab1d8af15554640a510c73692db24d0a6a' | ||
|
||
await phantom.importWalletFromPrivateKey('ethereum', privateKey) | ||
|
||
const importWalletPromise = phantom.importWalletFromPrivateKey('ethereum', privateKey) | ||
|
||
await expect(importWalletPromise).rejects.toThrowError( | ||
'[ImportWalletFromPrivateKey] Importing failed due to error: This account already exists in your wallet' | ||
) | ||
}) | ||
|
||
test('should throw an error if the private key is invalid', async ({ context, phantomPage }) => { | ||
const phantom = new Phantom(context, phantomPage, basicSetup.walletPassword) | ||
|
||
const importWalletPromise = phantom.importWalletFromPrivateKey('ethereum', '0xdeadbeef') | ||
|
||
await expect(importWalletPromise).rejects.toThrowError( | ||
'[ImportWalletFromPrivateKey] Importing failed due to error: Incorrect format' | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { testWithSynpress } from '@synthetixio/synpress-core' | ||
import { Phantom, phantomFixtures } from '../../../src/playwright' | ||
|
||
import basicSetup from '../wallet-setup/basic.setup' | ||
|
||
const test = testWithSynpress(phantomFixtures(basicSetup)) | ||
|
||
const { expect } = test | ||
|
||
test('should switch account', async ({ context, phantomPage }) => { | ||
const phantom = new Phantom(context, phantomPage, basicSetup.walletPassword) | ||
|
||
await phantom.importWalletFromPrivateKey( | ||
'ethereum', | ||
'ea084c575a01e2bbefcca3db101eaeab1d8af15554640a510c73692db24d0a6a' | ||
) | ||
|
||
await phantom.importWalletFromPrivateKey( | ||
'ethereum', | ||
'7dd4aab86170c0edbdcf97600eff0ae319fdc94149c5e8c33d5439f8417a40bf' | ||
) | ||
|
||
await phantom.switchAccount('Account 1') | ||
|
||
await expect(phantomPage.getByText('Account 1')).toBeVisible() | ||
|
||
await phantomPage.locator(phantom.homePage.selectors.accountMenu.accountName).hover() | ||
await expect(phantomPage.locator(phantom.homePage.selectors.ethereumWalletAddress)).toContainText('0xf39F...2266') | ||
}) | ||
|
||
test('should throw an error if there is no account with target name', async ({ context, phantomPage }) => { | ||
const phantom = new Phantom(context, phantomPage, basicSetup.walletPassword) | ||
|
||
const accountName = 'Account 420' | ||
const switchAccountPromise = phantom.switchAccount(accountName) | ||
|
||
await expect(switchAccountPromise).rejects.toThrowError(`[SwitchAccount] Account with name ${accountName} not found`) | ||
}) |