fix: fix TypeError when confirmed block is not found (#13264)
This commit is contained in:
@ -2535,10 +2535,11 @@ export class Connection {
|
|||||||
*/
|
*/
|
||||||
async getConfirmedBlock(slot: number): Promise<ConfirmedBlock> {
|
async getConfirmedBlock(slot: number): Promise<ConfirmedBlock> {
|
||||||
const unsafeRes = await this._rpcRequest('getConfirmedBlock', [slot]);
|
const unsafeRes = await this._rpcRequest('getConfirmedBlock', [slot]);
|
||||||
const {result, error} = GetConfirmedBlockRpcResult(unsafeRes);
|
const res = GetConfirmedBlockRpcResult(unsafeRes);
|
||||||
if (error) {
|
if (res.error) {
|
||||||
throw new Error('failed to get confirmed block: ' + result.error.message);
|
throw new Error('failed to get confirmed block: ' + res.error.message);
|
||||||
}
|
}
|
||||||
|
const result = res.result;
|
||||||
assert(typeof result !== 'undefined');
|
assert(typeof result !== 'undefined');
|
||||||
if (!result) {
|
if (!result) {
|
||||||
throw new Error('Confirmed block ' + slot + ' not found');
|
throw new Error('Confirmed block ' + slot + ' not found');
|
||||||
|
@ -1120,13 +1120,15 @@ test('get confirmed block', async () => {
|
|||||||
params: [Number.MAX_SAFE_INTEGER],
|
params: [Number.MAX_SAFE_INTEGER],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
error: null,
|
error: {
|
||||||
|
message: `Block not available for slot ${Number.MAX_SAFE_INTEGER}`,
|
||||||
|
},
|
||||||
result: null,
|
result: null,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
await expect(
|
await expect(
|
||||||
connection.getConfirmedBlock(Number.MAX_SAFE_INTEGER),
|
connection.getConfirmedBlock(Number.MAX_SAFE_INTEGER),
|
||||||
).rejects.toThrow();
|
).rejects.toThrow(`Block not available for slot ${Number.MAX_SAFE_INTEGER}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('get recent blockhash', async () => {
|
test('get recent blockhash', async () => {
|
||||||
|
Reference in New Issue
Block a user