1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Use strict assertion mode everywhere (#11012)

The `assert` module has two modes: "Legacy" and "strict". When using
strict mode, the "strict" version of each assertion method is implied.
Whereas in legacy mode, by default it will use the deprecated, "loose"
version of each assertion.

We now use strict mode everywhere. A few tests required updates where
they were asserting the wrong thing, and it was passing beforehand due
to the loose matching.
This commit is contained in:
Mark Stacey 2021-05-07 17:08:24 -02:30 committed by Dan Miller
parent 9d002cbff0
commit 3ba3b330f6
55 changed files with 79 additions and 79 deletions

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import { stripHexPrefix } from 'ethereumjs-util'; import { stripHexPrefix } from 'ethereumjs-util';
import accountImporter from '.'; import accountImporter from '.';

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import sinon from 'sinon'; import sinon from 'sinon';
import { KOVAN_CHAIN_ID } from '../../../shared/constants/network'; import { KOVAN_CHAIN_ID } from '../../../shared/constants/network';
import CachedBalancesController from './cached-balances'; import CachedBalancesController from './cached-balances';

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import sinon from 'sinon'; import sinon from 'sinon';
import { ObservableStore } from '@metamask/obs-store'; import { ObservableStore } from '@metamask/obs-store';
import contracts from '@metamask/contract-metadata'; import contracts from '@metamask/contract-metadata';

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import sinon from 'sinon'; import sinon from 'sinon';
import EnsController from '.'; import EnsController from '.';

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import sinon from 'sinon'; import sinon from 'sinon';
import proxyquire from 'proxyquire'; import proxyquire from 'proxyquire';
import nock from 'nock'; import nock from 'nock';

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import EventEmitter from 'events'; import EventEmitter from 'events';
import { ComposedStore, ObservableStore } from '@metamask/obs-store'; import { ComposedStore, ObservableStore } from '@metamask/obs-store';
import { JsonRpcEngine } from 'json-rpc-engine'; import { JsonRpcEngine } from 'json-rpc-engine';

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import { txMetaStub } from '../../../../test/stub/tx-meta-stub'; import { txMetaStub } from '../../../../test/stub/tx-meta-stub';
import { import {
createPendingNonceMiddleware, createPendingNonceMiddleware,

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import sinon from 'sinon'; import sinon from 'sinon';
import { import {
MAINNET_CHAIN_ID, MAINNET_CHAIN_ID,

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import sinon from 'sinon'; import sinon from 'sinon';
import { ethers } from 'ethers'; import { ethers } from 'ethers';
@ -645,7 +645,7 @@ describe('SwapsController', function () {
topAggId, topAggId,
resultQuotes, resultQuotes,
] = await swapsController._findTopQuoteAndCalculateSavings(testInput); ] = await swapsController._findTopQuoteAndCalculateSavings(testInput);
assert.equal(topAggId, [TEST_AGG_ID_2]); assert.equal(topAggId, TEST_AGG_ID_2);
assert.deepStrictEqual(resultQuotes, expectedResultQuotes); assert.deepStrictEqual(resultQuotes, expectedResultQuotes);
}); });
}); });

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import sinon from 'sinon'; import sinon from 'sinon';
import { ObservableStore } from '@metamask/obs-store'; import { ObservableStore } from '@metamask/obs-store';
import TokenRatesController from './token-rates'; import TokenRatesController from './token-rates';

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import { ObservableStore } from '@metamask/obs-store'; import { ObservableStore } from '@metamask/obs-store';
import ComposableObservableStore from './ComposableObservableStore'; import ComposableObservableStore from './ComposableObservableStore';

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import { import {
KOVAN_CHAIN_ID, KOVAN_CHAIN_ID,
MAINNET_CHAIN_ID, MAINNET_CHAIN_ID,

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import cleanErrorStack from './cleanErrorStack'; import cleanErrorStack from './cleanErrorStack';
describe('Clean Error Stack', function () { describe('Clean Error Stack', function () {
@ -14,7 +14,7 @@ describe('Clean Error Stack', function () {
}); });
it('tests error with message', function () { it('tests error with message', function () {
assert.equal(cleanErrorStack(testError), 'Error: Test Message'); assert.equal(cleanErrorStack(testError).toString(), 'Error: Test Message');
}); });
it('tests error with undefined name', function () { it('tests error with undefined name', function () {
@ -29,6 +29,6 @@ describe('Clean Error Stack', function () {
}); });
it('tests error with blank message', function () { it('tests error with blank message', function () {
assert.equal(cleanErrorStack(blankMsgError), 'Error'); assert.equal(cleanErrorStack(blankMsgError).toString(), 'Error');
}); });
}); });

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import { obj as createThoughStream } from 'through2'; import { obj as createThoughStream } from 'through2';
import createMetaRPCHandler from './createMetaRPCHandler'; import createMetaRPCHandler from './createMetaRPCHandler';

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction'; import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction';
import MessageManager from './message-manager'; import MessageManager from './message-manager';

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import { obj as createThoughStream } from 'through2'; import { obj as createThoughStream } from 'through2';
import metaRPCClientFactory from './metaRPCClientFactory'; import metaRPCClientFactory from './metaRPCClientFactory';

View File

@ -1,5 +1,5 @@
import fs from 'fs'; import fs from 'fs';
import assert from 'assert'; import { strict as assert } from 'assert';
import { cloneDeep } from 'lodash'; import { cloneDeep } from 'lodash';
import liveMigrations from '../../migrations'; import liveMigrations from '../../migrations';
import data from '../../first-time-state'; import data from '../../first-time-state';

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import nodeify from './nodeify'; import nodeify from './nodeify';
describe('nodeify', function () { describe('nodeify', function () {

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction'; import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction';
import PersonalMessageManager from './personal-message-manager'; import PersonalMessageManager from './personal-message-manager';

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import { cloneDeep } from 'lodash'; import { cloneDeep } from 'lodash';
import KeyringController from 'eth-keyring-controller'; import KeyringController from 'eth-keyring-controller';
import firstTimeState from '../first-time-state'; import firstTimeState from '../first-time-state';

View File

@ -1,5 +1,5 @@
import EventEmitter from 'events'; import EventEmitter from 'events';
import assert from 'assert'; import { strict as assert } from 'assert';
import { ObservableStore } from '@metamask/obs-store'; import { ObservableStore } from '@metamask/obs-store';
import { ethErrors } from 'eth-rpc-errors'; import { ethErrors } from 'eth-rpc-errors';
import { typedSignatureHash, TYPED_MESSAGE_SCHEMA } from 'eth-sig-util'; import { typedSignatureHash, TYPED_MESSAGE_SCHEMA } from 'eth-sig-util';

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import sinon from 'sinon'; import sinon from 'sinon';
import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction'; import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction';
import TypedMessageManager from './typed-message-manager'; import TypedMessageManager from './typed-message-manager';

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import extension from 'extensionizer'; import extension from 'extensionizer';
import { stripHexPrefix } from 'ethereumjs-util'; import { stripHexPrefix } from 'ethereumjs-util';
import BN from 'bn.js'; import BN from 'bn.js';

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import sinon from 'sinon'; import sinon from 'sinon';
import { cloneDeep } from 'lodash'; import { cloneDeep } from 'lodash';
import nock from 'nock'; import nock from 'nock';
@ -493,8 +493,8 @@ describe('MetaMaskController', function () {
); );
} catch (e) { } catch (e) {
assert.equal( assert.equal(
e, e.message,
'Error: MetamaskController:getKeyringForDevice - Unknown device', 'MetamaskController:getKeyringForDevice - Unknown device',
); );
} }
}); });
@ -535,8 +535,8 @@ describe('MetaMaskController', function () {
); );
} catch (e) { } catch (e) {
assert.equal( assert.equal(
e, e.message,
'Error: MetamaskController:getKeyringForDevice - Unknown device', 'MetamaskController:getKeyringForDevice - Unknown device',
); );
} }
}); });
@ -554,8 +554,8 @@ describe('MetaMaskController', function () {
await metamaskController.forgetDevice('Some random device name'); await metamaskController.forgetDevice('Some random device name');
} catch (e) { } catch (e) {
assert.equal( assert.equal(
e, e.message,
'Error: MetamaskController:getKeyringForDevice - Unknown device', 'MetamaskController:getKeyringForDevice - Unknown device',
); );
} }
}); });

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import wallet2 from '../../../test/lib/migrations/002.json'; import wallet2 from '../../../test/lib/migrations/002.json';
import migration21 from './021'; import migration21 from './021';

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction'; import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction';
import migration22 from './022'; import migration22 from './022';

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction'; import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction';
import migration23 from './023'; import migration23 from './023';

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import data from '../first-time-state'; import data from '../first-time-state';
import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction'; import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction';
import migration24 from './024'; import migration24 from './024';

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import data from '../first-time-state'; import data from '../first-time-state';
import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction'; import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction';
import migration25 from './025'; import migration25 from './025';

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import firstTimeState from '../first-time-state'; import firstTimeState from '../first-time-state';
import migration26 from './026'; import migration26 from './026';

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import firstTimeState from '../first-time-state'; import firstTimeState from '../first-time-state';
import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction'; import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction';
import migration27 from './027'; import migration27 from './027';

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import firstTimeState from '../first-time-state'; import firstTimeState from '../first-time-state';
import migration28 from './028'; import migration28 from './028';

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction'; import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction';
import migration29 from './029'; import migration29 from './029';

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import migrationTemplate from './030'; import migrationTemplate from './030';
const storage = { const storage = {

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import migration31 from './031'; import migration31 from './031';
describe('migration #31', function () { describe('migration #31', function () {

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import migration33 from './033'; import migration33 from './033';
describe('Migration to delete notice controller', function () { describe('Migration to delete notice controller', function () {

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import migration34 from './034'; import migration34 from './034';
describe('migration #34', function () { describe('migration #34', function () {

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import migration35 from './035'; import migration35 from './035';
describe('migration #35', function () { describe('migration #35', function () {

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import migration36 from './036'; import migration36 from './036';
describe('migration #36', function () { describe('migration #36', function () {

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import migration37 from './037'; import migration37 from './037';
describe('migration #37', function () { describe('migration #37', function () {

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import migration39 from './039'; import migration39 from './039';
describe('migration #39', function () { describe('migration #39', function () {

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import migration40 from './040'; import migration40 from './040';
describe('migration #40', function () { describe('migration #40', function () {

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import migration41 from './041'; import migration41 from './041';
describe('migration #41', function () { describe('migration #41', function () {

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import migration42 from './042'; import migration42 from './042';
describe('migration #42', function () { describe('migration #42', function () {

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import migration45 from './045'; import migration45 from './045';
describe('migration #45', function () { describe('migration #45', function () {

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import migration49 from './049'; import migration49 from './049';
describe('migration #49', function () { describe('migration #49', function () {

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import { import {
GOERLI, GOERLI,
GOERLI_CHAIN_ID, GOERLI_CHAIN_ID,

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import migration56 from './056'; import migration56 from './056';
const BAD_TOKEN_DATA = { symbol: null, decimals: null }; const BAD_TOKEN_DATA = { symbol: null, decimals: null };

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import wallet1 from '../../../test/lib/migrations/001.json'; import wallet1 from '../../../test/lib/migrations/001.json';
import vault4 from '../../../test/lib/migrations/004.json'; import vault4 from '../../../test/lib/migrations/004.json';
import migration2 from './002'; import migration2 from './002';
@ -52,7 +52,7 @@ describe('wallet1 is migrated successfully', function () {
const fourthData = fourthResult.data; const fourthData = fourthResult.data;
assert.equal( assert.equal(
fourthData.config.provider.rpcTarget, fourthData.config.provider.rpcTarget,
null, undefined,
'old rpcTarget should not exist.', 'old rpcTarget should not exist.',
); );
assert.equal( assert.equal(
@ -65,15 +65,15 @@ describe('wallet1 is migrated successfully', function () {
}) })
.then((fifthResult) => { .then((fifthResult) => {
const fifthData = fifthResult.data; const fifthData = fifthResult.data;
assert.equal(fifthData.vault, null, 'old vault should not exist'); assert.equal(fifthData.vault, undefined, 'old vault should not exist');
assert.equal( assert.equal(
fifthData.walletNicknames, fifthData.walletNicknames,
null, undefined,
'old walletNicknames should not exist', 'old walletNicknames should not exist',
); );
assert.equal( assert.equal(
fifthData.config.selectedAccount, fifthData.config.selectedAccount,
null, undefined,
'old config.selectedAccount should not exist', 'old config.selectedAccount should not exist',
); );
assert.equal( assert.equal(
@ -102,7 +102,7 @@ describe('wallet1 is migrated successfully', function () {
.then((sixthResult) => { .then((sixthResult) => {
assert.equal( assert.equal(
sixthResult.data.KeyringController.selectedAccount, sixthResult.data.KeyringController.selectedAccount,
null, undefined,
'old selectedAccount should not exist', 'old selectedAccount should not exist',
); );
assert.equal( assert.equal(
@ -117,12 +117,12 @@ describe('wallet1 is migrated successfully', function () {
.then((seventhResult) => { .then((seventhResult) => {
assert.equal( assert.equal(
seventhResult.data.transactions, seventhResult.data.transactions,
null, undefined,
'old transactions should not exist', 'old transactions should not exist',
); );
assert.equal( assert.equal(
seventhResult.data.gasMultiplier, seventhResult.data.gasMultiplier,
null, undefined,
'old gasMultiplier should not exist', 'old gasMultiplier should not exist',
); );
assert.equal( assert.equal(
@ -142,7 +142,7 @@ describe('wallet1 is migrated successfully', function () {
.then((eighthResult) => { .then((eighthResult) => {
assert.equal( assert.equal(
eighthResult.data.noticesList, eighthResult.data.noticesList,
null, undefined,
'old noticesList should not exist', 'old noticesList should not exist',
); );
assert.equal( assert.equal(
@ -157,22 +157,22 @@ describe('wallet1 is migrated successfully', function () {
.then((ninthResult) => { .then((ninthResult) => {
assert.equal( assert.equal(
ninthResult.data.currentFiat, ninthResult.data.currentFiat,
null, undefined,
'old currentFiat should not exist', 'old currentFiat should not exist',
); );
assert.equal( assert.equal(
ninthResult.data.fiatCurrency, ninthResult.data.fiatCurrency,
null, undefined,
'old fiatCurrency should not exist', 'old fiatCurrency should not exist',
); );
assert.equal( assert.equal(
ninthResult.data.conversionRate, ninthResult.data.conversionRate,
null, undefined,
'old conversionRate should not exist', 'old conversionRate should not exist',
); );
assert.equal( assert.equal(
ninthResult.data.conversionDate, ninthResult.data.conversionDate,
null, undefined,
'old conversionDate should not exist', 'old conversionDate should not exist',
); );
@ -198,7 +198,7 @@ describe('wallet1 is migrated successfully', function () {
.then((tenthResult) => { .then((tenthResult) => {
assert.equal( assert.equal(
tenthResult.data.shapeShiftTxList, tenthResult.data.shapeShiftTxList,
null, undefined,
'old shapeShiftTxList should not exist', 'old shapeShiftTxList should not exist',
); );
assert.equal( assert.equal(
@ -211,12 +211,12 @@ describe('wallet1 is migrated successfully', function () {
.then((eleventhResult) => { .then((eleventhResult) => {
assert.equal( assert.equal(
eleventhResult.data.isDisclaimerConfirmed, eleventhResult.data.isDisclaimerConfirmed,
null, undefined,
'isDisclaimerConfirmed should not exist', 'isDisclaimerConfirmed should not exist',
); );
assert.equal( assert.equal(
eleventhResult.data.TOSHash, eleventhResult.data.TOSHash,
null, undefined,
'TOSHash should not exist', 'TOSHash should not exist',
); );

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import migrationTemplate from './template'; import migrationTemplate from './template';
const storage = { const storage = {

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import nock from 'nock'; import nock from 'nock';
import getFetchWithTimeout from './fetch-with-timeout'; import getFetchWithTimeout from './fetch-with-timeout';

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import { import {
MAINNET_CHAIN_ID, MAINNET_CHAIN_ID,
MAINNET_NETWORK_ID, MAINNET_NETWORK_ID,

View File

@ -1,4 +1,4 @@
const assert = require('assert'); const { strict: assert } = require('assert');
const enLocaleMessages = require('../../app/_locales/en/messages.json'); const enLocaleMessages = require('../../app/_locales/en/messages.json');
const { tinyDelayMs, regularDelayMs, largeDelayMs } = require('./helpers'); const { tinyDelayMs, regularDelayMs, largeDelayMs } = require('./helpers');

View File

@ -1,4 +1,4 @@
import assert from 'assert'; import { strict as assert } from 'assert';
import currencyFormatter from 'currency-formatter'; import currencyFormatter from 'currency-formatter';
import availableCurrencies from '../../ui/helpers/constants/available-conversions.json'; import availableCurrencies from '../../ui/helpers/constants/available-conversions.json';

View File

@ -2,7 +2,7 @@
import './globalPatch'; import './globalPatch';
import 'ses/lockdown'; import 'ses/lockdown';
import '../../app/scripts/runLockdown'; import '../../app/scripts/runLockdown';
import assert from 'assert'; /* eslint-disable-line import/first,import/order */ import { strict as assert } from 'assert'; /* eslint-disable-line import/first,import/order */
describe('Promise global is immutable', function () { describe('Promise global is immutable', function () {
it('throws when reassinging promise (syntax 1)', function () { it('throws when reassinging promise (syntax 1)', function () {