From 0c4175c71c9f8b92da89e1954048e6bfb6647ae8 Mon Sep 17 00:00:00 2001 From: Frederik Bolding Date: Thu, 7 Sep 2023 12:11:29 +0200 Subject: [PATCH 1/4] Remove pump --- packages/snaps-controllers/package.json | 2 -- .../src/services/AbstractExecutionService.ts | 10 +++++++--- .../src/snaps/SnapController.test.ts | 6 +++--- .../snaps-controllers/src/snaps/location/npm.ts | 4 ++-- .../src/test-utils/execution-environment.ts | 4 ++-- .../snaps-controllers/src/test-utils/service.ts | 4 ++-- packages/snaps-execution-environments/package.json | 1 - .../src/iframe/IFrameSnapExecutor.ts | 4 ++-- .../src/node-process/ChildProcessSnapExecutor.ts | 4 ++-- .../src/node-thread/ThreadSnapExecutor.ts | 4 ++-- .../webworker/executor/WebWorkerSnapExecutor.ts | 4 ++-- packages/snaps-simulator/package.json | 2 -- .../src/features/simulation/sagas.ts | 8 +++----- yarn.lock | 14 -------------- 14 files changed, 27 insertions(+), 44 deletions(-) diff --git a/packages/snaps-controllers/package.json b/packages/snaps-controllers/package.json index b43834355c..50ca6fddcf 100644 --- a/packages/snaps-controllers/package.json +++ b/packages/snaps-controllers/package.json @@ -61,7 +61,6 @@ "json-rpc-engine": "^6.1.0", "json-rpc-middleware-stream": "^4.2.0", "nanoid": "^3.1.31", - "pump": "^3.0.0", "readable-web-to-node-stream": "^3.0.2", "tar-stream": "^2.2.0" }, @@ -84,7 +83,6 @@ "@types/jest": "^27.5.1", "@types/mocha": "^10.0.1", "@types/node": "18.14.2", - "@types/pump": "^1.1.1", "@types/readable-stream": "^2.3.15", "@types/tar-stream": "^2.2.2", "@typescript-eslint/eslint-plugin": "^5.42.1", diff --git a/packages/snaps-controllers/src/services/AbstractExecutionService.ts b/packages/snaps-controllers/src/services/AbstractExecutionService.ts index 17456797c2..8deb206187 100644 --- a/packages/snaps-controllers/src/services/AbstractExecutionService.ts +++ b/packages/snaps-controllers/src/services/AbstractExecutionService.ts @@ -12,7 +12,7 @@ import type { import { JsonRpcEngine } from 'json-rpc-engine'; import { createStreamMiddleware } from 'json-rpc-middleware-stream'; import { nanoid } from 'nanoid'; -import pump from 'pump'; +import { pipeline } from 'stream'; import type { Duplex } from 'stream'; import { log } from '../logging'; @@ -182,7 +182,11 @@ export abstract class AbstractExecutionService const jsonRpcConnection = createStreamMiddleware(); - pump(jsonRpcConnection.stream, streams.command, jsonRpcConnection.stream); + pipeline( + jsonRpcConnection.stream, + streams.command, + jsonRpcConnection.stream, + ); rpcEngine.push(jsonRpcConnection.middleware); @@ -448,7 +452,7 @@ export function setupMultiplex( streamName: string, ): ObjectMultiplex { const mux = new ObjectMultiplex(); - pump( + pipeline( connectionStream, // Typecast: stream type mismatch mux as unknown as Duplex, diff --git a/packages/snaps-controllers/src/snaps/SnapController.test.ts b/packages/snaps-controllers/src/snaps/SnapController.test.ts index ae9632bf60..cd3fb26c7c 100644 --- a/packages/snaps-controllers/src/snaps/SnapController.test.ts +++ b/packages/snaps-controllers/src/snaps/SnapController.test.ts @@ -35,7 +35,7 @@ import { ethErrors } from 'eth-rpc-errors'; import fetchMock from 'jest-fetch-mock'; import { createAsyncMiddleware, JsonRpcEngine } from 'json-rpc-engine'; import { createEngineStream } from 'json-rpc-middleware-stream'; -import pump from 'pump'; +import { pipeline } from 'stream'; import type { Duplex } from 'stream'; import type { NodeThreadExecutionService } from '../services'; @@ -1102,7 +1102,7 @@ describe('SnapController', () => { }); engine.push(middleware); const providerStream = createEngineStream({ engine }); - pump(stream, providerStream, stream); + pipeline(stream, providerStream, stream); }); await snapController.startSnap(snap.id); @@ -1183,7 +1183,7 @@ describe('SnapController', () => { }); engine.push(middleware); const providerStream = createEngineStream({ engine }); - pump(stream, providerStream, stream); + pipeline(stream, providerStream, stream); }); await snapController.startSnap(snap.id); diff --git a/packages/snaps-controllers/src/snaps/location/npm.ts b/packages/snaps-controllers/src/snaps/location/npm.ts index 4f82fa3b98..2fe0b483ed 100644 --- a/packages/snaps-controllers/src/snaps/location/npm.ts +++ b/packages/snaps-controllers/src/snaps/location/npm.ts @@ -18,8 +18,8 @@ import { } from '@metamask/utils'; import concat from 'concat-stream'; import createGunzipStream from 'gunzip-maybe'; -import pump from 'pump'; import { ReadableWebToNodeStream } from 'readable-web-to-node-stream'; +import { pipeline } from 'stream'; import type { Readable, Writable } from 'stream'; import { extract as tarExtract } from 'tar-stream'; @@ -182,7 +182,7 @@ export class NpmLocation implements SnapLocation { // We would need to replace tar-stream package because it requires immediate consumption of streams. await new Promise((resolve, reject) => { this.files = new Map(); - pump( + pipeline( getNodeStream(tarballResponse), // The "gz" in "tgz" stands for "gzip". The tarball needs to be decompressed // before we can actually grab any files from it. diff --git a/packages/snaps-controllers/src/test-utils/execution-environment.ts b/packages/snaps-controllers/src/test-utils/execution-environment.ts index 33cec2b79a..5870fd2918 100644 --- a/packages/snaps-controllers/src/test-utils/execution-environment.ts +++ b/packages/snaps-controllers/src/test-utils/execution-environment.ts @@ -2,7 +2,7 @@ import type { SnapRpcHookArgs } from '@metamask/snaps-utils'; import type { MockControllerMessenger } from '@metamask/snaps-utils/test-utils'; import { JsonRpcEngine } from 'json-rpc-engine'; import { createEngineStream } from 'json-rpc-middleware-stream'; -import pump from 'pump'; +import { pipeline } from 'stream'; import type { ExecutionService, @@ -58,7 +58,7 @@ export const getNodeEES = (messenger: ReturnType) => return next(); }); const providerStream = createEngineStream({ engine }); - pump(stream, providerStream, stream); + pipeline(stream, providerStream, stream); }), }); diff --git a/packages/snaps-controllers/src/test-utils/service.ts b/packages/snaps-controllers/src/test-utils/service.ts index 2abb7146cb..ab763325c9 100644 --- a/packages/snaps-controllers/src/test-utils/service.ts +++ b/packages/snaps-controllers/src/test-utils/service.ts @@ -1,7 +1,7 @@ import { ControllerMessenger } from '@metamask/base-controller'; import { JsonRpcEngine } from 'json-rpc-engine'; import { createEngineStream } from 'json-rpc-middleware-stream'; -import pump from 'pump'; +import { pipeline } from 'stream'; import type { Duplex } from 'stream'; import type { ErrorMessageEvent } from '../services'; @@ -56,7 +56,7 @@ export const createService = < return next(); }); const providerStream = createEngineStream({ engine }); - pump(stream, providerStream, stream); + pipeline(stream, providerStream, stream); }, ...options, }); diff --git a/packages/snaps-execution-environments/package.json b/packages/snaps-execution-environments/package.json index 7fde93898d..81f2d68c92 100644 --- a/packages/snaps-execution-environments/package.json +++ b/packages/snaps-execution-environments/package.json @@ -54,7 +54,6 @@ "eth-rpc-errors": "^4.0.3", "json-rpc-engine": "^6.1.0", "nanoid": "^3.1.31", - "pump": "^3.0.0", "superstruct": "^1.0.3" }, "devDependencies": { diff --git a/packages/snaps-execution-environments/src/iframe/IFrameSnapExecutor.ts b/packages/snaps-execution-environments/src/iframe/IFrameSnapExecutor.ts index 9154502d9d..453e348d57 100644 --- a/packages/snaps-execution-environments/src/iframe/IFrameSnapExecutor.ts +++ b/packages/snaps-execution-environments/src/iframe/IFrameSnapExecutor.ts @@ -2,7 +2,7 @@ import ObjectMultiplex from '@metamask/object-multiplex'; import type { BasePostMessageStream } from '@metamask/post-message-stream'; import { WindowPostMessageStream } from '@metamask/post-message-stream'; import { logError, SNAP_STREAM_NAMES } from '@metamask/snaps-utils'; -import pump from 'pump'; +import { pipeline } from 'stream'; import { BaseSnapExecutor } from '../common/BaseSnapExecutor'; import { log } from '../logging'; @@ -27,7 +27,7 @@ export class IFrameSnapExecutor extends BaseSnapExecutor { log('Worker: Connecting to parent.'); const mux = new ObjectMultiplex(); - pump(stream, mux, stream, (error) => { + pipeline(stream, mux, stream, (error) => { if (error) { logError(`Parent stream failure, closing worker.`, error); } diff --git a/packages/snaps-execution-environments/src/node-process/ChildProcessSnapExecutor.ts b/packages/snaps-execution-environments/src/node-process/ChildProcessSnapExecutor.ts index c51a717679..dfb8f9e97c 100644 --- a/packages/snaps-execution-environments/src/node-process/ChildProcessSnapExecutor.ts +++ b/packages/snaps-execution-environments/src/node-process/ChildProcessSnapExecutor.ts @@ -1,7 +1,7 @@ import ObjectMultiplex from '@metamask/object-multiplex'; import { ProcessMessageStream } from '@metamask/post-message-stream'; import { logError, SNAP_STREAM_NAMES } from '@metamask/snaps-utils'; -import pump from 'pump'; +import { pipeline } from 'stream'; import { BaseSnapExecutor } from '../common/BaseSnapExecutor'; import { log } from '../logging'; @@ -12,7 +12,7 @@ export class ChildProcessSnapExecutor extends BaseSnapExecutor { const parentStream = new ProcessMessageStream(); const mux = new ObjectMultiplex(); - pump(parentStream, mux as any, parentStream, (error) => { + pipeline(parentStream, mux as any, parentStream, (error) => { if (error) { logError(`Parent stream failure, closing worker.`, error); } diff --git a/packages/snaps-execution-environments/src/node-thread/ThreadSnapExecutor.ts b/packages/snaps-execution-environments/src/node-thread/ThreadSnapExecutor.ts index e7c5c12f6e..51770438ed 100644 --- a/packages/snaps-execution-environments/src/node-thread/ThreadSnapExecutor.ts +++ b/packages/snaps-execution-environments/src/node-thread/ThreadSnapExecutor.ts @@ -1,7 +1,7 @@ import ObjectMultiplex from '@metamask/object-multiplex'; import { ThreadMessageStream } from '@metamask/post-message-stream'; import { logError, SNAP_STREAM_NAMES } from '@metamask/snaps-utils'; -import pump from 'pump'; +import { pipeline } from 'stream'; import { BaseSnapExecutor } from '../common/BaseSnapExecutor'; import { log } from '../logging'; @@ -12,7 +12,7 @@ export class ThreadSnapExecutor extends BaseSnapExecutor { const parentStream = new ThreadMessageStream(); const mux = new ObjectMultiplex(); - pump(parentStream, mux as any, parentStream, (error) => { + pipeline(parentStream, mux as any, parentStream, (error) => { if (error) { logError(`Parent stream failure, closing worker.`, error); } diff --git a/packages/snaps-execution-environments/src/webworker/executor/WebWorkerSnapExecutor.ts b/packages/snaps-execution-environments/src/webworker/executor/WebWorkerSnapExecutor.ts index edaedd73bf..66252966a9 100644 --- a/packages/snaps-execution-environments/src/webworker/executor/WebWorkerSnapExecutor.ts +++ b/packages/snaps-execution-environments/src/webworker/executor/WebWorkerSnapExecutor.ts @@ -2,7 +2,7 @@ import ObjectMultiplex from '@metamask/object-multiplex'; import type { BasePostMessageStream } from '@metamask/post-message-stream'; import { WebWorkerPostMessageStream } from '@metamask/post-message-stream'; import { logError, SNAP_STREAM_NAMES } from '@metamask/snaps-utils'; -import pump from 'pump'; +import { pipeline } from 'stream'; import { BaseSnapExecutor } from '../../common/BaseSnapExecutor'; import { log } from '../../logging'; @@ -22,7 +22,7 @@ export class WebWorkerSnapExecutor extends BaseSnapExecutor { log('Worker: Connecting to parent.'); const mux = new ObjectMultiplex(); - pump(stream, mux, stream, (error) => { + pipeline(stream, mux, stream, (error) => { if (error) { logError(`Parent stream failure, closing worker.`, error); } diff --git a/packages/snaps-simulator/package.json b/packages/snaps-simulator/package.json index 6034497320..16ba70dcda 100644 --- a/packages/snaps-simulator/package.json +++ b/packages/snaps-simulator/package.json @@ -72,7 +72,6 @@ "json-rpc-engine": "^6.1.0", "json-rpc-middleware-stream": "^4.2.0", "monaco-editor": "^0.38.0", - "pump": "^3.0.0", "react": "^18.2.0", "react-dnd": "^16.0.1", "react-dom": "^18.2.0", @@ -100,7 +99,6 @@ "@types/express": "^4.17.17", "@types/jest": "^27.5.1", "@types/node": "18.14.2", - "@types/pump": "^1.1.1", "@types/react": "^18.2.5", "@types/react-dom": "^18.2.3", "@types/webpack-env": "^1.18.1", diff --git a/packages/snaps-simulator/src/features/simulation/sagas.ts b/packages/snaps-simulator/src/features/simulation/sagas.ts index e68b9c4b24..5c03b907f0 100644 --- a/packages/snaps-simulator/src/features/simulation/sagas.ts +++ b/packages/snaps-simulator/src/features/simulation/sagas.ts @@ -29,9 +29,9 @@ import { getSafeJson } from '@metamask/utils'; import type { PayloadAction } from '@reduxjs/toolkit'; import { JsonRpcEngine } from 'json-rpc-engine'; import { createEngineStream } from 'json-rpc-middleware-stream'; -import pump from 'pump'; import type { SagaIterator } from 'redux-saga'; import { all, call, put, select, takeLatest } from 'redux-saga/effects'; +import { pipeline } from 'stream'; import { runSaga } from '../../store/middleware'; import { getSnapId, getSrp, setSnapId } from '../configuration'; @@ -168,11 +168,9 @@ export function* initSaga({ payload }: PayloadAction) { }), setupSnapProvider: (_snapId, rpcStream) => { const mux = setupMultiplex(rpcStream, 'snapStream'); - const stream = mux.createStream( - 'metamask-provider', - ) as unknown as pump.Stream; + const stream = mux.createStream('metamask-provider'); const providerStream = createEngineStream({ engine }); - pump(stream, providerStream, stream); + pipeline(stream, providerStream, stream); }, }); diff --git a/yarn.lock b/yarn.lock index d1b053653f..58171eeea8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5057,7 +5057,6 @@ __metadata: "@types/jest": ^27.5.1 "@types/mocha": ^10.0.1 "@types/node": 18.14.2 - "@types/pump": ^1.1.1 "@types/readable-stream": ^2.3.15 "@types/tar-stream": ^2.2.2 "@typescript-eslint/eslint-plugin": ^5.42.1 @@ -5096,7 +5095,6 @@ __metadata: nanoid: ^3.1.31 prettier: ^2.7.1 prettier-plugin-packagejson: ^2.2.11 - pump: ^3.0.0 readable-web-to-node-stream: ^3.0.2 rimraf: ^4.1.2 tar-stream: ^2.2.0 @@ -5176,7 +5174,6 @@ __metadata: nanoid: ^3.1.31 prettier: ^2.7.1 prettier-plugin-packagejson: ^2.2.11 - pump: ^3.0.0 rimraf: ^4.1.2 serve-handler: ^6.1.5 ses: ^0.18.7 @@ -5333,7 +5330,6 @@ __metadata: "@types/express": ^4.17.17 "@types/jest": ^27.5.1 "@types/node": 18.14.2 - "@types/pump": ^1.1.1 "@types/react": ^18.2.5 "@types/react-dom": ^18.2.3 "@types/webpack-env": ^1.18.1 @@ -5373,7 +5369,6 @@ __metadata: prettier: ^2.7.1 prettier-plugin-packagejson: ^2.2.11 process: ^0.11.10 - pump: ^3.0.0 react: ^18.2.0 react-dnd: ^16.0.1 react-dom: ^18.2.0 @@ -7251,15 +7246,6 @@ __metadata: languageName: node linkType: hard -"@types/pump@npm:^1.1.1": - version: 1.1.1 - resolution: "@types/pump@npm:1.1.1" - dependencies: - "@types/node": "*" - checksum: dd4a1485f2f6052cacb71a94b48d9f360e07a2fc3fac03782ae4caa9856e6df7017ee89515d70ecefcfe281553311cde4a3748219c9fcd757fdb77f3a47e0f29 - languageName: node - linkType: hard - "@types/qs@npm:*": version: 6.9.7 resolution: "@types/qs@npm:6.9.7" From 081948bfbde0a4fd730fc16c8285aa207d5f5ecc Mon Sep 17 00:00:00 2001 From: Frederik Bolding Date: Thu, 7 Sep 2023 12:25:27 +0200 Subject: [PATCH 2/4] Update LavaMoat policies --- .../lavamoat/browserify/iframe/policy.json | 48 +++++++------- .../browserify/node-process/policy.json | 62 +++++++++---------- .../browserify/node-thread/policy.json | 62 +++++++++---------- .../browserify/worker-executor/policy.json | 48 +++++++------- .../lavamoat/build-system/policy.json | 38 ++++++------ 5 files changed, 129 insertions(+), 129 deletions(-) diff --git a/packages/snaps-execution-environments/lavamoat/browserify/iframe/policy.json b/packages/snaps-execution-environments/lavamoat/browserify/iframe/policy.json index c5df52a5eb..4aaa689683 100644 --- a/packages/snaps-execution-environments/lavamoat/browserify/iframe/policy.json +++ b/packages/snaps-execution-environments/lavamoat/browserify/iframe/policy.json @@ -16,9 +16,20 @@ "console.warn": true }, "packages": { - "@metamask/object-multiplex>readable-stream": true, - "pump>end-of-stream": true, - "pump>once": true + "@metamask/object-multiplex>end-of-stream": true, + "@metamask/object-multiplex>once": true, + "@metamask/object-multiplex>readable-stream": true + } + }, + "@metamask/object-multiplex>end-of-stream": { + "packages": { + "@metamask/object-multiplex>once": true, + "browserify>process": true + } + }, + "@metamask/object-multiplex>once": { + "packages": { + "@metamask/object-multiplex>once>wrappy": true } }, "@metamask/object-multiplex>readable-stream": { @@ -125,10 +136,10 @@ "@metamask/providers>extension-port-stream": true, "@metamask/providers>is-stream": true, "@metamask/providers>json-rpc-middleware-stream": true, + "@metamask/providers>pump": true, "eslint>fast-deep-equal": true, "eth-rpc-errors": true, - "json-rpc-engine": true, - "pump": true + "json-rpc-engine": true } }, "@metamask/providers>@metamask/safe-event-emitter": { @@ -189,6 +200,14 @@ "@metamask/providers>json-rpc-middleware-stream>readable-stream>safe-buffer": true } }, + "@metamask/providers>pump": { + "packages": { + "@metamask/object-multiplex>end-of-stream": true, + "@metamask/object-multiplex>once": true, + "browserify>browser-resolve": true, + "browserify>process": true + } + }, "@metamask/utils": { "globals": { "TextDecoder": true, @@ -357,25 +376,6 @@ "browserify>events": true } }, - "pump": { - "packages": { - "browserify>browser-resolve": true, - "browserify>process": true, - "pump>end-of-stream": true, - "pump>once": true - } - }, - "pump>end-of-stream": { - "packages": { - "browserify>process": true, - "pump>once": true - } - }, - "pump>once": { - "packages": { - "pump>once>wrappy": true - } - }, "superstruct": { "globals": { "console.warn": true, diff --git a/packages/snaps-execution-environments/lavamoat/browserify/node-process/policy.json b/packages/snaps-execution-environments/lavamoat/browserify/node-process/policy.json index c39cce0fe5..98a0e7db4d 100644 --- a/packages/snaps-execution-environments/lavamoat/browserify/node-process/policy.json +++ b/packages/snaps-execution-environments/lavamoat/browserify/node-process/policy.json @@ -5,9 +5,22 @@ "console.warn": true }, "packages": { - "@metamask/object-multiplex>readable-stream": true, - "pump>end-of-stream": true, - "pump>once": true + "@metamask/object-multiplex>end-of-stream": true, + "@metamask/object-multiplex>once": true, + "@metamask/object-multiplex>readable-stream": true + } + }, + "@metamask/object-multiplex>end-of-stream": { + "globals": { + "process.nextTick": true + }, + "packages": { + "@metamask/object-multiplex>once": true + } + }, + "@metamask/object-multiplex>once": { + "packages": { + "@metamask/object-multiplex>once>wrappy": true } }, "@metamask/object-multiplex>readable-stream": { @@ -157,10 +170,10 @@ "@metamask/providers>extension-port-stream": true, "@metamask/providers>is-stream": true, "@metamask/providers>json-rpc-middleware-stream": true, + "@metamask/providers>pump": true, "eslint>fast-deep-equal": true, "eth-rpc-errors": true, - "json-rpc-engine": true, - "pump": true + "json-rpc-engine": true } }, "@metamask/providers>@metamask/safe-event-emitter": { @@ -242,6 +255,19 @@ "@metamask/providers>json-rpc-middleware-stream>readable-stream>safe-buffer": true } }, + "@metamask/providers>pump": { + "builtin": { + "fs": true + }, + "globals": { + "process.version": true + }, + "packages": { + "@metamask/object-multiplex>end-of-stream": true, + "@metamask/object-multiplex>once": true, + "fs": true + } + }, "@metamask/utils": { "builtin": { "buffer.Buffer": true @@ -405,32 +431,6 @@ "events": true } }, - "pump": { - "builtin": { - "fs": true - }, - "globals": { - "process.version": true - }, - "packages": { - "fs": true, - "pump>end-of-stream": true, - "pump>once": true - } - }, - "pump>end-of-stream": { - "globals": { - "process.nextTick": true - }, - "packages": { - "pump>once": true - } - }, - "pump>once": { - "packages": { - "pump>once>wrappy": true - } - }, "superstruct": { "globals": { "console.warn": true, diff --git a/packages/snaps-execution-environments/lavamoat/browserify/node-thread/policy.json b/packages/snaps-execution-environments/lavamoat/browserify/node-thread/policy.json index c39cce0fe5..98a0e7db4d 100644 --- a/packages/snaps-execution-environments/lavamoat/browserify/node-thread/policy.json +++ b/packages/snaps-execution-environments/lavamoat/browserify/node-thread/policy.json @@ -5,9 +5,22 @@ "console.warn": true }, "packages": { - "@metamask/object-multiplex>readable-stream": true, - "pump>end-of-stream": true, - "pump>once": true + "@metamask/object-multiplex>end-of-stream": true, + "@metamask/object-multiplex>once": true, + "@metamask/object-multiplex>readable-stream": true + } + }, + "@metamask/object-multiplex>end-of-stream": { + "globals": { + "process.nextTick": true + }, + "packages": { + "@metamask/object-multiplex>once": true + } + }, + "@metamask/object-multiplex>once": { + "packages": { + "@metamask/object-multiplex>once>wrappy": true } }, "@metamask/object-multiplex>readable-stream": { @@ -157,10 +170,10 @@ "@metamask/providers>extension-port-stream": true, "@metamask/providers>is-stream": true, "@metamask/providers>json-rpc-middleware-stream": true, + "@metamask/providers>pump": true, "eslint>fast-deep-equal": true, "eth-rpc-errors": true, - "json-rpc-engine": true, - "pump": true + "json-rpc-engine": true } }, "@metamask/providers>@metamask/safe-event-emitter": { @@ -242,6 +255,19 @@ "@metamask/providers>json-rpc-middleware-stream>readable-stream>safe-buffer": true } }, + "@metamask/providers>pump": { + "builtin": { + "fs": true + }, + "globals": { + "process.version": true + }, + "packages": { + "@metamask/object-multiplex>end-of-stream": true, + "@metamask/object-multiplex>once": true, + "fs": true + } + }, "@metamask/utils": { "builtin": { "buffer.Buffer": true @@ -405,32 +431,6 @@ "events": true } }, - "pump": { - "builtin": { - "fs": true - }, - "globals": { - "process.version": true - }, - "packages": { - "fs": true, - "pump>end-of-stream": true, - "pump>once": true - } - }, - "pump>end-of-stream": { - "globals": { - "process.nextTick": true - }, - "packages": { - "pump>once": true - } - }, - "pump>once": { - "packages": { - "pump>once>wrappy": true - } - }, "superstruct": { "globals": { "console.warn": true, diff --git a/packages/snaps-execution-environments/lavamoat/browserify/worker-executor/policy.json b/packages/snaps-execution-environments/lavamoat/browserify/worker-executor/policy.json index c5df52a5eb..4aaa689683 100644 --- a/packages/snaps-execution-environments/lavamoat/browserify/worker-executor/policy.json +++ b/packages/snaps-execution-environments/lavamoat/browserify/worker-executor/policy.json @@ -16,9 +16,20 @@ "console.warn": true }, "packages": { - "@metamask/object-multiplex>readable-stream": true, - "pump>end-of-stream": true, - "pump>once": true + "@metamask/object-multiplex>end-of-stream": true, + "@metamask/object-multiplex>once": true, + "@metamask/object-multiplex>readable-stream": true + } + }, + "@metamask/object-multiplex>end-of-stream": { + "packages": { + "@metamask/object-multiplex>once": true, + "browserify>process": true + } + }, + "@metamask/object-multiplex>once": { + "packages": { + "@metamask/object-multiplex>once>wrappy": true } }, "@metamask/object-multiplex>readable-stream": { @@ -125,10 +136,10 @@ "@metamask/providers>extension-port-stream": true, "@metamask/providers>is-stream": true, "@metamask/providers>json-rpc-middleware-stream": true, + "@metamask/providers>pump": true, "eslint>fast-deep-equal": true, "eth-rpc-errors": true, - "json-rpc-engine": true, - "pump": true + "json-rpc-engine": true } }, "@metamask/providers>@metamask/safe-event-emitter": { @@ -189,6 +200,14 @@ "@metamask/providers>json-rpc-middleware-stream>readable-stream>safe-buffer": true } }, + "@metamask/providers>pump": { + "packages": { + "@metamask/object-multiplex>end-of-stream": true, + "@metamask/object-multiplex>once": true, + "browserify>browser-resolve": true, + "browserify>process": true + } + }, "@metamask/utils": { "globals": { "TextDecoder": true, @@ -357,25 +376,6 @@ "browserify>events": true } }, - "pump": { - "packages": { - "browserify>browser-resolve": true, - "browserify>process": true, - "pump>end-of-stream": true, - "pump>once": true - } - }, - "pump>end-of-stream": { - "packages": { - "browserify>process": true, - "pump>once": true - } - }, - "pump>once": { - "packages": { - "pump>once>wrappy": true - } - }, "superstruct": { "globals": { "console.warn": true, diff --git a/packages/snaps-execution-environments/lavamoat/build-system/policy.json b/packages/snaps-execution-environments/lavamoat/build-system/policy.json index b1e6ce78ba..4ac9094618 100644 --- a/packages/snaps-execution-environments/lavamoat/build-system/policy.json +++ b/packages/snaps-execution-environments/lavamoat/build-system/policy.json @@ -988,6 +988,19 @@ "@lavamoat/lavapack>readable-stream": true } }, + "@metamask/object-multiplex>end-of-stream": { + "globals": { + "process.nextTick": true + }, + "packages": { + "@metamask/object-multiplex>once": true + } + }, + "@metamask/object-multiplex>once": { + "packages": { + "@metamask/object-multiplex>once>wrappy": true + } + }, "@wdio/mocha-framework>mocha>supports-color": { "builtin": { "os.release": true, @@ -1279,12 +1292,12 @@ "process.platform": true }, "packages": { + "@metamask/object-multiplex>once": true, "browserify>glob>fs.realpath": true, "browserify>glob>inflight": true, "browserify>glob>minimatch": true, "browserify>glob>path-is-absolute": true, - "browserify>inherits": true, - "pump>once": true + "browserify>inherits": true } }, "browserify>glob>fs.realpath": { @@ -1317,8 +1330,8 @@ "process.nextTick": true }, "packages": { - "pump>once": true, - "pump>once>wrappy": true + "@metamask/object-multiplex>once": true, + "@metamask/object-multiplex>once>wrappy": true } }, "browserify>glob>minimatch": { @@ -1975,9 +1988,9 @@ }, "packages": { "@lavamoat/lavapack>readable-stream": true, + "@metamask/object-multiplex>end-of-stream": true, "browserify>inherits": true, - "lavamoat-browserify>duplexify>stream-shift": true, - "pump>end-of-stream": true + "lavamoat-browserify>duplexify>stream-shift": true } }, "lavamoat-browserify>through2": { @@ -2202,19 +2215,6 @@ "depcheck>@babel/traverse": true } }, - "pump>end-of-stream": { - "globals": { - "process.nextTick": true - }, - "packages": { - "pump>once": true - } - }, - "pump>once": { - "packages": { - "pump>once>wrappy": true - } - }, "terser": { "globals": { "Buffer": true, From a9b8b170b7be6856ef976a8808657019e1ced807 Mon Sep 17 00:00:00 2001 From: Frederik Bolding Date: Thu, 7 Sep 2023 13:41:04 +0200 Subject: [PATCH 3/4] Fix missing params --- packages/snaps-controllers/coverage.json | 8 ++++---- .../src/services/AbstractExecutionService.ts | 5 +++++ .../src/snaps/SnapController.test.ts | 13 +++++++++++-- .../src/test-utils/execution-environment.ts | 8 ++++++-- .../snaps-controllers/src/test-utils/service.ts | 7 ++++++- .../src/features/simulation/sagas.ts | 6 +++++- 6 files changed, 37 insertions(+), 10 deletions(-) diff --git a/packages/snaps-controllers/coverage.json b/packages/snaps-controllers/coverage.json index a49d0e5531..23473f6b61 100644 --- a/packages/snaps-controllers/coverage.json +++ b/packages/snaps-controllers/coverage.json @@ -1,6 +1,6 @@ { - "branches": 88.95, - "functions": 95.69, - "lines": 96.9, - "statements": 96.56 + "branches": 88.7, + "functions": 95, + "lines": 96.7, + "statements": 96.35 } diff --git a/packages/snaps-controllers/src/services/AbstractExecutionService.ts b/packages/snaps-controllers/src/services/AbstractExecutionService.ts index 8deb206187..507f492d9d 100644 --- a/packages/snaps-controllers/src/services/AbstractExecutionService.ts +++ b/packages/snaps-controllers/src/services/AbstractExecutionService.ts @@ -186,6 +186,11 @@ export abstract class AbstractExecutionService jsonRpcConnection.stream, streams.command, jsonRpcConnection.stream, + (error) => { + if (error) { + logError(`Command stream failure.`, error); + } + }, ); rpcEngine.push(jsonRpcConnection.middleware); diff --git a/packages/snaps-controllers/src/snaps/SnapController.test.ts b/packages/snaps-controllers/src/snaps/SnapController.test.ts index cd3fb26c7c..3edc2c9843 100644 --- a/packages/snaps-controllers/src/snaps/SnapController.test.ts +++ b/packages/snaps-controllers/src/snaps/SnapController.test.ts @@ -11,6 +11,7 @@ import { DEFAULT_REQUESTED_SNAP_VERSION, getSnapChecksum, HandlerType, + logError, SnapCaveatType, SnapStatus, VirtualFile, @@ -1102,7 +1103,11 @@ describe('SnapController', () => { }); engine.push(middleware); const providerStream = createEngineStream({ engine }); - pipeline(stream, providerStream, stream); + pipeline(stream, providerStream, stream, (error) => { + if (error) { + logError(`Provider stream failure.`, error); + } + }); }); await snapController.startSnap(snap.id); @@ -1183,7 +1188,11 @@ describe('SnapController', () => { }); engine.push(middleware); const providerStream = createEngineStream({ engine }); - pipeline(stream, providerStream, stream); + pipeline(stream, providerStream, stream, (error) => { + if (error) { + logError(`Provider stream failure.`, error); + } + }); }); await snapController.startSnap(snap.id); diff --git a/packages/snaps-controllers/src/test-utils/execution-environment.ts b/packages/snaps-controllers/src/test-utils/execution-environment.ts index 5870fd2918..6cb2842c3b 100644 --- a/packages/snaps-controllers/src/test-utils/execution-environment.ts +++ b/packages/snaps-controllers/src/test-utils/execution-environment.ts @@ -1,4 +1,4 @@ -import type { SnapRpcHookArgs } from '@metamask/snaps-utils'; +import { logError, type SnapRpcHookArgs } from '@metamask/snaps-utils'; import type { MockControllerMessenger } from '@metamask/snaps-utils/test-utils'; import { JsonRpcEngine } from 'json-rpc-engine'; import { createEngineStream } from 'json-rpc-middleware-stream'; @@ -58,7 +58,11 @@ export const getNodeEES = (messenger: ReturnType) => return next(); }); const providerStream = createEngineStream({ engine }); - pipeline(stream, providerStream, stream); + pipeline(stream, providerStream, stream, (error) => { + if (error) { + logError(`Provider stream failure.`, error); + } + }); }), }); diff --git a/packages/snaps-controllers/src/test-utils/service.ts b/packages/snaps-controllers/src/test-utils/service.ts index ab763325c9..caf144fb7a 100644 --- a/packages/snaps-controllers/src/test-utils/service.ts +++ b/packages/snaps-controllers/src/test-utils/service.ts @@ -1,4 +1,5 @@ import { ControllerMessenger } from '@metamask/base-controller'; +import { logError } from '@metamask/snaps-utils'; import { JsonRpcEngine } from 'json-rpc-engine'; import { createEngineStream } from 'json-rpc-middleware-stream'; import { pipeline } from 'stream'; @@ -56,7 +57,11 @@ export const createService = < return next(); }); const providerStream = createEngineStream({ engine }); - pipeline(stream, providerStream, stream); + pipeline(stream, providerStream, stream, (error) => { + if (error) { + logError(`Provider stream failure.`, error); + } + }); }, ...options, }); diff --git a/packages/snaps-simulator/src/features/simulation/sagas.ts b/packages/snaps-simulator/src/features/simulation/sagas.ts index 5c03b907f0..14771ab65a 100644 --- a/packages/snaps-simulator/src/features/simulation/sagas.ts +++ b/packages/snaps-simulator/src/features/simulation/sagas.ts @@ -170,7 +170,11 @@ export function* initSaga({ payload }: PayloadAction) { const mux = setupMultiplex(rpcStream, 'snapStream'); const stream = mux.createStream('metamask-provider'); const providerStream = createEngineStream({ engine }); - pipeline(stream, providerStream, stream); + pipeline(stream, providerStream, stream, (error) => { + if (error) { + logError(`Provider stream failure.`, error); + } + }); }, }); From e674213354a37742d99cc408af484ce13f329e7f Mon Sep 17 00:00:00 2001 From: Frederik Bolding Date: Thu, 7 Sep 2023 14:20:14 +0200 Subject: [PATCH 4/4] Fix coverage --- packages/snaps-simulator/jest.config.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/snaps-simulator/jest.config.js b/packages/snaps-simulator/jest.config.js index 6062336a6c..a4b6ef1246 100644 --- a/packages/snaps-simulator/jest.config.js +++ b/packages/snaps-simulator/jest.config.js @@ -5,10 +5,10 @@ const baseConfig = require('../../jest.config.base'); module.exports = deepmerge(baseConfig, { coverageThreshold: { global: { - branches: 74.13, - functions: 80.85, - lines: 90.17, - statements: 90, + branches: 72.88, + functions: 80.41, + lines: 90.13, + statements: 89.98, }, }, setupFiles: ['./jest.setup.js'],