From 927e21b045d3b7ec209a008ed909056b785f2126 Mon Sep 17 00:00:00 2001 From: Joe Tsang <30622993+jtsang586@users.noreply.github.com> Date: Thu, 24 Aug 2023 18:51:24 +0100 Subject: [PATCH] test(explorer): add e2e test for asset proposal on explorer (#4616) --- .../fixtures/mocks/new-asset-proposal.json | 26 +++++++++ .../src/integration/proposal.cy.js | 46 +++++++++++++++- .../src/support/governance.functions.js | 55 ++++++++++++++++++- .../cypress/src/lib/capsule/propose-market.ts | 6 +- 4 files changed, 128 insertions(+), 5 deletions(-) create mode 100644 apps/explorer-e2e/src/fixtures/mocks/new-asset-proposal.json diff --git a/apps/explorer-e2e/src/fixtures/mocks/new-asset-proposal.json b/apps/explorer-e2e/src/fixtures/mocks/new-asset-proposal.json new file mode 100644 index 000000000..f9295e651 --- /dev/null +++ b/apps/explorer-e2e/src/fixtures/mocks/new-asset-proposal.json @@ -0,0 +1,26 @@ +{ + "proposalSubmission": { + "rationale": { + "title": "Test new asset proposal", + "description": "E2E test for proposals" + }, + "terms": { + "newAsset": { + "changes": { + "name": "USDT Coin", + "symbol": "USDT", + "decimals": "18", + "quantum": "1", + "erc20": { + "contractAddress": "0xb404c51bbc10dcbe948077f18a4b8e553d160084", + "withdrawThreshold": "10", + "lifetimeLimit": "10" + } + } + }, + "closingTimestamp": 1724339572, + "enactmentTimestamp": 1724339572, + "validationTimestamp": 1692799617 + } + } +} diff --git a/apps/explorer-e2e/src/integration/proposal.cy.js b/apps/explorer-e2e/src/integration/proposal.cy.js index 1c6615d90..d3b512a8e 100644 --- a/apps/explorer-e2e/src/integration/proposal.cy.js +++ b/apps/explorer-e2e/src/integration/proposal.cy.js @@ -1,9 +1,10 @@ +import { getNewAssetTxBody } from '../support/governance.functions'; + context('Proposal page', { tags: '@smoke' }, function () { describe('Verify elements on page', function () { const proposalHeading = 'proposals-heading'; const dateTimeRegex = /(\d{1,2})\/(\d{1,2})\/(\d{4}), (\d{1,2}):(\d{1,2}):(\d{1,2})/gm; - const proposalTitle = 'Add Lorem Ipsum market'; before('Create market proposal', function () { cy.visit('/'); @@ -11,6 +12,8 @@ context('Proposal page', { tags: '@smoke' }, function () { }); it('Able to view proposal', function () { + const proposalTitle = 'Add Lorem Ipsum market'; + cy.navigate_to('governanceProposals'); cy.getByTestId(proposalHeading).should('be.visible'); cy.contains(proposalTitle) @@ -22,6 +25,9 @@ context('Proposal page', { tags: '@smoke' }, function () { cy.get_element_by_col_id('type').should('have.text', 'NewMarket'); cy.get_element_by_col_id('state').should('have.text', 'Enacted'); cy.getByTestId('vote-progress').should('be.visible'); + cy.getByTestId('vote-progress-bar-for') + .invoke('attr', 'style') + .should('eq', 'width: 100%;'); cy.get('[col-id="cDate"]') .invoke('text') .should('match', dateTimeRegex); @@ -35,9 +41,12 @@ context('Proposal page', { tags: '@smoke' }, function () { }); cy.getByTestId('dialog-title').should('have.text', proposalTitle); cy.get('.language-json').should('exist'); + cy.getByTestId('icon-cross').click(); }); it.skip('Proposal page displayed on mobile', function () { + const proposalTitle = 'Add Lorem Ipsum market'; + cy.common_switch_to_mobile_and_click_toggle(); cy.navigate_to('governanceProposals', true); cy.getByTestId(proposalHeading).should('be.visible'); @@ -45,5 +54,40 @@ context('Proposal page', { tags: '@smoke' }, function () { cy.get_element_by_col_id('title').should('have.text', proposalTitle); }); }); + + it('Able to view new asset proposal', function () { + const proposalTitle = 'Test new asset proposal'; + const newAssetProposalBody = getNewAssetTxBody(); + cy.VegaWalletSubmitProposal(newAssetProposalBody); + + cy.visit('/'); + cy.navigate_to('governanceProposals'); + cy.contains(proposalTitle) + .parent() + .parent() + .parent() + .within(() => { + cy.get_element_by_col_id('title').should('have.text', proposalTitle); + cy.get_element_by_col_id('type').should('have.text', 'NewAsset'); + cy.get_element_by_col_id('state').should( + 'have.text', + 'Waiting for Node Vote' + ); + cy.getByTestId('vote-progress').should('be.visible'); + cy.getByTestId('vote-progress-bar-against') + .invoke('attr', 'style') + .should('eq', 'width: 100%;'); + cy.get('[col-id="cDate"]') + .invoke('text') + .should('match', dateTimeRegex); + cy.get('[col-id="eDate"]') + .invoke('text') + .should('match', dateTimeRegex); + cy.getByTestId('external-link') + .should('have.attr', 'href') + .and('contains', 'https://governance.fairground.wtf/proposals/'); + cy.contains('View terms').should('exist').click(); + }); + }); }); }); diff --git a/apps/explorer-e2e/src/support/governance.functions.js b/apps/explorer-e2e/src/support/governance.functions.js index a509fa40d..bf0ec9321 100644 --- a/apps/explorer-e2e/src/support/governance.functions.js +++ b/apps/explorer-e2e/src/support/governance.functions.js @@ -1,8 +1,18 @@ +import { addSeconds, millisecondsToSeconds } from 'date-fns'; + export function createSuccessorMarketProposal(parentMarketId) { cy.VegaWalletSubmitProposal(getSuccessorTxBody(parentMarketId)); } function getSuccessorTxBody(parentMarketId) { + const MIN_CLOSE_SEC = 500; + const MIN_ENACT_SEC = 700; + + const closingDate = addSeconds(new Date(), MIN_CLOSE_SEC); + const enactmentDate = addSeconds(closingDate, MIN_ENACT_SEC); + const closingTimestamp = millisecondsToSeconds(closingDate.getTime()); + const enactmentTimestamp = millisecondsToSeconds(enactmentDate.getTime()); + return { proposalSubmission: { rationale: { @@ -122,8 +132,49 @@ function getSuccessorTxBody(parentMarketId) { }, }, }, - closingTimestamp: 1695666618, - enactmentTimestamp: 1695666618, + closingTimestamp, + enactmentTimestamp, + }, + }, + }; +} + +export function getNewAssetTxBody() { + const MIN_CLOSE_SEC = 500; + const MIN_ENACT_SEC = 700; + const MIN_VALID_SEC = 60; + + const closingDate = addSeconds(new Date(), MIN_CLOSE_SEC); + const enactmentDate = addSeconds(closingDate, MIN_ENACT_SEC); + const validationDate = addSeconds(new Date(), MIN_VALID_SEC); + + const closingTimestamp = millisecondsToSeconds(closingDate.getTime()); + const enactmentTimestamp = millisecondsToSeconds(enactmentDate.getTime()); + const validationTimestamp = millisecondsToSeconds(validationDate.getTime()); + + return { + proposalSubmission: { + rationale: { + title: 'Test new asset proposal', + description: 'E2E test for proposals', + }, + terms: { + newAsset: { + changes: { + name: 'USDT Coin', + symbol: 'USDT', + decimals: '18', + quantum: '1', + erc20: { + contractAddress: '0xb404c51bbc10dcbe948077f18a4b8e553d160084', + withdrawThreshold: '10', + lifetimeLimit: '10', + }, + }, + }, + closingTimestamp, + enactmentTimestamp, + validationTimestamp, }, }, }; diff --git a/libs/cypress/src/lib/capsule/propose-market.ts b/libs/cypress/src/lib/capsule/propose-market.ts index 09a7a54cb..83da99758 100644 --- a/libs/cypress/src/lib/capsule/propose-market.ts +++ b/libs/cypress/src/lib/capsule/propose-market.ts @@ -153,8 +153,10 @@ export function waitForProposal(id: string): Promise<{ id: string }> { try { const res = await getProposal(id); if ( - res.proposal !== null && - res.proposal.state === Schema.ProposalState.STATE_OPEN + (res.proposal !== null && + res.proposal.state === Schema.ProposalState.STATE_OPEN) || + res.proposal.state === + Schema.ProposalState.STATE_WAITING_FOR_NODE_VOTE ) { clearInterval(interval); resolve(res.proposal);