Skip to content

Commit

Permalink
fix specs
Browse files Browse the repository at this point in the history
  • Loading branch information
jiexi committed Jun 26, 2024
1 parent 2258ee7 commit 3c8b832
Showing 1 changed file with 0 additions and 115 deletions.
115 changes: 0 additions & 115 deletions app/scripts/metamask-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

Expand Down

0 comments on commit 3c8b832

Please sign in to comment.