From ca8bef4396b666f50531dfc933180551851ade1a Mon Sep 17 00:00:00 2001 From: david0xd Date: Thu, 5 Jan 2023 14:04:58 +0100 Subject: [PATCH] Remove specific test for interval and timeout --- .../nyc.config.js | 6 +- .../src/common/BaseSnapExecutor.test.ts | 117 ------------------ 2 files changed, 3 insertions(+), 120 deletions(-) diff --git a/packages/snaps-execution-environments/nyc.config.js b/packages/snaps-execution-environments/nyc.config.js index d66fed6f4c..a91f4677fe 100644 --- a/packages/snaps-execution-environments/nyc.config.js +++ b/packages/snaps-execution-environments/nyc.config.js @@ -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, }; diff --git a/packages/snaps-execution-environments/src/common/BaseSnapExecutor.test.ts b/packages/snaps-execution-environments/src/common/BaseSnapExecutor.test.ts index 15d1e72d5e..9828ab2f29 100644 --- a/packages/snaps-execution-environments/src/common/BaseSnapExecutor.test.ts +++ b/packages/snaps-execution-environments/src/common/BaseSnapExecutor.test.ts @@ -2,7 +2,6 @@ import 'ses'; import { HandlerType } from '@metamask/snaps-utils'; import { - assertIsJsonRpcSuccess, Json, JsonRpcParams, JsonRpcRequest, @@ -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 () => {