diff --git a/apps/token-e2e/src/integration/flow/staking.add-stake.test.js b/apps/token-e2e/src/integration/flow/staking.add-stake.test.js index cd768a0de..e7f213fc5 100644 --- a/apps/token-e2e/src/integration/flow/staking.add-stake.test.js +++ b/apps/token-e2e/src/integration/flow/staking.add-stake.test.js @@ -82,7 +82,7 @@ context('Staking Tab - with vega wallet connected', function () { }); it('Check - wallet - next epoch amount - updates balance for validator', function () { - cy.walletVega_checkValidator_StakeNextEpochValue( + cy.walletVega_checkValidator_StakeNextEpochValue_is( this.validatorName, parseFloat(this.initialStakeNextEpoch) + 0.1 ); diff --git a/apps/token-e2e/src/integration/flow/staking.rem-stake.test.js b/apps/token-e2e/src/integration/flow/staking.rem-stake.test.js index fb1adcd83..809951a92 100644 --- a/apps/token-e2e/src/integration/flow/staking.rem-stake.test.js +++ b/apps/token-e2e/src/integration/flow/staking.rem-stake.test.js @@ -85,7 +85,7 @@ context('Staking Tab - with vega wallet connected', function () { }); it('Check - wallet - next epoch amount - updates balance for validator', function () { - cy.walletVega_checkValidator_StakeNextEpochValue( + cy.walletVega_checkValidator_StakeNextEpochValue_is( this.validatorName, parseFloat(this.initialStakeNextEpoch) - 0.1 ); diff --git a/apps/token-e2e/src/integration/flow/staking.test.js b/apps/token-e2e/src/integration/flow/staking.test.js index 826176830..3380c1eec 100644 --- a/apps/token-e2e/src/integration/flow/staking.test.js +++ b/apps/token-e2e/src/integration/flow/staking.test.js @@ -11,29 +11,17 @@ context('Staking Tab - with vega wallet connected', function () { cy.get(navigation.staking).first().click(); cy.walletVega_connect(); cy.get(navigation.spinner, { timeout: 20000 }).should('not.exist'); - cy.walletVega_getUnstakedAmount().as('initialUnstakedBalance'); cy.stakingPage_getValidatorNamesSorted().as('validatorNames'); }); describe('Vega wallet - contains VEGA tokens', function () { - before('ensure environment fit for test', function () { - assert.isAtLeast( - parseInt(this.initialUnstakedBalance), - 0.1, - 'Checking we have at least 0.1 unstaked vega to play with' - ); - assert.isAtLeast( - this.validatorNames.length, - 2, - 'Checking we have at least 2 validators' - ); - // Choose the first validator from top of sorted list - this.validatorName = this.validatorNames[0]; - }); - - before('drill into a specific validator - and note values', function () { + beforeEach('drill into a specific validator - and note values', function () { + + cy.get(navigation.staking).first().click(); + cy.get(navigation.spinner, { timeout: 20000 }).should('not.exist'); cy.get(staking.validatorNames).contains(this.validatorNames[0]).click(); cy.contains('Manage your stake').should('be.visible'); + cy.walletVega_getUnstakedAmount().as('initialUnstakedBalance'); cy.get(staking.stakeNextEpochValue) .invoke('text') .as('initialStakeNextEpoch'); @@ -47,44 +35,152 @@ context('Staking Tab - with vega wallet connected', function () { .as('initialValidatorStake'); }); - describe('Flow - Able to stake against a validator', function () { - it('Able to stake against a validator', function () { - // Check - ability to fill in fields and request a stake of 0.1 tokens - cy.get(staking.addStakeRadioButton).click({ force: true }); - cy.get(staking.tokenAmountInput).type('0.1'); - // cy.staking_waitForEpochRemainingSeconds(5); - cy.get('button').contains('Add 0.1 $VEGA tokens').click(); + it('Able to stake against a validator', function () { + // Check - ability to fill in fields and request a stake of 0.1 tokens + cy.get(staking.addStakeRadioButton).click({ force: true }); + cy.get(staking.tokenAmountInput).type('0.1'); + // cy.staking_waitForEpochRemainingSeconds(5); + cy.get('button').contains('Add 0.1 $VEGA tokens').click(); - // Check - relevant successfull feedback provided after staking - Note: Wallet auto approves at this stage - cy.contains( - `Adding 0.1 $VEGA to validator ${this.validatorNames[0]}` - ).should('be.visible'); - cy.contains( - 'Waiting for confirmation that your change in nomination has been received' - ).should('be.visible'); - cy.contains( - 'Waiting for confirmation that your change in nomination has been received', - { timeout: 120000 } - ).should('not.exist'); - cy.contains( - 'At the beginning of the next epoch your $VEGA will be nominated to the validator' - ); + // Check - relevant successfull feedback provided after staking - Note: Wallet auto approves at this stage + cy.contains( + `Adding 0.1 $VEGA to validator ${this.validatorNames[0]}` + ).should('be.visible'); + cy.contains( + 'Waiting for confirmation that your change in nomination has been received' + ).should('be.visible'); + cy.contains( + 'Waiting for confirmation that your change in nomination has been received', + { timeout: 120000 } + ).should('not.exist'); + cy.contains( + 'At the beginning of the next epoch your $VEGA will be nominated to the validator' + ); - // Check - staking page - stake on node (next epoch) - updates to reflect stake - cy.stakingValidatorPage_check_stakeNextEpochValue( - parseFloat(this.initialStakeNextEpoch) + 0.1 - ); + // Check - staking page - stake on node (next epoch) - updates to reflect stake + cy.stakingValidatorPage_check_stakeNextEpochValue( + parseFloat(this.initialStakeNextEpoch) + 0.1 + ); - //Check - wallet staked amount - updates balance for validator - cy.walletVega_checkValidator_StakeNextEpochValue( - this.validatorName, - parseFloat(this.initialStakeNextEpoch) + 0.1 - ); + // Check - wallet staked amount - updates balance for validator + cy.walletVega_checkValidator_StakeNextEpochValue_is( + this.validatorNames[0], + parseFloat(this.initialStakeNextEpoch) + 0.1 + ); - //Check - wallet unstaked amount - updates balance - Note: Skipping until capsule can enable this test - // cy.walletVega_check_UnstakedValue_is( - // parseFloat(this.initialUnstakedBalance) - 0.1); - }); + //Check - wallet unstaked amount - updates balance - Note: Skipping until capsule can enable this test + // cy.walletVega_check_UnstakedValue_is( + // parseFloat(this.initialUnstakedBalance) - 0.1); + }); + + it.skip('Able to stake maximum tokens against a validator', function () { + // Check - ability to fill in fields and request a stake of 0.1 tokens + cy.get(staking.addStakeRadioButton).click({ force: true }); + cy.get(staking.stakeMaximumTokens).click(); + // cy.staking_waitForEpochRemainingSeconds(5); + cy.get('button').contains(`Add ${parseFloat(this.initialUnstakedBalance)} $VEGA tokens`).click(); + + // Check - relevant successfull feedback provided after staking - Note: Wallet auto approves at this stage + cy.contains( + `Adding 0.1 $VEGA to validator ${this.validatorNames[0]}` + ).should('be.visible'); + cy.contains( + 'Waiting for confirmation that your change in nomination has been received' + ).should('be.visible'); + cy.contains( + 'Waiting for confirmation that your change in nomination has been received', + { timeout: 120000 } + ).should('not.exist'); + cy.contains( + 'At the beginning of the next epoch your $VEGA will be nominated to the validator' + ); + + // Check - staking page - stake on node (next epoch) - updates to reflect stake + cy.stakingValidatorPage_check_stakeNextEpochValue( + parseFloat(this.initialStakeNextEpoch) + 0.1 + ); + + // Check - wallet staked amount - updates balance for validator + cy.walletVega_checkValidator_StakeNextEpochValue_is( + this.validatorNames[0], + parseFloat(this.initialStakeNextEpoch) + 0.1 + ); + + //Check - wallet unstaked amount - updates balance - Note: Skipping until capsule can enable this test + // cy.walletVega_check_UnstakedValue_is( + // parseFloat(this.initialUnstakedBalance) - 0.1); + }); + + it('Able to remove stake against a validator', function () { + // Check - ability to fill in fields and request a stake of 0.1 tokens + cy.get(staking.removeStakeRadioButton).click({ force: true }); + cy.get(staking.tokenAmountInput).type('0.1'); + // cy.staking_waitForEpochRemainingSeconds(5); + cy.get('button').contains('Remove 0.1 $VEGA tokens').click(); + + // Check - relevant successfull feedback provided after staking + // Wallet auto approves at this stage + cy.contains( + `Removing 0.1 $VEGA from validator ${this.validatorNames[0]}` + ).should('be.visible'); + cy.contains( + 'Waiting for confirmation that your change in nomination has been received' + ).should('be.visible'); + cy.contains( + 'Waiting for confirmation that your change in nomination has been received', + { timeout: 120000 } + ).should('not.exist'); + cy.contains( + `0.1 $VEGA has been removed from validator ${this.validatorNames[0]}` + ); + + // Check - staking page - stake on node (next epoch) - updates to reflect stake + cy.stakingValidatorPage_check_stakeNextEpochValue( + parseFloat(this.initialStakeNextEpoch) - 0.1 + ); + + cy.get(staking.stakeThisEpochValue) + .invoke('text').then(stakeThisEpochValue => { + cy.get(staking.stakeNextEpochValue) + .invoke('text').then(stakeNextEpochValue => { + if (stakeNextEpochValue == stakeThisEpochValue) + {cy.log('nothing')} + else{ + cy.walletVega_checkValidator_StakeNextEpochValue_is( + this.validatorNames[0], + parseFloat(this.initialStakeNextEpoch) + 0.1 + ); + } + }) + }) + + // Check - wallet - next epoch amount - updates balance for validator + // cy.walletVega_checkValidator_StakeNextEpochValue_is( + // this.validatorNames[0], + // parseFloat(this.initialStakeNextEpoch) - 0.1 + // ); + + // Check - wallet - unstaked amount - updates balance' + // Skipping until capsule can enable this test + // cy.walletVega_check_UnstakedValue_is( + // parseFloat(this.initialUnstakedBalance) - 0.1 + // ); + }); + + it('Unable to remove a stake with a negative value for a validator', function () { + // Check - ability to fill in fields and request a stake of 0.1 tokens + cy.get(staking.removeStakeRadioButton).click({ force: true }); + cy.get(staking.tokenAmountInput).type('-0.1'); + // cy.staking_waitForEpochRemainingSeconds(5); + cy.get('button').contains('Remove -0.1 $VEGA tokens at the end of epoch').should('be.disabled'); + }); + + it('Unable to remove a stake greater than staked amount next epoch for a validator', function () { + let amountToTry = this.initialStakeNextEpoch.slice(0, -1) + '1'; + cy.get(staking.removeStakeRadioButton).click({ force: true }); + cy.get(staking.tokenAmountInput).type(amountToTry); + // cy.staking_waitForEpochRemainingSeconds(5); + cy.get('button').contains(`Remove ${amountToTry} $VEGA tokens at the end of epoch`).should('be.disabled'); }); }); }); diff --git a/apps/token-e2e/src/locators/staking.locators.js b/apps/token-e2e/src/locators/staking.locators.js index 77964d149..438b04919 100644 --- a/apps/token-e2e/src/locators/staking.locators.js +++ b/apps/token-e2e/src/locators/staking.locators.js @@ -7,4 +7,5 @@ export default { stakedAmounts: '[data-testid="staked-validator-item"]', stakeNextEpochValue: '[data-testid="stake-next-epoch"]', stakeThisEpochValue: '[data-testid="stake-this-epoch"]', + stakeMaximumTokens: '[data-testid="token-amount-use-maximum"]' }; diff --git a/apps/token-e2e/src/support/wallet.functions.js b/apps/token-e2e/src/support/wallet.functions.js index 8d124017c..0d35d886e 100644 --- a/apps/token-e2e/src/support/wallet.functions.js +++ b/apps/token-e2e/src/support/wallet.functions.js @@ -31,9 +31,8 @@ Cypress.Commands.add('walletVega_getUnstakedAmount', function () { }); Cypress.Commands.add( - 'walletVega_checkValidator_StakeNextEpochValue', + 'walletVega_checkValidator_StakeNextEpochValue_is', function (validatorName, expectedVal) { - // need to check if validator is present first cy.get(wallet.vegawallet).within(() => { cy.contains(`${validatorName} (Next epoch)`) .siblings() @@ -45,7 +44,6 @@ Cypress.Commands.add( Cypress.Commands.add( 'walletVega_check_UnstakedValue_is', function (expectedVal) { - // need to check if validator is present first cy.get(wallet.vegawallet).within(() => { cy.contains(`Unstaked`) .siblings()