Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat: Get account address helper with missing token transfers #1107

Merged
merged 2 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions wallets/metamask/src/metamask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
13 changes: 13 additions & 0 deletions wallets/metamask/src/pages/HomePage/actions/getAccountAddress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { Page } from '@playwright/test'
import Selectors from '../selectors'

export default async function getAccountAddress(page: Page): Promise<string> {
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
}
1 change: 1 addition & 0 deletions wallets/metamask/src/pages/HomePage/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from './addNetwork'
export * from './toggleShowTestNetworks'
export * from './addNewAccount'
export * from './transactionDetails'
export { default as getAccountAddress } from './getAccountAddress'
5 changes: 5 additions & 0 deletions wallets/metamask/src/pages/HomePage/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Page } from '@playwright/test'
import {
addNetwork,
addNewAccount,
getAccountAddress,
importWalletFromPrivateKey,
lock,
settings,
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 3 additions & 1 deletion wallets/metamask/src/pages/HomePage/selectors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
29 changes: 29 additions & 0 deletions wallets/metamask/test/e2e/metamask/confirmTransaction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
Loading