Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/src/server/ws-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ const WATCH_METHODS = new Set([
"watchOrderBook",
"watchOrderBooks",
"watchTrades",
"watchAddress",
]);

/** Data-feed methods that produce streaming data. */
Expand All @@ -113,6 +114,7 @@ const FEED_WATCH_METHODS = new Set([
/** Methods for unsubscribing. */
const UNWATCH_METHODS: Record<string, string> = {
unwatchOrderBook: "watchOrderBook",
unwatchAddress: "watchAddress",
};

function send(ws: WebSocket, msg: ServerEvent): void {
Expand Down
26 changes: 26 additions & 0 deletions core/test/pipeline/ws-handler-streaming-methods.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import fs from 'fs';
import path from 'path';

const repoRoot = path.resolve(__dirname, '../../..');

function read(relativePath: string): string {
return fs.readFileSync(path.join(repoRoot, relativePath), 'utf8');
}

describe('WebSocket streaming method registry', () => {
it('accepts every exchange method declared with the ws verb', () => {
const methodVerbConfig = JSON.parse(read('core/src/server/method-verbs.json')) as Record<string, { verb?: string }>;
const wsHandler = read('core/src/server/ws-handler.ts');

const registeredMethodNames = new Set(
Array.from(wsHandler.matchAll(/(?:["'])(watch[A-Za-z]+|unwatch[A-Za-z]+)(?:["'])|\b(unwatch[A-Za-z]+)\s*:/g))
.map((match) => match[1] || match[2])
.filter(Boolean),
);
const wsMethods = Object.entries(methodVerbConfig)
.filter(([, config]) => config.verb === 'ws')
.map(([method]) => method);

expect(wsMethods.filter((method) => !registeredMethodNames.has(method))).toEqual([]);
});
});
Loading