Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
adderpositive committed Dec 12, 2024
1 parent f5a2015 commit c017bf8
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 11 deletions.
27 changes: 27 additions & 0 deletions packages/blockchain-link/tests/unit/fixtures/getInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
12 changes: 10 additions & 2 deletions packages/connect-common/files/coins-eth.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"is_testnet": false,
"name": "Ethereum",
"shortcut": "ETH",
"network": "ETH",
"slip44": 60,
"support": {
"T1B1": "1.6.2",
Expand All @@ -31,6 +32,7 @@
"is_testnet": false,
"name": "BNB Smart Chain",
"shortcut": "BNB",
"network": "BSC",
"slip44": 714,
"support": {
"T1B1": "1.9.4",
Expand All @@ -51,6 +53,7 @@
"is_testnet": false,
"name": "Ethereum Classic",
"shortcut": "ETC",
"network": "ETC",
"slip44": 61,
"support": {
"T1B1": "1.6.2",
Expand All @@ -71,6 +74,7 @@
"is_testnet": false,
"name": "Polygon",
"shortcut": "POL",
"network": "POL",
"slip44": 966,
"support": {
"T1B1": "1.9.4",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -130,6 +136,7 @@
"is_testnet": true,
"name": "Holesky",
"shortcut": "tHOL",
"network": "tHOL",
"slip44": 1,
"support": {
"T1B1": "1.11.3",
Expand All @@ -149,6 +156,7 @@
"is_testnet": true,
"name": "Sepolia",
"shortcut": "tSEP",
"network": "tSEP",
"slip44": 1,
"support": {
"T1B1": "1.11.3",
Expand Down
3 changes: 1 addition & 2 deletions packages/connect/e2e/__wscache__/blockbook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
Expand Down
2 changes: 1 addition & 1 deletion packages/connect/src/backend/Blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
29 changes: 28 additions & 1 deletion packages/connect/src/backend/__tests__/Blockchain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
1 change: 0 additions & 1 deletion packages/connect/src/data/coinInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit c017bf8

Please sign in to comment.