From 158fd1c8a706d64bf6bd6b7bc25bdf6aae70d7e9 Mon Sep 17 00:00:00 2001 From: dewanshparashar Date: Tue, 21 Jan 2025 19:17:00 +0530 Subject: [PATCH] dev: review comments --- .../src/token-bridge-sdk/EnhancedProvider.ts | 2 +- .../__tests__/EnhancedProvider.test.ts | 25 ++++++------------- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/packages/arb-token-bridge-ui/src/token-bridge-sdk/EnhancedProvider.ts b/packages/arb-token-bridge-ui/src/token-bridge-sdk/EnhancedProvider.ts index 42a521ba66..3aff892d27 100644 --- a/packages/arb-token-bridge-ui/src/token-bridge-sdk/EnhancedProvider.ts +++ b/packages/arb-token-bridge-ui/src/token-bridge-sdk/EnhancedProvider.ts @@ -73,7 +73,7 @@ const txReceiptFromString = (stringified: string): TransactionReceipt => { * @param txReceipt - The transaction receipt to check. * @returns True if the receipt can be cached, false otherwise. */ -const shouldCacheTxReceipt = ( +export const shouldCacheTxReceipt = ( chainId: number, txReceipt: TransactionReceipt ): boolean => { diff --git a/packages/arb-token-bridge-ui/src/token-bridge-sdk/__tests__/EnhancedProvider.test.ts b/packages/arb-token-bridge-ui/src/token-bridge-sdk/__tests__/EnhancedProvider.test.ts index f3d2bbbe89..ff9c0b2aa9 100644 --- a/packages/arb-token-bridge-ui/src/token-bridge-sdk/__tests__/EnhancedProvider.test.ts +++ b/packages/arb-token-bridge-ui/src/token-bridge-sdk/__tests__/EnhancedProvider.test.ts @@ -5,7 +5,7 @@ import { import { BigNumber } from 'ethers' import { ChainId } from '../../types/ChainId' import { rpcURLs } from '../../util/networks' -import EnhancedProvider from '../EnhancedProvider' +import EnhancedProvider, { shouldCacheTxReceipt } from '../EnhancedProvider' class TestStorage { private store: Record = {} @@ -50,10 +50,8 @@ describe('EnhancedProvider', () => { }) it('should fetch real transaction and use cache for subsequent requests', async () => { - const rpcUrl = rpcURLs[ChainId.Sepolia] - if (!rpcUrl) { - throw new Error('No RPC URL found for Sepolia') - } + const rpcUrl = rpcURLs[ChainId.Sepolia]! + const provider = new EnhancedProvider(rpcUrl, ChainId.Sepolia, storage) // Wait for network to be initialized await provider.ready @@ -108,18 +106,7 @@ describe('EnhancedProvider', () => { confirmations: 4 // Below Sepolia threshold of 5 } - // Mock the parent class's getTransactionReceipt - jest - .spyOn(StaticJsonRpcProvider.prototype, 'getTransactionReceipt') - .mockResolvedValue(mockReceipt) - - const receipt = await provider.getTransactionReceipt( - testTxReceipt.transactionHash - ) - expect(receipt).toBeTruthy() - - const cache = storage.getItem('arbitrum:bridge:tx-receipts-cache') - expect(cache).toBeFalsy() + expect(shouldCacheTxReceipt(ChainId.Sepolia, mockReceipt)).toBeFalsy() }) it('should cache receipt when confirmations are above threshold', async () => { @@ -133,7 +120,9 @@ describe('EnhancedProvider', () => { .spyOn(StaticJsonRpcProvider.prototype, 'getTransactionReceipt') .mockResolvedValue(mockReceipt) - const receipt = await provider.getTransactionReceipt('0x1234') + const receipt = await provider.getTransactionReceipt( + mockReceipt.transactionHash + ) expect(receipt).toBeTruthy() const cache = storage.getItem('arbitrum:bridge:tx-receipts-cache')