Skip to content

Commit 54c61f0

Browse files
committed
improve test coverage
1 parent 69255b8 commit 54c61f0

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

packages/account-tree-controller/src/AccountTreeController.test.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2187,6 +2187,70 @@ describe('AccountTreeController', () => {
21872187
});
21882188

21892189
describe('Fallback Naming', () => {
2190+
it('detects new groups based on account import time', () => {
2191+
const serviceStartTime = Date.now();
2192+
const mockAccountWithNewImportTime: Bip44Account<InternalAccount> = {
2193+
...MOCK_HD_ACCOUNT_1,
2194+
options: {
2195+
...MOCK_HD_ACCOUNT_1.options,
2196+
entropy: {
2197+
...MOCK_HD_ACCOUNT_1.options.entropy,
2198+
id: MOCK_HD_KEYRING_1.metadata.id,
2199+
groupIndex: 0,
2200+
},
2201+
},
2202+
metadata: {
2203+
...MOCK_HD_ACCOUNT_1.metadata,
2204+
importTime: serviceStartTime + 1000, // Imported after service start
2205+
},
2206+
};
2207+
2208+
const mockAccountWithOldImportTime: Bip44Account<InternalAccount> = {
2209+
...MOCK_HD_ACCOUNT_2,
2210+
options: {
2211+
...MOCK_HD_ACCOUNT_2.options,
2212+
entropy: {
2213+
...MOCK_HD_ACCOUNT_2.options.entropy,
2214+
id: MOCK_HD_KEYRING_1.metadata.id,
2215+
groupIndex: 1,
2216+
},
2217+
},
2218+
metadata: {
2219+
...MOCK_HD_ACCOUNT_2.metadata,
2220+
importTime: serviceStartTime - 1000, // Imported before service start
2221+
},
2222+
};
2223+
2224+
const { controller } = setup({
2225+
accounts: [mockAccountWithOldImportTime, mockAccountWithNewImportTime],
2226+
keyrings: [MOCK_HD_KEYRING_1],
2227+
});
2228+
2229+
controller.init();
2230+
2231+
const expectedWalletId = toMultichainAccountWalletId(
2232+
MOCK_HD_KEYRING_1.metadata.id,
2233+
);
2234+
2235+
const expectedGroupId1 = toMultichainAccountGroupId(
2236+
expectedWalletId,
2237+
mockAccountWithNewImportTime.options.entropy.groupIndex,
2238+
);
2239+
2240+
const expectedGroupId2 = toMultichainAccountGroupId(
2241+
expectedWalletId,
2242+
mockAccountWithOldImportTime.options.entropy.groupIndex,
2243+
);
2244+
2245+
const wallet = controller.state.accountTree.wallets[expectedWalletId];
2246+
const group1 = wallet?.groups[expectedGroupId1];
2247+
const group2 = wallet?.groups[expectedGroupId2];
2248+
2249+
// Groups should be named by index within the wallet
2250+
expect(group1?.metadata.name).toBe('Account 1');
2251+
expect(group2?.metadata.name).toBe('Account 2');
2252+
});
2253+
21902254
it('uses fallback naming when rule-based naming returns empty string', () => {
21912255
// Create accounts with empty names to trigger fallback naming
21922256
const mockAccountWithEmptyName1: Bip44Account<InternalAccount> = {

0 commit comments

Comments
 (0)