Skip to content

Commit

Permalink
Extract Cypress (#368)
Browse files Browse the repository at this point in the history
* Update Cypress

* Fix cypress tests

* Cleanup the delete account flow

* Cleanup the hooks flow

* Cleanup the networks flow

* Cleanup the NFTs flow

* Cleanup the offers flow

* Cleanup the payments flow

* Cleanup the receive flow

* Cleanup the send token flow

* Cleanup the set account flow

* Cleanup the set regular key flow

* Cleanup the sign transaction flow

* Cleanup the submit raw transaction flow

* Cleanup the submit transaction flow

* Cleanup the submit transaction bulk flow

* Cleanup the trustlines flow

* Cleanup the xahau flow

* Rename variable for local storage wallets

* Update gitignore

* Update naming for the environment variables

* Update the pipeline
  • Loading branch information
FlorianBouron authored May 22, 2024
1 parent b590d1e commit 72d9e56
Show file tree
Hide file tree
Showing 22 changed files with 233 additions and 443 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,11 @@ jobs:
browser: chrome
config-file: cypress.config.ts
working-directory: packages/extension
env:
CYPRESS_DEFAULT_WALLET_ADDRESS: ${{vars.CYPRESS_DEFAULT_WALLET_ADDRESS}}
CYPRESS_ISSUER_ETH_ADDRESS: ${{vars.CYPRESS_ISSUER_ETH_ADDRESS}}
CYPRESS_ISSUER_SOLO_ADDRESS: ${{vars.CYPRESS_ISSUER_SOLO_ADDRESS}}
CYPRESS_LOCAL_STORAGE_WALLETS: ${{vars.CYPRESS_LOCAL_STORAGE_WALLETS}}
CYPRESS_MNEMONIC: ${{vars.CYPRESS_MNEMONIC}}
CYPRESS_PASSWORD: ${{vars.CYPRESS_PASSWORD}}
CYPRESS_SEED: ${{vars.CYPRESS_SEED}}
4 changes: 4 additions & 0 deletions packages/extension/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ dist-ssr
.env.development.local
.env.test.local
.env.production.local


# Cypress
cypress.env.json
26 changes: 12 additions & 14 deletions packages/extension/cypress/e2e/NFT.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { Chain, XRPLNetwork } from '@gemwallet/constants';

import { navigate } from '../utils/navigation';

// deepcode ignore NoHardcodedPasswords: password used for testing purposes
const PASSWORD = 'SECRET_PASSWORD';
const PASSWORD = Cypress.env('PASSWORD');
const LOCAL_STORAGE_WALLETS = Cypress.env('LOCAL_STORAGE_WALLETS');
const ISSUER_ADDRESS = Cypress.env('ISSUER_SOLO_ADDRESS');
const STORAGE_KEY = '1693425372955.3833';

describe('Mint', () => {
Expand Down Expand Up @@ -33,10 +34,7 @@ describe('Mint', () => {
beforeEach(() => {
// Mock the localStorage with a wallet already loaded
cy.window().then((win) => {
win.localStorage.setItem(
'wallets',
'U2FsdGVkX19VA07d7tVhAAtUbt+YVbw0xQY7OZMykOW4YI4nRZK9iZ7LT3+xHvrj4kwlPKEcRg0S1GjbIWSFaMzg3Mw8fklZrZLL9QZvnbF821SeDB5lBBj/F9PBg8A07uZhYz1p4sTDsWAOFvrnKJjmlWIqXzN5MFFbWBb3os2xGtAGTslFVUXuTp6eM9X9'
);
win.localStorage.setItem('wallets', LOCAL_STORAGE_WALLETS);
win.localStorage.setItem(
'network',
JSON.stringify({
Expand Down Expand Up @@ -164,7 +162,7 @@ describe('Mint', () => {
const params = {
amount: {
currency: 'SOLO',
issuer: 'rHZwvHEs56GCmHupwjA4RY7oPA3EoAJWuN',
issuer: ISSUER_ADDRESS,
value: '0.4'
},
fee: '199',
Expand All @@ -189,7 +187,7 @@ describe('Mint', () => {

cy.contains('p', 'NFT').next().should('have.text', this.NFTokenID);
cy.contains('Amount').next().should('have.text', '0.4 SOLO');
cy.contains('Trustline').next().should('have.text', 'rHZwvHEs56GCmHupwjA4RY7oPA3EoAJWuN');
cy.contains('Trustline').next().should('have.text', ISSUER_ADDRESS);
cy.contains('Memo').next().should('have.text', 'Test memo');
cy.contains('Flags').next().should('have.text', 'Offer type: Sell offer');

Expand All @@ -214,7 +212,7 @@ describe('Mint', () => {
const params = {
amount: {
currency: '534F4C4F00000000000000000000000000000000',
issuer: 'rHZwvHEs56GCmHupwjA4RY7oPA3EoAJWuN',
issuer: ISSUER_ADDRESS,
value: '0.4'
},
fee: '199',
Expand All @@ -239,7 +237,7 @@ describe('Mint', () => {

cy.contains('p', 'NFT').next().should('have.text', this.NFTokenID);
cy.contains('Amount').next().should('have.text', '0.4 SOLO');
cy.contains('Trustline').next().should('have.text', 'rHZwvHEs56GCmHupwjA4RY7oPA3EoAJWuN');
cy.contains('Trustline').next().should('have.text', ISSUER_ADDRESS);
cy.contains('Memo').next().should('have.text', 'Test memo');
cy.contains('Flags').next().should('have.text', 'Offer type: Sell offer');

Expand Down Expand Up @@ -334,7 +332,7 @@ describe('Mint', () => {
],
NFTokenBrokerFee: {
currency: 'SOLO',
issuer: 'rHZwvHEs56GCmHupwjA4RY7oPA3EoAJWuN',
issuer: ISSUER_ADDRESS,
value: '0.1'
}
};
Expand All @@ -347,7 +345,7 @@ describe('Mint', () => {
cy.contains('Sell Offer').next().should('have.text', this.OfferID);

cy.contains('Broker Fee').next().should('have.text', '0.1 SOLO');
cy.contains('Trustline').next().should('have.text', 'rHZwvHEs56GCmHupwjA4RY7oPA3EoAJWuN');
cy.contains('Trustline').next().should('have.text', ISSUER_ADDRESS);

// Confirm
cy.contains('button', 'Submit').click();
Expand Down Expand Up @@ -375,7 +373,7 @@ describe('Mint', () => {
],
NFTokenBrokerFee: {
currency: '534F4C4F00000000000000000000000000000000',
issuer: 'rHZwvHEs56GCmHupwjA4RY7oPA3EoAJWuN',
issuer: ISSUER_ADDRESS,
value: '0.1'
}
};
Expand All @@ -388,7 +386,7 @@ describe('Mint', () => {
cy.contains('Sell Offer').next().should('have.text', this.OfferID);

cy.contains('Broker Fee').next().should('have.text', '0.1 SOLO');
cy.contains('Trustline').next().should('have.text', 'rHZwvHEs56GCmHupwjA4RY7oPA3EoAJWuN');
cy.contains('Trustline').next().should('have.text', ISSUER_ADDRESS);

// Confirm
cy.contains('button', 'Submit').click();
Expand Down
50 changes: 11 additions & 39 deletions packages/extension/cypress/e2e/delete_account.cy.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/// <reference types="cypress" />

import { Chain, XRPLNetwork } from '@gemwallet/constants';
import { navigate } from '../utils/navigation';

describe('Delete account', () => {
// deepcode ignore NoHardcodedPasswords: <Test file, not a real password>
const PASSWORD = 'SECRET_PASSWORD';
const PASSWORD = Cypress.env('PASSWORD');
const LOCAL_STORAGE_WALLETS = Cypress.env('LOCAL_STORAGE_WALLETS');
const DEFAULT_WALLET_ADDRESS = Cypress.env('DEFAULT_WALLET_ADDRESS');
const VALID_ADDRESS = 'rNvFCZXpDtGeQ3bVas95wGLN6N2stGmA9o';

describe('Delete account', () => {
beforeEach(() => {
// Mock the localStorage with a wallet already loaded
cy.window().then((win) => {
win.localStorage.setItem(
'wallets',
'U2FsdGVkX18AlCMtFj8wFHFphXwjUK7eE88VPubDBdA0p2PPWShzgCETsCScUwibFZBToMQ4k3pAJj1bwvo0IRlIr0eGnGizk3/Ga309btSK5igom3OSYbqT5SA3JHjCCdTgsM/+tSauA6kdb/A6O3GpNXdXihKa4V/SiuwxOUV9iTP/5zrgvGyGPkv6onJb'
);
win.localStorage.setItem('wallets', LOCAL_STORAGE_WALLETS);
win.localStorage.setItem(
'network',
JSON.stringify({
Expand Down Expand Up @@ -63,7 +63,7 @@ describe('Delete account', () => {

// Enter the same address as the current wallet
cy.get('input[name="destination-address"]').clear();
cy.get('input[name="destination-address"]').type('rJD2jq9TboEoQgNtuRYBRWqJCJupoq9uVr');
cy.get('input[name="destination-address"]').type(DEFAULT_WALLET_ADDRESS);
cy.get('input[name="destination-address"]').blur();
cy.get('#destination-address-helper-text').should(
'have.text',
Expand All @@ -73,7 +73,7 @@ describe('Delete account', () => {

// Enter valid address
cy.get('input[name="destination-address"]').clear();
cy.get('input[name="destination-address"]').type('rNvFCZXpDtGeQ3bVas95wGLN6N2stGmA9o');
cy.get('input[name="destination-address"]').type(VALID_ADDRESS);
cy.contains('button', 'Continue').should('not.be.disabled');
cy.contains('button', 'Continue').click();

Expand All @@ -82,11 +82,9 @@ describe('Delete account', () => {

cy.contains('You are about to permanently delete the following account from the XRPL:')
.next()
.should('have.text', 'rJD2jq9TboEoQgNtuRYBRWqJCJupoq9uVr');
.should('have.text', DEFAULT_WALLET_ADDRESS);

cy.contains('and transfer your XRP funds to:')
.next()
.should('have.text', 'rNvFCZXpDtGeQ3bVas95wGLN6N2stGmA9o');
cy.contains('and transfer your XRP funds to:').next().should('have.text', VALID_ADDRESS);

// We are not going to actually delete the account, so we just click on the cancel button
cy.contains('button', 'Cancel').click();
Expand All @@ -95,29 +93,3 @@ describe('Delete account', () => {
cy.contains('Settings').should('exist');
});
});

const navigate = (url: string, password: string) => {
cy.visit(url, {
onBeforeLoad(win) {
win['chrome'] = win['chrome'] || {};
win['chrome'].runtime = {
sendMessage() {}
};

win['chrome'].storage = {
local: {
get() {},
set(obj, cb) {
if (cb) cb();
}
}
};

cy.stub(win['chrome'].runtime, 'sendMessage').resolves({});
}
});

// Login
cy.get('input[name="password"]').type(password);
cy.contains('button', 'Unlock').click();
};
13 changes: 5 additions & 8 deletions packages/extension/cypress/e2e/hooks.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import { Chain, XahauNetwork } from '@gemwallet/constants';

import { navigate } from '../utils/navigation';

const PASSWORD = Cypress.env('PASSWORD');
const LOCAL_STORAGE_WALLETS = Cypress.env('LOCAL_STORAGE_WALLETS');
const STORAGE_KEY = '1693425372955.3833';

describe('Hooks', () => {
beforeEach(() => {
// Mock the localStorage with a wallet already loaded
cy.window().then((win) => {
win.localStorage.setItem(
'wallets',
'U2FsdGVkX19VA07d7tVhAAtUbt+YVbw0xQY7OZMykOW4YI4nRZK9iZ7LT3+xHvrj4kwlPKEcRg0S1GjbIWSFaMzg3Mw8fklZrZLL9QZvnbF821SeDB5lBBj/F9PBg8A07uZhYz1p4sTDsWAOFvrnKJjmlWIqXzN5MFFbWBb3os2xGtAGTslFVUXuTp6eM9X9'
);
win.localStorage.setItem('wallets', LOCAL_STORAGE_WALLETS);
win.localStorage.setItem(
'network',
JSON.stringify({
Expand All @@ -20,10 +21,6 @@ describe('Hooks', () => {
});
});

// deepcode ignore NoHardcodedPasswords: password used for testing purposes
const PASSWORD = 'SECRET_PASSWORD';
const STORAGE_KEY = '1693425372955.3833';

it('Set Hook through API', () => {
const url = `http://localhost:3000/set-hook?storageKey=${STORAGE_KEY}&id=210401976&requestMessage=undefined&transaction=setHook`;

Expand Down
37 changes: 6 additions & 31 deletions packages/extension/cypress/e2e/networks.cy.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,27 @@
/// <reference types="cypress" />

import { XRPLNetwork } from '@gemwallet/constants';
import { navigate } from '../utils/navigation';

describe('Switch networks', () => {
// deepcode ignore NoHardcodedPasswords: password used for testing purposes
const PASSWORD = 'SECRET_PASSWORD';
const PASSWORD = Cypress.env('PASSWORD');
const LOCAL_STORAGE_WALLETS = Cypress.env('LOCAL_STORAGE_WALLETS');

describe('Switch networks', () => {
let networkLocalStorage = undefined;
let customNetworkLocalStorage = undefined;
beforeEach(() => {
// Mock the localStorage with a wallet already loaded
cy.window().then((win) => {
win.localStorage.setItem(
'wallets',
'U2FsdGVkX18AlCMtFj8wFHFphXwjUK7eE88VPubDBdA0p2PPWShzgCETsCScUwibFZBToMQ4k3pAJj1bwvo0IRlIr0eGnGizk3/Ga309btSK5igom3OSYbqT5SA3JHjCCdTgsM/+tSauA6kdb/A6O3GpNXdXihKa4V/SiuwxOUV9iTP/5zrgvGyGPkv6onJb'
);
win.localStorage.setItem('wallets', LOCAL_STORAGE_WALLETS);
if (networkLocalStorage) {
win.localStorage.setItem('network', networkLocalStorage);
}
if (customNetworkLocalStorage) {
win.localStorage.setItem('customNetworks', customNetworkLocalStorage);
}
});
cy.visit('http://localhost:3000/', {
onBeforeLoad(win) {
(win as any).chrome = (win as any).chrome || {};
(win as any).chrome.runtime = {
sendMessage(message, cb) {}
};

(win as any).chrome.storage = {
local: {
get(key, cb) {},
set(obj, cb) {
if (cb) cb();
}
}
};

cy.stub((win as any).chrome.runtime, 'sendMessage').resolves({});
}
});

cy.get('.MuiCircularProgress-root', { timeout: 20000 }).should('not.exist');

// Login
cy.get('input[name="password"]').type(PASSWORD);
cy.contains('button', 'Unlock').click();
navigate('http://localhost:3000/', PASSWORD);
});

it('Switch from Mainnet (default network) to Testnet', () => {
Expand Down
Loading

0 comments on commit 72d9e56

Please sign in to comment.