Skip to content

Commit 303b2b9

Browse files
Adjust RPC methods
1 parent 6c1ea04 commit 303b2b9

File tree

5 files changed

+6
-42
lines changed

5 files changed

+6
-42
lines changed

packages/snaps-rpc-methods/jest.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ module.exports = deepmerge(baseConfig, {
1010
],
1111
coverageThreshold: {
1212
global: {
13-
branches: 95.7,
13+
branches: 95.68,
1414
functions: 98.75,
15-
lines: 98.99,
15+
lines: 98.98,
1616
statements: 98.69,
1717
},
1818
},

packages/snaps-rpc-methods/src/permitted/invokeKeyring.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ describe('wallet_invokeKeyring', () => {
303303
expect(response.error).toStrictEqual({
304304
...rpcErrors
305305
.invalidRequest({
306-
message: `The snap "${MOCK_SNAP_ID}" is not installed. Please install it first, before invoking the snap.`,
306+
message: `The Snap "${MOCK_SNAP_ID}" is not installed. Please install it before invoking it.`,
307307
})
308308
.serialize(),
309309
stack: expect.any(String),

packages/snaps-rpc-methods/src/permitted/invokeKeyring.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,9 @@ async function invokeKeyringImplementation(
107107

108108
if (!getSnap(snapId)) {
109109
return end(
110+
// Mirror error message from SnapController.
110111
rpcErrors.invalidRequest({
111-
message: `The snap "${snapId}" is not installed. Please install it first, before invoking the snap.`,
112+
message: `The Snap "${snapId}" is not installed. Please install it before invoking it.`,
112113
}),
113114
);
114115
}

packages/snaps-rpc-methods/src/restricted/invokeSnap.test.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ describe('builder', () => {
2323
targetName: WALLET_SNAP_PERMISSION_KEY,
2424
specificationBuilder: expect.any(Function),
2525
methodHooks: {
26-
getSnap: true,
2726
handleSnapRpcRequest: true,
2827
},
2928
});
@@ -33,7 +32,6 @@ describe('builder', () => {
3332
expect(
3433
invokeSnapBuilder.specificationBuilder({
3534
methodHooks: {
36-
getSnap: jest.fn(),
3735
handleSnapRpcRequest: jest.fn(),
3836
},
3937
}),
@@ -53,7 +51,6 @@ describe('builder', () => {
5351
describe('specificationBuilder', () => {
5452
const specification = invokeSnapBuilder.specificationBuilder({
5553
methodHooks: {
56-
getSnap: jest.fn(),
5754
handleSnapRpcRequest: jest.fn(),
5855
},
5956
});
@@ -90,7 +87,6 @@ describe('implementation', () => {
9087
}) as any;
9188
it('calls handleSnapRpcRequest', async () => {
9289
const hooks = getMockHooks();
93-
hooks.getSnap.mockImplementation(getTruncatedSnap);
9490
const implementation = getInvokeSnapImplementation(hooks);
9591
await implementation({
9692
context: { origin: MOCK_ORIGIN },
@@ -101,8 +97,6 @@ describe('implementation', () => {
10197
},
10298
});
10399

104-
expect(hooks.getSnap).toHaveBeenCalledTimes(1);
105-
expect(hooks.getSnap).toHaveBeenCalledWith(MOCK_SNAP_ID);
106100
expect(hooks.handleSnapRpcRequest).toHaveBeenCalledWith({
107101
handler: 'onRpcRequest',
108102
origin: MOCK_ORIGIN,
@@ -113,27 +107,6 @@ describe('implementation', () => {
113107
snapId: MOCK_SNAP_ID,
114108
});
115109
});
116-
117-
it('throws if snap is not installed', async () => {
118-
const hooks = getMockHooks();
119-
const implementation = getInvokeSnapImplementation(hooks);
120-
await expect(
121-
implementation({
122-
context: { origin: MOCK_ORIGIN },
123-
method: WALLET_SNAP_PERMISSION_KEY,
124-
params: {
125-
snapId: MOCK_SNAP_ID,
126-
request: { method: 'hello', params: {} },
127-
},
128-
}),
129-
).rejects.toThrow(
130-
`The snap "${MOCK_SNAP_ID}" is not installed. Please install it first, before invoking the snap.`,
131-
);
132-
expect(hooks.getSnap).toHaveBeenCalledTimes(1);
133-
expect(hooks.getSnap).toHaveBeenCalledWith(MOCK_SNAP_ID);
134-
135-
expect(hooks.handleSnapRpcRequest).not.toHaveBeenCalled();
136-
});
137110
});
138111

139112
describe('handleSnapInstall', () => {

packages/snaps-rpc-methods/src/restricted/invokeSnap.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type {
1212
RequestSnapsParams,
1313
RequestSnapsResult,
1414
} from '@metamask/snaps-sdk';
15-
import type { Snap, SnapRpcHookArgs } from '@metamask/snaps-utils';
15+
import type { SnapRpcHookArgs } from '@metamask/snaps-utils';
1616
import { HandlerType, SnapCaveatType } from '@metamask/snaps-utils';
1717
import type { Json, NonEmptyArray } from '@metamask/utils';
1818

@@ -37,7 +37,6 @@ export type GetPermittedSnaps = {
3737
type AllowedActions = InstallSnaps | GetPermittedSnaps;
3838

3939
export type InvokeSnapMethodHooks = {
40-
getSnap: (snapId: string) => Snap | undefined;
4140
handleSnapRpcRequest: ({
4241
snapId,
4342
origin,
@@ -139,7 +138,6 @@ const specificationBuilder: PermissionSpecificationBuilder<
139138
};
140139

141140
const methodHooks: MethodHooksObject<InvokeSnapMethodHooks> = {
142-
getSnap: true,
143141
handleSnapRpcRequest: true,
144142
};
145143

@@ -153,13 +151,11 @@ export const invokeSnapBuilder = Object.freeze({
153151
* Builds the method implementation for `wallet_snap_*`.
154152
*
155153
* @param hooks - The RPC method hooks.
156-
* @param hooks.getSnap - A function that retrieves all information stored about a snap.
157154
* @param hooks.handleSnapRpcRequest - A function that sends an RPC request to a snap's RPC handler or throws if that fails.
158155
* @returns The method implementation which returns the result of `handleSnapRpcRequest`.
159156
* @throws If the params are invalid.
160157
*/
161158
export function getInvokeSnapImplementation({
162-
getSnap,
163159
handleSnapRpcRequest,
164160
}: InvokeSnapMethodHooks) {
165161
return async function invokeSnap(
@@ -169,12 +165,6 @@ export function getInvokeSnapImplementation({
169165

170166
const { snapId, request } = params as InvokeSnapParams;
171167

172-
if (!getSnap(snapId)) {
173-
throw rpcErrors.invalidRequest({
174-
message: `The snap "${snapId}" is not installed. Please install it first, before invoking the snap.`,
175-
});
176-
}
177-
178168
const { origin } = context;
179169

180170
return (await handleSnapRpcRequest({

0 commit comments

Comments
 (0)