Skip to content

Commit

Permalink
wip: permission-controller: @metamask/rpc-errors migration
Browse files Browse the repository at this point in the history
  • Loading branch information
legobeat committed Sep 26, 2023
1 parent a957b47 commit a3100b7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5271,7 +5271,8 @@ describe('PermissionController', () => {
};

const expectedError = errors.unauthorized({
data: { origin, method: PermissionNames.wallet_getSecretArray },
data: { origin, method: PermissionNames.wallet_getSecretArray, cause: null },

Check failure on line 5274 in packages/permission-controller/src/PermissionController.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (20.x)

Replace `·origin,·method:·PermissionNames.wallet_getSecretArray,·cause:·null` with `⏎··········origin,⏎··········method:·PermissionNames.wallet_getSecretArray,⏎··········cause:·null,⏎·······`
message: "Unauthorized to perform action. Try requesting the required permission(s) first. For more information, see: https://docs.metamask.io/guide/rpc-api.html#permissions",

Check failure on line 5275 in packages/permission-controller/src/PermissionController.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (20.x)

Replace `·"Unauthorized·to·perform·action.·Try·requesting·the·required·permission(s)·first.·For·more·information,·see:·https://docs.metamask.io/guide/rpc-api.html#permissions"` with `⏎··········'Unauthorized·to·perform·action.·Try·requesting·the·required·permission(s)·first.·For·more·information,·see:·https://docs.metamask.io/guide/rpc-api.html#permissions'`
});

const { error }: any = await engine.handle(request);
Expand Down
1 change: 1 addition & 0 deletions packages/permission-controller/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { PermissionType } from './Permission';

type UnauthorizedArg = {
data?: Record<string, unknown>;
message?: string;
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ describe('requestPermissions RPC method', () => {
});

expect(response.result).toBeUndefined();
expect(response.error).toStrictEqual(serializeError(new Error('foo')));
delete response.error.stack;
delete response.error.data.cause.stack;
const expectedError = new Error('foo');
delete expectedError.stack;
expect(response.error).toStrictEqual(serializeError(expectedError, {shouldIncludeStack: false}));

Check failure on line 77 in packages/permission-controller/src/rpc-methods/requestPermissions.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (20.x)

Replace `serializeError(expectedError,·{shouldIncludeStack:·false})` with `⏎······serializeError(expectedError,·{·shouldIncludeStack:·false·}),⏎····`
expect(mockRequestPermissionsForOrigin).toHaveBeenCalledTimes(1);
expect(mockRequestPermissionsForOrigin).toHaveBeenCalledWith({}, '1');
});
Expand Down

0 comments on commit a3100b7

Please sign in to comment.