Skip to content

Commit 85b3488

Browse files
test: adds hyperliquid specifc endpoint mock (#24567)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** Adds a mock for `https://api.hyperliquid.xyz/info` made by the Hyperliquid SDK. <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: ## **Related issues** Fixes: ## **Manual testing steps** ```gherkin Feature: my feature name Scenario: user [verb for user action] Given [describe expected initial app state] When user [verb for user action] Then [describe expected outcome] ``` ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Introduces a mock for Hyperliquid SDK requests and improves visibility into POST traffic during E2E tests. > > - Adds `PERPS_HYPERLIQUID_MOCKS` with a POST mock for `https://api.hyperliquid.xyz/info` when `requestBody` is `{ type: 'meta' }`, returning `{}` with 200; included in `DEFAULT_MOCKS.POST` > - Removes `https://api.hyperliquid.xyz/info` from `mock-e2e-allowlist.ts` to ensure tests use mocks instead of live calls > - Enhances `MockServerE2E` to log POST request bodies when requests go to non-mocked live URLs or allowed URLs (both `/proxy` and unmatched requests) > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 42cb85f. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 9ccaa0d commit 85b3488

4 files changed

Lines changed: 20 additions & 1 deletion

File tree

e2e/api-mocking/MockServerE2E.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,9 @@ export default class MockServerE2E implements Resource {
322322
if (!isUrlAllowed(updatedUrl)) {
323323
const errorMessage = `Request going to live server: ${updatedUrl}`;
324324
logger.warn(errorMessage);
325+
if (method === 'POST') {
326+
logger.warn(`Request Body: ${requestBodyText}`);
327+
}
325328
this._server?._liveRequests?.push({
326329
url: updatedUrl,
327330
method,
@@ -367,6 +370,9 @@ export default class MockServerE2E implements Resource {
367370
if (!isUrlAllowed(translatedUrl)) {
368371
const errorMessage = `Request going to live server: ${translatedUrl}`;
369372
logger.warn(errorMessage);
373+
if (request.method === 'POST') {
374+
logger.warn(`Request Body: ${await request.body.getText()}`);
375+
}
370376
this._server?._liveRequests?.push({
371377
url: translatedUrl,
372378
method: request.method,

e2e/api-mocking/mock-e2e-allowlist.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,4 @@ export const ALLOWLISTED_URLS = [
5252
'https://signature-insights.api.cx.metamask.io/v1/signature?chainId=0x1',
5353
'https://price.api.cx.metamask.io/v1/exchange-rates?baseCurrency=usd',
5454
'https://api.hyperliquid.xyz/exchange',
55-
'https://api.hyperliquid.xyz/info',
5655
];

e2e/api-mocking/mock-responses/defaults/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { CHAINS_NETWORK_MOCK_RESPONSE } from '../chains-network-mocks';
2626
import { DEFAULT_REWARDS_MOCKS } from './rewards';
2727
import { ACL_EXECUTION_MOCKS } from './acl-execution';
2828
import { CONTENTFUL_BANNERS_MOCKS } from './contentful-banners';
29+
import { PERPS_HYPERLIQUID_MOCKS } from './perps-hyperliquid';
2930

3031
// Get auth mocks
3132
const authMocks = getAuthMocks();
@@ -306,6 +307,7 @@ export const DEFAULT_MOCKS = {
306307
},
307308
},
308309
...(DEFAULT_REWARDS_MOCKS.POST || []),
310+
...(PERPS_HYPERLIQUID_MOCKS.POST || []),
309311
],
310312
PUT: [...(USER_STORAGE_MOCK.PUT || [])],
311313
DELETE: [],
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { MockEventsObject } from '../../../framework';
2+
3+
export const PERPS_HYPERLIQUID_MOCKS: MockEventsObject = {
4+
POST: [
5+
{
6+
urlEndpoint: 'https://api.hyperliquid.xyz/info',
7+
requestBody: { type: 'meta' },
8+
responseCode: 200,
9+
response: {},
10+
},
11+
],
12+
};

0 commit comments

Comments
 (0)