Skip to content

Commit

Permalink
stash
Browse files Browse the repository at this point in the history
  • Loading branch information
MajorLift committed Nov 14, 2023
1 parent c9c9507 commit 0a03684
Show file tree
Hide file tree
Showing 6 changed files with 1,132 additions and 87 deletions.
1 change: 1 addition & 0 deletions packages/controller-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"devDependencies": {
"@metamask/auto-changelog": "^3.4.3",
"@metamask/eth-query": "^4.0.0",
"@metamask/network-controller": "^4.0.0",
"@types/jest": "^27.4.1",
"deepmerge": "^4.2.2",
"jest": "^27.5.1",
Expand Down
34 changes: 6 additions & 28 deletions packages/controller-utils/src/util.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import EthQuery, { type Provider } from '@metamask/eth-query';
import EthQuery from '@metamask/eth-query';
import { FakeProvider } from '@metamask/network-controller';
import { BN } from 'ethereumjs-util';
import nock from 'nock';

Expand Down Expand Up @@ -437,27 +438,17 @@ describe('util', () => {
describe('query', () => {
describe('when the given method exists directly on the EthQuery', () => {
it('should call the method on the EthQuery and, if it is successful, return a promise that resolves to the result', async () => {
class MockEthQuery extends EthQuery {
getBlockByHash(blockId: any, cb: any) {
cb(null, { id: blockId });
}
}
const result = await util.query(
new MockEthQuery({} as Provider),
new EthQuery(new FakeProvider()),
'getBlockByHash',
['0x1234'],
);
expect(result).toStrictEqual({ id: '0x1234' });
});

it('should call the method on the EthQuery and, if it errors, return a promise that is rejected with the error', async () => {
class MockEthQuery extends EthQuery {
getBlockByHash(_blockId: any, cb: any) {
cb(new Error('uh oh'), null);
}
}
await expect(
util.query(new MockEthQuery({} as Provider), 'getBlockByHash', [
util.query(new EthQuery(new FakeProvider()), 'getBlockByHash', [
'0x1234',
]),
).rejects.toThrow('uh oh');
Expand All @@ -466,30 +457,17 @@ describe('util', () => {

describe('when the given method does not exist directly on the EthQuery', () => {
it('should use sendAsync to call the RPC endpoint and, if it is successful, return a promise that resolves to the result', async () => {
class MockEthQuery extends EthQuery {
sendAsync({ method, params }: any, cb: any) {
if (method === 'eth_getBlockByHash') {
return cb(null, { id: params[0] });
}
throw new Error(`Unsupported method ${method}`);
}
}
const result = await util.query(
new MockEthQuery({} as Provider),
new EthQuery(new FakeProvider()),
'eth_getBlockByHash',
['0x1234'],
);
expect(result).toStrictEqual({ id: '0x1234' });
});

it('should use sendAsync to call the RPC endpoint and, if it errors, return a promise that is rejected with the error', async () => {
class MockEthQuery extends EthQuery {
sendAsync(_args: any, cb: any) {
cb(new Error('uh oh'), null);
}
}
await expect(
util.query(new MockEthQuery({} as Provider), 'eth_getBlockByHash', [
util.query(new EthQuery(new FakeProvider()), 'eth_getBlockByHash', [
'0x1234',
]),
).rejects.toThrow('uh oh');
Expand Down
1 change: 1 addition & 0 deletions packages/controller-utils/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"outDir": "./dist",
"rootDir": "./src"
},
"references": [{ "path": "../network-controller/tsconfig.build.json" }],
"include": ["../../types", "./src"]
}
1 change: 1 addition & 0 deletions packages/controller-utils/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"baseUrl": "./",
"lib": ["ES2017", "DOM"]
},
"references": [{ "path": "../network-controller" }],
"include": ["../../types", "./src"]
}
1 change: 1 addition & 0 deletions packages/network-controller/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export type { BlockTracker, Provider } from './types';
export type { NetworkClientConfiguration } from './types';
export { NetworkClientType } from './types';
export type { NetworkClient } from './create-network-client';
export { FakeProvider } from '../tests/fake-provider';
Loading

0 comments on commit 0a03684

Please sign in to comment.