test: enhancements

This commit is contained in:
AndyWhiteVega 2022-06-25 18:49:06 +01:00
parent aaae6e087e
commit f3e15f4aa1
7 changed files with 195 additions and 104 deletions

View File

@ -24,6 +24,8 @@
"tsConfig": "tsconfig.json",
"TAGS": "not @todo and not @ignore and not @manual",
"TRADING_TEST_VEGA_WALLET_PASSPHRASE": "123",
"ETH_WALLET_MNEMONIC": "ugly gallery notice network true range brave clarify flat logic someone chunk"
"ETH_WALLET_MNEMONIC": "ugly gallery notice network true range brave clarify flat logic someone chunk",
"WALLET_NAME" : "capsuleWallet",
"WALLET_PASSPHRASE" : "123"
}
}

View File

@ -1,16 +1,16 @@
/// <reference types="cypress" />
import navigation from '../../locators/navigation.locators';
import staking from '../../locators/staking.locators';
import wallet from '../../locators/wallet.locators';
import '../../support/staking.functions';
import '../../support/wallet.functions';
context('Staking Tab - with vega wallet connected', function () {
before('visit staking tab and connect vega wallet', function () {
cy.visit('/');
cy.walletVega_create();
cy.get(navigation.section, { timeout: 20000 }).should('be.visible');
cy.get(navigation.staking).first().click();
cy.walletVega_create();
cy.get(navigation.spinner, { timeout: 20000 }).should('not.exist');
cy.walletEth_connect();
cy.walletVega_connect();
cy.get(navigation.spinner, { timeout: 20000 }).should('not.exist');
@ -19,90 +19,69 @@ context('Staking Tab - with vega wallet connected', function () {
describe('Vega wallet - contains VEGA tokens', function () {
before('Associate VEGA tokens', function () {
cy.get(wallet.ethWallet).within(() => cy.get(wallet.ethWalletAssociate).click())
cy.get(staking.stakeAssociateWalletRadio, {timeout : 20000}).click();
cy.get(staking.tokenAmountInput, {timeout : 10000}).type('2');
cy.contains('$VEGA Tokens are approved for staking', {timeout : 20000})
})
beforeEach('drill into a specific validator - and note values', function () {
beforeEach('drill into a specific validator', function () {
cy.walletVega_teardown();
cy.get(navigation.staking).first().click();
cy.get(navigation.spinner, { timeout: 20000 }).should('not.exist');
cy.get(staking.validatorNames).contains(this.validatorName).click();
cy.contains('Manage your stake').should('be.visible');
cy.get(wallet.vegawallet).contains('Unstaked').siblings()
.invoke('text').as('initialUnstakedBalance');
cy.get(staking.stakeNextEpochValue).invoke('text')
.as('initialStakeNextEpoch');
cy.get(staking.stakeThisEpochValue).invoke('text')
.as('initialStakeThisEpoch');
});
cy.contains('Your Stake On Node (This Epoch)').should('be.visible');
})
it('Able to stake against a validator', function () {
cy.log("**Check - ability to fill in fields and request an add stake of 0.5 tokens**");
cy.get(staking.addStakeRadioButton).click({ force: true });
cy.get(staking.tokenAmountInput).type('0.5');
cy.contains('Waiting for next epoch to start', {timeout:10000});
cy.get(staking.tokenInputSubmit).should('be.enabled', {timeout:8000})
.and('contain', 'Add 0.5 $VEGA tokens')
.and('be.visible')
.click();
it('Able to associate tokens', function () {
cy.walletEth_associateTokens('2');
cy.walletVega_check_associatedValue_is('2.0')
})
cy.log("**Check - relevant successfull feedback provided after staking - after auto approval**");
cy.contains('At the beginning of the next epoch your $VEGA will be nominated to the validator');
it('Able to disassociate all tokens', function () {
cy.walletEth_associateTokens('2');
cy.walletVega_check_associatedValue_is('2.0')
cy.walletEth_disassociateAllTokens();
cy.walletVega_check_associatedValue_is('0.0')
})
cy.log("**Check - staking page - stake on node (next epoch) - updates to reflect stake**");
cy.stakingValidatorPage_check_stakeNextEpochValue(parseFloat(this.initialStakeNextEpoch) + 0.5);
cy.log("**Check - wallet - next epoch amount - updates balance for validator**");
cy.walletVega_checkThisValidator_StakeNextEpochValue_is(this.validatorName,
parseFloat(this.initialStakeNextEpoch) + 0.5);
cy.log("**Check - wallet - unstaked amount - updates balance**");
cy.walletVega_check_UnstakedValue_is(parseFloat(this.initialUnstakedBalance) - 0.5);
it.only('Able to stake against a validator', function () {
cy.walletEth_associateTokens('0.1');
cy.get('button').contains('Select a validator to nominate').click();
cy.get(staking.validatorNames).contains(this.validatorName).click();
cy.staking_addStake('0.1');
cy.walletVega_checkThisValidator_StakeNextEpochValue_is(this.validatorName, '0.1');
cy.walletVega_check_UnstakedValue_is('1.9');
});
it('Able to remove stake against a validator', function () {
cy.log("**Check - ability to fill in fields and request a removal stake of 0.1 tokens**");
cy.get(staking.removeStakeRadioButton).click({ force: true });
cy.get(staking.tokenAmountInput).type('0.1');
cy.contains('Waiting for next epoch to start', {timeout:10000});
cy.get(staking.tokenInputSubmit).should('be.enabled', {timeout:8000})
.and('contain', 'Remove 0.1 $VEGA tokens').and('be.visible').click();
cy.log("**Check - relevant successfull feedback provided after staking - after auto approval**");
cy.contains(`0.1 $VEGA has been removed from validator`).should('be.visible');
cy.log("**Check - staking page - stake on node (next epoch) - updates to reflect stake**");
cy.stakingValidatorPage_check_stakeNextEpochValue(parseFloat(this.initialStakeNextEpoch) - 0.1);
cy.log("**Check - wallet - next epoch amount - updates balance for validator**");
cy.walletVega_checkThisValidator_StakeNextEpochValue_is(this.validatorName,
parseFloat(this.initialStakeNextEpoch) - 0.1);
cy.log("**Check - wallet - unstaked amount - updates balance**");
cy.walletVega_check_UnstakedValue_is(parseFloat(this.initialUnstakedBalance) + 0.1);
cy.walletEth_associateTokens('0.1');
cy.get('button').contains('Select a validator to nominate').click();
cy.get(staking.validatorNames).contains(this.validatorName).click();
cy.staking_addStake('0.1');
cy.walletVega_checkThisValidator_StakeNextEpochValue_is(this.validatorName, '0.1');
cy.walletVega_check_UnstakedValue_is('1.9');
cy.staking_removeStake('0.1')
cy.walletVega_checkThisValidator_StakeNextEpochValue_is(this.validatorName, '0.0');
cy.walletVega_check_UnstakedValue_is('2.0');
cy.stakingValidatorPage_check_stakeNextEpochValue('0.0');
cy.walletVega_checkThisValidator_StakeNextEpochValue_is(this.validatorName, '0.0')
cy.walletVega_check_UnstakedValue_is('2.0');
});
it('Unable to remove a stake with a negative value for a validator', function () {
cy.get(staking.removeStakeRadioButton).click({ force: true });
cy.get(staking.tokenAmountInput).type('-0.1');
cy.contains('Waiting for next epoch to start', { timeout: 10000 });
cy.get(staking.tokenInputSubmit).should('be.disabled', {timeout:8000})
cy.get(staking.tokenInputSubmit)
.should('be.disabled', { timeout: 8000 })
.and('contain', `Remove -0.1 $VEGA tokens at the end of epoch`)
.and('be.visible')
.and('be.visible');
});
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.get(staking.tokenAmountInput).type(0.1);
cy.contains('Waiting for next epoch to start', { timeout: 10000 });
cy.get(staking.tokenInputSubmit).should('be.disabled', {timeout:8000})
.and('contain', `Remove ${amountToTry} $VEGA tokens at the end of epoch`)
.and('be.visible')
});
cy.get(staking.tokenInputSubmit)
.should('be.disabled', { timeout: 8000 })
.and('contain',`Remove 0.1 $VEGA tokens at the end of epoch`)
.and('be.visible');
});
});
});

View File

@ -10,5 +10,5 @@ export default {
stakeNextEpochValue: '[data-testid="stake-next-epoch"]',
stakeThisEpochValue: '[data-testid="stake-this-epoch"]',
stakeMaximumTokens: '[data-testid="token-amount-use-maximum"]',
stakeAssociateWalletRadio: '[data-testid="associate-radio-wallet"]'
stakeAssociateWalletRadio: '[data-testid="associate-radio-wallet"]',
};

View File

@ -6,5 +6,6 @@ export default {
ethWallet: '[data-testid="ethereum-wallet"]',
ethWalletConnectToEth: '[data-testid="connect-to-eth-wallet-button"]',
ethWalletConnect: '[data-testid="web3-connector-Unknown"]',
ethWalletAssociate: '[href="/staking/associate"]'
ethWalletAssociate: '[href="/staking/associate"]',
ethWalletDisassociate: '[href="/staking/disassociate"]',
};

View File

@ -6,7 +6,7 @@ Cypress.Commands.add(
'stakingValidatorPage_check_stakeNextEpochValue',
function (expectedVal) {
cy.get(staking.stakeNextEpochValue, { timeout: 10000 }).contains(
expectedVal.toFixed(2),
expectedVal,
{ timeout: 10000 }
);
}
@ -26,3 +26,37 @@ Cypress.Commands.add(
);
// ----------------------------------------------------------------------
Cypress.Commands.add(
'staking_addStake',
function (stake) {
cy.get(staking.addStakeRadioButton).click({ force: true });
cy.get(staking.tokenAmountInput).type(stake);
cy.contains('Waiting for next epoch to start', { timeout: 10000 });
cy.get(staking.tokenInputSubmit, { timeout: 8000 })
.should('be.enabled')
.and('contain', `Add ${stake} $VEGA tokens`)
.and('be.visible')
.click();
cy.contains(
'At the beginning of the next epoch your $VEGA will be nominated to the validator'
);
}
);
// ----------------------------------------------------------------------
Cypress.Commands.add(
'staking_removeStake',
function (stake) {
cy.get(staking.removeStakeRadioButton).click({ force: true });
cy.get(staking.tokenAmountInput).type(stake);
cy.contains('Waiting for next epoch to start', { timeout: 10000 });
cy.get(staking.tokenInputSubmit)
.should('be.enabled', { timeout: 8000 })
.and('contain', 'Remove 0.1 $VEGA tokens')
.and('be.visible')
.click();
cy.contains(`0.1 $VEGA has been removed from validator`).should('be.visible');
}
);

View File

@ -1,30 +1,32 @@
import wallet from '../locators/wallet.locators';
import staking from '../locators/staking.locators';
// ----------------------------------------------------------------------
const walletName = Cypress.env("WALLET_NAME");
const walletPassphrase = Cypress.env("WALLET_PASSPHRASE");
Cypress.Commands.add('walletVega_create', function () {
cy.exec('vegawallet init -f --home ~/.vegacapsule/testnet/wallet').then(() => {
cy.exec('echo "123" > ~/.vegacapsule/testnet/wallet/passphrase.txt').then(() => {
cy.exec('vegawallet create --wallet capsule_wallet -p ./passphrase.txt --home ~/.vegacapsule/testnet/wallet', {failOnNonZeroExit: false}).then(() => {
cy.exec('vegawallet service run --network DV --automatic-consent --home ~/.vegacapsule/testnet/wallet').then(() => {
return
})
})
})
})
cy.log('**Initializing Vega Wallet**' + walletName)
let vegaCapWalletLocation = "~/.vegacapsule/testnet/wallet";
cy.exec(`vegawallet init -f --home ${vegaCapWalletLocation}`);
cy.exec(`echo ${walletPassphrase} > ${vegaCapWalletLocation}/passphrase.txt`);
cy.exec(`vegawallet create --wallet ${walletName} -p ./passphrase.txt --home ${vegaCapWalletLocation}`,
{ failOnNonZeroExit: false })
cy.exec(`vegawallet service run --network DV --automatic-consent --home ${vegaCapWalletLocation}`);
cy.log('**Initializing Vega Wallet = COMPLETE**')
});
// ----------------------------------------------------------------------
Cypress.Commands.add('walletVega_connect', function () {
const walletName = "capsule_wallet";
const walletPassphrase = "123"
cy.log('**Connecting Vega Wallet**')
cy.intercept('POST', 'http://localhost:3028/query').as('vegaWalletGrab')
cy.get(wallet.vegawallet).within(() => {
cy.get('button')
.contains('Connect Vega wallet to use associated $VEGA')
.should('be.enabled').and('be.visible').click({force:true})
.should('be.enabled')
.and('be.visible')
.click({ force: true });
});
cy.get('button').contains('rest provider').click();
@ -35,43 +37,116 @@ Cypress.Commands.add('walletVega_connect', function () {
cy.get('button').contains('Connect').click();
});
cy.contains('capsule_wallet key 1', { timeout: 20000 }).should('be.visible');
cy.contains(`${walletName} key`, { timeout: 20000 }).should('be.visible');
// We have to wait for two fetchs of wallet balances to finish
// Since oddly the first fetch returns a balance of 0.0 (even if tokens present)
cy.wait('@vegaWalletGrab', {timeout : 10000}).wait('@vegaWalletGrab', {timeout : 10000});
// Then we turn off our intercept - so that we can use it again in the future
cy.intercept('POST', 'http://localhost:3028/query', (req) => req.continue());
cy.log('**Connecting Vega Wallet = COMPLETE**')
});
// ----------------------------------------------------------------------
Cypress.Commands.add(
'walletVega_checkThisValidator_StakeNextEpochValue_is',
Cypress.Commands.add('walletVega_checkThisValidator_StakeNextEpochValue_is',
function (validatorName, expectedVal) {
cy.log(`**Checking Stake Next Epoch Value for ${validatorName} is ${expectedVal}**`)
cy.get(wallet.vegawallet).within(() => {
cy.contains(`${validatorName} (Next epoch)`)
.siblings()
.contains(parseFloat(expectedVal).toPrecision(16));
});
cy.log('**Checking Stake Next Epoch Value = Complete**')
}
);
// ----------------------------------------------------------------------
Cypress.Commands.add(
'walletVega_check_UnstakedValue_is',
function (expectedVal) {
Cypress.Commands.add('walletVega_check_UnstakedValue_is', function (expectedVal) {
cy.log(`**Checking Vega Wallet Unstaked Value is ${expectedVal}**`)
cy.get(wallet.vegawallet).within(() => {
cy.contains(`Unstaked`)
cy.contains('Unstaked', {timeout : 20000})
.siblings()
.contains(parseFloat(expectedVal).toPrecision(16), { timeout: 10000 });
});
cy.log('**Checking Vega Wallet Unstaked Value = Complete**')
}
);
// ----------------------------------------------------------------------
Cypress.Commands.add('walletVega_check_associatedValue_is', function (expectedVal) {
cy.log(`**Checking Vega Wallet Asscoiated Value is ${expectedVal}**`)
cy.get(wallet.vegawallet).within(() => {
cy.contains('Associated', {timeout : 20000})
.parent()
.siblings()
.contains(expectedVal, {timeout : 40000});
});
cy.log('**Checking Vega Wallet Asscoiated Value = COMPLETE**')
}
);
// ----------------------------------------------------------------------
Cypress.Commands.add('walletEth_connect', function () {
cy.log('**Connecting Eth Wallet**');
cy.get(wallet.ethWalletConnectToEth).within(() => {
cy.contains('Connect Ethereum wallet to associate $VEGA')
.should('be.visible').click();
.should('be.visible')
.click()});
cy.get(wallet.ethWalletConnect).click();
cy.get(wallet.ethWalletConnect, {timeout : 60000}).should('not.exist')
cy.contains('Ethereum wallet connected').should('be.visible');
cy.log('**Connecting Eth Wallet = COMPLETE**')
});
cy.get(wallet.ethWalletConnect).click();
cy.contains('Ethereum wallet connected').should('be.visible');
});
// ----------------------------------------------------------------------
Cypress.Commands.add('walletEth_associateTokens', function (amount) {
cy.log(`**Associating ${amount} tokens from Eth Wallet**`)
cy.get(wallet.ethWallet).within(() =>
cy.get(wallet.ethWalletAssociate).click());
cy.get(staking.stakeAssociateWalletRadio, { timeout: 30000 }).click();
cy.get(staking.tokenAmountInput, { timeout: 10000 }).type(amount);
cy.get(staking.tokenInputSubmit, { timeout: 20000 }).should('be.enabled').click();
cy.contains('can now participate in governance and nominate a validator', { timeout: 60000 });
cy.log('**Associating tokens from Eth Wallet = COMPLETE**')
})
// ----------------------------------------------------------------------
Cypress.Commands.add('walletEth_disassociateAllTokens', function () {
cy.log('**Disassociating tokens from Eth Wallet**')
cy.get(wallet.ethWallet).within(() =>
cy.get(wallet.ethWalletDisassociate).click());
cy.get(staking.stakeAssociateWalletRadio, { timeout: 20000 }).click();
cy.get(staking.stakeMaximumTokens, { timeout: 60000 }).click();
cy.get(staking.tokenInputSubmit, { timeout: 10000 }).click();
cy.contains('$VEGA tokens have been returned to Ethereum wallet', { timeout: 60000 })
cy.walletVega_check_associatedValue_is('0.0')
cy.log('**Disassociating tokens from Eth Wallet = Complete**')
})
// ----------------------------------------------------------------------
Cypress.Commands.add('walletVega_teardown', function () {
cy.log('**Tearing down associated tokens from Vega Wallet**')
let vegaPresentInWallet = false;
cy.get(wallet.vegawallet).within(() => {
cy.contains('Associated', {timeout : 20000})
.parent()
.siblings()
.within(($associated) => {
if ($associated.text() != '0.000000000000000000')
vegaPresentInWallet = true;
})
}).then(() => {
if (vegaPresentInWallet == true) {
cy.root().walletEth_disassociateAllTokens()
}
else {cy.log('**No need to teardown vega wallet - wallet empty**')}
})
cy.log('**Tearing down associated tokens from Vega Wallet = COMPLETE**')
})