From c017bf8ecbaff641653d8e280d2b8cf8088f9c8c Mon Sep 17 00:00:00 2001 From: Martin Homola Date: Thu, 12 Dec 2024 17:41:04 +0100 Subject: [PATCH] wip --- .../tests/unit/fixtures/getInfo.ts | 27 +++++++++++++++++ packages/connect-common/files/coins-eth.json | 12 ++++++-- packages/connect/e2e/__wscache__/blockbook.js | 3 +- packages/connect/src/backend/Blockchain.ts | 2 +- .../src/backend/__tests__/Blockchain.test.ts | 29 ++++++++++++++++++- packages/connect/src/data/coinInfo.ts | 1 - .../__tests__/deviceFeaturesUtils.test.ts | 6 ++-- 7 files changed, 69 insertions(+), 11 deletions(-) diff --git a/packages/blockchain-link/tests/unit/fixtures/getInfo.ts b/packages/blockchain-link/tests/unit/fixtures/getInfo.ts index 8239c257aca..502cbdc961d 100644 --- a/packages/blockchain-link/tests/unit/fixtures/getInfo.ts +++ b/packages/blockchain-link/tests/unit/fixtures/getInfo.ts @@ -39,6 +39,33 @@ export default { consensusBranchId: 3268858036, }, }, + { + description: 'BASE L2 network', + serverFixtures: [ + { + method: 'getInfo', + response: { + data: { + name: 'Base Archive', + shortcut: 'ETH', + network: 'BASE', + decimals: 18, + bestHeight: 23603976, + backend: { + version: 'Geth/v1.101411.2-stable-3dd9b027/linux-amd64/go1.23.3', + }, + }, + }, + }, + ], + response: { + name: 'Base Archive', + shortcut: 'ETH', + network: 'BASE', + decimals: 18, + blockHeight: 23603976, + }, + }, { description: 'Error', serverFixtures: [ diff --git a/packages/connect-common/files/coins-eth.json b/packages/connect-common/files/coins-eth.json index e207c9ae541..e4fca325b7b 100644 --- a/packages/connect-common/files/coins-eth.json +++ b/packages/connect-common/files/coins-eth.json @@ -11,6 +11,7 @@ "is_testnet": false, "name": "Ethereum", "shortcut": "ETH", + "network": "ETH", "slip44": 60, "support": { "T1B1": "1.6.2", @@ -31,6 +32,7 @@ "is_testnet": false, "name": "BNB Smart Chain", "shortcut": "BNB", + "network": "BSC", "slip44": 714, "support": { "T1B1": "1.9.4", @@ -51,6 +53,7 @@ "is_testnet": false, "name": "Ethereum Classic", "shortcut": "ETC", + "network": "ETC", "slip44": 61, "support": { "T1B1": "1.6.2", @@ -71,6 +74,7 @@ "is_testnet": false, "name": "Polygon", "shortcut": "POL", + "network": "POL", "slip44": 966, "support": { "T1B1": "1.9.4", @@ -90,7 +94,8 @@ "coingecko_id": "base", "is_testnet": false, "name": "Base", - "shortcut": "BASE", + "shortcut": "ETH", + "network": "BASE", "slip44": 8453, "support": { "T1B1": "1.9.4", @@ -110,7 +115,8 @@ "coingecko_id": "optimistic-ethereum", "is_testnet": false, "name": "Optimism", - "shortcut": "OP", + "shortcut": "ETH", + "network": "OP", "slip44": 614, "support": { "T1B1": "1.9.4", @@ -130,6 +136,7 @@ "is_testnet": true, "name": "Holesky", "shortcut": "tHOL", + "network": "tHOL", "slip44": 1, "support": { "T1B1": "1.11.3", @@ -149,6 +156,7 @@ "is_testnet": true, "name": "Sepolia", "shortcut": "tSEP", + "network": "tSEP", "slip44": 1, "support": { "T1B1": "1.11.3", diff --git a/packages/connect/e2e/__wscache__/blockbook.js b/packages/connect/e2e/__wscache__/blockbook.js index f642f89aac8..f5ec6a71948 100644 --- a/packages/connect/e2e/__wscache__/blockbook.js +++ b/packages/connect/e2e/__wscache__/blockbook.js @@ -10,8 +10,7 @@ const blockbookFixtures = { bestHeight: 7000000, // high block to make sure that utxos have enough confirmations (composeTransaction test) bestHash: '', block0Hash: '', - // FIXME: consider to use params.network - network: params.shortcut, + network: params.network, testnet: true, version: '0.0.0-mocked', }, diff --git a/packages/connect/src/backend/Blockchain.ts b/packages/connect/src/backend/Blockchain.ts index b3fe864bfb2..3aa922683a0 100644 --- a/packages/connect/src/backend/Blockchain.ts +++ b/packages/connect/src/backend/Blockchain.ts @@ -129,7 +129,7 @@ export class Blockchain { this.serverInfo = info; const trezorNetworkShortcut = getNormalizedTrezorShortcut(this.coinInfo.shortcut); - const backendNetworkShortcut = this.serverInfo.network; + const backendNetworkShortcut = this.serverInfo?.network ?? this.serverInfo.shortcut; if (backendNetworkShortcut.toLowerCase() !== trezorNetworkShortcut.toLowerCase()) { throw ERRORS.TypedError('Backend_Invalid'); diff --git a/packages/connect/src/backend/__tests__/Blockchain.test.ts b/packages/connect/src/backend/__tests__/Blockchain.test.ts index 3d8e4086bd0..ae5cb66c31b 100644 --- a/packages/connect/src/backend/__tests__/Blockchain.test.ts +++ b/packages/connect/src/backend/__tests__/Blockchain.test.ts @@ -42,7 +42,34 @@ describe('backend/Blockchain', () => { }); it('cache estimated fees (ethereum-like)', async () => { - const coinInfo = getEthereumNetwork('Ethereum'); + const coinInfo = getEthereumNetwork('ETH'); + if (!coinInfo) throw new Error('coinInfo is missing'); + + const spy = jest.spyOn(BlockchainLink.prototype, 'estimateFee'); + + const backend = await initBlockchain(coinInfo, () => {}); + + // blocks: 1 was not requested before + await backend.estimateFee({ blocks: [1] }); + expect(spy.mock.calls.length).toEqual(1); + + // blocks: 1 is requested again, returned from cache + await backend.estimateFee({ blocks: [1] }); + expect(spy.mock.calls.length).toEqual(1); + + // blocks: 2 was not requested before + await backend.estimateFee({ blocks: [1, 2] }); + expect(spy.mock.calls.length).toEqual(2); + + // request with "specific" field + await backend.estimateFee({ blocks: [1, 2], specific: { value: '0x0' } }); + expect(spy.mock.calls.length).toEqual(3); + + spy.mockClear(); + }); + + it('cache estimated fees (ethereum-like) - L2 network', async () => { + const coinInfo = getEthereumNetwork('BASE'); if (!coinInfo) throw new Error('coinInfo is missing'); const spy = jest.spyOn(BlockchainLink.prototype, 'estimateFee'); diff --git a/packages/connect/src/data/coinInfo.ts b/packages/connect/src/data/coinInfo.ts index f4cd9afedef..910ca4374ca 100644 --- a/packages/connect/src/data/coinInfo.ts +++ b/packages/connect/src/data/coinInfo.ts @@ -39,7 +39,6 @@ export const getEthereumNetwork = (pathOrNetworkSymbol: DerivationPath) => { if (typeof pathOrNetworkSymbol === 'string') { const networkSymbol = pathOrNetworkSymbol.toLowerCase(); - // check coins-eth.json for chain; chain === networkSymbol return networks.find(network => network.chain.toLowerCase() === networkSymbol); } diff --git a/packages/connect/src/utils/__tests__/deviceFeaturesUtils.test.ts b/packages/connect/src/utils/__tests__/deviceFeaturesUtils.test.ts index ae0147e1a75..f650d2ac996 100644 --- a/packages/connect/src/utils/__tests__/deviceFeaturesUtils.test.ts +++ b/packages/connect/src/utils/__tests__/deviceFeaturesUtils.test.ts @@ -130,12 +130,11 @@ describe('utils/deviceFeaturesUtils', () => { ada: 'no-support', tada: 'no-support', bnb: 'update-required', - base: 'update-required', crw: 'update-required', eos: 'no-support', + eth: 'update-required', maid: 'no-capability', pol: 'update-required', - op: 'update-required', omni: 'no-capability', ppc: 'update-required', sol: 'no-support', @@ -171,14 +170,13 @@ describe('utils/deviceFeaturesUtils', () => { expect(getUnavailableCapabilities(featT2T1, coins2)).toEqual({ replaceTransaction: 'update-required', amountUnit: 'update-required', - base: 'update-required', bnb: 'update-required', + eth: 'update-required', decreaseOutput: 'update-required', eip1559: 'update-required', 'eip712-domain-only': 'update-required', maid: 'no-capability', pol: 'update-required', - op: 'update-required', omni: 'no-capability', taproot: 'update-required', tsep: 'update-required',