From 1125d34f0345559076148052daadde829273923e Mon Sep 17 00:00:00 2001 From: AndyWhiteVega Date: Fri, 1 Jul 2022 17:09:19 +0100 Subject: [PATCH] test: env variable handling and cleanup --- apps/token-e2e/cypress.config.js | 18 +------------- apps/token-e2e/src/fixtures/envVars.json | 15 ++++++++++++ apps/token-e2e/src/fixtures/vegaToken.json | 4 ---- .../src/integration/{app.cy.ts => app.cy.js} | 0 apps/token-e2e/src/integration/app.test.js | 12 ---------- .../src/integration/flow/staking-flow.cy.js | 12 ++++------ apps/token-e2e/src/integration/home.cy.js | 6 ++--- .../token-e2e/src/support/wallet.functions.js | 24 +++++++++---------- 8 files changed, 35 insertions(+), 56 deletions(-) create mode 100644 apps/token-e2e/src/fixtures/envVars.json delete mode 100644 apps/token-e2e/src/fixtures/vegaToken.json rename apps/token-e2e/src/integration/{app.cy.ts => app.cy.js} (100%) delete mode 100644 apps/token-e2e/src/integration/app.test.js diff --git a/apps/token-e2e/cypress.config.js b/apps/token-e2e/cypress.config.js index 31b2aeea9..6e2c8c9c2 100644 --- a/apps/token-e2e/cypress.config.js +++ b/apps/token-e2e/cypress.config.js @@ -13,21 +13,5 @@ module.exports = defineConfig({ videosFolder: '../../dist/cypress/apps/explorer-e2e/videos', screenshotsFolder: '../../dist/cypress/apps/explorer-e2e/screenshots', chromeWebSecurity: false, - }, - env: { - eth_provider_url: 'http://localhost:8545/', - eth_wallet_public_key: '0xEe7D375bcB50C26d52E1A4a472D8822A2A22d94F', - eth_staking_bridge_contract_address: - '0x9135f5afd6F055e731bca2348429482eE614CFfA', - vega_wallet_name: 'capsule_wallet', - vega_wallet_location: '~/.vegacapsule/testnet/wallet', - vega_wallet_passphrase: '123', - vega_wallet_mnemonic: - 'ozone access unlock valid olympic save include omit supply green clown session', - vega_wallet_public_key: - '02eceaba4df2bef76ea10caf728d8a099a2aa846cced25737cccaa9812342f65', - vega_wallet_public_key_short: '02ecea…2f65', - vega_token_contract_address: '0xF41bD86d462D36b997C0bbb4D97a0a3382f205B7', - vega_token_address: '0x67175Da1D5e966e40D11c4B2519392B2058373de', - }, + } }); diff --git a/apps/token-e2e/src/fixtures/envVars.json b/apps/token-e2e/src/fixtures/envVars.json new file mode 100644 index 000000000..280ea067e --- /dev/null +++ b/apps/token-e2e/src/fixtures/envVars.json @@ -0,0 +1,15 @@ +{ + "tokenAddress": "0x67175Da1D5e966e40D11c4B2519392B2058373de", + "vestingContract": "0xF41bD86d462D36b997C0bbb4D97a0a3382f205B7", + "ethProviderUrl": "http://localhost:8545/", + "ethWalletPublicKey": "0xEe7D375bcB50C26d52E1A4a472D8822A2A22d94F", + "ethStakingBridgeContractAddress": "0x9135f5afd6F055e731bca2348429482eE614CFfA", + "vegaWalletName": "capsule_wallet", + "vegaWalletLocation": "~/.vegacapsule/testnet/wallet", + "vegaWalletPassphrase": "123", + "vegaWalletMnemonic":"ozone access unlock valid olympic save include omit supply green clown session", + "vegaWalletPublicKey":"02eceaba4df2bef76ea10caf728d8a099a2aa846cced25737cccaa9812342f65", + "vegaWalletPublicKeyShort": "02ecea…2f65", + "vegaTokenContractAddress": "0xF41bD86d462D36b997C0bbb4D97a0a3382f205B7", + "vegaTokenAddress": "0x67175Da1D5e966e40D11c4B2519392B2058373de" +} \ No newline at end of file diff --git a/apps/token-e2e/src/fixtures/vegaToken.json b/apps/token-e2e/src/fixtures/vegaToken.json deleted file mode 100644 index ed95eef79..000000000 --- a/apps/token-e2e/src/fixtures/vegaToken.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "tokenAddress": "0x67175Da1D5e966e40D11c4B2519392B2058373de", - "vestingContract": "0xF41bD86d462D36b997C0bbb4D97a0a3382f205B7" -} diff --git a/apps/token-e2e/src/integration/app.cy.ts b/apps/token-e2e/src/integration/app.cy.js similarity index 100% rename from apps/token-e2e/src/integration/app.cy.ts rename to apps/token-e2e/src/integration/app.cy.js diff --git a/apps/token-e2e/src/integration/app.test.js b/apps/token-e2e/src/integration/app.test.js deleted file mode 100644 index d4ba0c282..000000000 --- a/apps/token-e2e/src/integration/app.test.js +++ /dev/null @@ -1,12 +0,0 @@ -const fairgroundSet = Cypress.env('FAIRGROUND'); - -describe('token', () => { - beforeEach(() => cy.visit('/')); - - it('should always have a header title based on environment', () => { - cy.get('[data-testid="header-title"]', { timeout: 8000 }).should( - 'have.text', - `${fairgroundSet ? 'Fairground token' : 'VEGA TOKEN'}` - ); - }); -}); diff --git a/apps/token-e2e/src/integration/flow/staking-flow.cy.js b/apps/token-e2e/src/integration/flow/staking-flow.cy.js index c7acbfdfc..18920f894 100644 --- a/apps/token-e2e/src/integration/flow/staking-flow.cy.js +++ b/apps/token-e2e/src/integration/flow/staking-flow.cy.js @@ -3,6 +3,7 @@ import navigation from '../../locators/navigation.locators'; import staking from '../../locators/staking.locators'; import '../../support/staking.functions'; import '../../support/wallet.functions'; +import envVars from '../../fixtures/envVars.json'; context('Staking Tab - with vega wallet connected', function () { before('visit staking tab and connect vega wallet', function () { @@ -16,9 +17,6 @@ context('Staking Tab - with vega wallet connected', function () { cy.get(navigation.staking).first().click(); cy.get(navigation.spinner, { timeout: 20000 }).should('not.exist'); cy.get(staking.validatorNames).first().invoke('text').as('validatorName'); - cy.wrap(Cypress.env('vega_wallet_public_key_short')).as( - 'vegaPublicKeyShort' - ); }); describe('Vega wallet - contains VEGA tokens', function () { @@ -36,7 +34,7 @@ context('Staking Tab - with vega wallet connected', function () { it('Able to associate tokens', function () { cy.ethereum_wallet_associate_tokens('2'); cy.ethereum_wallet_check_associated_vega_key_value_is( - this.vegaPublicKeyShort, + envVars.vegaWalletPublicKeyShort, '2.000000000000000000' ); cy.vega_wallet_check_associated_value_is('2.000000000000000000'); @@ -45,7 +43,7 @@ context('Staking Tab - with vega wallet connected', function () { it('Able to associate more tokens than the approved amount of 1000 - requires re-approval', function () { cy.ethereum_wallet_associate_tokens('1001', 'Approve'); cy.ethereum_wallet_check_associated_vega_key_value_is( - this.vegaPublicKeyShort, + envVars.vegaWalletPublicKeyShort, '1,001.000000000000000000' ); cy.vega_wallet_check_associated_value_is('1,001.000000000000000000'); @@ -57,7 +55,7 @@ context('Staking Tab - with vega wallet connected', function () { cy.ethereum_wallet_disassociate_tokens('1'); cy.ethereum_wallet_check_associated_vega_key_value_is( - this.vegaPublicKeyShort, + envVars.vegaWalletPublicKeyShort, '1.000000000000000000' ); cy.vega_wallet_check_associated_value_is('1.000000000000000000'); @@ -69,7 +67,7 @@ context('Staking Tab - with vega wallet connected', function () { cy.ethereum_wallet_disassociate_all_tokens(); cy.ethereum_wallet_check_associated_vega_key_is_no_longer_showing( - this.vegaPublicKeyShort + envVars.vegaWalletPublicKeyShort ); cy.vega_wallet_check_associated_value_is('0.000000000000000000'); }); diff --git a/apps/token-e2e/src/integration/home.cy.js b/apps/token-e2e/src/integration/home.cy.js index 9e6863824..438557a1d 100644 --- a/apps/token-e2e/src/integration/home.cy.js +++ b/apps/token-e2e/src/integration/home.cy.js @@ -1,6 +1,6 @@ import navigation from '../locators/navigation.locators'; import home from '../locators/home.locators'; -import vegaToken from '../fixtures/vegaToken.json'; +import envVars from '../fixtures/envVars.json'; context('Home Page - verify elements on page', function () { before('visit token home page', function () { @@ -51,7 +51,7 @@ context('Home Page - verify elements on page', function () { cy.get(home.address) .should('be.visible') .invoke('text') - .should('be.equal', vegaToken.tokenAddress); + .should('be.equal', envVars.vegaTokenAddress); }); }); it('should have VESTING CONTRACT', function () { @@ -59,7 +59,7 @@ context('Home Page - verify elements on page', function () { cy.get(home.contract) .should('be.visible') .invoke('text') - .should('be.equal', vegaToken.vestingContract); + .should('be.equal', envVars.vegaTokenContractAddress); }); }); it('should have TOTAL SUPPLY', function () { diff --git a/apps/token-e2e/src/support/wallet.functions.js b/apps/token-e2e/src/support/wallet.functions.js index 2186a9dab..e213bf95e 100644 --- a/apps/token-e2e/src/support/wallet.functions.js +++ b/apps/token-e2e/src/support/wallet.functions.js @@ -6,21 +6,20 @@ import { TokenVesting, } from '@vegaprotocol/smart-contracts'; import { ethers, Wallet } from 'ethers'; +import envVars from '../fixtures/envVars.json'; // ---------------------------------------------------------------------- -const vegaWalletName = Cypress.env('vega_wallet_name'); -const vegaWalletLocation = Cypress.env('vega_wallet_location'); -const vegaWalletPassphrase = Cypress.env('vega_wallet_passphrase'); -const vegaWalletMnemonic = Cypress.env('vega_wallet_mnemonic'); -const vegaWalletPubKey = Cypress.env('vega_wallet_public_key'); -const vegaTokenContractAddress = Cypress.env('vega_token_contract_address'); -const vegaTokenAddress = Cypress.env('vega_token_address'); -const ethWalletPubKey = Cypress.env('eth_wallet_public_key'); -const ethStakingBridgeContractAddress = Cypress.env( - 'eth_staking_bridge_contract_address' -); -const ethProviderUrl = Cypress.env('eth_provider_url'); +const vegaWalletName = envVars.vegaWalletName; +const vegaWalletLocation = envVars.vegaWalletLocation; +const vegaWalletPassphrase = envVars.vegaWalletPassphrase; +const vegaWalletMnemonic = envVars.vegaWalletMnemonic; +const vegaWalletPubKey = envVars.vegaWalletPublicKey; +const vegaTokenContractAddress = envVars.vegaTokenContractAddress; +const vegaTokenAddress = envVars.vegaTokenAddress; +const ethWalletPubKey = envVars.ethWalletPublicKey; +const ethStakingBridgeContractAddress = envVars.ethStakingBridgeContractAddress; +const ethProviderUrl = envVars.ethProviderUrl; const getAccount = (number = 0) => `m/44'/60'/0'/0/${number}`; // ---------------------------------------------------------------------- @@ -190,7 +189,6 @@ Cypress.Commands.add('vega_wallet_import', function () { Cypress.Commands.add('vega_wallet_connect', function () { cy.log('**_Connecting Vega Wallet_**'); - // cy.intercept('POST', queryUrl).as('queryGrab'); cy.get(wallet.vegawallet).within(() => { cy.get('button') .contains('Connect Vega wallet to use associated $VEGA')