|
| 1 | +/* |
| 2 | +This file is part of web3.js. |
| 3 | +
|
| 4 | +web3.js is free software: you can redistribute it and/or modify |
| 5 | +it under the terms of the GNU Lesser General Public License as published by |
| 6 | +the Free Software Foundation, either version 3 of the License, or |
| 7 | +(at your option) any later version. |
| 8 | +
|
| 9 | +web3.js is distributed in the hope that it will be useful, |
| 10 | +but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +GNU Lesser General Public License for more details. |
| 13 | +
|
| 14 | +You should have received a copy of the GNU Lesser General Public License |
| 15 | +along with web3.js. If not, see <http://www.gnu.org/licenses/>. |
| 16 | +*/ |
| 17 | + |
| 18 | +import { Web3APIPayload, EthExecutionAPI, JsonRpcResponse, Web3ProviderStatus } from 'web3-types'; |
| 19 | +import { SocketProvider } from '../../src/socket_provider'; |
| 20 | + |
| 21 | +const dummySocketConnection = { dummy: 'dummy' }; |
| 22 | + |
| 23 | +class TestProvider extends SocketProvider<any, any, any> { |
| 24 | + protected _socketConnection?: typeof dummySocketConnection; |
| 25 | + |
| 26 | + protected _openSocketConnection() { |
| 27 | + this._socketConnection = dummySocketConnection; |
| 28 | + } |
| 29 | + |
| 30 | + // Dummy implementation of the abstract base methods |
| 31 | + // eslint-disable-next-line |
| 32 | + protected _addSocketListeners(): void {} |
| 33 | + // eslint-disable-next-line |
| 34 | + protected _removeSocketListeners(): void {} |
| 35 | + // eslint-disable-next-line |
| 36 | + protected _onCloseEvent(_event: unknown): void {} |
| 37 | + // eslint-disable-next-line |
| 38 | + protected _sendToSocket(_payload: Web3APIPayload<EthExecutionAPI, any>): void {} |
| 39 | + // eslint-disable-next-line |
| 40 | + protected _parseResponses(_event: any): JsonRpcResponse[] { |
| 41 | + return [] as JsonRpcResponse[]; |
| 42 | + } |
| 43 | + // eslint-disable-next-line |
| 44 | + protected _closeSocketConnection( |
| 45 | + _code?: number | undefined, |
| 46 | + _data?: string | undefined, |
| 47 | + // eslint-disable-next-line |
| 48 | + ): void {} |
| 49 | + // eslint-disable-next-line |
| 50 | + getStatus(): Web3ProviderStatus { |
| 51 | + return 'connected'; |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +describe('SocketProvider', () => { |
| 56 | + const socketPath = `some_path`; |
| 57 | + const socketOption = { dummyOption: true } as const; |
| 58 | + |
| 59 | + describe('constructor', () => { |
| 60 | + it('should construct the instance of the provider', () => { |
| 61 | + const provider = new TestProvider(socketPath, socketOption); |
| 62 | + expect(provider).toBeInstanceOf(SocketProvider); |
| 63 | + expect(provider.SocketConnection).toEqual(dummySocketConnection); |
| 64 | + }); |
| 65 | + }); |
| 66 | +}); |
0 commit comments