Skip to content

Commit bb65ac5

Browse files
committed
fix: change path prefix const names + add testnet path prefix UT
1 parent ad6515d commit bb65ac5

2 files changed

Lines changed: 33 additions & 11 deletions

File tree

packages/keyring-eth-trezor/src/trezor-keyring-v2.test.ts

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import type { TrezorBridge } from './trezor-bridge';
1313
import { TrezorKeyring } from './trezor-keyring';
1414
import {
1515
BIP44_HD_PATH_PREFIX,
16-
LEGACY_MEW_PATH,
16+
LEGACY_MEW_PATH_PREFIX,
17+
SLIP0044_TESTNET_PATH_PREFIX,
1718
TrezorKeyringV2,
1819
} from './trezor-keyring-v2';
1920

@@ -482,23 +483,44 @@ describe('TrezorKeyringV2', () => {
482483

483484
it('creates an account with legacy MEW path', async () => {
484485
// Create wrapper with legacy MEW path pre-set to avoid HDKey reset
485-
const inner = createInnerKeyring(LEGACY_MEW_PATH);
486+
const inner = createInnerKeyring(LEGACY_MEW_PATH_PREFIX);
486487
const wrapper = new TrezorKeyringV2({
487488
legacyKeyring: inner,
488489
entropySource,
489490
});
490491

491492
const newAccounts = await wrapper.createAccounts(
492-
derivePathOptions(`${LEGACY_MEW_PATH}/3`),
493+
derivePathOptions(`${LEGACY_MEW_PATH_PREFIX}/3`),
493494
);
494495
const account = getFirstAccount(newAccounts);
495496

496497
expect(account.address).toBe(EXPECTED_ACCOUNTS[3]);
497498
expect(account.options.entropy.groupIndex).toBe(3);
498499
expect(account.options.entropy.derivationPath).toBe(
499-
`${LEGACY_MEW_PATH}/3`,
500+
`${LEGACY_MEW_PATH_PREFIX}/3`,
500501
);
501-
expect(inner.hdPath).toBe(LEGACY_MEW_PATH);
502+
expect(inner.hdPath).toBe(LEGACY_MEW_PATH_PREFIX);
503+
});
504+
505+
it('creates an account with SLIP0044 testnet path', async () => {
506+
// Create wrapper with testnet path pre-set to avoid HDKey reset
507+
const inner = createInnerKeyring(SLIP0044_TESTNET_PATH_PREFIX);
508+
const wrapper = new TrezorKeyringV2({
509+
legacyKeyring: inner,
510+
entropySource,
511+
});
512+
513+
const newAccounts = await wrapper.createAccounts(
514+
derivePathOptions(`${SLIP0044_TESTNET_PATH_PREFIX}/2`),
515+
);
516+
const account = getFirstAccount(newAccounts);
517+
518+
expect(account.address).toBe(EXPECTED_ACCOUNTS[2]);
519+
expect(account.options.entropy.groupIndex).toBe(2);
520+
expect(account.options.entropy.derivationPath).toBe(
521+
`${SLIP0044_TESTNET_PATH_PREFIX}/2`,
522+
);
523+
expect(inner.hdPath).toBe(SLIP0044_TESTNET_PATH_PREFIX);
502524
});
503525

504526
it('returns existing account if path already exists', async () => {
@@ -664,7 +686,7 @@ describe('TrezorKeyringV2', () => {
664686
describe('different HD paths', () => {
665687
it('uses the correct derivation path from the inner keyring', async () => {
666688
const inner = createInnerKeyring();
667-
inner.setHdPath(LEGACY_MEW_PATH);
689+
inner.setHdPath(LEGACY_MEW_PATH_PREFIX);
668690
inner.hdk = fakeHdKey; // Reset after setHdPath clears it
669691
inner.setAccountToUnlock(0);
670692
await inner.addAccounts(1);
@@ -678,7 +700,7 @@ describe('TrezorKeyringV2', () => {
678700
const account = getFirstAccount(accounts);
679701

680702
expect(account.options.entropy.derivationPath).toBe(
681-
`${LEGACY_MEW_PATH}/0`,
703+
`${LEGACY_MEW_PATH_PREFIX}/0`,
682704
);
683705
});
684706

packages/keyring-eth-trezor/src/trezor-keyring-v2.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,21 @@ export const BIP44_HD_PATH_PREFIX = `m/44'/60'/0'/0`;
4646
/**
4747
* SLIP-0044 testnet HD path prefix constant.
4848
*/
49-
export const SLIP0044_TESTNET_PATH = `m/44'/1'/0'/0`;
49+
export const SLIP0044_TESTNET_PATH_PREFIX = `m/44'/1'/0'/0`;
5050

5151
/**
5252
* Legacy MEW (MyEtherWallet) HD path prefix constant.
5353
*/
54-
export const LEGACY_MEW_PATH = `m/44'/60'/0'`;
54+
export const LEGACY_MEW_PATH_PREFIX = `m/44'/60'/0'`;
5555

5656
/**
5757
* Allowed HD paths for Trezor keyring.
5858
* These must match the keys in ALLOWED_HD_PATHS from trezor-keyring.ts.
5959
*/
6060
const ALLOWED_HD_PATHS = [
6161
BIP44_HD_PATH_PREFIX,
62-
SLIP0044_TESTNET_PATH,
63-
LEGACY_MEW_PATH,
62+
SLIP0044_TESTNET_PATH_PREFIX,
63+
LEGACY_MEW_PATH_PREFIX,
6464
] as const;
6565

6666
/**

0 commit comments

Comments
 (0)