test: more tests

This commit is contained in:
AndyWhiteVega 2022-06-24 10:22:52 +01:00
parent a85fbb0a65
commit c3c9cc0bd4
5 changed files with 151 additions and 56 deletions

View File

@ -82,7 +82,7 @@ context('Staking Tab - with vega wallet connected', function () {
}); });
it('Check - wallet - next epoch amount - updates balance for validator', function () { it('Check - wallet - next epoch amount - updates balance for validator', function () {
cy.walletVega_checkValidator_StakeNextEpochValue( cy.walletVega_checkValidator_StakeNextEpochValue_is(
this.validatorName, this.validatorName,
parseFloat(this.initialStakeNextEpoch) + 0.1 parseFloat(this.initialStakeNextEpoch) + 0.1
); );

View File

@ -85,7 +85,7 @@ context('Staking Tab - with vega wallet connected', function () {
}); });
it('Check - wallet - next epoch amount - updates balance for validator', function () { it('Check - wallet - next epoch amount - updates balance for validator', function () {
cy.walletVega_checkValidator_StakeNextEpochValue( cy.walletVega_checkValidator_StakeNextEpochValue_is(
this.validatorName, this.validatorName,
parseFloat(this.initialStakeNextEpoch) - 0.1 parseFloat(this.initialStakeNextEpoch) - 0.1
); );

View File

@ -11,29 +11,17 @@ context('Staking Tab - with vega wallet connected', function () {
cy.get(navigation.staking).first().click(); cy.get(navigation.staking).first().click();
cy.walletVega_connect(); cy.walletVega_connect();
cy.get(navigation.spinner, { timeout: 20000 }).should('not.exist'); cy.get(navigation.spinner, { timeout: 20000 }).should('not.exist');
cy.walletVega_getUnstakedAmount().as('initialUnstakedBalance');
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 () { beforeEach('drill into a specific validator - and note values', function () {
assert.isAtLeast(
parseInt(this.initialUnstakedBalance), cy.get(navigation.staking).first().click();
0.1, cy.get(navigation.spinner, { timeout: 20000 }).should('not.exist');
'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 () {
cy.get(staking.validatorNames).contains(this.validatorNames[0]).click(); cy.get(staking.validatorNames).contains(this.validatorNames[0]).click();
cy.contains('Manage your stake').should('be.visible'); cy.contains('Manage your stake').should('be.visible');
cy.walletVega_getUnstakedAmount().as('initialUnstakedBalance');
cy.get(staking.stakeNextEpochValue) cy.get(staking.stakeNextEpochValue)
.invoke('text') .invoke('text')
.as('initialStakeNextEpoch'); .as('initialStakeNextEpoch');
@ -47,44 +35,152 @@ context('Staking Tab - with vega wallet connected', function () {
.as('initialValidatorStake'); .as('initialValidatorStake');
}); });
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.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
cy.contains( cy.contains(
`Adding 0.1 $VEGA to validator ${this.validatorNames[0]}` `Adding 0.1 $VEGA to validator ${this.validatorNames[0]}`
).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'
).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',
{ timeout: 120000 } { timeout: 120000 }
).should('not.exist'); ).should('not.exist');
cy.contains( cy.contains(
'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'
); );
// Check - staking page - stake on node (next epoch) - updates to reflect stake // Check - staking page - stake on node (next epoch) - updates to reflect stake
cy.stakingValidatorPage_check_stakeNextEpochValue( cy.stakingValidatorPage_check_stakeNextEpochValue(
parseFloat(this.initialStakeNextEpoch) + 0.1 parseFloat(this.initialStakeNextEpoch) + 0.1
); );
//Check - wallet staked amount - updates balance for validator // Check - wallet staked amount - updates balance for validator
cy.walletVega_checkValidator_StakeNextEpochValue( cy.walletVega_checkValidator_StakeNextEpochValue_is(
this.validatorName, this.validatorNames[0],
parseFloat(this.initialStakeNextEpoch) + 0.1 parseFloat(this.initialStakeNextEpoch) + 0.1
); );
//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_check_UnstakedValue_is( // cy.walletVega_check_UnstakedValue_is(
// parseFloat(this.initialUnstakedBalance) - 0.1); // 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');
}); });
}); });
}); });

View File

@ -7,4 +7,5 @@ export default {
stakedAmounts: '[data-testid="staked-validator-item"]', stakedAmounts: '[data-testid="staked-validator-item"]',
stakeNextEpochValue: '[data-testid="stake-next-epoch"]', stakeNextEpochValue: '[data-testid="stake-next-epoch"]',
stakeThisEpochValue: '[data-testid="stake-this-epoch"]', stakeThisEpochValue: '[data-testid="stake-this-epoch"]',
stakeMaximumTokens: '[data-testid="token-amount-use-maximum"]'
}; };

View File

@ -31,9 +31,8 @@ Cypress.Commands.add('walletVega_getUnstakedAmount', function () {
}); });
Cypress.Commands.add( Cypress.Commands.add(
'walletVega_checkValidator_StakeNextEpochValue', 'walletVega_checkValidator_StakeNextEpochValue_is',
function (validatorName, expectedVal) { function (validatorName, expectedVal) {
// need to check if validator is present first
cy.get(wallet.vegawallet).within(() => { cy.get(wallet.vegawallet).within(() => {
cy.contains(`${validatorName} (Next epoch)`) cy.contains(`${validatorName} (Next epoch)`)
.siblings() .siblings()
@ -45,7 +44,6 @@ Cypress.Commands.add(
Cypress.Commands.add( Cypress.Commands.add(
'walletVega_check_UnstakedValue_is', 'walletVega_check_UnstakedValue_is',
function (expectedVal) { function (expectedVal) {
// need to check if validator is present first
cy.get(wallet.vegawallet).within(() => { cy.get(wallet.vegawallet).within(() => {
cy.contains(`Unstaked`) cy.contains(`Unstaked`)
.siblings() .siblings()