diff --git a/apps/trading-e2e/src/integration/wallet-eth.cy.ts b/apps/trading-e2e/src/integration/wallet-eth.cy.ts new file mode 100644 index 000000000..8e3947160 --- /dev/null +++ b/apps/trading-e2e/src/integration/wallet-eth.cy.ts @@ -0,0 +1,58 @@ +import { connectEthereumWallet } from '../support/ethereum-wallet'; + +const connectEthWalletBtn = 'connect-eth-wallet-btn'; + +describe('ethereum wallet', { tags: '@smoke' }, () => { + beforeEach(() => { + cy.mockWeb3Provider(); + // Using portfolio withdrawals tab is it requires Ethereum wallet connection + cy.mockTradingPage(); + cy.mockSubscription(); + cy.setVegaWallet(); + cy.visit('/#/portfolio'); + cy.get('main[data-testid="/portfolio"]').should('exist'); + cy.getByTestId('Withdrawals').click(); + }); + + it('can connect', () => { + // 0004-EWAL-001 + + cy.wait('@NetworkParams'); + cy.getByTestId('Deposits').click(); + cy.getByTestId('deposit-button').click(); + cy.getByTestId('connect-eth-wallet-btn').click(); + cy.getByTestId('web3-connector-list').should('exist'); + cy.getByTestId('web3-connector-MetaMask').click(); + cy.getByTestId('web3-connector-list').should('not.exist'); + cy.getByTestId('tab-deposits').should('not.be.empty'); + }); + + it('should see an option to cancel the attempted connection', () => { + // 0004-EWAL-003 + + cy.wait('@NetworkParams'); + cy.getByTestId('Deposits').click(); + cy.getByTestId('deposit-button').click(); + cy.getByTestId('connect-eth-wallet-btn').click(); + cy.getByTestId('web3-connector-list').should('exist'); + cy.getByTestId('web3-connector-WalletConnect').click(); + cy.get('#walletconnect-qrcode-text').should('exist'); + cy.get('#walletconnect-qrcode-close').click(); + }); + + it('able to disconnect eth wallet', () => { + // 0004-EWAL-004 + // 0004-EWAL-005 + // 0004-EWAL-006 + + const ethWalletAddress = Cypress.env('ETHEREUM_WALLET_ADDRESS'); + cy.getByTestId('Deposits').click(); + cy.getByTestId('deposit-button').click(); + connectEthereumWallet('MetaMask'); + cy.getByTestId('ethereum-address').should('have.text', ethWalletAddress); + cy.getByTestId('disconnect-ethereum-wallet') + .should('have.text', 'Disconnect') + .click(); + cy.getByTestId(connectEthWalletBtn).should('exist'); + }); +}); diff --git a/apps/trading-e2e/src/integration/wallets.cy.ts b/apps/trading-e2e/src/integration/wallet-vega.cy.ts similarity index 77% rename from apps/trading-e2e/src/integration/wallets.cy.ts rename to apps/trading-e2e/src/integration/wallet-vega.cy.ts index 56055f89f..2592ee14d 100644 --- a/apps/trading-e2e/src/integration/wallets.cy.ts +++ b/apps/trading-e2e/src/integration/wallet-vega.cy.ts @@ -1,7 +1,8 @@ -import { mockConnectWallet } from '@vegaprotocol/cypress'; -import { connectEthereumWallet } from '../support/ethereum-wallet'; +import { + mockConnectWallet, + mockConnectWalletWithUserError, +} from '@vegaprotocol/cypress'; -const connectEthWalletBtn = 'connect-eth-wallet-btn'; const connectVegaBtn = 'connect-vega-wallet'; const manageVegaBtn = 'manage-vega-wallet'; const form = 'rest-connector-form'; @@ -127,6 +128,21 @@ describe('connect vega wallet', { tags: '@smoke' }, () => { cy.getByTestId(manageVegaBtn).should('exist'); }); + it('can not connect', () => { + // 0002-WCON-002 + // 0002-WCON-005 + // 0002-WCON-007 + + mockConnectWalletWithUserError(); + cy.getByTestId(connectVegaBtn).click(); + cy.getByTestId('connectors-list') + .find('[data-testid="connector-jsonRpc"]') + .click(); + cy.getByTestId('dialog-content') + .should('contain.text', 'User error') + .and('contain.text', 'the user rejected the wallet connection'); + }); + it('can change selected public key and disconnect', () => { // 0002-WCON-022 // 0002-WCON-023 @@ -164,39 +180,3 @@ describe('connect vega wallet', { tags: '@smoke' }, () => { ); }); }); - -describe('ethereum wallet', { tags: '@smoke' }, () => { - beforeEach(() => { - cy.mockWeb3Provider(); - // Using portfolio withdrawals tab is it requires Ethereum wallet connection - cy.mockTradingPage(); - cy.mockSubscription(); - cy.setVegaWallet(); - cy.visit('/#/portfolio'); - cy.get('main[data-testid="/portfolio"]').should('exist'); - cy.getByTestId('Withdrawals').click(); - }); - - it('can connect', () => { - cy.wait('@NetworkParams'); - cy.getByTestId('Deposits').click(); - cy.getByTestId('deposit-button').click(); - cy.getByTestId('connect-eth-wallet-btn').click(); - cy.getByTestId('web3-connector-list').should('exist'); - cy.getByTestId('web3-connector-MetaMask').click(); - cy.getByTestId('web3-connector-list').should('not.exist'); - cy.getByTestId('tab-deposits').should('not.be.empty'); - }); - - it('able to disconnect eth wallet', () => { - const ethWalletAddress = Cypress.env('ETHEREUM_WALLET_ADDRESS'); - cy.getByTestId('Deposits').click(); - cy.getByTestId('deposit-button').click(); - connectEthereumWallet('MetaMask'); - cy.getByTestId('ethereum-address').should('have.text', ethWalletAddress); - cy.getByTestId('disconnect-ethereum-wallet') - .should('have.text', 'Disconnect') - .click(); - cy.getByTestId(connectEthWalletBtn).should('exist'); - }); -}); diff --git a/libs/cypress/src/index.ts b/libs/cypress/src/index.ts index 0796c406c..7876fe854 100644 --- a/libs/cypress/src/index.ts +++ b/libs/cypress/src/index.ts @@ -46,7 +46,10 @@ addVegaWalletSubmitProposal(); addVegaWalletSubmitLiquidityProvision(); addImportNodeWallets(); -export { mockConnectWallet } from './lib/commands/vega-wallet-connect'; +export { + mockConnectWallet, + mockConnectWalletWithUserError, +} from './lib/commands/vega-wallet-connect'; export type { onMessage } from './lib/mock-ws'; export { aliasGQLQuery } from './lib/mock-gql'; export { aliasWalletQuery } from './lib/mock-rest'; diff --git a/libs/cypress/src/lib/commands/vega-wallet-connect.ts b/libs/cypress/src/lib/commands/vega-wallet-connect.ts index ff7abcb7f..ab04edfb6 100644 --- a/libs/cypress/src/lib/commands/vega-wallet-connect.ts +++ b/libs/cypress/src/lib/commands/vega-wallet-connect.ts @@ -1,4 +1,7 @@ -import { aliasWalletConnectQuery } from '../mock-rest'; +import { + aliasWalletConnectQuery, + aliasWalletConnectWithUserError, +} from '../mock-rest'; declare global { // eslint-disable-next-line @typescript-eslint/no-namespace @@ -20,6 +23,12 @@ export const mockConnectWallet = () => { }); }; +export const mockConnectWalletWithUserError = () => { + cy.mockWallet((req) => { + aliasWalletConnectWithUserError(req); + }); +}; + export function addVegaWalletConnect() { Cypress.Commands.add('connectVegaWallet', (isMobile) => { mockConnectWallet(); diff --git a/libs/cypress/src/lib/mock-rest.ts b/libs/cypress/src/lib/mock-rest.ts index a56b6a218..5da0287c6 100644 --- a/libs/cypress/src/lib/mock-rest.ts +++ b/libs/cypress/src/lib/mock-rest.ts @@ -63,3 +63,23 @@ export const aliasWalletConnectQuery = ( }); } }; + +export const aliasWalletConnectWithUserError = ( + req: CyHttpMessages.IncomingHttpRequest +) => { + if (hasMethod(req, 'client.connect_wallet')) { + req.alias = 'client.connect_wallet'; + req.reply({ + statusCode: 400, + body: { + jsonrpc: '2.0', + error: { + code: 3001, + data: 'the user rejected the wallet connection', + message: 'User error', + }, + id: '0', + }, + }); + } +};