diff --git a/wallets/metamask/src/cypress/MetaMask.ts b/wallets/metamask/src/cypress/MetaMask.ts index a51c7ff6e..16cded469 100644 --- a/wallets/metamask/src/cypress/MetaMask.ts +++ b/wallets/metamask/src/cypress/MetaMask.ts @@ -192,6 +192,12 @@ export default class MetaMask { }) } + async rejectTokenPermission() { + await this.metamaskPlaywright.rejectTokenPermission() + + return true + } + // Network async approveNewNetwork() { @@ -206,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() { @@ -241,6 +259,12 @@ export default class MetaMask { }) } + async rejectSignature() { + await this.metamaskPlaywright.rejectSignature() + + return true + } + async confirmTransaction(options?: { gasSetting?: GasSettings }) { await waitFor( () => @@ -254,6 +278,12 @@ export default class MetaMask { return true } + async rejectTransaction() { + await this.metamaskPlaywright.rejectTransaction() + + return true + } + async confirmTransactionAndWaitForMining() { return this.metamaskPlaywright .confirmTransactionAndWaitForMining() diff --git a/wallets/metamask/src/cypress/configureSynpress.ts b/wallets/metamask/src/cypress/configureSynpress.ts index 7b65e6bc7..464190cf6 100644 --- a/wallets/metamask/src/cypress/configureSynpress.ts +++ b/wallets/metamask/src/cypress/configureSynpress.ts @@ -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), @@ -105,6 +107,7 @@ export default function configureSynpress(on: Cypress.PluginEvents, config: Cypr spendLimit?: number | 'max' gasSetting?: GasSettings }) => metamask?.approveTokenPermission(options), + rejectTokenPermission: () => metamask?.rejectTokenPermission(), // Encryption providePublicEncryptionKey: () => metamask?.providePublicEncryptionKey(), @@ -112,7 +115,9 @@ export default function configureSynpress(on: Cypress.PluginEvents, config: Cypr // Transactions confirmSignature: () => metamask?.confirmSignature(), + 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() diff --git a/wallets/metamask/src/cypress/support/synpressCommands.ts b/wallets/metamask/src/cypress/support/synpressCommands.ts index 936757ec2..089863af3 100644 --- a/wallets/metamask/src/cypress/support/synpressCommands.ts +++ b/wallets/metamask/src/cypress/support/synpressCommands.ts @@ -37,6 +37,8 @@ declare global { addNetwork(network: Network): Chainable approveNewNetwork(): Chainable approveSwitchNetwork(): Chainable + rejectNewNetwork(): Chainable + rejectSwitchNetwork(): Chainable deployToken(): Chainable addNewToken(): Chainable @@ -44,11 +46,14 @@ declare global { spendLimit?: number | 'max' gasSetting?: GasSettings }): Chainable + rejectTokenPermission(): Chainable providePublicEncryptionKey(): Chainable decrypt(): Chainable confirmSignature(): Chainable + rejectSignature(): Chainable confirmTransaction(options?: { gasSetting?: GasSettings }): Chainable + rejectTransaction(): Chainable confirmTransactionAndWaitForMining(): Chainable openTransactionDetails(txIndex: number): Chainable closeTransactionDetails(): Chainable @@ -122,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 @@ -140,6 +151,9 @@ export default function synpressCommands() { return cy.task('approveTokenPermission', options) } ) + Cypress.Commands.add('rejectTokenPermission', () => { + return cy.task('rejectTokenPermission') + }) // Others @@ -152,9 +166,15 @@ export default function synpressCommands() { Cypress.Commands.add('confirmSignature', () => { return cy.task('confirmSignature') }) + 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') }) diff --git a/wallets/metamask/test/cypress/rejectAddNetwork.cy.ts b/wallets/metamask/test/cypress/rejectAddNetwork.cy.ts new file mode 100644 index 000000000..1e23a418d --- /dev/null +++ b/wallets/metamask/test/cypress/rejectAddNetwork.cy.ts @@ -0,0 +1,18 @@ +it('should reject new network request', () => { + cy.createAnvilNode({ + chainId: 1338, + port: 8546 + }).then(() => { + cy.get('#addEthereumChain').click() + + cy.rejectNewNetwork().then(() => { + cy.get('#chainId').should('have.text', '0x1') + + cy.emptyAnvilNode() + }) + }) +}) + +after(() => { + cy.switchNetwork('Ethereum Mainnet') +}) diff --git a/wallets/metamask/test/cypress/rejectPermission.cy.ts b/wallets/metamask/test/cypress/rejectPermission.cy.ts new file mode 100644 index 000000000..062146eed --- /dev/null +++ b/wallets/metamask/test/cypress/rejectPermission.cy.ts @@ -0,0 +1,10 @@ +it('should reject approve request', () => { + cy.get('#tokenAddresses').should('be.empty') + cy.get('#createToken').click() + + cy.confirmTransaction().then(() => { + cy.get('#approveTokens').click() + + cy.rejectTokenPermission() + }) +}) diff --git a/wallets/metamask/test/cypress/rejectSignature.cy.ts b/wallets/metamask/test/cypress/rejectSignature.cy.ts new file mode 100644 index 000000000..7def51607 --- /dev/null +++ b/wallets/metamask/test/cypress/rejectSignature.cy.ts @@ -0,0 +1,44 @@ +it('should reject `personal_sign`', () => { + cy.get('#personalSign').click() + + cy.rejectSignature() + + cy.get('#personalSign').should( + 'have.text', + 'Error: MetaMask Personal Message Signature: User denied message signature.' + ) + cy.get('#personalSignResult').should('have.text', '') +}) + +it('should reject `eth_signTypedData`', () => { + cy.get('#signTypedData').click() + + cy.rejectSignature() + + cy.get('#signTypedDataResult').should( + 'have.text', + 'Error: MetaMask Typed Message Signature: User denied message signature.' + ) +}) + +it('should reject `eth_signTypedData_v3`', () => { + cy.get('#signTypedDataV3').click() + + cy.rejectSignature() + + cy.get('#signTypedDataV3Result').should( + 'have.text', + 'Error: MetaMask Typed Message Signature: User denied message signature.' + ) +}) + +it('should reject `eth_signTypedData_v4`', () => { + cy.get('#signTypedDataV4').click() + + cy.rejectSignature() + + cy.get('#signTypedDataV4Result').should( + 'have.text', + 'Error: MetaMask Typed Message Signature: User denied message signature.' + ) +}) diff --git a/wallets/metamask/test/cypress/rejectSwitchNetwork.cy.ts b/wallets/metamask/test/cypress/rejectSwitchNetwork.cy.ts new file mode 100644 index 000000000..b3fe24c85 --- /dev/null +++ b/wallets/metamask/test/cypress/rejectSwitchNetwork.cy.ts @@ -0,0 +1,11 @@ +it('should reject switch network request', () => { + cy.switchNetwork('Ethereum Mainnet').then(() => { + cy.get('#chainId').should('have.text', '0x1') + + cy.get('#switchEthereumChain').click() + + cy.rejectSwitchNetwork() + + cy.get('#chainId').should('have.text', '0x1') + }) +}) diff --git a/wallets/metamask/test/cypress/rejectTransaction.cy.ts b/wallets/metamask/test/cypress/rejectTransaction.cy.ts new file mode 100644 index 000000000..60d011060 --- /dev/null +++ b/wallets/metamask/test/cypress/rejectTransaction.cy.ts @@ -0,0 +1,8 @@ +it('should reject contract deployment', () => { + cy.get('#tokenAddresses').should('be.empty') + cy.get('#createToken').click() + + cy.rejectTransaction().then(() => { + cy.get('#tokenAddresses').should('have.text', 'Creation Failed') + }) +})