Skip to content

Commit 30b899d

Browse files
committed
chore: fix test
1 parent a1465fa commit 30b899d

File tree

4 files changed

+24
-19
lines changed

4 files changed

+24
-19
lines changed

packages/multichain-account-service/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export {
2222
EvmAccountProvider,
2323
SOL_ACCOUNT_PROVIDER_NAME,
2424
SolAccountProvider,
25+
BTC_ACCOUNT_PROVIDER_NAME,
26+
BtcAccountProvider,
2527
} from './providers';
2628
export { MultichainAccountWallet } from './MultichainAccountWallet';
2729
export { MultichainAccountGroup } from './MultichainAccountGroup';

packages/multichain-account-service/src/providers/BtcAccountProvider.test.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
getMultichainAccountServiceMessenger,
1414
getRootMessenger,
1515
MOCK_BTC_P2TR_ACCOUNT_1,
16+
MOCK_BTC_P2WPKH_ACCOUNT_1,
1617
MOCK_BTC_P2TR_DISCOVERED_ACCOUNT_1,
1718
MOCK_HD_ACCOUNT_1,
1819
MOCK_HD_KEYRING_1,
@@ -42,7 +43,7 @@ class MockBtcKeyring {
4243
#getIndexFromDerivationPath(derivationPath: string): number {
4344
// eslint-disable-next-line prefer-regex-literals
4445
const derivationPathIndexRegex = new RegExp(
45-
"^m/44'/501'/(?<index>[0-9]+)'/0'$",
46+
"^m/44'/0'/(?<index>[0-9]+)'/0'$",
4647
'u',
4748
);
4849

@@ -83,7 +84,7 @@ class MockBtcKeyring {
8384
}
8485

8586
/**
86-
* Sets up a SolAccountProvider for testing.
87+
* Sets up a BtcAccountProvider for testing.
8788
*
8889
* @param options - Configuration options for setup.
8990
* @param options.messenger - An optional messenger instance to use. Defaults to a new Messenger.
@@ -161,7 +162,7 @@ function setup({
161162
}
162163

163164
describe('BtcAccountProvider', () => {
164-
it('getName returns Solana', () => {
165+
it('getName returns Bitcoin', () => {
165166
const { provider } = setup({ accounts: [] });
166167
expect(provider.getName()).toBe('Bitcoin');
167168
});
@@ -197,7 +198,7 @@ describe('BtcAccountProvider', () => {
197198
});
198199

199200
it('creates accounts', async () => {
200-
const accounts = [MOCK_BTC_P2TR_ACCOUNT_1];
201+
const accounts = [MOCK_BTC_P2TR_ACCOUNT_1, MOCK_BTC_P2WPKH_ACCOUNT_1];
201202
const { provider, keyring } = setup({
202203
accounts,
203204
});
@@ -207,7 +208,7 @@ describe('BtcAccountProvider', () => {
207208
entropySource: MOCK_HD_KEYRING_1.metadata.id,
208209
groupIndex: newGroupIndex,
209210
});
210-
expect(newAccounts).toHaveLength(1);
211+
expect(newAccounts).toHaveLength(2);
211212
expect(keyring.createAccount).toHaveBeenCalled();
212213
});
213214

@@ -221,7 +222,7 @@ describe('BtcAccountProvider', () => {
221222
entropySource: MOCK_HD_KEYRING_1.metadata.id,
222223
groupIndex: 0,
223224
});
224-
expect(newAccounts).toHaveLength(1);
225+
expect(newAccounts).toHaveLength(2);
225226
expect(newAccounts[0]).toStrictEqual(MOCK_BTC_P2TR_ACCOUNT_1);
226227
});
227228

@@ -261,16 +262,16 @@ describe('BtcAccountProvider', () => {
261262
groupIndex: 0,
262263
});
263264

264-
expect(discovered).toHaveLength(1);
265+
expect(discovered).toHaveLength(2);
265266
// Ensure we did go through creation path
266267
expect(mocks.keyring.createAccount).toHaveBeenCalled();
267268
// Provider should now expose one account (newly created)
268-
expect(provider.getAccounts()).toHaveLength(1);
269+
expect(provider.getAccounts()).toHaveLength(2);
269270
});
270271

271272
it('returns existing account if it already exists at index', async () => {
272273
const { provider, mocks } = setup({
273-
accounts: [MOCK_BTC_P2TR_ACCOUNT_1],
274+
accounts: [MOCK_BTC_P2TR_ACCOUNT_1, MOCK_BTC_P2WPKH_ACCOUNT_1],
274275
});
275276

276277
// Simulate one discovered account — should resolve to the existing one
@@ -281,7 +282,10 @@ describe('BtcAccountProvider', () => {
281282
groupIndex: 0,
282283
});
283284

284-
expect(discovered).toStrictEqual([MOCK_BTC_P2TR_ACCOUNT_1]);
285+
expect(discovered).toStrictEqual([
286+
MOCK_BTC_P2TR_ACCOUNT_1,
287+
MOCK_BTC_P2WPKH_ACCOUNT_1,
288+
]);
285289
});
286290

287291
it('does not return any accounts if no account is discovered', async () => {

packages/multichain-account-service/src/providers/BtcAccountProvider.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ import { BtcAccountType, BtcScope } from '@metamask/keyring-api';
44
import { KeyringTypes } from '@metamask/keyring-controller';
55
import type { InternalAccount } from '@metamask/keyring-internal-api';
66
import { KeyringClient } from '@metamask/keyring-snap-client';
7-
import { withTimeout } from '@metamask/snaps-controllers';
87
import type { SnapId } from '@metamask/snaps-sdk';
98
import { HandlerType } from '@metamask/snaps-utils';
109
import type { Json, JsonRpcRequest } from '@metamask/utils';
1110

1211
import { SnapAccountProvider } from './SnapAccountProvider';
13-
import { withRetry } from './utils';
12+
import { withRetry, withTimeout } from './utils';
1413
import type { MultichainAccountServiceMessenger } from '../types';
1514

1615
export type BtcAccountProviderConfig = {
@@ -21,12 +20,12 @@ export type BtcAccountProviderConfig = {
2120
};
2221
};
2322

24-
export const BITCOIN_ACCOUNT_PROVIDER_NAME = 'Bitcoin' as const;
23+
export const BTC_ACCOUNT_PROVIDER_NAME = 'Bitcoin' as const;
2524

2625
export class BtcAccountProvider extends SnapAccountProvider {
27-
static NAME = BITCOIN_ACCOUNT_PROVIDER_NAME;
26+
static NAME = BTC_ACCOUNT_PROVIDER_NAME;
2827

29-
static BITCOIN_SNAP_ID = 'npm:@metamask/bitcoin-wallet-snap' as SnapId;
28+
static BTC_SNAP_ID = 'npm:@metamask/bitcoin-wallet-snap' as SnapId;
3029

3130
readonly #client: KeyringClient;
3231

@@ -42,9 +41,9 @@ export class BtcAccountProvider extends SnapAccountProvider {
4241
},
4342
},
4443
) {
45-
super(BtcAccountProvider.BITCOIN_SNAP_ID, messenger);
44+
super(BtcAccountProvider.BTC_SNAP_ID, messenger);
4645
this.#client = this.#getKeyringClientFromSnapId(
47-
BtcAccountProvider.BITCOIN_SNAP_ID,
46+
BtcAccountProvider.BTC_SNAP_ID,
4847
);
4948
this.#config = config;
5049
}

packages/multichain-account-service/src/tests/accounts.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ export const MOCK_BTC_P2WPKH_ACCOUNT_1: Bip44Account<InternalAccount> = {
170170
name: 'Bitcoin Native Segwit Account 1',
171171
importTime: 0,
172172
keyring: {
173-
type: 'Snap keyring',
173+
type: KeyringTypes.snap,
174174
},
175175
snap: {
176176
id: 'mock-btc-snap-id',
@@ -199,7 +199,7 @@ export const MOCK_BTC_P2TR_ACCOUNT_1: Bip44Account<InternalAccount> = {
199199
name: 'Bitcoin Taproot Account 1',
200200
importTime: 0,
201201
keyring: {
202-
type: 'Snap keyring',
202+
type: KeyringTypes.snap,
203203
},
204204
snap: {
205205
id: 'mock-btc-snap-id',

0 commit comments

Comments
 (0)