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 3f9cb8915..47e25ca80 100644 --- a/apps/token-e2e/src/integration/flow/staking-flow.cy.js +++ b/apps/token-e2e/src/integration/flow/staking-flow.cy.js @@ -1,31 +1,28 @@ -/// -import navigation from '../../locators/navigation.locators'; -import staking from '../../locators/staking.locators'; -import vegaWallet from '../../locators/wallet-vega.locators'; -import '../../support/staking.functions'; -import '../../support/wallet-vega.functions'; -import '../../support/wallet-eth.functions'; -import '../../support/wallet-teardown.functions'; - +const stakingPageLink = '[href="/staking"]'; +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 stakeNextEpochValue = '[data-testid="stake-next-epoch"]'; const vegaWalletPublicKeyShort = Cypress.env('vegaWalletPublicKeyShort'); +const vegaWalletContainer = '[data-testid="vega-wallet"]'; 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(navigation.section, { timeout: 20000 }).should('be.visible'); + cy.get(menuBar, { timeout: 20000 }).should('be.visible'); cy.vega_wallet_connect(); cy.vega_wallet_set_specified_approval_amount('1000'); cy.reload(); - cy.get(navigation.section, { timeout: 20000 }).should('be.visible'); + cy.get(menuBar, { timeout: 20000 }).should('be.visible'); cy.ethereum_wallet_connect(); - cy.get(navigation.staking).first().click(); - cy.get(navigation.spinner, { timeout: 20000 }).should('not.exist'); - cy.get(staking.validatorNames).first().invoke('text').as('validatorName'); - cy.get(staking.validatorNames) - .last() - .invoke('text') - .as('otherValidatorName'); + cy.get(stakingPageLink).first().click(); + cy.get(pageSpinner, { timeout: 20000 }).should('not.exist'); + cy.get(validatorList).first().invoke('text').as('validatorName'); + cy.get(validatorList).last().invoke('text').as('otherValidatorName'); }); describe('Eth wallet - contains VEGA tokens', function () { @@ -33,7 +30,7 @@ context('Staking Flow - with eth and vega wallets connected', function () { 'teardown wallet & drill into a specific validator', function () { cy.vega_wallet_teardown(); - cy.get(navigation.staking).first().click(); + cy.get(stakingPageLink).first().click(); } ); @@ -47,7 +44,7 @@ context('Staking Flow - with eth and vega wallets connected', function () { ); cy.get('button').contains('Select a validator to nominate').click(); - cy.get(staking.validatorNames).contains(this.validatorName).click(); + cy.get(validatorList).contains(this.validatorName).click(); cy.staking_validator_page_add_stake('2'); cy.vega_wallet_check_validator_stake_next_epoch_value_is( @@ -67,15 +64,15 @@ context('Staking Flow - with eth and vega wallets connected', function () { cy.staking_page_associate_tokens('5'); cy.vega_wallet_check_unstaked_value_is('5.000000000000000000'); cy.get('button').contains('Select a validator to nominate').click(); - cy.get(staking.validatorNames).contains(this.validatorName).click(); + cy.get(validatorList).contains(this.validatorName).click(); cy.staking_validator_page_add_stake('2'); cy.vega_wallet_check_validator_staked_value_is( this.validatorName, '2.000000000000000000' ); - cy.get(navigation.staking).first().click(); - cy.get(staking.validatorNames).contains(this.otherValidatorName).click(); + cy.get(stakingPageLink).first().click(); + cy.get(validatorList).contains(this.otherValidatorName).click(); cy.staking_validator_page_add_stake('1'); cy.vega_wallet_check_validator_staked_value_is( this.otherValidatorName, @@ -89,7 +86,7 @@ context('Staking Flow - with eth and vega wallets connected', function () { cy.vega_wallet_check_unstaked_value_is('4.000000000000000000'); cy.get('button').contains('Select a validator to nominate').click(); - cy.get(staking.validatorNames).contains(this.validatorName).click(); + cy.get(validatorList).contains(this.validatorName).click(); cy.staking_validator_page_add_stake('3'); cy.staking_validator_page_check_stake_next_epoch_value('3.0'); @@ -99,8 +96,8 @@ context('Staking Flow - with eth and vega wallets connected', function () { ); cy.vega_wallet_check_unstaked_value_is('1.000000000000000000'); - cy.get(navigation.staking).first().click(); - cy.get(staking.validatorNames).contains(this.validatorName).click(); + cy.get(stakingPageLink).first().click(); + cy.get(validatorList).contains(this.validatorName).click(); cy.staking_validator_page_removeStake('1'); cy.staking_validator_page_check_stake_next_epoch_value('2.0'); @@ -127,7 +124,7 @@ context('Staking Flow - with eth and vega wallets connected', function () { cy.vega_wallet_check_unstaked_value_is('3.000000000000000000'); cy.get('button').contains('Select a validator to nominate').click(); - cy.get(staking.validatorNames).contains(this.validatorName).click(); + cy.get(validatorList).contains(this.validatorName).click(); cy.staking_validator_page_add_stake('1'); cy.vega_wallet_check_validator_stake_next_epoch_value_is( @@ -136,8 +133,8 @@ context('Staking Flow - with eth and vega wallets connected', function () { ); cy.vega_wallet_check_unstaked_value_is('2.000000000000000000'); - cy.get(navigation.staking).first().click(); - cy.get(staking.validatorNames).contains(this.validatorName).click(); + cy.get(stakingPageLink).first().click(); + cy.get(validatorList).contains(this.validatorName).click(); cy.staking_validator_page_removeStake('1'); cy.staking_validator_page_check_stake_next_epoch_value('0.0'); @@ -161,7 +158,7 @@ context('Staking Flow - with eth and vega wallets connected', function () { cy.vega_wallet_check_unstaked_value_is('3.000000000000000000'); cy.get('button').contains('Select a validator to nominate').click(); - cy.get(staking.validatorNames).contains(this.validatorName).click(); + cy.get(validatorList).contains(this.validatorName).click(); cy.staking_validator_page_add_stake('2'); cy.staking_validator_page_check_stake_next_epoch_value('2.0'); @@ -171,12 +168,12 @@ context('Staking Flow - with eth and vega wallets connected', function () { ); cy.vega_wallet_check_unstaked_value_is('1.000000000000000000'); - cy.get(navigation.staking).first().click(); - cy.get(staking.validatorNames).contains(this.validatorName).click(); - cy.get(staking.removeStakeRadioButton).click({ force: true }); - cy.get(staking.tokenAmountInput).type('-0.1'); + cy.get(stakingPageLink).first().click(); + 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(staking.tokenInputSubmit) + cy.get(tokenSubmitButton) .should('be.disabled', { timeout: 8000 }) .and('contain', `Remove -0.1 $VEGA tokens at the end of epoch`) .and('be.visible'); @@ -187,7 +184,7 @@ context('Staking Flow - with eth and vega wallets connected', function () { cy.vega_wallet_check_unstaked_value_is('3.000000000000000000'); cy.get('button').contains('Select a validator to nominate').click(); - cy.get(staking.validatorNames).contains(this.validatorName).click(); + cy.get(validatorList).contains(this.validatorName).click(); cy.staking_validator_page_add_stake('2'); cy.staking_validator_page_check_stake_next_epoch_value('2.0'); @@ -197,12 +194,12 @@ context('Staking Flow - with eth and vega wallets connected', function () { ); cy.vega_wallet_check_unstaked_value_is('1.000000000000000000'); - cy.get(navigation.staking).first().click(); - cy.get(staking.validatorNames).contains(this.validatorName).click(); - cy.get(staking.removeStakeRadioButton).click({ force: true }); - cy.get(staking.tokenAmountInput).type(4); + cy.get(stakingPageLink).first().click(); + 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(staking.tokenInputSubmit) + cy.get(tokenSubmitButton) .should('be.disabled', { timeout: 8000 }) .and('contain', `Remove 4 $VEGA tokens at the end of epoch`) .and('be.visible'); @@ -213,7 +210,7 @@ context('Staking Flow - with eth and vega wallets connected', function () { cy.vega_wallet_check_unstaked_value_is('3.000000000000000000'); cy.get('button').contains('Select a validator to nominate').click(); - cy.get(staking.validatorNames).contains(this.validatorName).click(); + cy.get(validatorList).contains(this.validatorName).click(); cy.staking_validator_page_add_stake('2'); cy.vega_wallet_check_unstaked_value_is('1.000000000000000000'); @@ -221,7 +218,7 @@ context('Staking Flow - with eth and vega wallets connected', function () { this.validatorName, '2.000000000000000000' ); - cy.get(navigation.staking).first().click(); + cy.get(stakingPageLink).first().click(); cy.staking_page_disassociate_all_tokens(); cy.ethereum_wallet_check_associated_vega_key_is_no_longer_showing( vegaWalletPublicKeyShort @@ -236,7 +233,7 @@ context('Staking Flow - with eth and vega wallets connected', function () { cy.vega_wallet_check_unstaked_value_is('3.000000000000000000'); cy.get('button').contains('Select a validator to nominate').click(); - cy.get(staking.validatorNames).contains(this.validatorName).click(); + cy.get(validatorList).contains(this.validatorName).click(); cy.staking_validator_page_add_stake('2'); cy.vega_wallet_check_unstaked_value_is('1.000000000000000000'); @@ -244,7 +241,7 @@ context('Staking Flow - with eth and vega wallets connected', function () { this.validatorName, '2.000000000000000000' ); - cy.get(navigation.staking).first().click(); + cy.get(stakingPageLink).first().click(); cy.staking_page_disassociate_tokens('1'); cy.ethereum_wallet_check_associated_value_is('2.0'); cy.vega_wallet_check_associated_value_is('2.000000000000000000'); @@ -262,77 +259,89 @@ context('Staking Flow - with eth and vega wallets connected', function () { ); }); - cy.staking_validator_page_check_stake_next_epoch_value = (expectedVal) => { - cy.highlight( - `Checking Staking Page - Validator Stake Next Epoch Value is ${expectedVal}` - ); - cy.get(staking.stakeNextEpochValue, { timeout: 10000 }) - .contains(expectedVal, { timeout: 10000 }) - .should('be.visible'); - }; - - cy.staking_validator_page_check_stake_this_epoch_value = (expectedVal) => { - cy.highlight( - `Checking Staking Page - Validator Stake This Epoch Value is ${expectedVal}` - ); - cy.get(staking.stakeThisEpochValue, { timeout: 10000 }) - .contains(expectedVal, { timeout: 10000 }) - .should('be.visible'); - }; - - cy.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(vegaWallet.walletContainer).within(() => { - cy.contains(`${validatorName} (Next epoch)`, { timeout: 40000 }) - .siblings() - .contains(expectedVal, { timeout: 40000 }) + Cypress.Commands.add( + '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'); - }); - }; + } + ); - cy.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(vegaWallet.walletContainer).within(() => { - cy.contains(`${validatorName} (This Epoch)`, { timeout: 40000 }) - .siblings() - .contains(expectedVal, { timeout: 40000 }) + Cypress.Commands.add( + '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'); - }); - }; + } + ); - cy.vega_wallet_check_validator_no_longer_showing = (validatorName) => { - cy.highlight( - `Checking Validator and therefore stake removed for ${validatorName}` - ); - cy.get(vegaWallet.walletContainer).within(() => { - cy.contains(`${validatorName}`, { timeout: 40000 }).should('not.exist', { - timeout: 40000, + Cypress.Commands.add( + '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'); }); - }); - }; + } + ); - cy.vega_wallet_check_validator_staked_value_is = ( - validatorName, - expectedVal - ) => { - cy.highlight( - `Checking Validator Stake Value for ${validatorName} is ${expectedVal}` - ); - cy.get(vegaWallet.walletContainer).within(() => { - cy.contains(`${validatorName}`, { timeout: 40000 }) - .siblings() - .contains(expectedVal, { timeout: 40000 }) - .should('be.visible'); - }); - }; + Cypress.Commands.add( + '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'); + }); + } + ); + + Cypress.Commands.add( + '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, + } + ); + }); + } + ); + + Cypress.Commands.add( + '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 a4a967be8..a60ceb183 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,12 +1,7 @@ -/// -import navigation from '../../locators/navigation.locators'; -import staking from '../../locators/staking.locators'; -import ethWallet from '../../locators/wallet-eth.locators'; -import '../../support/staking.functions'; -import '../../support/wallet-vega.functions'; -import '../../support/wallet-eth.functions'; -import '../../support/wallet-teardown.functions'; - +const stakingPageLink = '[href="/staking"]'; +const pageSpinner = 'splash-loader'; +const menuBar = 'nav'; +const validatorList = '[data-testid="node-list-item-name"]'; const vegaWalletPublicKeyShort = Cypress.env('vegaWalletPublicKeyShort'); context( @@ -15,15 +10,15 @@ context( before('visit staking tab and connect vega wallet', function () { cy.vega_wallet_import(); cy.visit('/'); - cy.get(navigation.section, { timeout: 20000 }).should('be.visible'); + cy.get(menuBar, { timeout: 20000 }).should('be.visible'); cy.vega_wallet_connect(); cy.vega_wallet_set_specified_approval_amount('1000'); cy.reload(); - cy.get(navigation.section, { timeout: 20000 }).should('be.visible'); + cy.get(menuBar, { timeout: 20000 }).should('be.visible'); cy.ethereum_wallet_connect(); - cy.get(navigation.staking).first().click(); - cy.get(navigation.spinner, { timeout: 20000 }).should('not.exist'); - cy.get(staking.validatorNames).first().invoke('text').as('validatorName'); + cy.get(stakingPageLink).first().click(); + cy.get(pageSpinner, { timeout: 20000 }).should('not.exist'); + cy.get(validatorList).first().invoke('text').as('validatorName'); }); describe('Eth wallet - contains VEGA tokens', function () { @@ -31,12 +26,12 @@ context( 'teardown wallet & drill into a specific validator', function () { cy.vega_wallet_teardown(); - cy.get(navigation.staking).first().click(); - cy.get(navigation.spinner, { timeout: 20000 }).should('not.exist'); + cy.get(stakingPageLink).first().click(); + cy.get(pageSpinner, { timeout: 20000 }).should('not.exist'); } ); - it('Able to associate tokens - from staking page', function () { + it('Able to associate tokens', function () { cy.staking_page_associate_tokens('2'); cy.ethereum_wallet_check_associated_vega_key_value_is( vegaWalletPublicKeyShort, @@ -47,7 +42,7 @@ context( cy.vega_wallet_check_unstaked_value_is('2.000000000000000000'); }); - it('Able to disassociate tokens - from staking page', function () { + it('Able to disassociate tokens', function () { cy.staking_page_associate_tokens('2'); cy.ethereum_wallet_check_associated_vega_key_value_is( vegaWalletPublicKeyShort, @@ -64,24 +59,6 @@ context( cy.vega_wallet_check_associated_value_is('1.000000000000000000'); }); - it('Able to access associate token form - from eth wallet', function () { - cy.get(ethWallet.walletContainer).within(() => - cy.get(ethWallet.associate).click() - ); - cy.get(staking.stakeAssociateWalletRadio, { timeout: 30000 }).should( - 'be.enabled' - ); - }); - - it('Able to access disassociate token form - from eth wallet', function () { - cy.get(ethWallet.walletContainer).within(() => - cy.get(ethWallet.disassociate).click() - ); - cy.get(staking.stakeAssociateWalletRadio, { timeout: 30000 }).should( - 'be.enabled' - ); - }); - 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( diff --git a/apps/token-e2e/src/support/common.functions.js b/apps/token-e2e/src/support/common.functions.js new file mode 100644 index 000000000..ae7d1d705 --- /dev/null +++ b/apps/token-e2e/src/support/common.functions.js @@ -0,0 +1,7 @@ +Cypress.Commands.add( + 'convertTokenValueToNumber', + { prevSubject: true }, + (subject) => { + return parseFloat(subject.replace(/,/g, '')); + } +); diff --git a/apps/token-e2e/src/support/index.ts b/apps/token-e2e/src/support/index.ts index ac0235f29..f5a484c0d 100644 --- a/apps/token-e2e/src/support/index.ts +++ b/apps/token-e2e/src/support/index.ts @@ -1,5 +1,11 @@ import '@vegaprotocol/cypress'; +import './common.functions.js'; +import './staking.functions.js'; +import './wallet-eth.functions.js'; +import './wallet-teardown.functions.js'; +import './wallet-vega.functions.js'; + // Hide fetch/XHR requests - They create a lot of noise in command log const app = window.top; if (!app.document.head.querySelector('[data-hide-command-log-request]')) { diff --git a/apps/token-e2e/src/support/staking.functions.js b/apps/token-e2e/src/support/staking.functions.js index 57eb9e916..42652b3fb 100644 --- a/apps/token-e2e/src/support/staking.functions.js +++ b/apps/token-e2e/src/support/staking.functions.js @@ -1,11 +1,27 @@ -import staking from '../locators/staking.locators'; +const tokenAmountInputBox = '[data-testid="token-amount-input"]'; +const tokenSubmitButton = '[data-testid="token-input-submit-button"]'; +const tokenInputApprove = '[data-testid="token-input-approve-button"]'; +const addStakeRadioButton = '[data-testid="add-stake-radio"]'; +const removeStakeRadioButton = '[data-testid="remove-stake-radio"]'; +const ethWalletAssociateButton = '[href="/staking/associate"]'; +const ethWalletDissociateButton = '[href="/staking/disassociate"]'; +const associateWalletRadioButton = '[data-testid="associate-radio-wallet"]'; +const stakeMaximumTokens = '[data-testid="token-amount-use-maximum"]'; -cy.staking_validator_page_add_stake = (stake) => { +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' + ); + cy.contains('Waiting for next epoch to start', { timeout: 20000 }); +}); + +Cypress.Commands.add('staking_validator_page_add_stake', (stake) => { cy.highlight(`Adding a stake of ${stake}`); - cy.get(staking.addStakeRadioButton).click({ force: true }); - cy.get(staking.tokenAmountInput).type(stake); - cy.contains('Waiting for next epoch to start', { timeout: 10000 }); - cy.get(staking.tokenInputSubmit, { timeout: 8000 }) + cy.get(addStakeRadioButton).click({ force: true }); + cy.get(tokenAmountInputBox).type(stake); + cy.wait_for_begining_of_epoch(); + cy.get(tokenSubmitButton, { timeout: 8000 }) .should('be.enabled') .and('contain', `Add ${stake} $VEGA tokens`) .and('be.visible') @@ -14,14 +30,14 @@ cy.staking_validator_page_add_stake = (stake) => { 'At the beginning of the next epoch your $VEGA will be nominated to the validator', { timeout: 20000 } ).should('be.visible'); -}; +}); -cy.staking_validator_page_removeStake = (stake) => { +Cypress.Commands.add('staking_validator_page_removeStake', (stake) => { cy.highlight(`Removing a stake of ${stake}`); - cy.get(staking.removeStakeRadioButton).click({ force: true }); - cy.get(staking.tokenAmountInput).type(stake); - cy.contains('Waiting for next epoch to start', { timeout: 10000 }); - cy.get(staking.tokenInputSubmit) + cy.get(removeStakeRadioButton).click({ force: true }); + cy.get(tokenAmountInputBox).type(stake); + cy.wait_for_begining_of_epoch(); + cy.get(tokenSubmitButton) .should('be.enabled', { timeout: 8000 }) .and('contain', `Remove ${stake} $VEGA tokens at the end of epoch`) .and('be.visible') @@ -29,53 +45,52 @@ cy.staking_validator_page_removeStake = (stake) => { cy.contains(`${stake} $VEGA has been removed from validator`).should( 'be.visible' ); -}; +}); -cy.staking_page_associate_tokens = (amount, approve = false) => { - cy.highlight(`Associating ${amount} tokens`); - cy.get(staking.associateButton).click(); - cy.get(staking.stakeAssociateWalletRadio, { timeout: 30000 }).click(); - cy.get(staking.tokenAmountInput, { timeout: 10000 }).type(amount); - if (approve) { - cy.get(staking.tokenInputApprove, { timeout: 40000 }) - .should('be.enabled') - .click(); - cy.contains('Approve $VEGA Tokens for staking on Vega').should( - 'be.visible' - ); - cy.contains('Approve $VEGA Tokens for staking on Vega', { - timeout: 40000, - }).should('not.exist'); +Cypress.Commands.add( + 'staking_page_associate_tokens', + (amount, approve = false) => { + cy.highlight(`Associating ${amount} tokens`); + cy.get(ethWalletAssociateButton).first().click(); + cy.get(associateWalletRadioButton, { timeout: 30000 }).click(); + cy.get(tokenAmountInputBox, { timeout: 10000 }).type(amount); + if (approve) { + cy.get(tokenInputApprove, { timeout: 40000 }) + .should('be.enabled') + .click(); + cy.contains('Approve $VEGA Tokens for staking on Vega').should( + 'be.visible' + ); + cy.contains('Approve $VEGA Tokens for staking on Vega', { + timeout: 40000, + }).should('not.exist'); + } + cy.get(tokenSubmitButton, { timeout: 40000 }).should('be.enabled').click(); + cy.contains('can now participate in governance and nominate a validator', { + timeout: 60000, + }).should('be.visible'); } - cy.get(staking.tokenInputSubmit, { timeout: 40000 }) - .should('be.enabled') - .click(); - cy.contains('can now participate in governance and nominate a validator', { - timeout: 60000, - }).should('be.visible'); -}; +); -cy.staking_page_disassociate_tokens = (amount) => { +Cypress.Commands.add('staking_page_disassociate_tokens', (amount) => { cy.highlight(`Disassociating ${amount} tokens via Staking Page`); - cy.get(staking.disassociateButton).click(); - cy.get(staking.stakeAssociateWalletRadio, { timeout: 30000 }).click(); - cy.get(staking.tokenAmountInput, { timeout: 10000 }).type(amount); + cy.get(ethWalletDissociateButton).first().click(); + cy.get(associateWalletRadioButton, { timeout: 30000 }).click(); + cy.get(tokenAmountInputBox, { timeout: 10000 }).type(amount); - cy.get(staking.tokenInputSubmit, { timeout: 40000 }) - .should('be.enabled') - .click(); + cy.get(tokenSubmitButton, { timeout: 40000 }).should('be.enabled').click(); cy.contains(`${amount} $VEGA tokens have been returned to Ethereum wallet`, { timeout: 60000, }).should('be.visible'); -}; +}); -cy.staking_page_disassociate_all_tokens = () => { +Cypress.Commands.add('staking_page_disassociate_all_tokens', () => { cy.highlight(`Disassociating all tokens via Staking Page`); - cy.get(staking.disassociateButton).click(); - cy.get(staking.stakeAssociateWalletRadio, { timeout: 20000 }).click(); - cy.get(staking.stakeMaximumTokens, { timeout: 60000 }).click(); - cy.get(staking.tokenInputSubmit, { timeout: 10000 }).click(); + cy.get(ethWalletDissociateButton).first().click(); + cy.get(associateWalletRadioButton, { timeout: 20000 }).click(); + cy.get(stakeMaximumTokens, { timeout: 60000 }).click(); + cy.get(tokenSubmitButton, { timeout: 10000 }).click(); cy.contains('$VEGA tokens have been returned to Ethereum wallet', { timeout: 60000, }).should('be.visible'); -}; +}); diff --git a/apps/token-e2e/src/support/wallet-eth.functions.js b/apps/token-e2e/src/support/wallet-eth.functions.js index da6fcfb97..1a4bec47d 100644 --- a/apps/token-e2e/src/support/wallet-eth.functions.js +++ b/apps/token-e2e/src/support/wallet-eth.functions.js @@ -1,59 +1,57 @@ -import ethWallet from '../locators/wallet-eth.locators'; +const ethWalletContainer = '[data-testid="ethereum-wallet"]'; +const connectToEthButton = '[data-testid="connect-to-eth-wallet-button"]'; +const capsuleWalletConnectButton = '[data-testid="web3-connector-Unknown"]'; -cy.ethereum_wallet_connect = () => { +Cypress.Commands.add('ethereum_wallet_connect', () => { cy.highlight('Connecting Eth Wallet'); - cy.get(ethWallet.connectToEthButton).within(() => { + cy.get(connectToEthButton).within(() => { cy.contains('Connect Ethereum wallet to associate $VEGA') .should('be.visible') .click(); }); - cy.get(ethWallet.connectorCapsule).click(); - cy.get(ethWallet.connectorCapsule, { timeout: 60000 }).should('not.exist'); - cy.get(ethWallet.walletContainer).within(() => { + cy.get(capsuleWalletConnectButton).click(); + cy.get(capsuleWalletConnectButton, { timeout: 60000 }).should('not.exist'); + cy.get(ethWalletContainer).within(() => { // this check is required since it ensures the wallet is fully (not partially) loaded cy.contains('Locked', { timeout: 15000 }).should('be.visible'); }); -}; - -cy.ethereum_wallet_check_associated_value_is = (expectedVal) => { - cy.highlight(`Checking Eth Wallet - Associated Value is ${expectedVal}`); - cy.get(ethWallet.walletContainer).within(() => { - cy.contains('Associated', { timeout: 20000 }) - .parent() - .siblings() - .contains(expectedVal, { timeout: 40000 }) - .should('be.visible'); - }); -}; - -cy.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(ethWallet.walletContainer).within(() => { - cy.contains(vegaShortPublicKey, { timeout: 20000 }) - .parent() - .contains(expectedVal, { timeout: 40000 }) - .should('be.visible'); - }); -}; - -cy.ethereum_wallet_check_associated_vega_key_is_no_longer_showing = ( - vegaShortPublicKey -) => { - cy.highlight('Checking Eth Wallet - Vega Key Associated is not showing'); - cy.get(ethWallet.walletContainer).within(() => { - cy.contains(vegaShortPublicKey, { timeout: 20000 }).should('not.exist'); - }); -}; +}); Cypress.Commands.add( - 'convertTokenValueToNumber', - { prevSubject: true }, - (subject) => { - return parseFloat(subject.replace(/,/g, '')); + '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 aef6805af..5642c07e0 100644 --- a/apps/token-e2e/src/support/wallet-teardown.functions.js +++ b/apps/token-e2e/src/support/wallet-teardown.functions.js @@ -64,27 +64,30 @@ Cypress.Commands.add( } ); -cy.vega_wallet_teardown_staking = (stakingBridgeContract) => { - cy.highlight('Tearing down staking tokens from vega wallet if present'); - cy.wrap( - stakingBridgeContract.stakeBalance(ethWalletPubKey, vegaWalletPubKey), - { - timeout: transactionTimeout, - log: false, - } - ).then((stake_amount) => { - if (String(stake_amount) != '0') { - cy.wrap( - stakingBridgeContract.removeStake(stake_amount, vegaWalletPubKey), - { timeout: transactionTimeout, log: false } - ).then((tx) => { - cy.wait_for_transaction(tx); - }); - } - }); -}; +Cypress.Commands.add( + 'vega_wallet_teardown_staking', + (stakingBridgeContract) => { + cy.highlight('Tearing down staking tokens from vega wallet if present'); + cy.wrap( + stakingBridgeContract.stakeBalance(ethWalletPubKey, vegaWalletPubKey), + { + timeout: transactionTimeout, + log: false, + } + ).then((stake_amount) => { + if (String(stake_amount) != '0') { + cy.wrap( + stakingBridgeContract.removeStake(stake_amount, vegaWalletPubKey), + { timeout: transactionTimeout, log: false } + ).then((tx) => { + cy.wait_for_transaction(tx); + }); + } + }); + } +); -cy.vega_wallet_teardown_vesting = (vestingContract) => { +Cypress.Commands.add('vega_wallet_teardown_vesting', (vestingContract) => { cy.highlight('Tearing down vesting tokens from vega wallet if present'); cy.wrap(vestingContract.stakeBalance(ethWalletPubKey, vegaWalletPubKey), { timeout: transactionTimeout, @@ -99,8 +102,8 @@ cy.vega_wallet_teardown_vesting = (vestingContract) => { }); } }); -}; +}); -cy.wait_for_transaction = (tx) => { +Cypress.Commands.add('wait_for_transaction', (tx) => { cy.wrap(tx.wait(1).catch(cy.log), { timeout: transactionTimeout }); -}; +}); diff --git a/apps/token-e2e/src/support/wallet-vega.functions.js b/apps/token-e2e/src/support/wallet-vega.functions.js index 684df9d66..3ab43139d 100644 --- a/apps/token-e2e/src/support/wallet-vega.functions.js +++ b/apps/token-e2e/src/support/wallet-vega.functions.js @@ -1,10 +1,10 @@ -import vegaWallet from '../locators/wallet-vega.locators'; - +const vegaWalletContainer = '[data-testid="vega-wallet"]'; +const restConnectorForm = '[data-testid="rest-connector-form"]'; const vegaWalletName = Cypress.env('vegaWalletName'); const vegaWalletLocation = Cypress.env('vegaWalletLocation'); const vegaWalletPassphrase = Cypress.env('vegaWalletPassphrase'); -cy.vega_wallet_import = () => { +Cypress.Commands.add('vega_wallet_import', () => { cy.highlight(`Importing Vega Wallet ${vegaWalletName}`); cy.exec(`vegawallet init -f --home ${vegaWalletLocation}`); cy.exec( @@ -14,11 +14,11 @@ cy.vega_wallet_import = () => { cy.exec( `vegawallet service run --network DV --automatic-consent --home ${vegaWalletLocation}` ); -}; +}); -cy.vega_wallet_connect = () => { +Cypress.Commands.add('vega_wallet_connect', () => { cy.highlight('Connecting Vega Wallet'); - cy.get(vegaWallet.walletContainer).within(() => { + cy.get(vegaWalletContainer).within(() => { cy.get('button') .contains('Connect Vega wallet to use associated $VEGA') .should('be.enabled') @@ -26,31 +26,31 @@ cy.vega_wallet_connect = () => { .click({ force: true }); }); cy.get('button').contains('rest provider').click(); - cy.get(vegaWallet.connectRestForm).within(() => { - cy.get(vegaWallet.name).click().type(vegaWalletName); - cy.get(vegaWallet.passphrase).click().type(vegaWalletPassphrase); + cy.get(restConnectorForm).within(() => { + cy.get('#wallet').click().type(vegaWalletName); + cy.get('#passphrase').click().type(vegaWalletPassphrase); cy.get('button').contains('Connect').click(); }); cy.contains(`${vegaWalletName} key`, { timeout: 20000 }).should('be.visible'); -}; +}); -cy.vega_wallet_check_unstaked_value_is = (expectedVal) => { +Cypress.Commands.add('vega_wallet_check_unstaked_value_is', (expectedVal) => { cy.highlight(`Checking vega wallet - Unstaked Value is ${expectedVal}`); - cy.get(vegaWallet.walletContainer).within(() => { + cy.get(vegaWalletContainer).within(() => { cy.contains('Unstaked', { timeout: 40000 }) .siblings() .contains(expectedVal, { timeout: 40000 }) .should('be.visible'); }); -}; +}); -cy.vega_wallet_check_associated_value_is = (expectedVal) => { +Cypress.Commands.add('vega_wallet_check_associated_value_is', (expectedVal) => { cy.highlight(`Checking vega wallet - Associated Value is ${expectedVal}`); - cy.get(vegaWallet.walletContainer).within(() => { + cy.get(vegaWalletContainer).within(() => { cy.contains('Associated', { timeout: 40000 }) .parent() .siblings() .contains(expectedVal, { timeout: 40000 }) .should('be.visible'); }); -}; +});