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: Confirm transaction test cases with Cypress #1214

Merged
merged 3 commits into from
Sep 11, 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# VS Code
.vscode
.history

# JetBrains
.idea
Expand Down
3 changes: 2 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"**/playwright-report",
"**/.cache-synpress",
"**/.vitepress/cache",
"**/downloads"
"**/downloads",
"**/.history"
]
},
"formatter": {
Expand Down
54 changes: 45 additions & 9 deletions wallets/metamask/src/cypress/MetaMask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export default class MetaMask {
.innerText()
}

async getAccountAddress() {
return await this.metamaskPlaywright.getAccountAddress()
}

async getNetwork() {
return await this.metamaskExtensionPage
.locator(this.metamaskPlaywright.homePage.selectors.currentNetwork)
Expand Down Expand Up @@ -188,6 +192,12 @@ export default class MetaMask {
})
}

async rejectTokenPermission() {
await this.metamaskPlaywright.rejectTokenPermission()

return true
}

// Network

async approveNewNetwork() {
Expand All @@ -202,6 +212,18 @@ export default class MetaMask {
return true
}

async rejectNewNetwork() {
await this.metamaskPlaywright.rejectNewNetwork()

return true
}

async rejectSwitchNetwork() {
await this.metamaskPlaywright.rejectSwitchNetwork()

return true
}

// Others

async providePublicEncryptionKey() {
Expand Down Expand Up @@ -237,15 +259,29 @@ export default class MetaMask {
})
}

async confirmTransaction() {
return await this.metamaskPlaywright
.confirmTransaction()
.then(() => {
return true
})
.catch(() => {
return false
})
async rejectSignature() {
await this.metamaskPlaywright.rejectSignature()

return true
}

async confirmTransaction(options?: { gasSetting?: GasSettings }) {
await waitFor(
() =>
this.metamaskExtensionPage.locator(TransactionPage.nftApproveAllConfirmationPopup.approveButton).isVisible(),
5_000,
false
)

await this.metamaskPlaywright.confirmTransaction(options)

return true
}

async rejectTransaction() {
await this.metamaskPlaywright.rejectTransaction()

return true
}

async confirmTransactionAndWaitForMining() {
Expand Down
11 changes: 8 additions & 3 deletions wallets/metamask/src/cypress/configureSynpress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ export default function configureSynpress(on: Cypress.PluginEvents, config: Cypr
}
})

// Synpress API
on('task', {
// Synpress API

// Account
connectToDapp: () => metamask?.connectToDapp(),
getAccount: () => metamask?.getAccount(),
getAccountAddress: () => metamask?.getAccountAddress(),
addNewAccount: (accountName: string) => metamask?.addNewAccount(accountName),
switchAccount: (accountName: string) => metamask?.switchAccount(accountName),
renameAccount: ({
Expand All @@ -93,6 +93,8 @@ export default function configureSynpress(on: Cypress.PluginEvents, config: Cypr
addNetwork: (network: Network) => metamask?.addNetwork(network),
approveNewNetwork: () => metamask?.approveNewNetwork(),
approveSwitchNetwork: () => metamask?.approveSwitchNetwork(),
rejectNewNetwork: () => metamask?.rejectNewNetwork(),
rejectSwitchNetwork: () => metamask?.rejectSwitchNetwork(),

// Anvil
createAnvilNode: (options?: CreateAnvilOptions) => metamask?.createAnvilNode(options),
Expand All @@ -105,14 +107,17 @@ export default function configureSynpress(on: Cypress.PluginEvents, config: Cypr
spendLimit?: number | 'max'
gasSetting?: GasSettings
}) => metamask?.approveTokenPermission(options),
rejectTokenPermission: () => metamask?.rejectTokenPermission(),

// Encryption
providePublicEncryptionKey: () => metamask?.providePublicEncryptionKey(),
decrypt: () => metamask?.decrypt(),

// Transactions
confirmSignature: () => metamask?.confirmSignature(),
confirmTransaction: () => metamask?.confirmTransaction(),
rejectSignature: () => metamask?.rejectSignature(),
confirmTransaction: (options?: { gasSetting?: GasSettings }) => metamask?.confirmTransaction(options),
rejectTransaction: () => metamask?.rejectTransaction(),
confirmTransactionAndWaitForMining: () => metamask?.confirmTransactionAndWaitForMining(),
openTransactionDetails: (txIndex: number) => metamask?.openTransactionDetails(txIndex),
closeTransactionDetails: () => metamask?.closeTransactionDetails()
Expand Down
30 changes: 27 additions & 3 deletions wallets/metamask/src/cypress/support/synpressCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ declare global {
addNewAccount(accountName: string): Chainable<void>
switchAccount(accountName: string): Chainable<void>
renameAccount(currentAccountName: string, newAccountName: string): Chainable<void>
getAccountAddress(): Chainable<string>

switchNetwork(networkName: string, isTestnet?: boolean): Chainable<void>
createAnvilNode(options?: CreateAnvilOptions): Chainable<{
Expand All @@ -36,18 +37,23 @@ declare global {
addNetwork(network: Network): Chainable<void>
approveNewNetwork(): Chainable<void>
approveSwitchNetwork(): Chainable<void>
rejectNewNetwork(): Chainable<void>
rejectSwitchNetwork(): Chainable<void>

deployToken(): Chainable<void>
addNewToken(): Chainable<void>
approveTokenPermission(options?: {
spendLimit?: number | 'max'
gasSetting?: GasSettings
}): Chainable<void>
rejectTokenPermission(): Chainable<void>

providePublicEncryptionKey(): Chainable<void>
decrypt(): Chainable<void>
confirmSignature(): Chainable<void>
confirmTransaction(): Chainable<void>
rejectSignature(): Chainable<void>
confirmTransaction(options?: { gasSetting?: GasSettings }): Chainable<void>
rejectTransaction(): Chainable<void>
confirmTransactionAndWaitForMining(): Chainable<void>
openTransactionDetails(txIndex: number): Chainable<void>
closeTransactionDetails(): Chainable<void>
Expand Down Expand Up @@ -78,6 +84,9 @@ export default function synpressCommands() {
Cypress.Commands.add('renameAccount', (currentAccountName: string, newAccountName: string) => {
return cy.task('renameAccount', { currentAccountName, newAccountName })
})
Cypress.Commands.add('getAccountAddress', () => {
return cy.task('getAccountAddress')
})

// Network

Expand Down Expand Up @@ -118,6 +127,12 @@ export default function synpressCommands() {
Cypress.Commands.add('approveSwitchNetwork', () => {
return cy.task('approveSwitchNetwork')
})
Cypress.Commands.add('rejectNewNetwork', () => {
return cy.task('rejectNewNetwork')
})
Cypress.Commands.add('rejectSwitchNetwork', () => {
return cy.task('rejectSwitchNetwork')
})

// Token

Expand All @@ -136,6 +151,9 @@ export default function synpressCommands() {
return cy.task('approveTokenPermission', options)
}
)
Cypress.Commands.add('rejectTokenPermission', () => {
return cy.task('rejectTokenPermission')
})

// Others

Expand All @@ -148,8 +166,14 @@ export default function synpressCommands() {
Cypress.Commands.add('confirmSignature', () => {
return cy.task('confirmSignature')
})
Cypress.Commands.add('confirmTransaction', () => {
return cy.task('confirmTransaction')
Cypress.Commands.add('rejectSignature', () => {
return cy.task('rejectSignature')
})
Cypress.Commands.add('confirmTransaction', (options?: { gasSetting?: GasSettings }) => {
return cy.task('confirmTransaction', options)
})
Cypress.Commands.add('rejectTransaction', () => {
return cy.task('rejectTransaction')
})
Cypress.Commands.add('confirmTransactionAndWaitForMining', () => {
return cy.task('confirmTransactionAndWaitForMining')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Page } from '@playwright/test'
import Selectors from '../../../../selectors/pages/NotificationPage'
import { transaction } from './transaction'
import type { GasSettings } from '../../../../type/GasSettings'
import { transaction } from './transaction'

const editTokenPermission = async (notificationPage: Page, customSpendLimit: 'max' | number) => {
if (customSpendLimit === 'max') {
Expand Down
2 changes: 1 addition & 1 deletion wallets/metamask/src/playwright/utils/waitFor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const waitForMetaMaskLoad = async (page: Page) => {
})
)
.then(() => {
console.log('All loading indicators are hidden')
return true
})
.catch((error) => {
console.error('Error: ', error)
Expand Down
2 changes: 1 addition & 1 deletion wallets/metamask/src/type/MetaMaskAbstract.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SettingsSidebarMenus } from '../selectors/pages/HomePage/settings'
import type { GasSettings } from './GasSettings'
import type { Network } from './Network'
import type { GasSettings } from './GasSettings';

export abstract class MetaMaskAbstract {
/**
Expand Down
Loading
Loading