Test/704 expand tfe flow path coverage around association and staking (#743)

* test: refactor functions for cypress commands

* test: lint changes

* test: setting tweak to prevent race condition

* test: lint

* test: refactor functions and locators

* test: lint

* test: tweak on function locations

* test: lint
This commit is contained in:
AndyWhiteVega 2022-07-12 14:43:04 +01:00 committed by GitHub
parent ed03a5d0c5
commit 74bb4b9bf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 297 additions and 282 deletions

View File

@ -1,31 +1,28 @@
/// <reference types="cypress" /> const stakingPageLink = '[href="/staking"]';
import navigation from '../../locators/navigation.locators'; const pageSpinner = 'splash-loader';
import staking from '../../locators/staking.locators'; const menuBar = 'nav';
import vegaWallet from '../../locators/wallet-vega.locators'; const validatorList = '[data-testid="node-list-item-name"]';
import '../../support/staking.functions'; const removeStakeRadioButton = '[data-testid="remove-stake-radio"]';
import '../../support/wallet-vega.functions'; const tokenAmountInputBox = '[data-testid="token-amount-input"]';
import '../../support/wallet-eth.functions'; const tokenSubmitButton = '[data-testid="token-input-submit-button"]';
import '../../support/wallet-teardown.functions'; const stakeNextEpochValue = '[data-testid="stake-next-epoch"]';
const vegaWalletPublicKeyShort = Cypress.env('vegaWalletPublicKeyShort'); const vegaWalletPublicKeyShort = Cypress.env('vegaWalletPublicKeyShort');
const vegaWalletContainer = '[data-testid="vega-wallet"]';
context('Staking Flow - with eth and vega wallets connected', function () { context('Staking Flow - with eth and vega wallets connected', function () {
before('visit staking tab and connect vega wallet', function () { before('visit staking tab and connect vega wallet', function () {
cy.vega_wallet_import(); cy.vega_wallet_import();
cy.visit('/'); 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_connect();
cy.vega_wallet_set_specified_approval_amount('1000'); cy.vega_wallet_set_specified_approval_amount('1000');
cy.reload(); cy.reload();
cy.get(navigation.section, { timeout: 20000 }).should('be.visible'); cy.get(menuBar, { timeout: 20000 }).should('be.visible');
cy.ethereum_wallet_connect(); cy.ethereum_wallet_connect();
cy.get(navigation.staking).first().click(); cy.get(stakingPageLink).first().click();
cy.get(navigation.spinner, { timeout: 20000 }).should('not.exist'); cy.get(pageSpinner, { timeout: 20000 }).should('not.exist');
cy.get(staking.validatorNames).first().invoke('text').as('validatorName'); cy.get(validatorList).first().invoke('text').as('validatorName');
cy.get(staking.validatorNames) cy.get(validatorList).last().invoke('text').as('otherValidatorName');
.last()
.invoke('text')
.as('otherValidatorName');
}); });
describe('Eth wallet - contains VEGA tokens', function () { 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', 'teardown wallet & drill into a specific validator',
function () { function () {
cy.vega_wallet_teardown(); 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('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_add_stake('2');
cy.vega_wallet_check_validator_stake_next_epoch_value_is( 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.staking_page_associate_tokens('5');
cy.vega_wallet_check_unstaked_value_is('5.000000000000000000'); cy.vega_wallet_check_unstaked_value_is('5.000000000000000000');
cy.get('button').contains('Select a validator to nominate').click(); 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_add_stake('2');
cy.vega_wallet_check_validator_staked_value_is( cy.vega_wallet_check_validator_staked_value_is(
this.validatorName, this.validatorName,
'2.000000000000000000' '2.000000000000000000'
); );
cy.get(navigation.staking).first().click(); cy.get(stakingPageLink).first().click();
cy.get(staking.validatorNames).contains(this.otherValidatorName).click(); cy.get(validatorList).contains(this.otherValidatorName).click();
cy.staking_validator_page_add_stake('1'); cy.staking_validator_page_add_stake('1');
cy.vega_wallet_check_validator_staked_value_is( cy.vega_wallet_check_validator_staked_value_is(
this.otherValidatorName, 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.vega_wallet_check_unstaked_value_is('4.000000000000000000');
cy.get('button').contains('Select a validator to nominate').click(); 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_add_stake('3');
cy.staking_validator_page_check_stake_next_epoch_value('3.0'); 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.vega_wallet_check_unstaked_value_is('1.000000000000000000');
cy.get(navigation.staking).first().click(); cy.get(stakingPageLink).first().click();
cy.get(staking.validatorNames).contains(this.validatorName).click(); cy.get(validatorList).contains(this.validatorName).click();
cy.staking_validator_page_removeStake('1'); cy.staking_validator_page_removeStake('1');
cy.staking_validator_page_check_stake_next_epoch_value('2.0'); 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.vega_wallet_check_unstaked_value_is('3.000000000000000000');
cy.get('button').contains('Select a validator to nominate').click(); 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.staking_validator_page_add_stake('1');
cy.vega_wallet_check_validator_stake_next_epoch_value_is( 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.vega_wallet_check_unstaked_value_is('2.000000000000000000');
cy.get(navigation.staking).first().click(); cy.get(stakingPageLink).first().click();
cy.get(staking.validatorNames).contains(this.validatorName).click(); cy.get(validatorList).contains(this.validatorName).click();
cy.staking_validator_page_removeStake('1'); cy.staking_validator_page_removeStake('1');
cy.staking_validator_page_check_stake_next_epoch_value('0.0'); 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.vega_wallet_check_unstaked_value_is('3.000000000000000000');
cy.get('button').contains('Select a validator to nominate').click(); 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_add_stake('2');
cy.staking_validator_page_check_stake_next_epoch_value('2.0'); 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.vega_wallet_check_unstaked_value_is('1.000000000000000000');
cy.get(navigation.staking).first().click(); cy.get(stakingPageLink).first().click();
cy.get(staking.validatorNames).contains(this.validatorName).click(); cy.get(validatorList).contains(this.validatorName).click();
cy.get(staking.removeStakeRadioButton).click({ force: true }); cy.get(removeStakeRadioButton).click({ force: true });
cy.get(staking.tokenAmountInput).type('-0.1'); cy.get(tokenAmountInputBox).type('-0.1');
cy.contains('Waiting for next epoch to start', { timeout: 10000 }); cy.contains('Waiting for next epoch to start', { timeout: 10000 });
cy.get(staking.tokenInputSubmit) cy.get(tokenSubmitButton)
.should('be.disabled', { timeout: 8000 }) .should('be.disabled', { timeout: 8000 })
.and('contain', `Remove -0.1 $VEGA tokens at the end of epoch`) .and('contain', `Remove -0.1 $VEGA tokens at the end of epoch`)
.and('be.visible'); .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.vega_wallet_check_unstaked_value_is('3.000000000000000000');
cy.get('button').contains('Select a validator to nominate').click(); 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_add_stake('2');
cy.staking_validator_page_check_stake_next_epoch_value('2.0'); 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.vega_wallet_check_unstaked_value_is('1.000000000000000000');
cy.get(navigation.staking).first().click(); cy.get(stakingPageLink).first().click();
cy.get(staking.validatorNames).contains(this.validatorName).click(); cy.get(validatorList).contains(this.validatorName).click();
cy.get(staking.removeStakeRadioButton).click({ force: true }); cy.get(removeStakeRadioButton).click({ force: true });
cy.get(staking.tokenAmountInput).type(4); cy.get(tokenAmountInputBox).type(4);
cy.contains('Waiting for next epoch to start', { timeout: 10000 }); cy.contains('Waiting for next epoch to start', { timeout: 10000 });
cy.get(staking.tokenInputSubmit) cy.get(tokenSubmitButton)
.should('be.disabled', { timeout: 8000 }) .should('be.disabled', { timeout: 8000 })
.and('contain', `Remove 4 $VEGA tokens at the end of epoch`) .and('contain', `Remove 4 $VEGA tokens at the end of epoch`)
.and('be.visible'); .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.vega_wallet_check_unstaked_value_is('3.000000000000000000');
cy.get('button').contains('Select a validator to nominate').click(); 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_add_stake('2');
cy.vega_wallet_check_unstaked_value_is('1.000000000000000000'); 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, this.validatorName,
'2.000000000000000000' '2.000000000000000000'
); );
cy.get(navigation.staking).first().click(); cy.get(stakingPageLink).first().click();
cy.staking_page_disassociate_all_tokens(); cy.staking_page_disassociate_all_tokens();
cy.ethereum_wallet_check_associated_vega_key_is_no_longer_showing( cy.ethereum_wallet_check_associated_vega_key_is_no_longer_showing(
vegaWalletPublicKeyShort 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.vega_wallet_check_unstaked_value_is('3.000000000000000000');
cy.get('button').contains('Select a validator to nominate').click(); 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_add_stake('2');
cy.vega_wallet_check_unstaked_value_is('1.000000000000000000'); 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, this.validatorName,
'2.000000000000000000' '2.000000000000000000'
); );
cy.get(navigation.staking).first().click(); cy.get(stakingPageLink).first().click();
cy.staking_page_disassociate_tokens('1'); cy.staking_page_disassociate_tokens('1');
cy.ethereum_wallet_check_associated_value_is('2.0'); cy.ethereum_wallet_check_associated_value_is('2.0');
cy.vega_wallet_check_associated_value_is('2.000000000000000000'); 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) => { Cypress.Commands.add(
cy.highlight( 'staking_validator_page_check_stake_next_epoch_value',
`Checking Staking Page - Validator Stake Next Epoch Value is ${expectedVal}` (expectedVal) => {
); cy.highlight(
cy.get(staking.stakeNextEpochValue, { timeout: 10000 }) `Checking Staking Page - Validator Stake Next Epoch Value is ${expectedVal}`
.contains(expectedVal, { timeout: 10000 }) );
.should('be.visible'); cy.get(stakeNextEpochValue, { timeout: 10000 })
}; .contains(expectedVal, { timeout: 10000 })
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 })
.should('be.visible'); .should('be.visible');
}); }
}; );
cy.vega_wallet_check_validator_stake_this_epoch_value_is = ( Cypress.Commands.add(
validatorName, 'staking_validator_page_check_stake_this_epoch_value',
expectedVal (expectedVal) => {
) => { cy.highlight(
cy.highlight( `Checking Staking Page - Validator Stake This Epoch Value is ${expectedVal}`
`Checking vega wallet - Stake This Epoch Value for ${validatorName} is ${expectedVal}` );
); cy.get(stakeNextEpochValue, { timeout: 10000 })
cy.get(vegaWallet.walletContainer).within(() => { .contains(expectedVal, { timeout: 10000 })
cy.contains(`${validatorName} (This Epoch)`, { timeout: 40000 })
.siblings()
.contains(expectedVal, { timeout: 40000 })
.should('be.visible'); .should('be.visible');
}); }
}; );
cy.vega_wallet_check_validator_no_longer_showing = (validatorName) => { Cypress.Commands.add(
cy.highlight( 'vega_wallet_check_validator_stake_next_epoch_value_is',
`Checking Validator and therefore stake removed for ${validatorName}` (validatorName, expectedVal) => {
); cy.highlight(
cy.get(vegaWallet.walletContainer).within(() => { `Checking vega wallet - Stake Next Epoch Value for ${validatorName} is ${expectedVal}`
cy.contains(`${validatorName}`, { timeout: 40000 }).should('not.exist', { );
timeout: 40000, 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 = ( Cypress.Commands.add(
validatorName, 'vega_wallet_check_validator_stake_this_epoch_value_is',
expectedVal (validatorName, expectedVal) => {
) => { cy.highlight(
cy.highlight( `Checking vega wallet - Stake This Epoch Value for ${validatorName} is ${expectedVal}`
`Checking Validator Stake Value for ${validatorName} is ${expectedVal}` );
); cy.get(vegaWalletContainer).within(() => {
cy.get(vegaWallet.walletContainer).within(() => { cy.contains(`${validatorName} (This Epoch)`, { timeout: 40000 })
cy.contains(`${validatorName}`, { timeout: 40000 }) .siblings()
.siblings() .contains(expectedVal, { timeout: 40000 })
.contains(expectedVal, { timeout: 40000 }) .should('be.visible');
.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');
});
}
);
}); });

View File

@ -1,12 +1,7 @@
/// <reference types="cypress" /> const stakingPageLink = '[href="/staking"]';
import navigation from '../../locators/navigation.locators'; const pageSpinner = 'splash-loader';
import staking from '../../locators/staking.locators'; const menuBar = 'nav';
import ethWallet from '../../locators/wallet-eth.locators'; const validatorList = '[data-testid="node-list-item-name"]';
import '../../support/staking.functions';
import '../../support/wallet-vega.functions';
import '../../support/wallet-eth.functions';
import '../../support/wallet-teardown.functions';
const vegaWalletPublicKeyShort = Cypress.env('vegaWalletPublicKeyShort'); const vegaWalletPublicKeyShort = Cypress.env('vegaWalletPublicKeyShort');
context( context(
@ -15,15 +10,15 @@ context(
before('visit staking tab and connect vega wallet', function () { before('visit staking tab and connect vega wallet', function () {
cy.vega_wallet_import(); cy.vega_wallet_import();
cy.visit('/'); 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_connect();
cy.vega_wallet_set_specified_approval_amount('1000'); cy.vega_wallet_set_specified_approval_amount('1000');
cy.reload(); cy.reload();
cy.get(navigation.section, { timeout: 20000 }).should('be.visible'); cy.get(menuBar, { timeout: 20000 }).should('be.visible');
cy.ethereum_wallet_connect(); cy.ethereum_wallet_connect();
cy.get(navigation.staking).first().click(); cy.get(stakingPageLink).first().click();
cy.get(navigation.spinner, { timeout: 20000 }).should('not.exist'); cy.get(pageSpinner, { timeout: 20000 }).should('not.exist');
cy.get(staking.validatorNames).first().invoke('text').as('validatorName'); cy.get(validatorList).first().invoke('text').as('validatorName');
}); });
describe('Eth wallet - contains VEGA tokens', function () { describe('Eth wallet - contains VEGA tokens', function () {
@ -31,12 +26,12 @@ context(
'teardown wallet & drill into a specific validator', 'teardown wallet & drill into a specific validator',
function () { function () {
cy.vega_wallet_teardown(); cy.vega_wallet_teardown();
cy.get(navigation.staking).first().click(); cy.get(stakingPageLink).first().click();
cy.get(navigation.spinner, { timeout: 20000 }).should('not.exist'); 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.staking_page_associate_tokens('2');
cy.ethereum_wallet_check_associated_vega_key_value_is( cy.ethereum_wallet_check_associated_vega_key_value_is(
vegaWalletPublicKeyShort, vegaWalletPublicKeyShort,
@ -47,7 +42,7 @@ context(
cy.vega_wallet_check_unstaked_value_is('2.000000000000000000'); 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.staking_page_associate_tokens('2');
cy.ethereum_wallet_check_associated_vega_key_value_is( cy.ethereum_wallet_check_associated_vega_key_value_is(
vegaWalletPublicKeyShort, vegaWalletPublicKeyShort,
@ -64,24 +59,6 @@ context(
cy.vega_wallet_check_associated_value_is('1.000000000000000000'); 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 () { it('Able to associate more tokens than the approved amount of 1000 - requires re-approval', function () {
cy.staking_page_associate_tokens('1001', true); cy.staking_page_associate_tokens('1001', true);
cy.ethereum_wallet_check_associated_vega_key_value_is( cy.ethereum_wallet_check_associated_vega_key_value_is(

View File

@ -0,0 +1,7 @@
Cypress.Commands.add(
'convertTokenValueToNumber',
{ prevSubject: true },
(subject) => {
return parseFloat(subject.replace(/,/g, ''));
}
);

View File

@ -1,5 +1,11 @@
import '@vegaprotocol/cypress'; 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 // Hide fetch/XHR requests - They create a lot of noise in command log
const app = window.top; const app = window.top;
if (!app.document.head.querySelector('[data-hide-command-log-request]')) { if (!app.document.head.querySelector('[data-hide-command-log-request]')) {

View File

@ -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.highlight(`Adding a stake of ${stake}`);
cy.get(staking.addStakeRadioButton).click({ force: true }); cy.get(addStakeRadioButton).click({ force: true });
cy.get(staking.tokenAmountInput).type(stake); cy.get(tokenAmountInputBox).type(stake);
cy.contains('Waiting for next epoch to start', { timeout: 10000 }); cy.wait_for_begining_of_epoch();
cy.get(staking.tokenInputSubmit, { timeout: 8000 }) cy.get(tokenSubmitButton, { timeout: 8000 })
.should('be.enabled') .should('be.enabled')
.and('contain', `Add ${stake} $VEGA tokens`) .and('contain', `Add ${stake} $VEGA tokens`)
.and('be.visible') .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', 'At the beginning of the next epoch your $VEGA will be nominated to the validator',
{ timeout: 20000 } { timeout: 20000 }
).should('be.visible'); ).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.highlight(`Removing a stake of ${stake}`);
cy.get(staking.removeStakeRadioButton).click({ force: true }); cy.get(removeStakeRadioButton).click({ force: true });
cy.get(staking.tokenAmountInput).type(stake); cy.get(tokenAmountInputBox).type(stake);
cy.contains('Waiting for next epoch to start', { timeout: 10000 }); cy.wait_for_begining_of_epoch();
cy.get(staking.tokenInputSubmit) cy.get(tokenSubmitButton)
.should('be.enabled', { timeout: 8000 }) .should('be.enabled', { timeout: 8000 })
.and('contain', `Remove ${stake} $VEGA tokens at the end of epoch`) .and('contain', `Remove ${stake} $VEGA tokens at the end of epoch`)
.and('be.visible') .and('be.visible')
@ -29,53 +45,52 @@ cy.staking_validator_page_removeStake = (stake) => {
cy.contains(`${stake} $VEGA has been removed from validator`).should( cy.contains(`${stake} $VEGA has been removed from validator`).should(
'be.visible' 'be.visible'
); );
}; });
cy.staking_page_associate_tokens = (amount, approve = false) => { Cypress.Commands.add(
cy.highlight(`Associating ${amount} tokens`); 'staking_page_associate_tokens',
cy.get(staking.associateButton).click(); (amount, approve = false) => {
cy.get(staking.stakeAssociateWalletRadio, { timeout: 30000 }).click(); cy.highlight(`Associating ${amount} tokens`);
cy.get(staking.tokenAmountInput, { timeout: 10000 }).type(amount); cy.get(ethWalletAssociateButton).first().click();
if (approve) { cy.get(associateWalletRadioButton, { timeout: 30000 }).click();
cy.get(staking.tokenInputApprove, { timeout: 40000 }) cy.get(tokenAmountInputBox, { timeout: 10000 }).type(amount);
.should('be.enabled') if (approve) {
.click(); cy.get(tokenInputApprove, { timeout: 40000 })
cy.contains('Approve $VEGA Tokens for staking on Vega').should( .should('be.enabled')
'be.visible' .click();
); cy.contains('Approve $VEGA Tokens for staking on Vega').should(
cy.contains('Approve $VEGA Tokens for staking on Vega', { 'be.visible'
timeout: 40000, );
}).should('not.exist'); 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.highlight(`Disassociating ${amount} tokens via Staking Page`);
cy.get(staking.disassociateButton).click(); cy.get(ethWalletDissociateButton).first().click();
cy.get(staking.stakeAssociateWalletRadio, { timeout: 30000 }).click(); cy.get(associateWalletRadioButton, { timeout: 30000 }).click();
cy.get(staking.tokenAmountInput, { timeout: 10000 }).type(amount); cy.get(tokenAmountInputBox, { timeout: 10000 }).type(amount);
cy.get(staking.tokenInputSubmit, { timeout: 40000 }) cy.get(tokenSubmitButton, { timeout: 40000 }).should('be.enabled').click();
.should('be.enabled')
.click();
cy.contains(`${amount} $VEGA tokens have been returned to Ethereum wallet`, { cy.contains(`${amount} $VEGA tokens have been returned to Ethereum wallet`, {
timeout: 60000, timeout: 60000,
}).should('be.visible'); }).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.highlight(`Disassociating all tokens via Staking Page`);
cy.get(staking.disassociateButton).click(); cy.get(ethWalletDissociateButton).first().click();
cy.get(staking.stakeAssociateWalletRadio, { timeout: 20000 }).click(); cy.get(associateWalletRadioButton, { timeout: 20000 }).click();
cy.get(staking.stakeMaximumTokens, { timeout: 60000 }).click(); cy.get(stakeMaximumTokens, { timeout: 60000 }).click();
cy.get(staking.tokenInputSubmit, { timeout: 10000 }).click(); cy.get(tokenSubmitButton, { timeout: 10000 }).click();
cy.contains('$VEGA tokens have been returned to Ethereum wallet', { cy.contains('$VEGA tokens have been returned to Ethereum wallet', {
timeout: 60000, timeout: 60000,
}).should('be.visible'); }).should('be.visible');
}; });

View File

@ -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.highlight('Connecting Eth Wallet');
cy.get(ethWallet.connectToEthButton).within(() => { cy.get(connectToEthButton).within(() => {
cy.contains('Connect Ethereum wallet to associate $VEGA') cy.contains('Connect Ethereum wallet to associate $VEGA')
.should('be.visible') .should('be.visible')
.click(); .click();
}); });
cy.get(ethWallet.connectorCapsule).click(); cy.get(capsuleWalletConnectButton).click();
cy.get(ethWallet.connectorCapsule, { timeout: 60000 }).should('not.exist'); cy.get(capsuleWalletConnectButton, { timeout: 60000 }).should('not.exist');
cy.get(ethWallet.walletContainer).within(() => { cy.get(ethWalletContainer).within(() => {
// this check is required since it ensures the wallet is fully (not partially) loaded // this check is required since it ensures the wallet is fully (not partially) loaded
cy.contains('Locked', { timeout: 15000 }).should('be.visible'); 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( Cypress.Commands.add(
'convertTokenValueToNumber', 'ethereum_wallet_check_associated_value_is',
{ prevSubject: true }, (expectedVal) => {
(subject) => { cy.highlight(`Checking Eth Wallet - Associated Value is ${expectedVal}`);
return parseFloat(subject.replace(/,/g, '')); 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');
});
} }
); );

View File

@ -64,27 +64,30 @@ Cypress.Commands.add(
} }
); );
cy.vega_wallet_teardown_staking = (stakingBridgeContract) => { Cypress.Commands.add(
cy.highlight('Tearing down staking tokens from vega wallet if present'); 'vega_wallet_teardown_staking',
cy.wrap( (stakingBridgeContract) => {
stakingBridgeContract.stakeBalance(ethWalletPubKey, vegaWalletPubKey), cy.highlight('Tearing down staking tokens from vega wallet if present');
{ cy.wrap(
timeout: transactionTimeout, stakingBridgeContract.stakeBalance(ethWalletPubKey, vegaWalletPubKey),
log: false, {
} timeout: transactionTimeout,
).then((stake_amount) => { log: false,
if (String(stake_amount) != '0') { }
cy.wrap( ).then((stake_amount) => {
stakingBridgeContract.removeStake(stake_amount, vegaWalletPubKey), if (String(stake_amount) != '0') {
{ timeout: transactionTimeout, log: false } cy.wrap(
).then((tx) => { stakingBridgeContract.removeStake(stake_amount, vegaWalletPubKey),
cy.wait_for_transaction(tx); { 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.highlight('Tearing down vesting tokens from vega wallet if present');
cy.wrap(vestingContract.stakeBalance(ethWalletPubKey, vegaWalletPubKey), { cy.wrap(vestingContract.stakeBalance(ethWalletPubKey, vegaWalletPubKey), {
timeout: transactionTimeout, 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 }); cy.wrap(tx.wait(1).catch(cy.log), { timeout: transactionTimeout });
}; });

View File

@ -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 vegaWalletName = Cypress.env('vegaWalletName');
const vegaWalletLocation = Cypress.env('vegaWalletLocation'); const vegaWalletLocation = Cypress.env('vegaWalletLocation');
const vegaWalletPassphrase = Cypress.env('vegaWalletPassphrase'); const vegaWalletPassphrase = Cypress.env('vegaWalletPassphrase');
cy.vega_wallet_import = () => { Cypress.Commands.add('vega_wallet_import', () => {
cy.highlight(`Importing Vega Wallet ${vegaWalletName}`); cy.highlight(`Importing Vega Wallet ${vegaWalletName}`);
cy.exec(`vegawallet init -f --home ${vegaWalletLocation}`); cy.exec(`vegawallet init -f --home ${vegaWalletLocation}`);
cy.exec( cy.exec(
@ -14,11 +14,11 @@ cy.vega_wallet_import = () => {
cy.exec( cy.exec(
`vegawallet service run --network DV --automatic-consent --home ${vegaWalletLocation}` `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.highlight('Connecting Vega Wallet');
cy.get(vegaWallet.walletContainer).within(() => { cy.get(vegaWalletContainer).within(() => {
cy.get('button') cy.get('button')
.contains('Connect Vega wallet to use associated $VEGA') .contains('Connect Vega wallet to use associated $VEGA')
.should('be.enabled') .should('be.enabled')
@ -26,31 +26,31 @@ cy.vega_wallet_connect = () => {
.click({ force: true }); .click({ force: true });
}); });
cy.get('button').contains('rest provider').click(); cy.get('button').contains('rest provider').click();
cy.get(vegaWallet.connectRestForm).within(() => { cy.get(restConnectorForm).within(() => {
cy.get(vegaWallet.name).click().type(vegaWalletName); cy.get('#wallet').click().type(vegaWalletName);
cy.get(vegaWallet.passphrase).click().type(vegaWalletPassphrase); cy.get('#passphrase').click().type(vegaWalletPassphrase);
cy.get('button').contains('Connect').click(); cy.get('button').contains('Connect').click();
}); });
cy.contains(`${vegaWalletName} key`, { timeout: 20000 }).should('be.visible'); 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.highlight(`Checking vega wallet - Unstaked Value is ${expectedVal}`);
cy.get(vegaWallet.walletContainer).within(() => { cy.get(vegaWalletContainer).within(() => {
cy.contains('Unstaked', { timeout: 40000 }) cy.contains('Unstaked', { timeout: 40000 })
.siblings() .siblings()
.contains(expectedVal, { timeout: 40000 }) .contains(expectedVal, { timeout: 40000 })
.should('be.visible'); .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.highlight(`Checking vega wallet - Associated Value is ${expectedVal}`);
cy.get(vegaWallet.walletContainer).within(() => { cy.get(vegaWalletContainer).within(() => {
cy.contains('Associated', { timeout: 40000 }) cy.contains('Associated', { timeout: 40000 })
.parent() .parent()
.siblings() .siblings()
.contains(expectedVal, { timeout: 40000 }) .contains(expectedVal, { timeout: 40000 })
.should('be.visible'); .should('be.visible');
}); });
}; });