Skip to content

Commit

Permalink
fix: test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
vvava committed Dec 12, 2024
1 parent 4286c96 commit 32be99f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/background/services/network/NetworkService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions src/background/services/secrets/SecretsService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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)
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/background/services/secrets/SecretsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
}
Expand Down

0 comments on commit 32be99f

Please sign in to comment.