-
Notifications
You must be signed in to change notification settings - Fork 5.4k
test: split Solana WebSocket Mock setup logic from Websocket Mocks cp-13.3.1 #35552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,7 +26,7 @@ const { | |
| getServerMochaToBackground, | ||
| } = require('./background-socket/server-mocha-to-background'); | ||
| const LocalWebSocketServer = require('./websocket-server').default; | ||
| const { setSolanaWebsocketMocks } = require('./websocket-solana-mocks'); | ||
| const { setupSolanaWebsocketMocks } = require('./websocket-solana-mocks'); | ||
|
|
||
| const tinyDelayMs = 200; | ||
| const regularDelayMs = tinyDelayMs * 2; | ||
|
|
@@ -128,7 +128,10 @@ async function withFixtures(options, testSuite) { | |
| ethConversionInUsd, | ||
| monConversionInUsd, | ||
| manifestFlags, | ||
| withSolanaWebSocket = false, | ||
| withSolanaWebSocket = { | ||
| server: false, | ||
| mocks: [], | ||
| }, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: WebSocket Server Setup SkippedThe Additional Locations (2)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
ℹ️ there are no existing calls as I've updated all the old references |
||
| } = options; | ||
|
|
||
| // Normalize localNodeOptions | ||
|
|
@@ -261,12 +264,10 @@ async function withFixtures(options, testSuite) { | |
| } | ||
| } | ||
|
|
||
| if (withSolanaWebSocket) { | ||
| if (withSolanaWebSocket.server) { | ||
| localWebSocketServer = LocalWebSocketServer.getServerInstance(); | ||
| localWebSocketServer.start(); | ||
| // All specs use the same ws mocks. | ||
| // If we need custom ws mocks we can expand logic for supporting custom ws mocks like with http | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic has been updated, to be able to pass a mocks array with websocket mocks |
||
| await setSolanaWebsocketMocks(); | ||
| await setupSolanaWebsocketMocks(withSolanaWebSocket.mocks); | ||
| } | ||
|
|
||
| const { mockedEndpoint, getPrivacyReport } = await setupMocking( | ||
|
|
@@ -454,7 +455,7 @@ async function withFixtures(options, testSuite) { | |
| })(), | ||
| ); | ||
|
|
||
| if (withSolanaWebSocket) { | ||
| if (withSolanaWebSocket.server) { | ||
| shutdownTasks.push(localWebSocketServer.stopAndCleanup()); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| /** | ||
| * Configuration for a WebSocket message mock | ||
| */ | ||
| export type WebSocketMessageMock = { | ||
| /** String(s) that the message should include to trigger this mock */ | ||
| messageIncludes: string | string[]; | ||
| /** The JSON response to send back */ | ||
| response: object; | ||
| /** Delay before sending the response (in milliseconds) */ | ||
| delay?: number; | ||
| /** Custom log message for this mock */ | ||
| logMessage?: string; | ||
| }; | ||
|
|
||
| export const DEFAULT_SOLANA_WS_MOCKS: WebSocketMessageMock[] = [ | ||
| { | ||
| messageIncludes: 'signatureSubscribe', | ||
| response: { | ||
| jsonrpc: '2.0', | ||
| result: 8648699534240963, | ||
| id: '1', | ||
| }, | ||
| delay: 500, | ||
| logMessage: 'Signature subscribe message received from client', | ||
| }, | ||
| { | ||
| messageIncludes: 'accountSubscribe', | ||
| response: { | ||
| jsonrpc: '2.0', | ||
| result: | ||
| 'b07ebf7caf2238a9b604d4dfcaf1934280fcd347d6eded62bc0def6cbb767d11', | ||
| id: '1', | ||
| }, | ||
| delay: 500, | ||
| logMessage: 'Account subscribe message received from client', | ||
| }, | ||
| { | ||
| messageIncludes: [ | ||
| 'programSubscribe', | ||
| 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', | ||
| ], | ||
| response: { | ||
| jsonrpc: '2.0', | ||
| result: | ||
| '568eafd45635c108d0d426361143de125a841628a58679f5a024cbab9a20b41c', | ||
| id: '1', | ||
| }, | ||
| delay: 500, | ||
| logMessage: 'Program subscribe message received from client', | ||
| }, | ||
| { | ||
| messageIncludes: [ | ||
| 'programSubscribe', | ||
| 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb', | ||
| ], | ||
| response: { | ||
| jsonrpc: '2.0', | ||
| result: | ||
| 'f33dd9975158af47bf16c7f6062a73191d4595c59cfec605d5a51e25c65ffb51', | ||
| id: '1', | ||
| }, | ||
| delay: 500, | ||
| logMessage: 'Program subscribe message received from client', | ||
| }, | ||
| ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the first part of the refactor, the Websocket mock logic was joint with the Websocket setup.
As a second stage of this refactor, we now separate the 2, allowing flexibility