test: lint

This commit is contained in:
AndyWhiteVega 2022-07-06 14:25:36 +01:00
parent abc08664e2
commit 187b373cab
12 changed files with 238 additions and 134 deletions

View File

@ -17,14 +17,17 @@ module.exports = defineConfig({
env: { env: {
ethProviderUrl: 'http://localhost:8545/', ethProviderUrl: 'http://localhost:8545/',
ethWalletPublicKey: '0xEe7D375bcB50C26d52E1A4a472D8822A2A22d94F', ethWalletPublicKey: '0xEe7D375bcB50C26d52E1A4a472D8822A2A22d94F',
ethStakingBridgeContractAddress: '0x9135f5afd6F055e731bca2348429482eE614CFfA', ethStakingBridgeContractAddress:
'0x9135f5afd6F055e731bca2348429482eE614CFfA',
vegaWalletName: 'capsule_wallet', vegaWalletName: 'capsule_wallet',
vegaWalletLocation: '~/.vegacapsule/testnet/wallet', vegaWalletLocation: '~/.vegacapsule/testnet/wallet',
vegaWalletPassphrase: '123', vegaWalletPassphrase: '123',
vegaWalletMnemonic: 'ozone access unlock valid olympic save include omit supply green clown session', vegaWalletMnemonic:
vegaWalletPublicKey: '02eceaba4df2bef76ea10caf728d8a099a2aa846cced25737cccaa9812342f65', 'ozone access unlock valid olympic save include omit supply green clown session',
vegaWalletPublicKey:
'02eceaba4df2bef76ea10caf728d8a099a2aa846cced25737cccaa9812342f65',
vegaWalletPublicKeyShort: '02ecea…2f65', vegaWalletPublicKeyShort: '02ecea…2f65',
vegaTokenContractAddress: '0xF41bD86d462D36b997C0bbb4D97a0a3382f205B7', vegaTokenContractAddress: '0xF41bD86d462D36b997C0bbb4D97a0a3382f205B7',
vegaTokenAddress: '0x67175Da1D5e966e40D11c4B2519392B2058373de' vegaTokenAddress: '0x67175Da1D5e966e40D11c4B2519392B2058373de',
} },
}); });

View File

@ -7,7 +7,7 @@ import '../../support/vega-wallet.functions';
import '../../support/eth-wallet.functions'; import '../../support/eth-wallet.functions';
import '../../support/wallet-teardown.functions'; import '../../support/wallet-teardown.functions';
const vegaWalletPublicKeyShort = Cypress.env("vegaWalletPublicKeyShort"); const vegaWalletPublicKeyShort = Cypress.env('vegaWalletPublicKeyShort');
context('Staking Tab - with eth and vega wallets connected', function () { context('Staking Tab - with eth and vega wallets connected', function () {
before('visit staking tab and connect vega wallet', function () { before('visit staking tab and connect vega wallet', function () {
@ -22,7 +22,10 @@ context('Staking Tab - with eth and vega wallets connected', function () {
cy.get(navigation.staking).first().click(); cy.get(navigation.staking).first().click();
cy.get(navigation.spinner, { timeout: 20000 }).should('not.exist'); cy.get(navigation.spinner, { timeout: 20000 }).should('not.exist');
cy.get(staking.validatorNames).first().invoke('text').as('validatorName'); cy.get(staking.validatorNames).first().invoke('text').as('validatorName');
cy.get(staking.validatorNames).last().invoke('text').as('otherValidatorName'); cy.get(staking.validatorNames)
.last()
.invoke('text')
.as('otherValidatorName');
}); });
describe('Eth wallet - contains VEGA tokens', function () { describe('Eth wallet - contains VEGA tokens', function () {
@ -37,8 +40,11 @@ context('Staking Tab - with eth and vega wallets connected', function () {
it('Able to stake against a validator', function () { it('Able to stake against a validator', function () {
cy.staking_page_associate_tokens('3'); cy.staking_page_associate_tokens('3');
cy.vega_wallet_check_unstaked_value_is('3.000000000000000000'); cy.vega_wallet_check_unstaked_value_is('3.000000000000000000');
cy.ethereum_wallet_check_associated_value_is('3.0') cy.ethereum_wallet_check_associated_value_is('3.0');
cy.ethereum_wallet_check_associated_vega_key_value_is(vegaWalletPublicKeyShort,'3.000000000000000000'); cy.ethereum_wallet_check_associated_vega_key_value_is(
vegaWalletPublicKeyShort,
'3.000000000000000000'
);
cy.get('button').contains('Select a validator to nominate').click(); cy.get('button').contains('Select a validator to nominate').click();
cy.get(staking.validatorNames).contains(this.validatorName).click(); cy.get(staking.validatorNames).contains(this.validatorName).click();
@ -64,13 +70,15 @@ context('Staking Tab - with eth and vega wallets connected', function () {
cy.get(staking.validatorNames).contains(this.validatorName).click(); cy.get(staking.validatorNames).contains(this.validatorName).click();
cy.staking_validator_page_add_stake('2'); cy.staking_validator_page_add_stake('2');
cy.vega_wallet_check_validator_staked_value_is(this.validatorName, cy.vega_wallet_check_validator_staked_value_is(
this.validatorName,
'2.000000000000000000' '2.000000000000000000'
); );
cy.get(navigation.staking).first().click(); cy.get(navigation.staking).first().click();
cy.get(staking.validatorNames).contains(this.otherValidatorName).click(); cy.get(staking.validatorNames).contains(this.otherValidatorName).click();
cy.staking_validator_page_add_stake('1'); cy.staking_validator_page_add_stake('1');
cy.vega_wallet_check_validator_staked_value_is(this.otherValidatorName, cy.vega_wallet_check_validator_staked_value_is(
this.otherValidatorName,
'1.000000000000000000' '1.000000000000000000'
); );
cy.vega_wallet_check_unstaked_value_is('2.000000000000000000'); cy.vega_wallet_check_unstaked_value_is('2.000000000000000000');
@ -202,7 +210,7 @@ context('Staking Tab - with eth and vega wallets connected', function () {
}); });
it('Disassociating all tokens - removes all staked tokens', function () { it('Disassociating all tokens - removes all staked tokens', function () {
cy.staking_page_associate_tokens('3') cy.staking_page_associate_tokens('3');
cy.vega_wallet_check_unstaked_value_is('3.000000000000000000'); cy.vega_wallet_check_unstaked_value_is('3.000000000000000000');
cy.get('button').contains('Select a validator to nominate').click(); cy.get('button').contains('Select a validator to nominate').click();
@ -210,17 +218,22 @@ context('Staking Tab - with eth and vega wallets connected', function () {
cy.staking_validator_page_add_stake('2'); cy.staking_validator_page_add_stake('2');
cy.vega_wallet_check_unstaked_value_is('1.000000000000000000'); cy.vega_wallet_check_unstaked_value_is('1.000000000000000000');
cy.vega_wallet_check_validator_staked_value_is(this.validatorName, '2.000000000000000000'); cy.vega_wallet_check_validator_staked_value_is(
this.validatorName,
'2.000000000000000000'
);
cy.get(navigation.staking).first().click(); cy.get(navigation.staking).first().click();
cy.staking_page_disassociate_all_tokens(); cy.staking_page_disassociate_all_tokens();
cy.ethereum_wallet_check_associated_vega_key_is_no_longer_showing(vegaWalletPublicKeyShort); cy.ethereum_wallet_check_associated_vega_key_is_no_longer_showing(
vegaWalletPublicKeyShort
);
cy.ethereum_wallet_check_associated_value_is('0.0'); cy.ethereum_wallet_check_associated_value_is('0.0');
cy.vega_wallet_check_associated_value_is('0.000000000000000000'); cy.vega_wallet_check_associated_value_is('0.000000000000000000');
cy.vega_wallet_check_validator_no_longer_showing(this.validatorName); cy.vega_wallet_check_validator_no_longer_showing(this.validatorName);
}); });
it('Disassociating some tokens - prioritizes unstaked tokens', function () { it('Disassociating some tokens - prioritizes unstaked tokens', function () {
cy.staking_page_associate_tokens('3') cy.staking_page_associate_tokens('3');
cy.vega_wallet_check_unstaked_value_is('3.000000000000000000'); cy.vega_wallet_check_unstaked_value_is('3.000000000000000000');
cy.get('button').contains('Select a validator to nominate').click(); cy.get('button').contains('Select a validator to nominate').click();
@ -228,33 +241,46 @@ context('Staking Tab - with eth and vega wallets connected', function () {
cy.staking_validator_page_add_stake('2'); cy.staking_validator_page_add_stake('2');
cy.vega_wallet_check_unstaked_value_is('1.000000000000000000'); cy.vega_wallet_check_unstaked_value_is('1.000000000000000000');
cy.vega_wallet_check_validator_staked_value_is(this.validatorName, '2.000000000000000000'); cy.vega_wallet_check_validator_staked_value_is(
this.validatorName,
'2.000000000000000000'
);
cy.get(navigation.staking).first().click(); cy.get(navigation.staking).first().click();
cy.staking_page_disassociate_tokens('1'); cy.staking_page_disassociate_tokens('1');
cy.ethereum_wallet_check_associated_value_is('2.0'); cy.ethereum_wallet_check_associated_value_is('2.0');
cy.vega_wallet_check_associated_value_is('2.000000000000000000'); cy.vega_wallet_check_associated_value_is('2.000000000000000000');
cy.vega_wallet_check_validator_staked_value_is(this.validatorName, cy.vega_wallet_check_validator_staked_value_is(
this.validatorName,
'2.000000000000000000' '2.000000000000000000'
); );
}); });
}); });
cy.staking_validator_page_check_stake_next_epoch_value = (expectedVal) => { cy.staking_validator_page_check_stake_next_epoch_value = (expectedVal) => {
cy.highlight(`Checking Staking Page - Validator Stake Next Epoch Value is ${expectedVal}`); cy.highlight(
`Checking Staking Page - Validator Stake Next Epoch Value is ${expectedVal}`
);
cy.get(staking.stakeNextEpochValue, { timeout: 10000 }) cy.get(staking.stakeNextEpochValue, { timeout: 10000 })
.contains(expectedVal, { timeout: 10000 }) .contains(expectedVal, { timeout: 10000 })
.should('be.visible'); .should('be.visible');
}; };
cy.staking_validator_page_check_stake_this_epoch_value = (expectedVal) => { cy.staking_validator_page_check_stake_this_epoch_value = (expectedVal) => {
cy.highlight(`Checking Staking Page - Validator Stake This Epoch Value is ${expectedVal}`); cy.highlight(
`Checking Staking Page - Validator Stake This Epoch Value is ${expectedVal}`
);
cy.get(staking.stakeThisEpochValue, { timeout: 10000 }) cy.get(staking.stakeThisEpochValue, { timeout: 10000 })
.contains(expectedVal, { timeout: 10000 }) .contains(expectedVal, { timeout: 10000 })
.should('be.visible'); .should('be.visible');
}; };
cy.vega_wallet_check_validator_stake_next_epoch_value_is = (validatorName, expectedVal) => { cy.vega_wallet_check_validator_stake_next_epoch_value_is = (
cy.highlight(`Checking vega wallet - Stake Next Epoch Value for ${validatorName} is ${expectedVal}`); validatorName,
expectedVal
) => {
cy.highlight(
`Checking vega wallet - Stake Next Epoch Value for ${validatorName} is ${expectedVal}`
);
cy.get(wallet.vegawallet).within(() => { cy.get(wallet.vegawallet).within(() => {
cy.contains(`${validatorName} (Next epoch)`, { timeout: 40000 }) cy.contains(`${validatorName} (Next epoch)`, { timeout: 40000 })
.siblings() .siblings()
@ -263,8 +289,13 @@ context('Staking Tab - with eth and vega wallets connected', function () {
}); });
}; };
cy.vega_wallet_check_validator_stake_this_epoch_value_is = (validatorName, expectedVal) => { cy.vega_wallet_check_validator_stake_this_epoch_value_is = (
cy.highlight(`Checking vega wallet - Stake This Epoch Value for ${validatorName} is ${expectedVal}`); validatorName,
expectedVal
) => {
cy.highlight(
`Checking vega wallet - Stake This Epoch Value for ${validatorName} is ${expectedVal}`
);
cy.get(wallet.vegawallet).within(() => { cy.get(wallet.vegawallet).within(() => {
cy.contains(`${validatorName} (This Epoch)`, { timeout: 40000 }) cy.contains(`${validatorName} (This Epoch)`, { timeout: 40000 })
.siblings() .siblings()
@ -274,15 +305,23 @@ context('Staking Tab - with eth and vega wallets connected', function () {
}; };
cy.vega_wallet_check_validator_no_longer_showing = (validatorName) => { cy.vega_wallet_check_validator_no_longer_showing = (validatorName) => {
cy.highlight(`Checking Validator and therefore stake removed for ${validatorName}`); cy.highlight(
`Checking Validator and therefore stake removed for ${validatorName}`
);
cy.get(wallet.vegawallet).within(() => { cy.get(wallet.vegawallet).within(() => {
cy.contains(`${validatorName}`, { timeout: 40000 }) cy.contains(`${validatorName}`, { timeout: 40000 }).should('not.exist', {
.should('not.exist', { timeout: 40000 }); timeout: 40000,
});
}); });
}; };
cy.vega_wallet_check_validator_staked_value_is = (validatorName, expectedVal) => { cy.vega_wallet_check_validator_staked_value_is = (
cy.highlight(`Checking Validator Stake Value for ${validatorName} is ${expectedVal}`); validatorName,
expectedVal
) => {
cy.highlight(
`Checking Validator Stake Value for ${validatorName} is ${expectedVal}`
);
cy.get(wallet.vegawallet).within(() => { cy.get(wallet.vegawallet).within(() => {
cy.contains(`${validatorName}`, { timeout: 40000 }) cy.contains(`${validatorName}`, { timeout: 40000 })
.siblings() .siblings()

View File

@ -7,7 +7,7 @@ import '../../support/vega-wallet.functions';
import '../../support/eth-wallet.functions'; import '../../support/eth-wallet.functions';
import '../../support/wallet-teardown.functions'; import '../../support/wallet-teardown.functions';
const vegaWalletPublicKeyShort = Cypress.env("vegaWalletPublicKeyShort"); const vegaWalletPublicKeyShort = Cypress.env('vegaWalletPublicKeyShort');
context('Staking Tab - with eth and vega wallets connected', function () { context('Staking Tab - with eth and vega wallets connected', function () {
before('visit staking tab and connect vega wallet', function () { before('visit staking tab and connect vega wallet', function () {
@ -36,7 +36,10 @@ context('Staking Tab - with eth and vega wallets connected', function () {
it('Able to associate tokens - from staking page', function () { it('Able to associate tokens - from staking page', function () {
cy.staking_page_associate_tokens('2'); cy.staking_page_associate_tokens('2');
cy.ethereum_wallet_check_associated_vega_key_value_is(vegaWalletPublicKeyShort,'2.000000000000000000'); cy.ethereum_wallet_check_associated_vega_key_value_is(
vegaWalletPublicKeyShort,
'2.000000000000000000'
);
cy.ethereum_wallet_check_associated_value_is('2.0'); cy.ethereum_wallet_check_associated_value_is('2.0');
cy.vega_wallet_check_associated_value_is('2.000000000000000000'); cy.vega_wallet_check_associated_value_is('2.000000000000000000');
cy.vega_wallet_check_unstaked_value_is('2.000000000000000000'); cy.vega_wallet_check_unstaked_value_is('2.000000000000000000');
@ -44,28 +47,45 @@ context('Staking Tab - with eth and vega wallets connected', function () {
it('Able to disassociate tokens - from staking page', function () { it('Able to disassociate tokens - from staking page', function () {
cy.staking_page_associate_tokens('2'); cy.staking_page_associate_tokens('2');
cy.ethereum_wallet_check_associated_vega_key_value_is(vegaWalletPublicKeyShort,'2.000000000000000000'); cy.ethereum_wallet_check_associated_vega_key_value_is(
vegaWalletPublicKeyShort,
'2.000000000000000000'
);
cy.vega_wallet_check_associated_value_is('2.000000000000000000'); cy.vega_wallet_check_associated_value_is('2.000000000000000000');
cy.get('button').contains('Select a validator to nominate').click(); cy.get('button').contains('Select a validator to nominate').click();
cy.staking_page_disassociate_tokens('1'); cy.staking_page_disassociate_tokens('1');
cy.ethereum_wallet_check_associated_vega_key_value_is(vegaWalletPublicKeyShort,'1.000000000000000000'); cy.ethereum_wallet_check_associated_vega_key_value_is(
vegaWalletPublicKeyShort,
'1.000000000000000000'
);
cy.ethereum_wallet_check_associated_value_is('1.0'); cy.ethereum_wallet_check_associated_value_is('1.0');
cy.vega_wallet_check_associated_value_is('1.000000000000000000'); cy.vega_wallet_check_associated_value_is('1.000000000000000000');
}); });
it('Able to access associate token form - from eth wallet', function () { it('Able to access associate token form - from eth wallet', function () {
cy.get(wallet.ethWallet).within(() => cy.get(wallet.ethWalletAssociate).click()); cy.get(wallet.ethWallet).within(() =>
cy.get(staking.stakeAssociateWalletRadio, { timeout: 30000 }).should('be.enabled') cy.get(wallet.ethWalletAssociate).click()
);
cy.get(staking.stakeAssociateWalletRadio, { timeout: 30000 }).should(
'be.enabled'
);
}); });
it('Able to access disassociate token form - from eth wallet', function () { it('Able to access disassociate token form - from eth wallet', function () {
cy.get(wallet.ethWallet).within(() => cy.get(wallet.ethWalletDisassociate).click()); cy.get(wallet.ethWallet).within(() =>
cy.get(staking.stakeAssociateWalletRadio, { timeout: 30000 }).should('be.enabled') cy.get(wallet.ethWalletDisassociate).click()
);
cy.get(staking.stakeAssociateWalletRadio, { timeout: 30000 }).should(
'be.enabled'
);
}); });
it('Able to associate more tokens than the approved amount of 1000 - requires re-approval', function () { it('Able to associate more tokens than the approved amount of 1000 - requires re-approval', function () {
cy.staking_page_associate_tokens('1001', true); cy.staking_page_associate_tokens('1001', true);
cy.ethereum_wallet_check_associated_vega_key_value_is(vegaWalletPublicKeyShort,'1,001.000000000000000000'); cy.ethereum_wallet_check_associated_vega_key_value_is(
vegaWalletPublicKeyShort,
'1,001.000000000000000000'
);
cy.ethereum_wallet_check_associated_value_is('1,001.00'); cy.ethereum_wallet_check_associated_value_is('1,001.00');
cy.vega_wallet_check_associated_value_is('1,001.000000000000000000'); cy.vega_wallet_check_associated_value_is('1,001.000000000000000000');
}); });
@ -75,7 +95,10 @@ context('Staking Tab - with eth and vega wallets connected', function () {
cy.vega_wallet_check_associated_value_is('2.000000000000000000'); cy.vega_wallet_check_associated_value_is('2.000000000000000000');
cy.get('button').contains('Select a validator to nominate').click(); cy.get('button').contains('Select a validator to nominate').click();
cy.staking_page_disassociate_tokens('1'); cy.staking_page_disassociate_tokens('1');
cy.ethereum_wallet_check_associated_vega_key_value_is(vegaWalletPublicKeyShort,'1.000000000000000000'); cy.ethereum_wallet_check_associated_vega_key_value_is(
vegaWalletPublicKeyShort,
'1.000000000000000000'
);
cy.ethereum_wallet_check_associated_value_is('1.0'); cy.ethereum_wallet_check_associated_value_is('1.0');
cy.vega_wallet_check_associated_value_is('1.000000000000000000'); cy.vega_wallet_check_associated_value_is('1.000000000000000000');
}); });
@ -85,7 +108,9 @@ context('Staking Tab - with eth and vega wallets connected', function () {
cy.vega_wallet_check_associated_value_is('2.000000000000000000'); cy.vega_wallet_check_associated_value_is('2.000000000000000000');
cy.get('button').contains('Select a validator to nominate').click(); cy.get('button').contains('Select a validator to nominate').click();
cy.staking_page_disassociate_all_tokens(); cy.staking_page_disassociate_all_tokens();
cy.ethereum_wallet_check_associated_vega_key_is_no_longer_showing(vegaWalletPublicKeyShort); cy.ethereum_wallet_check_associated_vega_key_is_no_longer_showing(
vegaWalletPublicKeyShort
);
cy.ethereum_wallet_check_associated_value_is('0.0'); cy.ethereum_wallet_check_associated_value_is('0.0');
cy.vega_wallet_check_associated_value_is('0.000000000000000000'); cy.vega_wallet_check_associated_value_is('0.000000000000000000');
}); });

View File

@ -1,8 +1,8 @@
import navigation from '../locators/navigation.locators'; import navigation from '../locators/navigation.locators';
import home from '../locators/home.locators'; import home from '../locators/home.locators';
const vegaTokenAddress = Cypress.env("vegaTokenAddress");; const vegaTokenAddress = Cypress.env('vegaTokenAddress');
const vegaTokenContractAddress = Cypress.env("vegaTokenContractAddress"); const vegaTokenContractAddress = Cypress.env('vegaTokenContractAddress');
context('Home Page - verify elements on page', function () { context('Home Page - verify elements on page', function () {
before('visit token home page', function () { before('visit token home page', function () {

View File

@ -22,5 +22,5 @@ export default {
stakeAssociateWalletRadio: '[data-testid="associate-radio-wallet"]', stakeAssociateWalletRadio: '[data-testid="associate-radio-wallet"]',
disassociateButton: '[data-testid="disassociate-tokens-btn"]', disassociateButton: '[data-testid="disassociate-tokens-btn"]',
associateMoreTokensButton: '[data-testid="associate-more-tokens-btn"]', associateMoreTokensButton: '[data-testid="associate-more-tokens-btn"]',
associateButton: '[data-testid="associate-tokens-btn"]' associateButton: '[data-testid="associate-tokens-btn"]',
}; };

View File

@ -19,14 +19,20 @@ cy.ethereum_wallet_check_associated_value_is = (expectedVal) => {
cy.highlight(`Checking Eth Wallet - Associated Value is ${expectedVal}`); cy.highlight(`Checking Eth Wallet - Associated Value is ${expectedVal}`);
cy.get(wallet.ethWallet).within(() => { cy.get(wallet.ethWallet).within(() => {
cy.contains('Associated', { timeout: 20000 }) cy.contains('Associated', { timeout: 20000 })
.parent().siblings() .parent()
.siblings()
.contains(expectedVal, { timeout: 40000 }) .contains(expectedVal, { timeout: 40000 })
.should('be.visible'); .should('be.visible');
}); });
}; };
cy.ethereum_wallet_check_associated_vega_key_value_is = (vegaShortPublicKey, expectedVal) => { cy.ethereum_wallet_check_associated_vega_key_value_is = (
cy.highlight(`Checking Eth Wallet - Vega Key Associated Value is ${expectedVal} for key ${vegaShortPublicKey}`); vegaShortPublicKey,
expectedVal
) => {
cy.highlight(
`Checking Eth Wallet - Vega Key Associated Value is ${expectedVal} for key ${vegaShortPublicKey}`
);
cy.get(wallet.ethWallet).within(() => { cy.get(wallet.ethWallet).within(() => {
cy.contains(vegaShortPublicKey, { timeout: 20000 }) cy.contains(vegaShortPublicKey, { timeout: 20000 })
.parent() .parent()
@ -35,7 +41,9 @@ cy.ethereum_wallet_check_associated_vega_key_value_is = (vegaShortPublicKey, exp
}); });
}; };
cy.ethereum_wallet_check_associated_vega_key_is_no_longer_showing = (vegaShortPublicKey) => { cy.ethereum_wallet_check_associated_vega_key_is_no_longer_showing = (
vegaShortPublicKey
) => {
cy.highlight('Checking Eth Wallet - Vega Key Associated is not showing'); cy.highlight('Checking Eth Wallet - Vega Key Associated is not showing');
cy.get(wallet.ethWallet).within(() => { cy.get(wallet.ethWallet).within(() => {
cy.contains(vegaShortPublicKey, { timeout: 20000 }).should('not.exist'); cy.contains(vegaShortPublicKey, { timeout: 20000 }).should('not.exist');

View File

@ -48,11 +48,12 @@ cy.staking_page_associate_tokens = (amount, approve=false) => {
}).should('not.exist'); }).should('not.exist');
} }
cy.get(staking.tokenInputSubmit, { timeout: 40000 }) cy.get(staking.tokenInputSubmit, { timeout: 40000 })
.should('be.enabled').click(); .should('be.enabled')
.click();
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,
}).should('be.visible'); }).should('be.visible');
} };
cy.staking_page_disassociate_tokens = (amount) => { cy.staking_page_disassociate_tokens = (amount) => {
cy.highlight(`Disassociating ${amount} tokens via Staking Page`); cy.highlight(`Disassociating ${amount} tokens via Staking Page`);

View File

@ -1,8 +1,8 @@
import wallet from '../locators/wallet.locators'; import wallet from '../locators/wallet.locators';
const vegaWalletName = Cypress.env("vegaWalletName"); const vegaWalletName = Cypress.env('vegaWalletName');
const vegaWalletLocation = Cypress.env("vegaWalletLocation"); const vegaWalletLocation = Cypress.env('vegaWalletLocation');
const vegaWalletPassphrase = Cypress.env("vegaWalletPassphrase"); const vegaWalletPassphrase = Cypress.env('vegaWalletPassphrase');
cy.vega_wallet_import = () => { cy.vega_wallet_import = () => {
cy.highlight(`Importing Vega Wallet ${vegaWalletName}`); cy.highlight(`Importing Vega Wallet ${vegaWalletName}`);

View File

@ -1,33 +1,42 @@
import { StakingBridge, Token, TokenVesting } from '@vegaprotocol/smart-contracts'; import {
StakingBridge,
Token,
TokenVesting,
} from '@vegaprotocol/smart-contracts';
import { ethers, Wallet } from 'ethers'; import { ethers, Wallet } from 'ethers';
const vegaWalletMnemonic = Cypress.env("vegaWalletMnemonic"); const vegaWalletMnemonic = Cypress.env('vegaWalletMnemonic');
const vegaWalletPubKey = Cypress.env("vegaWalletPublicKey"); const vegaWalletPubKey = Cypress.env('vegaWalletPublicKey');
const vegaTokenContractAddress = Cypress.env("vegaTokenContractAddress"); const vegaTokenContractAddress = Cypress.env('vegaTokenContractAddress');
const vegaTokenAddress = Cypress.env("vegaTokenAddress"); const vegaTokenAddress = Cypress.env('vegaTokenAddress');
const ethWalletPubKey = Cypress.env("ethWalletPublicKey"); const ethWalletPubKey = Cypress.env('ethWalletPublicKey');
const ethStakingBridgeContractAddress = Cypress.env("ethStakingBridgeContractAddress"); const ethStakingBridgeContractAddress = Cypress.env(
const ethProviderUrl = Cypress.env("ethProviderUrl"); 'ethStakingBridgeContractAddress'
);
const ethProviderUrl = Cypress.env('ethProviderUrl');
const getAccount = (number = 0) => `m/44'/60'/0'/0/${number}`; const getAccount = (number = 0) => `m/44'/60'/0'/0/${number}`;
const transactionTimeout = '50000'; const transactionTimeout = '50000';
before('Vega wallet teardown prep', function () { before('Vega wallet teardown prep', function () {
cy.wrap(new ethers.providers.JsonRpcProvider({ url: ethProviderUrl }), { cy.wrap(new ethers.providers.JsonRpcProvider({ url: ethProviderUrl }), {
log: false}).as('provider'); log: false,
}).as('provider');
cy.wrap(Wallet.fromMnemonic(vegaWalletMnemonic, getAccount(0)).privateKey, { cy.wrap(Wallet.fromMnemonic(vegaWalletMnemonic, getAccount(0)).privateKey, {
log: false}).then((privateKey) => { log: false,
}).then((privateKey) => {
cy.wrap(new Wallet(privateKey, this.provider), { log: false }).as('signer'); cy.wrap(new Wallet(privateKey, this.provider), { log: false }).as('signer');
}) });
cy.get("@signer", {log: false}).then((signer => { cy.get('@signer', { log: false }).then((signer) => {
cy.wrap(new StakingBridge(ethStakingBridgeContractAddress, signer), { cy.wrap(new StakingBridge(ethStakingBridgeContractAddress, signer), {
log: false}).as('stakingBridgeContract') log: false,
}).as('stakingBridgeContract');
cy.wrap(new TokenVesting(vegaTokenContractAddress, signer), { cy.wrap(new TokenVesting(vegaTokenContractAddress, signer), {
log: false}).as('vestingContract') log: false,
})) }).as('vestingContract');
});
}) });
Cypress.Commands.add('vega_wallet_teardown', function () { Cypress.Commands.add('vega_wallet_teardown', function () {
cy.vega_wallet_teardown_staking(this.stakingBridgeContract); cy.vega_wallet_teardown_staking(this.stakingBridgeContract);
@ -35,45 +44,64 @@ Cypress.Commands.add('vega_wallet_teardown', function () {
cy.vega_wallet_check_associated_value_is('0.000000000000000000'); cy.vega_wallet_check_associated_value_is('0.000000000000000000');
}); });
Cypress.Commands.add('vega_wallet_set_specified_approval_amount', function (resetAmount) { Cypress.Commands.add(
'vega_wallet_set_specified_approval_amount',
function (resetAmount) {
cy.highlight(`Setting token approval amount to ${resetAmount}`); cy.highlight(`Setting token approval amount to ${resetAmount}`);
cy.wrap(new Token(vegaTokenAddress, this.signer), { log: false }) cy.wrap(new Token(vegaTokenAddress, this.signer), { log: false }).then(
.then((token) => { (token) => {
cy.wrap(token.approve(ethStakingBridgeContractAddress, cy.wrap(
token.approve(
ethStakingBridgeContractAddress,
resetAmount.concat('000000000000000000') resetAmount.concat('000000000000000000')
), ),
{ timeout: transactionTimeout, log: false }) { timeout: transactionTimeout, log: false }
.then((tx) => { cy.wait_for_transaction(tx) }); ).then((tx) => {
cy.wait_for_transaction(tx);
}); });
}
);
// ensure to cy.reload() after running this in order to take affect // ensure to cy.reload() after running this in order to take affect
}); }
);
cy.vega_wallet_teardown_staking = (stakingBridgeContract) => { cy.vega_wallet_teardown_staking = (stakingBridgeContract) => {
cy.highlight('Tearing down staking tokens from vega wallet if present'); cy.highlight('Tearing down staking tokens from vega wallet if present');
cy.wrap(stakingBridgeContract.stakeBalance(ethWalletPubKey, vegaWalletPubKey), { cy.wrap(
timeout: transactionTimeout, log: false}) stakingBridgeContract.stakeBalance(ethWalletPubKey, vegaWalletPubKey),
.then((stake_amount) => { {
if (String(stake_amount) != '0') { timeout: transactionTimeout,
cy.wrap(stakingBridgeContract.removeStake(stake_amount, vegaWalletPubKey), log: false,
{ timeout: transactionTimeout, log: false })
.then((tx) => { cy.wait_for_transaction(tx) });
} }
}) ).then((stake_amount) => {
if (String(stake_amount) != '0') {
cy.wrap(
stakingBridgeContract.removeStake(stake_amount, vegaWalletPubKey),
{ timeout: transactionTimeout, log: false }
).then((tx) => {
cy.wait_for_transaction(tx);
});
}
});
}; };
cy.vega_wallet_teardown_vesting = (vestingContract) => { cy.vega_wallet_teardown_vesting = (vestingContract) => {
cy.highlight('Tearing down vesting tokens from vega wallet if present'); cy.highlight('Tearing down vesting tokens from vega wallet if present');
cy.wrap(vestingContract.stakeBalance(ethWalletPubKey, vegaWalletPubKey), { cy.wrap(vestingContract.stakeBalance(ethWalletPubKey, vegaWalletPubKey), {
timeout: transactionTimeout, log: false}) timeout: transactionTimeout,
.then((vesting_amount) => { log: false,
}).then((vesting_amount) => {
if (String(vesting_amount) != '0') { if (String(vesting_amount) != '0') {
cy.wrap(vestingContract.removeStake(vesting_amount, vegaWalletPubKey), cy.wrap(vestingContract.removeStake(vesting_amount, vegaWalletPubKey), {
{ timeout: transactionTimeout, log: false }) timeout: transactionTimeout,
.then((tx) => { cy.wait_for_transaction(tx) }); log: false,
}).then((tx) => {
cy.wait_for_transaction(tx);
});
} }
}); });
}; };
cy.wait_for_transaction = (tx) => { cy.wait_for_transaction = (tx) => {
cy.wrap(tx.wait(1).catch(cy.log), {timeout: transactionTimeout}) cy.wrap(tx.wait(1).catch(cy.log), { timeout: transactionTimeout });
}; };