web3.js: add support for batch getParsedConfirmedTransactions (#16001)

* feat: add support for batch requests

* feat: get confirmed transactions batch

* feat: test get parsed confirmed transactions

* fix: run prettier

* fix: test uses one signature

* fix: fix docs and return type on ParsedConfirmedTransactions

* fix: null values in test
This commit is contained in:
Josh
2021-03-22 10:22:59 -07:00
committed by GitHub
parent a2dae8e8d4
commit 63d0c78b20
3 changed files with 367 additions and 4 deletions

View File

@ -5,7 +5,7 @@ import * as mockttp from 'mockttp';
import {mockRpcMessage} from './rpc-websockets';
import {Account, Connection, PublicKey, Transaction} from '../../src';
import type {Commitment} from '../../src/connection';
import type {Commitment, RpcParams} from '../../src/connection';
export const mockServer: mockttp.Mockttp | undefined =
process.env.TEST_LIVE === undefined ? mockttp.getLocal() : undefined;
@ -24,6 +24,40 @@ export const mockErrorResponse = {
message: mockErrorMessage,
};
export const mockRpcBatchResponse = async ({
batch,
result,
error,
}: {
batch: RpcParams[];
result: any[];
error?: string;
}) => {
if (!mockServer) return;
const request = batch.map((batch: RpcParams) => {
return {
jsonrpc: '2.0',
method: batch.methodName,
params: batch.args,
};
});
const response = result.map((result: any) => {
return {
jsonrpc: '2.0',
id: '',
result,
error,
};
});
await mockServer
.post('/')
.withJsonBodyIncluding(request)
.thenReply(200, JSON.stringify(response));
};
export const mockRpcResponse = async ({
method,
params,