Test/866 add ac references to association tests (#1103)

* test: added ACs to existing tests

* test: add more association test to match coverage

* chore: missing braces added

Co-authored-by: Rado <rado@vegaprotocol.io>
This commit is contained in:
Radosław Szpiech 2022-08-23 10:34:13 +02:00 committed by GitHub
parent f7bc2fb6fd
commit 696e1174bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 195 additions and 54 deletions

View File

@ -8,6 +8,15 @@ const vegaWalletUnstakedBalance =
'[data-testid="vega-wallet-balance-unstaked"]'; '[data-testid="vega-wallet-balance-unstaked"]';
const txTimeout = { timeout: 40000 }; const txTimeout = { timeout: 40000 };
const vegaWalletPublicKeyShort = Cypress.env('vegaWalletPublicKeyShort'); const vegaWalletPublicKeyShort = Cypress.env('vegaWalletPublicKeyShort');
const ethWalletAssociateButton = '[href="/staking/associate"]';
const associateWalletRadioButton = '[data-testid="associate-radio-wallet"]';
const tokenAmountInputBox = '[data-testid="token-amount-input"]';
const tokenSubmitButton = '[data-testid="token-input-submit-button"]';
const ethWalletDissociateButton = '[href="/staking/disassociate"]';
const vestingContractSection = '[data-testid="vega-in-vesting-contract"]';
const vegaInWalletSection = '[data-testid="vega-in-wallet"]';
const associatedKey = '[data-test-id="associated-key"]';
const associatedAmount = '[data-test-id="associated-amount"]';
context( context(
'Token association flow - with eth and vega wallets connected', 'Token association flow - with eth and vega wallets connected',
@ -37,6 +46,13 @@ context(
); );
it('Able to associate tokens', function () { it('Able to associate tokens', function () {
//1000-ASSO-0008
//1000-ASSO-0009
//1000-ASSO-0030
//1000-ASSO-0012
//1000-ASSO-0014
//1000-ASSO-0015
//1000-ASSO-0030
cy.staking_page_associate_tokens('2'); cy.staking_page_associate_tokens('2');
cy.get(ethWalletAssociatedBalances, txTimeout) cy.get(ethWalletAssociatedBalances, txTimeout)
@ -54,6 +70,11 @@ context(
}); });
it('Able to disassociate tokens', function () { it('Able to disassociate tokens', function () {
// 1000-ASSO-0025
// 1000-ASSO-0027
// 1000-ASSO-0028
// 1000-ASSO-0029
cy.staking_page_associate_tokens('2'); cy.staking_page_associate_tokens('2');
cy.get(ethWalletAssociatedBalances, txTimeout) cy.get(ethWalletAssociatedBalances, txTimeout)
@ -80,7 +101,8 @@ context(
}); });
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); //1000-ASSO-0011
cy.staking_page_associate_tokens('1001', { approve: true });
cy.get(ethWalletAssociatedBalances, txTimeout) cy.get(ethWalletAssociatedBalances, txTimeout)
.contains(vegaWalletPublicKeyShort) .contains(vegaWalletPublicKeyShort)
@ -120,12 +142,18 @@ context(
}); });
it('Able to disassociate all tokens', function () { it('Able to disassociate all tokens', function () {
// 1000-ASSO-0026
cy.staking_page_associate_tokens('2'); cy.staking_page_associate_tokens('2');
cy.get(vegaWalletAssociatedBalance, txTimeout).should('contain', 2.0); cy.get(vegaWalletAssociatedBalance, txTimeout).should('contain', 2.0);
cy.get('button').contains('Select a validator to nominate').click(); cy.get('button').contains('Select a validator to nominate').click();
cy.get(ethWalletDissociateButton).click();
cy.contains(
'If you disassociate tokens that have been nominated to a node, you will sacrifice any rewards they are due for the current epoch. If you do not wish to sacrifice rewards, remove your stake from a node at the end of an epoch before disassociating.'
).should('be.visible');
cy.staking_page_disassociate_all_tokens(); cy.staking_page_disassociate_all_tokens();
cy.get(ethWalletContainer).within(() => { cy.get(ethWalletContainer).within(() => {
@ -142,6 +170,74 @@ context(
cy.get(vegaWalletAssociatedBalance, txTimeout).should('contain', 0.0); cy.get(vegaWalletAssociatedBalance, txTimeout).should('contain', 0.0);
}); });
it('Able to associate and disassociate vesting contract tokens', function () {
// 1000-ASSO-0006
// 1000-ASSO-0024
// 1000-ASSO-0023
cy.staking_page_associate_tokens('2', { type: 'contract' });
cy.get(ethWalletAssociatedBalances, txTimeout)
.contains(vegaWalletPublicKeyShort)
.parent(txTimeout)
.should('contain', 2.0);
cy.get(ethWalletTotalAssociatedBalance, txTimeout)
.contains('2.0', txTimeout)
.should('be.visible');
cy.get(vegaWalletAssociatedBalance, txTimeout).should('contain', 2.0);
cy.get(vegaWalletUnstakedBalance, txTimeout).should('contain', 2.0);
cy.staking_page_disassociate_tokens('1', { type: 'contract' });
cy.get(ethWalletAssociatedBalances, txTimeout)
.contains(vegaWalletPublicKeyShort)
.parent(txTimeout)
.should('contain', 1.0);
cy.get(ethWalletTotalAssociatedBalance, txTimeout)
.contains('1.0', txTimeout)
.should('be.visible');
});
it('Associate both wallet and vesting contract tokens', function () {
// 1000-ASSO-0019
// 1000-ASSO-0020
// 1000-ASSO-0021
// 1000-ASSO-0022
cy.staking_page_associate_tokens('21', { type: 'wallet' });
cy.get('button').contains('Select a validator to nominate').click();
cy.staking_page_associate_tokens('37', { type: 'contract' });
cy.get(vestingContractSection).within(() => {
cy.get(associatedKey).should(
'contain',
Cypress.env('vegaWalletPublicKeyShort')
);
cy.get(associatedAmount).should('contain', '37');
});
cy.get(vegaInWalletSection).within(() => {
cy.get(associatedKey).should(
'contain',
Cypress.env('vegaWalletPublicKeyShort')
);
cy.get(associatedAmount).should('contain', '21');
});
});
it('Not able to associate more tokens than owned', function () {
// 1000-ASSO-0010
// No warning visible as described in AC, but the button is disabled
cy.get(ethWalletAssociateButton).first().click();
cy.get(associateWalletRadioButton, { timeout: 30000 }).click();
cy.get(tokenAmountInputBox, { timeout: 10000 }).type(6500000);
cy.get(tokenSubmitButton, txTimeout).should('be.disabled');
});
}); });
} }
); );

View File

@ -76,6 +76,7 @@ context('Home Page - verify elements on page', function () {
}); });
}); });
it('should have VESTING CONTRACT', function () { it('should have VESTING CONTRACT', function () {
// 1000-ASSO-0001
cy.get(tokenDetailsTable).within(() => { cy.get(tokenDetailsTable).within(() => {
cy.get(contract) cy.get(contract)
.should('be.visible') .should('be.visible')

View File

@ -45,6 +45,7 @@ context('Ethereum Wallet - verify elements on widget', function () {
}); });
describe('when Connect Ethereum clicked', function () { describe('when Connect Ethereum clicked', function () {
// 1000-ASSO-0002
before('', function () { before('', function () {
cy.get(connectToEthButton).click(); cy.get(connectToEthButton).click();
}); });
@ -121,6 +122,7 @@ context('Ethereum Wallet - verify elements on widget', function () {
}); });
describe('VEGA IN VESTING CONTRACT', function () { describe('VEGA IN VESTING CONTRACT', function () {
// 1000-ASSO-0007
it('should have currency title visible', function () { it('should have currency title visible', function () {
cy.get(vegaInVesting).within(() => { cy.get(vegaInVesting).within(() => {
cy.get(currencyTitle) cy.get(currencyTitle)
@ -185,6 +187,7 @@ context('Ethereum Wallet - verify elements on widget', function () {
}); });
describe('VEGA IN WALLET', function () { describe('VEGA IN WALLET', function () {
// 1000-ASSO-0007
it('should have currency title visible', function () { it('should have currency title visible', function () {
cy.get(vegaInWallet).within(() => { cy.get(vegaInWallet).within(() => {
cy.get(currencyTitle) cy.get(currencyTitle)

View File

@ -9,6 +9,7 @@ const vegaWalletUnstakedBalance =
'[data-testid="vega-wallet-balance-unstaked"]'; '[data-testid="vega-wallet-balance-unstaked"]';
const vegaWalletAssociatedBalance = '[data-testid="currency-value"]'; const vegaWalletAssociatedBalance = '[data-testid="currency-value"]';
const associateWalletRadioButton = '[data-testid="associate-radio-wallet"]'; const associateWalletRadioButton = '[data-testid="associate-radio-wallet"]';
const associateContractRadioButton = '[data-testid="associate-radio-contract"]';
const stakeMaximumTokens = '[data-testid="token-amount-use-maximum"]'; const stakeMaximumTokens = '[data-testid="token-amount-use-maximum"]';
const stakeValidatorListPendingStake = '[col-id="pendingStake"]'; const stakeValidatorListPendingStake = '[col-id="pendingStake"]';
const stakeValidatorListTotalStake = '[col-id="totalStakeThisEpoch"]'; const stakeValidatorListTotalStake = '[col-id="totalStakeThisEpoch"]';
@ -48,32 +49,38 @@ Cypress.Commands.add('staking_validator_page_remove_stake', (stake) => {
.click(); .click();
}); });
Cypress.Commands.add( Cypress.Commands.add('staking_page_associate_tokens', (amount, options) => {
'staking_page_associate_tokens', let approve = options && options.approve ? options.approve : false;
(amount, approve = false) => { let type = options && options.type ? options.type : 'wallet';
cy.highlight(`Associating ${amount} tokens`); cy.highlight(`Associating ${amount} tokens`);
cy.get(ethWalletAssociateButton).first().click(); cy.get(ethWalletAssociateButton).first().click();
if (type === 'wallet') {
cy.get(associateWalletRadioButton, { timeout: 30000 }).click(); cy.get(associateWalletRadioButton, { timeout: 30000 }).click();
cy.get(tokenAmountInputBox, epochTimeout).type(amount); } else if (type === 'contract') {
cy.get(associateContractRadioButton, { timeout: 30000 }).click();
} else {
cy.highlight(`${type} is not association option`);
}
cy.get(tokenAmountInputBox, { timeout: 10000 }).type(amount);
if (approve) { if (approve) {
cy.get(tokenInputApprove, txTimeout).should('be.enabled').click(); cy.get(tokenInputApprove, txTimeout).should('be.enabled').click();
cy.contains('Approve $VEGA Tokens for staking on Vega').should( cy.contains('Approve $VEGA Tokens for staking on Vega').should(
'be.visible' 'be.visible'
); );
cy.contains( cy.contains('Approve $VEGA Tokens for staking on Vega', {
'Approve $VEGA Tokens for staking on Vega', timeout: 40000,
epochTimeout }).should('not.exist');
).should('not.exist');
} }
cy.get(tokenSubmitButton, epochTimeout).should('be.enabled').click(); cy.get(tokenSubmitButton, txTimeout).should('be.enabled').click();
cy.contains( cy.contains('can now participate in governance and nominate a validator', {
'can now participate in governance and nominate a validator', timeout: 60000,
txTimeout }).should('be.visible');
).should('be.visible'); });
}
); Cypress.Commands.add('staking_page_disassociate_tokens', (amount, options) => {
let type = options && options.type ? options.type : 'wallet';
Cypress.Commands.add('staking_page_disassociate_tokens', (amount) => {
cy.highlight(`Disassociating ${amount} tokens via Staking Page`); cy.highlight(`Disassociating ${amount} tokens via Staking Page`);
cy.get(ethWalletDissociateButton).first().click(); cy.get(ethWalletDissociateButton).first().click();
cy.get(associateWalletRadioButton, epochTimeout).click(); cy.get(associateWalletRadioButton, epochTimeout).click();
@ -84,6 +91,32 @@ Cypress.Commands.add('staking_page_disassociate_tokens', (amount) => {
`${amount} $VEGA tokens have been returned to Ethereum wallet`, `${amount} $VEGA tokens have been returned to Ethereum wallet`,
txTimeout txTimeout
).should('be.visible'); ).should('be.visible');
if (type === 'wallet') {
cy.get(associateWalletRadioButton, { timeout: 30000 }).click();
} else if (type === 'contract') {
cy.get(associateContractRadioButton, { timeout: 30000 }).click();
} else {
cy.highlight(`${type} is not association option`);
}
cy.get(tokenAmountInputBox, { timeout: 10000 }).type(amount);
cy.get(tokenSubmitButton, txTimeout).should('be.enabled').click();
if (type === 'wallet') {
cy.contains(
`${amount} $VEGA tokens have been returned to Ethereum wallet`,
{
timeout: 60000,
}
).should('be.visible');
} else if (type === 'contract') {
cy.contains(
`${amount} $VEGA tokens have been returned to Vesting contract`,
{
timeout: 60000,
}
).should('be.visible');
}
}); });
Cypress.Commands.add('staking_page_disassociate_all_tokens', () => { Cypress.Commands.add('staking_page_disassociate_all_tokens', () => {

View File

@ -129,8 +129,9 @@ const ConnectedKey = () => {
return ( return (
<> <>
{totalVestedBalance.plus(totalLockedBalance).isEqualTo(0) ? null : (
<section data-testid="vega-in-vesting-contract"> <section data-testid="vega-in-vesting-contract">
{totalVestedBalance.plus(totalLockedBalance).isEqualTo(0) ? null : (
<section>
<WalletCardAsset <WalletCardAsset
image={vegaVesting} image={vegaVesting}
decimals={appState.decimals} decimals={appState.decimals}
@ -156,6 +157,7 @@ const ConnectedKey = () => {
notAssociated={notAssociatedInContract} notAssociated={notAssociatedInContract}
/> />
)} )}
</section>
<section data-testid="vega-in-wallet"> <section data-testid="vega-in-wallet">
<WalletCardAsset <WalletCardAsset
image={vegaWhite} image={vegaWhite}

View File

@ -95,12 +95,18 @@ export const WalletCardRow = ({
{label} {label}
</Link> </Link>
) : ( ) : (
<span className={`max-w-[200px] ${dark ? 'text-white' : 'text-black'}`}> <span
className={`max-w-[200px] ${dark ? 'text-white' : 'text-black'}`}
data-test-id="associated-key"
>
{label} {label}
</span> </span>
)} )}
{value && ( {value && (
<span className="font-mono flex-1 text-right"> <span
className="font-mono flex-1 text-right"
data-test-id="associated-amount"
>
<span className={dark ? 'text-white' : 'text-black'}> <span className={dark ? 'text-white' : 'text-black'}>
{integers}. {integers}.
</span> </span>