From e66e5af6a388f7a5d1cc14a5003d9237827cc647 Mon Sep 17 00:00:00 2001 From: AndyWhiteVega <106072061+AndyWhiteVega@users.noreply.github.com> Date: Thu, 1 Sep 2022 12:25:11 +0100 Subject: [PATCH] Test/token association fixes (#1216) * test: fixes * test: lint --- apps/token-e2e/cypress.config.js | 2 +- .../src/integration/flow/staking-flow.cy.js | 45 ++++++------ .../flow/token-association-flow.cy.js | 71 ++++++++++++------- .../src/support/staking.functions.js | 4 +- 4 files changed, 74 insertions(+), 48 deletions(-) diff --git a/apps/token-e2e/cypress.config.js b/apps/token-e2e/cypress.config.js index 30daf6fee..a03a7e839 100644 --- a/apps/token-e2e/cypress.config.js +++ b/apps/token-e2e/cypress.config.js @@ -23,7 +23,7 @@ module.exports = defineConfig({ chromeWebSecurity: false, viewportWidth: 1440, viewportHeight: 900, - numTestsKeptInMemory: 4, + numTestsKeptInMemory: 5, }, env: { ethProviderUrl: 'http://localhost:8545/', diff --git a/apps/token-e2e/src/integration/flow/staking-flow.cy.js b/apps/token-e2e/src/integration/flow/staking-flow.cy.js index 574dae11c..d6d42e372 100644 --- a/apps/token-e2e/src/integration/flow/staking-flow.cy.js +++ b/apps/token-e2e/src/integration/flow/staking-flow.cy.js @@ -25,6 +25,7 @@ const ethWalletAssociatedBalances = '[data-testid="eth-wallet-associated-balances"]'; const ethWalletTotalAssociatedBalance = '[data-testid="currency-locked"]'; const ethWalletContainer = '[data-testid="ethereum-wallet"]'; +const vegaWallet = '[data-testid="vega-wallet"]'; const partValidatorId = '…'; const txTimeout = Cypress.env('txTimeout'); const epochTimeout = Cypress.env('epochTimeout'); @@ -550,11 +551,12 @@ context('Staking Tab - with eth and vega wallets connected', function () { .contains('0.0', txTimeout) .should('be.visible'); - cy.get(vegaWalletAssociatedBalance, txTimeout).should( - 'contain', - '0.000000000000000000', - txTimeout - ); + cy.get(vegaWallet).within(() => { + cy.get(vegaWalletAssociatedBalance, txTimeout).should( + 'contain', + '0.000000000000000000' + ); + }); cy.get(vegaWalletStakedBalances, txTimeout).should( 'not.exist', @@ -603,11 +605,12 @@ context('Staking Tab - with eth and vega wallets connected', function () { .contains('0.0', txTimeout) .should('be.visible'); - cy.get(vegaWalletAssociatedBalance, txTimeout).should( - 'contain', - '0.000000000000000000', - txTimeout - ); + cy.get(vegaWallet).within(() => { + cy.get(vegaWalletAssociatedBalance, txTimeout).should( + 'contain', + '0.000000000000000000' + ); + }); cy.get(vegaWalletStakedBalances, txTimeout).should( 'not.exist', @@ -650,11 +653,12 @@ context('Staking Tab - with eth and vega wallets connected', function () { .contains('2.0', txTimeout) .should('be.visible'); - cy.get(vegaWalletAssociatedBalance, txTimeout).should( - 'contain', - '2.000000000000000000', - txTimeout - ); + cy.get(vegaWallet).within(() => { + cy.get(vegaWalletAssociatedBalance, txTimeout).should( + 'contain', + '2.000000000000000000' + ); + }); cy.get(vegaWalletStakedBalances, txTimeout) .should('contain', 2.0, txTimeout) @@ -804,11 +808,12 @@ context('Staking Tab - with eth and vega wallets connected', function () { cy.staking_page_associate_tokens('6'); - cy.get(vegaWalletAssociatedBalance, txTimeout).should( - 'contain', - '12.000000000000000000', - txTimeout - ); + cy.get(vegaWallet).within(() => { + cy.get(vegaWalletAssociatedBalance, txTimeout).should( + 'contain', + '12.000000000000000000' + ); + }); cy.get(vegaWalletStakedBalances, txTimeout) .should('contain', '4.0', txTimeout) diff --git a/apps/token-e2e/src/integration/flow/token-association-flow.cy.js b/apps/token-e2e/src/integration/flow/token-association-flow.cy.js index c14f13e23..e7f6c9257 100644 --- a/apps/token-e2e/src/integration/flow/token-association-flow.cy.js +++ b/apps/token-e2e/src/integration/flow/token-association-flow.cy.js @@ -1,4 +1,3 @@ -const validatorsGrid = '[data-testid="validators-grid"]'; const ethWalletContainer = '[data-testid="ethereum-wallet"]'; const ethWalletAssociatedBalances = '[data-testid="eth-wallet-associated-balances"]'; @@ -6,7 +5,7 @@ const ethWalletTotalAssociatedBalance = '[data-testid="currency-locked"]'; const vegaWalletAssociatedBalance = '[data-testid="currency-value"]'; const vegaWalletUnstakedBalance = '[data-testid="vega-wallet-balance-unstaked"]'; -const txTimeout = { timeout: 40000 }; +const txTimeout = Cypress.env('txTimeout'); const vegaWalletPublicKeyShort = Cypress.env('vegaWalletPublicKeyShort'); const ethWalletAssociateButton = '[href="/staking/associate"]'; const associateWalletRadioButton = '[data-testid="associate-radio-wallet"]'; @@ -18,6 +17,7 @@ const vegaInWalletSection = '[data-testid="vega-in-wallet"]'; const associatedKey = '[data-test-id="associated-key"]'; const associatedAmount = '[data-test-id="associated-amount"]'; const disassocitiationWarning = '[data-testid="disassociation-warning"]'; +const vegaWallet = '[data-testid="vega-wallet"]'; context( 'Token association flow - with eth and vega wallets connected', @@ -33,7 +33,7 @@ context( cy.ethereum_wallet_connect(); cy.navigate_to('staking'); cy.wait_for_spinner(); - cy.get(validatorsGrid).should('be.visible'); + cy.wait_for_begining_of_epoch(); }); describe('Eth wallet - contains VEGA tokens', function () { @@ -46,7 +46,7 @@ context( } ); - it('Able to associate tokens', function () { + it('Able to associate tokens - from wallet', function () { //1000-ASSO-0008 //1000-ASSO-0009 //1000-ASSO-0030 @@ -66,12 +66,14 @@ context( .contains('2.0', txTimeout) .should('be.visible'); - cy.get(vegaWalletAssociatedBalance, txTimeout).should('contain', 2.0); + cy.get(vegaWallet).within(() => { + cy.get(vegaWalletAssociatedBalance, txTimeout).should('contain', 2.0); + }); cy.get(vegaWalletUnstakedBalance, txTimeout).should('contain', 2.0); }); - it('Able to disassociate tokens', function () { + it('Able to disassociate all associated tokens - manually', function () { // 1000-ASSO-0025 // 1000-ASSO-0027 // 1000-ASSO-0028 @@ -90,15 +92,12 @@ context( cy.get('button').contains('Select a validator to nominate').click(); - cy.staking_page_disassociate_tokens('1'); + cy.staking_page_disassociate_tokens('2'); - cy.get(ethWalletAssociatedBalances, txTimeout) - .contains(vegaWalletPublicKeyShort) - .parent(txTimeout) - .should('contain', 1.0); + cy.get(ethWalletAssociatedBalances, txTimeout).should('not.exist'); cy.get(ethWalletTotalAssociatedBalance, txTimeout) - .contains('1.0', txTimeout) + .contains('0.00', txTimeout) .should('be.visible'); }); @@ -115,16 +114,20 @@ context( .contains('1,001.00', txTimeout) .should('be.visible'); - cy.get(vegaWalletAssociatedBalance, txTimeout).should( - 'contain', - '1,001.000000000000000000' - ); + cy.get(vegaWallet).within(() => { + cy.get(vegaWalletAssociatedBalance, txTimeout).should( + 'contain', + '1,001.000000000000000000' + ); + }); }); it('Able to disassociate a partial amount of tokens currently associated', function () { cy.staking_page_associate_tokens('2'); - cy.get(vegaWalletAssociatedBalance, txTimeout).should('contain', 2.0); + cy.get(vegaWallet).within(() => { + cy.get(vegaWalletAssociatedBalance, txTimeout).should('contain', 2.0); + }); cy.get('button').contains('Select a validator to nominate').click(); @@ -140,17 +143,21 @@ context( .parent(txTimeout) .should('contain', 1.0); - cy.get(vegaWalletAssociatedBalance, txTimeout).should('contain', 1.0); + cy.get(vegaWallet).within(() => { + cy.get(vegaWalletAssociatedBalance, txTimeout).should('contain', 1.0); + }); }); - it('Able to disassociate all tokens', function () { + it('Able to disassociate all tokens - using max', function () { // 1000-ASSO-0026 const warningText = 'Warning: Any tokens that have been nominated to a node will sacrifice rewards they are due for the current epoch. If you do not wish to sacrifice these, you should remove stake from a node at the end of an epoch before disassociation.'; cy.staking_page_associate_tokens('2'); - cy.get(vegaWalletAssociatedBalance, txTimeout).should('contain', 2.0); + cy.get(vegaWallet).within(() => { + cy.get(vegaWalletAssociatedBalance, txTimeout).should('contain', 2.0); + }); cy.get('button').contains('Select a validator to nominate').click(); @@ -171,7 +178,9 @@ context( ); }); - cy.get(vegaWalletAssociatedBalance, txTimeout).should('contain', 0.0); + cy.get(vegaWallet).within(() => { + cy.get(vegaWalletAssociatedBalance, txTimeout).should('contain', 0.0); + }); }); it('Able to associate and disassociate vesting contract tokens', function () { @@ -190,7 +199,9 @@ context( .contains('2.0', txTimeout) .should('be.visible'); - cy.get(vegaWalletAssociatedBalance, txTimeout).should('contain', 2.0); + cy.get(vegaWallet).within(() => { + cy.get(vegaWalletAssociatedBalance, txTimeout).should('contain', 2.0); + }); cy.get(vegaWalletUnstakedBalance, txTimeout).should('contain', 2.0); cy.staking_page_disassociate_tokens('1', { type: 'contract' }); @@ -231,21 +242,29 @@ context( cy.get(associatedAmount, txTimeout).should('contain', 21); }); - cy.get(vegaWalletAssociatedBalance, txTimeout).should('contain', 58); + cy.get(vegaWallet).within(() => { + cy.get(vegaWalletAssociatedBalance, txTimeout).should('contain', 58); + }); cy.staking_page_disassociate_tokens('6', { type: 'contract' }); cy.get(vestingContractSection).within(() => { cy.get(associatedAmount, txTimeout).should('contain', 31); }); - cy.get(vegaWalletAssociatedBalance, txTimeout).should('contain', 52); - cy.get('[href="/staking"]').first().click(); + cy.get(vegaWallet).within(() => { + cy.get(vegaWalletAssociatedBalance, txTimeout).should('contain', 52); + }); + + cy.navigate_to('staking'); cy.staking_page_disassociate_tokens('9', { type: 'wallet' }); cy.get(vegaInWalletSection).within(() => { cy.get(associatedAmount, txTimeout).should('contain', 12); }); - cy.get(vegaWalletAssociatedBalance, txTimeout).should('contain', 43); + + cy.get(vegaWallet).within(() => { + cy.get(vegaWalletAssociatedBalance, txTimeout).should('contain', 43); + }); }); it('Not able to associate more tokens than owned', function () { diff --git a/apps/token-e2e/src/support/staking.functions.js b/apps/token-e2e/src/support/staking.functions.js index 6b94425b6..0c9afa870 100644 --- a/apps/token-e2e/src/support/staking.functions.js +++ b/apps/token-e2e/src/support/staking.functions.js @@ -24,7 +24,9 @@ Cypress.Commands.add('wait_for_begining_of_epoch', () => { cy.contains('Waiting for next epoch to start', epochTimeout).should( 'not.exist' ); - cy.contains('Waiting for next epoch to start', epochTimeout); + cy.contains('Waiting for next epoch to start', epochTimeout).should( + 'be.visible' + ); }); Cypress.Commands.add('staking_validator_page_add_stake', (stake) => {