From 85c3eff31e89233f698645fc9cc0255fb8e418a5 Mon Sep 17 00:00:00 2001 From: AndyWhiteVega <106072061+AndyWhiteVega@users.noreply.github.com> Date: Thu, 14 Jul 2022 15:21:51 +0100 Subject: [PATCH] Test/746 expand coverage of tfe tests (#759) * test: adding extra checks within tests * test: lint * test: refactor to bring assertions inline with new wallet locators * test: lint * test: lint correction * test: formatting for lint * test: formatting for lint * test: fix test and make use of common functions * test: lint --- .../src/integration/flow/staking-flow.cy.js | 650 ++++++++++++------ .../flow/token-association-flow.cy.js | 162 +++-- .../token-e2e/src/support/common.functions.js | 5 + .../src/support/staking.functions.js | 10 +- .../src/support/wallet-eth.functions.js | 39 -- .../src/support/wallet-teardown.functions.js | 8 +- .../src/support/wallet-vega.functions.js | 21 - .../src/components/eth-wallet/eth-wallet.tsx | 14 +- .../components/vega-wallet/vega-wallet.tsx | 42 +- 9 files changed, 602 insertions(+), 349 deletions(-) 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 46d5618db..e9e84e398 100644 --- a/apps/token-e2e/src/integration/flow/staking-flow.cy.js +++ b/apps/token-e2e/src/integration/flow/staking-flow.cy.js @@ -1,28 +1,44 @@ -const pageSpinner = 'splash-loader'; -const menuBar = 'nav'; -const validatorList = '[data-testid="node-list-item-name"]'; -const removeStakeRadioButton = '[data-testid="remove-stake-radio"]'; -const tokenAmountInputBox = '[data-testid="token-amount-input"]'; -const tokenSubmitButton = '[data-testid="token-input-submit-button"]'; +/// +const stakeValidatorList = '[data-testid="node-list-item-name"]'; +const stakeValidatorWithinList = '[data-testid="node-list-item"]'; +const stakeRemoveStakeRadioButton = '[data-testid="remove-stake-radio"]'; +const stakeTokenAmountInputBox = '[data-testid="token-amount-input"]'; +const stakeTokenSubmitButton = '[data-testid="token-input-submit-button"]'; const stakeNextEpochValue = '[data-testid="stake-next-epoch"]'; -const vegaWalletContainer = '[data-testid="vega-wallet"]'; - +const stakeThisEpochValue = '[data-testid="stake-this-epoch"]'; +const stakeAddStakeRadioButton = '[data-testid="add-stake-radio"]'; +const stakeMaximumTokens = '[data-testid="token-amount-use-maximum"]'; const vegaWalletPublicKeyShort = Cypress.env('vegaWalletPublicKeyShort'); +const vegaWalletAssociatedBalance = '[data-testid="currency-value"]'; +const vegaWalletUnstakedBalance = + '[data-testid="vega-wallet-balance-unstaked"]'; +const vegaWalletStakedBalances = + '[data-testid="vega-wallet-balance-staked-validators"]'; +const vegaWalletThisEpochBalances = + '[data-testid="vega-wallet-balance-this-epoch"]'; +const vegaWalletNextEpochBalances = + '[data-testid="vega-wallet-balance-next-epoch"]'; +const ethWalletAssociatedBalances = + '[data-testid="eth-wallet-associated-balances"]'; +const ethWalletTotalAssociatedBalance = '[data-testid="currency-locked"]'; +const ethWalletContainer = '[data-testid="ethereum-wallet"]'; +const txTimeout = { timeout: 40000 }; +const epochTimeout = { timeout: 10000 }; context('Staking Flow - with eth and vega wallets connected', function () { before('visit staking tab and connect vega wallet', function () { cy.vega_wallet_import(); cy.visit('/'); - cy.get(menuBar, { timeout: 20000 }).should('be.visible'); + cy.verify_page_header('The $VEGA token'); cy.vega_wallet_connect(); cy.vega_wallet_set_specified_approval_amount('1000'); cy.reload(); - cy.get(menuBar, { timeout: 20000 }).should('be.visible'); + cy.verify_page_header('The $VEGA token'); cy.ethereum_wallet_connect(); cy.navigate_to('staking'); - cy.get(pageSpinner, { timeout: 20000 }).should('not.exist'); - cy.get(validatorList).first().invoke('text').as('validatorName'); - cy.get(validatorList).last().invoke('text').as('otherValidatorName'); + cy.wait_for_spinner(); + cy.get(stakeValidatorList).first().invoke('text').as('validatorName'); + cy.get(stakeValidatorList).last().invoke('text').as('otherValidatorName'); }); describe('Eth wallet - contains VEGA tokens', function () { @@ -36,219 +52,505 @@ context('Staking Flow - with eth and vega wallets connected', function () { it('Able to stake against a validator', function () { cy.staking_page_associate_tokens('3'); - cy.vega_wallet_check_unstaked_value_is('3.000000000000000000'); - cy.ethereum_wallet_check_associated_value_is('3.0'); - cy.ethereum_wallet_check_associated_vega_key_value_is( - vegaWalletPublicKeyShort, - '3.000000000000000000' + + cy.get(vegaWalletUnstakedBalance, txTimeout).should( + 'contain', + 3.0, + txTimeout ); + cy.get(ethWalletTotalAssociatedBalance, txTimeout) + .contains('3.0', txTimeout) + .should('be.visible'); + + cy.get(ethWalletAssociatedBalances, txTimeout) + .contains(vegaWalletPublicKeyShort) + .parent() + .should('contain', 3.0, txTimeout); + cy.get('button').contains('Select a validator to nominate').click(); - cy.get(validatorList).contains(this.validatorName).click(); + + cy.get(stakeValidatorList).contains(this.validatorName).click(); cy.staking_validator_page_add_stake('2'); - vega_wallet_check_validator_stake_next_epoch_value_is( - this.validatorName, - '2.000000000000000000' + + cy.get(vegaWalletNextEpochBalances, txTimeout) + .should('contain', 2.0, txTimeout) + .and('contain', this.validatorName) + .and('contain', 'Next epoch'); + + cy.get(vegaWalletUnstakedBalance, txTimeout).should( + 'contain', + 1.0, + txTimeout ); - cy.vega_wallet_check_unstaked_value_is('1.000000000000000000'); - vega_wallet_check_validator_staked_value_is( - this.validatorName, - '2.000000000000000000' - ); - staking_validator_page_check_stake_next_epoch_value('2.0'); - staking_validator_page_check_stake_this_epoch_value('2.0'); + + cy.get(vegaWalletStakedBalances, txTimeout) + .should('contain', 2.0, txTimeout) + .and('contain', this.validatorName); + + cy.get(stakeNextEpochValue, epochTimeout) + .contains(2.0, epochTimeout) + .should('be.visible'); + + cy.get(stakeThisEpochValue, epochTimeout) + .contains(2.0, epochTimeout) + .should('be.visible'); + + cy.navigate_to('staking'); + + cy.get(stakeValidatorWithinList, epochTimeout) + .contains(this.validatorName) + .parent() + .contains('Total stake') + .parent() + .should('contain', '2.0') + .and('contain', '100%'); }); it('Able to stake against mulitple validators', function () { cy.staking_page_associate_tokens('5'); - cy.vega_wallet_check_unstaked_value_is('5.000000000000000000'); + + cy.get(vegaWalletUnstakedBalance, txTimeout).should( + 'contain', + 5.0, + txTimeout + ); + cy.get('button').contains('Select a validator to nominate').click(); - cy.get(validatorList).contains(this.validatorName).click(); + cy.get(stakeValidatorList).contains(this.validatorName).click(); cy.staking_validator_page_add_stake('2'); - vega_wallet_check_validator_staked_value_is( - this.validatorName, - '2.000000000000000000' - ); + + cy.get(vegaWalletStakedBalances, txTimeout) + .contains(this.validatorName, txTimeout) + .parent() + .should('contain', 2.0, txTimeout); + cy.navigate_to('staking'); - cy.get(validatorList).contains(this.otherValidatorName).click(); + cy.get(stakeValidatorList).contains(this.otherValidatorName).click(); + cy.staking_validator_page_add_stake('1'); - vega_wallet_check_validator_staked_value_is( - this.otherValidatorName, - '1.000000000000000000' + + cy.get(vegaWalletStakedBalances, txTimeout) + .should('have.length', 2, txTimeout) + .contains(this.otherValidatorName, txTimeout) + .parent() + .should('contain', 1.0, txTimeout); + + cy.get(vegaWalletStakedBalances, txTimeout) + .contains(this.validatorName, txTimeout) + .parent() + .should('contain', 2.0, txTimeout); + + cy.get(vegaWalletUnstakedBalance, txTimeout).should( + 'contain', + 2.0, + txTimeout ); - cy.vega_wallet_check_unstaked_value_is('2.000000000000000000'); + + cy.navigate_to('staking'); + + cy.get(stakeValidatorWithinList, epochTimeout) + .contains(this.validatorName) + .parent() + .contains('Total stake') + .parent() + .should('contain', '2.0') + .and('contain', '66.67%'); + + cy.get(stakeValidatorWithinList, epochTimeout) + .contains(this.otherValidatorName) + .parent() + .contains('Total stake') + .parent() + .should('contain', '1.0') + .and('contain', '33.33%'); }); - it.skip('Able to remove part of a stake against a validator', function () { + it('Able to remove part of a stake against a validator', function () { cy.staking_page_associate_tokens('4'); - cy.vega_wallet_check_unstaked_value_is('4.000000000000000000'); + + cy.get(vegaWalletUnstakedBalance, txTimeout).should( + 'contain', + 4.0, + txTimeout + ); cy.get('button').contains('Select a validator to nominate').click(); - cy.get(validatorList).contains(this.validatorName).click(); + cy.get(stakeValidatorList).contains(this.validatorName).click(); cy.staking_validator_page_add_stake('3'); - staking_validator_page_check_stake_next_epoch_value('3.0'); - vega_wallet_check_validator_stake_next_epoch_value_is( - this.validatorName, - '3.000000000000000000' + + cy.get(stakeNextEpochValue, epochTimeout) + .contains(3.0, epochTimeout) + .should('be.visible'); + + cy.get(vegaWalletNextEpochBalances, txTimeout) + .should('contain', 3.0, txTimeout) + .and('contain', this.validatorName) + .and('contain', 'Next epoch'); + + cy.get(vegaWalletUnstakedBalance, txTimeout).should( + 'contain', + 1.0, + txTimeout ); - cy.vega_wallet_check_unstaked_value_is('1.000000000000000000'); cy.navigate_to('staking'); - cy.get(validatorList).contains(this.validatorName).click(); + cy.get(stakeValidatorList).contains(this.validatorName).click(); - cy.staking_validator_page_removeStake('1'); - staking_validator_page_check_stake_next_epoch_value('2.0'); - staking_validator_page_check_stake_this_epoch_value('3.0'); - vega_wallet_check_validator_stake_next_epoch_value_is( - this.validatorName, - '2.000000000000000000' + cy.staking_validator_page_remove_stake('1'); + + cy.get(stakeNextEpochValue, epochTimeout) + .contains(2.0, epochTimeout) + .should('be.visible'); + + cy.get(vegaWalletNextEpochBalances, txTimeout) + .should('contain', 2.0, txTimeout) + .and('contain', this.validatorName) + .and('contain', 'Next epoch'); + + cy.get(vegaWalletThisEpochBalances, txTimeout) + .should('contain', 3.0, txTimeout) + .and('contain', this.validatorName) + .and('contain', 'This Epoch'); + + cy.get(vegaWalletUnstakedBalance, txTimeout).should( + 'contain', + 2.0, + txTimeout ); - vega_wallet_check_validator_stake_this_epoch_value_is( - this.validatorName, - '3.000000000000000000' - ); - cy.vega_wallet_check_unstaked_value_is('2.000000000000000000'); - vega_wallet_check_validator_staked_value_is( - this.validatorName, - '2.000000000000000000' - ); - staking_validator_page_check_stake_next_epoch_value('2.0'); - staking_validator_page_check_stake_this_epoch_value('2.0'); + + cy.get(vegaWalletStakedBalances, txTimeout) + .should('contain', 2.0, txTimeout) + .and('contain', this.validatorName); + + cy.get(stakeNextEpochValue, epochTimeout) + .contains(2.0, epochTimeout) + .should('be.visible'); + + cy.get(stakeThisEpochValue, epochTimeout) + .contains(2.0, epochTimeout) + .should('be.visible'); + + cy.navigate_to('staking'); + + cy.get(stakeValidatorWithinList, epochTimeout) + .contains(this.validatorName) + .parent() + .contains('Total stake') + .parent() + .should('contain', '2.0') + .and('contain', '100%'); }); it('Able to remove a full stake against a validator', function () { cy.staking_page_associate_tokens('3'); - cy.vega_wallet_check_unstaked_value_is('3.000000000000000000'); + + cy.get(vegaWalletUnstakedBalance, txTimeout).should( + 'contain', + 3.0, + txTimeout + ); cy.get('button').contains('Select a validator to nominate').click(); - cy.get(validatorList).contains(this.validatorName).click(); + + cy.get(stakeValidatorList).contains(this.validatorName).click(); cy.staking_validator_page_add_stake('1'); - vega_wallet_check_validator_stake_next_epoch_value_is( - this.validatorName, - '1.000000000000000000' + + cy.get(vegaWalletNextEpochBalances, txTimeout) + .should('contain', 1.0, txTimeout) + .and('contain', this.validatorName) + .and('contain', 'Next epoch'); + + cy.get(vegaWalletUnstakedBalance, txTimeout).should( + 'contain', + 2.0, + txTimeout ); - cy.vega_wallet_check_unstaked_value_is('2.000000000000000000'); cy.navigate_to('staking'); - cy.get(validatorList).contains(this.validatorName).click(); - cy.staking_validator_page_removeStake('1'); - staking_validator_page_check_stake_next_epoch_value('0.0'); + cy.get(stakeValidatorList).contains(this.validatorName).click(); - vega_wallet_check_validator_stake_this_epoch_value_is( - this.validatorName, - '1.000000000000000000' + cy.staking_validator_page_remove_stake('1'); + + cy.get(stakeNextEpochValue, epochTimeout) + .contains(0.0, epochTimeout) + .should('be.visible'); + + cy.get(vegaWalletThisEpochBalances, txTimeout) + .should('contain', 1.0, txTimeout) + .and('contain', this.validatorName) + .and('contain', 'This Epoch'); + + cy.get(vegaWalletNextEpochBalances, txTimeout) + .should('contain', 0.0, txTimeout) + .and('contain', this.validatorName) + .and('contain', 'Next epoch'); + + cy.get(vegaWalletUnstakedBalance, txTimeout).should( + 'contain', + 3.0, + txTimeout ); - vega_wallet_check_validator_stake_next_epoch_value_is( - this.validatorName, - '0.000000000000000000' - ); - cy.vega_wallet_check_unstaked_value_is('3.000000000000000000'); - staking_validator_page_check_stake_next_epoch_value('0.0'); - staking_validator_page_check_stake_this_epoch_value('0.0'); - vega_wallet_check_validator_no_longer_showing(this.validatorName); + + cy.get(stakeNextEpochValue, epochTimeout) + .contains(0.0, epochTimeout) + .should('be.visible'); + + cy.get(stakeThisEpochValue, epochTimeout) + .contains(0.0, epochTimeout) + .should('be.visible'); + + cy.get(vegaWalletStakedBalances, txTimeout) + .contains(this.validatorName, txTimeout) + .should('not.exist', txTimeout); + + cy.navigate_to('staking'); + + cy.get(stakeValidatorWithinList, epochTimeout) + .contains(this.validatorName) + .parent() + .contains('Total stake') + .parent() + .should('contain', '0.0'); }); - it.skip('Unable to remove a stake with a negative value for a validator', function () { + it('Unable to remove a stake with a negative value for a validator', function () { cy.staking_page_associate_tokens('3'); - cy.vega_wallet_check_unstaked_value_is('3.000000000000000000'); + + cy.get(vegaWalletUnstakedBalance, txTimeout).should( + 'contain', + 3.0, + txTimeout + ); cy.get('button').contains('Select a validator to nominate').click(); - cy.get(validatorList).contains(this.validatorName).click(); + + cy.get(stakeValidatorList).contains(this.validatorName).click(); cy.staking_validator_page_add_stake('2'); - staking_validator_page_check_stake_next_epoch_value('2.0'); - vega_wallet_check_validator_stake_next_epoch_value_is( - this.validatorName, - '2.000000000000000000' + + cy.get(stakeNextEpochValue, epochTimeout) + .contains(2.0, epochTimeout) + .should('be.visible'); + + cy.get(vegaWalletNextEpochBalances, txTimeout) + .should('contain', 2.0, txTimeout) + .and('contain', this.validatorName) + .and('contain', 'Next epoch'); + + cy.get(vegaWalletUnstakedBalance, txTimeout).should( + 'contain', + 3.0, + txTimeout ); - cy.vega_wallet_check_unstaked_value_is('1.000000000000000000'); cy.navigate_to('staking'); - cy.get(validatorList).contains(this.validatorName).click(); - cy.get(removeStakeRadioButton).click({ force: true }); - cy.get(tokenAmountInputBox).type('-0.1'); - cy.contains('Waiting for next epoch to start', { timeout: 10000 }); - cy.get(tokenSubmitButton) - .should('be.disabled', { timeout: 8000 }) + + cy.get(stakeValidatorList).contains(this.validatorName).click(); + + cy.get(stakeRemoveStakeRadioButton).click({ force: true }); + + cy.get(stakeTokenAmountInputBox).type('-0.1'); + + cy.contains('Waiting for next epoch to start', epochTimeout); + + cy.get(stakeTokenSubmitButton) + .should('be.disabled', epochTimeout) .and('contain', `Remove -0.1 $VEGA tokens at the end of epoch`) .and('be.visible'); }); - it.skip('Unable to remove a stake greater than staked amount next epoch for a validator', function () { + it('Unable to remove a stake greater than staked amount next epoch for a validator', function () { cy.staking_page_associate_tokens('3'); - cy.vega_wallet_check_unstaked_value_is('3.000000000000000000'); + + cy.get(vegaWalletUnstakedBalance, txTimeout).should( + 'contain', + 3.0, + txTimeout + ); cy.get('button').contains('Select a validator to nominate').click(); - cy.get(validatorList).contains(this.validatorName).click(); + + cy.get(stakeValidatorList).contains(this.validatorName).click(); cy.staking_validator_page_add_stake('2'); - staking_validator_page_check_stake_next_epoch_value('2.0'); - vega_wallet_check_validator_stake_next_epoch_value_is( - this.validatorName, - '2.000000000000000000' + + cy.get(stakeNextEpochValue, epochTimeout) + .contains(2.0, epochTimeout) + .should('be.visible'); + + cy.get(vegaWalletNextEpochBalances, txTimeout) + .should('contain', 2.0, txTimeout) + .and('contain', this.validatorName) + .and('contain', 'Next epoch'); + + cy.get(vegaWalletUnstakedBalance, txTimeout).should( + 'contain', + 1.0, + txTimeout ); - cy.vega_wallet_check_unstaked_value_is('1.000000000000000000'); cy.navigate_to('staking'); - cy.get(validatorList).contains(this.validatorName).click(); - cy.get(removeStakeRadioButton).click({ force: true }); - cy.get(tokenAmountInputBox).type(4); - cy.contains('Waiting for next epoch to start', { timeout: 10000 }); - cy.get(tokenSubmitButton) - .should('be.disabled', { timeout: 8000 }) + + cy.get(stakeValidatorList).contains(this.validatorName).click(); + + cy.get(stakeRemoveStakeRadioButton).click({ force: true }); + + cy.get(stakeTokenAmountInputBox).type(4); + + cy.contains('Waiting for next epoch to start', epochTimeout); + + cy.get(stakeTokenSubmitButton) + .should('be.disabled', epochTimeout) .and('contain', `Remove 4 $VEGA tokens at the end of epoch`) .and('be.visible'); }); - it.skip('Disassociating all tokens - removes all staked tokens', function () { + it('Disassociating all tokens - removes all staked tokens', function () { cy.staking_page_associate_tokens('3'); - cy.vega_wallet_check_unstaked_value_is('3.000000000000000000'); + + cy.get(vegaWalletUnstakedBalance, txTimeout).should( + 'contain', + 3.0, + txTimeout + ); cy.get('button').contains('Select a validator to nominate').click(); - cy.get(validatorList).contains(this.validatorName).click(); + + cy.get(stakeValidatorList).contains(this.validatorName).click(); cy.staking_validator_page_add_stake('2'); - cy.vega_wallet_check_unstaked_value_is('1.000000000000000000'); - vega_wallet_check_validator_staked_value_is( - this.validatorName, - '2.000000000000000000' + + cy.get(vegaWalletUnstakedBalance, txTimeout).should( + 'contain', + 1.0, + txTimeout ); + + cy.get(vegaWalletStakedBalances, txTimeout) + .should('contain', 2.0, txTimeout) + .and('contain', this.validatorName); + cy.navigate_to('staking'); + cy.staking_page_disassociate_all_tokens(); - cy.ethereum_wallet_check_associated_vega_key_is_no_longer_showing( - vegaWalletPublicKeyShort + + cy.get(ethWalletContainer).within(() => { + cy.contains(vegaWalletPublicKeyShort, { timeout: 20000 }).should( + 'not.exist' + ); + }); + + cy.get(ethWalletTotalAssociatedBalance, txTimeout) + .contains('0.0', txTimeout) + .should('be.visible'); + + cy.get(vegaWalletAssociatedBalance, txTimeout).should( + 'contain', + '0.000000000000000000', + txTimeout ); - cy.ethereum_wallet_check_associated_value_is('0.0'); - cy.vega_wallet_check_associated_value_is('0.000000000000000000'); - vega_wallet_check_validator_no_longer_showing(this.validatorName); + + cy.get(vegaWalletStakedBalances, txTimeout) + .contains(this.validatorName, txTimeout) + .should('not.exist', txTimeout); + + cy.navigate_to('staking'); + + cy.get(stakeValidatorWithinList, epochTimeout) + .contains(this.validatorName) + .parent() + .contains('Total stake') + .parent() + .should('contain', '0.0'); }); it('Disassociating some tokens - prioritizes unstaked tokens', function () { cy.staking_page_associate_tokens('3'); - cy.vega_wallet_check_unstaked_value_is('3.000000000000000000'); + + cy.get(vegaWalletUnstakedBalance, txTimeout).should( + 'contain', + 3.0, + txTimeout + ); cy.get('button').contains('Select a validator to nominate').click(); - cy.get(validatorList).contains(this.validatorName).click(); + cy.get(stakeValidatorList).contains(this.validatorName).click(); cy.staking_validator_page_add_stake('2'); - cy.vega_wallet_check_unstaked_value_is('1.000000000000000000'); - vega_wallet_check_validator_staked_value_is( - this.validatorName, - '2.000000000000000000' + cy.get(vegaWalletUnstakedBalance, txTimeout).should( + 'contain', + 1.0, + txTimeout ); + + cy.get(vegaWalletStakedBalances, txTimeout) + .should('contain', 2.0, txTimeout) + .and('contain', this.validatorName); + cy.navigate_to('staking'); + cy.staking_page_disassociate_tokens('1'); - cy.ethereum_wallet_check_associated_value_is('2.0'); - cy.vega_wallet_check_associated_value_is('2.000000000000000000'); - vega_wallet_check_validator_staked_value_is( - this.validatorName, - '2.000000000000000000' + + cy.get(ethWalletTotalAssociatedBalance, txTimeout) + .contains('2.0', txTimeout) + .should('be.visible'); + + cy.get(vegaWalletAssociatedBalance, txTimeout).should( + 'contain', + '2.000000000000000000', + txTimeout ); + + cy.get(vegaWalletStakedBalances, txTimeout) + .should('contain', 2.0, txTimeout) + .and('contain', this.validatorName); + + cy.navigate_to('staking'); + + cy.get(stakeValidatorWithinList, epochTimeout) + .contains(this.validatorName) + .parent() + .contains('Total stake') + .parent() + .should('contain', '2.0') + .and('contain', '100%'); + }); + + it('Selecting use maximum where tokens are allready staked - suggests the unstaked token amount', function () { + cy.staking_page_associate_tokens('3'); + + cy.get(vegaWalletUnstakedBalance, txTimeout).should( + 'contain', + 3.0, + txTimeout + ); + + cy.get('button').contains('Select a validator to nominate').click(); + cy.get(stakeValidatorList).contains(this.validatorName).click(); + + cy.staking_validator_page_add_stake('2'); + + cy.get(vegaWalletUnstakedBalance, txTimeout).should( + 'contain', + 1.0, + txTimeout + ); + + cy.navigate_to('staking'); + + cy.get(stakeValidatorList).contains(this.otherValidatorName).click(); + + cy.get(stakeAddStakeRadioButton).click({ force: true }); + + cy.get(stakeMaximumTokens, { timeout: 60000 }).click(); + + cy.get(stakeTokenSubmitButton).should('contain', 'Add 1 $VEGA tokens'); }); after( @@ -259,77 +561,3 @@ context('Staking Flow - with eth and vega wallets connected', function () { ); }); }); - -function staking_validator_page_check_stake_next_epoch_value(expectedVal) { - cy.highlight( - `Checking Staking Page - Validator Stake Next Epoch Value is ${expectedVal}` - ); - cy.get(stakeNextEpochValue, { timeout: 10000 }) - .contains(expectedVal, { timeout: 10000 }) - .should('be.visible'); -} - -function staking_validator_page_check_stake_this_epoch_value(expectedVal) { - cy.highlight( - `Checking Staking Page - Validator Stake This Epoch Value is ${expectedVal}` - ); - cy.get(stakeNextEpochValue, { timeout: 10000 }) - .contains(expectedVal, { timeout: 10000 }) - .should('be.visible'); -} - -function vega_wallet_check_validator_stake_next_epoch_value_is( - validatorName, - expectedVal -) { - cy.highlight( - `Checking vega wallet - Stake Next Epoch Value for ${validatorName} is ${expectedVal}` - ); - cy.get(vegaWalletContainer).within(() => { - cy.contains(`${validatorName} (Next epoch)`, { timeout: 40000 }) - .siblings() - .contains(expectedVal, { timeout: 40000 }) - .should('be.visible'); - }); -} - -function vega_wallet_check_validator_stake_this_epoch_value_is( - validatorName, - expectedVal -) { - cy.highlight( - `Checking vega wallet - Stake This Epoch Value for ${validatorName} is ${expectedVal}` - ); - cy.get(vegaWalletContainer).within(() => { - cy.contains(`${validatorName} (This Epoch)`, { timeout: 40000 }) - .siblings() - .contains(expectedVal, { timeout: 40000 }) - .should('be.visible'); - }); -} - -function vega_wallet_check_validator_no_longer_showing(validatorName) { - cy.highlight( - `Checking Validator and therefore stake removed for ${validatorName}` - ); - cy.get(vegaWalletContainer).within(() => { - cy.contains(`${validatorName}`, { timeout: 40000 }).should('not.exist', { - timeout: 40000, - }); - }); -} - -function vega_wallet_check_validator_staked_value_is( - validatorName, - expectedVal -) { - cy.highlight( - `Checking Validator Stake Value for ${validatorName} is ${expectedVal}` - ); - cy.get(vegaWalletContainer).within(() => { - cy.contains(`${validatorName}`, { timeout: 40000 }) - .siblings() - .contains(expectedVal, { timeout: 40000 }) - .should('be.visible'); - }); -} 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 7d87be4b4..12074d615 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,7 +1,12 @@ -const pageSpinner = 'splash-loader'; -const menuBar = 'nav'; const validatorList = '[data-testid="node-list-item-name"]'; - +const ethWalletContainer = '[data-testid="ethereum-wallet"]'; +const ethWalletAssociatedBalances = + '[data-testid="eth-wallet-associated-balances"]'; +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 vegaWalletPublicKeyShort = Cypress.env('vegaWalletPublicKeyShort'); context( @@ -10,14 +15,14 @@ context( before('visit staking tab and connect vega wallet', function () { cy.vega_wallet_import(); cy.visit('/'); - cy.get(menuBar, { timeout: 20000 }).should('be.visible'); + cy.verify_page_header('The $VEGA token'); cy.vega_wallet_connect(); cy.vega_wallet_set_specified_approval_amount('1000'); cy.reload(); - cy.get(menuBar, { timeout: 20000 }).should('be.visible'); + cy.verify_page_header('The $VEGA token'); cy.ethereum_wallet_connect(); cy.navigate_to('staking'); - cy.get(pageSpinner, { timeout: 20000 }).should('not.exist'); + cy.wait_for_spinner(); cy.get(validatorList).first().invoke('text').as('validatorName'); }); @@ -27,71 +32,140 @@ context( function () { cy.vega_wallet_teardown(); cy.navigate_to('staking'); - cy.get(pageSpinner, { timeout: 20000 }).should('not.exist'); + cy.wait_for_spinner(); } ); it('Able to associate tokens', function () { cy.staking_page_associate_tokens('2'); - cy.ethereum_wallet_check_associated_vega_key_value_is( - vegaWalletPublicKeyShort, - '2.000000000000000000' + + cy.get(ethWalletAssociatedBalances, txTimeout) + .contains(vegaWalletPublicKeyShort) + .parent() + .should('contain', 2.0, txTimeout); + + cy.get(ethWalletTotalAssociatedBalance, txTimeout) + .contains('2.0', txTimeout) + .should('be.visible'); + + cy.get(vegaWalletAssociatedBalance, txTimeout).should( + 'contain', + 2.0, + txTimeout + ); + + cy.get(vegaWalletUnstakedBalance, txTimeout).should( + 'contain', + 2.0, + txTimeout ); - cy.ethereum_wallet_check_associated_value_is('2.0'); - cy.vega_wallet_check_associated_value_is('2.000000000000000000'); - cy.vega_wallet_check_unstaked_value_is('2.000000000000000000'); }); it('Able to disassociate tokens', function () { cy.staking_page_associate_tokens('2'); - cy.ethereum_wallet_check_associated_vega_key_value_is( - vegaWalletPublicKeyShort, - '2.000000000000000000' - ); - cy.vega_wallet_check_associated_value_is('2.000000000000000000'); + + cy.get(ethWalletAssociatedBalances, txTimeout) + .contains(vegaWalletPublicKeyShort) + .parent() + .should('contain', 2.0, txTimeout); + + cy.get(ethWalletTotalAssociatedBalance, txTimeout) + .contains('2.0', txTimeout) + .should('be.visible'); + cy.get('button').contains('Select a validator to nominate').click(); + cy.staking_page_disassociate_tokens('1'); - cy.ethereum_wallet_check_associated_vega_key_value_is( - vegaWalletPublicKeyShort, - '1.000000000000000000' - ); - cy.ethereum_wallet_check_associated_value_is('1.0'); - cy.vega_wallet_check_associated_value_is('1.000000000000000000'); + + cy.get(ethWalletAssociatedBalances, txTimeout) + .contains(vegaWalletPublicKeyShort) + .parent() + .should('contain', 1.0, txTimeout); + + cy.get(ethWalletTotalAssociatedBalance, txTimeout) + .contains('1.0', txTimeout) + .should('be.visible'); }); it('Able to associate more tokens than the approved amount of 1000 - requires re-approval', function () { cy.staking_page_associate_tokens('1001', true); - cy.ethereum_wallet_check_associated_vega_key_value_is( - vegaWalletPublicKeyShort, - '1,001.000000000000000000' + + cy.get(ethWalletAssociatedBalances, txTimeout) + .contains(vegaWalletPublicKeyShort) + .parent() + .should('contain', '1,001.000000000000000000', txTimeout); + + cy.get(ethWalletTotalAssociatedBalance, txTimeout) + .contains('1,001.00', txTimeout) + .should('be.visible'); + + cy.get(vegaWalletAssociatedBalance, txTimeout).should( + 'contain', + '1,001.000000000000000000', + txTimeout ); - cy.ethereum_wallet_check_associated_value_is('1,001.00'); - cy.vega_wallet_check_associated_value_is('1,001.000000000000000000'); }); it('Able to disassociate a partial amount of tokens currently associated', function () { cy.staking_page_associate_tokens('2'); - cy.vega_wallet_check_associated_value_is('2.000000000000000000'); - cy.get('button').contains('Select a validator to nominate').click(); - cy.staking_page_disassociate_tokens('1'); - cy.ethereum_wallet_check_associated_vega_key_value_is( - vegaWalletPublicKeyShort, - '1.000000000000000000' + + cy.get(vegaWalletAssociatedBalance, txTimeout).should( + 'contain', + 2.0, + txTimeout + ); + + cy.get('button').contains('Select a validator to nominate').click(); + + cy.staking_page_disassociate_tokens('1'); + + cy.get(ethWalletAssociatedBalances, txTimeout) + .contains(vegaWalletPublicKeyShort) + .parent() + .should('contain', 1.0, txTimeout); + + cy.get(ethWalletAssociatedBalances, txTimeout) + .contains(vegaWalletPublicKeyShort) + .parent() + .should('contain', 1.0, txTimeout); + + cy.get(vegaWalletAssociatedBalance, txTimeout).should( + 'contain', + 1.0, + txTimeout ); - cy.ethereum_wallet_check_associated_value_is('1.0'); - cy.vega_wallet_check_associated_value_is('1.000000000000000000'); }); it('Able to disassociate all tokens', function () { cy.staking_page_associate_tokens('2'); - cy.vega_wallet_check_associated_value_is('2.000000000000000000'); - cy.get('button').contains('Select a validator to nominate').click(); - cy.staking_page_disassociate_all_tokens(); - cy.ethereum_wallet_check_associated_vega_key_is_no_longer_showing( - vegaWalletPublicKeyShort + + cy.get(vegaWalletAssociatedBalance, txTimeout).should( + 'contain', + 2.0, + txTimeout + ); + + cy.get('button').contains('Select a validator to nominate').click(); + + cy.staking_page_disassociate_all_tokens(); + + cy.get(ethWalletContainer).within(() => { + cy.contains(vegaWalletPublicKeyShort, { timeout: 20000 }).should( + 'not.exist' + ); + }); + + cy.get(ethWalletContainer).within(() => { + cy.contains(vegaWalletPublicKeyShort, { timeout: 20000 }).should( + 'not.exist' + ); + }); + + cy.get(vegaWalletAssociatedBalance, txTimeout).should( + 'contain', + 0.0, + txTimeout ); - cy.ethereum_wallet_check_associated_value_is('0.0'); - cy.vega_wallet_check_associated_value_is('0.000000000000000000'); }); }); } diff --git a/apps/token-e2e/src/support/common.functions.js b/apps/token-e2e/src/support/common.functions.js index 3f02096b0..065fd18ae 100644 --- a/apps/token-e2e/src/support/common.functions.js +++ b/apps/token-e2e/src/support/common.functions.js @@ -14,6 +14,7 @@ const navigation = { rewards: '[href="/rewards"]', withdraw: '[href="/withdraw"]', governance: '[href="/governance"]', + pageSpinner: 'splash-loader', }; Cypress.Commands.add('navigate_to', (page) => { @@ -31,3 +32,7 @@ Cypress.Commands.add('verify_tab_highlighted', (page) => { Cypress.Commands.add('verify_page_header', (text) => { return cy.get('header h1').should('be.visible').and('have.text', text); }); + +Cypress.Commands.add('wait_for_spinner', () => { + cy.get(navigation.pageSpinner, { timeout: 20000 }).should('not.exist'); +}); diff --git a/apps/token-e2e/src/support/staking.functions.js b/apps/token-e2e/src/support/staking.functions.js index 42652b3fb..40bd9fa0a 100644 --- a/apps/token-e2e/src/support/staking.functions.js +++ b/apps/token-e2e/src/support/staking.functions.js @@ -9,7 +9,6 @@ const associateWalletRadioButton = '[data-testid="associate-radio-wallet"]'; const stakeMaximumTokens = '[data-testid="token-amount-use-maximum"]'; Cypress.Commands.add('wait_for_begining_of_epoch', () => { - cy.highlight(`Waiting for next epoch to start`); cy.contains('Waiting for next epoch to start', { timeout: 10000 }).should( 'not.exist' ); @@ -26,13 +25,9 @@ Cypress.Commands.add('staking_validator_page_add_stake', (stake) => { .and('contain', `Add ${stake} $VEGA tokens`) .and('be.visible') .click(); - cy.contains( - 'At the beginning of the next epoch your $VEGA will be nominated to the validator', - { timeout: 20000 } - ).should('be.visible'); }); -Cypress.Commands.add('staking_validator_page_removeStake', (stake) => { +Cypress.Commands.add('staking_validator_page_remove_stake', (stake) => { cy.highlight(`Removing a stake of ${stake}`); cy.get(removeStakeRadioButton).click({ force: true }); cy.get(tokenAmountInputBox).type(stake); @@ -42,9 +37,6 @@ Cypress.Commands.add('staking_validator_page_removeStake', (stake) => { .and('contain', `Remove ${stake} $VEGA tokens at the end of epoch`) .and('be.visible') .click(); - cy.contains(`${stake} $VEGA has been removed from validator`).should( - 'be.visible' - ); }); Cypress.Commands.add( diff --git a/apps/token-e2e/src/support/wallet-eth.functions.js b/apps/token-e2e/src/support/wallet-eth.functions.js index 1a4bec47d..73afc921b 100644 --- a/apps/token-e2e/src/support/wallet-eth.functions.js +++ b/apps/token-e2e/src/support/wallet-eth.functions.js @@ -16,42 +16,3 @@ Cypress.Commands.add('ethereum_wallet_connect', () => { cy.contains('Locked', { timeout: 15000 }).should('be.visible'); }); }); - -Cypress.Commands.add( - 'ethereum_wallet_check_associated_value_is', - (expectedVal) => { - cy.highlight(`Checking Eth Wallet - Associated Value is ${expectedVal}`); - cy.get(ethWalletContainer).within(() => { - cy.contains('Associated', { timeout: 20000 }) - .parent() - .siblings() - .contains(expectedVal, { timeout: 40000 }) - .should('be.visible'); - }); - } -); - -Cypress.Commands.add( - 'ethereum_wallet_check_associated_vega_key_value_is', - (vegaShortPublicKey, expectedVal) => { - cy.highlight( - `Checking Eth Wallet - Vega Key Associated Value is ${expectedVal} for key ${vegaShortPublicKey}` - ); - cy.get(ethWalletContainer).within(() => { - cy.contains(vegaShortPublicKey, { timeout: 20000 }) - .parent() - .contains(expectedVal, { timeout: 40000 }) - .should('be.visible'); - }); - } -); - -Cypress.Commands.add( - 'ethereum_wallet_check_associated_vega_key_is_no_longer_showing', - (vegaShortPublicKey) => { - cy.highlight('Checking Eth Wallet - Vega Key Associated is not showing'); - cy.get(ethWalletContainer).within(() => { - cy.contains(vegaShortPublicKey, { timeout: 20000 }).should('not.exist'); - }); - } -); diff --git a/apps/token-e2e/src/support/wallet-teardown.functions.js b/apps/token-e2e/src/support/wallet-teardown.functions.js index 5642c07e0..46eabf2f6 100644 --- a/apps/token-e2e/src/support/wallet-teardown.functions.js +++ b/apps/token-e2e/src/support/wallet-teardown.functions.js @@ -5,6 +5,7 @@ import { } from '@vegaprotocol/smart-contracts'; import { ethers, Wallet } from 'ethers'; +const vegaWalletAssociatedBalance = '[data-testid="currency-value"]'; const vegaWalletMnemonic = Cypress.env('vegaWalletMnemonic'); const vegaWalletPubKey = Cypress.env('vegaWalletPublicKey'); const vegaTokenContractAddress = Cypress.env('vegaTokenContractAddress'); @@ -41,7 +42,12 @@ before('Vega wallet teardown prep', function () { Cypress.Commands.add('vega_wallet_teardown', function () { cy.vega_wallet_teardown_staking(this.stakingBridgeContract); cy.vega_wallet_teardown_vesting(this.vestingContract); - cy.vega_wallet_check_associated_value_is('0.000000000000000000'); + + cy.get(vegaWalletAssociatedBalance, { timeout: transactionTimeout }).should( + 'contain', + '0.000000000000000000', + { timeout: transactionTimeout } + ); }); Cypress.Commands.add( diff --git a/apps/token-e2e/src/support/wallet-vega.functions.js b/apps/token-e2e/src/support/wallet-vega.functions.js index 3ab43139d..f77a2759d 100644 --- a/apps/token-e2e/src/support/wallet-vega.functions.js +++ b/apps/token-e2e/src/support/wallet-vega.functions.js @@ -33,24 +33,3 @@ Cypress.Commands.add('vega_wallet_connect', () => { }); cy.contains(`${vegaWalletName} key`, { timeout: 20000 }).should('be.visible'); }); - -Cypress.Commands.add('vega_wallet_check_unstaked_value_is', (expectedVal) => { - cy.highlight(`Checking vega wallet - Unstaked Value is ${expectedVal}`); - cy.get(vegaWalletContainer).within(() => { - cy.contains('Unstaked', { timeout: 40000 }) - .siblings() - .contains(expectedVal, { timeout: 40000 }) - .should('be.visible'); - }); -}); - -Cypress.Commands.add('vega_wallet_check_associated_value_is', (expectedVal) => { - cy.highlight(`Checking vega wallet - Associated Value is ${expectedVal}`); - cy.get(vegaWalletContainer).within(() => { - cy.contains('Associated', { timeout: 40000 }) - .parent() - .siblings() - .contains(expectedVal, { timeout: 40000 }) - .should('be.visible'); - }); -}); diff --git a/apps/token/src/components/eth-wallet/eth-wallet.tsx b/apps/token/src/components/eth-wallet/eth-wallet.tsx index 509542acc..aa0e15280 100644 --- a/apps/token/src/components/eth-wallet/eth-wallet.tsx +++ b/apps/token/src/components/eth-wallet/eth-wallet.tsx @@ -83,12 +83,14 @@ const AssociatedAmounts = ({ /> {vestingAssociationByVegaKey.map(([key, amount]) => { return ( - +
+ +
); })} diff --git a/apps/token/src/components/vega-wallet/vega-wallet.tsx b/apps/token/src/components/vega-wallet/vega-wallet.tsx index 8eac261b9..ff81d2a17 100644 --- a/apps/token/src/components/vega-wallet/vega-wallet.tsx +++ b/apps/token/src/components/vega-wallet/vega-wallet.tsx @@ -154,31 +154,37 @@ const VegaWalletConnected = ({ vegaKeys }: VegaWalletConnectedProps) => { balance={currentStakeAvailable} dark={true} /> - +
+ +
{delegatedNodes.length ? ( ) : null} {delegatedNodes.map((d) => ( -
+
{d.currentEpochStake && d.currentEpochStake.isGreaterThan(0) && ( - +
+ +
)} {d.hasStakePending && ( - +
+ +
)}
))}