Skip to content

Commit

Permalink
Removing code related to 'adding new network'
Browse files Browse the repository at this point in the history
  • Loading branch information
zgz2020 committed Dec 9, 2024
1 parent aba1f44 commit f9d241f
Show file tree
Hide file tree
Showing 18 changed files with 7 additions and 649 deletions.
144 changes: 0 additions & 144 deletions wallets/phantom/src/cypress/Phantom.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import { type BrowserContext, type Page, expect } from '@playwright/test'
import { type Anvil, type CreateAnvilOptions, type Pool, createPool } from '@viem/anvil'
import { Phantom as PhantomPlaywright } from '../playwright/Phantom'
import { waitFor } from '../playwright/utils/waitFor'
import HomePageSelectors from '../selectors/pages/HomePage'
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 { Network } from '../type/Network'
import getPlaywrightPhantom from './getPlaywrightPhantom'

let pool: Pool

/**
* Phantom class for interacting with the Phantom extension in Cypress tests.
*/
Expand Down Expand Up @@ -173,90 +169,6 @@ export default class Phantom {
})
}

/**
* Creates an Anvil node for testing.
* @param options - Optional Anvil node creation options
* @returns Object containing the Anvil instance, RPC URL, and chain ID
*/
async createAnvilNode(options?: CreateAnvilOptions): Promise<{ anvil: Anvil; rpcUrl: string; chainId: number }> {
pool = createPool()
const nodeId = Array.from(pool.instances()).length
const anvil = await pool.start(nodeId, options)
const rpcUrl = `http://${anvil.host}:${anvil.port}`
const DEFAULT_ANVIL_CHAIN_ID = 31337
const chainId = options?.chainId ?? DEFAULT_ANVIL_CHAIN_ID
return { anvil, rpcUrl, chainId }
}

/**
* Empties the Anvil node pool.
* @returns True if the operation was successful
*/
async emptyAnvilNode(): Promise<boolean> {
await pool.empty()
return true
}

/**
* Connects to an Anvil node.
* @param options - Object containing the RPC URL and chain ID
* @param options.rpcUrl - The RPC URL of the Anvil node
* @param options.chainId - The chain ID of the Anvil node
* @returns True if the connection was successful, false otherwise
*/
async connectToAnvil({
rpcUrl,
chainId
}: {
rpcUrl: string
chainId: number
}): Promise<boolean> {
try {
await this.phantomPlaywright.addNetwork({
name: 'Anvil',
rpcUrl,
chainId,
symbol: 'ETH',
blockExplorerUrl: 'https://etherscan.io/'
})
await this.phantomPlaywright.switchNetwork('Anvil')
return true
} catch (e) {
console.error('Error connecting to Anvil network', e)
return false
}
}

/**
* Adds a new network to Phantom.
* @param network - The network configuration to add
* @returns True if the network was added successfully
*/
async addNetwork(network: Network): Promise<boolean> {
await this.phantomPlaywright.addNetwork(network)
await waitFor(
() => this.phantomExtensionPage.locator(HomePageSelectors.networkAddedPopover.switchToNetworkButton).isVisible(),
3_000,
false
)
await this.phantomExtensionPage.locator(HomePageSelectors.networkAddedPopover.switchToNetworkButton).click()
return true
}

/**
* Deploys a token.
* @returns True if the token was deployed successfully
*/
async deployToken(): Promise<boolean> {
await waitFor(
() => this.phantomExtensionPage.locator(TransactionPage.nftApproveAllConfirmationPopup.approveButton).isVisible(),
3_000,
false
)
await this.phantomPlaywright.confirmTransaction()
return true
}

/**
* Adds a new token to Phantom.
* @returns True if the token was added successfully
Expand Down Expand Up @@ -297,62 +209,6 @@ export default class Phantom {
return true
}

/**
* Approves adding a new network.
* @returns True if the new network was approved successfully
*/
async approveNewNetwork(): Promise<boolean> {
await this.phantomPlaywright.approveNewNetwork()
return true
}

/**
* Approves switching to a new network.
* @returns True if the network switch was approved successfully
*/
async approveSwitchNetwork(): Promise<boolean> {
await this.phantomPlaywright.approveSwitchNetwork()
return true
}

/**
* Rejects adding a new network.
* @returns True if the new network was rejected successfully
*/
async rejectNewNetwork(): Promise<boolean> {
await this.phantomPlaywright.rejectNewNetwork()
return true
}

/**
* Rejects switching to a new network.
* @returns True if the network switch was rejected successfully
*/
async rejectSwitchNetwork(): Promise<boolean> {
await this.phantomPlaywright.rejectSwitchNetwork()
return true
}

/**
* Approves adding a new RPC provider for Ethereum Mainnet.
*
* @returns True if the RPC provider was approved successfully
*/
async approveNewEthereumRPC(): Promise<boolean> {
await this.phantomPlaywright.approveNewEthereumRPC()
return true
}

/**
* Rejects adding a new RPC provider for Ethereum Mainnet.
*
* @returns True if the RPC provider was rejected successfully
*/
async rejectNewEthereumRPC(): Promise<boolean> {
await this.phantomPlaywright.rejectNewEthereumRPC()
return true
}

/**
* Locks the Phantom wallet.
* @returns True if the wallet was locked successfully
Expand Down
14 changes: 0 additions & 14 deletions wallets/phantom/src/cypress/configureSynpress.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import type { BrowserContext, Page } from '@playwright/test'
import { ensureRdpPort } from '@synthetixio/synpress-core'
import type { CreateAnvilOptions } from '@viem/anvil'
import type { SettingsSidebarMenus } from '../selectors/pages/HomePage/settings'
import type { GasSettings } from '../type/GasSettings'
import type { Network } from '../type/Network'
import Phantom from './Phantom'
import importPhantomWallet from './support/importPhantomWallet'
import { initPhantom } from './support/initPhantom'
Expand Down Expand Up @@ -140,20 +138,8 @@ export default function configureSynpress(
networkName,
isTestnet
}),
addNetwork: (network: Network) => phantom?.addNetwork(network),
approveNewNetwork: () => phantom?.approveNewNetwork(),
approveSwitchNetwork: () => phantom?.approveSwitchNetwork(),
approveNewEthereumRPC: () => phantom?.approveNewEthereumRPC(),
rejectNewNetwork: () => phantom?.rejectNewNetwork(),
rejectSwitchNetwork: () => phantom?.rejectSwitchNetwork(),
rejectNewEthereumRPC: () => phantom?.rejectNewEthereumRPC(),

// Anvil
createAnvilNode: (options?: CreateAnvilOptions) => phantom?.createAnvilNode(options),
emptyAnvilNode: () => phantom?.emptyAnvilNode(),

// Token
deployToken: () => phantom?.deployToken(),
addNewToken: () => phantom?.addNewToken(),
approveTokenPermission: (options?: {
spendLimit?: number | 'max'
Expand Down
126 changes: 6 additions & 120 deletions wallets/phantom/src/cypress/support/synpressCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
// https://on.cypress.io/custom-commands
// ***********************************************

import type { Anvil, CreateAnvilOptions } from '@viem/anvil'
import type { SettingsSidebarMenus } from '../../selectors/pages/HomePage/settings'
import type { GasSettings } from '../../type/GasSettings'
import type { Network } from '../../type/Network'

declare global {
namespace Cypress {
Expand All @@ -32,22 +30,7 @@ declare global {
resetAccount(): Chainable<void>

switchNetwork(networkName: string, isTestnet?: boolean): Chainable<void>
createAnvilNode(options?: CreateAnvilOptions): Chainable<{
anvil: Anvil
rpcUrl: string
chainId: number
}>
connectToAnvil(): Chainable<void>
emptyAnvilNode(): Chainable<void>
addNetwork(network: Network): Chainable<void>
approveNewNetwork(): Chainable<void>
approveSwitchNetwork(): Chainable<void>
approveNewEthereumRPC(): Chainable<void>
rejectNewNetwork(): Chainable<void>
rejectSwitchNetwork(): Chainable<void>
rejectNewEthereumRPC(): Chainable<void>

deployToken(): Chainable<void>

addNewToken(): Chainable<void>
approveTokenPermission(options?: {
spendLimit?: number | 'max'
Expand All @@ -59,7 +42,9 @@ declare global {
decrypt(): Chainable<void>
confirmSignature(): Chainable<void>
rejectSignature(): Chainable<void>
confirmTransaction(options?: { gasSetting?: GasSettings }): Chainable<void>
confirmTransaction(options?: {
gasSetting?: GasSettings
}): Chainable<void>
rejectTransaction(): Chainable<void>
confirmTransactionAndWaitForMining(): Chainable<void>
openTransactionDetails(txIndex: number): Chainable<void>
Expand Down Expand Up @@ -90,7 +75,7 @@ declare global {
* Key features:
* - Wallet: Import wallet, connect to dApps
* - Account: Add, switch, rename, reset accounts
* - Network: Switch networks, create and manage Anvil nodes, add custom networks
* - Network: Switch networks
* - Tokens: Deploy tokens, add new tokens, approve token permissions
* - Transactions: Confirm, reject, and view transaction details
* - Phantom UI: Lock/unlock, toggle settings, navigate UI
Expand Down Expand Up @@ -195,104 +180,8 @@ export default function synpressCommandsForPhantom(): void {
return cy.task('switchNetwork', { networkName, isTestnet })
})

/**
* Creates an Anvil node
* @param options - Options for creating the Anvil node
* @returns An object containing the Anvil instance, RPC URL, and chain ID
*/
Cypress.Commands.add('createAnvilNode', (options?: CreateAnvilOptions) => {
return cy.task('createAnvilNode', options)
})

/**
* Connects to an Anvil node
*/
Cypress.Commands.add('connectToAnvil', () => {
return cy.task('createAnvilNode').then((anvilNetwork) => {
const anvilNetworkDetails = anvilNetwork as {
anvil: Anvil
rpcUrl: string
chainId: number
}

const network = {
name: 'Anvil',
rpcUrl: anvilNetworkDetails.rpcUrl,
chainId: anvilNetworkDetails.chainId,
symbol: 'ETH',
blockExplorerUrl: 'https://etherscan.io/'
}

return cy.task('addNetwork', network)
})
})

/**
* Empties the Anvil node
*/
Cypress.Commands.add('emptyAnvilNode', () => {
return cy.task('emptyAnvilNode')
})

/**
* Adds a new network
* @param network - The network to add
*/
Cypress.Commands.add('addNetwork', (network: Network) => {
return cy.task('addNetwork', network)
})

/**
* Approves adding a new network
*/
Cypress.Commands.add('approveNewNetwork', () => {
return cy.task('approveNewNetwork')
})

/**
* Approves switching to a new network
*/
Cypress.Commands.add('approveSwitchNetwork', () => {
return cy.task('approveSwitchNetwork')
})

/**
* Rejects adding a new network
*/
Cypress.Commands.add('rejectNewNetwork', () => {
return cy.task('rejectNewNetwork')
})

/**
* Rejects switching to a new network
*/
Cypress.Commands.add('rejectSwitchNetwork', () => {
return cy.task('rejectSwitchNetwork')
})

/**
* Approves adding a new RPC provider for Ethereum Mainnet
*/
Cypress.Commands.add('approveNewEthereumRPC', () => {
return cy.task('approveNewEthereumRPC')
})

/**
* Rejects adding a new RPC provider for Ethereum Mainnet
*/
Cypress.Commands.add('rejectNewEthereumRPC', () => {
return cy.task('rejectNewEthereumRPC')
})

// Token

/**
* Deploys a token
*/
Cypress.Commands.add('deployToken', () => {
return cy.task('deployToken')
})

/**
* Adds a new token
*/
Expand All @@ -308,10 +197,7 @@ export default function synpressCommandsForPhantom(): void {
*/
Cypress.Commands.add(
'approveTokenPermission',
(options?: {
spendLimit?: number | 'max'
gasSetting?: GasSettings
}) => {
(options?: { spendLimit?: number | 'max'; gasSetting?: GasSettings }) => {
return cy.task('approveTokenPermission', options)
}
)
Expand Down
Loading

0 comments on commit f9d241f

Please sign in to comment.