Skip to content

Commit

Permalink
Merge branch 'dev' into fix/align-cache-hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
matstyler authored Nov 24, 2024
2 parents 3e81e68 + 21f3e06 commit 9d0029e
Show file tree
Hide file tree
Showing 13 changed files with 182 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pnpm add -D @synthetixio/synpress@latest

## 📝 Documentation

For comprehensive guides, API references, and examples, refer to our [official documentation](https://synpress.io/docs/getting-started).
For comprehensive guides, API references, and examples, refer to our [official documentation](https://docs.synpress.io/docs/introduction).

## 🧑‍🤝‍🧑 Community

Expand Down
32 changes: 32 additions & 0 deletions docs/api/cypress/classes/MetaMask.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,22 @@ True if the token was added successfully

***

### approveNewEthereumRPC()

```ts
approveNewEthereumRPC(): Promise<boolean>
```

Approves adding a new RPC provider for Ethereum Mainnet.

#### Returns

`Promise`\<`boolean`\>

True if the RPC provider was added successfully

***

### approveNewNetwork()

```ts
Expand Down Expand Up @@ -558,6 +574,22 @@ True if the key was provided successfully, false otherwise
***
### rejectNewEthereumRPC()
```ts
rejectNewEthereumRPC(): Promise<boolean>
```
Rejects adding a new RPC provider for Ethereum Mainnet.
#### Returns
`Promise`\<`boolean`\>
True if the new RPC provided was rejected successfully
***
### rejectNewNetwork()
```ts
Expand Down
36 changes: 36 additions & 0 deletions docs/api/playwright/classes/MetaMask.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,24 @@ If extensionId is not set.
***
### approveNewEthereumRPC()
```ts
approveNewEthereumRPC(): Promise<void>
```
Approves adding a new RPC provider for Ethereum Mainnet.
#### Returns
`Promise`\<`void`\>
#### Throws
If extensionId is not set.
***
### approveNewNetwork()
```ts
Expand Down Expand Up @@ -586,6 +604,24 @@ If extensionId is not set.
***
### rejectNewEthereumRPC()
```ts
rejectNewEthereumRPC(): Promise<void>
```
Rejects adding a new RPC provider for Ethereum Mainnet.
#### Returns
`Promise`\<`void`\>
#### Throws
If extensionId is not set.
***
### rejectNewNetwork()
```ts
Expand Down
20 changes: 20 additions & 0 deletions wallets/metamask/src/cypress/MetaMask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,26 @@ export default class MetaMask {
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.metamaskPlaywright.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.metamaskPlaywright.rejectNewEthereumRPC()
return true
}

/**
* Locks the MetaMask wallet.
* @returns True if the wallet was locked successfully
Expand Down
2 changes: 2 additions & 0 deletions wallets/metamask/src/cypress/configureSynpress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,10 @@ export default function configureSynpress(
addNetwork: (network: Network) => metamask?.addNetwork(network),
approveNewNetwork: () => metamask?.approveNewNetwork(),
approveSwitchNetwork: () => metamask?.approveSwitchNetwork(),
approveNewEthereumRPC: () => metamask?.approveNewEthereumRPC(),
rejectNewNetwork: () => metamask?.rejectNewNetwork(),
rejectSwitchNetwork: () => metamask?.rejectSwitchNetwork(),
rejectNewEthereumRPC: () => metamask?.rejectNewEthereumRPC(),

// Anvil
createAnvilNode: (options?: CreateAnvilOptions) => metamask?.createAnvilNode(options),
Expand Down
16 changes: 16 additions & 0 deletions wallets/metamask/src/cypress/support/synpressCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ declare global {
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>
Expand Down Expand Up @@ -268,6 +270,20 @@ export default function synpressCommandsForMetaMask(): void {
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

/**
Expand Down
30 changes: 29 additions & 1 deletion wallets/metamask/src/playwright/MetaMask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,41 @@ export class MetaMask extends MetaMaskAbstract {
await this.notificationPage.rejectSwitchNetwork(this.extensionId)
}

/**
* Approves adding a new RPC provider for Ethereum Mainnet.
*
* @throws {Error} If extensionId is not set.
*/
async approveNewEthereumRPC(): Promise<void> {
if (!this.extensionId) {
throw NO_EXTENSION_ID_ERROR
}

await this.notificationPage.approveNewEthereumRPC(this.extensionId)
}

/**
* Rejects adding a new RPC provider for Ethereum Mainnet.
*
* @throws {Error} If extensionId is not set.
*/
async rejectNewEthereumRPC(): Promise<void> {
if (!this.extensionId) {
throw NO_EXTENSION_ID_ERROR
}

await this.notificationPage.rejectNewEthereumRPC(this.extensionId)
}

/**
* Confirms a transaction.
*
* @param options - Optional gas settings for the transaction.
* @throws {Error} If extensionId is not set.
*/
async confirmTransaction(options?: { gasSetting?: GasSettings }): Promise<void> {
async confirmTransaction(options?: {
gasSetting?: GasSettings
}): Promise<void> {
if (!this.extensionId) {
throw NO_EXTENSION_ID_ERROR
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { Page } from '@playwright/test'
import Selectors from '../../../../selectors/pages/NotificationPage'

const approveNewEthereumRPC = async (notificationPage: Page) => {
await notificationPage.locator(Selectors.EthereumRpcPage.approveNewRpc).click()
}

const rejectNewEthereumRPC = async (notificationPage: Page) => {
await notificationPage.locator(Selectors.EthereumRpcPage.rejectNewRpc).click()
}

export const ethereumRpc = {
approveNewEthereumRPC,
rejectNewEthereumRPC
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export * from './transaction'
export * from './network'
export * from './token'
export * from './encryption'
export * from './ethereumRpc'
13 changes: 13 additions & 0 deletions wallets/metamask/src/playwright/pages/NotificationPage/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
approvePermission,
connectToDapp,
decryptMessage,
ethereumRpc,
network,
providePublicEncryptionKey,
signSimpleMessage,
Expand Down Expand Up @@ -99,6 +100,18 @@ export class NotificationPage {
await network.rejectSwitchNetwork(notificationPage)
}

async approveNewEthereumRPC(extensionId: string) {
const notificationPage = await getNotificationPageAndWaitForLoad(this.page.context(), extensionId)

await ethereumRpc.approveNewEthereumRPC(notificationPage)
}

async rejectNewEthereumRPC(extensionId: string) {
const notificationPage = await getNotificationPageAndWaitForLoad(this.page.context(), extensionId)

await ethereumRpc.rejectNewEthereumRPC(notificationPage)
}

async confirmTransaction(extensionId: string, options?: { gasSetting?: GasSettings }) {
const notificationPage = await getNotificationPageAndWaitForLoad(this.page.context(), extensionId)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default {
approveNewRpc: '.confirmation-warning-modal__content .mm-button-primary--type-danger',
rejectNewRpc: '.confirmation-warning-modal__content .mm-button-secondary'
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ActionFooter from './actionFooter'
import ConnectPage from './connectPage'
import EthereumRpcPage from './ethereumRpcPage'
import NetworkPage from './networkPage'
import PermissionPage from './permissionPage'
import SignaturePage from './signaturePage'
Expand All @@ -8,8 +9,9 @@ import TransactionPage from './transactionPage'
export default {
ActionFooter,
ConnectPage,
SignaturePage,
EthereumRpcPage,
NetworkPage,
PermissionPage,
SignaturePage,
TransactionPage
}
10 changes: 10 additions & 0 deletions wallets/metamask/src/type/MetaMaskAbstract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ export abstract class MetaMaskAbstract {
*/
abstract rejectSwitchNetwork(): void

/**
* Approves a new RPC provider request.
*/
abstract approveNewEthereumRPC(): void

/**
* Rejects a new RPC provider request.
*/
abstract rejectNewEthereumRPC(): void

/**
* Confirms a transaction request.
*
Expand Down

0 comments on commit 9d0029e

Please sign in to comment.