From 32be99fd910924c6b838fc7cdec273426f35f4ba Mon Sep 17 00:00:00 2001 From: Viktor Vasas Date: Thu, 12 Dec 2024 16:33:46 +0100 Subject: [PATCH] fix: test cases --- src/background/services/network/NetworkService.ts | 8 +++++--- src/background/services/secrets/SecretsService.test.ts | 5 +++++ src/background/services/secrets/SecretsService.ts | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/background/services/network/NetworkService.ts b/src/background/services/network/NetworkService.ts index 4bf8978e..b603601f 100644 --- a/src/background/services/network/NetworkService.ts +++ b/src/background/services/network/NetworkService.ts @@ -597,9 +597,11 @@ export class NetworkService implements OnLock, OnStorageReady { async saveCustomNetwork(customNetworkPayload: CustomNetworkPayload) { const customNetwork = decorateWithCaipId(customNetworkPayload); - const chainId = customNetworkPayload.caipId - ? caipToChainId(customNetworkPayload.caipId) - : parseInt(customNetwork.chainId.toString(16), 16); + const chainId = + customNetworkPayload.caipId && !customNetwork.chainId + ? caipToChainId(customNetworkPayload.caipId) + : parseInt(customNetwork.chainId.toString(16), 16); + const chainlist = await this._rawNetworks.promisify(); if (!chainlist) { diff --git a/src/background/services/secrets/SecretsService.test.ts b/src/background/services/secrets/SecretsService.test.ts index 47a03a1c..26b02531 100644 --- a/src/background/services/secrets/SecretsService.test.ts +++ b/src/background/services/secrets/SecretsService.test.ts @@ -1425,6 +1425,7 @@ describe('src/background/services/secrets/SecretsService.ts', () => { [NetworkVMType.AVM]: 'X-', [NetworkVMType.PVM]: 'P-', [NetworkVMType.CoreEth]: 'C-', + [NetworkVMType.HVM]: addressC, }); it('throws error if walletId is not provided', async () => { @@ -1446,6 +1447,8 @@ describe('src/background/services/secrets/SecretsService.ts', () => { it('returns the addresses for xpub', async () => { mockLedgerWallet(); (getAddressFromXPub as jest.Mock).mockReturnValueOnce('0x1'); + // TODO: remove this when the HVM will get the own address calculation + (getAddressFromXPub as jest.Mock).mockReturnValueOnce('0x1'); (getBech32AddressFromXPub as jest.Mock).mockReturnValueOnce('0x2'); await expect( secretsService.getAddresses(0, ACTIVE_WALLET_ID, networkService) @@ -1477,6 +1480,8 @@ describe('src/background/services/secrets/SecretsService.ts', () => { }); (networkService.isMainnet as jest.Mock).mockReturnValueOnce(false); (getEvmAddressFromPubKey as jest.Mock).mockReturnValueOnce('0x1'); + // TODO: remove when HVM address is implemented + (getEvmAddressFromPubKey as jest.Mock).mockReturnValueOnce('0x1'); (getBtcAddressFromPubKey as jest.Mock).mockReturnValueOnce('0x2'); await expect( diff --git a/src/background/services/secrets/SecretsService.ts b/src/background/services/secrets/SecretsService.ts index 25ebf806..3a4b294a 100644 --- a/src/background/services/secrets/SecretsService.ts +++ b/src/background/services/secrets/SecretsService.ts @@ -787,7 +787,7 @@ export class SecretsService implements OnUnlock { [NetworkVMType.AVM]: xAddr, [NetworkVMType.PVM]: pAddr, [NetworkVMType.CoreEth]: cAddr, - // TODO: getaddressfromhvm + // TODO: getaddressfromhvm -> todo in tests as well [NetworkVMType.HVM]: getAddressFromXPub(secrets.xpub, index), }; }