Skip to content

Commit 9f713d1

Browse files
refactor: Simplify RPC handling in SnapController
1 parent 00e1f33 commit 9f713d1

File tree

5 files changed

+81
-322
lines changed

5 files changed

+81
-322
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"branches": 93.67,
3-
"functions": 98.16,
4-
"lines": 98.51,
5-
"statements": 98.34
2+
"branches": 94.2,
3+
"functions": 98.13,
4+
"lines": 98.58,
5+
"statements": 98.41
66
}

packages/snaps-controllers/src/snaps/RequestQueue.test.ts

Lines changed: 0 additions & 56 deletions
This file was deleted.

packages/snaps-controllers/src/snaps/RequestQueue.ts

Lines changed: 0 additions & 51 deletions
This file was deleted.

packages/snaps-controllers/src/snaps/SnapController.test.tsx

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -4874,85 +4874,6 @@ describe('SnapController', () => {
48744874
snapController.destroy();
48754875
});
48764876

4877-
it('handlers will throw if there are too many pending requests before a snap has started', async () => {
4878-
const rootMessenger = getControllerMessenger();
4879-
const messenger = getSnapControllerMessenger(rootMessenger);
4880-
const fakeSnap = getPersistedSnapObject({ status: SnapStatus.Stopped });
4881-
const snapId = fakeSnap.id;
4882-
const snapController = getSnapController(
4883-
getSnapControllerOptions({
4884-
messenger,
4885-
state: {
4886-
snaps: {
4887-
[snapId]: fakeSnap,
4888-
},
4889-
},
4890-
}),
4891-
);
4892-
4893-
let resolveExecutePromise: any;
4894-
const deferredExecutePromise = new Promise((resolve) => {
4895-
resolveExecutePromise = resolve;
4896-
});
4897-
4898-
rootMessenger.registerActionHandler(
4899-
'ExecutionService:executeSnap',
4900-
async () => deferredExecutePromise,
4901-
);
4902-
4903-
// Fill up the request queue
4904-
const finishPromise = Promise.all(
4905-
new Array(100).fill(1).map(async (_, id) =>
4906-
snapController.handleRequest({
4907-
snapId,
4908-
origin: MOCK_ORIGIN,
4909-
handler: HandlerType.OnRpcRequest,
4910-
request: {
4911-
jsonrpc: '2.0',
4912-
method: 'bar',
4913-
params: {},
4914-
id,
4915-
},
4916-
}),
4917-
),
4918-
);
4919-
4920-
await expect(
4921-
snapController.handleRequest({
4922-
snapId,
4923-
origin: MOCK_ORIGIN,
4924-
handler: HandlerType.OnRpcRequest,
4925-
request: {
4926-
jsonrpc: '2.0',
4927-
method: 'bar',
4928-
params: {},
4929-
id: 100,
4930-
},
4931-
}),
4932-
).rejects.toThrow(
4933-
'Exceeds maximum number of requests waiting to be resolved, please try again.',
4934-
);
4935-
4936-
// Before processing the pending requests,
4937-
// we need an rpc message handler function to be returned
4938-
jest
4939-
.spyOn(messenger, 'call')
4940-
.mockImplementation(async (method, ..._args: unknown[]) => {
4941-
if (method === 'ExecutionService:executeSnap') {
4942-
return deferredExecutePromise;
4943-
} else if (method === 'ExecutionService:handleRpcRequest') {
4944-
return Promise.resolve(undefined);
4945-
}
4946-
return true;
4947-
});
4948-
4949-
// Resolve the promise that the pending requests are waiting for and wait for them to finish
4950-
resolveExecutePromise();
4951-
await finishPromise;
4952-
4953-
snapController.destroy();
4954-
});
4955-
49564877
it('crashes the Snap on unhandled errors', async () => {
49574878
const { manifest, sourceCode, svgIcon } =
49584879
await getMockSnapFilesWithUpdatedChecksum({

0 commit comments

Comments
 (0)