From 0465fb8ca949eee46e78fc29a0daa7c6703946fb Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 1 Jun 2023 11:37:41 +0100 Subject: [PATCH] test(trading): key to key transfer tests (#4014) --- .../trading-e2e/src/integration/capsule.cy.ts | 2 + .../src/integration/trading-accounts.cy.ts | 2 + .../src/integration/withdraw-key-to-key.cy.ts | 356 ++++++++++++------ 3 files changed, 254 insertions(+), 106 deletions(-) diff --git a/apps/trading-e2e/src/integration/capsule.cy.ts b/apps/trading-e2e/src/integration/capsule.cy.ts index 71c0b83d5..0311937cc 100644 --- a/apps/trading-e2e/src/integration/capsule.cy.ts +++ b/apps/trading-e2e/src/integration/capsule.cy.ts @@ -114,6 +114,8 @@ describe('capsule - without MultiSign', { tags: '@slow' }, () => { }); it('can key to key transfers', function () { + // 1003-TRAN-023 + // 1003-TRAN-006 cy.get('main[data-testid="/portfolio"]').should('exist'); cy.getByTestId(collateralTab).click(); diff --git a/apps/trading-e2e/src/integration/trading-accounts.cy.ts b/apps/trading-e2e/src/integration/trading-accounts.cy.ts index 03ac6c599..5cefea00c 100644 --- a/apps/trading-e2e/src/integration/trading-accounts.cy.ts +++ b/apps/trading-e2e/src/integration/trading-accounts.cy.ts @@ -19,6 +19,7 @@ describe('accounts', { tags: '@smoke' }, () => { // 7001-COLL-005 // 7001-COLL-006 // 7001-COLL-007 + // 1003-TRAN-001 const tradingAccountRowId = '[row-id="t-0"]'; cy.getByTestId('Collateral').click(); @@ -62,6 +63,7 @@ describe('accounts', { tags: '@smoke' }, () => { .click(); cy.getByTestId('deposit').should('be.visible'); cy.getByTestId('withdraw').should('be.visible'); + cy.getByTestId('transfer').should('be.visible'); cy.getByTestId('breakdown').should('be.visible'); cy.getByTestId('Collateral').click({ force: true }); }); diff --git a/apps/trading-e2e/src/integration/withdraw-key-to-key.cy.ts b/apps/trading-e2e/src/integration/withdraw-key-to-key.cy.ts index 4097ef914..f69b0da10 100644 --- a/apps/trading-e2e/src/integration/withdraw-key-to-key.cy.ts +++ b/apps/trading-e2e/src/integration/withdraw-key-to-key.cy.ts @@ -1,95 +1,141 @@ import { selectAsset } from '../support/helpers'; - -const formFieldError = 'input-error-text'; -const toAddressField = '[name="toAddress"]'; +// #region consts const amountField = 'input[name="amount"]'; -const submitTransferBtn = '[type="submit"]'; -const transferForm = 'transfer-form'; -const errorText = 'input-error-text'; -const openTransferDialog = 'open-transfer-dialog'; +const amountShortName = 'input[name="amount"] + div + span.text-xs'; +const assetSelection = 'select-asset'; +const assetBalance = 'asset-balance'; +const assetOption = 'rich-select-option'; const closeDialog = 'dialog-close'; +const dialogTitle = 'dialog-title'; const dialogTransferText = 'dialog-transfer-text'; +const dropdownMenu = 'dropdown-menu'; +const errorText = 'input-error-text'; +const formFieldError = 'input-error-text'; +const includeTransferFeeRadioBtn = 'include-transfer-fee'; +const keyID = '[data-testid="dialog-transfer-text"] > .rounded-md'; +const manageVegaWallet = 'manage-vega-wallet'; +const openTransferDialog = 'open-transfer-dialog'; +const submitTransferBtn = '[type="submit"]'; +const toAddressField = '[name="toAddress"]'; +const totalTransferfee = 'total-transfer-fee'; +const transfer = 'transfer'; +const transferAmount = 'transfer-amount'; +const transferForm = 'transfer-form'; +const transferFee = 'transfer-fee'; +const walletTransfer = 'wallet-transfer'; -const ASSET_SEPOLIA_TBTC = 2; const ASSET_EURO = 1; +const ASSET_SEPOLIA_TBTC = 2; -const toastContent = 'toast-content'; const collateralTab = 'Collateral'; const toastCloseBtn = 'toast-close'; +const toastContent = 'toast-content'; +// #endregion +describe('transfer fees', { tags: '@regression', testIsolation: true }, () => { + beforeEach(() => { + cy.mockWeb3Provider(); + cy.mockTradingPage(); + cy.mockSubscription(); + cy.setVegaWallet(); + + cy.visit('/#/portfolio'); + cy.getByTestId('Trading').first().click(); + cy.getByTestId(collateralTab).click(); + cy.getByTestId(dropdownMenu).first().click(); + cy.getByTestId(transfer).click(); + + cy.wait('@Accounts'); + cy.wait('@Assets'); + cy.mockVegaWalletTransaction(); + }); + + it('transfer fees tooltips', () => { + // 1003-TRAN-015 + // 1003-TRAN-016 + // 1003-TRAN-017 + // 1003-TRAN-018 + // 1003-TRAN-019 + cy.getByTestId(transferForm); + cy.contains('Enter manually').click(); + + cy.getByTestId(transferForm) + .find(toAddressField) + .type('7f9cf07d3a9905b1a61a1069f7a758855da428bc0f4a97de87f48644bfc25535'); + selectAsset(ASSET_SEPOLIA_TBTC); + cy.getByTestId(transferForm) + .find(amountField) + .type('1', { delay: 100, force: true }); + + /// Check Include Transfer Fee tooltip + cy.get('label[for="include-transfer-fee"] div').realHover(); + cy.get('[data-side="bottom"] div') + .should('be.visible') + .should('not.be.empty'); + cy.getByTestId(dialogTitle).click(); + + //Check Transfer Fee tooltip + cy.contains('div', 'Transfer fee').realHover(); + cy.get('[data-side="bottom"] div') + .should('be.visible') + .should('not.be.empty'); + cy.getByTestId(dialogTitle).click(); + + //Check Amount to be transferred tooltip + cy.contains('div', 'Amount to be transferred').realHover(); + cy.get('[data-side="bottom"] div') + .should('be.visible') + .should('not.be.empty'); + cy.getByTestId(dialogTitle).click(); + + //Check Total amount (with fee) tooltip + cy.contains('div', 'Total amount (with fee)').realHover(); + cy.get('[data-side="bottom"] div') + .should('be.visible') + .should('not.be.empty'); + }); + + it('transfer fees', () => { + // 1003-TRAN-020 + // 1003-TRAN-021 + // 1003-TRAN-022 + // 1003-TRAN-023 + cy.getByTestId(transferForm); + cy.contains('Enter manually').click(); + + cy.getByTestId(transferForm) + .find(toAddressField) + .type('7f9cf07d3a9905b1a61a1069f7a758855da428bc0f4a97de87f48644bfc25535'); + selectAsset(ASSET_SEPOLIA_TBTC); + cy.getByTestId(includeTransferFeeRadioBtn).should('be.disabled'); + + cy.getByTestId(transferForm) + .find(amountField) + .type('1', { delay: 100, force: true }); + + cy.getByTestId(transferFee) + .should('be.visible') + .should('contain.text', '0.01'); + cy.getByTestId(transferAmount) + .should('be.visible') + .should('contain.text', '1.00'); + cy.getByTestId(totalTransferfee) + .should('be.visible') + .should('contain.text', '1.01'); + cy.getByTestId(includeTransferFeeRadioBtn).click(); + cy.getByTestId(transferFee) + .should('be.visible') + .should('contain.text', '0.01'); + cy.getByTestId(transferAmount) + .should('be.visible') + .should('contain.text', '0.99'); + cy.getByTestId(totalTransferfee) + .should('be.visible') + .should('contain.text', '1.00'); + }); +}); describe( - 'transfer form validation and transfer from options', - { tags: '@smoke' }, - () => { - before(() => { - cy.mockWeb3Provider(); - cy.mockTradingPage(); - cy.mockSubscription(); - cy.setVegaWallet(); - - cy.visit('/#/portfolio'); - cy.getByTestId(collateralTab).click(); - cy.getByTestId(openTransferDialog).click(); - - cy.wait('@Accounts'); - cy.wait('@Assets'); - }); - - it('empty fields', () => { - cy.getByTestId(transferForm).find(submitTransferBtn).click(); - - cy.getByTestId(formFieldError).should('contain.text', 'Required'); - // only 2 despite 3 fields because the ethereum address will be auto populated - cy.getByTestId(formFieldError).should('have.length', 3); - }); - it('min amount', () => { - // 1002-WITH-010 - selectAsset(ASSET_SEPOLIA_TBTC); - cy.get(amountField).clear().type('0'); - cy.getByTestId(transferForm).find(submitTransferBtn).click(); - cy.getByTestId(errorText).should( - 'contain.text', - 'Value is below minimum' - ); - }); - it('max amount', () => { - selectAsset(ASSET_EURO); // Will be above maximum because the vega wallet doesn't have any collateral - cy.get(amountField).clear().type('1001', { delay: 100 }); - cy.getByTestId(transferForm).find(submitTransferBtn).click(); - cy.getByTestId(errorText).should( - 'contain.text', - 'You cannot transfer more than your available collateral' - ); - }); - - it('can start transfer from vega wallet', () => { - cy.getByTestId(closeDialog).click(); - cy.getByTestId('manage-vega-wallet').click(); - cy.getByTestId('wallet-transfer').should('have.text', 'Transfer').click(); - cy.getByTestId(dialogTransferText).should( - 'contain.text', - 'Transfer funds to another Vega key from 02ecea…342f65 If you are at all unsure, stop and seek advice.' - ); - }); - - it('can start transfer from trading collateral table', () => { - cy.getByTestId(closeDialog).click(); - cy.getByTestId('Trading').first().click(); - cy.getByTestId(collateralTab).click(); - cy.getByTestId(openTransferDialog).should('not.exist'); - cy.getByTestId('Portfolio').eq(0).click(); - cy.getByTestId(collateralTab).click(); - cy.getByTestId(openTransferDialog).click(); - cy.getByTestId(dialogTransferText).should( - 'contain.text', - 'Transfer funds to another Vega key from 02ecea…342f65 If you are at all unsure, stop and seek advice.' - ); - }); - } -); - -describe( - 'withdraw actions', + 'transfer form validation', { tags: '@regression', testIsolation: true }, () => { beforeEach(() => { @@ -99,43 +145,141 @@ describe( cy.setVegaWallet(); cy.visit('/#/portfolio'); - cy.getByTestId(collateralTab).click(); - cy.getByTestId(openTransferDialog).click(); + cy.getByTestId(manageVegaWallet).click(); + cy.getByTestId(walletTransfer).click(); cy.wait('@Accounts'); cy.wait('@Assets'); - cy.mockVegaWalletTransaction(); }); - it('key to key transfers by select key', function () { - cy.getByTestId(transferForm).should('be.visible'); - cy.getByTestId(transferForm).find(toAddressField).select(1); - selectAsset(ASSET_SEPOLIA_TBTC); - cy.getByTestId(transferForm).find(amountField).type('1', { delay: 100 }); - cy.getByTestId(transferForm).find(submitTransferBtn).click(); - cy.getByTestId(toastContent).should( - 'contain.text', - 'Awaiting confirmation' - ); - cy.getByTestId(toastCloseBtn).click(); + it('transfer Text', () => { + // 1003-TRAN-003 + cy.getByTestId(dialogTransferText) + .should('exist') + .get(keyID) + .invoke('text') + .should('match', /[\w.]{6}…[\w.]{6}/); }); - it('key to key transfers by enter manual key', function () { + it('invalid vega key validation', () => { + //1003-TRAN-013 + //1003-TRAN-004 cy.getByTestId(transferForm).should('be.visible'); cy.contains('Enter manually').click(); - cy.getByTestId(transferForm) - .find(toAddressField) - .type( - '7f9cf07d3a9905b1a61a1069f7a758855da428bc0f4a97de87f48644bfc25535' - ); - selectAsset(ASSET_SEPOLIA_TBTC); - cy.getByTestId(transferForm).find(amountField).type('1', { delay: 100 }); + cy.getByTestId(transferForm).find(toAddressField).type('asd'); cy.getByTestId(transferForm).find(submitTransferBtn).click(); - cy.getByTestId(toastContent).should( + cy.getByTestId(formFieldError).should('contain.text', 'Invalid Vega key'); + cy.contains('label', 'Vega key').should('be.visible'); + cy.contains('label', 'Asset').should('be.visible'); + cy.contains('label', 'Amount').should('be.visible'); + }); + + it('empty fields', () => { + // 1003-TRAN-012 + cy.getByTestId(transferForm).find(submitTransferBtn).click(); + cy.getByTestId(formFieldError).should('contain.text', 'Required'); + cy.getByTestId(formFieldError).should('have.length', 3); + }); + + it('min amount', () => { + // 1002-WITH-010 + // 1003-TRAN-014 + selectAsset(ASSET_SEPOLIA_TBTC); + cy.get(amountField).clear().type('0'); + cy.getByTestId(transferForm).find(submitTransferBtn).click(); + cy.getByTestId(errorText).should( 'contain.text', - 'Awaiting confirmation' + 'Value is below minimum' ); - cy.getByTestId(toastCloseBtn).click(); + }); + + it('max amount', () => { + // 1003-TRAN-002 + // 1003-TRAN-011 + // 1003-TRAN-002 + selectAsset(ASSET_EURO); // Will be above maximum because the vega wallet doesn't have any collateral + cy.get(amountField).clear().type('1001', { delay: 100 }); + cy.getByTestId(transferForm).find(submitTransferBtn).click(); + cy.getByTestId(errorText).should( + 'contain.text', + 'You cannot transfer more than your available collateral' + ); + cy.getByTestId(closeDialog).click(); }); } ); +describe('withdraw actions', { tags: '@smoke', testIsolation: true }, () => { + beforeEach(() => { + cy.mockWeb3Provider(); + cy.mockTradingPage(); + cy.mockSubscription(); + cy.setVegaWallet(); + + cy.visit('/#/portfolio'); + cy.getByTestId(collateralTab).click(); + cy.getByTestId(openTransferDialog).click(); + + cy.wait('@Accounts'); + cy.wait('@Assets'); + cy.mockVegaWalletTransaction(); + }); + + it('key to key transfers by select key', () => { + // 1003-TRAN-001 + // 1003-TRAN-006 + // 1003-TRAN-007 + // 1003-TRAN-008 + // 1003-TRAN-009 + // 1003-TRAN-010 + // 1003-TRAN-023 + cy.getByTestId(transferForm).should('be.visible'); + cy.getByTestId(transferForm).find(toAddressField).select(1); + + cy.getByTestId(assetSelection).click(); + cy.getByTestId(assetOption); + cy.getByTestId(assetBalance).should('not.be.empty'); + cy.getByTestId(assetOption).should('have.length.gt', 4); + + let optionText: string; + cy.getByTestId(assetOption) + .eq(2) + .invoke('text') + .then((text: string) => { + optionText = text; + cy.getByTestId(assetOption).eq(2).click(); + cy.getByTestId(assetSelection).should('have.text', optionText); + }); + + cy.getByTestId(transferForm) + .find(amountField) + .type('1', { delay: 100, force: true }); + + cy.getByTestId(transferForm).find(amountShortName).should('not.be.empty'); + + cy.getByTestId(transferForm).find(submitTransferBtn).click(); + cy.getByTestId(toastContent).should( + 'contain.text', + 'Awaiting confirmation' + ); + cy.getByTestId(toastCloseBtn).click(); + }); + + it('key to key transfers by enter manual key', () => { + //1003-TRAN-005 + cy.getByTestId(transferForm).should('be.visible'); + cy.contains('Enter manually').click(); + cy.getByTestId(transferForm) + .find(toAddressField) + .type('7f9cf07d3a9905b1a61a1069f7a758855da428bc0f4a97de87f48644bfc25535'); + selectAsset(ASSET_SEPOLIA_TBTC); + cy.getByTestId(transferForm) + .find(amountField) + .type('1', { delay: 100, force: true }); + cy.getByTestId(transferForm).find(submitTransferBtn).click(); + cy.getByTestId(toastContent).should( + 'contain.text', + 'Awaiting confirmation' + ); + cy.getByTestId(toastCloseBtn).click(); + }); +});