diff --git a/apps/console-lite-e2e/src/integration/market-selector.test.ts b/apps/console-lite-e2e/src/integration/market-selector.test.ts index d4340f8db..c346850fe 100644 --- a/apps/console-lite-e2e/src/integration/market-selector.test.ts +++ b/apps/console-lite-e2e/src/integration/market-selector.test.ts @@ -4,8 +4,8 @@ const marketName = 'ACTIVE MARKET'; describe('market selector', { tags: '@smoke' }, () => { beforeEach(() => { cy.mockConsole(); + cy.setVegaWallet(); cy.visit(`/trading/${marketId}`); - cy.connectVegaWallet(); cy.wait('@Markets'); }); diff --git a/apps/console-lite-e2e/src/integration/market-trade.test.ts b/apps/console-lite-e2e/src/integration/market-trade.test.ts index d41e21cb9..4e814bfc7 100644 --- a/apps/console-lite-e2e/src/integration/market-trade.test.ts +++ b/apps/console-lite-e2e/src/integration/market-trade.test.ts @@ -51,8 +51,8 @@ describe('Market trade', { tags: '@regression' }, () => { cy.mockGQL((req) => { aliasGQLQuery(req, 'Market', marketQuery(marketOverride)); }); + cy.setVegaWallet(); cy.visit(`/trading/${marketId}`); - cy.connectVegaWallet(); cy.wait('@Market'); }); diff --git a/apps/console-lite-e2e/src/integration/portfolio-page.test.ts b/apps/console-lite-e2e/src/integration/portfolio-page.test.ts index a9c5c8a97..ccbd52009 100644 --- a/apps/console-lite-e2e/src/integration/portfolio-page.test.ts +++ b/apps/console-lite-e2e/src/integration/portfolio-page.test.ts @@ -34,11 +34,11 @@ describe('Portfolio page tabs', { tags: '@smoke' }, () => { aliasGQLQuery(req, 'Accounts', accountsQuery()); aliasGQLQuery(req, 'Assets', assetsQuery()); }); + cy.setVegaWallet(); }); it('certain tabs should exist', () => { cy.visit('/portfolio'); - cy.connectVegaWallet(); cy.getByTestId('assets').click(); cy.location('pathname').should('eq', '/portfolio/assets'); @@ -68,17 +68,13 @@ describe('Portfolio page tabs', { tags: '@smoke' }, () => { aliasGQLQuery(req, 'Accounts', accountsQuery()); aliasGQLQuery(req, 'Assets', assetsQuery()); }); + cy.setVegaWallet(); cy.visit('/portfolio/assets'); - cy.connectVegaWallet(); }); it('data should be properly rendered', () => { cy.get('.ag-center-cols-container .ag-row').should('have.length', 5); - cy.get( - '.ag-center-cols-container [row-id="ACCOUNT_TYPE_GENERAL-asset-id-null"]' - ) - .find('button') - .click(); + cy.get('[title="tEURO"] button').click(); cy.getByTestId('dialog-title').should( 'have.text', 'Asset details - tEURO' @@ -99,8 +95,8 @@ describe('Portfolio page tabs', { tags: '@smoke' }, () => { aliasGQLQuery(req, 'Accounts', accountsQuery()); aliasGQLQuery(req, 'Assets', assetsQuery()); }); + cy.setVegaWallet(); cy.visit('/portfolio/positions'); - cy.connectVegaWallet(); }); it('data should be properly rendered', () => { @@ -116,8 +112,8 @@ describe('Portfolio page tabs', { tags: '@smoke' }, () => { aliasGQLQuery(req, 'Orders', ordersQuery()); aliasGQLQuery(req, 'Markets', marketsQuery()); }); + cy.setVegaWallet(); cy.visit('/portfolio/orders'); - cy.connectVegaWallet(); }); it('data should be properly rendered', () => { @@ -134,8 +130,8 @@ describe('Portfolio page tabs', { tags: '@smoke' }, () => { aliasGQLQuery(req, 'Markets', marketsQuery()); aliasGQLQuery(req, 'Fills', fillsQuery()); }); + cy.setVegaWallet(); cy.visit('/portfolio/fills'); - cy.connectVegaWallet(); }); it('data should be properly rendered', () => { @@ -161,8 +157,8 @@ describe('Portfolio page tabs', { tags: '@smoke' }, () => { aliasGQLQuery(req, 'Margins', marginsQuery()); aliasGQLQuery(req, 'MarketsData', marketsDataQuery()); }); + cy.setVegaWallet(); cy.visit('/portfolio'); - cy.connectVegaWallet(); }); it('"No data to display" should be always displayed', () => { diff --git a/apps/trading-e2e/src/integration/deposit.cy.ts b/apps/trading-e2e/src/integration/deposit.cy.ts index 837e50473..4838256b7 100644 --- a/apps/trading-e2e/src/integration/deposit.cy.ts +++ b/apps/trading-e2e/src/integration/deposit.cy.ts @@ -6,43 +6,41 @@ const amountField = 'input[name="amount"]'; const formFieldError = 'input-error-text'; describe('deposit form validation', { tags: '@smoke' }, () => { - beforeEach(() => { + before(() => { cy.mockWeb3Provider(); cy.mockSubscription(); cy.mockTradingPage(); + cy.setVegaWallet(); cy.visit('/#/portfolio'); cy.get('main[data-testid="/portfolio"]').should('exist'); cy.getByTestId('Deposits').click(); - cy.getByTestId('tab-deposits').contains('Connect your Vega wallet'); - cy.connectVegaWallet(); cy.getByTestId('deposit-button').click(); cy.wait('@Assets'); + connectEthereumWallet(); + cy.getByTestId('deposit-submit').click(); + }); + + it('handles empty fields', () => { + cy.getByTestId(formFieldError).should('contain.text', 'Required'); + cy.getByTestId(formFieldError).should('have.length', 2); }); it('unable to select assets not enabled', () => { - connectEthereumWallet(); - cy.getByTestId('deposit-submit').click(); // Assets not enabled in mocks cy.get(assetSelectField + ' option:contains(Asset 2)').should('not.exist'); cy.get(assetSelectField + ' option:contains(Asset 3)').should('not.exist'); cy.get(assetSelectField + ' option:contains(Asset 4)').should('not.exist'); }); - it('handles empty fields', () => { - connectEthereumWallet(); - // Submit form to trigger any empty validation messages - cy.getByTestId('deposit-submit').click(); - - cy.getByTestId(formFieldError).should('contain.text', 'Required'); - cy.getByTestId(formFieldError).should('have.length', 2); - - // Invalid public key + it('invalid public key', () => { cy.get(toAddressField) .clear() .type('INVALID_DEPOSIT_TO_ADDRESS') .next(`[data-testid="${formFieldError}"]`) .should('have.text', 'Invalid Vega key'); + }); + it('invalid amount', () => { // Deposit amount smaller than minimum viable for selected asset // Select an amount so that we have a known decimal places value to work with cy.get(assetSelectField).select('Euro'); @@ -51,7 +49,9 @@ describe('deposit form validation', { tags: '@smoke' }, () => { .type('0.00000000000000000000000000000000001') .next(`[data-testid="${formFieldError}"]`) .should('have.text', 'Value is below minimum'); + }); + it('insufficient funds', () => { // Deposit amount is valid, but less than approved. This will always be the case because our // CI wallet wont have approved any assets cy.get(amountField) diff --git a/apps/trading-e2e/src/integration/market-summary.cy.ts b/apps/trading-e2e/src/integration/market-summary.cy.ts index f3c7bca86..af7e72a62 100644 --- a/apps/trading-e2e/src/integration/market-summary.cy.ts +++ b/apps/trading-e2e/src/integration/market-summary.cy.ts @@ -235,9 +235,9 @@ describe('market states not accepting orders', { tags: '@smoke' }, function () { beforeEach(function () { cy.mockTradingPage(marketState); cy.mockSubscription(); + cy.setVegaWallet(); cy.visit('/#/markets/market-0'); cy.wait('@Market'); - cy.connectVegaWallet(); }); it('must display that market is not accepting orders', function () { cy.getByTestId('place-order').click(); diff --git a/apps/trading-e2e/src/integration/trading-accounts.cy.ts b/apps/trading-e2e/src/integration/trading-accounts.cy.ts index 6b3423e85..ec705d801 100644 --- a/apps/trading-e2e/src/integration/trading-accounts.cy.ts +++ b/apps/trading-e2e/src/integration/trading-accounts.cy.ts @@ -2,6 +2,7 @@ beforeEach(() => { cy.mockTradingPage(); cy.mockWeb3Provider(); cy.mockSubscription(); + cy.setVegaWallet(); cy.visit('/#/markets/market-0'); }); @@ -10,8 +11,6 @@ describe('accounts', { tags: '@smoke' }, () => { const tradingAccountRowId = '[row-id="asset-0"]'; cy.getByTestId('Collateral').click(); - cy.connectVegaWallet(); - cy.getByTestId('tab-accounts').should('be.visible'); cy.getByTestId('tab-accounts') diff --git a/apps/trading-e2e/src/integration/trading-deal-ticket.cy.ts b/apps/trading-e2e/src/integration/trading-deal-ticket.cy.ts index c5f89ee30..853c358a8 100644 --- a/apps/trading-e2e/src/integration/trading-deal-ticket.cy.ts +++ b/apps/trading-e2e/src/integration/trading-deal-ticket.cy.ts @@ -30,16 +30,7 @@ const displayTomorrow = () => { describe('time in force default values', () => { before(() => { - cy.window().then((win) => { - win.localStorage.setItem( - 'vega_wallet_config', - JSON.stringify({ - token: Cypress.env('VEGA_WALLET_API_TOKEN'), - connector: 'jsonRpc', - url: 'http://localhost:1789', - }) - ); - }); + cy.setVegaWallet(); cy.mockTradingPage(); cy.mockSubscription(); cy.visit('/#/markets/market-0'); @@ -68,7 +59,7 @@ describe('time in force default values', () => { describe('must submit order', { tags: '@smoke' }, () => { // 7002-SORD-039 before(() => { - setVegaConfig(); + cy.setVegaWallet(); cy.mockTradingPage(); cy.mockSubscription(); cy.visit('/#/markets/market-0'); @@ -76,7 +67,7 @@ describe('must submit order', { tags: '@smoke' }, () => { }); beforeEach(() => { - setVegaConfig(); + cy.setVegaWallet(); }); it('successfully places market buy order', () => { @@ -162,7 +153,7 @@ describe( { tags: '@regression' }, () => { before(() => { - setVegaConfig(); + cy.setVegaWallet(); cy.mockTradingPage( Schema.MarketState.STATE_SUSPENDED, Schema.MarketTradingMode.TRADING_MODE_BATCH_AUCTION, @@ -174,7 +165,7 @@ describe( }); beforeEach(() => { - setVegaConfig(); + cy.setVegaWallet(); }); it('successfully places limit buy order', () => { @@ -231,7 +222,7 @@ describe( { tags: '@regression' }, () => { before(() => { - setVegaConfig(); + cy.setVegaWallet(); cy.mockTradingPage( Schema.MarketState.STATE_SUSPENDED, Schema.MarketTradingMode.TRADING_MODE_OPENING_AUCTION, @@ -243,7 +234,7 @@ describe( }); beforeEach(() => { - setVegaConfig(); + cy.setVegaWallet(); }); it('successfully places limit buy order', () => { @@ -300,7 +291,7 @@ describe( { tags: '@regression' }, () => { before(() => { - setVegaConfig(); + cy.setVegaWallet(); cy.mockTradingPage( Schema.MarketState.STATE_SUSPENDED, Schema.MarketTradingMode.TRADING_MODE_MONITORING_AUCTION, @@ -312,7 +303,7 @@ describe( }); beforeEach(() => { - setVegaConfig(); + cy.setVegaWallet(); }); it('successfully places limit buy order', () => { @@ -410,7 +401,7 @@ describe('deal ticket validation', { tags: '@smoke' }, () => { describe('deal ticket size validation', { tags: '@smoke' }, function () { beforeEach(() => { - setVegaConfig(); + cy.setVegaWallet(); cy.mockTradingPage(); cy.visit('/#/markets/market-0'); cy.wait('@Market'); @@ -444,7 +435,7 @@ describe('deal ticket size validation', { tags: '@smoke' }, function () { describe('limit order validations', { tags: '@smoke' }, () => { before(() => { - setVegaConfig(); + cy.setVegaWallet(); cy.mockTradingPage(); cy.mockSubscription(); cy.visit('/#/markets/market-0'); @@ -453,7 +444,7 @@ describe('limit order validations', { tags: '@smoke' }, () => { }); beforeEach(() => { - setVegaConfig(); + cy.setVegaWallet(); }); it('must see the price unit', function () { @@ -537,7 +528,7 @@ describe('limit order validations', { tags: '@smoke' }, () => { describe('market order validations', { tags: '@smoke' }, () => { before(() => { - setVegaConfig(); + cy.setVegaWallet(); cy.mockTradingPage(); cy.visit('/#/markets/market-0'); cy.wait('@Market'); @@ -545,7 +536,7 @@ describe('market order validations', { tags: '@smoke' }, () => { }); beforeEach(() => { - setVegaConfig(); + cy.setVegaWallet(); }); it('must not see the price unit', function () { @@ -586,7 +577,7 @@ describe('market order validations', { tags: '@smoke' }, () => { describe('suspended market validation', { tags: '@regression' }, () => { before(() => { - setVegaConfig(); + cy.setVegaWallet(); cy.mockTradingPage( Schema.MarketState.STATE_SUSPENDED, Schema.MarketTradingMode.TRADING_MODE_MONITORING_AUCTION, @@ -598,7 +589,7 @@ describe('suspended market validation', { tags: '@regression' }, () => { }); beforeEach(() => { - setVegaConfig(); + cy.setVegaWallet(); }); it('should show warning for market order', function () { @@ -639,7 +630,7 @@ describe('suspended market validation', { tags: '@regression' }, () => { describe('account validation', { tags: '@regression' }, () => { describe('zero balance error', () => { beforeEach(() => { - setVegaConfig(); + cy.setVegaWallet(); cy.mockTradingPage(); cy.mockGQL((req) => { aliasGQLQuery( @@ -686,7 +677,7 @@ describe('account validation', { tags: '@regression' }, () => { describe('not enough balance warning', () => { beforeEach(() => { - setVegaConfig(); + cy.setVegaWallet(); cy.mockTradingPage(); cy.mockGQL((req) => { aliasGQLQuery( @@ -745,16 +736,3 @@ const createOrder = (order: OrderSubmission): void => { } cy.getByTestId(placeOrderBtn).click(); }; - -const setVegaConfig = () => { - cy.window().then((win) => { - win.localStorage.setItem( - 'vega_wallet_config', - JSON.stringify({ - token: Cypress.env('VEGA_WALLET_API_TOKEN'), - connector: 'jsonRpc', - url: 'http://localhost:1789', - }) - ); - }); -}; diff --git a/apps/trading-e2e/src/integration/trading-fills.cy.ts b/apps/trading-e2e/src/integration/trading-fills.cy.ts index cc168336e..ccf3d2d6d 100644 --- a/apps/trading-e2e/src/integration/trading-fills.cy.ts +++ b/apps/trading-e2e/src/integration/trading-fills.cy.ts @@ -12,6 +12,7 @@ describe('fills', { tags: '@regression' }, () => { ) ); }); + cy.setVegaWallet(); cy.mockTradingPage(); cy.mockGQL((req) => { aliasGQLQuery( @@ -27,20 +28,12 @@ describe('fills', { tags: '@regression' }, () => { cy.visit('/#/portfolio'); cy.get('main[data-testid="/portfolio"]').should('exist'); cy.getByTestId('Fills').click(); - cy.getByTestId('tab-fills').contains('Connect your Vega wallet'); - cy.connectVegaWallet(); validateFillsDisplayed(); }); it('renders fills on trading tab', () => { - cy.mockTradingPage(); cy.visit('/#/markets/market-0'); cy.getByTestId('Fills').click(); - cy.getByTestId('tab-fills').should( - 'contain.text', - 'Connect your Vega wallet' - ); - cy.connectVegaWallet(); validateFillsDisplayed(); }); diff --git a/apps/trading-e2e/src/integration/trading-orders.cy.ts b/apps/trading-e2e/src/integration/trading-orders.cy.ts index 2cbe5cc1d..4b66c78ec 100644 --- a/apps/trading-e2e/src/integration/trading-orders.cy.ts +++ b/apps/trading-e2e/src/integration/trading-orders.cy.ts @@ -27,9 +27,9 @@ describe('orders list', { tags: '@smoke' }, () => { cy.spy(subscriptionMocks, 'OrdersUpdate'); cy.mockTradingPage(); cy.mockSubscription(subscriptionMocks); + cy.setVegaWallet(); cy.visit('/#/markets/market-0'); cy.getByTestId('Orders').click(); - cy.connectVegaWallet(); cy.wait('@Orders').then(() => { expect(subscriptionMocks.OrdersUpdate).to.be.calledOnce; }); @@ -125,9 +125,9 @@ describe('subscribe orders', { tags: '@smoke' }, () => { cy.spy(subscriptionMocks, 'OrdersUpdate'); cy.mockTradingPage(); cy.mockSubscription(subscriptionMocks); + cy.setVegaWallet(); cy.visit('/#/markets/market-0'); cy.getByTestId('Orders').click(); - cy.connectVegaWallet(); cy.wait('@Orders').then(() => { expect(subscriptionMocks.OrdersUpdate).to.be.calledOnce; }); @@ -341,9 +341,9 @@ describe('amend and cancel order', { tags: '@smoke' }, () => { cy.spy(subscriptionMocks, 'OrdersUpdate'); cy.mockTradingPage(); cy.mockSubscription(subscriptionMocks); + cy.setVegaWallet(); cy.visit('/#/markets/market-0'); cy.getByTestId('Orders').click(); - cy.connectVegaWallet(); cy.wait('@Orders').then(() => { expect(subscriptionMocks.OrdersUpdate).to.be.calledOnce; }); diff --git a/apps/trading-e2e/src/integration/trading-portfolio.cy.ts b/apps/trading-e2e/src/integration/trading-portfolio.cy.ts index c39f8a7c8..ea33500b3 100644 --- a/apps/trading-e2e/src/integration/trading-portfolio.cy.ts +++ b/apps/trading-e2e/src/integration/trading-portfolio.cy.ts @@ -13,11 +13,11 @@ describe('Portfolio page', { tags: '@smoke' }, () => { aliasGQLQuery(req, 'Markets', marketsQuery()); }); cy.mockSubscription(); + cy.setVegaWallet(); }); describe('Ledger entries', () => { it('List should be properly rendered', () => { cy.visit('/#/portfolio'); - cy.connectVegaWallet(); cy.getByTestId('"Ledger entries"').click(); const headers = [ 'Sender', diff --git a/apps/trading-e2e/src/integration/trading-positions.cy.ts b/apps/trading-e2e/src/integration/trading-positions.cy.ts index cd2412eec..48f4b0166 100644 --- a/apps/trading-e2e/src/integration/trading-positions.cy.ts +++ b/apps/trading-e2e/src/integration/trading-positions.cy.ts @@ -1,25 +1,19 @@ beforeEach(() => { cy.mockTradingPage(); cy.mockSubscription(); + cy.setVegaWallet(); }); describe('positions', { tags: '@smoke' }, () => { it('renders positions on trading page', () => { cy.visit('/#/markets/market-0'); cy.getByTestId('Positions').click(); - cy.getByTestId('tab-positions').should( - 'contain.text', - 'Connect your Vega wallet' - ); - - cy.connectVegaWallet(); validatePositionsDisplayed(); }); it('renders positions on portfolio page', () => { cy.visit('/#/portfolio'); cy.getByTestId('Positions').click(); - cy.connectVegaWallet(); validatePositionsDisplayed(); }); diff --git a/apps/trading-e2e/src/integration/withdraw.cy.ts b/apps/trading-e2e/src/integration/withdraw.cy.ts index b0e332a7c..225cadca1 100644 --- a/apps/trading-e2e/src/integration/withdraw.cy.ts +++ b/apps/trading-e2e/src/integration/withdraw.cy.ts @@ -15,13 +15,11 @@ describe('withdraw form validation', { tags: '@smoke' }, () => { cy.mockWeb3Provider(); cy.mockTradingPage(); cy.mockSubscription(); + cy.setVegaWallet(); cy.visit('/#/portfolio'); cy.getByTestId('Withdrawals').click(); - // Withdraw page requires vega wallet connection - cy.connectVegaWallet(); - cy.getByTestId('withdraw-dialog-button').click(); // It also requires connection Ethereum wallet @@ -72,13 +70,10 @@ describe('withdraw actions', { tags: '@regression' }, () => { cy.mockWeb3Provider(); cy.mockTradingPage(); cy.mockSubscription(); + cy.setVegaWallet(); cy.visit('/#/portfolio'); cy.getByTestId('Withdrawals').click(); - - // Withdraw page requires vega wallet connection - cy.connectVegaWallet(); - cy.getByTestId('withdraw-dialog-button').click(); connectEthereumWallet(); diff --git a/libs/cypress/src/index.ts b/libs/cypress/src/index.ts index a8615898f..f69f6a1b7 100644 --- a/libs/cypress/src/index.ts +++ b/libs/cypress/src/index.ts @@ -10,7 +10,10 @@ import { addVegaWalletReceiveFaucetedAsset } from './lib/commands/vega-wallet-re import { addContainsExactly } from './lib/commands/contains-exactly'; import { addGetNetworkParameters } from './lib/commands/get-network-parameters'; import { addUpdateCapsuleMultiSig } from './lib/commands/add-validators-to-multisig'; -import { addVegaWalletConnect } from './lib/commands/vega-wallet-connect'; +import { + addVegaWalletConnect, + addSetVegaWallet, +} from './lib/commands/vega-wallet-connect'; import { addMockTransactionResponse } from './lib/commands/mock-transaction-response'; addGetTestIdcommand(); @@ -26,6 +29,7 @@ addContainsExactly(); addGetNetworkParameters(); addUpdateCapsuleMultiSig(); addVegaWalletConnect(); +addSetVegaWallet(); addMockTransactionResponse(); export { mockConnectWallet } from './lib/commands/vega-wallet-connect'; diff --git a/libs/cypress/src/lib/commands/vega-wallet-connect.ts b/libs/cypress/src/lib/commands/vega-wallet-connect.ts index 7fe557e49..046c7b338 100644 --- a/libs/cypress/src/lib/commands/vega-wallet-connect.ts +++ b/libs/cypress/src/lib/commands/vega-wallet-connect.ts @@ -7,6 +7,10 @@ declare global { interface Chainable { connectVegaWallet(): void; } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + interface Chainable { + setVegaWallet(): void; + } } } @@ -21,7 +25,6 @@ export const mockConnectWallet = () => { }; export function addVegaWalletConnect() { - // @ts-ignore - ignoring Cypress type error which gets resolved when Cypress uses the command Cypress.Commands.add('connectVegaWallet', () => { mockConnectWallet(); cy.highlight(`Connecting Vega Wallet`); @@ -38,3 +41,18 @@ export function addVegaWalletConnect() { cy.get('[data-testid=dialog-content]').should('not.exist'); }); } + +export function addSetVegaWallet() { + Cypress.Commands.add('setVegaWallet', () => { + cy.window().then((win) => { + win.localStorage.setItem( + 'vega_wallet_config', + JSON.stringify({ + token: Cypress.env('VEGA_WALLET_API_TOKEN'), + connector: 'jsonRpc', + url: 'http://localhost:1789', + }) + ); + }); + }); +}