From 6b95286704433adc616b760ba983161b4ab85c99 Mon Sep 17 00:00:00 2001 From: Alex Luu Date: Tue, 20 Feb 2024 15:23:01 -0500 Subject: [PATCH 1/5] update utils --- packages/web3-utils/package.json | 1 + packages/web3-utils/src/event_emitter.ts | 94 +----------------------- 2 files changed, 4 insertions(+), 91 deletions(-) diff --git a/packages/web3-utils/package.json b/packages/web3-utils/package.json index 8d5a9296086..299fb8333c7 100644 --- a/packages/web3-utils/package.json +++ b/packages/web3-utils/package.json @@ -64,6 +64,7 @@ }, "dependencies": { "ethereum-cryptography": "^2.0.0", + "eventemitter3": "^5.0.1", "web3-errors": "^1.1.4", "web3-types": "^1.4.0", "web3-validator": "^2.0.4" diff --git a/packages/web3-utils/src/event_emitter.ts b/packages/web3-utils/src/event_emitter.ts index 7d9c3ccdb2e..e5994f7187c 100644 --- a/packages/web3-utils/src/event_emitter.ts +++ b/packages/web3-utils/src/event_emitter.ts @@ -16,75 +16,16 @@ along with web3.js. If not, see . */ /* eslint-disable max-classes-per-file */ -import { EventEmitter as EventEmitterAtNode } from 'events'; +import EventEmitter3 from 'eventemitter3'; -// eslint-disable-next-line @typescript-eslint/no-explicit-any -type Callback = (params: any) => void | Promise; - -type EventTargetCallback = (params: CustomEvent) => void; - -const wrapFunction = - (fn: Callback): EventTargetCallback => - (params: CustomEvent) => - fn(params.detail); /** * This class copy the behavior of Node.js EventEmitter class. * It is used to provide the same interface for the browser environment. */ -class EventEmitterAtBrowser extends EventTarget { - private _listeners: Record = {}; +export class EventEmitter extends EventEmitter3 { private maxListeners = Number.MAX_SAFE_INTEGER; - public on(eventName: string, fn: Callback) { - this.addEventListener(eventName, fn); - return this; - } - - public once(eventName: string, fn: Callback) { - const onceCallback = async (params: Callback) => { - this.off(eventName, onceCallback); - await fn(params); - }; - return this.on(eventName, onceCallback); - } - - public off(eventName: string, fn: Callback) { - this.removeEventListener(eventName, fn); - return this; - } - - public emit(eventName: string, params: unknown) { - const event = new CustomEvent(eventName, { detail: params }); - return super.dispatchEvent(event); - } - - public listenerCount(eventName: string): number { - const eventListeners = this._listeners[eventName]; - return eventListeners ? eventListeners.length : 0; - } - - public listeners(eventName: string): Callback[] { - return this._listeners[eventName].map(value => value[0]) || []; - } - - public eventNames(): string[] { - return Object.keys(this._listeners); - } - - public removeAllListeners() { - Object.keys(this._listeners).forEach(event => { - this._listeners[event].forEach( - (listener: [key: Callback, value: EventTargetCallback]) => { - super.removeEventListener(event, listener[1] as EventListener); - }, - ); - }); - - this._listeners = {}; - return this; - } - public setMaxListeners(maxListeners: number) { this.maxListeners = maxListeners; return this; @@ -94,35 +35,6 @@ class EventEmitterAtBrowser extends EventTarget { return this.maxListeners; } - public addEventListener(eventName: string, fn: Callback) { - const wrappedFn = wrapFunction(fn); - super.addEventListener(eventName, wrappedFn as EventListener); - if (!this._listeners[eventName]) { - this._listeners[eventName] = []; - } - this._listeners[eventName].push([fn, wrappedFn]); - } - - public removeEventListener(eventName: string, fn: Callback) { - const eventListeners = this._listeners[eventName]; - if (eventListeners) { - const index = eventListeners.findIndex(item => item[0] === fn); - if (index !== -1) { - super.removeEventListener(eventName, eventListeners[index][1] as EventListener); - eventListeners.splice(index, 1); - } - } - } } - // eslint-disable-next-line import/no-mutable-exports -let EventEmitterType: typeof EventEmitterAtNode; -// Check if the code is running in a Node.js environment -if (typeof window === 'undefined') { - EventEmitterType = EventEmitterAtNode; -} else { - // Fallback for the browser environment - EventEmitterType = EventEmitterAtBrowser as unknown as typeof EventEmitterAtNode; -} - -export class EventEmitter extends EventEmitterType {} \ No newline at end of file +// let EventEmitterType: typeof EventEmitter3; \ No newline at end of file From 97255b38e7ef9403319f83280d96d9c17b880d52 Mon Sep 17 00:00:00 2001 From: Alex Luu Date: Wed, 21 Feb 2024 16:01:39 -0500 Subject: [PATCH 2/5] replace web3 eventemitter for eventemitter3 --- packages/web3-eth-contract/package.json | 1 + packages/web3-eth-contract/test/unit/contract.test.ts | 5 +++-- packages/web3-utils/CHANGELOG.md | 6 +++++- packages/web3-utils/src/chunk_response_parser.ts | 2 +- packages/web3-utils/src/event_emitter.ts | 5 ++--- packages/web3-utils/src/web3_eip1193_provider.ts | 2 +- .../web3-utils/test/unit/chunk_response_parser.test.ts | 2 +- yarn.lock | 10 ++++++++++ 8 files changed, 24 insertions(+), 9 deletions(-) diff --git a/packages/web3-eth-contract/package.json b/packages/web3-eth-contract/package.json index a587cbd8679..1218671f498 100644 --- a/packages/web3-eth-contract/package.json +++ b/packages/web3-eth-contract/package.json @@ -62,6 +62,7 @@ "eslint-config-base-web3": "0.1.0", "eslint-config-prettier": "^8.5.0", "eslint-plugin-import": "^2.26.0", + "flatted": "^3.3.1", "jest": "^29.7.0", "jest-extended": "^3.0.1", "prettier": "^2.7.1", diff --git a/packages/web3-eth-contract/test/unit/contract.test.ts b/packages/web3-eth-contract/test/unit/contract.test.ts index b55a19c1457..c870f56e255 100644 --- a/packages/web3-eth-contract/test/unit/contract.test.ts +++ b/packages/web3-eth-contract/test/unit/contract.test.ts @@ -21,6 +21,7 @@ import { Web3ContractError } from 'web3-errors'; import { Web3Context , Web3ConfigEvent } from 'web3-core'; import { Web3ValidatorError } from 'web3-validator'; import { AbiItem } from 'web3-utils'; +import { stringify } from 'flatted'; import {Abi} from '../fixtures/AbiItem' import { Contract } from '../../src'; import { sampleStorageContractABI } from '../fixtures/storage'; @@ -755,7 +756,7 @@ describe('Contract', () => { const clonnedContract = contract.clone(); - expect(JSON.stringify(contract)).toStrictEqual(JSON.stringify(clonnedContract)); + expect(stringify(contract)).toStrictEqual(stringify(clonnedContract)); contract.options.jsonInterface = GreeterAbi; }); @@ -764,7 +765,7 @@ describe('Contract', () => { const contract = new Contract(sampleStorageContractABI); const clonnedContract = contract.clone(); - expect(JSON.stringify(contract)).toStrictEqual(JSON.stringify(clonnedContract)); + expect(stringify(contract)).toStrictEqual(stringify(clonnedContract)); }); it('should be able to update the jsonInterface', () => { diff --git a/packages/web3-utils/CHANGELOG.md b/packages/web3-utils/CHANGELOG.md index 477b9031953..3bb09ffe5e0 100644 --- a/packages/web3-utils/CHANGELOG.md +++ b/packages/web3-utils/CHANGELOG.md @@ -193,4 +193,8 @@ Documentation: - Adds missing exported type `AbiItem` from 1.x to v4 for compatabiltiy (#6678) -## [Unreleased] \ No newline at end of file +## [Unreleased] + +### Fixed + +- replaced our eventEmitter to EventEmitter3 to support react native builds (#6253) \ No newline at end of file diff --git a/packages/web3-utils/src/chunk_response_parser.ts b/packages/web3-utils/src/chunk_response_parser.ts index 629323415cb..68e708e58b5 100644 --- a/packages/web3-utils/src/chunk_response_parser.ts +++ b/packages/web3-utils/src/chunk_response_parser.ts @@ -16,7 +16,7 @@ along with web3.js. If not, see . */ import { JsonRpcResponse } from 'web3-types'; import { InvalidResponseError } from 'web3-errors'; -import { EventEmitter } from 'events'; +import { EventEmitter } from 'eventemitter3'; import { Timeout } from './promise_helpers.js'; export class ChunkResponseParser { diff --git a/packages/web3-utils/src/event_emitter.ts b/packages/web3-utils/src/event_emitter.ts index e5994f7187c..bc7fee36f04 100644 --- a/packages/web3-utils/src/event_emitter.ts +++ b/packages/web3-utils/src/event_emitter.ts @@ -24,6 +24,7 @@ import EventEmitter3 from 'eventemitter3'; * It is used to provide the same interface for the browser environment. */ export class EventEmitter extends EventEmitter3 { + // must be defined for backwards compatibility private maxListeners = Number.MAX_SAFE_INTEGER; public setMaxListeners(maxListeners: number) { @@ -35,6 +36,4 @@ export class EventEmitter extends EventEmitter3 { return this.maxListeners; } -} -// eslint-disable-next-line import/no-mutable-exports -// let EventEmitterType: typeof EventEmitter3; \ No newline at end of file +} \ No newline at end of file diff --git a/packages/web3-utils/src/web3_eip1193_provider.ts b/packages/web3-utils/src/web3_eip1193_provider.ts index 15f132f6215..f0e2d4d30bf 100644 --- a/packages/web3-utils/src/web3_eip1193_provider.ts +++ b/packages/web3-utils/src/web3_eip1193_provider.ts @@ -23,7 +23,7 @@ import { Web3APISpec, Web3BaseProvider, } from 'web3-types'; -import { EventEmitter } from 'events'; +import { EventEmitter } from 'eventemitter3'; import { EIP1193ProviderRpcError } from 'web3-errors'; import { toPayload } from './json_rpc.js'; diff --git a/packages/web3-utils/test/unit/chunk_response_parser.test.ts b/packages/web3-utils/test/unit/chunk_response_parser.test.ts index 1fc08c2fceb..27241b4243b 100644 --- a/packages/web3-utils/test/unit/chunk_response_parser.test.ts +++ b/packages/web3-utils/test/unit/chunk_response_parser.test.ts @@ -15,7 +15,7 @@ You should have received a copy of the GNU Lesser General Public License along with web3.js. If not, see . */ -import { EventEmitter } from 'events'; +import { EventEmitter } from 'eventemitter3'; import { InvalidResponseError } from 'web3-errors'; import { ChunkResponseParser } from '../../src/chunk_response_parser'; import { hugeData } from '../fixtures/hugeData'; diff --git a/yarn.lock b/yarn.lock index 98bbc72e352..bc653ed8db7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5676,6 +5676,11 @@ eventemitter3@^4.0.0, eventemitter3@^4.0.4: resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-4.0.7.tgz#2de9b68f6528d5644ef5c59526a1b4a07306169f" integrity sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw== +eventemitter3@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-5.0.1.tgz#53f5ffd0a492ac800721bb42c66b841de96423c4" + integrity sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA== + events@^3.0.0, events@^3.2.0, events@^3.3.0: version "3.3.0" resolved "https://registry.yarnpkg.com/events/-/events-3.3.0.tgz#31a95ad0a924e2d2c419a813aeb2c4e878ea7400" @@ -6052,6 +6057,11 @@ flatted@^3.1.0: resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.6.tgz#022e9218c637f9f3fc9c35ab9c9193f05add60b2" integrity sha512-0sQoMh9s0BYsm+12Huy/rkKxVu4R1+r96YX5cG44rHV0pQ6iC3Q+mkoMFaGWObMFYQxCVT+ssG1ksneA2MI9KQ== +flatted@^3.3.1: + version "3.3.1" + resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.3.1.tgz#21db470729a6734d4997002f439cb308987f567a" + integrity sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw== + follow-redirects@^1.0.0, follow-redirects@^1.12.1: version "1.15.1" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.1.tgz#0ca6a452306c9b276e4d3127483e29575e207ad5" From 79a25f2aeff62b9c7b17cf587d6af524af0b6f02 Mon Sep 17 00:00:00 2001 From: Alex Luu Date: Sat, 24 Feb 2024 14:42:29 -0500 Subject: [PATCH 3/5] update tests --- .../__snapshots__/web3_context.test.ts.snap | 83 ------------------- .../web_socket_provider_integration.test.ts | 15 ++++ .../test/unit/__mocks__/isomorphic-ws.ts | 16 ++-- .../test/unit/check_implementation.test.ts | 20 +---- packages/web3-utils/src/socket_provider.ts | 2 - 5 files changed, 25 insertions(+), 111 deletions(-) delete mode 100644 packages/web3-core/test/unit/__snapshots__/web3_context.test.ts.snap diff --git a/packages/web3-core/test/unit/__snapshots__/web3_context.test.ts.snap b/packages/web3-core/test/unit/__snapshots__/web3_context.test.ts.snap deleted file mode 100644 index b832a1f8200..00000000000 --- a/packages/web3-core/test/unit/__snapshots__/web3_context.test.ts.snap +++ /dev/null @@ -1,83 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Web3Context getContextObject should return correct context object 1`] = ` -{ - "accountProvider": undefined, - "config": { - "blockHeaderTimeout": 10, - "contractDataInputFill": "data", - "defaultAccount": undefined, - "defaultBlock": "latest", - "defaultChain": "mainnet", - "defaultCommon": undefined, - "defaultHardfork": "london", - "defaultMaxPriorityFeePerGas": "0x9502f900", - "defaultNetworkId": undefined, - "defaultTransactionType": "0x2", - "enableExperimentalFeatures": { - "useRpcCallSpecification": false, - "useSubscriptionWhenCheckingBlockTimeout": false, - }, - "handleRevert": false, - "maxListenersWarningThreshold": 100, - "transactionBlockTimeout": 50, - "transactionBuilder": undefined, - "transactionConfirmationBlocks": 24, - "transactionConfirmationPollingInterval": undefined, - "transactionPollingInterval": 1000, - "transactionPollingTimeout": 750000, - "transactionReceiptPollingInterval": undefined, - "transactionSendTimeout": 750000, - "transactionTypeParser": undefined, - }, - "provider": HttpProvider { - "clientUrl": "http://test/abc", - "httpProviderOptions": undefined, - }, - "providers": { - "HttpProvider": [Function], - "WebsocketProvider": [Function], - }, - "registeredSubscriptions": {}, - "requestManager": Web3RequestManager { - "_emitter": { - "_events": { - "BEFORE_PROVIDER_CHANGE": [Function], - "PROVIDER_CHANGED": [Function], - }, - "_eventsCount": 2, - "_maxListeners": undefined, - Symbol(kCapture): false, - Symbol(shapeMode): false, - }, - "_provider": HttpProvider { - "clientUrl": "http://test/abc", - "httpProviderOptions": undefined, - }, - "useRpcCallSpecification": undefined, - }, - "subscriptionManager": Web3SubscriptionManager { - "_subscriptions": Map {}, - "registeredSubscriptions": {}, - "requestManager": Web3RequestManager { - "_emitter": { - "_events": { - "BEFORE_PROVIDER_CHANGE": [Function], - "PROVIDER_CHANGED": [Function], - }, - "_eventsCount": 2, - "_maxListeners": undefined, - Symbol(kCapture): false, - Symbol(shapeMode): false, - }, - "_provider": HttpProvider { - "clientUrl": "http://test/abc", - "httpProviderOptions": undefined, - }, - "useRpcCallSpecification": undefined, - }, - "tolerateUnlinkedSubscription": false, - }, - "wallet": undefined, -} -`; diff --git a/packages/web3-providers-ws/test/integration/web_socket_provider_integration.test.ts b/packages/web3-providers-ws/test/integration/web_socket_provider_integration.test.ts index d93521be0c2..ccc1a97714f 100644 --- a/packages/web3-providers-ws/test/integration/web_socket_provider_integration.test.ts +++ b/packages/web3-providers-ws/test/integration/web_socket_provider_integration.test.ts @@ -137,6 +137,21 @@ describeIf(isWs)('WebSocketProvider - implemented methods', () => { webSocketProvider.disconnect(code); await closePromise; }); + + it('should error when no connection is established', async () => { + const wsProvider = new WebSocketProvider("ws://localhost:999",{}, { autoReconnect: false }); + let errored = false; + try{ + await wsProvider.request(jsonRpcPayload); + // should not be able to reach here + + }catch(e){ + // eslint-disable-next-line jest/no-conditional-expect + expect((e as any).message).toBe('Connection not open') + errored = true; + } + expect(errored).toBe(true); + }); }); describe('disconnect and reset test', () => { diff --git a/packages/web3-providers-ws/test/unit/__mocks__/isomorphic-ws.ts b/packages/web3-providers-ws/test/unit/__mocks__/isomorphic-ws.ts index 42a0cdf4871..d5e9d79cef9 100644 --- a/packages/web3-providers-ws/test/unit/__mocks__/isomorphic-ws.ts +++ b/packages/web3-providers-ws/test/unit/__mocks__/isomorphic-ws.ts @@ -23,10 +23,9 @@ export default class WebSocket extends EventEmitter { public CONNECTING = 0; public OPEN = 1; - public constructor(...args: any[]) { + public constructor() { + super() // eslint-disable-next-line @typescript-eslint/no-unsafe-call - super(...args); - // Connected state this.readyState = 1; } @@ -43,13 +42,12 @@ export default class WebSocket extends EventEmitter { }, 100); } - public addEventListener(event: any, cb: () => void) { - // eslint-disable-next-line @typescript-eslint/no-unsafe-call - this.prependListener(event, cb); + public addEventListener(_event: any, _cb: () => void) { + this.on(_event, _cb) + } - public removeEventListener(event: any, cb: () => void) { - // eslint-disable-next-line @typescript-eslint/no-unsafe-call - this.removeListener(event, cb); + public removeEventListener(_event: any, _cb: () => void) { + this.off(_event, _cb) } } diff --git a/packages/web3-providers-ws/test/unit/check_implementation.test.ts b/packages/web3-providers-ws/test/unit/check_implementation.test.ts index 99d7013b45b..138855b9509 100644 --- a/packages/web3-providers-ws/test/unit/check_implementation.test.ts +++ b/packages/web3-providers-ws/test/unit/check_implementation.test.ts @@ -85,21 +85,6 @@ describe('WebSocketProvider', () => { ws.disconnect(code, data); expect(close).toHaveBeenCalledWith(code, data); }); - it('connection error', async () => { - const ws = new WebSocketProvider('ws://localhost:8545'); - // @ts-expect-error mock method - ws._socketConnection.readyState = 2; - ws.connect = jest.fn(); - - await expect( - ws.request({ - jsonrpc: '2.0', - id: 42, - method: 'eth_getBalance', - params: ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', 'latest'], - }), - ).rejects.toThrow('Connection not open'); - }); it('onCloseEvent autoReconnect=false', () => { const ws = new WebSocketProvider('ws://localhost:8545', {}, { autoReconnect: false }); const _clearQueues = jest.fn(); @@ -107,6 +92,7 @@ describe('WebSocketProvider', () => { const _onDisconnect = jest.fn(); // @ts-expect-error mock method ws._socketConnection.close = jest.fn(); + // @ts-expect-error mock method ws._clearQueues = _clearQueues; // @ts-expect-error mock method @@ -140,7 +126,7 @@ describe('WebSocketProvider', () => { const ws = new WebSocketProvider('ws://localhost:8545'); // @ts-expect-error mock method ws._socketConnection.listeners = () => { - throw new Error('error'); + throw new Error('error'); }; const addEventListener = jest.fn(); // @ts-expect-error mock method @@ -161,6 +147,6 @@ describe('WebSocketProvider', () => { expect(removeEventListener).toHaveBeenCalledWith('open', ws._onOpenHandler); // @ts-expect-error mock method expect(removeEventListener).toHaveBeenCalledWith('close', ws._onCloseHandler); - }); + }); }); }); diff --git a/packages/web3-utils/src/socket_provider.ts b/packages/web3-utils/src/socket_provider.ts index 3c879a2df84..d847dcbccc9 100644 --- a/packages/web3-utils/src/socket_provider.ts +++ b/packages/web3-utils/src/socket_provider.ts @@ -118,7 +118,6 @@ export abstract class SocketProvider< this._socketPath = socketPath; this._socketOptions = socketOptions; - this._reconnectOptions = { ...DEFAULT_RECONNECTION_OPTIONS, ...(reconnectOptions ?? {}), @@ -465,7 +464,6 @@ export abstract class SocketProvider< if (this._sentRequestsQueue.has(requestId)) { throw new RequestAlreadySentError(requestId); } - const deferredPromise = new Web3DeferredPromise>(); deferredPromise.catch(error => { this._eventEmitter.emit('error', error); From fb28b3b45da4f4fe525cbb911c85fb0e4bdb1528 Mon Sep 17 00:00:00 2001 From: Alex Luu Date: Sat, 24 Feb 2024 15:04:56 -0500 Subject: [PATCH 4/5] update snapshot --- .../__snapshots__/web3_context.test.ts.snap | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 packages/web3-core/test/unit/__snapshots__/web3_context.test.ts.snap diff --git a/packages/web3-core/test/unit/__snapshots__/web3_context.test.ts.snap b/packages/web3-core/test/unit/__snapshots__/web3_context.test.ts.snap new file mode 100644 index 00000000000..7e9121c85d2 --- /dev/null +++ b/packages/web3-core/test/unit/__snapshots__/web3_context.test.ts.snap @@ -0,0 +1,113 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Web3Context getContextObject should return correct context object 1`] = ` +{ + "accountProvider": undefined, + "config": { + "blockHeaderTimeout": 10, + "contractDataInputFill": "data", + "defaultAccount": undefined, + "defaultBlock": "latest", + "defaultChain": "mainnet", + "defaultCommon": undefined, + "defaultHardfork": "london", + "defaultMaxPriorityFeePerGas": "0x9502f900", + "defaultNetworkId": undefined, + "defaultTransactionType": "0x2", + "enableExperimentalFeatures": { + "useRpcCallSpecification": false, + "useSubscriptionWhenCheckingBlockTimeout": false, + }, + "handleRevert": false, + "maxListenersWarningThreshold": 100, + "transactionBlockTimeout": 50, + "transactionBuilder": undefined, + "transactionConfirmationBlocks": 24, + "transactionConfirmationPollingInterval": undefined, + "transactionPollingInterval": 1000, + "transactionPollingTimeout": 750000, + "transactionReceiptPollingInterval": undefined, + "transactionSendTimeout": 750000, + "transactionTypeParser": undefined, + }, + "provider": HttpProvider { + "clientUrl": "http://test/abc", + "httpProviderOptions": undefined, + }, + "providers": { + "HttpProvider": [Function], + "WebsocketProvider": [Function], + }, + "registeredSubscriptions": {}, + "requestManager": Web3RequestManager { + "_emitter": { + "_events": { + "BEFORE_PROVIDER_CHANGE": EE { + "context": EventEmitter { + "_events": [Circular], + "_eventsCount": 2, + "maxListeners": 9007199254740991, + }, + "fn": [Function], + "once": false, + }, + "PROVIDER_CHANGED": EE { + "context": EventEmitter { + "_events": [Circular], + "_eventsCount": 2, + "maxListeners": 9007199254740991, + }, + "fn": [Function], + "once": false, + }, + }, + "_eventsCount": 2, + "maxListeners": 9007199254740991, + Symbol(shapeMode): false, + }, + "_provider": HttpProvider { + "clientUrl": "http://test/abc", + "httpProviderOptions": undefined, + }, + "useRpcCallSpecification": undefined, + }, + "subscriptionManager": Web3SubscriptionManager { + "_subscriptions": Map {}, + "registeredSubscriptions": {}, + "requestManager": Web3RequestManager { + "_emitter": { + "_events": { + "BEFORE_PROVIDER_CHANGE": EE { + "context": EventEmitter { + "_events": [Circular], + "_eventsCount": 2, + "maxListeners": 9007199254740991, + }, + "fn": [Function], + "once": false, + }, + "PROVIDER_CHANGED": EE { + "context": EventEmitter { + "_events": [Circular], + "_eventsCount": 2, + "maxListeners": 9007199254740991, + }, + "fn": [Function], + "once": false, + }, + }, + "_eventsCount": 2, + "maxListeners": 9007199254740991, + Symbol(shapeMode): false, + }, + "_provider": HttpProvider { + "clientUrl": "http://test/abc", + "httpProviderOptions": undefined, + }, + "useRpcCallSpecification": undefined, + }, + "tolerateUnlinkedSubscription": false, + }, + "wallet": undefined, +} +`; From 334ea0bbb1c1a5d363e918c838b2ab6c77f4e33e Mon Sep 17 00:00:00 2001 From: Alex Luu Date: Sat, 24 Feb 2024 15:17:54 -0500 Subject: [PATCH 5/5] remove connection error test --- .../test/unit/check_implementation.test.ts | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/packages/web3-providers-ipc/test/unit/check_implementation.test.ts b/packages/web3-providers-ipc/test/unit/check_implementation.test.ts index 3b75744a25a..cc13c1b0281 100644 --- a/packages/web3-providers-ipc/test/unit/check_implementation.test.ts +++ b/packages/web3-providers-ipc/test/unit/check_implementation.test.ts @@ -97,23 +97,6 @@ describe('IPCProvider', () => { expect(end).toHaveBeenCalled(); }); - it('connection error', async () => { - const ipc = new IpcProvider(socketPath); - // @ts-expect-error mock method - ipc._socketConnection.connecting = false; - // @ts-expect-error mock method - ipc._connectionStatus = 'disconnected'; - ipc.connect = jest.fn(); - - await expect( - ipc.request({ - jsonrpc: '2.0', - id: 42, - method: 'eth_getBalance', - params: ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', 'latest'], - }), - ).rejects.toThrow('Connection not open'); - }); it('_onCloseHandler autoReconnect=false', () => { const ipc = new IpcProvider(socketPath, {}, { autoReconnect: false }); const _clearQueues = jest.fn();