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');
});
describe('vega wallet contains VEGA tokens', function () {
describe('Vega wallet - contains VEGA tokens', function () {
before('ensure environment fit for test', function () {
assert.isAtLeast(
parseInt(this.initialUnstakedBalance),
@ -27,14 +27,12 @@ context('Staking Tab - with vega wallet connected', function () {
2,
'Checking we have at least 2 validators'
);
// Ensure we are not in last minute - as this adds flake
cy.get(staking.epochEndingText)
.contains('Next epoch in 1 minutes', { timeout: 65000 })
.should('not.exist');
// Choose the first validator from top of sorted list
this.validatorName = this.validatorNames[0];
});
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.get(staking.stakeNextEpochValue)
.invoke('text')
@ -49,17 +47,18 @@ context('Staking Tab - with vega wallet connected', function () {
.as('initialValidatorStake');
});
describe('Able to stake against a validator', function () {
it('Check - ability to fill in fields and request a stake of 0.1 tokens', function () {
describe('Flow - Able to stake against a validator', 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.tokenAmountInput).type('0.1');
// cy.staking_waitForEpochRemainingSeconds(5);
cy.get('button').contains('Add 0.1 $VEGA tokens').click();
});
it('Check - relevant successfull feedback provided after staking', function () {
// Wallet auto approves at this stage
cy.contains(
`Adding 0.1 $VEGA to validator ${this.validatorNames[0]}`
`Adding 0.1 $VEGA to validator ${this.validatorName}`
).should('be.visible');
cy.contains(
'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 () {
let expectedStakeNextEpochValue =
parseFloat(this.initialStakeNextEpoch) + 0.1;
cy.get(staking.stakeNextEpochValue, { timeout: 10000 }).contains(
expectedStakeNextEpochValue.toFixed(2),
{ timeout: 10000 }
);
cy.stakingValidatorPage_check_stakeNextEpochValue(
parseFloat(this.initialStakeNextEpoch) + 0.1);
});
it('Check - wallet - next epoch amount - updates balance for validator', function () {
let expectedValStakeNextEpochValue =
parseFloat(this.initialStakeNextEpoch) + 0.1;
cy.walletVega_getNextEpochStakeForSpecifiedValidator(
this.validatorNames[0]
).then((actualNextEpochStake) => {
assert.equal(
parseFloat(actualNextEpochStake).toPrecision(12),
parseFloat(expectedValStakeNextEpochValue).toPrecision(12)
);
});
cy.walletVega_checkValidator_StakeNextEpochValue(
this.validatorName, parseFloat(this.initialStakeNextEpoch) + 0.1);
});
it.skip('Check - wallet - unstaked amount - updates balance', function () {
// 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);
});
});
});

View File

@ -15,21 +15,19 @@ context('Staking Tab - with vega wallet connected', function () {
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 () {
assert.isAtLeast(
this.validatorNames.length,
2,
'Checking we have at least 2 validators'
);
// Ensure we are not in last minute - as this adds flake
cy.get(staking.epochEndingText)
.contains('Next epoch in 1 minutes', { timeout: 65000 })
.should('not.exist');
// Choose the first validator from top of sorted list
this.validatorName = this.validatorNames[0];
});
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.get(staking.stakeNextEpochValue)
.invoke('text')
@ -44,26 +42,26 @@ context('Staking Tab - with vega wallet connected', function () {
.as('initialValidatorStake');
});
describe('Able to remove a stake against a validator', function () {
it('Check - validator has tokens to remove', function () {
let tokensToRemove = parseFloat(this.initialStakeNextEpoch);
describe('Flow - Ability to remove a stake against a validator', function () {
before('Check - validator has tokens to remove', function () {
assert.isAtLeast(
tokensToRemove,
parseFloat(this.initialStakeNextEpoch),
0.1,
'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.tokenAmountInput).type('0.1');
// cy.staking_waitForEpochRemainingSeconds(5);
cy.get('button').contains('Remove 0.1 $VEGA tokens').click();
});
it('Check - relevant successfull feedback provided after staking', function () {
// Wallet auto approves at this stage
cy.contains(
`Removing 0.1 $VEGA from validator ${this.validatorNames[0]}`
`Removing 0.1 $VEGA from validator ${this.validatorName}`
).should('be.visible');
cy.contains(
'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 }
).should('not.exist');
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 () {
let expectedStakeNextEpochValue =
parseFloat(this.initialStakeNextEpoch) - 0.1;
cy.get(staking.stakeNextEpochValue, { timeout: 10000 })
.contains(expectedStakeNextEpochValue.toFixed(2), { timeout: 10000 })
.should('be.visible');
cy.stakingValidatorPage_check_stakeNextEpochValue(
parseFloat(this.initialStakeNextEpoch) - 0.1);
});
it('Check - wallet - next epoch amount - updates balance for validator', function () {
let expectedValStakeNextEpochValue =
parseFloat(this.initialStakeNextEpoch) - 0.1;
cy.walletVega_getNextEpochStakeForSpecifiedValidator(
this.validatorNames[0]
).then((actualNextEpochStake) => {
assert.equal(
parseFloat(actualNextEpochStake).toPrecision(12),
parseFloat(expectedValStakeNextEpochValue).toPrecision(12)
);
});
cy.walletVega_checkValidator_StakeNextEpochValue(
this.validatorName, parseFloat(this.initialStakeNextEpoch) - 0.1)
});
it.skip('Check - wallet - unstaked amount - updates balance', function () {
// 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);
});
});
});

View File

@ -15,7 +15,7 @@ context('Staking Tab - with vega wallet connected', function () {
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 () {
assert.isAtLeast(
parseInt(this.initialUnstakedBalance),
@ -27,10 +27,8 @@ context('Staking Tab - with vega wallet connected', function () {
2,
'Checking we have at least 2 validators'
);
// Ensure we are not in last minute - as this adds flake
cy.get(staking.epochEndingText)
.contains('Next epoch in 1 minutes', { timeout: 65000 })
.should('not.exist');
// Choose the first validator from top of sorted list
this.validatorName = this.validatorNames[0];
});
before('drill into a specific validator - and note values', function () {
@ -49,11 +47,12 @@ context('Staking Tab - with vega wallet connected', function () {
.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 () {
// 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
@ -72,27 +71,16 @@ context('Staking Tab - with vega wallet connected', function () {
);
// Check - staking page - stake on node (next epoch) - updates to reflect stake
let expectedStakeNextEpochValue =
parseFloat(this.initialStakeNextEpoch) + 0.1;
cy.get(staking.stakeNextEpochValue, { timeout: 10000 }).contains(
expectedStakeNextEpochValue.toFixed(2),
{ timeout: 10000 }
);
cy.stakingValidatorPage_check_stakeNextEpochValue(
parseFloat(this.initialStakeNextEpoch) + 0.1);
//Check - wallet staked amount - updates balance for validator
let expectedValStakeNextEpochValue =
parseFloat(this.initialStakeNextEpoch) + 0.1;
cy.walletVega_getNextEpochStakeForSpecifiedValidator(
this.validatorNames[0]
).then((actualNextEpochStake) => {
assert.equal(
parseFloat(actualNextEpochStake).toPrecision(12),
parseFloat(expectedValStakeNextEpochValue).toPrecision(12)
);
});
cy.walletVega_checkValidator_StakeNextEpochValue(
this.validatorName, parseFloat(this.initialStakeNextEpoch) + 0.1);
//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();
});
});
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(
'walletVega_getNextEpochStakeForSpecifiedValidator',
function (validatorName) {
'walletVega_checkValidator_StakeNextEpochValue',
function (validatorName, expectedVal) {
// need to check if validator is present first
let fieldPresent = false;
cy.get(wallet.vegawallet)
.within(($wallet) => {
if ($wallet.text().includes(`${validatorName} (Next epoch)`))
fieldPresent = true;
})
.then(() => {
if (fieldPresent == true) {
.within(() => {
cy.contains(`${validatorName} (Next epoch)`)
.siblings()
.invoke('text');
} else {
return '0.000000000000000000';
}
});
.contains(parseFloat(expectedVal).toPrecision(16));
})
}
);
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));
})
}
);