chore: change connect vega wallet to set vega wallet config in local storage (#2502)

This commit is contained in:
Radosław Szpiech 2023-01-03 14:56:33 +01:00 committed by GitHub
parent 0167a42990
commit 14f0c5a5fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 75 additions and 98 deletions

View File

@ -4,8 +4,8 @@ const marketName = 'ACTIVE MARKET';
describe('market selector', { tags: '@smoke' }, () => {
beforeEach(() => {
cy.mockConsole();
cy.setVegaWallet();
cy.visit(`/trading/${marketId}`);
cy.connectVegaWallet();
cy.wait('@Markets');
});

View File

@ -51,8 +51,8 @@ describe('Market trade', { tags: '@regression' }, () => {
cy.mockGQL((req) => {
aliasGQLQuery(req, 'Market', marketQuery(marketOverride));
});
cy.setVegaWallet();
cy.visit(`/trading/${marketId}`);
cy.connectVegaWallet();
cy.wait('@Market');
});

View File

@ -34,11 +34,11 @@ describe('Portfolio page tabs', { tags: '@smoke' }, () => {
aliasGQLQuery(req, 'Accounts', accountsQuery());
aliasGQLQuery(req, 'Assets', assetsQuery());
});
cy.setVegaWallet();
});
it('certain tabs should exist', () => {
cy.visit('/portfolio');
cy.connectVegaWallet();
cy.getByTestId('assets').click();
cy.location('pathname').should('eq', '/portfolio/assets');
@ -68,17 +68,13 @@ describe('Portfolio page tabs', { tags: '@smoke' }, () => {
aliasGQLQuery(req, 'Accounts', accountsQuery());
aliasGQLQuery(req, 'Assets', assetsQuery());
});
cy.setVegaWallet();
cy.visit('/portfolio/assets');
cy.connectVegaWallet();
});
it('data should be properly rendered', () => {
cy.get('.ag-center-cols-container .ag-row').should('have.length', 5);
cy.get(
'.ag-center-cols-container [row-id="ACCOUNT_TYPE_GENERAL-asset-id-null"]'
)
.find('button')
.click();
cy.get('[title="tEURO"] button').click();
cy.getByTestId('dialog-title').should(
'have.text',
'Asset details - tEURO'
@ -99,8 +95,8 @@ describe('Portfolio page tabs', { tags: '@smoke' }, () => {
aliasGQLQuery(req, 'Accounts', accountsQuery());
aliasGQLQuery(req, 'Assets', assetsQuery());
});
cy.setVegaWallet();
cy.visit('/portfolio/positions');
cy.connectVegaWallet();
});
it('data should be properly rendered', () => {
@ -116,8 +112,8 @@ describe('Portfolio page tabs', { tags: '@smoke' }, () => {
aliasGQLQuery(req, 'Orders', ordersQuery());
aliasGQLQuery(req, 'Markets', marketsQuery());
});
cy.setVegaWallet();
cy.visit('/portfolio/orders');
cy.connectVegaWallet();
});
it('data should be properly rendered', () => {
@ -134,8 +130,8 @@ describe('Portfolio page tabs', { tags: '@smoke' }, () => {
aliasGQLQuery(req, 'Markets', marketsQuery());
aliasGQLQuery(req, 'Fills', fillsQuery());
});
cy.setVegaWallet();
cy.visit('/portfolio/fills');
cy.connectVegaWallet();
});
it('data should be properly rendered', () => {
@ -161,8 +157,8 @@ describe('Portfolio page tabs', { tags: '@smoke' }, () => {
aliasGQLQuery(req, 'Margins', marginsQuery());
aliasGQLQuery(req, 'MarketsData', marketsDataQuery());
});
cy.setVegaWallet();
cy.visit('/portfolio');
cy.connectVegaWallet();
});
it('"No data to display" should be always displayed', () => {

View File

@ -6,43 +6,41 @@ const amountField = 'input[name="amount"]';
const formFieldError = 'input-error-text';
describe('deposit form validation', { tags: '@smoke' }, () => {
beforeEach(() => {
before(() => {
cy.mockWeb3Provider();
cy.mockSubscription();
cy.mockTradingPage();
cy.setVegaWallet();
cy.visit('/#/portfolio');
cy.get('main[data-testid="/portfolio"]').should('exist');
cy.getByTestId('Deposits').click();
cy.getByTestId('tab-deposits').contains('Connect your Vega wallet');
cy.connectVegaWallet();
cy.getByTestId('deposit-button').click();
cy.wait('@Assets');
connectEthereumWallet();
cy.getByTestId('deposit-submit').click();
});
it('handles empty fields', () => {
cy.getByTestId(formFieldError).should('contain.text', 'Required');
cy.getByTestId(formFieldError).should('have.length', 2);
});
it('unable to select assets not enabled', () => {
connectEthereumWallet();
cy.getByTestId('deposit-submit').click();
// Assets not enabled in mocks
cy.get(assetSelectField + ' option:contains(Asset 2)').should('not.exist');
cy.get(assetSelectField + ' option:contains(Asset 3)').should('not.exist');
cy.get(assetSelectField + ' option:contains(Asset 4)').should('not.exist');
});
it('handles empty fields', () => {
connectEthereumWallet();
// Submit form to trigger any empty validation messages
cy.getByTestId('deposit-submit').click();
cy.getByTestId(formFieldError).should('contain.text', 'Required');
cy.getByTestId(formFieldError).should('have.length', 2);
// Invalid public key
it('invalid public key', () => {
cy.get(toAddressField)
.clear()
.type('INVALID_DEPOSIT_TO_ADDRESS')
.next(`[data-testid="${formFieldError}"]`)
.should('have.text', 'Invalid Vega key');
});
it('invalid amount', () => {
// Deposit amount smaller than minimum viable for selected asset
// Select an amount so that we have a known decimal places value to work with
cy.get(assetSelectField).select('Euro');
@ -51,7 +49,9 @@ describe('deposit form validation', { tags: '@smoke' }, () => {
.type('0.00000000000000000000000000000000001')
.next(`[data-testid="${formFieldError}"]`)
.should('have.text', 'Value is below minimum');
});
it('insufficient funds', () => {
// Deposit amount is valid, but less than approved. This will always be the case because our
// CI wallet wont have approved any assets
cy.get(amountField)

View File

@ -235,9 +235,9 @@ describe('market states not accepting orders', { tags: '@smoke' }, function () {
beforeEach(function () {
cy.mockTradingPage(marketState);
cy.mockSubscription();
cy.setVegaWallet();
cy.visit('/#/markets/market-0');
cy.wait('@Market');
cy.connectVegaWallet();
});
it('must display that market is not accepting orders', function () {
cy.getByTestId('place-order').click();

View File

@ -2,6 +2,7 @@ beforeEach(() => {
cy.mockTradingPage();
cy.mockWeb3Provider();
cy.mockSubscription();
cy.setVegaWallet();
cy.visit('/#/markets/market-0');
});
@ -10,8 +11,6 @@ describe('accounts', { tags: '@smoke' }, () => {
const tradingAccountRowId = '[row-id="asset-0"]';
cy.getByTestId('Collateral').click();
cy.connectVegaWallet();
cy.getByTestId('tab-accounts').should('be.visible');
cy.getByTestId('tab-accounts')

View File

@ -30,16 +30,7 @@ const displayTomorrow = () => {
describe('time in force default values', () => {
before(() => {
cy.window().then((win) => {
win.localStorage.setItem(
'vega_wallet_config',
JSON.stringify({
token: Cypress.env('VEGA_WALLET_API_TOKEN'),
connector: 'jsonRpc',
url: 'http://localhost:1789',
})
);
});
cy.setVegaWallet();
cy.mockTradingPage();
cy.mockSubscription();
cy.visit('/#/markets/market-0');
@ -68,7 +59,7 @@ describe('time in force default values', () => {
describe('must submit order', { tags: '@smoke' }, () => {
// 7002-SORD-039
before(() => {
setVegaConfig();
cy.setVegaWallet();
cy.mockTradingPage();
cy.mockSubscription();
cy.visit('/#/markets/market-0');
@ -76,7 +67,7 @@ describe('must submit order', { tags: '@smoke' }, () => {
});
beforeEach(() => {
setVegaConfig();
cy.setVegaWallet();
});
it('successfully places market buy order', () => {
@ -162,7 +153,7 @@ describe(
{ tags: '@regression' },
() => {
before(() => {
setVegaConfig();
cy.setVegaWallet();
cy.mockTradingPage(
Schema.MarketState.STATE_SUSPENDED,
Schema.MarketTradingMode.TRADING_MODE_BATCH_AUCTION,
@ -174,7 +165,7 @@ describe(
});
beforeEach(() => {
setVegaConfig();
cy.setVegaWallet();
});
it('successfully places limit buy order', () => {
@ -231,7 +222,7 @@ describe(
{ tags: '@regression' },
() => {
before(() => {
setVegaConfig();
cy.setVegaWallet();
cy.mockTradingPage(
Schema.MarketState.STATE_SUSPENDED,
Schema.MarketTradingMode.TRADING_MODE_OPENING_AUCTION,
@ -243,7 +234,7 @@ describe(
});
beforeEach(() => {
setVegaConfig();
cy.setVegaWallet();
});
it('successfully places limit buy order', () => {
@ -300,7 +291,7 @@ describe(
{ tags: '@regression' },
() => {
before(() => {
setVegaConfig();
cy.setVegaWallet();
cy.mockTradingPage(
Schema.MarketState.STATE_SUSPENDED,
Schema.MarketTradingMode.TRADING_MODE_MONITORING_AUCTION,
@ -312,7 +303,7 @@ describe(
});
beforeEach(() => {
setVegaConfig();
cy.setVegaWallet();
});
it('successfully places limit buy order', () => {
@ -410,7 +401,7 @@ describe('deal ticket validation', { tags: '@smoke' }, () => {
describe('deal ticket size validation', { tags: '@smoke' }, function () {
beforeEach(() => {
setVegaConfig();
cy.setVegaWallet();
cy.mockTradingPage();
cy.visit('/#/markets/market-0');
cy.wait('@Market');
@ -444,7 +435,7 @@ describe('deal ticket size validation', { tags: '@smoke' }, function () {
describe('limit order validations', { tags: '@smoke' }, () => {
before(() => {
setVegaConfig();
cy.setVegaWallet();
cy.mockTradingPage();
cy.mockSubscription();
cy.visit('/#/markets/market-0');
@ -453,7 +444,7 @@ describe('limit order validations', { tags: '@smoke' }, () => {
});
beforeEach(() => {
setVegaConfig();
cy.setVegaWallet();
});
it('must see the price unit', function () {
@ -537,7 +528,7 @@ describe('limit order validations', { tags: '@smoke' }, () => {
describe('market order validations', { tags: '@smoke' }, () => {
before(() => {
setVegaConfig();
cy.setVegaWallet();
cy.mockTradingPage();
cy.visit('/#/markets/market-0');
cy.wait('@Market');
@ -545,7 +536,7 @@ describe('market order validations', { tags: '@smoke' }, () => {
});
beforeEach(() => {
setVegaConfig();
cy.setVegaWallet();
});
it('must not see the price unit', function () {
@ -586,7 +577,7 @@ describe('market order validations', { tags: '@smoke' }, () => {
describe('suspended market validation', { tags: '@regression' }, () => {
before(() => {
setVegaConfig();
cy.setVegaWallet();
cy.mockTradingPage(
Schema.MarketState.STATE_SUSPENDED,
Schema.MarketTradingMode.TRADING_MODE_MONITORING_AUCTION,
@ -598,7 +589,7 @@ describe('suspended market validation', { tags: '@regression' }, () => {
});
beforeEach(() => {
setVegaConfig();
cy.setVegaWallet();
});
it('should show warning for market order', function () {
@ -639,7 +630,7 @@ describe('suspended market validation', { tags: '@regression' }, () => {
describe('account validation', { tags: '@regression' }, () => {
describe('zero balance error', () => {
beforeEach(() => {
setVegaConfig();
cy.setVegaWallet();
cy.mockTradingPage();
cy.mockGQL((req) => {
aliasGQLQuery(
@ -686,7 +677,7 @@ describe('account validation', { tags: '@regression' }, () => {
describe('not enough balance warning', () => {
beforeEach(() => {
setVegaConfig();
cy.setVegaWallet();
cy.mockTradingPage();
cy.mockGQL((req) => {
aliasGQLQuery(
@ -745,16 +736,3 @@ const createOrder = (order: OrderSubmission): void => {
}
cy.getByTestId(placeOrderBtn).click();
};
const setVegaConfig = () => {
cy.window().then((win) => {
win.localStorage.setItem(
'vega_wallet_config',
JSON.stringify({
token: Cypress.env('VEGA_WALLET_API_TOKEN'),
connector: 'jsonRpc',
url: 'http://localhost:1789',
})
);
});
};

View File

@ -12,6 +12,7 @@ describe('fills', { tags: '@regression' }, () => {
)
);
});
cy.setVegaWallet();
cy.mockTradingPage();
cy.mockGQL((req) => {
aliasGQLQuery(
@ -27,20 +28,12 @@ describe('fills', { tags: '@regression' }, () => {
cy.visit('/#/portfolio');
cy.get('main[data-testid="/portfolio"]').should('exist');
cy.getByTestId('Fills').click();
cy.getByTestId('tab-fills').contains('Connect your Vega wallet');
cy.connectVegaWallet();
validateFillsDisplayed();
});
it('renders fills on trading tab', () => {
cy.mockTradingPage();
cy.visit('/#/markets/market-0');
cy.getByTestId('Fills').click();
cy.getByTestId('tab-fills').should(
'contain.text',
'Connect your Vega wallet'
);
cy.connectVegaWallet();
validateFillsDisplayed();
});

View File

@ -27,9 +27,9 @@ describe('orders list', { tags: '@smoke' }, () => {
cy.spy(subscriptionMocks, 'OrdersUpdate');
cy.mockTradingPage();
cy.mockSubscription(subscriptionMocks);
cy.setVegaWallet();
cy.visit('/#/markets/market-0');
cy.getByTestId('Orders').click();
cy.connectVegaWallet();
cy.wait('@Orders').then(() => {
expect(subscriptionMocks.OrdersUpdate).to.be.calledOnce;
});
@ -125,9 +125,9 @@ describe('subscribe orders', { tags: '@smoke' }, () => {
cy.spy(subscriptionMocks, 'OrdersUpdate');
cy.mockTradingPage();
cy.mockSubscription(subscriptionMocks);
cy.setVegaWallet();
cy.visit('/#/markets/market-0');
cy.getByTestId('Orders').click();
cy.connectVegaWallet();
cy.wait('@Orders').then(() => {
expect(subscriptionMocks.OrdersUpdate).to.be.calledOnce;
});
@ -341,9 +341,9 @@ describe('amend and cancel order', { tags: '@smoke' }, () => {
cy.spy(subscriptionMocks, 'OrdersUpdate');
cy.mockTradingPage();
cy.mockSubscription(subscriptionMocks);
cy.setVegaWallet();
cy.visit('/#/markets/market-0');
cy.getByTestId('Orders').click();
cy.connectVegaWallet();
cy.wait('@Orders').then(() => {
expect(subscriptionMocks.OrdersUpdate).to.be.calledOnce;
});

View File

@ -13,11 +13,11 @@ describe('Portfolio page', { tags: '@smoke' }, () => {
aliasGQLQuery(req, 'Markets', marketsQuery());
});
cy.mockSubscription();
cy.setVegaWallet();
});
describe('Ledger entries', () => {
it('List should be properly rendered', () => {
cy.visit('/#/portfolio');
cy.connectVegaWallet();
cy.getByTestId('"Ledger entries"').click();
const headers = [
'Sender',

View File

@ -1,25 +1,19 @@
beforeEach(() => {
cy.mockTradingPage();
cy.mockSubscription();
cy.setVegaWallet();
});
describe('positions', { tags: '@smoke' }, () => {
it('renders positions on trading page', () => {
cy.visit('/#/markets/market-0');
cy.getByTestId('Positions').click();
cy.getByTestId('tab-positions').should(
'contain.text',
'Connect your Vega wallet'
);
cy.connectVegaWallet();
validatePositionsDisplayed();
});
it('renders positions on portfolio page', () => {
cy.visit('/#/portfolio');
cy.getByTestId('Positions').click();
cy.connectVegaWallet();
validatePositionsDisplayed();
});

View File

@ -15,13 +15,11 @@ describe('withdraw form validation', { tags: '@smoke' }, () => {
cy.mockWeb3Provider();
cy.mockTradingPage();
cy.mockSubscription();
cy.setVegaWallet();
cy.visit('/#/portfolio');
cy.getByTestId('Withdrawals').click();
// Withdraw page requires vega wallet connection
cy.connectVegaWallet();
cy.getByTestId('withdraw-dialog-button').click();
// It also requires connection Ethereum wallet
@ -72,13 +70,10 @@ describe('withdraw actions', { tags: '@regression' }, () => {
cy.mockWeb3Provider();
cy.mockTradingPage();
cy.mockSubscription();
cy.setVegaWallet();
cy.visit('/#/portfolio');
cy.getByTestId('Withdrawals').click();
// Withdraw page requires vega wallet connection
cy.connectVegaWallet();
cy.getByTestId('withdraw-dialog-button').click();
connectEthereumWallet();

View File

@ -10,7 +10,10 @@ import { addVegaWalletReceiveFaucetedAsset } from './lib/commands/vega-wallet-re
import { addContainsExactly } from './lib/commands/contains-exactly';
import { addGetNetworkParameters } from './lib/commands/get-network-parameters';
import { addUpdateCapsuleMultiSig } from './lib/commands/add-validators-to-multisig';
import { addVegaWalletConnect } from './lib/commands/vega-wallet-connect';
import {
addVegaWalletConnect,
addSetVegaWallet,
} from './lib/commands/vega-wallet-connect';
import { addMockTransactionResponse } from './lib/commands/mock-transaction-response';
addGetTestIdcommand();
@ -26,6 +29,7 @@ addContainsExactly();
addGetNetworkParameters();
addUpdateCapsuleMultiSig();
addVegaWalletConnect();
addSetVegaWallet();
addMockTransactionResponse();
export { mockConnectWallet } from './lib/commands/vega-wallet-connect';

View File

@ -7,6 +7,10 @@ declare global {
interface Chainable<Subject> {
connectVegaWallet(): void;
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface Chainable<Subject> {
setVegaWallet(): void;
}
}
}
@ -21,7 +25,6 @@ export const mockConnectWallet = () => {
};
export function addVegaWalletConnect() {
// @ts-ignore - ignoring Cypress type error which gets resolved when Cypress uses the command
Cypress.Commands.add('connectVegaWallet', () => {
mockConnectWallet();
cy.highlight(`Connecting Vega Wallet`);
@ -38,3 +41,18 @@ export function addVegaWalletConnect() {
cy.get('[data-testid=dialog-content]').should('not.exist');
});
}
export function addSetVegaWallet() {
Cypress.Commands.add('setVegaWallet', () => {
cy.window().then((win) => {
win.localStorage.setItem(
'vega_wallet_config',
JSON.stringify({
token: Cypress.env('VEGA_WALLET_API_TOKEN'),
connector: 'jsonRpc',
url: 'http://localhost:1789',
})
);
});
});
}