Skip to content

Commit 84276de

Browse files
k-g-jgantunesr
andauthored
test: increase test coverage (#51)
## Description PR adds more unit tests for specific flows and error messages with the `keyring.ts` file. There is a minor refactor in the createAccount method to check for duplicate accounts. * Fixes [#254](https://app.zenhub.com/workspaces/metamask-accounts-team-v2-64c91cbeaa9d1c00126621fd/issues/gh/metamask/accounts-planning/254) * See: [#244](https://app.zenhub.com/workspaces/metamask-accounts-team-v2-64c91cbeaa9d1c00126621fd/issues/gh/metamask/accounts-planning/244) ## Pre-requisites - [ ] https://github.com/MetaMask/accounts-planning/issues/308 * [x] MetaMask/eth-snap-keyring#231 * [ ] https://github.com/MetaMask/accounts-planning/issues/307 ## Test Coverage Report ### Summary The test coverage has been updated as part of the efforts to increase the code coverage for the `snap-account-abstraction-keyring` module. The tests were executed with `yarn test:coverage --no-cache`, ensuring that cached results did not influence the outcomes. The coverage for the `keyring.ts` file is now above 95%. - **Test Suites**: 1 passed, 1 total - **Tests**: 35 passed, 35 total ### Coverage Overview ```plaintext ---------------------|---------|----------|---------|---------|------------------------- File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s ---------------------|---------|----------|---------|---------|------------------------- All files | 87.58 | 60.63 | 82.45 | 87.75 | snap | 100 | 100 | 100 | 100 | hardhat.config.ts | 100 | 100 | 100 | 100 | snap/src | 92.34 | 67.74 | 87.5 | 92.26 | keyring.ts | 95.67 | 67.92 | 100 | 95.62 | 195,443-445,547-549,562 logger.ts | 75 | 57.14 | 55.55 | 75 | 64,81-92,112-122 permissions.ts | 100 | 100 | 100 | 100 | stateManagement.ts | 62.5 | 100 | 50 | 62.5 | 18-25 snap/src/constants | 93.75 | 0 | 100 | 93.75 | aa-factories.ts | 100 | 100 | 100 | 100 | chain-ids.ts | 100 | 100 | 100 | 100 | chainConfig.ts | 100 | 100 | 100 | 100 | dummy-values.ts | 88.88 | 0 | 100 | 88.88 | 15 entrypoints.ts | 100 | 100 | 100 | 100 | snap/src/utils | 72 | 42.85 | 68.75 | 72.6 | ecdsa.ts | 100 | 100 | 100 | 100 | util.ts | 43.33 | 0 | 50 | 42.85 | 15-27,37-49,105 validation.ts | 89.47 | 80 | 100 | 89.47 | 49,81-84,88 ---------------------|---------|----------|---------|---------|------------------------- --------- Co-authored-by: Gustavo Antunes <17601467+gantunesr@users.noreply.github.com>
1 parent f404b32 commit 84276de

File tree

10 files changed

+663
-46
lines changed

10 files changed

+663
-46
lines changed

packages/site/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"@emotion/styled": "^11.11.0",
3434
"@metamask/keyring-api": "^3.0.0",
3535
"@metamask/providers": "^14.0.2",
36+
"@metamask/snap-account-abstraction-keyring": "workspace:^",
3637
"@mui/icons-material": "^5.14.0",
3738
"@mui/material": "^5.14.0",
3839
"@types/react-helmet": "^6.1.6",

packages/site/src/pages/index.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import type { KeyringAccount, KeyringRequest } from '@metamask/keyring-api';
22
import { KeyringSnapRpcClient } from '@metamask/keyring-api';
3+
import {
4+
CaipNamespaces,
5+
toCaipChainId,
6+
} from '@metamask/snap-account-abstraction-keyring/src/utils/caip';
37
import Grid from '@mui/material/Grid';
48
import React, { useContext, useEffect, useState } from 'react';
59
import * as uuid from 'uuid';
@@ -99,9 +103,13 @@ const Index = () => {
99103
if (!chainConfig) {
100104
return;
101105
}
106+
const reference = window.ethereum.chainId;
107+
if (!reference) {
108+
throw new Error('No chain ID found');
109+
}
102110
const request: KeyringRequest = {
103111
id: uuid.v4(),
104-
scope: '',
112+
scope: `${toCaipChainId(CaipNamespaces.Eip155, reference)}`,
105113
account: uuid.v4(),
106114
request: {
107115
method: 'snap.internal.setConfig',

packages/snap/jest.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,11 @@ module.exports = {
1010
'contracts',
1111
'artifacts',
1212
],
13+
coverageThreshold: {
14+
'./src/keyring.ts': {
15+
statements: 95,
16+
functions: 95,
17+
lines: 95,
18+
},
19+
},
1320
};

packages/snap/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
"lint:types": "tsc --noEmit",
4141
"serve": "mm-snap serve",
4242
"start": "NODE_ENV='development' mm-snap watch",
43-
"test": "jest --detectOpenHandles"
43+
"test": "jest --detectOpenHandles",
44+
"test:coverage": "jest --detectOpenHandles --coverage"
4445
},
4546
"dependencies": {
4647
"@ethereumjs/tx": "^5.1.0",
@@ -86,6 +87,7 @@
8687
"hardhat": "^2.19.4",
8788
"hardhat-gas-reporter": "^1.0.8",
8889
"jest": "^29.7.0",
90+
"jest-extended": "^4.0.2",
8991
"prettier": "^2.2.1",
9092
"rimraf": "^3.0.2",
9193
"solidity-coverage": "^0.8.1",

packages/snap/snap.manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"url": "git+https://github.com/MetaMask/snap-account-abstraction-keyring.git"
88
},
99
"source": {
10-
"shasum": "WfB+J7Rzl/po7NKMCmFe9KLNUfps/dncIaWtCm/WvWQ=",
10+
"shasum": "yGUjODv2K9nZZ0a2us4NLGJPmV61Rtz0tXoIKOB00cU=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

0 commit comments

Comments
 (0)