Skip to content

Commit 6c0595d

Browse files
committed
feat: add tests to util and mocks
1 parent 9b8a1eb commit 6c0595d

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { EthAccountType } from '@metamask/keyring-api';
2+
3+
import { createMockInternalAccount } from './mocks';
4+
5+
describe('createMockInternalAccount', () => {
6+
it('should create a mock internal account', () => {
7+
const account = createMockInternalAccount();
8+
expect(account).toStrictEqual({
9+
id: expect.any(String),
10+
address: expect.any(String),
11+
type: expect.any(String),
12+
options: expect.any(Object),
13+
methods: expect.any(Array),
14+
metadata: {
15+
name: expect.any(String),
16+
keyring: { type: expect.any(String) },
17+
importTime: expect.any(Number),
18+
lastSelected: expect.any(Number),
19+
snap: undefined,
20+
},
21+
});
22+
});
23+
24+
it('should create a mock internal account with custom values', () => {
25+
const customSnap = {
26+
id: '1',
27+
enabled: true,
28+
name: 'Snap 1',
29+
};
30+
const account = createMockInternalAccount({
31+
id: '1',
32+
address: '0x123',
33+
type: EthAccountType.Erc4337,
34+
name: 'Custom Account',
35+
snap: customSnap,
36+
});
37+
expect(account).toStrictEqual({
38+
id: '1',
39+
address: '0x123',
40+
type: EthAccountType.Erc4337,
41+
options: expect.any(Object),
42+
methods: expect.any(Array),
43+
metadata: {
44+
name: 'Custom Account',
45+
keyring: { type: expect.any(String) },
46+
importTime: expect.any(Number),
47+
lastSelected: expect.any(Number),
48+
snap: customSnap,
49+
},
50+
});
51+
});
52+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { EthAccountType } from '@metamask/keyring-api';
2+
3+
import { createMockInternalAccount } from './tests/mocks';
4+
import { isEVMAccount } from './utils';
5+
6+
describe('isEVMAccount', () => {
7+
it.each([
8+
[EthAccountType.Eoa, true],
9+
[EthAccountType.Erc4337, true],
10+
['bip122', false],
11+
])('%s should return %s', (accountType, expected) => {
12+
expect(
13+
isEVMAccount(
14+
createMockInternalAccount({ type: accountType as EthAccountType }),
15+
),
16+
).toBe(expected);
17+
});
18+
});

0 commit comments

Comments
 (0)