-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Expand file tree
/
Copy pathperps-fixture-config.ts
More file actions
653 lines (622 loc) · 22.4 KB
/
Copy pathperps-fixture-config.ts
File metadata and controls
653 lines (622 loc) · 22.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
import type { Hex, Json } from '@metamask/utils';
import type { Mockttp } from 'mockttp';
import FixtureBuilderV2 from '../../fixtures/fixture-builder-v2';
import { DEFAULT_FIXTURE_ACCOUNT_LOWERCASE } from '../../constants';
import {
getProductionRemoteFlagApiResponse,
getProductionRemoteFlagDefaults,
} from '../../feature-flags/feature-flag-registry';
import { formatUnits } from '../../../../shared/lib/unit';
import {
MOCK_ETH_OPEN_LONG_FILL,
MOCK_ETH_LIMIT_ORDER,
MOCK_ETH_FUNDING,
MOCK_USDC_DEPOSIT,
} from './mocks/websocketActivityMocks';
/**
* Production remote flag defaults used as the base for Perps remote flag state
* and HTTP mocks. Starting from these ensures any flag added to the registry is
* automatically included without having to update this file.
*/
const PROD_REMOTE_FLAGS = getProductionRemoteFlagDefaults();
const {
// Omitted from generic Perps manifest flags because the production payload is
// large and the withdraw confirmation tests provide a small explicit override.
// eslint-disable-next-line @typescript-eslint/naming-convention
confirmations_pay_post_quote: _confirmationsPayPostQuote,
...PERPS_PROD_REMOTE_FLAGS
} = PROD_REMOTE_FLAGS;
const ARBITRUM_CHAIN_ID = '0xa4b1';
const ARBITRUM_CHAIN_ID_DECIMAL = Number(ARBITRUM_CHAIN_ID);
const ARBITRUM_USDC_ADDRESS: Hex = '0xaf88d065e77c8cC2239327C5EDb3A432268e5831';
const ARBITRUM_USDC_PRICE_IN_ETH = 1 / 1700;
const HYPERCORE_CHAIN_ID = '0x539';
const HYPERCORE_CHAIN_ID_DECIMAL = Number(HYPERCORE_CHAIN_ID);
const PRICE_API_BASE_URL = 'https://price.api.cx.metamask.io';
const RELAY_API_BASE_URL = 'https://api.relay.link';
const RELAY_REQUEST_ID = 'perps-withdraw-e2e-request-id';
const RELAY_TRANSACTION_HASH =
'0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef';
const PERPS_WITHDRAW_CONFIRMATION_DISABLED_FLAG = {
overrides: {
perpsWithdraw: {
enabled: false,
},
},
};
const PERPS_WITHDRAW_CONFIRMATION_ENABLED_FLAG = {
overrides: {
perpsWithdraw: {
enabled: true,
},
},
};
const ARBITRUM_USDC_MARKET_DATA = {
tokenAddress: ARBITRUM_USDC_ADDRESS,
currency: 'ETH',
allTimeHigh: 1,
allTimeLow: 1,
circulatingSupply: 0,
dilutedMarketCap: 0,
high1d: 1,
low1d: 1,
marketCap: 0,
marketCapPercentChange1d: 0,
price: ARBITRUM_USDC_PRICE_IN_ETH,
priceChange1d: 0,
pricePercentChange1d: 0,
pricePercentChange1h: 0,
pricePercentChange1y: 0,
pricePercentChange7d: 0,
pricePercentChange14d: 0,
pricePercentChange30d: 0,
pricePercentChange200d: 0,
totalVolume: 0,
};
type RelayQuoteRequestBody = {
amount?: string;
user?: string;
};
const PERPS_ELIGIBLE_REMOTE_FEATURE_FLAGS = {
...PERPS_PROD_REMOTE_FLAGS,
// Keep existing Perps E2E coverage on the legacy withdraw page unless a test
// explicitly opts into the confirmation flow.
// eslint-disable-next-line @typescript-eslint/naming-convention
confirmations_pay_post_quote: PERPS_WITHDRAW_CONFIRMATION_DISABLED_FLAG,
perpsEnabledVersion: { enabled: true, minimumVersion: '0.0.0' },
perpsPerpTradingGeoBlockedCountriesV2: { blockedRegions: [] },
// Disable the configurable max-slippage controls in the generic Perps E2E
// fixture. When enabled, market-order submit is gated on a live order-book
// slippage estimate (usePerpsEstimatedSlippage) that the lifecycle WS mock
// does not feed, leaving submit-order-button permanently disabled. The flag
// is on in production (registry value), so it stays registered; tests that
// need the slippage UI can opt in explicitly. Covered by unit tests + recipe.
perpsSlippageConfig2: { enabled: false, minimumVersion: '0.0.0' },
};
/**
* Keep the manifest override small for Firefox's manifest size limit. The full
* production-default flag set is seeded into RemoteFeatureFlagController state.
*/
export const PERPS_ELIGIBLE_FLAG = {
remoteFeatureFlags: {
perpsEnabledVersion:
PERPS_ELIGIBLE_REMOTE_FEATURE_FLAGS.perpsEnabledVersion,
perpsPerpTradingGeoBlockedCountriesV2:
PERPS_ELIGIBLE_REMOTE_FEATURE_FLAGS.perpsPerpTradingGeoBlockedCountriesV2,
// eslint-disable-next-line @typescript-eslint/naming-convention
confirmations_pay_post_quote:
PERPS_ELIGIBLE_REMOTE_FEATURE_FLAGS.confirmations_pay_post_quote,
},
};
export const PERPS_WITHDRAW_CONFIRMATION_FLAG = {
remoteFeatureFlags: {
...PERPS_ELIGIBLE_REMOTE_FEATURE_FLAGS,
// eslint-disable-next-line @typescript-eslint/naming-convention
confirmations_pay_post_quote: PERPS_WITHDRAW_CONFIRMATION_ENABLED_FLAG,
},
};
/**
* Keep the manifest override small for Firefox's manifest size limit. The full
* production-default flag set is seeded into RemoteFeatureFlagController state.
*/
const PERPS_WITHDRAW_CONFIRMATION_MANIFEST_FLAG = {
remoteFeatureFlags: {
perpsEnabledVersion:
PERPS_WITHDRAW_CONFIRMATION_FLAG.remoteFeatureFlags.perpsEnabledVersion,
perpsPerpTradingGeoBlockedCountriesV2:
PERPS_WITHDRAW_CONFIRMATION_FLAG.remoteFeatureFlags
.perpsPerpTradingGeoBlockedCountriesV2,
// eslint-disable-next-line @typescript-eslint/naming-convention
confirmations_pay_post_quote:
PERPS_WITHDRAW_CONFIRMATION_FLAG.remoteFeatureFlags
.confirmations_pay_post_quote,
},
};
/**
* Remote feature flags for geo-blocked (ineligible) users.
* The geolocation mock returns 'US-TX', so blocking 'US' makes the user ineligible.
* EligibilityService.checkEligibility checks geoLocation.startsWith(blockedRegion).
*/
const PERPS_GEO_BLOCKED_REMOTE_FEATURE_FLAGS = {
...PROD_REMOTE_FLAGS,
// Keep existing Perps E2E coverage on the legacy withdraw page unless a test
// explicitly opts into the confirmation flow.
// eslint-disable-next-line @typescript-eslint/naming-convention
confirmations_pay_post_quote:
PERPS_ELIGIBLE_REMOTE_FEATURE_FLAGS.confirmations_pay_post_quote,
perpsEnabledVersion: { enabled: true, minimumVersion: '0.0.0' },
perpsPerpTradingGeoBlockedCountriesV2: { blockedRegions: ['US'] },
};
const PERPS_GEO_BLOCKED_FLAG = {
remoteFeatureFlags: {
perpsEnabledVersion:
PERPS_GEO_BLOCKED_REMOTE_FEATURE_FLAGS.perpsEnabledVersion,
perpsPerpTradingGeoBlockedCountriesV2:
PERPS_GEO_BLOCKED_REMOTE_FEATURE_FLAGS.perpsPerpTradingGeoBlockedCountriesV2,
// eslint-disable-next-line @typescript-eslint/naming-convention
confirmations_pay_post_quote:
PERPS_GEO_BLOCKED_REMOTE_FEATURE_FLAGS.confirmations_pay_post_quote,
},
};
/**
* Perps E2E fixture for geo-block tests: enables perps with geo-block flags and HTTP flag mock.
* Sets `useExternalServices: false` so eligibility monitoring never starts:
* without `GeolocationController:getGeolocation` on PerpsControllerMessenger,
* `refreshEligibility()` would fail and perps-controller would set `isEligible`
* to true, hiding the geo-block modal. Deferred checks keep `isEligible: false`.
* Callers must use `login(..., { waitForNonEvmAccounts: false })` because the
* home flow otherwise waits for non-EVM account icons that do not load when
* basic functionality is off.
*
* Also sets isFirstTimeUser to false so the tutorial modal does not intercept clicks.
*
* @param title - The test title (e.g. this.test?.fullTitle()) for debugging.
* @returns Partial withFixtures config to spread into withFixtures().
*/
export function getPerpsGeoBlockConfig(title?: string) {
return {
fixtures: new FixtureBuilderV2()
.withPerpsController({
isFirstTimeUser: { mainnet: false, testnet: false },
isEligible: false,
})
.withRemoteFeatureFlagController({
remoteFeatureFlags: PERPS_GEO_BLOCKED_REMOTE_FEATURE_FLAGS,
})
.build(),
title,
manifestFlags: PERPS_GEO_BLOCKED_FLAG,
/**
* Override /v1/flags so the background RemoteFeatureFlagController sees
* perpsPerpTradingGeoBlockedCountriesV2 with blockedRegions: ['US'].
* The geolocation mock returns 'US-TX', so startsWith('US') → ineligible.
*
* manifestFlags.remoteFeatureFlags only affects the UI selector; the
* background reads client-config when external services are on. This mock
* reinforces US blocking for tests that enable eligibility refresh.
* @param server
*/
testSpecificMock: async (server: Mockttp) => {
const geoBlockedFlags = getProductionRemoteFlagApiResponseWithOverrides({
// eslint-disable-next-line @typescript-eslint/naming-convention
confirmations_pay_post_quote:
PERPS_ELIGIBLE_REMOTE_FEATURE_FLAGS.confirmations_pay_post_quote,
// eslint-disable-next-line @typescript-eslint/naming-convention
confirmations_pay: { name: 'empty' },
perpsPerpTradingGeoBlockedCountriesV2: { blockedRegions: ['US'] },
});
await server
.forGet('https://client-config.api.cx.metamask.io/v1/flags')
.withQuery({ client: 'extension', distribution: 'main' })
.thenCallback(() => ({
ok: true,
statusCode: 200,
json: geoBlockedFlags,
}));
},
};
}
function getProductionRemoteFlagApiResponseWithOverrides(
overrides: Record<string, Json>,
): Json[] {
const overrideNames = new Set(Object.keys(overrides));
return [
...getProductionRemoteFlagApiResponse().filter(
(entry) =>
!Object.keys(entry as Record<string, Json>).some((name) =>
overrideNames.has(name),
),
),
...Object.entries(overrides).map(([name, value]) => ({ [name]: value })),
];
}
/**
* Registers the eligible feature-flag HTTP mock on `server`.
* Overrides /v1/flags so the background RemoteFeatureFlagController sees
* `perpsPerpTradingGeoBlockedCountriesV2` with `blockedRegions: []`,
* keeping US-TX eligible.
*
* Extracted to avoid duplicating this logic across config functions that
* all need the same flag mock alongside their own additional mocks.
*
* @param server - The Mockttp server instance to register the mock on.
*/
async function mockEligibleFeatureFlags(server: Mockttp): Promise<void> {
const eligibleFlags = getProductionRemoteFlagApiResponseWithOverrides({
// eslint-disable-next-line @typescript-eslint/naming-convention
confirmations_pay_post_quote:
PERPS_ELIGIBLE_REMOTE_FEATURE_FLAGS.confirmations_pay_post_quote,
// eslint-disable-next-line @typescript-eslint/naming-convention
confirmations_pay: { name: 'empty' },
perpsPerpTradingGeoBlockedCountriesV2: { blockedRegions: [] },
// Mirror the seeded controller state: the background
// RemoteFeatureFlagController refetches /v1/flags on load and would
// otherwise overwrite the seeded `enabled: false` with the production
// default (`enabled: true`), re-enabling slippage gating and leaving
// market submit disabled without order-book estimates.
perpsSlippageConfig2:
PERPS_ELIGIBLE_REMOTE_FEATURE_FLAGS.perpsSlippageConfig2,
});
await server
.forGet('https://client-config.api.cx.metamask.io/v1/flags')
.withQuery({
client: 'extension',
distribution: 'main',
environment: 'dev',
})
.thenCallback(() => ({
ok: true,
statusCode: 200,
json: eligibleFlags,
}));
}
async function mockArbitrumUsdcPriceData(server: Mockttp): Promise<void> {
await server
.forGet(`${PRICE_API_BASE_URL}/v1/exchange-rates`)
.always()
.thenCallback(() => ({
statusCode: 200,
json: {
eth: {
name: 'Ether',
ticker: 'eth',
value: ARBITRUM_USDC_PRICE_IN_ETH,
currencyType: 'crypto',
},
usd: {
name: 'US Dollar',
ticker: 'usd',
value: 1,
currencyType: 'fiat',
},
},
}));
}
function getArbitrumUsdcRawAmount(sourceRawAmount: string): string {
try {
return (BigInt(sourceRawAmount) / 100n).toString();
} catch {
return '0';
}
}
async function mockRelayWithdrawData(server: Mockttp): Promise<void> {
await server
.forPost(`${RELAY_API_BASE_URL}/quote`)
.always()
.thenCallback(async (request) => {
const body =
((await request.body.getJson()) as RelayQuoteRequestBody | undefined) ??
{};
const sourceRawAmount =
typeof body.amount === 'string' ? body.amount : '0';
if (sourceRawAmount === '0') {
return {
statusCode: 400,
json: {
message: 'Amount is required',
},
};
}
const targetRawAmount = getArbitrumUsdcRawAmount(sourceRawAmount);
const formattedAmount = formatUnits(BigInt(targetRawAmount), 6);
const user =
typeof body.user === 'string'
? body.user
: DEFAULT_FIXTURE_ACCOUNT_LOWERCASE;
return {
statusCode: 200,
json: {
details: {
currencyIn: {
amount: sourceRawAmount,
amountFormatted: formattedAmount,
amountUsd: formattedAmount,
currency: {
chainId: HYPERCORE_CHAIN_ID_DECIMAL,
decimals: 8,
},
},
currencyOut: {
amount: targetRawAmount,
amountFormatted: formattedAmount,
amountUsd: formattedAmount,
currency: {
chainId: ARBITRUM_CHAIN_ID_DECIMAL,
decimals: 6,
},
minimumAmount: targetRawAmount,
},
timeEstimate: 60,
totalImpact: {
usd: '0',
},
},
fees: {
app: {
amountUsd: '0',
},
relayer: {
amountUsd: '0',
},
},
metamask: {
gasLimits: [],
is7702: false,
},
steps: [
{
id: 'authorize',
items: [
{
data: {
sign: {
signatureKind: 'eip712',
domain: {
name: 'Relay',
version: '1',
chainId: ARBITRUM_CHAIN_ID_DECIMAL,
verifyingContract:
'0x0000000000000000000000000000000000000000',
},
types: {
Authorize: [
{ name: 'nonce', type: 'uint256' },
{ name: 'user', type: 'address' },
],
},
value: {
nonce: '1',
user,
},
primaryType: 'Authorize',
},
post: {
endpoint: `${RELAY_API_BASE_URL}/authorize`,
method: 'POST',
body: {
requestId: RELAY_REQUEST_ID,
},
},
},
status: 'incomplete',
},
],
kind: 'signature',
requestId: RELAY_REQUEST_ID,
},
{
id: 'deposit',
items: [
{
check: {
endpoint: 'https://api.hyperliquid.xyz/exchange',
method: 'POST',
},
data: {
action: {
type: 'sendAsset',
parameters: {
destination: user,
token: 'USDC',
amount: formattedAmount,
time: '1',
},
},
nonce: 1,
eip712PrimaryType: 'HyperliquidTransaction',
eip712Types: {
HyperliquidTransaction: [
{ name: 'destination', type: 'address' },
{ name: 'token', type: 'string' },
{ name: 'amount', type: 'string' },
{ name: 'time', type: 'string' },
{ name: 'type', type: 'string' },
{ name: 'signatureChainId', type: 'string' },
],
},
},
status: 'incomplete',
},
],
kind: 'transaction',
requestId: RELAY_REQUEST_ID,
},
],
},
};
});
await server
.forPost(`${RELAY_API_BASE_URL}/authorize`)
.always()
.thenCallback(() => ({
statusCode: 200,
json: { status: 'ok' },
}));
await server
.forGet(`${RELAY_API_BASE_URL}/intents/status/v3`)
.withQuery({ requestId: RELAY_REQUEST_ID })
.always()
.thenCallback(() => ({
statusCode: 200,
json: {
status: 'success',
inTxHashes: [RELAY_TRANSACTION_HASH],
txHashes: [RELAY_TRANSACTION_HASH],
updatedAt: Date.now(),
originChainId: HYPERCORE_CHAIN_ID_DECIMAL,
destinationChainId: ARBITRUM_CHAIN_ID_DECIMAL,
},
}));
}
/**
* withFixtures config for Perps E2E tests with an eligible (non-geo-blocked) user.
* Use this for tests that exercise trading actions (Long/Short, Add Funds, Close All).
*
* The geolocation mock returns 'US-TX'. The production default for
* `perpsPerpTradingGeoBlockedCountriesV2` blocks US, so this config overrides it
* to `blockedRegions: []` both in `manifestFlags` (UI) and via `testSpecificMock`
* (background RemoteFeatureFlagController).
*
* @param title - The test title for debugging.
* @returns Partial withFixtures config to spread into withFixtures().
*/
export function getPerpsConfigEligible(title?: string) {
return {
fixtures: new FixtureBuilderV2()
.withPerpsController({
isEligible: true,
isFirstTimeUser: { mainnet: false, testnet: false },
})
.withRemoteFeatureFlagController({
remoteFeatureFlags: PERPS_ELIGIBLE_REMOTE_FEATURE_FLAGS,
})
.build(),
title,
manifestFlags: PERPS_ELIGIBLE_FLAG,
testSpecificMock: (server: Mockttp) => mockEligibleFeatureFlags(server),
};
}
/**
* Eligible Perps fixture for the Withdraw confirmation flow.
*
* The confirmation selects Arbitrum USDC as its destination token immediately
* on load. Pre-seeding token metadata and rates avoids depending on async token
* discovery before `TransactionPayController` resolves that token.
*
* @param title - The test title for debugging.
* @returns Partial withFixtures config to spread into withFixtures().
*/
export function getPerpsConfigEligibleWithArbitrumUsdc(title?: string) {
return {
fixtures: new FixtureBuilderV2()
.withPerpsController({
isEligible: true,
isFirstTimeUser: { mainnet: false, testnet: false },
})
.withRemoteFeatureFlagController({
remoteFeatureFlags: PERPS_WITHDRAW_CONFIRMATION_FLAG.remoteFeatureFlags,
})
.withTokensController({
allTokens: {
[ARBITRUM_CHAIN_ID]: {
[DEFAULT_FIXTURE_ACCOUNT_LOWERCASE]: [
{
address: ARBITRUM_USDC_ADDRESS,
symbol: 'USDC',
image: `https://static.cx.metamask.io/api/v1/tokenIcons/42161/${ARBITRUM_USDC_ADDRESS.toLowerCase()}.png`,
isERC721: false,
decimals: 6,
aggregators: ['metamask'],
name: 'USD Coin',
},
],
},
},
})
.withTokenRatesController({
marketData: {
[ARBITRUM_CHAIN_ID]: {
[ARBITRUM_USDC_ADDRESS]: ARBITRUM_USDC_MARKET_DATA,
},
},
})
.withCurrencyController({
currencyRates: {
ETH: {
conversionDate: 0,
conversionRate: 1700,
usdConversionRate: 1700,
},
},
})
.build(),
title,
manifestFlags: PERPS_WITHDRAW_CONFIRMATION_MANIFEST_FLAG,
testSpecificMock: async (server: Mockttp) => {
await mockEligibleFeatureFlags(server);
await mockArbitrumUsdcPriceData(server);
await mockRelayWithdrawData(server);
},
};
}
/**
* withFixtures config for Perps Activity E2E tests.
*
* Extends the eligible config by adding HTTP mock overrides for all four
* activity transaction types. Uses `withJsonBodyIncluding` so only the
* specific request types are intercepted; everything else (clearinghouseState,
* meta, allMids, etc.) falls through to the global mock-e2e.js handlers.
*
* Activity data injected:
* - Trades: one ETH "Open Long" fill (`userFills`)
* - Orders: one ETH Limit buy order (`openOrders`)
* - Funding: one ETH funding payment (`userFunding`)
* - Deposits: one USDC deposit entry (`userNonFundingLedgerUpdates`)
*
* @param title - The test title for debugging.
* @returns Partial withFixtures config to spread into withFixtures().
*/
export function getPerpsConfigEligibleWithActivity(title?: string) {
return {
fixtures: new FixtureBuilderV2()
.withPerpsController({
isEligible: true,
isFirstTimeUser: { mainnet: false, testnet: false },
})
.withRemoteFeatureFlagController({
remoteFeatureFlags: PERPS_ELIGIBLE_REMOTE_FEATURE_FLAGS,
})
.build(),
title,
manifestFlags: PERPS_ELIGIBLE_FLAG,
testSpecificMock: async (server: Mockttp) => {
await mockEligibleFeatureFlags(server);
// Override userFills — returns an ETH open-long fill for the Trades filter
await server
.forPost('https://api.hyperliquid.xyz/info')
.withJsonBodyIncluding({ type: 'userFills' })
.thenCallback(() => ({
statusCode: 200,
json: [MOCK_ETH_OPEN_LONG_FILL],
}));
// Override openOrders — returns an ETH limit buy for the Orders filter
await server
.forPost('https://api.hyperliquid.xyz/info')
.withJsonBodyIncluding({ type: 'openOrders' })
.thenCallback(() => ({
statusCode: 200,
json: [MOCK_ETH_LIMIT_ORDER],
}));
// Override userFunding — returns an ETH funding payment for the Funding filter
await server
.forPost('https://api.hyperliquid.xyz/info')
.withJsonBodyIncluding({ type: 'userFunding' })
.thenCallback(() => ({ statusCode: 200, json: [MOCK_ETH_FUNDING] }));
// Override userNonFundingLedgerUpdates — returns a USDC deposit for the Deposits filter
await server
.forPost('https://api.hyperliquid.xyz/info')
.withJsonBodyIncluding({ type: 'userNonFundingLedgerUpdates' })
.thenCallback(() => ({ statusCode: 200, json: [MOCK_USDC_DEPOSIT] }));
},
};
}