From fcd9a0321b811dde463498c9b073d6224c5b11c9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rados=C5=82aw=20Szpiech?=
Date: Tue, 30 Aug 2022 11:09:47 +0200
Subject: [PATCH] test: dissassociation tests reworked to current
implementation (#1182)
---
.../flow/token-association-flow.cy.js | 30 +++++++++++++++----
.../src/support/staking.functions.js | 30 ++++++++-----------
.../disassociate/disassociate-page.tsx | 2 +-
3 files changed, 38 insertions(+), 24 deletions(-)
diff --git a/apps/token-e2e/src/integration/flow/token-association-flow.cy.js b/apps/token-e2e/src/integration/flow/token-association-flow.cy.js
index 32405fac3..c14f13e23 100644
--- a/apps/token-e2e/src/integration/flow/token-association-flow.cy.js
+++ b/apps/token-e2e/src/integration/flow/token-association-flow.cy.js
@@ -17,6 +17,7 @@ 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"]';
+const disassocitiationWarning = '[data-testid="disassociation-warning"]';
context(
'Token association flow - with eth and vega wallets connected',
@@ -144,6 +145,9 @@ context(
it('Able to disassociate all tokens', function () {
// 1000-ASSO-0026
+ const warningText =
+ 'Warning: Any tokens that have been nominated to a node will sacrifice rewards they are due for the current epoch. If you do not wish to sacrifice these, you should remove stake from a node at the end of an epoch before disassociation.';
+
cy.staking_page_associate_tokens('2');
cy.get(vegaWalletAssociatedBalance, txTimeout).should('contain', 2.0);
@@ -151,9 +155,7 @@ context(
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.get(disassocitiationWarning).should('contain', warningText);
cy.staking_page_disassociate_all_tokens();
@@ -203,7 +205,7 @@ context(
.should('be.visible');
});
- it('Associate both wallet and vesting contract tokens', function () {
+ it('Able to associate & disassociate both wallet and vesting contract tokens', function () {
// 1000-ASSO-0019
// 1000-ASSO-0020
// 1000-ASSO-0021
@@ -218,7 +220,7 @@ context(
'contain',
Cypress.env('vegaWalletPublicKeyShort')
);
- cy.get(associatedAmount).should('contain', '37');
+ cy.get(associatedAmount, txTimeout).should('contain', 37);
});
cy.get(vegaInWalletSection).within(() => {
@@ -226,8 +228,24 @@ context(
'contain',
Cypress.env('vegaWalletPublicKeyShort')
);
- cy.get(associatedAmount).should('contain', '21');
+ cy.get(associatedAmount, txTimeout).should('contain', 21);
});
+
+ cy.get(vegaWalletAssociatedBalance, txTimeout).should('contain', 58);
+
+ cy.staking_page_disassociate_tokens('6', { type: 'contract' });
+ cy.get(vestingContractSection).within(() => {
+ cy.get(associatedAmount, txTimeout).should('contain', 31);
+ });
+ cy.get(vegaWalletAssociatedBalance, txTimeout).should('contain', 52);
+
+ cy.get('[href="/staking"]').first().click();
+
+ cy.staking_page_disassociate_tokens('9', { type: 'wallet' });
+ cy.get(vegaInWalletSection).within(() => {
+ cy.get(associatedAmount, txTimeout).should('contain', 12);
+ });
+ cy.get(vegaWalletAssociatedBalance, txTimeout).should('contain', 43);
});
it('Not able to associate more tokens than owned', function () {
diff --git a/apps/token-e2e/src/support/staking.functions.js b/apps/token-e2e/src/support/staking.functions.js
index 094de1bd3..7d31788a1 100644
--- a/apps/token-e2e/src/support/staking.functions.js
+++ b/apps/token-e2e/src/support/staking.functions.js
@@ -15,6 +15,8 @@ const stakeValidatorListPendingStake = '[col-id="pendingStake"]';
const stakeValidatorListTotalStake = '[col-id="totalStakeThisEpoch"]';
const stakeValidatorListTotalShare = '[col-id="share"]';
const stakeValidatorListName = '[col-id="validator"]';
+const vegaKeySelector = '#vega-key-selector';
+
const txTimeout = Cypress.env('txTimeout');
const epochTimeout = Cypress.env('epochTimeout');
@@ -91,24 +93,19 @@ Cypress.Commands.add('staking_page_disassociate_tokens', (amount, options) => {
cy.highlight(`Disassociating ${amount} tokens via Staking Page`);
cy.get(ethWalletDissociateButton).first().click();
- cy.get(associateWalletRadioButton, epochTimeout).click();
+
+ cy.get(vegaKeySelector)
+ .invoke('attr', 'disabled')
+ .then((disabled) => {
+ if (!disabled) {
+ cy.get(vegaKeySelector).select(
+ `${type}-${Cypress.env('vegaWalletPublicKey')}`
+ );
+ }
+ });
+
cy.get(tokenAmountInputBox, epochTimeout).type(amount);
-
cy.get(tokenSubmitButton, epochTimeout).should('be.enabled').click();
- cy.contains(
- `${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(
@@ -130,7 +127,6 @@ Cypress.Commands.add('staking_page_disassociate_tokens', (amount, options) => {
Cypress.Commands.add('staking_page_disassociate_all_tokens', () => {
cy.highlight(`Disassociating all tokens via Staking Page`);
cy.get(ethWalletDissociateButton).first().click();
- cy.get(associateWalletRadioButton, epochTimeout).click();
cy.get(stakeMaximumTokens, epochTimeout).click();
cy.get(tokenSubmitButton, epochTimeout).click();
cy.contains(
diff --git a/apps/token/src/routes/staking/disassociate/disassociate-page.tsx b/apps/token/src/routes/staking/disassociate/disassociate-page.tsx
index 863e1e976..84e8bd34d 100644
--- a/apps/token/src/routes/staking/disassociate/disassociate-page.tsx
+++ b/apps/token/src/routes/staking/disassociate/disassociate-page.tsx
@@ -170,7 +170,7 @@ export const DisassociatePage = ({
'Use this form to disassociate VEGA tokens with a Vega key. This returns them to either the Ethereum wallet that used the Staking bridge or the vesting contract.'
)}
-
+
{t('Warning')}:{' '}
{t(
'Any tokens that have been nominated to a node will sacrifice rewards they are due for the current epoch. If you do not wish to sacrifice these, you should remove stake from a node at the end of an epoch before disassociation.'