From fae61c28cadb93981294c7258526f6ee4efef42b Mon Sep 17 00:00:00 2001 From: Joe Tsang <30622993+jtsang586@users.noreply.github.com> Date: Fri, 12 May 2023 13:44:22 +0100 Subject: [PATCH] chore(cypress): remove cypress project id (#3739) --- .github/workflows/cypress-live-test.yml | 1 - .github/workflows/cypress-run.yml | 2 +- .../src/integration/flow/staking-flow.cy.ts | 1 - .../src/integration/view/validators.cy.ts | 3 - apps/governance-e2e/src/support/index.js | 2 + .../lib/commands/validators-self-delegate.ts | 221 ++++++++++-------- 6 files changed, 130 insertions(+), 100 deletions(-) diff --git a/.github/workflows/cypress-live-test.yml b/.github/workflows/cypress-live-test.yml index 13adf57d9..dcd813036 100644 --- a/.github/workflows/cypress-live-test.yml +++ b/.github/workflows/cypress-live-test.yml @@ -33,5 +33,4 @@ jobs: config: baseUrl=${{ github.event.inputs.url }} env: grepTags=@live env: - CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/cypress-run.yml b/.github/workflows/cypress-run.yml index 700403159..e8c07eaa9 100644 --- a/.github/workflows/cypress-run.yml +++ b/.github/workflows/cypress-run.yml @@ -66,7 +66,7 @@ jobs: ###### - name: Run Cypress tests - run: yarn nx run ${{ matrix.project }}:e2e ${{ env.SKIP_CACHE }} --record --key ${{ secrets.CYPRESS_RECORD_KEY }} --browser chrome --env.grepTags="${{ inputs.tags }}" + run: yarn nx run ${{ matrix.project }}:e2e ${{ env.SKIP_CACHE }} --browser chrome --env.grepTags="${{ inputs.tags }}" working-directory: frontend-monorepo env: CYPRESS_SLACK_WEBHOOK: ${{ secrets.CYPRESS_SLACK_WEBHOOK }} diff --git a/apps/governance-e2e/src/integration/flow/staking-flow.cy.ts b/apps/governance-e2e/src/integration/flow/staking-flow.cy.ts index abcdbb8c1..6d85d1ead 100644 --- a/apps/governance-e2e/src/integration/flow/staking-flow.cy.ts +++ b/apps/governance-e2e/src/integration/flow/staking-flow.cy.ts @@ -57,7 +57,6 @@ context( // 2001-STKE-002, 2001-STKE-032 before('visit staking tab and connect vega wallet', function () { cy.visit('/'); - cy.validatorsSelfDelegate(); ethereumWalletConnect(); // this is a workaround for #2422 which can be removed once issue is resolved cy.associateTokensToVegaWallet('4'); diff --git a/apps/governance-e2e/src/integration/view/validators.cy.ts b/apps/governance-e2e/src/integration/view/validators.cy.ts index 2c3ffce97..501c8ed84 100644 --- a/apps/governance-e2e/src/integration/view/validators.cy.ts +++ b/apps/governance-e2e/src/integration/view/validators.cy.ts @@ -31,9 +31,6 @@ const totalPenaltyToolTip = '[data-testid="total-penalty-tooltip"]'; const epochCountDown = '[data-testid="epoch-countdown"]'; const stakeNumberRegex = /^\d{1,3}(,\d{3})*(\.\d+)?$/; -// If running locally, validators need to have self-stake to be displayed -// Run cy.validatorsSelfDelegate() in before hook - context('Validators Page - verify elements on page', function () { before('navigate to validators page', function () { cy.visit('/validators'); diff --git a/apps/governance-e2e/src/support/index.js b/apps/governance-e2e/src/support/index.js index 8c49a0b4e..029f2cd28 100644 --- a/apps/governance-e2e/src/support/index.js +++ b/apps/governance-e2e/src/support/index.js @@ -33,4 +33,6 @@ before(() => { aliasGQLQuery(req, 'ChainId', chainIdQuery()); aliasGQLQuery(req, 'Statistics', statisticsQuery()); }); + // Self stake validators so they are displayed + cy.validatorsSelfDelegate(); }); diff --git a/libs/cypress/src/lib/commands/validators-self-delegate.ts b/libs/cypress/src/lib/commands/validators-self-delegate.ts index 96bf977f4..07f689dac 100644 --- a/libs/cypress/src/lib/commands/validators-self-delegate.ts +++ b/libs/cypress/src/lib/commands/validators-self-delegate.ts @@ -1,4 +1,6 @@ +import { gql } from 'graphql-request'; import { selfDelegate } from '../capsule/self-delegate'; +import { requestGQL, setGraphQLEndpoint } from '../capsule/request'; declare global { // eslint-disable-next-line @typescript-eslint/no-namespace @@ -19,112 +21,143 @@ export const addValidatorsSelfDelegate = () => { vegaUrl: Cypress.env('VEGA_URL'), faucetUrl: Cypress.env('FAUCET_URL'), }; + setGraphQLEndpoint(config.vegaUrl); + cy.wrap(getStakedByOperator()).as('selfStakeAmount'); + cy.get('@selfStakeAmount').then((selfStakeAmount) => { + if (String(selfStakeAmount) == '0') { + // Get node wallet recovery phrases + cy.exec('vegacapsule nodes ls --home-path ~/.vegacapsule/testnet/') + .its('stdout') + .then((result) => { + const obj = JSON.parse(result); + console.log(obj); + cy.writeFile( + './src/fixtures/wallet/node0RecoveryPhrase', + obj['testnet-nodeset-validators-0-validator'].Vega.NodeWalletInfo + .VegaWalletRecoveryPhrase + ); + cy.writeFile( + './src/fixtures/wallet/node1RecoveryPhrase', + obj['testnet-nodeset-validators-1-validator'].Vega.NodeWalletInfo + .VegaWalletRecoveryPhrase + ); + cy.wrap( + obj['testnet-nodeset-validators-0-validator'].Vega.NodeWalletInfo + .VegaWalletPublicKey + ).as('node0PubKey'); + cy.wrap( + obj['testnet-nodeset-validators-1-validator'].Vega.NodeWalletInfo + .VegaWalletPublicKey + ).as('node1PubKey'); - // Get node wallet recovery phrases - cy.exec('vegacapsule nodes ls --home-path ~/.vegacapsule/testnet/') - .its('stdout') - .then((result) => { - const obj = JSON.parse(result); - console.log(obj); - cy.writeFile( - './src/fixtures/wallet/node0RecoveryPhrase', - obj['testnet-nodeset-validators-0-validator'].Vega.NodeWalletInfo - .VegaWalletRecoveryPhrase + cy.wrap( + obj['testnet-nodeset-validators-0-validator'].Vega.NodeWalletInfo + .VegaWalletID + ).as('node0Id'); + cy.wrap( + obj['testnet-nodeset-validators-1-validator'].Vega.NodeWalletInfo + .VegaWalletID + ).as('node1Id'); + }); + + // Import node wallets + cy.exec( + 'vega wallet import -w node0_wallet --recovery-phrase-file ./src/fixtures/wallet/node0RecoveryPhrase -p ./src/fixtures/wallet/passphrase --home ~/.vegacapsule/testnet/wallet' ); - cy.writeFile( - './src/fixtures/wallet/node1RecoveryPhrase', - obj['testnet-nodeset-validators-1-validator'].Vega.NodeWalletInfo - .VegaWalletRecoveryPhrase + cy.exec( + 'vega wallet import -w node1_wallet --recovery-phrase-file ./src/fixtures/wallet/node1RecoveryPhrase -p ./src/fixtures/wallet/passphrase --home ~/.vegacapsule/testnet/wallet' ); - cy.wrap( - obj['testnet-nodeset-validators-0-validator'].Vega.NodeWalletInfo - .VegaWalletPublicKey - ).as('node0PubKey'); - cy.wrap( - obj['testnet-nodeset-validators-1-validator'].Vega.NodeWalletInfo - .VegaWalletPublicKey - ).as('node1PubKey'); - cy.wrap( - obj['testnet-nodeset-validators-0-validator'].Vega.NodeWalletInfo - .VegaWalletID - ).as('node0Id'); - cy.wrap( - obj['testnet-nodeset-validators-1-validator'].Vega.NodeWalletInfo - .VegaWalletID - ).as('node1Id'); - }); + // Initialise api token + cy.exec( + 'vega wallet api-token init --home ~/.vegacapsule/testnet/wallet --passphrase-file ./src/fixtures/wallet/passphrase' + ); - // Import node wallets - cy.exec( - 'vega wallet import -w node0_wallet --recovery-phrase-file ./src/fixtures/wallet/node0RecoveryPhrase -p ./src/fixtures/wallet/passphrase --home ~/.vegacapsule/testnet/wallet' - ); - cy.exec( - 'vega wallet import -w node1_wallet --recovery-phrase-file ./src/fixtures/wallet/node1RecoveryPhrase -p ./src/fixtures/wallet/passphrase --home ~/.vegacapsule/testnet/wallet' - ); + // Generate api tokens for wallets + cy.exec( + 'vega wallet api-token generate --wallet-name node0_wallet --tokens-passphrase-file ./src/fixtures/wallet/passphrase --wallet-passphrase-file ./src/fixtures/wallet/passphrase --home ~/.vegacapsule/testnet/wallet' + ) + .its('stdout') + .then((result) => { + const apiToken = result.match('[a-zA-Z0-9]{64}'); + if (apiToken) { + cy.wrap(apiToken[0]).as('node0ApiToken'); + } + }); - // Initialise api token - cy.exec( - 'vega wallet api-token init --home ~/.vegacapsule/testnet/wallet --passphrase-file ./src/fixtures/wallet/passphrase' - ); + cy.exec( + 'vega wallet api-token generate --wallet-name node1_wallet --tokens-passphrase-file ./src/fixtures/wallet/passphrase --wallet-passphrase-file ./src/fixtures/wallet/passphrase --home ~/.vegacapsule/testnet/wallet' + ) + .its('stdout') + .then((result) => { + const apiToken = result.match('[a-zA-Z0-9]{64}'); + if (apiToken) { + cy.wrap(apiToken[0]).as('node1ApiToken'); + } + }); - // Generate api tokens for wallets - cy.exec( - 'vega wallet api-token generate --wallet-name node0_wallet --tokens-passphrase-file ./src/fixtures/wallet/passphrase --wallet-passphrase-file ./src/fixtures/wallet/passphrase --home ~/.vegacapsule/testnet/wallet' - ) - .its('stdout') - .then((result) => { - const apiToken = result.match('[a-zA-Z0-9]{64}'); - if (apiToken) { - cy.wrap(apiToken[0]).as('node0ApiToken'); - } - }); + cy.updateCapsuleMultiSig(); + cy.highlight('Validators self-delegating'); - cy.exec( - 'vega wallet api-token generate --wallet-name node1_wallet --tokens-passphrase-file ./src/fixtures/wallet/passphrase --wallet-passphrase-file ./src/fixtures/wallet/passphrase --home ~/.vegacapsule/testnet/wallet' - ) - .its('stdout') - .then((result) => { - const apiToken = result.match('[a-zA-Z0-9]{64}'); - if (apiToken) { - cy.wrap(apiToken[0]).as('node1ApiToken'); - } - }); - - cy.updateCapsuleMultiSig(); - cy.highlight('Validators self-delegating'); - - // Self delegating Node 0 wallet - cy.get('@node0PubKey').then((node0PubKey) => { - cy.get('@node0ApiToken').then((node0ApiToken) => { - cy.get('@node0Id').then((node0Id) => { - cy.wrap( - selfDelegate( - config, - String(node0PubKey), - String(node0ApiToken), - String(node0Id) - ), - { timeout: 60000 } - ); - // Self delegating Node 1 wallet - cy.get('@node1PubKey').then((node1PubKey) => { - cy.get('@node1ApiToken').then((node1ApiToken) => { - cy.get('@node1Id').then((node1Id) => { - cy.wrap( - selfDelegate( - config, - String(node1PubKey), - String(node1ApiToken), - String(node1Id) - ), - { timeout: 60000 } - ); + // Self delegating Node 0 wallet + cy.get('@node0PubKey').then((node0PubKey) => { + cy.get('@node0ApiToken').then((node0ApiToken) => { + cy.get('@node0Id').then((node0Id) => { + cy.wrap( + selfDelegate( + config, + String(node0PubKey), + String(node0ApiToken), + String(node0Id) + ), + { timeout: 60000 } + ); + // Self delegating Node 1 wallet + cy.get('@node1PubKey').then((node1PubKey) => { + cy.get('@node1ApiToken').then((node1ApiToken) => { + cy.get('@node1Id').then((node1Id) => { + cy.wrap( + selfDelegate( + config, + String(node1PubKey), + String(node1ApiToken), + String(node1Id) + ), + { timeout: 60000 } + ); + }); + }); }); }); }); }); - }); + } }); }); }; + +async function getStakedByOperator() { + const query = gql` + query ExplorerNodes { + nodesConnection { + edges { + node { + stakedByOperator + } + } + } + } + `; + + const res = await requestGQL<{ + nodesConnection: { + edges: Array<{ + node: { + stakedByOperator: string; + }; + }>; + }; + }>(query); + + return res.nodesConnection.edges[0].node.stakedByOperator; +}