Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
FrederikBolding committed Sep 21, 2023
1 parent 964f6a6 commit e148de8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 38 deletions.
4 changes: 2 additions & 2 deletions app/scripts/controllers/permissions/specifications.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ describe('PermissionController specifications', () => {
expect(caveatSpecifications.permittedCoinTypes.type).toStrictEqual(
SnapCaveatType.PermittedCoinTypes,
);
expect(caveatSpecifications.snapKeyring.type).toStrictEqual(
SnapCaveatType.SnapKeyring,
expect(caveatSpecifications.chainIds.type).toStrictEqual(
SnapCaveatType.ChainIds,
);
expect(caveatSpecifications.snapCronjob.type).toStrictEqual(
SnapCaveatType.SnapCronjob,
Expand Down
39 changes: 3 additions & 36 deletions shared/constants/permissions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { restrictedMethodPermissionBuilders } from '@metamask/rpc-methods';
import {
EndowmentPermissions,
ExcludedSnapEndowments,
ExcludedSnapPermissions,
RestrictedMethods,
} from './permissions';

Expand All @@ -24,46 +23,14 @@ describe('EndowmentPermissions', () => {
});
});

const FlaskOnlyPermissions = ['snap_manageAccounts', 'snap_getLocale'];

// This test is flawed because it doesn't take fencing into consideration
// TODO: Figure out a better way to test this
describe('RestrictedMethods', () => {
it('has the expected permission keys', () => {
// this is done because we there is a difference between flask and stable permissions
// the code fence in `shared/constants/snaps/permissions.ts` is not supported in jest
const mainBuildRestrictedMethodPermissions = Object.keys(RestrictedMethods)
.filter((key) => !FlaskOnlyPermissions.includes(key))
.sort();

expect(mainBuildRestrictedMethodPermissions).toStrictEqual(
[
'eth_accounts',
...Object.keys(restrictedMethodPermissionBuilders).filter(
(targetName) =>
!Object.keys(ExcludedSnapPermissions).includes(targetName),
),
].sort(),
);
});
});

// Kept here because code fences are not supported in jest.
// rpc methods flask has more restricted endowment permission builders
jest.mock('@metamask/rpc-methods', () =>
jest.requireActual('@metamask/rpc-methods-flask'),
);

describe('Flask Restricted Methods', () => {
it('has the expected flask permission keys', () => {
const flaskExcludedSnapPermissions = Object.keys(
ExcludedSnapPermissions,
).filter((key) => !FlaskOnlyPermissions.includes(key));

expect(Object.keys(RestrictedMethods).sort()).toStrictEqual(
[
'eth_accounts',
...Object.keys(restrictedMethodPermissionBuilders).filter(
(targetName) => !flaskExcludedSnapPermissions.includes(targetName),
),
...Object.keys(restrictedMethodPermissionBuilders),
].sort(),
);
});
Expand Down
1 change: 1 addition & 0 deletions shared/constants/snaps/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const EndowmentPermissions = Object.freeze({
///: BEGIN:ONLY_INCLUDE_IN(build-flask)
'endowment:long-running': 'endowment:long-running',
'endowment:lifecycle-hooks': 'endowment:lifecycle-hooks',
'endowment:name-lookup': 'endowment:name-lookup',
///: END:ONLY_INCLUDE_IN
} as const);

Expand Down

0 comments on commit e148de8

Please sign in to comment.