test: function Enhancements

This commit is contained in:
AndyWhiteVega 2022-06-23 23:42:35 +01:00
parent f0d1c1d15d
commit dcafcdcd8e
8 changed files with 94 additions and 100 deletions

11
apps/*/src/support/customCommands.d.ts vendored Normal file
View File

@ -0,0 +1,11 @@
declare namespace Cypress {
interface Chainable<Subject> {
stakingPage_getValidatorNamesSorted(): Chainable<any>
stakingValidatorPage_check_stakeNextEpochValue(expectedVal: any): Chainable<any>
staking_waitForEpochRemainingSeconds(secondsRemaining: any): Chainable<any>
walletVega_connect(): Chainable<any>
walletVega_getUnstakedAmount(): Chainable<any>
walletVega_checkValidator_StakeNextEpochValue(validatorName: any, expectedVal: any): Chainable<any>
walletVega_check_UnstakedValue_is(expectedVal: any): Chainable<any>
}
}

View File

@ -15,7 +15,7 @@ context('Staking Tab - with vega wallet connected', function () {
cy.stakingPage_getValidatorNamesSorted().as('validatorNames'); cy.stakingPage_getValidatorNamesSorted().as('validatorNames');
}); });
describe('vega wallet contains VEGA tokens', function () { describe('Vega wallet - contains VEGA tokens', function () {
before('ensure environment fit for test', function () { before('ensure environment fit for test', function () {
assert.isAtLeast( assert.isAtLeast(
parseInt(this.initialUnstakedBalance), parseInt(this.initialUnstakedBalance),
@ -27,14 +27,12 @@ context('Staking Tab - with vega wallet connected', function () {
2, 2,
'Checking we have at least 2 validators' 'Checking we have at least 2 validators'
); );
// Ensure we are not in last minute - as this adds flake // Choose the first validator from top of sorted list
cy.get(staking.epochEndingText) this.validatorName = this.validatorNames[0];
.contains('Next epoch in 1 minutes', { timeout: 65000 })
.should('not.exist');
}); });
before('drill into a specific validator - and note values', function () { before('drill into a specific validator - and note values', function () {
cy.get(staking.validatorNames).contains(this.validatorNames[0]).click(); cy.get(staking.validatorNames).contains(this.validatorName).click();
cy.contains('Manage your stake').should('be.visible'); cy.contains('Manage your stake').should('be.visible');
cy.get(staking.stakeNextEpochValue) cy.get(staking.stakeNextEpochValue)
.invoke('text') .invoke('text')
@ -49,17 +47,18 @@ context('Staking Tab - with vega wallet connected', function () {
.as('initialValidatorStake'); .as('initialValidatorStake');
}); });
describe('Able to stake against a validator', function () { describe('Flow - Able to stake against a validator', function () {
it('Check - ability to fill in fields and request a stake of 0.1 tokens', function () { before('Check - ability to fill in fields and request a stake of 0.1 tokens', function () {
cy.get(staking.addStakeRadioButton).click({ force: true }); cy.get(staking.addStakeRadioButton).click({ force: true });
cy.get(staking.tokenAmountInput).type('0.1'); cy.get(staking.tokenAmountInput).type('0.1');
// cy.staking_waitForEpochRemainingSeconds(5);
cy.get('button').contains('Add 0.1 $VEGA tokens').click(); cy.get('button').contains('Add 0.1 $VEGA tokens').click();
}); });
it('Check - relevant successfull feedback provided after staking', function () { it('Check - relevant successfull feedback provided after staking', function () {
// Wallet auto approves at this stage // Wallet auto approves at this stage
cy.contains( cy.contains(
`Adding 0.1 $VEGA to validator ${this.validatorNames[0]}` `Adding 0.1 $VEGA to validator ${this.validatorName}`
).should('be.visible'); ).should('be.visible');
cy.contains( cy.contains(
'Waiting for confirmation that your change in nomination has been received' 'Waiting for confirmation that your change in nomination has been received'
@ -74,33 +73,19 @@ context('Staking Tab - with vega wallet connected', function () {
}); });
it('Check - staking page - stake on node (next epoch) - updates to reflect stake', function () { it('Check - staking page - stake on node (next epoch) - updates to reflect stake', function () {
let expectedStakeNextEpochValue = cy.stakingValidatorPage_check_stakeNextEpochValue(
parseFloat(this.initialStakeNextEpoch) + 0.1; parseFloat(this.initialStakeNextEpoch) + 0.1);
cy.get(staking.stakeNextEpochValue, { timeout: 10000 }).contains(
expectedStakeNextEpochValue.toFixed(2),
{ timeout: 10000 }
);
}); });
it('Check - wallet - next epoch amount - updates balance for validator', function () { it('Check - wallet - next epoch amount - updates balance for validator', function () {
let expectedValStakeNextEpochValue = cy.walletVega_checkValidator_StakeNextEpochValue(
parseFloat(this.initialStakeNextEpoch) + 0.1; this.validatorName, parseFloat(this.initialStakeNextEpoch) + 0.1);
cy.walletVega_getNextEpochStakeForSpecifiedValidator(
this.validatorNames[0]
).then((actualNextEpochStake) => {
assert.equal(
parseFloat(actualNextEpochStake).toPrecision(12),
parseFloat(expectedValStakeNextEpochValue).toPrecision(12)
);
});
}); });
it.skip('Check - wallet - unstaked amount - updates balance', function () { it.skip('Check - wallet - unstaked amount - updates balance', function () {
// Skipping until capsule can enable this test // Skipping until capsule can enable this test
cy.walletVega_getUnstakedAmount().should( cy.walletVega_check_UnstakedValue_is(
'equal', parseFloat(this.initialUnstakedBalance) - 0.1);
this.initialUnstakedBalance - 0.1
);
}); });
}); });
}); });

View File

@ -15,21 +15,19 @@ context('Staking Tab - with vega wallet connected', function () {
cy.stakingPage_getValidatorNamesSorted().as('validatorNames'); cy.stakingPage_getValidatorNamesSorted().as('validatorNames');
}); });
describe('vega wallet contains VEGA tokens', function () { describe('Vega wallet - contains VEGA tokens', function () {
before('ensure environment fit for test', function () { before('ensure environment fit for test', function () {
assert.isAtLeast( assert.isAtLeast(
this.validatorNames.length, this.validatorNames.length,
2, 2,
'Checking we have at least 2 validators' 'Checking we have at least 2 validators'
); );
// Ensure we are not in last minute - as this adds flake // Choose the first validator from top of sorted list
cy.get(staking.epochEndingText) this.validatorName = this.validatorNames[0];
.contains('Next epoch in 1 minutes', { timeout: 65000 })
.should('not.exist');
}); });
before('drill into a specific validator - and note values', function () { before('drill into a specific validator - and note values', function () {
cy.get(staking.validatorNames).contains(this.validatorNames[0]).click(); cy.get(staking.validatorNames).contains(this.validatorName).click();
cy.contains('Manage your stake').should('be.visible'); cy.contains('Manage your stake').should('be.visible');
cy.get(staking.stakeNextEpochValue) cy.get(staking.stakeNextEpochValue)
.invoke('text') .invoke('text')
@ -44,26 +42,26 @@ context('Staking Tab - with vega wallet connected', function () {
.as('initialValidatorStake'); .as('initialValidatorStake');
}); });
describe('Able to remove a stake against a validator', function () { describe('Flow - Ability to remove a stake against a validator', function () {
it('Check - validator has tokens to remove', function () { before('Check - validator has tokens to remove', function () {
let tokensToRemove = parseFloat(this.initialStakeNextEpoch);
assert.isAtLeast( assert.isAtLeast(
tokensToRemove, parseFloat(this.initialStakeNextEpoch),
0.1, 0.1,
'Checking we have tokens to remove' 'Checking we have tokens to remove'
); );
}); });
it('Check - ability to fill in fields and request a stake of 0.1 tokens', function () { before('Check - ability to fill in fields and request a stake of 0.1 tokens', function () {
cy.get(staking.removeStakeRadioButton).click({ force: true }); cy.get(staking.removeStakeRadioButton).click({ force: true });
cy.get(staking.tokenAmountInput).type('0.1'); cy.get(staking.tokenAmountInput).type('0.1');
// cy.staking_waitForEpochRemainingSeconds(5);
cy.get('button').contains('Remove 0.1 $VEGA tokens').click(); cy.get('button').contains('Remove 0.1 $VEGA tokens').click();
}); });
it('Check - relevant successfull feedback provided after staking', function () { it('Check - relevant successfull feedback provided after staking', function () {
// Wallet auto approves at this stage // Wallet auto approves at this stage
cy.contains( cy.contains(
`Removing 0.1 $VEGA from validator ${this.validatorNames[0]}` `Removing 0.1 $VEGA from validator ${this.validatorName}`
).should('be.visible'); ).should('be.visible');
cy.contains( cy.contains(
'Waiting for confirmation that your change in nomination has been received' 'Waiting for confirmation that your change in nomination has been received'
@ -73,37 +71,24 @@ context('Staking Tab - with vega wallet connected', function () {
{ timeout: 120000 } { timeout: 120000 }
).should('not.exist'); ).should('not.exist');
cy.contains( cy.contains(
`0.1 $VEGA has been removed from validator ${this.validatorNames[0]}` `0.1 $VEGA has been removed from validator ${this.validatorName}`
); );
}); });
it('Check - staking page - stake on node (next epoch) - updates to reflect stake', function () { it('Check - staking page - stake on node (next epoch) - updates to reflect stake', function () {
let expectedStakeNextEpochValue = cy.stakingValidatorPage_check_stakeNextEpochValue(
parseFloat(this.initialStakeNextEpoch) - 0.1; parseFloat(this.initialStakeNextEpoch) - 0.1);
cy.get(staking.stakeNextEpochValue, { timeout: 10000 })
.contains(expectedStakeNextEpochValue.toFixed(2), { timeout: 10000 })
.should('be.visible');
}); });
it('Check - wallet - next epoch amount - updates balance for validator', function () { it('Check - wallet - next epoch amount - updates balance for validator', function () {
let expectedValStakeNextEpochValue = cy.walletVega_checkValidator_StakeNextEpochValue(
parseFloat(this.initialStakeNextEpoch) - 0.1; this.validatorName, parseFloat(this.initialStakeNextEpoch) - 0.1)
cy.walletVega_getNextEpochStakeForSpecifiedValidator(
this.validatorNames[0]
).then((actualNextEpochStake) => {
assert.equal(
parseFloat(actualNextEpochStake).toPrecision(12),
parseFloat(expectedValStakeNextEpochValue).toPrecision(12)
);
});
}); });
it.skip('Check - wallet - unstaked amount - updates balance', function () { it.skip('Check - wallet - unstaked amount - updates balance', function () {
// Skipping until capsule can enable this test // Skipping until capsule can enable this test
cy.walletVega_getUnstakedAmount().should( cy.walletVega_check_UnstakedValue_is(
'equal', parseFloat(this.initialUnstakedBalance) - 0.1);
this.initialUnstakedBalance - 0.1
);
}); });
}); });
}); });

View File

@ -15,7 +15,7 @@ context('Staking Tab - with vega wallet connected', function () {
cy.stakingPage_getValidatorNamesSorted().as('validatorNames'); cy.stakingPage_getValidatorNamesSorted().as('validatorNames');
}); });
describe('vega wallet contains VEGA tokens', function () { describe('Vega wallet - contains VEGA tokens', function () {
before('ensure environment fit for test', function () { before('ensure environment fit for test', function () {
assert.isAtLeast( assert.isAtLeast(
parseInt(this.initialUnstakedBalance), parseInt(this.initialUnstakedBalance),
@ -27,10 +27,8 @@ context('Staking Tab - with vega wallet connected', function () {
2, 2,
'Checking we have at least 2 validators' 'Checking we have at least 2 validators'
); );
// Ensure we are not in last minute - as this adds flake // Choose the first validator from top of sorted list
cy.get(staking.epochEndingText) this.validatorName = this.validatorNames[0];
.contains('Next epoch in 1 minutes', { timeout: 65000 })
.should('not.exist');
}); });
before('drill into a specific validator - and note values', function () { before('drill into a specific validator - and note values', function () {
@ -49,11 +47,12 @@ context('Staking Tab - with vega wallet connected', function () {
.as('initialValidatorStake'); .as('initialValidatorStake');
}); });
describe('Able to stake against a validator', function () { describe('Flow - Able to stake against a validator', function () {
it('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 // Check - ability to fill in fields and request a stake of 0.1 tokens
cy.get(staking.addStakeRadioButton).click({ force: true }); cy.get(staking.addStakeRadioButton).click({ force: true });
cy.get(staking.tokenAmountInput).type('0.1'); cy.get(staking.tokenAmountInput).type('0.1');
// cy.staking_waitForEpochRemainingSeconds(5);
cy.get('button').contains('Add 0.1 $VEGA tokens').click(); cy.get('button').contains('Add 0.1 $VEGA tokens').click();
// Check - relevant successfull feedback provided after staking - Note: Wallet auto approves at this stage // Check - relevant successfull feedback provided after staking - Note: Wallet auto approves at this stage
@ -72,27 +71,16 @@ context('Staking Tab - with vega wallet connected', function () {
); );
// Check - staking page - stake on node (next epoch) - updates to reflect stake // Check - staking page - stake on node (next epoch) - updates to reflect stake
let expectedStakeNextEpochValue = cy.stakingValidatorPage_check_stakeNextEpochValue(
parseFloat(this.initialStakeNextEpoch) + 0.1; parseFloat(this.initialStakeNextEpoch) + 0.1);
cy.get(staking.stakeNextEpochValue, { timeout: 10000 }).contains(
expectedStakeNextEpochValue.toFixed(2),
{ timeout: 10000 }
);
//Check - wallet staked amount - updates balance for validator //Check - wallet staked amount - updates balance for validator
let expectedValStakeNextEpochValue = cy.walletVega_checkValidator_StakeNextEpochValue(
parseFloat(this.initialStakeNextEpoch) + 0.1; this.validatorName, parseFloat(this.initialStakeNextEpoch) + 0.1);
cy.walletVega_getNextEpochStakeForSpecifiedValidator(
this.validatorNames[0]
).then((actualNextEpochStake) => {
assert.equal(
parseFloat(actualNextEpochStake).toPrecision(12),
parseFloat(expectedValStakeNextEpochValue).toPrecision(12)
);
});
//Check - wallet unstaked amount - updates balance - Note: Skipping until capsule can enable this test //Check - wallet unstaked amount - updates balance - Note: Skipping until capsule can enable this test
// cy.walletVega_getUnstakedAmount().should('equal', this.initialUnstakedBalance - 0.1); // cy.walletVega_check_UnstakedValue_is(
// parseFloat(this.initialUnstakedBalance) - 0.1);
}); });
}); });
}); });

2
apps/token-e2e/src/support/index.d.ts vendored Normal file
View File

@ -0,0 +1,2 @@
// type definitions for Cypress object "cy"
/// <reference types="cypress" />

View File

@ -10,3 +10,22 @@ Cypress.Commands.add('stakingPage_getValidatorNamesSorted', function () {
return validatorNames.sort(); return validatorNames.sort();
}); });
}); });
Cypress.Commands.add(
'stakingValidatorPage_check_stakeNextEpochValue',
function (expectedVal) {
cy.get(staking.stakeNextEpochValue, { timeout: 10000 })
.contains(expectedVal.toFixed(2),
{ timeout: 10000 }
);
}
);
Cypress.Commands.add(
'staking_waitForEpochRemainingSeconds',
function (secondsRemaining) {
cy.get(staking.epochEndingText)
.contains(`Next epoch in ${secondsRemaining} seconds`, { timeout: `${secondsRemaining*1100}` })
.should('be.visible');
}
);

View File

@ -31,23 +31,27 @@ Cypress.Commands.add('walletVega_getUnstakedAmount', function () {
}); });
Cypress.Commands.add( Cypress.Commands.add(
'walletVega_getNextEpochStakeForSpecifiedValidator', 'walletVega_checkValidator_StakeNextEpochValue',
function (validatorName) { function (validatorName, expectedVal) {
// need to check if validator is present first // need to check if validator is present first
let fieldPresent = false;
cy.get(wallet.vegawallet) cy.get(wallet.vegawallet)
.within(($wallet) => { .within(() => {
if ($wallet.text().includes(`${validatorName} (Next epoch)`))
fieldPresent = true;
})
.then(() => {
if (fieldPresent == true) {
cy.contains(`${validatorName} (Next epoch)`) cy.contains(`${validatorName} (Next epoch)`)
.siblings() .siblings()
.invoke('text'); .contains(parseFloat(expectedVal).toPrecision(16));
} else { })
return '0.000000000000000000'; }
} );
});
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()
.contains(parseFloat(expectedVal).toPrecision(16));
})
} }
); );