fix: handle empty rpc batch requests properly (#16254)
This commit is contained in:
parent
c344702fa0
commit
2c94c6f8e8
|
@ -722,6 +722,9 @@ function createRpcRequest(client: RpcClient): RpcRequest {
|
||||||
function createRpcBatchRequest(client: RpcClient): RpcBatchRequest {
|
function createRpcBatchRequest(client: RpcClient): RpcBatchRequest {
|
||||||
return (requests: RpcParams[]) => {
|
return (requests: RpcParams[]) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
// Do nothing if requests is empty
|
||||||
|
if (requests.length === 0) resolve([]);
|
||||||
|
|
||||||
const batch = requests.map((params: RpcParams) => {
|
const batch = requests.map((params: RpcParams) => {
|
||||||
return client.request(params.methodName, params.args);
|
return client.request(params.methodName, params.args);
|
||||||
});
|
});
|
||||||
|
|
|
@ -894,7 +894,7 @@ describe('Connection', () => {
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await connection.getParsedConfirmedTransactions([
|
let result = await connection.getParsedConfirmedTransactions([
|
||||||
confirmedTransaction,
|
confirmedTransaction,
|
||||||
confirmedTransaction,
|
confirmedTransaction,
|
||||||
]);
|
]);
|
||||||
|
@ -913,6 +913,14 @@ describe('Connection', () => {
|
||||||
if (result[1] !== null) {
|
if (result[1] !== null) {
|
||||||
expect(result[1].transaction.signatures).not.to.be.null;
|
expect(result[1].transaction.signatures).not.to.be.null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result = await connection.getParsedConfirmedTransactions([]);
|
||||||
|
if (!result) {
|
||||||
|
expect(result).to.be.ok;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(result).to.be.empty;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('get confirmed transaction', async () => {
|
it('get confirmed transaction', async () => {
|
||||||
|
|
Loading…
Reference in New Issue