diff --git a/apps/trading-e2e/src/support/trading.ts b/apps/trading-e2e/src/support/trading.ts index d8ae8b840..011597092 100644 --- a/apps/trading-e2e/src/support/trading.ts +++ b/apps/trading-e2e/src/support/trading.ts @@ -30,6 +30,7 @@ import { withdrawalsQuery, protocolUpgradeProposalsQuery, blockStatisticsQuery, + networkParamQuery, } from '@vegaprotocol/mock'; import type { PartialDeep } from 'type-fest'; import type { MarketDataQuery, MarketsQuery } from '@vegaprotocol/markets'; @@ -160,6 +161,7 @@ const mockTradingPage = ( aliasGQLQuery(req, 'Candles', candlesQuery()); aliasGQLQuery(req, 'Withdrawals', withdrawalsQuery()); aliasGQLQuery(req, 'NetworkParams', networkParamsQuery()); + aliasGQLQuery(req, 'NetworkParam', networkParamQuery); aliasGQLQuery(req, 'EstimateFees', estimateFeesQuery()); aliasGQLQuery(req, 'EstimatePosition', estimatePositionQuery()); aliasGQLQuery(req, 'ProposalsList', proposalListQuery()); diff --git a/libs/cypress/src/lib/mock-gql.ts b/libs/cypress/src/lib/mock-gql.ts index 1303ff282..f8a9512be 100644 --- a/libs/cypress/src/lib/mock-gql.ts +++ b/libs/cypress/src/lib/mock-gql.ts @@ -25,6 +25,21 @@ const hasOperationName = ( ); }; +/** + * Extracts variables from the intercepted GQL request. + * @returns Intercepted variables or empty object + */ +const extractVariables = (req: CyHttpMessages.IncomingHttpRequest): object => { + const { body } = req; + return ( + (typeof body === 'object' && + body !== null && + 'variables' in body && + body.variables) || + {} + ); +}; + export function addMockGQLCommand() { Cypress.Commands.add('mockGQL', (handler: RouteHandler) => { cy.intercept('POST', Cypress.env('VEGA_URL'), handler).as('GQL'); @@ -36,16 +51,25 @@ export const aliasGQLQuery = ( req: CyHttpMessages.IncomingHttpRequest, operationName: string, // eslint-disable-next-line @typescript-eslint/no-explicit-any - data?: any, + dataOrDataGetter?: any | ((variables: Record) => any), errors?: Partial[], headers?: Record ) => { if (hasOperationName(req, operationName)) { req.alias = operationName; + + let data = dataOrDataGetter; + if (typeof dataOrDataGetter === 'function') { + const variables = extractVariables(req); + data = dataOrDataGetter(variables); + } if (data !== undefined || errors !== undefined) { req.reply({ statusCode: 200, - body: { ...(data && { data }), ...(errors && { errors }) }, + body: { + ...(data && { data }), + ...(errors && { errors }), + }, headers: { ...req.headers, // basic default block height header response diff --git a/libs/network-parameters/src/network-params.mock.ts b/libs/network-parameters/src/network-params.mock.ts index 8ee9d8c41..7ae79ab2a 100644 --- a/libs/network-parameters/src/network-params.mock.ts +++ b/libs/network-parameters/src/network-params.mock.ts @@ -1,6 +1,7 @@ import merge from 'lodash/merge'; import type { NetworkParamQuery, + NetworkParamQueryVariables, NetworkParamsQuery, } from './__generated__/NetworkParams'; import type { PartialDeep } from 'type-fest'; @@ -20,12 +21,12 @@ export const networkParamsQuery = ( }; export const networkParamQuery = ( - override?: PartialDeep + variables: NetworkParamQueryVariables ): NetworkParamQuery => { - const defaultResult: NetworkParamQuery = { - networkParameter: networkParams[0], + const param = networkParams.find((p) => p.key === variables.key); + return { + networkParameter: param || null, }; - return merge(defaultResult, override); }; const networkParams = [ @@ -34,6 +35,16 @@ const networkParams = [ key: 'governance.proposal.market.requiredMajority', value: '0.66', }, + { + __typename: 'NetworkParameter' as const, + key: 'transfer.fee.factor', + value: '0.01', + }, + { + __typename: 'NetworkParameter' as const, + key: 'spam.protection.minimumWithdrawalQuantumMultiple', + value: '10', + }, { __typename: 'NetworkParameter' as const, key: 'blockchains.ethereumConfig',