test: completion of first iteration of happy paths

This commit is contained in:
AndyWhiteVega 2022-07-01 12:13:14 +01:00
parent 2e15e4dc2e
commit 63f219944d
8 changed files with 253 additions and 235 deletions

View File

@ -11,10 +11,6 @@ NX_VEGA_REST=http://localhost:3029
NX_ETHEREUM_CHAIN_ID=1440 NX_ETHEREUM_CHAIN_ID=1440
NX_ETH_URL_CONNECT=1 NX_ETH_URL_CONNECT=1
NX_ETH_WALLET_MNEMONIC=ozone access unlock valid olympic save include omit supply green clown session NX_ETH_WALLET_MNEMONIC=ozone access unlock valid olympic save include omit supply green clown session
NX_ETH_WALLET_PUBLIC_KEY=0xEe7D375bcB50C26d52E1A4a472D8822A2A22d94F
NX_ETH_STAKING_BRIDGE_CONTRACT_ADDRESS=0x9135f5afd6F055e731bca2348429482eE614CFfA
NX_VEGA_TOKEN_CONTRACT_ADDRESS=0xF41bD86d462D36b997C0bbb4D97a0a3382f205B7
NX_VEGA_TOKEN_ADDRESS=0x67175Da1D5e966e40D11c4B2519392B2058373de
NX_LOCAL_PROVIDER_URL=http://localhost:8545/ NX_LOCAL_PROVIDER_URL=http://localhost:8545/
#Test configuration variables #Test configuration variables

View File

@ -14,4 +14,18 @@ module.exports = defineConfig({
screenshotsFolder: '../../dist/cypress/apps/explorer-e2e/screenshots', screenshotsFolder: '../../dist/cypress/apps/explorer-e2e/screenshots',
chromeWebSecurity: false, chromeWebSecurity: false,
}, },
env: {
eth_provider_url: 'http://localhost:8545/',
eth_wallet_public_key: '0xEe7D375bcB50C26d52E1A4a472D8822A2A22d94F',
eth_staking_bridge_contract_address: '0x9135f5afd6F055e731bca2348429482eE614CFfA',
vega_wallet_name : 'capsule_wallet',
vega_wallet_location : '~/.vegacapsule/testnet/wallet',
vega_wallet_passphrase : '123',
vega_wallet_mnemonic: 'ozone access unlock valid olympic save include omit supply green clown session',
vega_wallet_public_key:'02eceaba4df2bef76ea10caf728d8a099a2aa846cced25737cccaa9812342f65',
vega_wallet_public_key_short:'02ecea…2f65',
vega_token_contract_address:'0xF41bD86d462D36b997C0bbb4D97a0a3382f205B7',
vega_token_address:'0x67175Da1D5e966e40D11c4B2519392B2058373de'
}
}); });

View File

@ -0,0 +1 @@
ozone access unlock valid olympic save include omit supply green clown session

View File

@ -0,0 +1,141 @@
/// <reference types="cypress" />
import navigation from '../../locators/navigation.locators';
import staking from '../../locators/staking.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.vega_wallet_import();
cy.visit('/');
cy.get(navigation.section, { timeout: 20000 }).should('be.visible');
cy.vega_wallet_connect();
cy.vega_wallet_set_specified_approval_amount_and_reload('1000');
cy.get(navigation.section, { timeout: 20000 }).should('be.visible');
cy.ethereum_wallet_connect();
cy.get(navigation.staking).first().click();
cy.get(navigation.spinner, { timeout: 20000 }).should('not.exist');
cy.get(staking.validatorNames).first().invoke('text').as('validatorName');
cy.wrap(Cypress.env('vega_wallet_public_key_short')).as('vegaPublicKeyShort');
});
describe('Vega wallet - contains VEGA tokens', function () {
beforeEach('teardown wallet & drill into a specific validator', function () {
cy.vega_wallet_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('Your Stake On Node (This Epoch)').should('be.visible');
})
it('Able to associate tokens', function () {
cy.ethereum_wallet_associate_tokens('2');
cy.ethereum_wallet_check_associated_vega_key_value_is(this.vegaPublicKeyShort, '2.000000000000000000');
cy.vega_wallet_check_associated_value_is('2.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(this.vegaPublicKeyShort, '1,001.000000000000000000');
cy.vega_wallet_check_associated_value_is('1,001.000000000000000000');
})
it('Able to disassociate a partial amount of tokens currently associated', function () {
cy.ethereum_wallet_associate_tokens('2');
cy.vega_wallet_check_associated_value_is('2.000000000000000000');
cy.ethereum_wallet_disassociate_tokens('1');
cy.ethereum_wallet_check_associated_vega_key_value_is(this.vegaPublicKeyShort, '1.000000000000000000');
cy.vega_wallet_check_associated_value_is('1.000000000000000000');
})
it('Able to disassociate all tokens', function () {
cy.ethereum_wallet_associate_tokens('2');
cy.vega_wallet_check_associated_value_is('2.000000000000000000');
cy.ethereum_wallet_disassociate_all_tokens();
cy.ethereum_wallet_check_associated_vega_key_is_no_longer_showing(this.vegaPublicKeyShort);
cy.vega_wallet_check_associated_value_is('0.000000000000000000');
})
it('Able to stake against a validator', function () {
cy.ethereum_wallet_associate_tokens('3');
cy.vega_wallet_check_unstaked_value_is('3.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('2');
cy.vega_wallet_check_validator_stake_next_epoch_value_is(this.validatorName, '2.000000000000000000');
cy.vega_wallet_check_unstaked_value_is('1.000000000000000000');
});
it('Able to remove stake against a validator', function () {
cy.ethereum_wallet_associate_tokens('3');
cy.vega_wallet_check_unstaked_value_is('3.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('1');
cy.staking_validator_page_check_stake_next_epoch_value('1.0');
cy.vega_wallet_check_validator_stake_next_epoch_value_is(this.validatorName, '1.000000000000000000');
cy.vega_wallet_check_unstaked_value_is('2.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('0.0');
cy.vega_wallet_check_validator_stake_next_epoch_value_is(this.validatorName, '0.000000000000000000');
cy.vega_wallet_check_unstaked_value_is('3.000000000000000000');
});
it('Unable to remove a stake with a negative value for a validator', function () {
cy.ethereum_wallet_associate_tokens('3');
cy.vega_wallet_check_unstaked_value_is('3.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('2');
cy.staking_validator_page_check_stake_next_epoch_value('2.0');
cy.vega_wallet_check_validator_stake_next_epoch_value_is(this.validatorName, '2.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.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 })
.and('contain', `Remove -0.1 $VEGA tokens at the end of epoch`)
.and('be.visible');
});
it('Unable to remove a stake greater than staked amount next epoch for a validator', function () {
cy.ethereum_wallet_associate_tokens('3');
cy.vega_wallet_check_unstaked_value_is('3.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('2');
cy.staking_validator_page_check_stake_next_epoch_value('2.0');
cy.vega_wallet_check_validator_stake_next_epoch_value_is(this.validatorName, '2.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.get(staking.removeStakeRadioButton).click({ force: true });
cy.get(staking.tokenAmountInput).type(4);
cy.contains('Waiting for next epoch to start', { timeout: 10000 });
cy.get(staking.tokenInputSubmit)
.should('be.disabled', { timeout: 8000 })
.and('contain',`Remove 4 $VEGA tokens at the end of epoch`)
.and('be.visible');
});
});
});

View File

@ -1,141 +0,0 @@
/// <reference types="cypress" />
import navigation from '../../locators/navigation.locators';
import staking from '../../locators/staking.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.vega_wallet_create();
cy.visit('/');
cy.get(navigation.section, { timeout: 20000 }).should('be.visible');
cy.ethereum_wallet_connect();
cy.vega_wallet_connect();
cy.vega_wallet_set_approval_amount_to('1000');
cy.get(navigation.staking).first().click();
cy.get(navigation.spinner, { timeout: 20000 }).should('not.exist');
cy.get(staking.validatorNames).first().invoke('text').as('validatorName');
});
describe('Vega wallet - contains VEGA tokens', function () {
beforeEach('teardown wallet & drill into a specific validator', function () {
cy.vega_wallet_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('Your Stake On Node (This Epoch)').should('be.visible');
})
it('Able to associate tokens - having previously approved', function () {
cy.ethereum_wallet_associateTokens('2');
cy.vega_wallet_check_associatedValue_is('2.000000000000000000');
})
it('Able to associate more tokens for then the approved amount of 1000 - requires re-approval', function () {
cy.ethereum_wallet_associateTokens('1001', 'Approve');
cy.vega_wallet_check_associatedValue_is('1,001.000000000000000000');
})
it('Able to disassociate some tokens - but not all', function () {
cy.ethereum_wallet_associateTokens('2');
cy.vega_wallet_check_associatedValue_is('2.000000000000000000');
cy.ethereum_wallet_disassociateTokens('1');
cy.vega_wallet_check_associatedValue_is('1.000000000000000000');
})
it('Able to disassociate all tokens', function () {
cy.ethereum_wallet_associateTokens('2');
cy.vega_wallet_check_associatedValue_is('2.000000000000000000');
cy.ethereum_wallet_disassociateAllTokens();
cy.vega_wallet_check_associatedValue_is('0.000000000000000000');
})
it('Able to stake against a validator', function () {
cy.ethereum_wallet_associateTokens('3');
cy.vega_wallet_check_unstakedValue_is('3.000000000000000000');
cy.get('button').contains('Select a validator to nominate').click();
cy.get(staking.validatorNames).contains(this.validatorName).click();
cy.staking_validator_page_addStake('2');
cy.vega_wallet_check_validator_stakeNextEpochValue_is(this.validatorName, '2.000000000000000000');
cy.vega_wallet_check_unstakedValue_is('1.000000000000000000');
});
it('Able to remove stake against a validator', function () {
cy.ethereum_wallet_associateTokens('3');
cy.vega_wallet_check_unstakedValue_is('3.000000000000000000');
cy.get('button').contains('Select a validator to nominate').click();
cy.get(staking.validatorNames).contains(this.validatorName).click();
cy.staking_validator_page_addStake('1');
cy.staking_validator_page_check_stakeNextEpochValue('1.0');
cy.vega_wallet_check_validator_stakeNextEpochValue_is(this.validatorName, '1.000000000000000000');
cy.vega_wallet_check_unstakedValue_is('2.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_stakeNextEpochValue('0.0');
cy.vega_wallet_check_validator_stakeNextEpochValue_is(this.validatorName, '0.000000000000000000');
cy.vega_wallet_check_unstakedValue_is('3.000000000000000000');
});
it('Unable to remove a stake with a negative value for a validator', function () {
cy.ethereum_wallet_associateTokens('3');
cy.vega_wallet_check_unstakedValue_is('3.000000000000000000');
cy.get('button').contains('Select a validator to nominate').click();
cy.get(staking.validatorNames).contains(this.validatorName).click();
cy.staking_validator_page_addStake('2');
cy.staking_validator_page_check_stakeNextEpochValue('2.0');
cy.vega_wallet_check_validator_stakeNextEpochValue_is(this.validatorName, '2.000000000000000000');
cy.vega_wallet_check_unstakedValue_is('1.000000000000000000');
cy.get(navigation.staking).first().click();
cy.get(staking.validatorNames).contains(this.validatorName).click();
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 })
.and('contain', `Remove -0.1 $VEGA tokens at the end of epoch`)
.and('be.visible');
});
it('Unable to remove a stake greater than staked amount next epoch for a validator', function () {
cy.ethereum_wallet_associateTokens('3');
cy.vega_wallet_check_unstakedValue_is('3.000000000000000000');
cy.get('button').contains('Select a validator to nominate').click();
cy.get(staking.validatorNames).contains(this.validatorName).click();
cy.staking_validator_page_addStake('2');
cy.staking_validator_page_check_stakeNextEpochValue('2.0');
cy.vega_wallet_check_validator_stakeNextEpochValue_is(this.validatorName, '2.000000000000000000');
cy.vega_wallet_check_unstakedValue_is('1.000000000000000000');
cy.get(navigation.staking).first().click();
cy.get(staking.validatorNames).contains(this.validatorName).click();
cy.get(staking.removeStakeRadioButton).click({ force: true });
cy.get(staking.tokenAmountInput).type(4);
cy.contains('Waiting for next epoch to start', { timeout: 10000 });
cy.get(staking.tokenInputSubmit)
.should('be.disabled', { timeout: 8000 })
.and('contain',`Remove 4 $VEGA tokens at the end of epoch`)
.and('be.visible');
});
it('Able to associate more tokens for then the approved amount of 1000 - requires re-approval', function () {
cy.ethereum_wallet_associateTokens('1001', 'Approve');
cy.vega_wallet_check_associatedValue_is('1,001.000000000000000000');
})
});
});

View File

@ -3,11 +3,10 @@ import staking from '../locators/staking.locators';
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
Cypress.Commands.add( Cypress.Commands.add(
'staking_validator_page_check_stakeNextEpochValue', 'staking_validator_page_check_stake_next_epoch_value',
function (expectedVal) { function (expectedVal) {
cy.get(staking.stakeNextEpochValue, { timeout: 10000 }).contains( cy.get(staking.stakeNextEpochValue, { timeout: 10000 }).contains(
expectedVal, expectedVal, { timeout: 10000 }
{ timeout: 10000 }
); );
} }
); );
@ -27,7 +26,7 @@ Cypress.Commands.add(
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
Cypress.Commands.add('staking_validator_page_addStake', function (stake) { Cypress.Commands.add('staking_validator_page_add_stake', function (stake) {
cy.get(staking.addStakeRadioButton).click({ force: true }); cy.get(staking.addStakeRadioButton).click({ force: true });
cy.get(staking.tokenAmountInput).type(stake); cy.get(staking.tokenAmountInput).type(stake);
cy.contains('Waiting for next epoch to start', { timeout: 10000 }); cy.contains('Waiting for next epoch to start', { timeout: 10000 });

View File

@ -8,44 +8,36 @@ import {
import { ethers, Wallet } from 'ethers'; import { ethers, Wallet } from 'ethers';
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
const vegaWalletName = Cypress.env('VEGA_WALLET_NAME');
const vegaWalletLocation = Cypress.env('VEGA_WALLET_LOCATION');
const vegaWalletPassphrase = Cypress.env('VEGA_WALLET_PASSPHRASE');
const ethPubKey = '0xEe7D375bcB50C26d52E1A4a472D8822A2A22d94F'; const vegaWalletName = Cypress.env('vega_wallet_name');
const ethProviderUrl = 'http://localhost:8545/'; const vegaWalletLocation = Cypress.env('vega_wallet_location');
const ethStakingBridgeContractAddress = const vegaWalletPassphrase = Cypress.env('vega_wallet_passphrase');
'0x9135f5afd6F055e731bca2348429482eE614CFfA'; const vegaWalletMnemonic = Cypress.env('vega_wallet_mnemonic');
const ethWalletMnemonic = const vegaWalletPubKey = Cypress.env('vega_wallet_public_key');
'ozone access unlock valid olympic save include omit supply green clown session'; const vegaTokenContractAddress = Cypress.env('vega_token_contract_address');
const vegaPubKey = const vegaTokenAddress = Cypress.env('vega_token_address');
'fc8661e5550f277dfae5ca2bb38a7524072f84ea56198edab35f81a733031b06'; const ethWalletPubKey = Cypress.env('eth_wallet_public_key')
const vegaTokenContractAddress = '0xF41bD86d462D36b997C0bbb4D97a0a3382f205B7'; const ethStakingBridgeContractAddress = Cypress.env('eth_staking_bridge_contract_address')
const vegaTokenAddress = '0x67175Da1D5e966e40D11c4B2519392B2058373de'; const ethProviderUrl = Cypress.env('eth_provider_url');
const queryUrl = 'http://localhost:3028/query';
const getAccount = (number = 0) => `m/44'/60'/0'/0/${number}`; const getAccount = (number = 0) => `m/44'/60'/0'/0/${number}`;
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
Cypress.Commands.add('vega_wallet_teardown', function () { Cypress.Commands.add('vega_wallet_teardown', function () {
cy.log('**_Connecting Vega Wallet_**');
cy.wrap( cy.wrap(
Wallet.fromMnemonic(ethWalletMnemonic, getAccount(0)).privateKey Wallet.fromMnemonic(vegaWalletMnemonic, getAccount(0)).privateKey
).then((privateKey) => { ).then((privateKey) => {
cy.vega_wallet_teardown_staking(privateKey); cy.vega_wallet_teardown_staking(privateKey);
cy.vega_wallet_teardown_vesting(privateKey); cy.vega_wallet_teardown_vesting(privateKey);
}); });
cy.intercept('POST', queryUrl).as('queryGrab'); cy.log('**_Connecting Vega Wallet = COMPLETE_**');
// Wait for a couple of queries to complete so wallet UI takes changes on board
cy.wait(['@queryGrab', '@queryGrab'], { timeout: 10000 });
// Then we turn off our intercept - so that we can use it again in the future
cy.intercept('POST', queryUrl, (req) => req.continue());
cy.log('**Connecting Vega Wallet = COMPLETE**');
}); });
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
Cypress.Commands.add('vega_wallet_teardown_staking', function (privateKey) { Cypress.Commands.add('vega_wallet_teardown_staking', function (privateKey) {
cy.log('**Tearing down staking tokens if required**'); cy.log('**_Tearing down staking tokens if required_**');
cy.wrap(new ethers.providers.JsonRpcProvider({ url: ethProviderUrl }), { cy.wrap(new ethers.providers.JsonRpcProvider({ url: ethProviderUrl }), {
log: false, log: false,
}).as('provider'); }).as('provider');
@ -56,30 +48,30 @@ Cypress.Commands.add('vega_wallet_teardown_staking', function (privateKey) {
log: false, log: false,
}).as('stakingBridge'); }).as('stakingBridge');
cy.get('@stakingBridge', { log: false }).then((stakingBridge) => { cy.get('@stakingBridge', { log: false }).then((stakingBridge) => {
cy.wrap(stakingBridge.stakeBalance(ethPubKey, vegaPubKey), { cy.wrap(stakingBridge.stakeBalance(ethWalletPubKey, vegaWalletPubKey), {
timeout: 40000, timeout: 40000,
log: false, log: false,
}).then((stake_amount) => { }).then((stake_amount) => {
if (String(stake_amount) != '0') { if (String(stake_amount) != '0') {
cy.wrap(stakingBridge.removeStake(stake_amount, vegaPubKey), { cy.wrap(stakingBridge.removeStake(stake_amount, vegaWalletPubKey), {
timeout: 40000, timeout: 40000,
log: false, log: false,
}).then((tx) => { }).then((tx) => {
cy.wrap(tx.wait(1), { timeout: 40000, log: false }); cy.wrap(tx.wait(1), { timeout: 40000, log: false });
cy.vega_wallet_check_associatedValue_is('0.000000000000000000'); cy.vega_wallet_check_associated_value_is('0.000000000000000000');
}); });
} }
}); });
}); });
}); });
}); });
cy.log('**Tearing down staking tokens = COMPLETE**'); cy.log('**_Tearing down staking tokens = COMPLETE_**');
}); });
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
Cypress.Commands.add('vega_wallet_teardown_vesting', function (privateKey) { Cypress.Commands.add('vega_wallet_teardown_vesting', function (privateKey) {
cy.log('**Tearing down vesting tokens if required**'); cy.log('**_Tearing down vesting tokens if required_**');
cy.wrap(new ethers.providers.JsonRpcProvider({ url: ethProviderUrl }), { cy.wrap(new ethers.providers.JsonRpcProvider({ url: ethProviderUrl }), {
log: false, log: false,
}).as('provider'); }).as('provider');
@ -90,12 +82,12 @@ Cypress.Commands.add('vega_wallet_teardown_vesting', function (privateKey) {
log: false, log: false,
}).as('vesting'); }).as('vesting');
cy.get('@vesting', { log: false }).then((vesting) => { cy.get('@vesting', { log: false }).then((vesting) => {
cy.wrap(vesting.stakeBalance(ethPubKey, vegaPubKey), { cy.wrap(vesting.stakeBalance(ethWalletPubKey, vegaWalletPubKey), {
timeout: 40000, timeout: 40000,
log: false, log: false,
}).then((vesting_amount) => { }).then((vesting_amount) => {
if (String(vesting_amount) != '0') { if (String(vesting_amount) != '0') {
cy.wrap(vesting.removeStake(vesting_amount, vegaPubKey), { cy.wrap(vesting.removeStake(vesting_amount, vegaWalletPubKey), {
timeout: 40000, timeout: 40000,
log: false, log: false,
}).then((tx) => { }).then((tx) => {
@ -106,16 +98,16 @@ Cypress.Commands.add('vega_wallet_teardown_vesting', function (privateKey) {
}); });
}); });
}); });
cy.log('**Tearing down vesting tokens = COMPLETE**'); cy.log('**_Tearing down vesting tokens = COMPLETE_**');
}); });
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
Cypress.Commands.add( Cypress.Commands.add(
'vega_wallet_set_approval_amount_to', 'vega_wallet_set_specified_approval_amount_and_reload',
function (resetAmount) { function (resetAmount) {
cy.log(`**Setting token approval amount to ${resetAmount}**`); cy.log(`**_Setting token approval amount to ${resetAmount}_**`);
cy.wrap(Wallet.fromMnemonic(ethWalletMnemonic, getAccount(0)).privateKey, { cy.wrap(Wallet.fromMnemonic(vegaWalletMnemonic, getAccount(0)).privateKey, {
log: false, log: false,
}).then((privateKey) => { }).then((privateKey) => {
cy.wrap(new ethers.providers.JsonRpcProvider({ url: ethProviderUrl }), { cy.wrap(new ethers.providers.JsonRpcProvider({ url: ethProviderUrl }), {
@ -141,19 +133,17 @@ Cypress.Commands.add(
}); });
}); });
}); });
cy.intercept('POST', queryUrl).as('queryGrab'); cy.log(`**_Setting token approval amount to ${resetAmount} = COMPLETE_**`);
// Wait for a couple of queries to complete so wallet UI takes changes on board cy.log('**_Reloading app for token approval setting to take affect_**')
cy.wait(['@queryGrab', '@queryGrab'], { timeout: 10000 }); cy.reload();
// Then we turn off our intercept - so that we can use it again in the future cy.log('**_Reloading app for token approval setting to take affect = COMPLETE_**')
cy.intercept('POST', queryUrl, (req) => req.continue());
cy.log(`**Setting token approval amount to ${resetAmount} = COMPLETE**`);
} }
); );
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
Cypress.Commands.add('vega_wallet_teardown_ui', function () { Cypress.Commands.add('vega_wallet_teardown_ui', function () {
cy.log('**Tearing down associated tokens from Vega Wallet**'); cy.log('**_Tearing down associated tokens from Vega Wallet_**');
let vegaPresentInWallet = false; let vegaPresentInWallet = false;
cy.get(wallet.vegawallet) cy.get(wallet.vegawallet)
.within(() => { .within(() => {
@ -167,39 +157,36 @@ Cypress.Commands.add('vega_wallet_teardown_ui', function () {
}) })
.then(() => { .then(() => {
if (vegaPresentInWallet == true) { if (vegaPresentInWallet == true) {
cy.root().ethereum_wallet_disassociateAllTokens(); cy.root().ethereum_wallet_disassociate_all_tokens();
cy.vega_wallet_check_associatedValue_is('0.0'); cy.vega_wallet_check_associated_value_is('0.0');
} else { } else {
cy.log('**No need to teardown vega wallet - wallet empty**'); cy.log('**_No need to teardown vega wallet - wallet empty_**');
} }
}); });
cy.log('**Tearing down associated tokens from Vega Wallet = COMPLETE**'); cy.log('**_Tearing down associated tokens from Vega Wallet = COMPLETE_**');
}); });
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
Cypress.Commands.add('vega_wallet_create', function () { Cypress.Commands.add('vega_wallet_import', function () {
cy.log('**Initializing Vega Wallet** ' + vegaWalletName); cy.log(`**_Importing Vega Wallet ${vegaWalletName}_**`);
cy.exec(`vegawallet init -f --home ${vegaWalletLocation}`); cy.exec(`vegawallet init -f --home ${vegaWalletLocation}`);
cy.exec( cy.exec(
`echo ${vegaWalletPassphrase} > ./src/fixtures/vegaWalletPassphrase.txt` `vegawallet import -w ${vegaWalletName} --recovery-phrase-file ./src/fixtures/wallet/recovery -p ./src/fixtures/wallet/passphrase --home ~/.vegacapsule/testnet/wallet`,
);
cy.exec(
`vegawallet create -w ${vegaWalletName} -p ./src/fixtures//vegaWalletPassphrase.txt --home ${vegaWalletLocation}`,
{ failOnNonZeroExit: false } { failOnNonZeroExit: false }
).then((result) => cy.log(result.stderr)); )
cy.exec( cy.exec(
`vegawallet service run --network DV --automatic-consent --home ${vegaWalletLocation}` `vegawallet service run --network DV --automatic-consent --home ${vegaWalletLocation}`
); );
cy.log('**Initializing Vega Wallet = COMPLETE**'); cy.log('**_Importing Vega Wallet = COMPLETE_**');
}); });
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
Cypress.Commands.add('vega_wallet_connect', function () { Cypress.Commands.add('vega_wallet_connect', function () {
cy.log('**Connecting Vega Wallet**'); cy.log('**_Connecting Vega Wallet_**');
cy.intercept('POST', queryUrl).as('queryGrab'); // cy.intercept('POST', queryUrl).as('queryGrab');
cy.get(wallet.vegawallet).within(() => { cy.get(wallet.vegawallet).within(() => {
cy.get('button') cy.get('button')
.contains('Connect Vega wallet to use associated $VEGA') .contains('Connect Vega wallet to use associated $VEGA')
@ -217,67 +204,61 @@ Cypress.Commands.add('vega_wallet_connect', function () {
}); });
cy.contains(`${vegaWalletName} key`, { timeout: 20000 }).should('be.visible'); cy.contains(`${vegaWalletName} key`, { timeout: 20000 }).should('be.visible');
// We have to wait for two queries to finish cy.log('**_Connecting Vega Wallet = COMPLETE_**');
cy.wait('@queryGrab', { timeout: 10000 }).wait('@queryGrab', {
timeout: 10000,
});
// Then we turn off our intercept - so that we can use it again in the future
cy.intercept('POST', queryUrl, (req) => req.continue());
cy.log('**Connecting Vega Wallet = COMPLETE**');
}); });
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
Cypress.Commands.add( Cypress.Commands.add(
'vega_wallet_check_validator_stakeNextEpochValue_is', 'vega_wallet_check_validator_stake_next_epoch_value_is',
function (validatorName, expectedVal) { function (validatorName, expectedVal) {
cy.log( cy.log(
`**Checking Stake Next Epoch Value for ${validatorName} is ${expectedVal}**` `**_Checking Stake Next Epoch Value for ${validatorName} is ${expectedVal}_**`
); );
cy.get(wallet.vegawallet).within(() => { cy.get(wallet.vegawallet).within(() => {
cy.contains(`${validatorName} (Next epoch)`) cy.contains(`${validatorName} (Next epoch)`, { timeout: 40000 })
.siblings() .siblings()
.contains(expectedVal, { timeout: 10000 }); .contains(expectedVal, { timeout: 40000 });
}); });
cy.log('**Checking Stake Next Epoch Value = Complete**'); cy.log('**_Checking Stake Next Epoch Value = Complete_**');
} }
); );
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
Cypress.Commands.add( Cypress.Commands.add(
'vega_wallet_check_unstakedValue_is', 'vega_wallet_check_unstaked_value_is',
function (expectedVal) { 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.get(wallet.vegawallet).within(() => {
cy.contains('Unstaked', { timeout: 20000 }) cy.contains('Unstaked', { timeout: 40000 })
.siblings() .siblings()
.contains(expectedVal, { timeout: 10000 }); .contains(expectedVal, { timeout: 40000 });
}); });
cy.log('**Checking Vega Wallet Unstaked Value = Complete**'); cy.log('**_Checking Vega Wallet Unstaked Value = Complete_**');
} }
); );
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
Cypress.Commands.add( Cypress.Commands.add(
'vega_wallet_check_associatedValue_is', 'vega_wallet_check_associated_value_is',
function (expectedVal) { function (expectedVal) {
cy.log(`**Checking Vega Wallet Asscoiated Value is ${expectedVal}**`); cy.log(`**_Checking Vega Wallet Associated Value is ${expectedVal}_**`);
cy.get(wallet.vegawallet).within(() => { cy.get(wallet.vegawallet).within(() => {
cy.contains('Associated', { timeout: 20000 }) cy.contains('Associated', { timeout: 40000 })
.parent() .parent()
.siblings() .siblings()
.contains(expectedVal, { timeout: 40000 }); .contains(expectedVal, { timeout: 40000 });
}); });
cy.log('**Checking Vega Wallet Asscoiated Value = COMPLETE**'); cy.log('**_Checking Vega Wallet Associated Value = COMPLETE_**');
} }
); );
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
Cypress.Commands.add('ethereum_wallet_connect', function () { Cypress.Commands.add('ethereum_wallet_connect', function () {
cy.log('**Connecting Eth Wallet**'); cy.log('**_Connecting Eth Wallet_**');
cy.get(wallet.ethWalletConnectToEth).within(() => { cy.get(wallet.ethWalletConnectToEth).within(() => {
cy.contains('Connect Ethereum wallet to associate $VEGA') cy.contains('Connect Ethereum wallet to associate $VEGA')
.should('be.visible') .should('be.visible')
@ -289,15 +270,15 @@ Cypress.Commands.add('ethereum_wallet_connect', function () {
// this check is required since it ensures the wallet is fully (not partially) loaded // this check is required since it ensures the wallet is fully (not partially) loaded
cy.contains('Locked', { timeout: 10000 }).should('be.visible'); cy.contains('Locked', { timeout: 10000 }).should('be.visible');
}); });
cy.log('**Connecting Eth Wallet = COMPLETE**'); cy.log('**_Connecting Eth Wallet = COMPLETE_**');
}); });
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
Cypress.Commands.add( Cypress.Commands.add(
'ethereum_wallet_associateTokens', 'ethereum_wallet_associate_tokens',
function (amount, approve) { function (amount, approve) {
cy.log(`**Associating ${amount} tokens from Eth Wallet**`); cy.log(`**_Associating ${amount} tokens from Eth Wallet_**`);
cy.get(wallet.ethWallet).within(() => cy.get(wallet.ethWallet).within(() =>
cy.get(wallet.ethWalletAssociate).click() cy.get(wallet.ethWalletAssociate).click()
); );
@ -322,14 +303,14 @@ Cypress.Commands.add(
cy.contains('can now participate in governance and nominate a validator', { cy.contains('can now participate in governance and nominate a validator', {
timeout: 60000, timeout: 60000,
}); });
cy.log('**Associating tokens from Eth Wallet = COMPLETE**'); cy.log('**_Associating tokens from Eth Wallet = COMPLETE_**');
} }
); );
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
Cypress.Commands.add('ethereum_wallet_disassociateTokens', function (amount) { Cypress.Commands.add('ethereum_wallet_disassociate_tokens', function (amount) {
cy.log(`**Disassociating ${amount} tokens from Eth Wallet**`); cy.log(`**_Disassociating ${amount} tokens from Eth Wallet_**`);
cy.get(wallet.ethWallet).within(() => cy.get(wallet.ethWallet).within(() =>
cy.get(wallet.ethWalletDisassociate).click() cy.get(wallet.ethWalletDisassociate).click()
); );
@ -342,13 +323,13 @@ Cypress.Commands.add('ethereum_wallet_disassociateTokens', function (amount) {
cy.contains(`${amount} $VEGA tokens have been returned to Ethereum wallet`, { cy.contains(`${amount} $VEGA tokens have been returned to Ethereum wallet`, {
timeout: 60000, timeout: 60000,
}); });
cy.log('**Disassociating tokens from Eth Wallet = COMPLETE**'); cy.log('**_Disassociating tokens from Eth Wallet = COMPLETE_**');
}); });
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
Cypress.Commands.add('ethereum_wallet_disassociateAllTokens', function () { Cypress.Commands.add('ethereum_wallet_disassociate_all_tokens', function () {
cy.log('**Disassociating tokens from Eth Wallet**'); cy.log('**_Disassociating tokens from Eth Wallet_**');
cy.get(wallet.ethWallet).within(() => cy.get(wallet.ethWallet).within(() =>
cy.get(wallet.ethWalletDisassociate).click() cy.get(wallet.ethWalletDisassociate).click()
); );
@ -358,7 +339,34 @@ Cypress.Commands.add('ethereum_wallet_disassociateAllTokens', function () {
cy.contains('$VEGA tokens have been returned to Ethereum wallet', { cy.contains('$VEGA tokens have been returned to Ethereum wallet', {
timeout: 60000, timeout: 60000,
}); });
cy.log('**Disassociating tokens from Eth Wallet = Complete**'); cy.log('**_Disassociating tokens from Eth Wallet = Complete_**');
}); });
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
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}_**`);
cy.get(wallet.ethWallet).within(() => {
cy.contains(vegaShortPublicKey, { timeout: 20000 })
.parent()
.contains(expectedVal, { timeout: 40000 });
});
cy.log('**_Checking Eth Wallet Vega Key Associated Value = COMPLETE_**');
}
);
// ----------------------------------------------------------------------
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.get(wallet.ethWallet).within(() => {
cy.contains(vegaShortPublicKey, { timeout: 20000 })
.should('not.exist')
});
cy.log('**_Checking Eth Wallet Vega Key Associated is not showing = COMPLETE_**');
}
);