Skip to content

Commit

Permalink
Fix tests to initialize mock eth query using FakeProvider type
Browse files Browse the repository at this point in the history
  • Loading branch information
MajorLift committed Nov 15, 2023
1 parent bb7f348 commit 687d3eb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
17 changes: 10 additions & 7 deletions packages/controller-utils/src/util.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import EthQuery, { type Provider } from '@metamask/eth-query';
import EthQuery from '@metamask/eth-query';
import { BN } from 'ethereumjs-util';
import nock from 'nock';

import { FakeProvider } from '../../../tests/fake-provider';
import { MAX_SAFE_CHAIN_ID } from './constants';
import * as util from './util';

Expand Down Expand Up @@ -443,7 +444,7 @@ describe('util', () => {
}
}
const result = await util.query(
new MockEthQuery({} as Provider),
new MockEthQuery(new FakeProvider()),
'getBlockByHash',
['0x1234'],
);
Expand All @@ -457,7 +458,7 @@ describe('util', () => {
}
}
await expect(
util.query(new MockEthQuery({} as Provider), 'getBlockByHash', [
util.query(new MockEthQuery(new FakeProvider()), 'getBlockByHash', [
'0x1234',
]),
).rejects.toThrow('uh oh');
Expand All @@ -475,7 +476,7 @@ describe('util', () => {
}
}
const result = await util.query(
new MockEthQuery({} as Provider),
new MockEthQuery(new FakeProvider()),
'eth_getBlockByHash',
['0x1234'],
);
Expand All @@ -489,9 +490,11 @@ describe('util', () => {
}
}
await expect(
util.query(new MockEthQuery({} as Provider), 'eth_getBlockByHash', [
'0x1234',
]),
util.query(
new MockEthQuery(new FakeProvider()),
'eth_getBlockByHash',
['0x1234'],
),
).rejects.toThrow('uh oh');
});
});
Expand Down
5 changes: 3 additions & 2 deletions packages/gas-fee-controller/src/fetchBlockFeeHistory.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { query, fromHex, toHex } from '@metamask/controller-utils';
import EthQuery, { type Provider } from '@metamask/eth-query';
import EthQuery from '@metamask/eth-query';
import { BN } from 'ethereumjs-util';
import { when } from 'jest-when';

import { FakeProvider } from '../../../tests/fake-provider';
import fetchBlockFeeHistory from './fetchBlockFeeHistory';

jest.mock('@metamask/controller-utils', () => {
Expand Down Expand Up @@ -34,7 +35,7 @@ function times<T>(n: number, fn: (n: number) => T): T[] {
}

describe('fetchBlockFeeHistory', () => {
const mockEthQuery = new EthQuery({} as Provider);
const mockEthQuery = new EthQuery(new FakeProvider());
describe('with a minimal set of arguments', () => {
const latestBlockNumber = 3;
const numberOfRequestedBlocks = 3;
Expand Down
27 changes: 14 additions & 13 deletions packages/transaction-controller/src/utils/transaction-type.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import EthQuery, { type Provider } from '@metamask/eth-query';
import EthQuery from '@metamask/eth-query';

import { FakeProvider } from '../../../../tests/fake-provider';
import { TransactionType } from '../types';
import { determineTransactionType } from './transaction-type';

Expand All @@ -23,7 +24,7 @@ describe('determineTransactionType', () => {
data: '0xa9059cbb0000000000000000000000002f318C334780961FB129D2a6c30D0763d9a5C970000000000000000000000000000000000000000000000000000000000000000a',
from: FROM_MOCK,
},
new MockEthQuery({} as Provider),
new MockEthQuery(new FakeProvider()),
);

expect(result).toMatchObject({
Expand All @@ -44,7 +45,7 @@ describe('determineTransactionType', () => {
const resultWithEmptyValue = await determineTransactionType(
txParams,

new MockEthQuery({} as Provider),
new MockEthQuery(new FakeProvider()),
);
expect(resultWithEmptyValue).toMatchObject({
type: TransactionType.tokenMethodTransfer,
Expand All @@ -57,7 +58,7 @@ describe('determineTransactionType', () => {
...txParams,
},

new MockEthQuery({} as Provider),
new MockEthQuery(new FakeProvider()),
);

expect(resultWithEmptyValue2).toMatchObject({
Expand All @@ -71,7 +72,7 @@ describe('determineTransactionType', () => {
...txParams,
},

new MockEthQuery({} as Provider),
new MockEthQuery(new FakeProvider()),
);
expect(resultWithValue).toMatchObject({
type: TransactionType.contractInteraction,
Expand All @@ -88,7 +89,7 @@ describe('determineTransactionType', () => {
}
const result = await determineTransactionType(
txParams,
new MockEthQuery({} as Provider),
new MockEthQuery(new FakeProvider()),
);
expect(result).toMatchObject({
type: TransactionType.simpleSend,
Expand All @@ -107,7 +108,7 @@ describe('determineTransactionType', () => {
...txParams,
data: '0x095ea7b30000000000000000000000002f318C334780961FB129D2a6c30D0763d9a5C9700000000000000000000000000000000000000000000000000000000000000005',
},
new MockEthQuery({} as Provider),
new MockEthQuery(new FakeProvider()),
);
expect(result).toMatchObject({
type: TransactionType.tokenMethodApprove,
Expand All @@ -127,7 +128,7 @@ describe('determineTransactionType', () => {
to: '',
data: '0xabd',
},
new MockEthQuery({} as Provider),
new MockEthQuery(new FakeProvider()),
);
expect(result).toMatchObject({
type: TransactionType.deployContract,
Expand All @@ -146,7 +147,7 @@ describe('determineTransactionType', () => {
...txParams,
data: '0xabd',
},
new MockEthQuery({} as Provider),
new MockEthQuery(new FakeProvider()),
);
expect(result).toMatchObject({
type: TransactionType.simpleSend,
Expand All @@ -165,7 +166,7 @@ describe('determineTransactionType', () => {
...txParams,
data: '0xabd',
},
new MockEthQuery({} as Provider),
new MockEthQuery(new FakeProvider()),
);
expect(result).toMatchObject({
type: TransactionType.simpleSend,
Expand All @@ -184,7 +185,7 @@ describe('determineTransactionType', () => {
...txParams,
data: 'abd',
},
new MockEthQuery({} as Provider),
new MockEthQuery(new FakeProvider()),
);
expect(result).toMatchObject({
type: TransactionType.contractInteraction,
Expand All @@ -203,7 +204,7 @@ describe('determineTransactionType', () => {
...txParams,
data: '',
},
new MockEthQuery({} as Provider),
new MockEthQuery(new FakeProvider()),
);
expect(result).toMatchObject({
type: TransactionType.contractInteraction,
Expand All @@ -224,7 +225,7 @@ describe('determineTransactionType', () => {
value: '0x5af3107a4000',
data: '0x095ea7b30000000000000000000000002f318C334780961FB129D2a6c30D0763d9a5C9700000000000000000000000000000000000000000000000000000000000000005',
},
new MockEthQuery({} as Provider),
new MockEthQuery(new FakeProvider()),
);
expect(result).toMatchObject({
type: TransactionType.contractInteraction,
Expand Down

0 comments on commit 687d3eb

Please sign in to comment.