test: linting

This commit is contained in:
AndyWhiteVega 2022-06-30 14:33:02 +01:00
parent 527df2b123
commit e4ab8e92f9
2 changed files with 178 additions and 131 deletions

View File

@ -27,9 +27,7 @@ Cypress.Commands.add(
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
Cypress.Commands.add( Cypress.Commands.add('staking_validator_page_addStake', function (stake) {
'staking_validator_page_addStake',
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 });
@ -39,16 +37,14 @@ Cypress.Commands.add(
.and('be.visible') .and('be.visible')
.click(); .click();
cy.contains( cy.contains(
'At the beginning of the next epoch your $VEGA will be nominated to the validator', {timeout: 20000} 'At the beginning of the next epoch your $VEGA will be nominated to the validator',
{ timeout: 20000 }
); );
} });
);
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
Cypress.Commands.add( Cypress.Commands.add('staking_validator_page_removeStake', function (stake) {
'staking_validator_page_removeStake',
function (stake) {
cy.get(staking.removeStakeRadioButton).click({ force: true }); cy.get(staking.removeStakeRadioButton).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 });
@ -57,6 +53,7 @@ Cypress.Commands.add(
.and('contain', `Remove ${stake} $VEGA tokens at the end of epoch`) .and('contain', `Remove ${stake} $VEGA tokens at the end of epoch`)
.and('be.visible') .and('be.visible')
.click(); .click();
cy.contains(`${stake} $VEGA has been removed from validator`).should('be.visible'); cy.contains(`${stake} $VEGA has been removed from validator`).should(
} 'be.visible'
); );
});

View File

@ -1,6 +1,10 @@
import wallet from '../locators/wallet.locators'; import wallet from '../locators/wallet.locators';
import staking from '../locators/staking.locators'; import staking from '../locators/staking.locators';
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';
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -10,9 +14,12 @@ const vegaWalletPassphrase = Cypress.env('VEGA_WALLET_PASSPHRASE');
const ethPubKey = '0xEe7D375bcB50C26d52E1A4a472D8822A2A22d94F'; const ethPubKey = '0xEe7D375bcB50C26d52E1A4a472D8822A2A22d94F';
const ethProviderUrl = 'http://localhost:8545/'; const ethProviderUrl = 'http://localhost:8545/';
const ethStakingBridgeContractAddress = '0x9135f5afd6F055e731bca2348429482eE614CFfA'; const ethStakingBridgeContractAddress =
const ethWalletMnemonic = 'ozone access unlock valid olympic save include omit supply green clown session'; '0x9135f5afd6F055e731bca2348429482eE614CFfA';
const vegaPubKey = 'fc8661e5550f277dfae5ca2bb38a7524072f84ea56198edab35f81a733031b06'; const ethWalletMnemonic =
'ozone access unlock valid olympic save include omit supply green clown session';
const vegaPubKey =
'fc8661e5550f277dfae5ca2bb38a7524072f84ea56198edab35f81a733031b06';
const vegaTokenContractAddress = '0xF41bD86d462D36b997C0bbb4D97a0a3382f205B7'; const vegaTokenContractAddress = '0xF41bD86d462D36b997C0bbb4D97a0a3382f205B7';
const vegaTokenAddress = '0x67175Da1D5e966e40D11c4B2519392B2058373de'; const vegaTokenAddress = '0x67175Da1D5e966e40D11c4B2519392B2058373de';
const queryUrl = 'http://localhost:3028/query'; const queryUrl = 'http://localhost:3028/query';
@ -21,94 +28,127 @@ 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.wrap(Wallet.fromMnemonic(ethWalletMnemonic, getAccount(0)).privateKey) cy.wrap(
.then((privateKey) => { Wallet.fromMnemonic(ethWalletMnemonic, getAccount(0)).privateKey
cy.vega_wallet_teardown_staking(privateKey) ).then((privateKey) => {
cy.vega_wallet_teardown_vesting(privateKey) cy.vega_wallet_teardown_staking(privateKey);
}) cy.vega_wallet_teardown_vesting(privateKey);
});
cy.intercept('POST', queryUrl).as('queryGrab'); cy.intercept('POST', queryUrl).as('queryGrab');
// Wait for a couple of queries to complete so wallet UI takes changes on board // Wait for a couple of queries to complete so wallet UI takes changes on board
cy.wait(['@queryGrab','@queryGrab'], { timeout: 10000 }) cy.wait(['@queryGrab', '@queryGrab'], { timeout: 10000 });
// Then we turn off our intercept - so that we can use it again in the future // Then we turn off our intercept - so that we can use it again in the future
cy.intercept('POST', queryUrl, (req) => req.continue()); cy.intercept('POST', queryUrl, (req) => req.continue());
cy.log('**Connecting Vega Wallet = COMPLETE**'); 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}), {log : false}).as('provider') cy.wrap(new ethers.providers.JsonRpcProvider({ url: ethProviderUrl }), {
cy.get('@provider', {log : false}).then((provider) => { log: false,
cy.wrap(new Wallet(privateKey, provider), {log : false}).as('signer') }).as('provider');
cy.get('@signer', {log : false}).then((signer) => { cy.get('@provider', { log: false }).then((provider) => {
cy.wrap(new StakingBridge(ethStakingBridgeContractAddress, signer), {log : false}).as('stakingBridge'); cy.wrap(new Wallet(privateKey, provider), { log: false }).as('signer');
cy.get('@stakingBridge', {log : false}).then((stakingBridge) => { cy.get('@signer', { log: false }).then((signer) => {
cy.wrap(stakingBridge.stakeBalance(ethPubKey, vegaPubKey), {timeout : 40000, log : false}).then((stake_amount) => { cy.wrap(new StakingBridge(ethStakingBridgeContractAddress, signer), {
if (String(stake_amount) != '0') log: false,
{ }).as('stakingBridge');
cy.wrap(stakingBridge.removeStake(stake_amount, vegaPubKey), {timeout : 40000, log : false}).then((tx) => { cy.get('@stakingBridge', { log: false }).then((stakingBridge) => {
cy.wrap(tx.wait(1), {timeout : 40000, log : false}) cy.wrap(stakingBridge.stakeBalance(ethPubKey, vegaPubKey), {
timeout: 40000,
log: false,
}).then((stake_amount) => {
if (String(stake_amount) != '0') {
cy.wrap(stakingBridge.removeStake(stake_amount, vegaPubKey), {
timeout: 40000,
log: false,
}).then((tx) => {
cy.wrap(tx.wait(1), { timeout: 40000, log: false });
cy.vega_wallet_check_associatedValue_is('0.000000000000000000'); cy.vega_wallet_check_associatedValue_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}), {log : false}).as('provider') cy.wrap(new ethers.providers.JsonRpcProvider({ url: ethProviderUrl }), {
cy.get('@provider', {log : false}).then((provider) => { log: false,
cy.wrap(new Wallet(privateKey, provider), {log : false}).as('signer') }).as('provider');
cy.get('@signer', {log : false}).then((signer) => { cy.get('@provider', { log: false }).then((provider) => {
cy.wrap(new TokenVesting(vegaTokenContractAddress, signer), {log : false}).as('vesting'); cy.wrap(new Wallet(privateKey, provider), { log: false }).as('signer');
cy.get('@vesting', {log : false}).then((vesting) => { cy.get('@signer', { log: false }).then((signer) => {
cy.wrap(vesting.stakeBalance(ethPubKey, vegaPubKey), {timeout : 40000, log : false}).then((vesting_amount) => { cy.wrap(new TokenVesting(vegaTokenContractAddress, signer), {
if (String(vesting_amount) != '0') log: false,
{ }).as('vesting');
cy.wrap(vesting.removeStake(vesting_amount, vegaPubKey), {timeout : 40000, log : false}).then((tx) => { cy.get('@vesting', { log: false }).then((vesting) => {
cy.wrap(tx.wait(1), {timeout : 40000, log : false}) cy.wrap(vesting.stakeBalance(ethPubKey, vegaPubKey), {
timeout: 40000,
log: false,
}).then((vesting_amount) => {
if (String(vesting_amount) != '0') {
cy.wrap(vesting.removeStake(vesting_amount, vegaPubKey), {
timeout: 40000,
log: false,
}).then((tx) => {
cy.wrap(tx.wait(1), { timeout: 40000, log: false });
}); });
} }
}); });
}) });
}) });
}) });
cy.log('**Tearing down vesting tokens = COMPLETE**') cy.log('**Tearing down vesting tokens = COMPLETE**');
}) });
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
Cypress.Commands.add('vega_wallet_set_approval_amount_to', function (resetAmount, ) { Cypress.Commands.add(
cy.log(`**Setting token approval amount to ${resetAmount}**`) 'vega_wallet_set_approval_amount_to',
cy.wrap(Wallet.fromMnemonic(ethWalletMnemonic, getAccount(0)).privateKey, {log : false}).then((privateKey) => { function (resetAmount) {
cy.wrap(new ethers.providers.JsonRpcProvider({url: ethProviderUrl}), {log : false}).as('provider') cy.log(`**Setting token approval amount to ${resetAmount}**`);
cy.get('@provider', {log : false}).then((provider) => { cy.wrap(Wallet.fromMnemonic(ethWalletMnemonic, getAccount(0)).privateKey, {
cy.wrap(new Wallet(privateKey, provider), {log : false}).as('signer') log: false,
cy.get('@signer', {log : false}).then((signer) => { }).then((privateKey) => {
cy.wrap(new Token(vegaTokenAddress, signer), {log : false}).as('token') cy.wrap(new ethers.providers.JsonRpcProvider({ url: ethProviderUrl }), {
cy.get('@token', {log : false}).then((token) => { log: false,
cy.wrap(token.approve(ethStakingBridgeContractAddress, resetAmount.concat('000000000000000000')), {timeout : 60000, log : false}) }).as('provider');
.then((tx) => { cy.get('@provider', { log: false }).then((provider) => {
cy.wrap(tx.wait(1), {timeout : 40000, log : false}) cy.wrap(new Wallet(privateKey, provider), { log: false }).as('signer');
cy.get('@signer', { log: false }).then((signer) => {
cy.wrap(new Token(vegaTokenAddress, signer), { log: false }).as(
'token'
);
cy.get('@token', { log: false }).then((token) => {
cy.wrap(
token.approve(
ethStakingBridgeContractAddress,
resetAmount.concat('000000000000000000')
),
{ timeout: 60000, log: false }
).then((tx) => {
cy.wrap(tx.wait(1), { timeout: 40000, log: false });
});
});
});
});
}); });
})
})
})
})
cy.intercept('POST', queryUrl).as('queryGrab'); cy.intercept('POST', queryUrl).as('queryGrab');
// Wait for a couple of queries to complete so wallet UI takes changes on board // Wait for a couple of queries to complete so wallet UI takes changes on board
cy.wait(['@queryGrab','@queryGrab'], { timeout: 10000 }) cy.wait(['@queryGrab', '@queryGrab'], { timeout: 10000 });
// Then we turn off our intercept - so that we can use it again in the future // Then we turn off our intercept - so that we can use it again in the future
cy.intercept('POST', queryUrl, (req) => req.continue()); cy.intercept('POST', queryUrl, (req) => req.continue());
cy.log(`**Setting token approval amount to ${resetAmount} = COMPLETE**`) cy.log(`**Setting token approval amount to ${resetAmount} = COMPLETE**`);
}) }
);
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -141,7 +181,9 @@ Cypress.Commands.add('vega_wallet_teardown_ui', function () {
Cypress.Commands.add('vega_wallet_create', function () { Cypress.Commands.add('vega_wallet_create', function () {
cy.log('**Initializing Vega Wallet** ' + vegaWalletName); cy.log('**Initializing Vega Wallet** ' + vegaWalletName);
cy.exec(`vegawallet init -f --home ${vegaWalletLocation}`); cy.exec(`vegawallet init -f --home ${vegaWalletLocation}`);
cy.exec(`echo ${vegaWalletPassphrase} > ./src/fixtures/vegaWalletPassphrase.txt`); cy.exec(
`echo ${vegaWalletPassphrase} > ./src/fixtures/vegaWalletPassphrase.txt`
);
cy.exec( cy.exec(
`vegawallet create -w ${vegaWalletName} -p ./src/fixtures//vegaWalletPassphrase.txt --home ${vegaWalletLocation}`, `vegawallet create -w ${vegaWalletName} -p ./src/fixtures//vegaWalletPassphrase.txt --home ${vegaWalletLocation}`,
{ failOnNonZeroExit: false } { failOnNonZeroExit: false }
@ -245,14 +287,16 @@ Cypress.Commands.add('ethereum_wallet_connect', function () {
cy.get(wallet.ethWalletConnect, { timeout: 60000 }).should('not.exist'); cy.get(wallet.ethWalletConnect, { timeout: 60000 }).should('not.exist');
cy.get(wallet.ethWallet).within(() => { cy.get(wallet.ethWallet).within(() => {
// 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('ethereum_wallet_associateTokens', function (amount, approve) { Cypress.Commands.add(
'ethereum_wallet_associateTokens',
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()
@ -260,11 +304,16 @@ Cypress.Commands.add('ethereum_wallet_associateTokens', function (amount, approv
cy.get(staking.stakeAssociateWalletRadio, { timeout: 30000 }).click(); cy.get(staking.stakeAssociateWalletRadio, { timeout: 30000 }).click();
cy.get(staking.tokenAmountInput, { timeout: 10000 }).type(amount); cy.get(staking.tokenAmountInput, { timeout: 10000 }).type(amount);
if (approve !== undefined && approve.toLowerCase() == 'approve') if (approve !== undefined && approve.toLowerCase() == 'approve') {
{ cy.get(staking.tokenInputApprove, { timeout: 40000 })
cy.get(staking.tokenInputApprove, { timeout: 40000 }).should('be.enabled').click(); .should('be.enabled')
cy.contains('Approve $VEGA Tokens for staking on Vega').should('be.visible'); .click();
cy.contains('Approve $VEGA Tokens for staking on Vega', { timeout: 40000 }).should('not.exist'); 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 }) cy.get(staking.tokenInputSubmit, { timeout: 40000 })
@ -274,7 +323,8 @@ Cypress.Commands.add('ethereum_wallet_associateTokens', function (amount, approv
timeout: 60000, timeout: 60000,
}); });
cy.log('**Associating tokens from Eth Wallet = COMPLETE**'); cy.log('**Associating tokens from Eth Wallet = COMPLETE**');
}); }
);
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------