Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/scripts/controllers/bridge-status/validators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ const BridgeTxStatusResponses = {

describe('validators', () => {
describe('bridgeStatusValidator', () => {
// @ts-expect-error - it.each is a function
it.each([
{
input: BridgeTxStatusResponses.STATUS_PENDING_VALID,
Expand Down
1 change: 0 additions & 1 deletion app/scripts/controllers/encryption-public-key.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ describe('EncryptionPublicKeyController', () => {
});

describe('newRequestEncryptionPublicKey', () => {
// @ts-expect-error This function is missing from the Mocha type definitions
it.each([
['Ledger', KeyringType.ledger],
['Trezor', KeyringType.trezor],
Expand Down
1 change: 0 additions & 1 deletion app/scripts/controllers/metametrics-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,6 @@ describe('MetaMetricsController', function () {
});

describe('Change Signature XXX anonymous event names', function () {
// @ts-expect-error This function is missing from the Mocha type definitions
it.each([
['Signature Requested', 'Signature Requested Anon'],
['Signature Rejected', 'Signature Rejected Anon'],
Expand Down
1 change: 0 additions & 1 deletion app/scripts/lib/AccountIdentitiesPetnamesBridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ describe('AccountIdentitiesPetnamesBridge', () => {
});

describe('shouldSyncPetname', () => {
// @ts-expect-error This is missing from the Mocha type definitions
it.each([
{
origin: NameOrigin.ACCOUNT_IDENTITY,
Expand Down
3 changes: 0 additions & 3 deletions app/scripts/lib/approval/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ describe('Approval Utils', () => {
);
});

// @ts-expect-error This function is missing from the Mocha type definitions
it.each([
ApprovalType.SnapDialogAlert,
ApprovalType.SnapDialogPrompt,
Expand All @@ -64,7 +63,6 @@ describe('Approval Utils', () => {
expect(approvalController.accept).toHaveBeenCalledWith(ID_MOCK, null);
});

// @ts-expect-error This function is missing from the Mocha type definitions
it.each([
ApprovalType.SnapDialogConfirmation,
SNAP_MANAGE_ACCOUNTS_CONFIRMATION_TYPES.confirmAccountCreation,
Expand All @@ -81,7 +79,6 @@ describe('Approval Utils', () => {
expect(approvalController.accept).toHaveBeenCalledWith(ID_MOCK, false);
});

// @ts-expect-error This function is missing from the Mocha type definitions
it.each([
ApprovalType.SnapDialogAlert,
ApprovalType.SnapDialogPrompt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ import createEvmMethodsToNonEvmAccountReqFilterMiddleware, {
} from './createEvmMethodsToNonEvmAccountReqFilterMiddleware';

describe('createEvmMethodsToNonEvmAccountReqFilterMiddleware', () => {
const getMockRequest = (method: string, params: Record<string, Json>) => ({
const getMockRequest = (
method: string,
params: Record<string, Json>[] | undefined,
) => ({
jsonrpc: jsonrpc2,
id: 1,
method,
params,
});
const getMockResponse = () => ({ jsonrpc: jsonrpc2, id: 'foo' });

// @ts-expect-error This function is missing from the Mocha type definitions
it.each([
// EVM requests
{
Expand Down Expand Up @@ -285,8 +287,8 @@ describe('createEvmMethodsToNonEvmAccountReqFilterMiddleware', () => {
}: {
accountType: EthAccountType | BtcAccountType;
method: string;
params: Record<string, Json>;
calledNext: number;
params: Record<string, Json>[] | undefined;
calledNext: boolean;
}) => {
const filterFn = createEvmMethodsToNonEvmAccountReqFilterMiddleware({
messenger: {
Expand Down
76 changes: 29 additions & 47 deletions app/scripts/lib/multichain/address.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,91 +4,73 @@ import {
normalizeSafeAddress,
} from './address';

type TestAddress = {
address: string;
normalizedAddress: string;
checksumAddress: string;
};

const ETH_ADDRESSES = [
// Lower-case address
{
address: '0x6431726eee67570bf6f0cf892ae0a3988f03903f',
normalizedAddress: '0x6431726eee67570bf6f0cf892ae0a3988f03903f',
checksumAddress: '0x6431726EEE67570BF6f0Cf892aE0a3988F03903F',
},
// Checksum address
{
address: '0x6431726EEE67570BF6f0Cf892aE0a3988F03903F',
normalizedAddress: '0x6431726eee67570bf6f0cf892ae0a3988f03903f',
checksumAddress: '0x6431726EEE67570BF6f0Cf892aE0a3988F03903F',
},
];
describe('address', () => {
const TEST_CASES_EVM_ADDRESSES = [
{
address: '0x6431726eee67570bf6f0cf892ae0a3988f03903f', // Lower-case address
normalizedAddress: '0x6431726eee67570bf6f0cf892ae0a3988f03903f',
checksumAddress: '0x6431726EEE67570BF6f0Cf892aE0a3988F03903F',
},
{
address: '0x6431726EEE67570BF6f0Cf892aE0a3988F03903F', // Checksum address
normalizedAddress: '0x6431726eee67570bf6f0cf892ae0a3988f03903f',
checksumAddress: '0x6431726EEE67570BF6f0Cf892aE0a3988F03903F',
},
];

const NON_EVM_ADDRESSES = [
{
address: '0xdeadbeef',
},
{
address: 'bc1ql49ydapnjafl5t2cp9zqpjwe6pdgmxy98859v2',
},
];
const TEST_CASES_NON_EVM_ADDRESSES = [
'0xdeadbeef',
'bc1ql49ydapnjafl5t2cp9zqpjwe6pdgmxy98859v2',
];

describe('address', () => {
describe('isEthAddress', () => {
// @ts-expect-error This is missing from the Mocha type definitions
it.each(ETH_ADDRESSES)(
it.each(TEST_CASES_EVM_ADDRESSES)(
'returns true if address is an ethereum address: $address',
({ address }: TestAddress) => {
({ address }) => {
expect(isEthAddress(address)).toBe(true);
expect(isEthAddress(address.toLowerCase())).toBe(true);
},
);

// @ts-expect-error This is missing from the Mocha type definitions
it.each(NON_EVM_ADDRESSES)(
it.each(TEST_CASES_NON_EVM_ADDRESSES)(
'returns false if address is not an ethereum address: $address',
({ address }: TestAddress) => {
(address) => {
expect(isEthAddress(address)).toBe(false);
},
);
});

describe('normalizeAddress', () => {
// @ts-expect-error This is missing from the Mocha type definitions
it.each(ETH_ADDRESSES)(
it.each(TEST_CASES_EVM_ADDRESSES)(
'normalizes address: $address',
({ address, normalizedAddress }: TestAddress) => {
({ address, normalizedAddress }) => {
expect(normalizeAddress(address)).toBe(normalizedAddress);
expect(normalizeAddress(address.toLowerCase())).toBe(normalizedAddress);
},
);

// @ts-expect-error This is missing from the Mocha type definitions
it.each(NON_EVM_ADDRESSES)(
it.each(TEST_CASES_NON_EVM_ADDRESSES)(
'returns the original address if its a non-EVM address',
({ address }: TestAddress) => {
(address) => {
expect(normalizeAddress(address)).toBe(address);
},
);
});

describe('normalizeSafeAddress', () => {
// @ts-expect-error This is missing from the Mocha type definitions
it.each(ETH_ADDRESSES)(
it.each(TEST_CASES_EVM_ADDRESSES)(
'normalizes address to its "safe" form: $address to: $checksumAddress',
({ address, checksumAddress }: TestAddress) => {
({ address, checksumAddress }) => {
expect(normalizeSafeAddress(address)).toBe(checksumAddress);
expect(normalizeSafeAddress(address.toLowerCase())).toBe(
checksumAddress,
);
},
);

// @ts-expect-error This is missing from the Mocha type definitions
it.each(NON_EVM_ADDRESSES)(
it.each(TEST_CASES_NON_EVM_ADDRESSES)(
'returns the original address if its a non-EVM address',
({ address }: TestAddress) => {
(address) => {
expect(normalizeSafeAddress(address)).toBe(address);
},
);
Expand Down
1 change: 0 additions & 1 deletion app/scripts/lib/ppom/ppom-util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ describe('PPOM Utils', () => {
);
});

// @ts-expect-error This is missing from the Mocha type definitions
it.each([METHOD_SIGN_TYPED_DATA_V3, METHOD_SIGN_TYPED_DATA_V4])(
'sanitizes request params if method is %s',
async (method: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ describe('createUnsupportedMethodMiddleware', () => {
expect(endMock).not.toHaveBeenCalled();
});

// @ts-expect-error This function is missing from the Mocha type definitions
it.each([...UNSUPPORTED_RPC_METHODS])(
'ends requests for default unsupported rpc methods when no list is provided: %s',
(method: string) => {
Expand All @@ -40,7 +39,6 @@ describe('createUnsupportedMethodMiddleware', () => {

const unsupportedMethods = new Set(['foo', 'bar']);

// @ts-expect-error This function is missing from the Mocha type definitions
it.each([...unsupportedMethods])(
'ends requests for methods that are in the provided list of unsupported methods: %s',
(method: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ describe('Ethereum Chain Utils', () => {
});
});

// @ts-expect-error This function is missing from the Mocha type definitions
describe.each([
['legacy', false],
['multichain', true],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ describe('revokePermissionsHandler', () => {
);
});

// @ts-expect-error This is missing from the Mocha type definitions
describe.each([
[RestrictedMethods.eth_accounts],
[PermissionNames.permittedChains],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ describe('keyringSnapPermissionsBuilder', () => {
});

describe('Portfolio origin', () => {
// @ts-expect-error This is missing from the Mocha type definitions
it.each(PORTFOLIO_ORIGINS)(
'returns the methods that can be called by %s',
(origin: string) => {
Expand All @@ -49,7 +48,6 @@ describe('keyringSnapPermissionsBuilder', () => {
},
);

// @ts-expect-error This is missing from the Mocha type definitions
it.each(PORTFOLIO_ORIGINS)(
'%s cannot create an account',
(origin: string) => {
Expand All @@ -61,7 +59,6 @@ describe('keyringSnapPermissionsBuilder', () => {
},
);

// @ts-expect-error This is missing from the Mocha type definitions
it.each(PORTFOLIO_ORIGINS)('%s can submit a request', (origin: string) => {
const permissions = keyringSnapPermissionsBuilder(mockController, origin);
expect(permissions()).toContain(KeyringRpcMethod.SubmitRequest);
Expand Down Expand Up @@ -113,7 +110,6 @@ describe('keyringSnapPermissionsBuilder', () => {
expect(permissions()).toStrictEqual([]);
});

// @ts-expect-error This is missing from the Mocha type definitions
it.each([
'',
'null',
Expand All @@ -139,7 +135,6 @@ describe('keyringSnapPermissionsBuilder', () => {
});

describe('isProtocolAllowed', () => {
// @ts-expect-error This is missing from the Mocha type definitions
it.each([
['http://some-dapp.com', true],
['https://some-dapp.com', true],
Expand Down
1 change: 0 additions & 1 deletion app/scripts/lib/snap-keyring/utils/isBlockedUrl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ describe('isBlockedUrl', () => {
},
});

// @ts-expect-error This is missing from the Mocha type definitions
it.each([
['http://metamask.io', false],
['https://metamask.io', false],
Expand Down
1 change: 0 additions & 1 deletion app/scripts/lib/transaction/eip5792.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,6 @@ describe('EIP-5792', () => {
);
});

// @ts-expect-error This function is missing from the Mocha type definitions
it.each([
TransactionStatus.approved,
TransactionStatus.signed,
Expand Down
44 changes: 21 additions & 23 deletions app/scripts/lib/tx-verification/tx-verification-middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ describe('tx verification middleware', () => {
expect(end).not.toHaveBeenCalled();
});

// @ts-expect-error Our test types are broken
it.each([
['null', null],
['string', 'foo'],
Expand All @@ -75,29 +74,29 @@ describe('tx verification middleware', () => {
'non-"0x"-prefixed "chainId"',
[{ data: 'data', from: 'from', to: 'to', value: 'value', chainId: '1' }],
],
])(
'ignores invalid params: %s',
(_: string, invalidParams: JsonRpcParams) => {
const middleware = createTxVerificationMiddleware(
getMockNetworkController(),
mockTrustedSigners,
);
])('ignores invalid params: %s', (_: string, invalidParams) => {
const middleware = createTxVerificationMiddleware(
getMockNetworkController(),
mockTrustedSigners,
);

const { req, res, next, end } = getMiddlewareParams(
'eth_sendTransaction',
invalidParams,
);
middleware(req, res, next, end);
const { req, res, next, end } = getMiddlewareParams(
'eth_sendTransaction',
invalidParams as JsonRpcParams,
);
middleware(req, res, next, end);

expect(next).toHaveBeenCalledTimes(1);
expect(end).not.toHaveBeenCalled();
},
);
expect(next).toHaveBeenCalledTimes(1);
expect(end).not.toHaveBeenCalled();
});

// @ts-expect-error Our test types are broken
it.each(Object.keys(FIRST_PARTY_CONTRACT_NAMES['MetaMask Bridge']))(
it.each(
Object.keys(
FIRST_PARTY_CONTRACT_NAMES[EXPERIENCES_TYPE.METAMASK_BRIDGE],
) as Hex[],
)(
'ignores transactions that are not addressed to the bridge contract for chain %s',
(chainId: `0x${string}`) => {
(chainId) => {
const middleware = createTxVerificationMiddleware(
getMockNetworkController(),
mockTrustedSigners,
Expand All @@ -114,10 +113,9 @@ describe('tx verification middleware', () => {
},
);

// @ts-expect-error Our test types are broken
it.each(['0x11111', '0x111', '0x222222'])(
it.each(['0x11111', '0x111', '0x222222'] as Hex[])(
'ignores transactions that do not have a bridge contract deployed for chain %s',
(chainId: `0x${string}`) => {
(chainId) => {
const middleware = createTxVerificationMiddleware(
getMockNetworkController(),
mockTrustedSigners,
Expand Down
1 change: 0 additions & 1 deletion app/scripts/migrations/095.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ describe('migration #95', () => {
});
});

// @ts-expect-error This is missing from the Mocha type definitions
it.each([
['undefined', undefined],
['empty', {}],
Expand Down
1 change: 0 additions & 1 deletion app/scripts/migrations/121.1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ describe('migration #121.1', () => {
},
];

// @ts-expect-error 'each' function missing from type definitions, but it does exist
it.each(invalidState)(
'captures error when state is invalid due to: $label',
async ({
Expand Down
1 change: 0 additions & 1 deletion app/scripts/migrations/131.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ describe(`migration #${version}`, () => {
},
];

// @ts-expect-error 'each' function missing from type definitions, but it does exist
it.each(invalidState)(
'captures error when state is invalid due to: $label',
async ({
Expand Down
Loading
Loading