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"]';
const txTimeout = { timeout: 40000 };
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(
'Token association flow - with eth and vega wallets connected',
@ -37,6 +46,13 @@ context(
);
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.get(ethWalletAssociatedBalances, txTimeout)
@ -54,6 +70,11 @@ context(
});
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.get(ethWalletAssociatedBalances, txTimeout)
@ -80,7 +101,8 @@ context(
});
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)
.contains(vegaWalletPublicKeyShort)
@ -120,12 +142,18 @@ context(
});
it('Able to disassociate all tokens', function () {
// 1000-ASSO-0026
cy.staking_page_associate_tokens('2');
cy.get(vegaWalletAssociatedBalance, txTimeout).should('contain', 2.0);
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.get(ethWalletContainer).within(() => {
@ -142,6 +170,74 @@ context(
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 () {
// 1000-ASSO-0001
cy.get(tokenDetailsTable).within(() => {
cy.get(contract)
.should('be.visible')

View File

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

View File

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

View File

@ -129,33 +129,35 @@ const ConnectedKey = () => {
return (
<>
{totalVestedBalance.plus(totalLockedBalance).isEqualTo(0) ? null : (
<section data-testid="vega-in-vesting-contract">
<WalletCardAsset
image={vegaVesting}
decimals={appState.decimals}
name="VEGA"
symbol="In vesting contract"
balance={totalInVestingContract}
dark={true}
<section data-testid="vega-in-vesting-contract">
{totalVestedBalance.plus(totalLockedBalance).isEqualTo(0) ? null : (
<section>
<WalletCardAsset
image={vegaVesting}
decimals={appState.decimals}
name="VEGA"
symbol="In vesting contract"
balance={totalInVestingContract}
dark={true}
/>
<LockedProgress
locked={totalLockedBalance}
unlocked={totalVestedBalance}
total={totalVestedBalance.plus(totalLockedBalance)}
leftLabel={t('Locked')}
rightLabel={t('Unlocked')}
light={false}
/>
</section>
)}
{!Object.keys(appState.associationBreakdown.vestingAssociations)
.length ? null : (
<AssociatedAmounts
associations={appState.associationBreakdown.vestingAssociations}
notAssociated={notAssociatedInContract}
/>
<LockedProgress
locked={totalLockedBalance}
unlocked={totalVestedBalance}
total={totalVestedBalance.plus(totalLockedBalance)}
leftLabel={t('Locked')}
rightLabel={t('Unlocked')}
light={false}
/>
</section>
)}
{!Object.keys(appState.associationBreakdown.vestingAssociations)
.length ? null : (
<AssociatedAmounts
associations={appState.associationBreakdown.vestingAssociations}
notAssociated={notAssociatedInContract}
/>
)}
)}
</section>
<section data-testid="vega-in-wallet">
<WalletCardAsset
image={vegaWhite}

View File

@ -95,12 +95,18 @@ export const WalletCardRow = ({
{label}
</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}
</span>
)}
{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'}>
{integers}.
</span>