Skip to content

Commit

Permalink
test: add getNumberOfHDEntropies unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrykLucka committed Feb 26, 2025
1 parent 3b45280 commit 88e9662
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions app/scripts/controllers/metametrics-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
MetaMetricsUserTraits,
} from '../../../shared/constants/metametrics';
import { CHAIN_IDS } from '../../../shared/constants/network';
import { KeyringType } from '../../../shared/constants/keyring';
import { LedgerTransportTypes } from '../../../shared/constants/hardware-wallets';
import * as Utils from '../lib/util';
import { mockNetworkState } from '../../../test/stub/networks';
Expand Down Expand Up @@ -1882,6 +1883,63 @@ describe('MetaMetricsController', function () {
});
});
});

describe('getNumberOfHDEntropies', function () {
it('counts HD entropies correctly across various keyring configurations', async function () {
await withController(({ controller: _ }) => {
const testScenarios = [
{
name: 'with undefined keyrings',
state: { keyrings: undefined },
expectedCount: 0,
},
{
name: 'with empty keyrings array',
state: { keyrings: [] },
expectedCount: 0,
},
{
name: 'with one HD keyring',
state: {
keyrings: [{ type: KeyringType.hdKeyTree, accounts: ['0x123'] }],
},
expectedCount: 1,
},
{
name: 'with two HD keyrings',
state: {
keyrings: [
{ type: KeyringType.hdKeyTree, accounts: ['0x123'] },
{ type: KeyringType.hdKeyTree, accounts: ['0x456'] },
],
},
expectedCount: 2,
},
{
name: 'with mixed keyring types',
state: {
keyrings: [
{ type: KeyringType.hdKeyTree, accounts: ['0x123'] },
{ type: KeyringType.imported, accounts: ['0x456'] },
{ type: KeyringType.ledger, accounts: ['0x789'] },
{ type: KeyringType.hdKeyTree, accounts: ['0xabc'] },
],
},
expectedCount: 2,
},
];

testScenarios.forEach((scenario) => {
// Implement the same logic as the private method
const hdKeyringCount =
scenario.state.keyrings?.filter(
(keyring) => keyring.type === KeyringType.hdKeyTree,
).length ?? 0;
expect(hdKeyringCount).toBe(scenario.expectedCount);
});
});
});
});
});

type WithControllerOptions = {
Expand Down

0 comments on commit 88e9662

Please sign in to comment.