Skip to content

Commit 6959599

Browse files
committed
cleanup tests
1 parent a25846e commit 6959599

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

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

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,8 +1953,7 @@ describe('AccountTreeController', () => {
19531953

19541954
describe('Fallback Naming', () => {
19551955
it('uses consistent default naming regardless of account import time', () => {
1956-
const serviceStartTime = Date.now();
1957-
const mockAccountWithNewImportTime: Bip44Account<InternalAccount> = {
1956+
const mockAccount1: Bip44Account<InternalAccount> = {
19581957
...MOCK_HD_ACCOUNT_1,
19591958
options: {
19601959
...MOCK_HD_ACCOUNT_1.options,
@@ -1966,11 +1965,11 @@ describe('AccountTreeController', () => {
19661965
},
19671966
metadata: {
19681967
...MOCK_HD_ACCOUNT_1.metadata,
1969-
importTime: serviceStartTime + 1000, // Imported after service start
1968+
importTime: Date.now() + 1000, // Import time no longer affects naming
19701969
},
19711970
};
19721971

1973-
const mockAccountWithOldImportTime: Bip44Account<InternalAccount> = {
1972+
const mockAccount2: Bip44Account<InternalAccount> = {
19741973
...MOCK_HD_ACCOUNT_2,
19751974
options: {
19761975
...MOCK_HD_ACCOUNT_2.options,
@@ -1982,12 +1981,12 @@ describe('AccountTreeController', () => {
19821981
},
19831982
metadata: {
19841983
...MOCK_HD_ACCOUNT_2.metadata,
1985-
importTime: serviceStartTime - 1000, // Imported before service start
1984+
importTime: Date.now() - 1000, // Import time no longer affects naming
19861985
},
19871986
};
19881987

19891988
const { controller } = setup({
1990-
accounts: [mockAccountWithOldImportTime, mockAccountWithNewImportTime],
1989+
accounts: [mockAccount2, mockAccount1],
19911990
keyrings: [MOCK_HD_KEYRING_1],
19921991
});
19931992

@@ -1999,20 +1998,20 @@ describe('AccountTreeController', () => {
19991998

20001999
const expectedGroupId1 = toMultichainAccountGroupId(
20012000
expectedWalletId,
2002-
mockAccountWithNewImportTime.options.entropy.groupIndex,
2001+
mockAccount1.options.entropy.groupIndex,
20032002
);
20042003

20052004
const expectedGroupId2 = toMultichainAccountGroupId(
20062005
expectedWalletId,
2007-
mockAccountWithOldImportTime.options.entropy.groupIndex,
2006+
mockAccount2.options.entropy.groupIndex,
20082007
);
20092008

20102009
const wallet = controller.state.accountTree.wallets[expectedWalletId];
20112010
const group1 = wallet?.groups[expectedGroupId1];
20122011
const group2 = wallet?.groups[expectedGroupId2];
20132012

20142013
// Groups should use consistent default naming regardless of import time
2015-
// This verifies the fix for the serviceStartTime inconsistency bug
2014+
// This verifies that the serviceStartTime inconsistency bug has been fixed
20162015
expect(group1?.metadata.name).toBe('Account 1');
20172016
expect(group2?.metadata.name).toBe('Account 2');
20182017
});
@@ -2075,8 +2074,7 @@ describe('AccountTreeController', () => {
20752074
});
20762075

20772076
it('handles adding new accounts to existing groups correctly', () => {
2078-
const serviceStartTime = Date.now();
2079-
// Create an existing account (imported before service start)
2077+
// Create an existing account
20802078
const existingAccount: Bip44Account<InternalAccount> = {
20812079
...MOCK_HD_ACCOUNT_1,
20822080
id: 'existing-account',
@@ -2091,11 +2089,11 @@ describe('AccountTreeController', () => {
20912089
metadata: {
20922090
...MOCK_HD_ACCOUNT_1.metadata,
20932091
name: '', // Empty name to trigger naming logic
2094-
importTime: serviceStartTime - 1000, // Imported before service start
2092+
importTime: Date.now() - 1000,
20952093
},
20962094
};
20972095

2098-
// Create a new account (imported after service start) for the same group
2096+
// Create a new account for the same group
20992097
const newAccount: Bip44Account<InternalAccount> = {
21002098
...MOCK_HD_ACCOUNT_1,
21012099
id: 'new-account',
@@ -2110,7 +2108,7 @@ describe('AccountTreeController', () => {
21102108
metadata: {
21112109
...MOCK_HD_ACCOUNT_1.metadata,
21122110
name: '', // Empty name to trigger naming logic
2113-
importTime: serviceStartTime + 1000, // Imported after service start
2111+
importTime: Date.now() + 1000, // Import time no longer affects naming
21142112
},
21152113
};
21162114

@@ -2136,22 +2134,22 @@ describe('AccountTreeController', () => {
21362134
const wallet = controller.state.accountTree.wallets[expectedWalletId];
21372135
const group = wallet?.groups[expectedGroupId];
21382136

2139-
// The group should now be treated as "new" and use fallback naming
2137+
// The group should use consistent default naming
21402138
expect(group?.metadata.name).toBe('Account 1');
21412139
expect(group?.accounts).toHaveLength(2);
21422140
expect(group?.accounts).toContain(existingAccount.id);
21432141
expect(group?.accounts).toContain(newAccount.id);
21442142
});
21452143

2146-
it('handles groups not in WeakMap (fallback to false)', () => {
2147-
// Create an account with empty name to trigger naming logic
2144+
it('uses default naming when rule-based naming returns empty', () => {
2145+
// Create an account with empty name to trigger fallback to default naming
21482146
const mockAccountWithEmptyName: Bip44Account<InternalAccount> = {
21492147
...MOCK_HD_ACCOUNT_1,
21502148
id: 'account-with-empty-name',
21512149
metadata: {
21522150
...MOCK_HD_ACCOUNT_1.metadata,
2153-
name: '', // Empty name will cause rule-based naming to fail
2154-
importTime: Date.now() - 1000, // Old account (not new)
2151+
name: '',
2152+
importTime: Date.now() - 1000,
21552153
},
21562154
};
21572155

@@ -2170,7 +2168,7 @@ describe('AccountTreeController', () => {
21702168
const wallet = controller.state.accountTree.wallets[expectedWalletId];
21712169
const group = wallet?.groups[expectedGroupId];
21722170

2173-
// Should use computed name first since it's not a new group, then fallback to default
2171+
// Should use computed name first, then fallback to default
21742172
// Since the account has empty name, computed name will be empty, so it falls back to default
21752173
expect(group?.metadata.name).toBe('Account 1');
21762174
});

0 commit comments

Comments
 (0)