test: enhancements to logging to aid debugging

This commit is contained in:
AndyWhiteVega 2022-07-04 09:14:02 +01:00
parent 7edc437e57
commit bcd37e21ae
5 changed files with 218 additions and 87 deletions

View File

@ -1,6 +1,4 @@
{
"tokenAddress": "0x67175Da1D5e966e40D11c4B2519392B2058373de",
"vestingContract": "0xF41bD86d462D36b997C0bbb4D97a0a3382f205B7",
"ethProviderUrl": "http://localhost:8545/",
"ethWalletPublicKey": "0xEe7D375bcB50C26d52E1A4a472D8822A2A22d94F",
"ethStakingBridgeContractAddress": "0x9135f5afd6F055e731bca2348429482eE614CFfA",

View File

@ -5,7 +5,7 @@ import '../../support/staking.functions';
import '../../support/wallet.functions';
import envVars from '../../fixtures/envVars.json';
context('Staking Tab - with vega wallet connected', function () {
context('Staking Tab - with eth and vega wallets connected', function () {
before('visit staking tab and connect vega wallet', function () {
cy.vega_wallet_import();
cy.visit('/');
@ -19,7 +19,7 @@ context('Staking Tab - with vega wallet connected', function () {
cy.get(staking.validatorNames).first().invoke('text').as('validatorName');
});
describe('Vega wallet - contains VEGA tokens', function () {
describe('Eth wallet - contains VEGA tokens', function () {
beforeEach(
'teardown wallet & drill into a specific validator',
function () {
@ -31,7 +31,7 @@ context('Staking Tab - with vega wallet connected', function () {
}
);
it('Able to associate tokens', function () {
it('Able to associate tokens - from eth wallet', function () {
cy.ethereum_wallet_associate_tokens('2');
cy.ethereum_wallet_check_associated_vega_key_value_is(
envVars.vegaWalletPublicKeyShort,
@ -40,6 +40,34 @@ context('Staking Tab - with vega wallet connected', function () {
cy.vega_wallet_check_associated_value_is('2.000000000000000000');
});
it('Able to associate tokens - from staking page', function () {
cy.get(navigation.staking).first().click();
cy.staking_page_associate_tokens('2');
cy.ethereum_wallet_check_associated_vega_key_value_is(
envVars.vegaWalletPublicKeyShort,
'2.000000000000000000'
);
cy.vega_wallet_check_associated_value_is('2.000000000000000000');
});
it('Able to disassociate tokens - from staking page', function () {
cy.get(navigation.staking).first().click();
cy.staking_page_associate_tokens('2');
cy.ethereum_wallet_check_associated_vega_key_value_is(
envVars.vegaWalletPublicKeyShort,
'2.000000000000000000'
);
cy.vega_wallet_check_associated_value_is('2.000000000000000000');
cy.get(navigation.staking).first().click();
cy.staking_page_disassociate_tokens('1');
cy.ethereum_wallet_check_associated_vega_key_value_is(
envVars.vegaWalletPublicKeyShort,
'1.000000000000000000'
);
cy.vega_wallet_check_associated_value_is('1.000000000000000000');
});
it('Able to associate more tokens than the approved amount of 1000 - requires re-approval', function () {
cy.ethereum_wallet_associate_tokens('1001', 'Approve');
cy.ethereum_wallet_check_associated_vega_key_value_is(
@ -85,9 +113,53 @@ context('Staking Tab - with vega wallet connected', function () {
'2.000000000000000000'
);
cy.vega_wallet_check_unstaked_value_is('1.000000000000000000');
cy.vega_wallet_check_validator_staked_value_is(
this.validatorName,
'2.000000000000000000'
);
cy.staking_validator_page_check_stake_next_epoch_value('2.0');
cy.staking_validator_page_check_stake_this_epoch_value('2.0');
});
it('Able to remove stake against a validator', function () {
it('Able to remove part of a stake against a validator', function () {
cy.ethereum_wallet_associate_tokens('4');
cy.vega_wallet_check_unstaked_value_is('4.000000000000000000');
cy.get('button').contains('Select a validator to nominate').click();
cy.get(staking.validatorNames).contains(this.validatorName).click();
cy.staking_validator_page_add_stake('3');
cy.staking_validator_page_check_stake_next_epoch_value('3.0');
cy.vega_wallet_check_validator_stake_next_epoch_value_is(
this.validatorName,
'3.000000000000000000'
);
cy.vega_wallet_check_unstaked_value_is('1.000000000000000000');
cy.get(navigation.staking).first().click();
cy.get(staking.validatorNames).contains(this.validatorName).click();
cy.staking_validator_page_removeStake('1');
cy.staking_validator_page_check_stake_next_epoch_value('2.0');
cy.staking_validator_page_check_stake_this_epoch_value('3.0');
cy.vega_wallet_check_validator_stake_next_epoch_value_is(
this.validatorName,
'2.000000000000000000'
);
cy.vega_wallet_check_validator_stake_this_epoch_value_is(
this.validatorName,
'3.000000000000000000'
);
cy.vega_wallet_check_unstaked_value_is('2.000000000000000000');
cy.vega_wallet_check_validator_staked_value_is(
this.validatorName,
'2.000000000000000000'
);
cy.staking_validator_page_check_stake_next_epoch_value('2.0');
cy.staking_validator_page_check_stake_this_epoch_value('2.0');
});
it('Able to remove a full stake against a validator', function () {
cy.ethereum_wallet_associate_tokens('3');
cy.vega_wallet_check_unstaked_value_is('3.000000000000000000');
@ -107,11 +179,18 @@ context('Staking Tab - with vega wallet connected', function () {
cy.staking_validator_page_removeStake('1');
cy.staking_validator_page_check_stake_next_epoch_value('0.0');
cy.vega_wallet_check_validator_stake_this_epoch_value_is(
this.validatorName,
'1.000000000000000000'
);
cy.vega_wallet_check_validator_stake_next_epoch_value_is(
this.validatorName,
'0.000000000000000000'
);
cy.vega_wallet_check_unstaked_value_is('3.000000000000000000');
cy.staking_validator_page_check_stake_next_epoch_value('0.0');
cy.staking_validator_page_check_stake_this_epoch_value('0.0');
});
it('Unable to remove a stake with a negative value for a validator', function () {

View File

@ -20,4 +20,7 @@ export default {
stakeThisEpochValue: '[data-testid="stake-this-epoch"]',
stakeMaximumTokens: '[data-testid="token-amount-use-maximum"]',
stakeAssociateWalletRadio: '[data-testid="associate-radio-wallet"]',
disassociateButton: '[data-testid="disassociate-tokens-btn"]',
associateMoreTokensButton: '[data-testid="associate-more-tokens-btn"]',
associateButton: '[data-testid="associate-tokens-btn"]'
};

View File

@ -5,29 +5,37 @@ import staking from '../locators/staking.locators';
Cypress.Commands.add(
'staking_validator_page_check_stake_next_epoch_value',
function (expectedVal) {
cy.log(
`👉 **_Checking Staking Page - Validator Stake Next Epoch Value is ${expectedVal}_**`
);
cy.get(staking.stakeNextEpochValue, { timeout: 10000 }).contains(
expectedVal,
{ timeout: 10000 }
);
).should('be.visible');
}
);
// ----------------------------------------------------------------------
Cypress.Commands.add(
'staking_waitForEpochRemainingSeconds',
function (secondsRemaining) {
cy.get(staking.epochEndingText)
.contains(`Next epoch in ${secondsRemaining} seconds`, {
timeout: `${secondsRemaining * 1100}`,
})
.should('be.visible');
'staking_validator_page_check_stake_this_epoch_value',
function (expectedVal) {
cy.log(
`👉 **_Checking Staking Page - Validator Stake This Epoch Value is ${expectedVal}_**`
);
cy.get(staking.stakeThisEpochValue, { timeout: 10000 }).contains(
expectedVal,
{ timeout: 10000 }
).should('be.visible');
}
);
// ----------------------------------------------------------------------
Cypress.Commands.add('staking_validator_page_add_stake', function (stake) {
cy.log(
`👉 **_Adding a stake of ${stake}_**`
);
cy.get(staking.addStakeRadioButton).click({ force: true });
cy.get(staking.tokenAmountInput).type(stake);
cy.contains('Waiting for next epoch to start', { timeout: 10000 });
@ -39,12 +47,15 @@ Cypress.Commands.add('staking_validator_page_add_stake', function (stake) {
cy.contains(
'At the beginning of the next epoch your $VEGA will be nominated to the validator',
{ timeout: 20000 }
);
).should('be.visible');
});
// ----------------------------------------------------------------------
Cypress.Commands.add('staking_validator_page_removeStake', function (stake) {
cy.log(
`👉 **_Removing a stake of ${stake}_**`
);
cy.get(staking.removeStakeRadioButton).click({ force: true });
cy.get(staking.tokenAmountInput).type(stake);
cy.contains('Waiting for next epoch to start', { timeout: 10000 });
@ -57,3 +68,53 @@ Cypress.Commands.add('staking_validator_page_removeStake', function (stake) {
'be.visible'
);
});
// ----------------------------------------------------------------------
Cypress.Commands.add(
'staking_page_associate_tokens',
function (amount, approve) {
cy.log(`👉 **_Associating ${amount} tokens via Staking Page_**`);
cy.get(staking.associateButton).click();
cy.get(staking.stakeAssociateWalletRadio, { timeout: 30000 }).click();
cy.get(staking.tokenAmountInput, { timeout: 10000 }).type(amount);
if (approve !== undefined && approve.toLowerCase() == 'approve') {
cy.get(staking.tokenInputApprove, { timeout: 40000 })
.should('be.enabled')
.click();
cy.contains('Approve $VEGA Tokens for staking on Vega').should(
'be.visible'
);
cy.contains('Approve $VEGA Tokens for staking on Vega', {
timeout: 40000,
}).should('not.exist');
}
cy.get(staking.tokenInputSubmit, { timeout: 40000 })
.should('be.enabled')
.click();
cy.contains('can now participate in governance and nominate a validator', {
timeout: 60000,
}).should('be.visible');
}
);
// ----------------------------------------------------------------------
Cypress.Commands.add('staking_page_disassociate_tokens', function (amount) {
cy.log(`👉 **_Disassociating ${amount} tokens via Staking Page_**`);
cy.get(staking.disassociateButton).click();
cy.get(staking.stakeAssociateWalletRadio, { timeout: 30000 }).click();
cy.get(staking.tokenAmountInput, { timeout: 10000 }).type(amount);
cy.get(staking.tokenInputSubmit, { timeout: 40000 })
.should('be.enabled')
.click();
cy.contains(`${amount} $VEGA tokens have been returned to Ethereum wallet`, {
timeout: 60000,
}).should('be.visible');
});
// ----------------------------------------------------------------------

View File

@ -25,20 +25,19 @@ const getAccount = (number = 0) => `m/44'/60'/0'/0/${number}`;
// ----------------------------------------------------------------------
Cypress.Commands.add('vega_wallet_teardown', function () {
cy.log('**_Connecting Vega Wallet_**');
cy.wrap(
Wallet.fromMnemonic(vegaWalletMnemonic, getAccount(0)).privateKey
Wallet.fromMnemonic(vegaWalletMnemonic, getAccount(0)).privateKey, {log: false}
).then((privateKey) => {
cy.vega_wallet_teardown_staking(privateKey);
cy.vega_wallet_teardown_vesting(privateKey);
cy.vega_wallet_check_associated_value_is('0.000000000000000000');
});
cy.log('**_Connecting Vega Wallet = COMPLETE_**');
});
// ----------------------------------------------------------------------
Cypress.Commands.add('vega_wallet_teardown_staking', function (privateKey) {
cy.log('**_Tearing down staking tokens if required_**');
cy.log('👉 **_Tearing down staking tokens from vega wallet if present_**');
cy.wrap(new ethers.providers.JsonRpcProvider({ url: ethProviderUrl }), {
log: false,
}).as('provider');
@ -59,20 +58,18 @@ Cypress.Commands.add('vega_wallet_teardown_staking', function (privateKey) {
log: false,
}).then((tx) => {
cy.wrap(tx.wait(1), { timeout: 40000, log: false });
cy.vega_wallet_check_associated_value_is('0.000000000000000000');
});
}
});
});
});
});
cy.log('**_Tearing down staking tokens = COMPLETE_**');
});
// ----------------------------------------------------------------------
Cypress.Commands.add('vega_wallet_teardown_vesting', function (privateKey) {
cy.log('**_Tearing down vesting tokens if required_**');
cy.log('👉 **_Tearing down vesting tokens from vega wallet if present_**');
cy.wrap(new ethers.providers.JsonRpcProvider({ url: ethProviderUrl }), {
log: false,
}).as('provider');
@ -99,7 +96,6 @@ Cypress.Commands.add('vega_wallet_teardown_vesting', function (privateKey) {
});
});
});
cy.log('**_Tearing down vesting tokens = COMPLETE_**');
});
// ----------------------------------------------------------------------
@ -107,7 +103,7 @@ Cypress.Commands.add('vega_wallet_teardown_vesting', function (privateKey) {
Cypress.Commands.add(
'vega_wallet_set_specified_approval_amount_and_reload',
function (resetAmount) {
cy.log(`**_Setting token approval amount to ${resetAmount}_**`);
cy.log(`👉 **_Setting token approval amount to ${resetAmount}_**`);
cy.wrap(Wallet.fromMnemonic(vegaWalletMnemonic, getAccount(0)).privateKey, {
log: false,
}).then((privateKey) => {
@ -134,45 +130,15 @@ Cypress.Commands.add(
});
});
});
cy.log(`**_Setting token approval amount to ${resetAmount} = COMPLETE_**`);
cy.log('**_Reloading app for token approval setting to take affect_**');
cy.log('👉 **_Reloading app for token approval setting to take affect_**');
cy.reload();
cy.log(
'**_Reloading app for token approval setting to take affect = COMPLETE_**'
);
}
);
// ----------------------------------------------------------------------
Cypress.Commands.add('vega_wallet_teardown_ui', 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().ethereum_wallet_disassociate_all_tokens();
cy.vega_wallet_check_associated_value_is('0.0');
} else {
cy.log('**_No need to teardown vega wallet - wallet empty_**');
}
});
cy.log('**_Tearing down associated tokens from Vega Wallet = COMPLETE_**');
});
// ----------------------------------------------------------------------
Cypress.Commands.add('vega_wallet_import', function () {
cy.log(`**_Importing Vega Wallet ${vegaWalletName}_**`);
cy.log(`👉 **_Importing Vega Wallet ${vegaWalletName}_**`);
cy.exec(`vegawallet init -f --home ${vegaWalletLocation}`);
cy.exec(
`vegawallet import -w ${vegaWalletName} --recovery-phrase-file ./src/fixtures/wallet/recovery -p ./src/fixtures/wallet/passphrase --home ~/.vegacapsule/testnet/wallet`,
@ -181,14 +147,12 @@ Cypress.Commands.add('vega_wallet_import', function () {
cy.exec(
`vegawallet service run --network DV --automatic-consent --home ${vegaWalletLocation}`
);
cy.log('**_Importing Vega Wallet = COMPLETE_**');
});
// ----------------------------------------------------------------------
Cypress.Commands.add('vega_wallet_connect', function () {
cy.log('**_Connecting Vega Wallet_**');
cy.log('👉 **_Connecting Vega Wallet_**');
cy.get(wallet.vegawallet).within(() => {
cy.get('button')
.contains('Connect Vega wallet to use associated $VEGA')
@ -206,7 +170,6 @@ Cypress.Commands.add('vega_wallet_connect', function () {
});
cy.contains(`${vegaWalletName} key`, { timeout: 20000 }).should('be.visible');
cy.log('**_Connecting Vega Wallet = COMPLETE_**');
});
// ----------------------------------------------------------------------
@ -215,14 +178,48 @@ Cypress.Commands.add(
'vega_wallet_check_validator_stake_next_epoch_value_is',
function (validatorName, expectedVal) {
cy.log(
`**_Checking Stake Next Epoch Value for ${validatorName} is ${expectedVal}_**`
`**_Checking vega wallet - Stake Next Epoch Value for ${validatorName} is ${expectedVal}_**`
);
cy.get(wallet.vegawallet).within(() => {
cy.contains(`${validatorName} (Next epoch)`, { timeout: 40000 })
.siblings()
.contains(expectedVal, { timeout: 40000 });
.contains(expectedVal, { timeout: 40000 })
.should('be.visible');
});
}
);
// ----------------------------------------------------------------------
Cypress.Commands.add(
'vega_wallet_check_validator_stake_this_epoch_value_is',
function (validatorName, expectedVal) {
cy.log(
`**_Checking vega wallet - Stake This Epoch Value for ${validatorName} is ${expectedVal}_**`
);
cy.get(wallet.vegawallet).within(() => {
cy.contains(`${validatorName} (This Epoch)`, { timeout: 40000 })
.siblings()
.contains(expectedVal, { timeout: 40000 })
.should('be.visible');
});
}
);
// ----------------------------------------------------------------------
Cypress.Commands.add(
'vega_wallet_check_validator_staked_value_is',
function (validatorName, expectedVal) {
cy.log(
`**_Checking Validator Stake Value for ${validatorName} is ${expectedVal}_**`
);
cy.get(wallet.vegawallet).within(() => {
cy.contains(`${validatorName}`, { timeout: 40000 })
.siblings()
.contains(expectedVal, { timeout: 40000 })
.should('be.visible');
});
cy.log('**_Checking Stake Next Epoch Value = Complete_**');
}
);
@ -231,13 +228,13 @@ Cypress.Commands.add(
Cypress.Commands.add(
'vega_wallet_check_unstaked_value_is',
function (expectedVal) {
cy.log(`**_Checking Vega Wallet Unstaked Value is ${expectedVal}_**`);
cy.log(`👉 **_Checking vega wallet - Unstaked Value is ${expectedVal}_**`);
cy.get(wallet.vegawallet).within(() => {
cy.contains('Unstaked', { timeout: 40000 })
.siblings()
.contains(expectedVal, { timeout: 40000 });
.contains(expectedVal, { timeout: 40000 })
.should('be.visible');
});
cy.log('**_Checking Vega Wallet Unstaked Value = Complete_**');
}
);
@ -246,21 +243,21 @@ Cypress.Commands.add(
Cypress.Commands.add(
'vega_wallet_check_associated_value_is',
function (expectedVal) {
cy.log(`**_Checking Vega Wallet Associated Value is ${expectedVal}_**`);
cy.log(`👉 **_Checking vega wallet - Associated Value is ${expectedVal}_**`);
cy.get(wallet.vegawallet).within(() => {
cy.contains('Associated', { timeout: 40000 })
.parent()
.siblings()
.contains(expectedVal, { timeout: 40000 });
.contains(expectedVal, { timeout: 40000 })
.should('be.visible');
});
cy.log('**_Checking Vega Wallet Associated Value = COMPLETE_**');
}
);
// ----------------------------------------------------------------------
Cypress.Commands.add('ethereum_wallet_connect', function () {
cy.log('**_Connecting Eth Wallet_**');
cy.log('👉 **_Connecting Eth Wallet_**');
cy.get(wallet.ethWalletConnectToEth).within(() => {
cy.contains('Connect Ethereum wallet to associate $VEGA')
.should('be.visible')
@ -272,7 +269,6 @@ Cypress.Commands.add('ethereum_wallet_connect', function () {
// this check is required since it ensures the wallet is fully (not partially) loaded
cy.contains('Locked', { timeout: 10000 }).should('be.visible');
});
cy.log('**_Connecting Eth Wallet = COMPLETE_**');
});
// ----------------------------------------------------------------------
@ -280,7 +276,7 @@ Cypress.Commands.add('ethereum_wallet_connect', function () {
Cypress.Commands.add(
'ethereum_wallet_associate_tokens',
function (amount, approve) {
cy.log(`**_Associating ${amount} tokens from Eth Wallet_**`);
cy.log(`👉 **_Associating ${amount} tokens via Eth Wallet_**`);
cy.get(wallet.ethWallet).within(() =>
cy.get(wallet.ethWalletAssociate).click()
);
@ -304,15 +300,14 @@ Cypress.Commands.add(
.click();
cy.contains('can now participate in governance and nominate a validator', {
timeout: 60000,
});
cy.log('**_Associating tokens from Eth Wallet = COMPLETE_**');
}).should('be.visible');
}
);
// ----------------------------------------------------------------------
Cypress.Commands.add('ethereum_wallet_disassociate_tokens', function (amount) {
cy.log(`**_Disassociating ${amount} tokens from Eth Wallet_**`);
cy.log(`👉 **_Disassociating ${amount} tokens via Eth Wallet_**`);
cy.get(wallet.ethWallet).within(() =>
cy.get(wallet.ethWalletDisassociate).click()
);
@ -324,14 +319,13 @@ Cypress.Commands.add('ethereum_wallet_disassociate_tokens', function (amount) {
.click();
cy.contains(`${amount} $VEGA tokens have been returned to Ethereum wallet`, {
timeout: 60000,
});
cy.log('**_Disassociating tokens from Eth Wallet = COMPLETE_**');
}).should('be.visible');
});
// ----------------------------------------------------------------------
Cypress.Commands.add('ethereum_wallet_disassociate_all_tokens', function () {
cy.log('**_Disassociating tokens from Eth Wallet_**');
cy.log('👉 **_Disassociating all tokens via Eth Wallet_**');
cy.get(wallet.ethWallet).within(() =>
cy.get(wallet.ethWalletDisassociate).click()
);
@ -340,8 +334,7 @@ Cypress.Commands.add('ethereum_wallet_disassociate_all_tokens', function () {
cy.get(staking.tokenInputSubmit, { timeout: 10000 }).click();
cy.contains('$VEGA tokens have been returned to Ethereum wallet', {
timeout: 60000,
});
cy.log('**_Disassociating tokens from Eth Wallet = Complete_**');
}).should('be.visible');
});
// ----------------------------------------------------------------------
@ -350,14 +343,14 @@ Cypress.Commands.add(
'ethereum_wallet_check_associated_vega_key_value_is',
function (vegaShortPublicKey, expectedVal) {
cy.log(
`**_Checking Eth Wallet Vega Key Associated Value is ${expectedVal} for key ${vegaShortPublicKey}_**`
`**_Checking Eth Wallet - Vega Key Associated Value is ${expectedVal} for key ${vegaShortPublicKey}_**`
);
cy.get(wallet.ethWallet).within(() => {
cy.contains(vegaShortPublicKey, { timeout: 20000 })
.parent()
.contains(expectedVal, { timeout: 40000 });
.contains(expectedVal, { timeout: 40000 })
.should('be.visible');
});
cy.log('**_Checking Eth Wallet Vega Key Associated Value = COMPLETE_**');
}
);
@ -366,12 +359,9 @@ Cypress.Commands.add(
Cypress.Commands.add(
'ethereum_wallet_check_associated_vega_key_is_no_longer_showing',
function (vegaShortPublicKey) {
cy.log(`**_Checking Eth Wallet Vega Key Associated is not showing_**`);
cy.log(`👉 **_Checking Eth Wallet - Vega Key Associated is not showing_**`);
cy.get(wallet.ethWallet).within(() => {
cy.contains(vegaShortPublicKey, { timeout: 20000 }).should('not.exist');
});
cy.log(
'**_Checking Eth Wallet Vega Key Associated is not showing = COMPLETE_**'
);
}
);