diff --git a/README.md b/README.md index c39979df70e1..7d373f1f68e3 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,8 @@ Run unit tests and the linter with `yarn test`. To run just unit tests, run `yar You can run the linter by itself with `yarn lint`, and you can automatically fix some lint problems with `yarn lint:fix`. You can also run these two commands just on your local changes to save time with `yarn lint:changed` and `yarn lint:changed:fix` respectively. +For Jest debugging guide using Node.js, see [docs/tests/jest.md](docs/tests/jest.md). + ### Running E2E Tests Our e2e test suite can be run on either Firefox or Chrome. diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json index f7efae1ee2dd..d71994b69697 100644 --- a/app/_locales/en/messages.json +++ b/app/_locales/en/messages.json @@ -2668,6 +2668,10 @@ "permissionRevoked": { "message": "Revoked in this update" }, + "permission_accessNamedSnap": { + "message": "Connect to $1.", + "description": "The description for the `wallet_snap_*` permission. $1 is the human-readable name of the Snap." + }, "permission_accessNetwork": { "message": "Access the internet.", "description": "The description of the `endowment:network-access` permission." diff --git a/docs/tests/jest.md b/docs/tests/jest.md new file mode 100644 index 000000000000..c4dc613aa46a --- /dev/null +++ b/docs/tests/jest.md @@ -0,0 +1,66 @@ +# Getting Started + +## Running a Jest test + +```bash +> yarn jest +``` + +## Debugging + +### Debugging Jest in VS Code + +1. Open **VS Code** +2. Open the “Run and Debug” panel (⇧⌘D) +3. Click the “JavaScript Debug Terminal” button to open the Terminal +4. Run Jest using Node + + ```bash + > yarn jest --watch + ``` + +Additional methods and information to debug in VS Code can be found [here](https://jestjs.io/docs/troubleshooting#debugging-in-vs-code) + +### Debugging Jest on Chrome DevTools + +1. Run Jest using Node with the V8 Inspector + + ```bash + > node --inspect ./node_modules/.bin/jest --watch -i + + or + + > node --inspect ./node_modules/.bin/jest + ``` + + **Options:** + + ```jsx + node: + + --inspect=[host:]port + Activate inspector on host:port. Default is 127.0.0.1:9229. + + V8 Inspector integration allows attaching Chrome DevTools and IDEs + to Node.js instances for debugging and profiling. It uses the + Chrome DevTools Protocol. + + jest: + + --watch Watch files for changes and rerun tests + related to changed files. If you want to + re-run all tests when a file has changed, + use the `--watchAll` option. [boolean] + + -i, --runInBand Run all tests serially in the current + process (rather than creating a worker pool + of child processes that run tests). This is + sometimes useful for debugging, but such use + cases are pretty rare. [boolean] + ``` + + +1. Open Chrome DevTools for Node + 1. Open a **Chromium** browser + 2. Go to [chrome://inspect/#devices](chrome://inspect/#devices) + 3. Click “Open dedicated DevTools for Node” link diff --git a/lavamoat/browserify/beta/policy.json b/lavamoat/browserify/beta/policy.json index cd680dc6f393..2d82f59230a3 100644 --- a/lavamoat/browserify/beta/policy.json +++ b/lavamoat/browserify/beta/policy.json @@ -703,15 +703,16 @@ "setTimeout": true }, "packages": { - "@ethersproject/abi": true, "@ethersproject/contracts": true, "@ethersproject/providers": true, + "@metamask/assets-controllers>@metamask/abi-utils": true, + "@metamask/assets-controllers>@metamask/controller-utils": true, "@metamask/assets-controllers>abort-controller": true, "@metamask/assets-controllers>multiformats": true, "@metamask/base-controller": true, "@metamask/contract-metadata": true, - "@metamask/controller-utils": true, "@metamask/metamask-eth-abis": true, + "@metamask/utils": true, "browserify>events": true, "eth-json-rpc-filters>async-mutex": true, "eth-query": true, @@ -721,6 +722,27 @@ "uuid": true } }, + "@metamask/assets-controllers>@metamask/abi-utils": { + "packages": { + "@metamask/utils": true, + "@metamask/utils>superstruct": true + } + }, + "@metamask/assets-controllers>@metamask/controller-utils": { + "globals": { + "console.error": true, + "fetch": true, + "setTimeout": true + }, + "packages": { + "@metamask/controller-utils>isomorphic-fetch": true, + "browserify>buffer": true, + "eslint>fast-deep-equal": true, + "eth-ens-namehash": true, + "ethereumjs-util": true, + "ethjs>ethjs-unit": true + } + }, "@metamask/assets-controllers>abort-controller": { "globals": { "AbortController": true @@ -1204,12 +1226,27 @@ }, "packages": { "@metamask/base-controller": true, - "@metamask/controller-utils": true, "@metamask/controller-utils>isomorphic-fetch": true, + "@metamask/phishing-controller>@metamask/controller-utils": true, "@metamask/phishing-controller>eth-phishing-detect": true, "punycode": true } }, + "@metamask/phishing-controller>@metamask/controller-utils": { + "globals": { + "console.error": true, + "fetch": true, + "setTimeout": true + }, + "packages": { + "@metamask/controller-utils>isomorphic-fetch": true, + "browserify>buffer": true, + "eslint>fast-deep-equal": true, + "eth-ens-namehash": true, + "ethereumjs-util": true, + "ethjs>ethjs-unit": true + } + }, "@metamask/phishing-controller>eth-phishing-detect": { "packages": { "eslint>optionator>fast-levenshtein": true diff --git a/lavamoat/browserify/flask/policy.json b/lavamoat/browserify/flask/policy.json index 1da0ea6fe98a..eeaeaf3d53f8 100644 --- a/lavamoat/browserify/flask/policy.json +++ b/lavamoat/browserify/flask/policy.json @@ -703,15 +703,16 @@ "setTimeout": true }, "packages": { - "@ethersproject/abi": true, "@ethersproject/contracts": true, "@ethersproject/providers": true, + "@metamask/assets-controllers>@metamask/abi-utils": true, + "@metamask/assets-controllers>@metamask/controller-utils": true, "@metamask/assets-controllers>abort-controller": true, "@metamask/assets-controllers>multiformats": true, "@metamask/base-controller": true, "@metamask/contract-metadata": true, - "@metamask/controller-utils": true, "@metamask/metamask-eth-abis": true, + "@metamask/utils": true, "browserify>events": true, "eth-json-rpc-filters>async-mutex": true, "eth-query": true, @@ -721,6 +722,27 @@ "uuid": true } }, + "@metamask/assets-controllers>@metamask/abi-utils": { + "packages": { + "@metamask/utils": true, + "@metamask/utils>superstruct": true + } + }, + "@metamask/assets-controllers>@metamask/controller-utils": { + "globals": { + "console.error": true, + "fetch": true, + "setTimeout": true + }, + "packages": { + "@metamask/controller-utils>isomorphic-fetch": true, + "browserify>buffer": true, + "eslint>fast-deep-equal": true, + "eth-ens-namehash": true, + "ethereumjs-util": true, + "ethjs>ethjs-unit": true + } + }, "@metamask/assets-controllers>abort-controller": { "globals": { "AbortController": true @@ -1216,12 +1238,27 @@ }, "packages": { "@metamask/base-controller": true, - "@metamask/controller-utils": true, "@metamask/controller-utils>isomorphic-fetch": true, + "@metamask/phishing-controller>@metamask/controller-utils": true, "@metamask/phishing-controller>eth-phishing-detect": true, "punycode": true } }, + "@metamask/phishing-controller>@metamask/controller-utils": { + "globals": { + "console.error": true, + "fetch": true, + "setTimeout": true + }, + "packages": { + "@metamask/controller-utils>isomorphic-fetch": true, + "browserify>buffer": true, + "eslint>fast-deep-equal": true, + "eth-ens-namehash": true, + "ethereumjs-util": true, + "ethjs>ethjs-unit": true + } + }, "@metamask/phishing-controller>eth-phishing-detect": { "packages": { "eslint>optionator>fast-levenshtein": true diff --git a/lavamoat/browserify/main/policy.json b/lavamoat/browserify/main/policy.json index cd680dc6f393..2d82f59230a3 100644 --- a/lavamoat/browserify/main/policy.json +++ b/lavamoat/browserify/main/policy.json @@ -703,15 +703,16 @@ "setTimeout": true }, "packages": { - "@ethersproject/abi": true, "@ethersproject/contracts": true, "@ethersproject/providers": true, + "@metamask/assets-controllers>@metamask/abi-utils": true, + "@metamask/assets-controllers>@metamask/controller-utils": true, "@metamask/assets-controllers>abort-controller": true, "@metamask/assets-controllers>multiformats": true, "@metamask/base-controller": true, "@metamask/contract-metadata": true, - "@metamask/controller-utils": true, "@metamask/metamask-eth-abis": true, + "@metamask/utils": true, "browserify>events": true, "eth-json-rpc-filters>async-mutex": true, "eth-query": true, @@ -721,6 +722,27 @@ "uuid": true } }, + "@metamask/assets-controllers>@metamask/abi-utils": { + "packages": { + "@metamask/utils": true, + "@metamask/utils>superstruct": true + } + }, + "@metamask/assets-controllers>@metamask/controller-utils": { + "globals": { + "console.error": true, + "fetch": true, + "setTimeout": true + }, + "packages": { + "@metamask/controller-utils>isomorphic-fetch": true, + "browserify>buffer": true, + "eslint>fast-deep-equal": true, + "eth-ens-namehash": true, + "ethereumjs-util": true, + "ethjs>ethjs-unit": true + } + }, "@metamask/assets-controllers>abort-controller": { "globals": { "AbortController": true @@ -1204,12 +1226,27 @@ }, "packages": { "@metamask/base-controller": true, - "@metamask/controller-utils": true, "@metamask/controller-utils>isomorphic-fetch": true, + "@metamask/phishing-controller>@metamask/controller-utils": true, "@metamask/phishing-controller>eth-phishing-detect": true, "punycode": true } }, + "@metamask/phishing-controller>@metamask/controller-utils": { + "globals": { + "console.error": true, + "fetch": true, + "setTimeout": true + }, + "packages": { + "@metamask/controller-utils>isomorphic-fetch": true, + "browserify>buffer": true, + "eslint>fast-deep-equal": true, + "eth-ens-namehash": true, + "ethereumjs-util": true, + "ethjs>ethjs-unit": true + } + }, "@metamask/phishing-controller>eth-phishing-detect": { "packages": { "eslint>optionator>fast-levenshtein": true diff --git a/package.json b/package.json index 97ce5e233a9a..4ebac80c03ae 100644 --- a/package.json +++ b/package.json @@ -221,7 +221,7 @@ "@metamask/address-book-controller": "^1.0.0", "@metamask/announcement-controller": "^1.0.0", "@metamask/approval-controller": "^1.0.0", - "@metamask/assets-controllers": "^3.0.1", + "@metamask/assets-controllers": "^4.0.1", "@metamask/base-controller": "^1.0.0", "@metamask/contract-metadata": "^2.2.0", "@metamask/controller-utils": "^1.0.0", @@ -238,7 +238,7 @@ "@metamask/notification-controller": "^1.0.0", "@metamask/obs-store": "^5.0.0", "@metamask/permission-controller": "^1.0.0", - "@metamask/phishing-controller": "^1.1.0", + "@metamask/phishing-controller": "^1.1.2", "@metamask/post-message-stream": "^6.0.0", "@metamask/providers": "^10.2.1", "@metamask/rate-limit-controller": "^1.0.0", diff --git a/shared/constants/snaps.ts b/shared/constants/snaps.ts new file mode 100644 index 000000000000..2c0e21a88bf2 --- /dev/null +++ b/shared/constants/snaps.ts @@ -0,0 +1,43 @@ +///: BEGIN:ONLY_INCLUDE_IN(flask) +type SnapsMetadata = { + [snapId: string]: { + name: string; + }; +}; + +// If a Snap ID is present in this object, its metadata is used before the info +// of the snap is fetched. Ideally this information would be fetched from the +// snap registry, but this is a temporary solution. +export const SNAPS_METADATA: SnapsMetadata = { + 'npm:@metamask/test-snap-error': { + name: 'Error Test Snap', + }, + 'npm:@metamask/test-snap-confirm': { + name: 'Confirm Test Snap', + }, + 'npm:@metamask/test-snap-dialog': { + name: 'Dialog Test Snap', + }, + 'npm:@metamask/test-snap-bip44': { + name: 'BIP-44 Test Snap', + }, + 'npm:@metamask/test-snap-managestate': { + name: 'Manage State Test Snap', + }, + 'npm:@metamask/test-snap-notification': { + name: 'Notification Test Snap', + }, + 'npm:@metamask/test-snap-bip32': { + name: 'BIP-32 Test Snap', + }, + 'npm:@metamask/test-snap-insights': { + name: 'Insights Test Snap', + }, + 'npm:@metamask/test-snap-rpc': { + name: 'RPC Test Snap', + }, + 'npm:@metamask/test-snap-cronjob': { + name: 'Cronjob Test Snap', + }, +}; +///: END:ONLY_INCLUDE_IN diff --git a/ui/components/app/flask/snaps-authorship-pill/snaps-authorship-pill.js b/ui/components/app/flask/snaps-authorship-pill/snaps-authorship-pill.js index 4499def2c15d..6a845f314e36 100644 --- a/ui/components/app/flask/snaps-authorship-pill/snaps-authorship-pill.js +++ b/ui/components/app/flask/snaps-authorship-pill/snaps-authorship-pill.js @@ -11,11 +11,12 @@ import { TextColor, } from '../../../../helpers/constants/design-system'; import { useI18nContext } from '../../../../hooks/useI18nContext'; +import { SNAPS_METADATA } from '../../../../../shared/constants/snaps'; const snapIdPrefixes = ['npm:', 'local:']; const SnapsAuthorshipPill = ({ snapId, version, className }) => { - // @todo Use getSnapPrefix from snaps-skunkworks when possible + // @todo Use getSnapPrefix from snaps-monorepo when possible // We're using optional chaining with snapId, because with the current implementation // of snap update in the snap controller, we do not have reference to snapId when an // update request is rejected because the reference comes from the request itself and not subject metadata @@ -30,6 +31,9 @@ const SnapsAuthorshipPill = ({ snapId, version, className }) => { : packageName; const icon = isNPM ? 'fab fa-npm fa-lg' : 'fas fa-code'; const t = useI18nContext(); + + const friendlyName = SNAPS_METADATA[snapId]?.name ?? packageName; + return ( { variant={TypographyVariant.H7} as="span" color={TextColor.textAlternative} - title={packageName} + title={friendlyName} > - {packageName} + {friendlyName} diff --git a/ui/components/app/modals/metametrics-opt-in-modal/__snapshots__/metametrics-opt-in-modal.test.js.snap b/ui/components/app/modals/metametrics-opt-in-modal/__snapshots__/metametrics-opt-in-modal.test.js.snap index fa8d0b9d94e0..199f7c2b73be 100644 --- a/ui/components/app/modals/metametrics-opt-in-modal/__snapshots__/metametrics-opt-in-modal.test.js.snap +++ b/ui/components/app/modals/metametrics-opt-in-modal/__snapshots__/metametrics-opt-in-modal.test.js.snap @@ -310,7 +310,7 @@ exports[`MetaMetrics Opt In should match snapshot 1`] = ` >