Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeRx committed Nov 6, 2024
1 parent a7e496e commit 4f124a1
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion packages/snaps-controllers/src/snaps/SnapController.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 4f124a1

Please sign in to comment.