From 76453a01597682fb384c94c344072408dda67c25 Mon Sep 17 00:00:00 2001 From: Tim Robinson Date: Wed, 12 Jul 2023 19:31:55 +1000 Subject: [PATCH 1/3] Use JsonRpc provider for initial block number --- src/services/rpc-provider/rpc-provider.service.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/services/rpc-provider/rpc-provider.service.ts b/src/services/rpc-provider/rpc-provider.service.ts index 50585633c0..c014ecf998 100644 --- a/src/services/rpc-provider/rpc-provider.service.ts +++ b/src/services/rpc-provider/rpc-provider.service.ts @@ -1,5 +1,5 @@ import { Network } from '@/lib/config'; -import { JsonRpcProvider, WebSocketProvider } from '@ethersproject/providers'; +import { JsonRpcProvider } from '@ethersproject/providers'; import { configService } from '@/services/config/config.service'; @@ -15,8 +15,8 @@ export default class RpcProviderService { ) {} public initBlockListener(newBlockHandler: NewBlockHandler): void { - const wsProvider = new WebSocketProvider(this.config.ws); - wsProvider.once('block', newBlockNumber => { + const blockProvider = new JsonRpcProvider(this.config.rpc); + blockProvider.once('block', newBlockNumber => { let currentBlockNumber = newBlockNumber; newBlockHandler(currentBlockNumber); setInterval(() => { From 1cc71ff0d1e7d7b76632e94ee1607a9fcac447c7 Mon Sep 17 00:00:00 2001 From: Tim Robinson Date: Wed, 12 Jul 2023 19:58:11 +1000 Subject: [PATCH 2/3] Add once function to mock provider in test --- src/services/rpc-provider/rpc-provider.service.spec.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/services/rpc-provider/rpc-provider.service.spec.ts b/src/services/rpc-provider/rpc-provider.service.spec.ts index 9c51d15a43..5098267e8b 100644 --- a/src/services/rpc-provider/rpc-provider.service.spec.ts +++ b/src/services/rpc-provider/rpc-provider.service.spec.ts @@ -6,7 +6,9 @@ import { StaticJsonRpcBatchProvider } from './static-json-rpc-batch-provider'; vi.mock('@ethersproject/providers', () => { return { JsonRpcProvider: vi.fn().mockImplementation(() => { - return {}; + return { + once: vi.fn(), + }; }), WebSocketProvider: vi.fn().mockImplementation(() => { return { From d9412c7585c4c88d09f886178b9604ea15f517eb Mon Sep 17 00:00:00 2001 From: Tim Robinson Date: Wed, 12 Jul 2023 20:06:46 +1000 Subject: [PATCH 3/3] Removed websocket provider and fixed test --- .../rpc-provider/rpc-provider.service.spec.ts | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/services/rpc-provider/rpc-provider.service.spec.ts b/src/services/rpc-provider/rpc-provider.service.spec.ts index 5098267e8b..d0f3aab22b 100644 --- a/src/services/rpc-provider/rpc-provider.service.spec.ts +++ b/src/services/rpc-provider/rpc-provider.service.spec.ts @@ -1,4 +1,4 @@ -import { JsonRpcProvider, WebSocketProvider } from '@ethersproject/providers'; +import { JsonRpcProvider } from '@ethersproject/providers'; import RpcProviderService from '@/services/rpc-provider/rpc-provider.service'; import { StaticJsonRpcBatchProvider } from './static-json-rpc-batch-provider'; @@ -10,11 +10,6 @@ vi.mock('@ethersproject/providers', () => { once: vi.fn(), }; }), - WebSocketProvider: vi.fn().mockImplementation(() => { - return { - once: vi.fn(), - }; - }), }; }); @@ -32,12 +27,10 @@ describe('RPC provider service', () => { StaticJsonRpcBatchProvider, true ); - const MockedWebSocketProvider = vi.mocked(WebSocketProvider, true); beforeEach(() => { MockedJsonRpcProvider.mockClear(); MockedStaticJsonRpcBatchProvider.mockClear(); - MockedWebSocketProvider.mockClear(); }); it('Instantiates the provider service', () => { @@ -52,6 +45,6 @@ describe('RPC provider service', () => { it('Calls the WebSocketProvider', () => { new RpcProviderService().initBlockListener(() => ({})); - expect(WebSocketProvider).toHaveBeenCalledTimes(1); + expect(MockedJsonRpcProvider).toHaveBeenCalledTimes(1); }); });