Skip to content

Commit 08b6fa0

Browse files
committed
test: move fixtures to separate file
1 parent 0b3231e commit 08b6fa0

3 files changed

Lines changed: 220 additions & 196 deletions

File tree

packages/keyring-eth-qr/src/qr-keyring.test.ts

Lines changed: 17 additions & 195 deletions
Original file line numberDiff line numberDiff line change
@@ -1,202 +1,24 @@
1-
import { Common } from '@ethereumjs/common';
2-
import { TransactionFactory } from '@ethereumjs/tx';
3-
import type { StoredKeyring } from '@keystonehq/base-eth-keyring';
4-
import {
5-
CryptoAccount,
6-
CryptoHDKey,
7-
CryptoOutput,
8-
ETHSignature,
9-
ScriptExpressions,
10-
} from '@keystonehq/bc-ur-registry-eth';
1+
import { CryptoAccount, ETHSignature } from '@keystonehq/bc-ur-registry-eth';
112
import { MetaMaskKeyring as KeystoneKeyring } from '@keystonehq/metamask-airgapped-keyring';
3+
import type { Hex } from '@metamask/utils';
124
import * as uuid from 'uuid';
135

14-
import type { QrKeyringBridge, SerializedQrKeyringState } from '.';
6+
import type { QrKeyringBridge } from '.';
157
import { QrKeyring, QrScanRequestType } from '.';
16-
import { DeviceMode } from './device';
17-
import { Hex } from '@metamask/utils';
18-
19-
// This CBOR and the the following test fixtures are all derived from this SRP:
20-
// abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about
21-
const KNOWN_HDKEY_CBOR =
22-
'a503582102eae4b876a8696134b868f88cc2f51f715f2dbedb7446b8e6edf3d4541c4eb67b045820d882718b7a42806803eeb17f7483f20620611adb88fc943c898dc5aba94c281906d90130a20186182cf5183cf500f5021ad32e4508081ad32e45080972696d546f6b656e2d4163636f756e74203031';
23-
24-
const KNOWN_HDKEY: CryptoHDKey = CryptoHDKey.fromCBOR(
25-
Buffer.from(KNOWN_HDKEY_CBOR, 'hex'),
26-
);
27-
28-
const KNOWN_HDKEY_UR = KNOWN_HDKEY.toUREncoder(2000).nextPart();
29-
30-
const KNOWN_CRYPTO_ACCOUNT = new CryptoAccount(Buffer.from('37b5eed4', 'hex'), [
31-
new CryptoOutput([ScriptExpressions.WITNESS_SCRIPT_HASH], KNOWN_HDKEY),
32-
]);
33-
34-
const KNOWN_CRYPTO_ACCOUNT_UR =
35-
KNOWN_CRYPTO_ACCOUNT.toUREncoder(2000).nextPart();
36-
37-
const EXPECTED_ACCOUNTS = [
38-
'0x9858EfFD232B4033E47d90003D41EC34EcaEda94',
39-
'0x6Fac4D18c912343BF86fa7049364Dd4E424Ab9C0',
40-
'0xb6716976A3ebe8D39aCEB04372f22Ff8e6802D7A',
41-
'0xF3f50213C1d2e255e4B2bAD430F8A38EEF8D718E',
42-
'0x51cA8ff9f1C0a99f88E86B8112eA3237F55374cA',
43-
'0xA40cFBFc8534FFC84E20a7d8bBC3729B26a35F6f',
44-
'0xB191a13bfE648B61002F2e2135867015B71816a6',
45-
'0x593814d3309e2dF31D112824F0bb5aa7Cb0D7d47',
46-
'0xB14c391e2bf19E5a26941617ab546FA620A4f163',
47-
'0x4C1C56443AbFe6dD33de31dAaF0a6E929DBc4971',
48-
] as const;
49-
50-
// Coming from an extension installation using `@keystonehq/metamask-airgapped-keyring`
51-
// and with a paired QR-based Device configured with the above known SRP
52-
const SERIALIZED_KEYSTONE_KEYRING: StoredKeyring = {
53-
initialized: true,
54-
accounts: [
55-
'0x9858EfFD232B4033E47d90003D41EC34EcaEda94',
56-
'0x6Fac4D18c912343BF86fa7049364Dd4E424Ab9C0',
57-
'0xb6716976A3ebe8D39aCEB04372f22Ff8e6802D7A',
58-
],
59-
keyringAccount: 'account.standard',
60-
keyringMode: DeviceMode.HD,
61-
name: 'imToken-Account 01',
62-
version: 1,
63-
xfp: '65174ca1',
64-
xpub: 'xpub6DCoCpSuQZB2jawqnGMEPS63ePKWkwWPH4TU45Q7LPXWuNd8TMtVxRrgjtEshuqpK3mdhaWHPFsBngh5GFZaM6si3yZdUsT8ddYM3PwnATt',
65-
hdPath: "m/44'/60'/0'",
66-
childrenPath: '0/*',
67-
indexes: {
68-
'0x9858EfFD232B4033E47d90003D41EC34EcaEda94': 0,
69-
'0x6Fac4D18c912343BF86fa7049364Dd4E424Ab9C0': 1,
70-
'0xb6716976A3ebe8D39aCEB04372f22Ff8e6802D7A': 2,
71-
},
72-
paths: {},
73-
// These last properties are not used by `@metamask/eth-qr-keyring`
74-
currentAccount: 0,
75-
page: 0,
76-
perPage: 5,
77-
};
78-
79-
const HDKEY_SERIALIZED_KEYRING_WITH_NO_ACCOUNTS: SerializedQrKeyringState = {
80-
initialized: true,
81-
name: 'imToken-Account 01',
82-
keyringMode: DeviceMode.HD,
83-
keyringAccount: KNOWN_HDKEY.getNote(),
84-
xfp: KNOWN_HDKEY.getParentFingerprint()?.toString('hex'),
85-
xpub: KNOWN_HDKEY.getBip32Key(),
86-
indexes: {},
87-
hdPath: "m/44'/60'/0'",
88-
childrenPath: '0/*',
89-
};
90-
91-
const HDKEY_SERIALIZED_KEYRING_WITH_ACCOUNTS: SerializedQrKeyringState = {
92-
...HDKEY_SERIALIZED_KEYRING_WITH_NO_ACCOUNTS,
93-
accounts: EXPECTED_ACCOUNTS.slice(0, 3),
94-
indexes: {
95-
[EXPECTED_ACCOUNTS[0]]: 0,
96-
[EXPECTED_ACCOUNTS[1]]: 1,
97-
[EXPECTED_ACCOUNTS[2]]: 2,
98-
},
99-
};
100-
101-
const ACCOUNT_SERIALIZED_KEYRING_WITH_NO_ACCOUNTS: SerializedQrKeyringState = {
102-
initialized: true,
103-
name: 'imToken-Account 01',
104-
keyringMode: DeviceMode.ACCOUNT,
105-
keyringAccount: KNOWN_HDKEY.getNote(),
106-
xfp: '37b5eed4',
107-
paths: {
108-
'0x2043858DA83bCD92Ae342C1bAaD4D5F5B5C328B3': "M/44'/60'/0'",
109-
},
110-
indexes: {},
111-
};
112-
113-
const ACCOUNT_SERIALIZED_KEYRING_WITH_ACCOUNTS: SerializedQrKeyringState = {
114-
...ACCOUNT_SERIALIZED_KEYRING_WITH_NO_ACCOUNTS,
115-
accounts: ['0x2043858DA83bCD92Ae342C1bAaD4D5F5B5C328B3'],
116-
indexes: {
117-
'0x2043858DA83bCD92Ae342C1bAaD4D5F5B5C328B3': 0,
118-
},
119-
};
120-
121-
const TRANSACTION = TransactionFactory.fromTxData({
122-
accessList: [],
123-
chainId: '0x1',
124-
data: '0x',
125-
gasLimit: '0x5208',
126-
maxFeePerGas: '0x2540be400',
127-
maxPriorityFeePerGas: '0x3b9aca00',
128-
nonce: '0x68',
129-
to: '0x0c54fccd2e384b4bb6f2e405bf5cbc15a017aafb',
130-
value: '0x0',
131-
type: 2,
132-
});
133-
134-
const LEGACY_TRANSACTION = TransactionFactory.fromTxData(
135-
{
136-
chainId: '0xaa36a7',
137-
data: '0x',
138-
gasLimit: '0x5208',
139-
gasPrice: '0x2540be400',
140-
nonce: '0x68',
141-
to: '0x0c54fccd2e384b4bb6f2e405bf5cbc15a017aafb',
142-
value: '0x0',
143-
},
144-
{
145-
common: new Common({ chain: 'sepolia' }),
146-
},
147-
);
148-
149-
const TYPED_MESSAGE = {
150-
domain: {
151-
chainId: 1,
152-
name: 'Ether Mail',
153-
verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
154-
version: '1',
155-
salt: new TextEncoder().encode('hello'),
156-
},
157-
message: {
158-
contents: 'Hello, Bob!',
159-
from: {
160-
name: 'Cow',
161-
wallets: [
162-
'0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
163-
'0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF',
164-
],
165-
},
166-
to: [
167-
{
168-
name: 'Bob',
169-
wallets: [
170-
'0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
171-
'0xB0BdaBea57B0BDABeA57b0bdABEA57b0BDabEa57',
172-
'0xB0B0b0b0b0b0B000000000000000000000000000',
173-
],
174-
},
175-
],
176-
},
177-
primaryType: 'Mail' as const,
178-
types: {
179-
EIP712Domain: [
180-
{ name: 'name', type: 'string' },
181-
{ name: 'version', type: 'string' },
182-
{ name: 'chainId', type: 'uint256' },
183-
{ name: 'verifyingContract', type: 'address' },
184-
],
185-
Group: [
186-
{ name: 'name', type: 'string' },
187-
{ name: 'members', type: 'Person[]' },
188-
],
189-
Mail: [
190-
{ name: 'from', type: 'Person' },
191-
{ name: 'to', type: 'Person[]' },
192-
{ name: 'contents', type: 'string' },
193-
],
194-
Person: [
195-
{ name: 'name', type: 'string' },
196-
{ name: 'wallets', type: 'address[]' },
197-
],
198-
},
199-
};
8+
import {
9+
ACCOUNT_SERIALIZED_KEYRING_WITH_ACCOUNTS,
10+
ACCOUNT_SERIALIZED_KEYRING_WITH_NO_ACCOUNTS,
11+
EXPECTED_ACCOUNTS,
12+
HDKEY_SERIALIZED_KEYRING_WITH_ACCOUNTS,
13+
HDKEY_SERIALIZED_KEYRING_WITH_NO_ACCOUNTS,
14+
KNOWN_CRYPTO_ACCOUNT_UR,
15+
KNOWN_HDKEY_CBOR,
16+
KNOWN_HDKEY_UR,
17+
LEGACY_TRANSACTION,
18+
SERIALIZED_KEYSTONE_KEYRING,
19+
TRANSACTION,
20+
TYPED_MESSAGE,
21+
} from '../test/fixtures';
20022

20123
/**
20224
* Get the xpub from a keyring.

0 commit comments

Comments
 (0)