Skip to content

Commit

Permalink
Remove specific test for interval and timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
david0xd committed Jan 5, 2023
1 parent eb2ffef commit ca8bef4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 120 deletions.
6 changes: 3 additions & 3 deletions packages/snaps-execution-environments/nyc.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*/
module.exports = {
'check-coverage': true,
branches: 91.02,
lines: 91.36,
branches: 90.31,
lines: 91.21,
functions: 92.85,
statements: 91.36,
statements: 91.21,
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import 'ses';
import { HandlerType } from '@metamask/snaps-utils';
import {
assertIsJsonRpcSuccess,
Json,
JsonRpcParams,
JsonRpcRequest,
Expand Down Expand Up @@ -305,122 +304,6 @@ describe('BaseSnapExecutor', () => {

expect(consoleErrorSpy).not.toHaveBeenCalled();
});

it.each(['Timeout', 'Interval'])(
"can't clear set%s of other snaps",
async (name: string) => {
// Since we don't know how the handle looks like we have to actually retrieve it after creating it
const CODE_1 = `
let handle;
exports.onRpcRequest = (({ origin, request }) => {
switch (request.method) {
case 'set':
let resolve;
const promise = new Promise((r) => { resolve = r; });
handle = set${name}(() => {
clear${name}(handle);
resolve('SNAP 1 OK');
}, 1000);
return promise;
case 'getHandle':
return {};
}
});
`;
const CODE_2 = `
exports.onRpcRequest = (({ origin, request }) => {
const handle = request.params[0];
clear${name}(handle);
return 'SNAP 2 OK';
})
`;
const SNAP_NAME_1 = `${FAKE_SNAP_NAME}_1`;
const SNAP_NAME_2 = `${FAKE_SNAP_NAME}_2`;

const executor = new TestSnapExecutor();

// Initiate the snaps
await executor.executeSnap(1, SNAP_NAME_1, CODE_1, TIMER_ENDOWMENTS);

expect(await executor.readCommand()).toStrictEqual({
jsonrpc: '2.0',
id: 1,
result: 'OK',
});

await executor.executeSnap(2, SNAP_NAME_2, CODE_2, TIMER_ENDOWMENTS);

expect(await executor.readCommand()).toStrictEqual({
jsonrpc: '2.0',
id: 2,
result: 'OK',
});

// The order of below is extremely important!

await executor.writeCommand({
jsonrpc: '2.0',
id: 3,
method: 'snapRpc',
params: [
SNAP_NAME_1,
ON_RPC_REQUEST,
FAKE_ORIGIN,
{ jsonrpc: '2.0', method: 'set' },
],
});

await executor.writeCommand({
jsonrpc: '2.0',
id: 4,
method: 'snapRpc',
params: [
SNAP_NAME_1,
ON_RPC_REQUEST,
FAKE_ORIGIN,
{ jsonrpc: '2.0', method: 'getHandle' },
],
});

const getHandleResult = await executor.readCommand();
expect(getHandleResult).toStrictEqual(
expect.objectContaining({
jsonrpc: '2.0',
id: 4,
result: expect.anything(),
}),
);

assertIsJsonRpcSuccess(getHandleResult);
const handle = getHandleResult.result;

await executor.writeCommand({
jsonrpc: '2.0',
id: 5,
method: 'snapRpc',
params: [
SNAP_NAME_2,
ON_RPC_REQUEST,
FAKE_ORIGIN,
{ jsonrpc: '2.0', method: '', params: [handle] },
],
});

expect(await executor.readCommand()).toStrictEqual({
jsonrpc: '2.0',
id: 5,
result: 'SNAP 2 OK',
});

jest.advanceTimersByTime(1000);

expect(await executor.readCommand()).toStrictEqual({
jsonrpc: '2.0',
id: 3,
result: 'SNAP 1 OK',
});
},
);
});

it('terminates a request when terminate RPC is called', async () => {
Expand Down

0 comments on commit ca8bef4

Please sign in to comment.