Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.
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
4 changes: 4 additions & 0 deletions packages/web3-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,7 @@ Documentation:
[Migration Guide from 1.x](https://docs.web3js.org/guides/web3_upgrade_guide/x/)

## [Unreleased]

### Fixed

- Fixed Batch requests erroring out on one request (#6164)
20 changes: 20 additions & 0 deletions packages/web3-eth/test/integration/batch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ describe('eth', () => {
});

describe('methods', () => {
it('executes one batch request', async () => {
const acc1 = await createTempAccount();

const batch = new web3Eth.BatchRequest();
const request1 = {
id: 10,
method: 'eth_getBalance',
params: [acc1.address, 'latest'],
};
const r1 = batch.add(request1).catch(console.error);
const [response1] = await batch.execute();

// eslint-disable-next-line jest/no-standalone-expect
expect(response1.result).toBeDefined();
// TODO: in future release add test for validation of returned results , ( match balance )
// eslint-disable-next-line jest/no-standalone-expect
expect(Number(hexToNumber(String(response1.result)))).toBeGreaterThan(0);
const [res1] = await Promise.all([r1]);
expect(res1).toBe(response1.result);
});
it('BatchRequest', async () => {
const acc1 = await createTempAccount();
const acc2 = await createTempAccount();
Expand Down
4 changes: 2 additions & 2 deletions packages/web3-utils/src/json_rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const isValidResponse = <Result = unknown, Error = unknown>(
export const isBatchResponse = <Result = unknown, Error = unknown>(
response: JsonRpcResponse<Result, Error>,
): response is JsonRpcBatchResponse<Result, Error> =>
Array.isArray(response) && response.length > 1 && isValidResponse(response);
Array.isArray(response) && response.length > 0 && isValidResponse(response);

// internal optional variable to increment and use for the jsonrpc `id`
let requestIdSeed: number | undefined;
Expand Down Expand Up @@ -127,4 +127,4 @@ export const toBatchPayload = (requests: JsonRpcOptionalRequest<unknown>[]): Jso

export const isBatchRequest = (
request: JsonRpcBatchRequest | JsonRpcRequest<unknown> | JsonRpcOptionalRequest<unknown>,
): request is JsonRpcBatchRequest => Array.isArray(request) && request.length > 1;
): request is JsonRpcBatchRequest => Array.isArray(request) && request.length > 0;