From 3c8b8328e714f86313fe23f8e465373529ff134c Mon Sep 17 00:00:00 2001 From: Jiexi Luan Date: Wed, 26 Jun 2024 12:28:53 -0700 Subject: [PATCH] fix specs --- app/scripts/metamask-controller.test.js | 115 ------------------------ 1 file changed, 115 deletions(-) diff --git a/app/scripts/metamask-controller.test.js b/app/scripts/metamask-controller.test.js index e78e09b4ce18..f7b99be06d32 100644 --- a/app/scripts/metamask-controller.test.js +++ b/app/scripts/metamask-controller.test.js @@ -1399,121 +1399,6 @@ describe('MetaMaskController', () => { }); describe('#setupUntrustedCommunicationCaip', () => { - const mockTxParams = { from: TEST_ADDRESS }; - - beforeEach(() => { - initializeMockMiddlewareLog(); - metamaskController.preferencesController.setSecurityAlertsEnabled( - false, - ); - jest - .spyOn(metamaskController.onboardingController.store, 'getState') - .mockReturnValue({ completedOnboarding: true }); - metamaskController.preferencesController.setUsePhishDetect(true); - }); - - afterAll(() => { - tearDownMockMiddlewareLog(); - }); - - it('adds a tabId, origin and networkClient to requests', async () => { - const messageSender = { - url: 'http://mycrypto.com', - tab: { id: 456 }, - }; - const streamTest = createThroughStream((chunk, _, cb) => { - if (chunk.data && chunk.data.method) { - cb(null, chunk); - return; - } - cb(); - }); - - metamaskController.setupUntrustedCommunicationCaip({ - connectionStream: streamTest, - sender: messageSender, - }); - - const message = { - id: 1999133338649204, - jsonrpc: '2.0', - params: [{ ...mockTxParams }], - method: 'eth_sendTransaction', - }; - await new Promise((resolve) => { - streamTest.write( - { - type: 'caip-x', - data: message, - }, - null, - () => { - setTimeout(() => { - expect(loggerMiddlewareMock.requests[0]).toHaveProperty( - 'origin', - 'http://mycrypto.com', - ); - expect(loggerMiddlewareMock.requests[0]).toHaveProperty( - 'tabId', - 456, - ); - expect(loggerMiddlewareMock.requests[0]).toHaveProperty( - 'networkClientId', - 'networkConfigurationId1', - ); - resolve(); - }); - }, - ); - }); - }); - - it('should add only origin to request if tabId not provided', async () => { - const messageSender = { - url: 'http://mycrypto.com', - }; - const streamTest = createThroughStream((chunk, _, cb) => { - if (chunk.data && chunk.data.method) { - cb(null, chunk); - return; - } - cb(); - }); - - metamaskController.setupUntrustedCommunicationCaip({ - connectionStream: streamTest, - sender: messageSender, - }); - - const message = { - id: 1999133338649204, - jsonrpc: '2.0', - params: [{ ...mockTxParams }], - method: 'eth_sendTransaction', - }; - await new Promise((resolve) => { - streamTest.write( - { - type: 'caip-x', - data: message, - }, - null, - () => { - setTimeout(() => { - expect(loggerMiddlewareMock.requests[0]).not.toHaveProperty( - 'tabId', - ); - expect(loggerMiddlewareMock.requests[0]).toHaveProperty( - 'origin', - 'http://mycrypto.com', - ); - resolve(); - }); - }, - ); - }); - }); - it.todo('should only process `caip-x` CAIP formatted messages'); });