2022-08-26 01:07:31 +02:00
|
|
|
const { strict: assert } = require('assert');
|
2023-07-31 23:19:32 +02:00
|
|
|
const { Browser } = require('selenium-webdriver');
|
2022-08-26 01:07:31 +02:00
|
|
|
const { convertToHexValue, withFixtures } = require('../helpers');
|
2022-10-28 10:42:12 +02:00
|
|
|
const FixtureBuilder = require('../fixture-builder');
|
2022-08-26 01:07:31 +02:00
|
|
|
|
|
|
|
describe('Sentry errors', function () {
|
2023-07-31 23:19:32 +02:00
|
|
|
const migrationError =
|
|
|
|
process.env.SELENIUM_BROWSER === Browser.CHROME
|
|
|
|
? `Cannot read properties of undefined (reading 'version')`
|
|
|
|
: 'meta is undefined';
|
|
|
|
async function mockSentryMigratorError(mockServer) {
|
|
|
|
return await mockServer
|
|
|
|
.forPost('https://sentry.io/api/0000000/envelope/')
|
|
|
|
.withBodyIncluding(migrationError)
|
|
|
|
.thenCallback(() => {
|
|
|
|
return {
|
|
|
|
statusCode: 200,
|
|
|
|
json: {},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function mockSentryTestError(mockServer) {
|
2022-08-26 01:07:31 +02:00
|
|
|
return await mockServer
|
2023-06-27 16:45:02 +02:00
|
|
|
.forPost('https://sentry.io/api/0000000/envelope/')
|
|
|
|
.withBodyIncluding('Test Error')
|
2022-08-26 01:07:31 +02:00
|
|
|
.thenCallback(() => {
|
|
|
|
return {
|
|
|
|
statusCode: 200,
|
|
|
|
json: {},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
const ganacheOptions = {
|
|
|
|
accounts: [
|
|
|
|
{
|
|
|
|
secretKey:
|
|
|
|
'0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC',
|
|
|
|
balance: convertToHexValue(25000000000000000000),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2023-07-31 23:19:32 +02:00
|
|
|
|
|
|
|
describe('before initialization', function () {
|
|
|
|
it('should NOT send error events when participateInMetaMetrics is false', async function () {
|
|
|
|
await withFixtures(
|
|
|
|
{
|
|
|
|
fixtures: {
|
|
|
|
...new FixtureBuilder()
|
|
|
|
.withMetaMetricsController({
|
|
|
|
metaMetricsId: null,
|
|
|
|
participateInMetaMetrics: false,
|
|
|
|
})
|
|
|
|
.build(),
|
|
|
|
// Intentionally corrupt state to trigger migration error during initialization
|
|
|
|
meta: undefined,
|
|
|
|
},
|
|
|
|
ganacheOptions,
|
|
|
|
title: this.test.title,
|
|
|
|
failOnConsoleError: false,
|
|
|
|
testSpecificMock: mockSentryMigratorError,
|
|
|
|
},
|
|
|
|
async ({ driver, mockedEndpoint }) => {
|
|
|
|
await driver.navigate();
|
|
|
|
|
|
|
|
// Wait for Sentry request
|
|
|
|
await driver.delay(3000);
|
|
|
|
const isPending = await mockedEndpoint.isPending();
|
|
|
|
assert.ok(
|
|
|
|
isPending,
|
|
|
|
'A request to sentry was sent when it should not have been',
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
it('should send error events', async function () {
|
|
|
|
await withFixtures(
|
|
|
|
{
|
|
|
|
fixtures: {
|
|
|
|
...new FixtureBuilder()
|
|
|
|
.withMetaMetricsController({
|
|
|
|
metaMetricsId: 'fake-metrics-id',
|
|
|
|
participateInMetaMetrics: true,
|
|
|
|
})
|
|
|
|
.build(),
|
|
|
|
// Intentionally corrupt state to trigger migration error during initialization
|
|
|
|
meta: undefined,
|
|
|
|
},
|
|
|
|
ganacheOptions,
|
|
|
|
title: this.test.title,
|
|
|
|
failOnConsoleError: false,
|
|
|
|
testSpecificMock: mockSentryMigratorError,
|
|
|
|
},
|
|
|
|
async ({ driver, mockedEndpoint }) => {
|
|
|
|
await driver.navigate();
|
|
|
|
|
|
|
|
// Wait for Sentry request
|
|
|
|
await driver.wait(async () => {
|
|
|
|
const isPending = await mockedEndpoint.isPending();
|
|
|
|
return isPending === false;
|
|
|
|
}, 3000);
|
|
|
|
|
|
|
|
const [mockedRequest] = await mockedEndpoint.getSeenRequests();
|
|
|
|
const mockTextBody = mockedRequest.body.text.split('\n');
|
|
|
|
const mockJsonBody = JSON.parse(mockTextBody[2]);
|
|
|
|
const { level } = mockJsonBody;
|
|
|
|
const [{ type, value }] = mockJsonBody.exception.values;
|
|
|
|
// Verify request
|
|
|
|
assert.equal(type, 'TypeError');
|
|
|
|
assert(value.includes(migrationError));
|
|
|
|
assert.equal(level, 'error');
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
2023-07-26 14:13:28 +02:00
|
|
|
});
|
2023-07-31 23:19:32 +02:00
|
|
|
|
|
|
|
describe('after initialization', function () {
|
|
|
|
it('should NOT send error events when participateInMetaMetrics is false', async function () {
|
|
|
|
await withFixtures(
|
|
|
|
{
|
|
|
|
fixtures: new FixtureBuilder()
|
|
|
|
.withMetaMetricsController({
|
|
|
|
metaMetricsId: null,
|
|
|
|
participateInMetaMetrics: false,
|
|
|
|
})
|
|
|
|
.build(),
|
|
|
|
ganacheOptions,
|
|
|
|
title: this.test.title,
|
|
|
|
failOnConsoleError: false,
|
|
|
|
testSpecificMock: mockSentryTestError,
|
|
|
|
},
|
|
|
|
async ({ driver, mockedEndpoint }) => {
|
|
|
|
await driver.navigate();
|
|
|
|
await driver.fill('#password', 'correct horse battery staple');
|
|
|
|
await driver.press('#password', driver.Key.ENTER);
|
|
|
|
// Trigger error
|
|
|
|
driver.executeScript('window.stateHooks.throwTestError()');
|
|
|
|
driver.delay(3000);
|
|
|
|
// Wait for Sentry request
|
2022-08-26 01:07:31 +02:00
|
|
|
const isPending = await mockedEndpoint.isPending();
|
2023-07-31 23:19:32 +02:00
|
|
|
assert.ok(
|
|
|
|
isPending,
|
|
|
|
'A request to sentry was sent when it should not have been',
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
it('should send error events', async function () {
|
|
|
|
await withFixtures(
|
|
|
|
{
|
|
|
|
fixtures: new FixtureBuilder()
|
|
|
|
.withMetaMetricsController({
|
|
|
|
metaMetricsId: 'fake-metrics-id',
|
|
|
|
participateInMetaMetrics: true,
|
|
|
|
})
|
|
|
|
.build(),
|
|
|
|
ganacheOptions,
|
|
|
|
title: this.test.title,
|
|
|
|
failOnConsoleError: false,
|
|
|
|
testSpecificMock: mockSentryTestError,
|
|
|
|
},
|
|
|
|
async ({ driver, mockedEndpoint }) => {
|
|
|
|
await driver.navigate();
|
|
|
|
await driver.fill('#password', 'correct horse battery staple');
|
|
|
|
await driver.press('#password', driver.Key.ENTER);
|
|
|
|
// Trigger error
|
|
|
|
driver.executeScript('window.stateHooks.throwTestError()');
|
|
|
|
// Wait for Sentry request
|
|
|
|
await driver.wait(async () => {
|
|
|
|
const isPending = await mockedEndpoint.isPending();
|
|
|
|
return isPending === false;
|
|
|
|
}, 10000);
|
|
|
|
const [mockedRequest] = await mockedEndpoint.getSeenRequests();
|
|
|
|
const mockTextBody = mockedRequest.body.text.split('\n');
|
|
|
|
const mockJsonBody = JSON.parse(mockTextBody[2]);
|
|
|
|
const { level, extra } = mockJsonBody;
|
|
|
|
const [{ type, value }] = mockJsonBody.exception.values;
|
|
|
|
const { participateInMetaMetrics } = extra.appState.store.metamask;
|
|
|
|
// Verify request
|
|
|
|
assert.equal(type, 'TestError');
|
|
|
|
assert.equal(value, 'Test Error');
|
|
|
|
assert.equal(level, 'error');
|
|
|
|
assert.equal(participateInMetaMetrics, true);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
2022-08-26 01:07:31 +02:00
|
|
|
});
|
|
|
|
});
|