From f7109f8ea21757b04d34ed8529f6a9c1dab3ed6c Mon Sep 17 00:00:00 2001 From: Francisco Date: Fri, 2 Jun 2023 09:48:32 +0200 Subject: [PATCH 01/14] StorageService to 100% --- packages/bridge-ui/jest.config.js | 4 +- .../src/storage/StorageService.spec.ts | 45 +++++++++++++++---- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/packages/bridge-ui/jest.config.js b/packages/bridge-ui/jest.config.js index f13e75b6cd..c5a1ccd9da 100644 --- a/packages/bridge-ui/jest.config.js +++ b/packages/bridge-ui/jest.config.js @@ -46,8 +46,8 @@ export default { // - bridge/ERC20Bridge (partial test coverage) // - bridge/ETHBridge (partial test coverage) statements: 89, - branches: 86, - functions: 91, + branches: 88, + functions: 92, lines: 89, }, }, diff --git a/packages/bridge-ui/src/storage/StorageService.spec.ts b/packages/bridge-ui/src/storage/StorageService.spec.ts index 0738dc59af..4199cab803 100644 --- a/packages/bridge-ui/src/storage/StorageService.spec.ts +++ b/packages/bridge-ui/src/storage/StorageService.spec.ts @@ -236,7 +236,7 @@ describe('storage tests', () => { ]); }); - it('ignore txs from unsupported chains when getting all txs', async () => { + it('ignores txs from unsupported chains when getting all txs', async () => { providers[L1_CHAIN_ID] = undefined; const svc = new StorageService(mockStorage as any, providers); @@ -258,7 +258,7 @@ describe('storage tests', () => { expect(tx).toBeUndefined(); }); - it('get transaction by hash, no receipt', async () => { + it('gets transaction by hash, no receipt', async () => { mockProvider.getTransactionReceipt.mockImplementation(() => { return null; }); @@ -270,7 +270,7 @@ describe('storage tests', () => { expect(tx).toEqual(tx); }); - it('get transaction by hash, no event', async () => { + it('gets transaction by hash, no event', async () => { mockContract.queryFilter.mockImplementation(() => { return []; }); @@ -285,7 +285,7 @@ describe('storage tests', () => { }); }); - it('get transaction by hash where tx.from !== address', async () => { + it('gets transaction by hash where tx.from !== address', async () => { const svc = new StorageService(mockStorage as any, providers); const tx = await svc.getTransactionByHash('0x666', mockTx.hash); @@ -293,7 +293,7 @@ describe('storage tests', () => { expect(tx).toBeUndefined(); }); - it('get transaction by hash, ETH transfer', async () => { + it('gets transaction by hash, ETH transfer', async () => { mockContract.queryFilter.mockImplementation(() => { return mockQuery; }); @@ -315,7 +315,7 @@ describe('storage tests', () => { }); }); - it('get transaction by hash, no ERC20Sent event', async () => { + it('gets transaction by hash, no ERC20Sent event', async () => { mockContract.queryFilter.mockImplementation((filter: string) => { if (filter === 'ERC20Sent') return []; return mockErc20Query; // MessageSent @@ -334,7 +334,7 @@ describe('storage tests', () => { }); }); - it('get transaction by hash, ERC20 transfer', async () => { + it('gets transaction by hash, ERC20 transfer', async () => { mockContract.queryFilter.mockImplementation(() => { return mockErc20Query; }); @@ -360,7 +360,7 @@ describe('storage tests', () => { }); }); - it('ignore txs from unsupported chains when getting txs by hash', async () => { + it('ignores txs from unsupported chains when getting txs by hash', async () => { providers[L1_CHAIN_ID] = undefined; const svc = new StorageService(mockStorage as any, providers); @@ -370,6 +370,35 @@ describe('storage tests', () => { expect(tx).toBeUndefined(); }); + it('makes sure New transactions are on top of the list', async () => { + mockStorage.getItem.mockImplementation(() => { + return JSON.stringify([ + { ...mockTx, status: MessageStatus.New }, + { ...mockTx, status: MessageStatus.Done }, + { ...mockTx, status: MessageStatus.Retriable }, + { ...mockTx, status: MessageStatus.New }, + ]); + }); + + mockContract.queryFilter.mockImplementation(() => { + return []; + }); + + const svc = new StorageService(mockStorage as any, providers); + + const tx = await svc.getAllByAddress('0x123'); + const statuses = tx.map((t) => t.status); + + // New txs should be on top + expect(statuses).toEqual([ + MessageStatus.New, + MessageStatus.New, + //----------------// + MessageStatus.Done, + MessageStatus.Retriable, + ]); + }); + it('updates storage by address', () => { mockStorage.getItem.mockImplementation(() => { return JSON.stringify(mockTxs); From 2fc1d14b855f7bb248264a7a91a08290694b5bd1 Mon Sep 17 00:00:00 2001 From: Francisco Date: Fri, 2 Jun 2023 10:48:15 +0200 Subject: [PATCH 02/14] improve type checking --- .../bridge-ui/src/bridge/ETHBridge.spec.ts | 2 + .../components/BridgeForm/BridgeForm.svelte | 4 +- packages/bridge-ui/src/constants/envVars.ts | 35 ++++---- packages/bridge-ui/src/domain/chain.ts | 3 +- packages/bridge-ui/src/domain/relayerApi.ts | 12 +-- packages/bridge-ui/src/domain/token.ts | 7 +- packages/bridge-ui/src/globals.d.ts | 1 + .../bridge-ui/src/proof/ProofService.spec.ts | 80 +++++++++---------- .../src/relayer-api/RelayerAPIService.spec.ts | 2 +- .../src/relayer-api/RelayerAPIService.ts | 8 +- .../bridge-ui/src/signer/subscriber.spec.ts | 2 +- packages/bridge-ui/src/signer/subscriber.ts | 9 ++- .../src/storage/StorageService.spec.ts | 2 +- .../bridge-ui/src/storage/StorageService.ts | 11 +-- .../bridge-ui/src/utils/addressAvatar.spec.ts | 2 - .../src/utils/addressSubsection.spec.ts | 2 - .../checkIfTokenIsDeployedCrossChain.spec.ts | 4 +- .../bridge-ui/src/utils/getAddressForToken.ts | 3 +- .../src/utils/isOnCorrectChain.spec.ts | 2 +- .../src/utils/recommendProcessingFee.spec.ts | 3 +- .../src/utils/truncateString.spec.ts | 2 - packages/bridge-ui/src/vault/tokenVaults.ts | 4 +- 22 files changed, 97 insertions(+), 103 deletions(-) diff --git a/packages/bridge-ui/src/bridge/ETHBridge.spec.ts b/packages/bridge-ui/src/bridge/ETHBridge.spec.ts index 466b0d5842..e99479e61a 100644 --- a/packages/bridge-ui/src/bridge/ETHBridge.spec.ts +++ b/packages/bridge-ui/src/bridge/ETHBridge.spec.ts @@ -68,6 +68,8 @@ describe('bridge tests', () => { contractAddress: '0x1234', spenderAddress: '0x', }); + + expect(tx).toEqual({}); }); it('bridges with processing fee, owner !== to', async () => { diff --git a/packages/bridge-ui/src/components/BridgeForm/BridgeForm.svelte b/packages/bridge-ui/src/components/BridgeForm/BridgeForm.svelte index 5948595410..b43a49fe32 100644 --- a/packages/bridge-ui/src/components/BridgeForm/BridgeForm.svelte +++ b/packages/bridge-ui/src/components/BridgeForm/BridgeForm.svelte @@ -1,5 +1,5 @@