vega-frontend-monorepo/apps/token-e2e/src/support/wallet-teardown.functions.js

107 lines
3.4 KiB
JavaScript
Raw Normal View History

Task/token flow tests (#695) * test(token-e2e): initial commit * test(token-e2e): lint * test: function Enhancements * test: linting * test: remove custom command type decs * test: more tests * test: linting * test: working with capsule still needs rounding issues sorting * test: enhancements * test: enhancements * test: check enhancements * test: add brdige logic * test: share instance rather than recreating on each test * test: minor bug fix, add comment * test: ensure working against capsule * test: teardown functions in place * test: linting * test: completion of first iteration of happy paths * test: lint * test: typo change * test: tweaks * test: fix merge issues * test: lint * test: env variable handling and cleanup * test: lint * test: enhancements to logging to aid debugging * test: lint * test: ehancements after feedback * test: lint * Update apps/token-e2e/src/support/wallet-teardown.functions.js Co-authored-by: Dexter Edwards <dexter.edwards93@gmail.com> * test: skipping non-essential tests to reduce time * test: typo * test: ci test fails coz capsule runs quicker their - disabled this one check to help * test: reduction of coverage to help PR time * test: disable infinte scroll test since capsule blockchain data to small * test: corrected test: staked tokens field value no longer in a fixed state * test: clearup to stop test bleed across projects plus bugfix * test: lint * test: update .env for trading * Revert "test: update .env for trading" This reverts commit 741743e4d2f9b7ab695dab52935467f9ae26e4a8. Co-authored-by: Dexter <dexter.edwards93@gmail.com>
2022-07-08 10:48:51 +00:00
import {
StakingBridge,
Token,
TokenVesting,
} from '@vegaprotocol/smart-contracts';
import { ethers, Wallet } from 'ethers';
const vegaWalletMnemonic = Cypress.env('vegaWalletMnemonic');
const vegaWalletPubKey = Cypress.env('vegaWalletPublicKey');
const vegaTokenContractAddress = Cypress.env('vegaTokenContractAddress');
const vegaTokenAddress = Cypress.env('vegaTokenAddress');
const ethWalletPubKey = Cypress.env('ethWalletPublicKey');
const ethStakingBridgeContractAddress = Cypress.env(
'ethStakingBridgeContractAddress'
);
const ethProviderUrl = Cypress.env('ethProviderUrl');
const getAccount = (number = 0) => `m/44'/60'/0'/0/${number}`;
const transactionTimeout = '50000';
before('Vega wallet teardown prep', function () {
cy.wrap(new ethers.providers.JsonRpcProvider({ url: ethProviderUrl }), {
log: false,
}).as('provider');
cy.wrap(Wallet.fromMnemonic(vegaWalletMnemonic, getAccount(0)).privateKey, {
log: false,
}).then((privateKey) => {
cy.wrap(new Wallet(privateKey, this.provider), { log: false }).as('signer');
});
cy.get('@signer', { log: false }).then((signer) => {
cy.wrap(new StakingBridge(ethStakingBridgeContractAddress, signer), {
log: false,
}).as('stakingBridgeContract');
cy.wrap(new TokenVesting(vegaTokenContractAddress, signer), {
log: false,
}).as('vestingContract');
});
});
Cypress.Commands.add('vega_wallet_teardown', function () {
cy.vega_wallet_teardown_staking(this.stakingBridgeContract);
cy.vega_wallet_teardown_vesting(this.vestingContract);
cy.vega_wallet_check_associated_value_is('0.000000000000000000');
});
Cypress.Commands.add(
'vega_wallet_set_specified_approval_amount',
function (resetAmount) {
cy.highlight(`Setting token approval amount to ${resetAmount}`);
cy.wrap(new Token(vegaTokenAddress, this.signer), { log: false }).then(
(token) => {
cy.wrap(
token.approve(
ethStakingBridgeContractAddress,
resetAmount.concat('000000000000000000')
),
{ timeout: transactionTimeout, log: false }
).then((tx) => {
cy.wait_for_transaction(tx);
});
}
);
}
);
cy.vega_wallet_teardown_staking = (stakingBridgeContract) => {
cy.highlight('Tearing down staking tokens from vega wallet if present');
cy.wrap(
stakingBridgeContract.stakeBalance(ethWalletPubKey, vegaWalletPubKey),
{
timeout: transactionTimeout,
log: false,
}
).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.highlight('Tearing down vesting tokens from vega wallet if present');
cy.wrap(vestingContract.stakeBalance(ethWalletPubKey, vegaWalletPubKey), {
timeout: transactionTimeout,
log: false,
}).then((vesting_amount) => {
if (String(vesting_amount) != '0') {
cy.wrap(vestingContract.removeStake(vesting_amount, vegaWalletPubKey), {
timeout: transactionTimeout,
log: false,
}).then((tx) => {
cy.wait_for_transaction(tx);
});
}
});
};
cy.wait_for_transaction = (tx) => {
cy.wrap(tx.wait(1).catch(cy.log), { timeout: transactionTimeout });
};