Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { testsForRpcMethodsThatCheckForBlockHashInResponse } from '../../../tests/network-client/block-hash-in-response';
import { NetworkClientType } from '../../types';

describe('createNetworkClient - methods included in the Ethereum JSON-RPC spec - methods with block hashes in their result', () => {
for (const networkClientType of [
NetworkClientType.Infura,
NetworkClientType.Custom,
]) {
const methodsWithBlockHashInResponse = [
{ name: 'eth_getTransactionByHash', numberOfParameters: 1 },
{ name: 'eth_getTransactionReceipt', numberOfParameters: 1 },
];
methodsWithBlockHashInResponse.forEach(({ name, numberOfParameters }) => {
describe(`method name: ${name}`, () => {
testsForRpcMethodsThatCheckForBlockHashInResponse(name, {
numberOfParameters,
providerType: networkClientType,
});
});
});
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { testsForRpcMethodSupportingBlockParam } from '../../../tests/network-client/block-param';
import { NetworkClientType } from '../../types';

describe('createNetworkClient - methods included in the Ethereum JSON-RPC spec - methods that have a param to specify the block', () => {
for (const networkClientType of [
NetworkClientType.Infura,
NetworkClientType.Custom,
]) {
const supportingBlockParam = [
{
name: 'eth_call',
blockParamIndex: 1,
numberOfParameters: 2,
},
{
name: 'eth_getBalance',
blockParamIndex: 1,
numberOfParameters: 2,
},
{
name: 'eth_getBlockByNumber',
blockParamIndex: 0,
numberOfParameters: 2,
},
{ name: 'eth_getCode', blockParamIndex: 1, numberOfParameters: 2 },
{
name: 'eth_getStorageAt',
blockParamIndex: 2,
numberOfParameters: 3,
},
{
name: 'eth_getTransactionCount',
blockParamIndex: 1,
numberOfParameters: 2,
},
];
supportingBlockParam.forEach(
({ name, blockParamIndex, numberOfParameters }) => {
describe(`method name: ${name}`, () => {
testsForRpcMethodSupportingBlockParam(name, {
providerType: networkClientType,
blockParamIndex,
numberOfParameters,
});
});
},
);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { testsForRpcMethodAssumingNoBlockParam } from '../../../tests/network-client/no-block-param';
import { NetworkClientType } from '../../types';

describe('createNetworkClient - methods included in the Ethereum JSON-RPC spec - methods that assume there is no block param', () => {
for (const networkClientType of [
NetworkClientType.Infura,
NetworkClientType.Custom,
]) {
const assumingNoBlockParam = [
{ name: 'eth_getFilterLogs', numberOfParameters: 1 },
{ name: 'eth_blockNumber', numberOfParameters: 0 },
{ name: 'eth_estimateGas', numberOfParameters: 2 },
{ name: 'eth_gasPrice', numberOfParameters: 0 },
{ name: 'eth_getBlockByHash', numberOfParameters: 2 },
{
name: 'eth_getBlockTransactionCountByHash',
numberOfParameters: 1,
},
{
name: 'eth_getTransactionByBlockHashAndIndex',
numberOfParameters: 2,
},
{ name: 'eth_getUncleByBlockHashAndIndex', numberOfParameters: 2 },
{ name: 'eth_getUncleCountByBlockHash', numberOfParameters: 1 },
];
const blockParamIgnored = [
{ name: 'eth_getUncleCountByBlockNumber', numberOfParameters: 1 },
{ name: 'eth_getUncleByBlockNumberAndIndex', numberOfParameters: 2 },
{
name: 'eth_getTransactionByBlockNumberAndIndex',
numberOfParameters: 2,
},
{
name: 'eth_getBlockTransactionCountByNumber',
numberOfParameters: 1,
},
];
assumingNoBlockParam
.concat(blockParamIgnored)
.forEach(({ name, numberOfParameters }) =>
describe(`method name: ${name}`, () => {
testsForRpcMethodAssumingNoBlockParam(name, {
providerType: networkClientType,
numberOfParameters,
});
}),
);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { testsForRpcMethodNotHandledByMiddleware } from '../../../tests/network-client/not-handled-by-middleware';
import { NetworkClientType } from '../../types';

describe('createNetworkClient - methods included in the Ethereum JSON-RPC spec - methods not handled by middleware', () => {
for (const networkClientType of [
NetworkClientType.Infura,
NetworkClientType.Custom,
]) {
const notHandledByMiddleware = [
{ name: 'eth_newFilter', numberOfParameters: 1 },
{ name: 'eth_getFilterChanges', numberOfParameters: 1 },
{ name: 'eth_newBlockFilter', numberOfParameters: 0 },
{ name: 'eth_newPendingTransactionFilter', numberOfParameters: 0 },
{ name: 'eth_uninstallFilter', numberOfParameters: 1 },

{ name: 'eth_sendRawTransaction', numberOfParameters: 1 },
{ name: 'eth_sendTransaction', numberOfParameters: 1 },
{ name: 'eth_createAccessList', numberOfParameters: 2 },
{ name: 'eth_getLogs', numberOfParameters: 1 },
{ name: 'eth_getProof', numberOfParameters: 3 },
{ name: 'eth_getWork', numberOfParameters: 0 },
{ name: 'eth_maxPriorityFeePerGas', numberOfParameters: 0 },
{ name: 'eth_submitHashRate', numberOfParameters: 2 },
{ name: 'eth_submitWork', numberOfParameters: 3 },
{ name: 'eth_syncing', numberOfParameters: 0 },
{ name: 'eth_feeHistory', numberOfParameters: 3 },
{ name: 'debug_getRawHeader', numberOfParameters: 1 },
{ name: 'debug_getRawBlock', numberOfParameters: 1 },
{ name: 'debug_getRawTransaction', numberOfParameters: 1 },
{ name: 'debug_getRawReceipts', numberOfParameters: 1 },
{ name: 'debug_getBadBlocks', numberOfParameters: 0 },

{ name: 'eth_accounts', numberOfParameters: 0 },
{ name: 'eth_coinbase', numberOfParameters: 0 },
{ name: 'eth_hashrate', numberOfParameters: 0 },
{ name: 'eth_mining', numberOfParameters: 0 },

{ name: 'eth_signTransaction', numberOfParameters: 1 },
];
notHandledByMiddleware.forEach(({ name, numberOfParameters }) => {
// This is a valid title.
// eslint-disable-next-line jest/valid-title
describe(name, () => {
testsForRpcMethodNotHandledByMiddleware(name, {
providerType: networkClientType,
numberOfParameters,
});
});
});
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import {
withMockedCommunications,
withNetworkClient,
} from '../../../tests/network-client/helpers';
import { NetworkClientType } from '../../types';

describe('createNetworkClient - methods included in the Ethereum JSON-RPC spec - other methods', () => {
for (const networkClientType of [
NetworkClientType.Infura,
NetworkClientType.Custom,
]) {
describe('eth_getTransactionByHash', () => {
it("refreshes the block tracker's current block if it is less than the block number that comes back in the response", async () => {
const method = 'eth_getTransactionByHash';

await withMockedCommunications(
{ providerType: networkClientType },
async (comms) => {
const request = { method };

comms.mockNextBlockTrackerRequest({ blockNumber: '0x100' });
// This is our request.
comms.mockRpcCall({
request,
response: {
result: {
blockNumber: '0x200',
},
},
});
comms.mockNextBlockTrackerRequest({ blockNumber: '0x300' });

await withNetworkClient(
{ providerType: networkClientType },
async ({ makeRpcCall, blockTracker }) => {
await makeRpcCall(request);
expect(blockTracker.getCurrentBlock()).toBe('0x300');
},
);
},
);
});
});

describe('eth_getTransactionReceipt', () => {
it("refreshes the block tracker's current block if it is less than the block number that comes back in the response", async () => {
const method = 'eth_getTransactionReceipt';

await withMockedCommunications(
{ providerType: networkClientType },
async (comms) => {
const request = { method };

comms.mockNextBlockTrackerRequest({ blockNumber: '0x100' });
// This is our request.
comms.mockRpcCall({
request,
response: {
result: {
blockNumber: '0x200',
},
},
});
comms.mockNextBlockTrackerRequest({ blockNumber: '0x300' });

await withNetworkClient(
{ providerType: networkClientType },
async ({ makeRpcCall, blockTracker }) => {
await makeRpcCall(request);
expect(blockTracker.getCurrentBlock()).toBe('0x300');
},
);
},
);
});
});

if (networkClientType === NetworkClientType.Custom) {
describe('eth_chainId', () => {
it('does not hit the RPC endpoint, instead returning the configured chain id', async () => {
const chainId = await withNetworkClient(
{ providerType: networkClientType, customChainId: '0x1' },
({ makeRpcCall }) => {
return makeRpcCall({ method: 'eth_chainId' });
},
);

expect(chainId).toBe('0x1');
});
});
}
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { testsForRpcMethodAssumingNoBlockParam } from '../../../tests/network-client/no-block-param';
import { NetworkClientType } from '../../types';

describe('createNetworkClient - methods not included in the Ethereum JSON-RPC spec - methods that assume there is no block param', () => {
for (const networkClientType of [
NetworkClientType.Infura,
NetworkClientType.Custom,
]) {
const assumingNoBlockParam = [
{ name: 'web3_clientVersion', numberOfParameters: 0 },
{ name: 'eth_protocolVersion', numberOfParameters: 0 },
];
assumingNoBlockParam.forEach(({ name, numberOfParameters }) =>
describe(`method name: ${name}`, () => {
testsForRpcMethodAssumingNoBlockParam(name, {
providerType: networkClientType,
numberOfParameters,
});
}),
);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { testsForRpcMethodNotHandledByMiddleware } from '../../../tests/network-client/not-handled-by-middleware';
import { NetworkClientType } from '../../types';

describe('createNetworkClient - methods not included in the Ethereum JSON-RPC spec - methods not handled by middleware', () => {
for (const networkClientType of [
NetworkClientType.Infura,
NetworkClientType.Custom,
]) {
const notHandledByMiddleware = [
{ name: 'net_listening', numberOfParameters: 0 },
{ name: 'eth_subscribe', numberOfParameters: 1 },
{ name: 'eth_unsubscribe', numberOfParameters: 1 },
{ name: 'custom_rpc_method', numberOfParameters: 1 },
{ name: 'net_peerCount', numberOfParameters: 0 },
{ name: 'parity_nextNonce', numberOfParameters: 1 },
];
notHandledByMiddleware.forEach(({ name, numberOfParameters }) => {
describe(`method name: ${name}`, () => {
testsForRpcMethodNotHandledByMiddleware(name, {
providerType: networkClientType,
numberOfParameters,
});
});
});
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { TESTNET } from '../../../tests/helpers';
import {
withMockedCommunications,
withNetworkClient,
} from '../../../tests/network-client/helpers';
import { NetworkClientType } from '../../types';

describe('createNetworkClient - methods not included in the Ethereum JSON-RPC spec - other methods', () => {
for (const networkClientType of [
NetworkClientType.Infura,
NetworkClientType.Custom,
]) {
describe('net_version', () => {
const networkArgs = {
providerType: networkClientType,
infuraNetwork:
networkClientType === NetworkClientType.Infura
? TESTNET.networkType
: undefined,
} as const;

it('hits the RPC endpoint', async () => {
await withMockedCommunications(networkArgs, async (comms) => {
comms.mockRpcCall({
request: { method: 'net_version' },
response: { result: '1' },
});

const networkId = await withNetworkClient(
networkArgs,
({ makeRpcCall }) => {
return makeRpcCall({
method: 'net_version',
});
},
);

expect(networkId).toBe('1');
});
});
});
}
});

This file was deleted.

Loading
Loading