From 4f124a12633247c198f25fa4c704f1267950d67d Mon Sep 17 00:00:00 2001 From: Guillaume Roux Date: Wed, 6 Nov 2024 11:56:53 +0100 Subject: [PATCH] Add test --- .../src/snaps/SnapController.test.tsx | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/packages/snaps-controllers/src/snaps/SnapController.test.tsx b/packages/snaps-controllers/src/snaps/SnapController.test.tsx index 575b495317..a21b00125d 100644 --- a/packages/snaps-controllers/src/snaps/SnapController.test.tsx +++ b/packages/snaps-controllers/src/snaps/SnapController.test.tsx @@ -18,7 +18,7 @@ import { handlerEndowments, SnapEndowments, } from '@metamask/snaps-rpc-methods'; -import type { SnapId } from '@metamask/snaps-sdk'; +import type { Snap, SnapId } from '@metamask/snaps-sdk'; import { AuxiliaryFileEncoding, text } from '@metamask/snaps-sdk'; import { Text } from '@metamask/snaps-sdk/jsx'; import type { SnapPermissions, RpcOrigins } from '@metamask/snaps-utils'; @@ -1010,6 +1010,42 @@ describe('SnapController', () => { snapController.destroy(); }); + it('filters out removed permissions', async () => { + const messenger = getSnapControllerMessenger(); + const initialPermissions: SnapPermissions = { + [handlerEndowments.onRpcRequest as string]: { snaps: false, dapps: true }, + // eslint-disable-next-line @typescript-eslint/naming-convention + snap_manageAccounts: {}, + }; + + const { manifest } = await getMockSnapFilesWithUpdatedChecksum({ + manifest: getSnapManifest({ + initialPermissions, + }), + }); + + const snapController = getSnapController( + getSnapControllerOptions({ + messenger, + detectSnapLocation: loopbackDetect({ + manifest: manifest.result, + }), + }), + ); + + const snap = await snapController.installSnaps(MOCK_ORIGIN, { + [MOCK_SNAP_ID]: {}, + }); + + const permissions = (snap[MOCK_SNAP_ID] as Snap).initialPermissions; + + expect(permissions).toStrictEqual({ + [handlerEndowments.onRpcRequest as string]: { snaps: false, dapps: true }, + }); + + snapController.destroy(); + }); + it('throws an error if the installation is disabled during installSnaps', async () => { const controller = getSnapController( getSnapControllerOptions({