From 02a43285e466aa8a2ff9d2a397cd5ed00434ea56 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Tue, 26 Nov 2024 18:07:47 +0300 Subject: [PATCH] fix: remove chainId from ws api params (#49) --- package.json | 13 +++++--- pnpm-lock.yaml | 29 ++++++++++-------- src/ws-api/README.md | 29 ++---------------- src/ws-api/ws-api.ts | 23 +++++++------- src/ws-api/ws.spec.ts | 71 ++++++++++++++----------------------------- 5 files changed, 61 insertions(+), 104 deletions(-) diff --git a/package.json b/package.json index 8081b75..115dda3 100644 --- a/package.json +++ b/package.json @@ -51,15 +51,16 @@ }, "devDependencies": { "@1inch/eslint-config": "3.0.6", + "@1inch/tsconfig": "1.0.7", "@eslint/compat": "1.1.0", "@eslint/eslintrc": "^3.1.0", "@eslint/js": "^9.5.0", "@jest/types": "29.6.3", - "@1inch/tsconfig": "1.0.7", "@swc/core": "1.5.25", "@swc/jest": "0.2.36", "@types/jest": "29.5.12", "@types/node": "^18.16.0", + "@types/ws": "^8.5.12", "@typescript-eslint/eslint-plugin": "^7.14.1", "@typescript-eslint/parser": "^7.14.1", "eslint": "9.6", @@ -75,9 +76,8 @@ "jest": "29.7.0", "prettier": "^3.3.2", "ts-mockito": "2.6.1", - "typescript": "5.5.2", - "@types/ws": "^8.5.12", - "type-fest": "4.23.0" + "type-fest": "4.23.0", + "typescript": "5.5.2" }, "peerDependencies": { "assert": "^2.0.0" @@ -92,5 +92,10 @@ }, "volta": { "node": "18.16.0" + }, + "pnpm": { + "overrides": { + "cross-spawn@>=7.0.0 <7.0.5": ">=7.0.5" + } } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 95dfe18..abcb7b6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4,6 +4,9 @@ settings: autoInstallPeers: true excludeLinksFromLockfile: false +overrides: + cross-spawn@>=7.0.0 <7.0.5: '>=7.0.5' + importers: .: @@ -38,7 +41,7 @@ importers: devDependencies: '@1inch/eslint-config': specifier: 3.0.6 - version: 3.0.6(fdu2mpimk256a4uot5gtfjjqlq) + version: 3.0.6(oqdtfnpns64yv6s4qaao4plb6e) '@1inch/tsconfig': specifier: 1.0.7 version: 1.0.7 @@ -83,7 +86,7 @@ importers: version: 9.1.0(eslint@9.6.0) eslint-config-standard: specifier: ^17.1.0 - version: 17.1.0(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.18.0(eslint@9.6.0)(typescript@5.5.2))(eslint-import-resolver-typescript@3.6.1)(eslint@9.6.0))(eslint-plugin-n@17.10.2(eslint@9.6.0))(eslint-plugin-promise@6.6.0(eslint@9.6.0))(eslint@9.6.0) + version: 17.1.0(eslint-plugin-import@2.29.1)(eslint-plugin-n@17.10.2(eslint@9.6.0))(eslint-plugin-promise@6.6.0(eslint@9.6.0))(eslint@9.6.0) eslint-import-resolver-typescript: specifier: ^3.6.1 version: 3.6.1(@typescript-eslint/parser@7.18.0(eslint@9.6.0)(typescript@5.5.2))(eslint-plugin-import@2.29.1)(eslint@9.6.0) @@ -1104,8 +1107,8 @@ packages: engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} hasBin: true - cross-spawn@7.0.3: - resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==} + cross-spawn@7.0.6: + resolution: {integrity: sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==} engines: {node: '>= 8'} data-view-buffer@1.0.1: @@ -2540,7 +2543,7 @@ snapshots: optionalDependencies: assert: 2.1.0 - '@1inch/eslint-config@3.0.6(fdu2mpimk256a4uot5gtfjjqlq)': + '@1inch/eslint-config@3.0.6(oqdtfnpns64yv6s4qaao4plb6e)': dependencies: '@eslint/compat': 1.1.0 '@eslint/eslintrc': 3.1.0 @@ -2550,7 +2553,7 @@ snapshots: '@typescript-eslint/parser': 7.18.0(eslint@9.6.0)(typescript@5.5.2) eslint: 9.6.0 eslint-config-prettier: 9.1.0(eslint@9.6.0) - eslint-config-standard: 17.1.0(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.18.0(eslint@9.6.0)(typescript@5.5.2))(eslint-import-resolver-typescript@3.6.1)(eslint@9.6.0))(eslint-plugin-n@17.10.2(eslint@9.6.0))(eslint-plugin-promise@6.6.0(eslint@9.6.0))(eslint@9.6.0) + eslint-config-standard: 17.1.0(eslint-plugin-import@2.29.1)(eslint-plugin-n@17.10.2(eslint@9.6.0))(eslint-plugin-promise@6.6.0(eslint@9.6.0))(eslint@9.6.0) eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@7.18.0(eslint@9.6.0)(typescript@5.5.2))(eslint-plugin-import@2.29.1)(eslint@9.6.0) eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.18.0(eslint@9.6.0)(typescript@5.5.2))(eslint-import-resolver-typescript@3.6.1)(eslint@9.6.0) eslint-plugin-n: 17.10.2(eslint@9.6.0) @@ -3812,7 +3815,7 @@ snapshots: - supports-color - ts-node - cross-spawn@7.0.3: + cross-spawn@7.0.6: dependencies: path-key: 3.1.1 shebang-command: 2.0.0 @@ -4004,7 +4007,7 @@ snapshots: dependencies: eslint: 9.6.0 - eslint-config-standard@17.1.0(eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.18.0(eslint@9.6.0)(typescript@5.5.2))(eslint-import-resolver-typescript@3.6.1)(eslint@9.6.0))(eslint-plugin-n@17.10.2(eslint@9.6.0))(eslint-plugin-promise@6.6.0(eslint@9.6.0))(eslint@9.6.0): + eslint-config-standard@17.1.0(eslint-plugin-import@2.29.1)(eslint-plugin-n@17.10.2(eslint@9.6.0))(eslint-plugin-promise@6.6.0(eslint@9.6.0))(eslint@9.6.0): dependencies: eslint: 9.6.0 eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.18.0(eslint@9.6.0)(typescript@5.5.2))(eslint-import-resolver-typescript@3.6.1)(eslint@9.6.0) @@ -4024,7 +4027,7 @@ snapshots: debug: 4.3.6 enhanced-resolve: 5.17.1 eslint: 9.6.0 - eslint-module-utils: 2.8.1(@typescript-eslint/parser@7.18.0(eslint@9.6.0)(typescript@5.5.2))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.18.0(eslint@9.6.0)(typescript@5.5.2))(eslint-plugin-import@2.29.1)(eslint@9.6.0))(eslint@9.6.0) + eslint-module-utils: 2.8.1(@typescript-eslint/parser@7.18.0(eslint@9.6.0)(typescript@5.5.2))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1)(eslint@9.6.0) eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.18.0(eslint@9.6.0)(typescript@5.5.2))(eslint-import-resolver-typescript@3.6.1)(eslint@9.6.0) fast-glob: 3.3.2 get-tsconfig: 4.7.6 @@ -4036,7 +4039,7 @@ snapshots: - eslint-import-resolver-webpack - supports-color - eslint-module-utils@2.8.1(@typescript-eslint/parser@7.18.0(eslint@9.6.0)(typescript@5.5.2))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.18.0(eslint@9.6.0)(typescript@5.5.2))(eslint-plugin-import@2.29.1)(eslint@9.6.0))(eslint@9.6.0): + eslint-module-utils@2.8.1(@typescript-eslint/parser@7.18.0(eslint@9.6.0)(typescript@5.5.2))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1)(eslint@9.6.0): dependencies: debug: 3.2.7 optionalDependencies: @@ -4064,7 +4067,7 @@ snapshots: doctrine: 2.1.0 eslint: 9.6.0 eslint-import-resolver-node: 0.3.9 - eslint-module-utils: 2.8.1(@typescript-eslint/parser@7.18.0(eslint@9.6.0)(typescript@5.5.2))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.18.0(eslint@9.6.0)(typescript@5.5.2))(eslint-plugin-import@2.29.1)(eslint@9.6.0))(eslint@9.6.0) + eslint-module-utils: 2.8.1(@typescript-eslint/parser@7.18.0(eslint@9.6.0)(typescript@5.5.2))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1)(eslint@9.6.0) hasown: 2.0.2 is-core-module: 2.15.1 is-glob: 4.0.3 @@ -4134,7 +4137,7 @@ snapshots: '@nodelib/fs.walk': 1.2.8 ajv: 6.12.6 chalk: 4.1.2 - cross-spawn: 7.0.3 + cross-spawn: 7.0.6 debug: 4.3.6 escape-string-regexp: 4.0.0 eslint-scope: 8.0.2 @@ -4196,7 +4199,7 @@ snapshots: execa@5.1.1: dependencies: - cross-spawn: 7.0.3 + cross-spawn: 7.0.6 get-stream: 6.0.1 human-signals: 2.1.0 is-stream: 2.0.1 diff --git a/src/ws-api/README.md b/src/ws-api/README.md index ee5953a..6658e6c 100644 --- a/src/ws-api/README.md +++ b/src/ws-api/README.md @@ -9,7 +9,6 @@ import {WebSocketApi, NetworkEnum} from '@1inch/cross-chain-sdk' const wsSdk = new WebSocketApi({ url: 'wss://api.1inch.dev/fusion-plus/ws', - network: NetworkEnum.ETHEREUM, authKey: 'your-auth-key' }) @@ -27,7 +26,6 @@ import {WebSocketApi, NetworkEnum} from '@1inch/cross-chain-sdk' const ws = new WebSocketApi({ url: 'wss://api.1inch.dev/fusion/ws', - network: NetworkEnum.ETHEREUM, authKey: 'your-auth-key' }) ``` @@ -56,7 +54,6 @@ import {WebSocketApi, NetworkEnum} from '@1inch/cross-chain-sdk' const ws = WebSocketApi.new({ url: 'wss://api.1inch.dev/fusion-plus/ws', - network: NetworkEnum.ETHEREUM }) ``` @@ -96,7 +93,6 @@ import {WebSocketApi, NetworkEnum} from '@1inch/cross-chain-sdk' const ws = new WebSocketApi({ url: 'wss://api.1inch.dev/fusion-plus/ws', - network: NetworkEnum.ETHEREUM }) ws.on(WebSocketEvent.Error, console.error) @@ -126,7 +122,6 @@ import {WebSocketApi, NetworkEnum} from '@1inch/cross-chain-sdk' const ws = new WebSocketApi({ url: 'wss://api.1inch.dev/fusion-plus/ws', - network: NetworkEnum.ETHEREUM }) ws.on(WebSocketEvent.Error, console.error) @@ -159,7 +154,6 @@ import {WebSocketApi, NetworkEnum} from '@1inch/cross-chain-sdk' const ws = new WebSocketApi({ url: 'wss://api.1inch.dev/fusion-plus/ws', - network: NetworkEnum.ETHEREUM }) ws.onOpen(() => { @@ -182,7 +176,6 @@ import {WebSocketApi, NetworkEnum} from '@1inch/cross-chain-sdk' const ws = new WebSocketApi({ url: 'wss://api.1inch.dev/fusion-plus/ws', - network: NetworkEnum.ETHEREUM }) ws.send('my message') @@ -199,7 +192,6 @@ import {WebSocketApi, NetworkEnum} from '@1inch/cross-chain-sdk' const ws = new WebSocketApi({ url: 'wss://api.1inch.dev/fusion-plus/ws', - network: NetworkEnum.ETHEREUM }) ws.close() @@ -220,7 +212,6 @@ import {WebSocketApi, NetworkEnum} from '@1inch/cross-chain-sdk' const ws = new WebSocketApi({ url: 'wss://api.1inch.dev/fusion-plus/ws', - network: NetworkEnum.ETHEREUM }) ws.onMessage((data) => { @@ -239,7 +230,6 @@ import {WebSocketApi, NetworkEnum} from '@1inch/cross-chain-sdk' const ws = new WebSocketApi({ url: 'wss://api.1inch.dev/fusion-plus/ws', - network: NetworkEnum.ETHEREUM }) ws.onClose(() => { @@ -262,7 +252,6 @@ import {WebSocketApi, NetworkEnum} from '@1inch/cross-chain-sdk' const ws = new WebSocketApi({ url: 'wss://api.1inch.dev/fusion-plus/ws', - network: NetworkEnum.ETHEREUM }) ws.onError((error) => { @@ -287,7 +276,6 @@ import {WebSocketApi, NetworkEnum} from '@1inch/cross-chain-sdk' const ws = new WebSocketApi({ url: 'wss://api.1inch.dev/fusion-plus/ws', - network: NetworkEnum.ETHEREUM }) ws.order.onOrder((data) => { @@ -315,7 +303,6 @@ import {WebSocketApi, NetworkEnum} from '@1inch/cross-chain-sdk' const ws = new WebSocketApi({ url: 'wss://api.1inch.dev/fusion-plus/ws', - network: NetworkEnum.ETHEREUM }) ws.order.onOrderCreated((data) => { @@ -338,7 +325,6 @@ import {WebSocketApi, NetworkEnum} from '@1inch/cross-chain-sdk' const ws = new WebSocketApi({ url: 'wss://api.1inch.dev/fusion-plus/ws', - network: NetworkEnum.ETHEREUM }) ws.order.onOrderInvalid((data) => { @@ -361,7 +347,6 @@ import {WebSocketApi, NetworkEnum} from '@1inch/cross-chain-sdk' const ws = new WebSocketApi({ url: 'wss://api.1inch.dev/fusion-plus/ws', - network: NetworkEnum.ETHEREUM }) ws.order.onOrderBalanceChange((data) => { @@ -384,7 +369,6 @@ import {WebSocketApi, NetworkEnum} from '@1inch/cross-chain-sdk' const ws = new WebSocketApi({ url: 'wss://api.1inch.dev/fusion-plus/ws', - network: NetworkEnum.ETHEREUM }) ws.order.onOrderAllowanceChange((data) => { @@ -407,7 +391,6 @@ import {WebSocketApi, NetworkEnum} from '@1inch/cross-chain-sdk' const ws = new WebSocketApi({ url: 'wss://api.1inch.dev/fusion-plus/ws', - network: NetworkEnum.ETHEREUM }) ws.order.onOrderFilled((data) => { @@ -430,7 +413,6 @@ import {WebSocketApi, NetworkEnum} from '@1inch/cross-chain-sdk' const ws = new WebSocketApi({ url: 'wss://api.1inch.dev/fusion-plus/ws', - network: NetworkEnum.ETHEREUM }) ws.order.onOrderFilledPartially((data) => { @@ -453,7 +435,6 @@ import {WebSocketApi, NetworkEnum} from '@1inch/cross-chain-sdk' const ws = new WebSocketApi({ url: 'wss://api.1inch.dev/fusion-plus/ws', - network: NetworkEnum.ETHEREUM }) ws.order.onOrderCancelled((data) => { @@ -478,7 +459,6 @@ import {WebSocketApi, NetworkEnum} from '@1inch/cross-chain-sdk' const ws = new WebSocketApi({ url: 'wss://api.1inch.dev/fusion-plus/ws', - network: NetworkEnum.ETHEREUM }) ws.rpc.onPong((data) => { @@ -497,7 +477,6 @@ import {WebSocketApi, NetworkEnum} from '@1inch/cross-chain-sdk' const ws = new WebSocketApi({ url: 'wss://api.1inch.dev/fusion-plus/ws', - network: NetworkEnum.ETHEREUM }) ws.rpc.ping() @@ -514,7 +493,6 @@ import {WebSocketApi, NetworkEnum} from '@1inch/cross-chain-sdk' const ws = new WebSocketApi({ url: 'wss://api.1inch.dev/fusion-plus/ws', - network: NetworkEnum.ETHEREUM }) ws.rpc.getAllowedMethods() @@ -535,7 +513,6 @@ import {WebSocketApi, NetworkEnum} from '@1inch/cross-chain-sdk' const ws = new WebSocketApi({ url: 'wss://api.1inch.dev/fusion-plus/ws', - network: NetworkEnum.ETHEREUM }) ws.rpc.onGetAllowedMethods((data) => { @@ -553,8 +530,7 @@ ws.rpc.onGetAllowedMethods((data) => { import {WebSocketApi, NetworkEnum} from '@1inch/cross-chain-sdk' const ws = new WebSocketApi({ - url: 'wss://api.1inch.dev/fusion-plus/ws', - network: NetworkEnum.ETHEREUM + url: 'wss://api.1inch.dev/fusion-plus/ws' }) ws.rpc.getActiveOrders() @@ -574,8 +550,7 @@ ws.rpc.getActiveOrders() import {WebSocketApi, NetworkEnum} from '@1inch/cross-chain-sdk' const ws = new WebSocketApi({ - url: 'wss://api.1inch.dev/fusion-plus/ws', - network: NetworkEnum.ETHEREUM + url: 'wss://api.1inch.dev/fusion-plus/ws' }) ws.rpc.onGetActiveOrders((data) => { diff --git a/src/ws-api/ws-api.ts b/src/ws-api/ws-api.ts index 5b83afc..8154776 100644 --- a/src/ws-api/ws-api.ts +++ b/src/ws-api/ws-api.ts @@ -4,7 +4,8 @@ import { OnMessageCb, WebsocketClient, WsApiConfigWithNetwork, - WsProviderConnector + WsProviderConnector, + WsApiConfig } from '@1inch/fusion-sdk' import {ActiveOrdersWebSocketApi} from './active-websocket-orders-api' import {RpcWebsocketApi} from './rpc-websocket-api' @@ -20,13 +21,13 @@ export class WebSocketApi { public readonly provider: WsProviderConnector - constructor( - configOrProvider: WsApiConfigWithNetwork | WsProviderConnector - ) { - if (instanceOfWsApiConfigWithNetwork(configOrProvider)) { + constructor(configOrProvider: WsApiConfig | WsProviderConnector) { + if (instanceOfWsApiConfig(configOrProvider)) { const url = castUrl(configOrProvider.url) - const urlWithNetwork = `${url}/${WebSocketApi.Version}/${configOrProvider.network}` - const configWithUrl = {...configOrProvider, url: urlWithNetwork} + const configWithUrl = { + ...configOrProvider, + url: `${url}/${WebSocketApi.Version}` + } const provider = new WebsocketClient(configWithUrl) this.provider = provider @@ -84,8 +85,8 @@ export class WebSocketApi { } } -function instanceOfWsApiConfigWithNetwork( - val: WsApiConfigWithNetwork | WsProviderConnector -): val is WsApiConfigWithNetwork { - return 'url' in val && 'network' in val +function instanceOfWsApiConfig( + val: WsApiConfig | WsProviderConnector +): val is WsApiConfig { + return !('send' in val) } diff --git a/src/ws-api/ws.spec.ts b/src/ws-api/ws.spec.ts index 05bf1a7..e353dbe 100644 --- a/src/ws-api/ws.spec.ts +++ b/src/ws-api/ws.spec.ts @@ -36,7 +36,6 @@ describe(__filename, () => { const wsSdk = new WebSocketApi({ url, - network: NetworkEnum.ETHEREUM, authKey: '' }) @@ -54,7 +53,6 @@ describe(__filename, () => { const wsSdk = new WebSocketApi({ url, - network: NetworkEnum.ETHEREUM, authKey: '' }) @@ -71,7 +69,6 @@ describe(__filename, () => { const wsSdk = new WebSocketApi({ url, - network: NetworkEnum.ETHEREUM, authKey: '' }) @@ -86,8 +83,7 @@ describe(__filename, () => { // TODO repair waiting a lot of time .... xit('should be possible to subscribe to error', (done) => { const wsSdk = new WebSocketApi({ - url: 'ws://localhost:2345', - network: NetworkEnum.ETHEREUM + url: 'ws://localhost:2345' }) wsSdk.on(WebSocketEvent.Error, (error) => { @@ -99,10 +95,10 @@ describe(__filename, () => { it('should be possible to initialize in lazy mode', (done) => { const message = {id: 1} - const port = 8080 + const port = getPort() const url = `ws://localhost:${port}/ws` - const wss = new WebSocketServer({port, path: '/ws/v1.0/1'}) + const wss = new WebSocketServer({port, path: '/ws/v1.0'}) wss.on('connection', (ws: WebSocket) => { for (const m of [message]) { @@ -112,7 +108,6 @@ describe(__filename, () => { const wsSdk = new WebSocketApi({ url, - network: NetworkEnum.ETHEREUM, lazyInit: true, authKey: '' }) @@ -135,7 +130,6 @@ describe(__filename, () => { it('should be safe to call methods on uninitialized ws', () => { const wsSdk = new WebSocketApi({ url: 'random', - network: NetworkEnum.ETHEREUM, lazyInit: true }) @@ -144,10 +138,10 @@ describe(__filename, () => { it('should be possible to initialize not in lazy mode', (done) => { const message = {id: 1} - const port = 8080 + const port = getPort() const url = `ws://localhost:${port}/ws` - const wss = new WebSocketServer({port, path: '/ws/v1.0/1'}) + const wss = new WebSocketServer({port, path: '/ws/v1.0'}) wss.on('connection', (ws: WebSocket) => { for (const m of [message]) { @@ -157,7 +151,6 @@ describe(__filename, () => { const wsSdk = new WebSocketApi({ url, - network: NetworkEnum.ETHEREUM, lazyInit: false }) @@ -174,20 +167,11 @@ describe(__filename, () => { it('should be possible to pass provider instead of config', (done) => { const message = {id: 1} - const port = 8080 - const url = `ws://localhost:${port}/ws` - const wss = new WebSocketServer({port, path: '/ws/v1.0/1'}) - - wss.on('connection', (ws: WebSocket) => { - for (const m of [message]) { - ws.send(JSON.stringify(m)) - } - }) + const {wss, url} = createWebsocketServerMock([message]) const castedUrl = castUrl(url) - const urlWithNetwork = `${castedUrl}/v1.0/1` - const provider = new WebsocketClient({url: urlWithNetwork}) + const provider = new WebsocketClient({url: `${castedUrl}/v1.0`}) const wsSdk = new WebSocketApi(provider) @@ -207,10 +191,10 @@ describe(__filename, () => { it('should be possible to initialize with new method', (done) => { const message = {id: 1} - const port = 8080 + const port = getPort() const url = `ws://localhost:${port}/ws` - const wss = new WebSocketServer({port, path: '/ws/v1.0/1'}) + const wss = new WebSocketServer({port, path: '/ws/v1.0'}) wss.on('connection', (ws: WebSocket) => { for (const m of [message]) { @@ -219,7 +203,7 @@ describe(__filename, () => { }) const castedUrl = castUrl(url) - const urlWithNetwork = `${castedUrl}/v1.0/1` + const urlWithNetwork = `${castedUrl}/v1.0` const provider = new WebsocketClient({ url: urlWithNetwork, authKey: '' @@ -247,7 +231,6 @@ describe(__filename, () => { const wsSdk = new WebSocketApi({ url, - network: NetworkEnum.ETHEREUM, authKey: '' }) @@ -278,7 +261,6 @@ describe(__filename, () => { const wsSdk = new WebSocketApi({ url, - network: NetworkEnum.ETHEREUM, authKey: '' }) @@ -313,7 +295,6 @@ describe(__filename, () => { const wsSdk = new WebSocketApi({ url, - network: NetworkEnum.ETHEREUM, authKey: '' }) @@ -352,7 +333,6 @@ describe(__filename, () => { const wsSdk = new WebSocketApi({ url, - network: NetworkEnum.ETHEREUM, authKey: '' }) @@ -391,7 +371,6 @@ describe(__filename, () => { const wsSdk = new WebSocketApi({ url, - network: NetworkEnum.ETHEREUM, authKey: '' }) @@ -465,7 +444,6 @@ describe(__filename, () => { const wsSdk = new WebSocketApi({ url, - network: NetworkEnum.ETHEREUM, authKey: '' }) @@ -498,7 +476,6 @@ describe(__filename, () => { const wsSdk = new WebSocketApi({ url, - network: NetworkEnum.ETHEREUM, authKey: '' }) @@ -568,7 +545,6 @@ describe(__filename, () => { const wsSdk = new WebSocketApi({ url, - network: NetworkEnum.ETHEREUM, authKey: '' }) @@ -641,7 +617,6 @@ describe(__filename, () => { const wsSdk = new WebSocketApi({ url, - network: NetworkEnum.ETHEREUM, authKey: '' }) @@ -714,7 +689,6 @@ describe(__filename, () => { const wsSdk = new WebSocketApi({ url, - network: NetworkEnum.ETHEREUM, authKey: '' }) @@ -781,7 +755,6 @@ describe(__filename, () => { const wsSdk = new WebSocketApi({ url, - network: NetworkEnum.ETHEREUM, authKey: '' }) @@ -848,7 +821,6 @@ describe(__filename, () => { const wsSdk = new WebSocketApi({ url, - network: NetworkEnum.ETHEREUM, authKey: '' }) @@ -921,7 +893,6 @@ describe(__filename, () => { const wsSdk = new WebSocketApi({ url, - network: NetworkEnum.ETHEREUM, authKey: '' }) @@ -995,7 +966,6 @@ describe(__filename, () => { const wsSdk = new WebSocketApi({ url, - network: NetworkEnum.ETHEREUM, authKey: '' }) @@ -1071,7 +1041,6 @@ describe(__filename, () => { const wsSdk = new WebSocketApi({ url, - network: NetworkEnum.ETHEREUM, authKey: '' }) @@ -1170,7 +1139,6 @@ describe(__filename, () => { const wsSdk = new WebSocketApi({ url, - network: NetworkEnum.ETHEREUM, authKey: '' }) @@ -1192,30 +1160,30 @@ describe(__filename, () => { }) function createWebsocketRpcServerMock( - cb: (ws: WebSocket, result: any) => void + cb: (ws: WebSocket, result: string) => void ): { url: string wss: WebSocketServer } { - const port = 8080 + const port = getPort() const returnUrl = `ws://localhost:${port}/ws` - const wss = new WebSocketServer({port, path: '/ws/v1.0/1'}) + const wss = new WebSocketServer({port, path: '/ws/v1.0'}) wss.on('connection', (ws: WebSocket) => { - ws.on('message', (data) => cb(ws, data)) + ws.on('message', (data) => cb(ws, data.toString())) }) return {url: returnUrl, wss} } -function createWebsocketServerMock(messages: any[]): { +function createWebsocketServerMock(messages: unknown[]): { url: string wss: WebSocketServer } { - const port = 8080 + const port = getPort() const returnUrl = `ws://localhost:${port}/ws` - const wss = new WebSocketServer({port, path: '/ws/v1.0/1'}) + const wss = new WebSocketServer({port, path: '/ws/v1.0'}) wss.on('connection', (ws: WebSocket) => { for (const message of messages) { @@ -1225,3 +1193,8 @@ function createWebsocketServerMock(messages: any[]): { return {url: returnUrl, wss} } + +let nextPort = 8090 +function getPort(): number { + return nextPort++ +}