feat: add getConfirmedBlock api

This commit is contained in:
Justin Starry
2019-11-16 11:28:14 -05:00
committed by Michael Vines
parent 5212a98b83
commit 3c08e5b9c4
3 changed files with 114 additions and 98 deletions

View File

@ -419,50 +419,7 @@ test('get minimum balance for rent exemption', async () => {
expect(count).toBeGreaterThanOrEqual(0);
});
test('get blocks since slot', async () => {
const connection = new Connection(url);
const expectedBlocks = [0, 1, 3, 4, 7, 8];
mockRpc.push([
url,
{
method: 'getBlocksSince',
params: [0],
},
{
error: null,
result: expectedBlocks,
},
]);
const blocks = await connection.getBlocksSince(0);
if (mockRpcEnabled) {
expect(blocks.length).toEqual(6);
} else {
// No idea how many blocks since slot 0 on a live cluster
expect(blocks.length).toBeGreaterThan(0);
}
const errorMessage = 'Slot 10000: SlotNotRooted';
mockRpc.push([
url,
{
method: 'getBlocksSince',
params: [10000],
},
{
error: {
message: errorMessage,
},
result: undefined,
},
]);
await expect(connection.getBlocksSince(10000)).rejects.toThrow(errorMessage);
});
test('get block', async () => {
test('get confirmed block', async () => {
if (mockRpcEnabled) {
console.log('non-live test skipped');
return;
@ -470,10 +427,10 @@ test('get block', async () => {
const connection = new Connection(url);
// These test cases need to be updated when upstream solana RPC api is fleshed out
const zeroTransactions = await connection.getBlock(0);
const zeroTransactions = await connection.getConfirmedBlock(0);
expect(zeroTransactions.length).toBe(0);
const oneTransaction = await connection.getBlock(1);
const oneTransaction = await connection.getConfirmedBlock(1);
expect(oneTransaction.length).toBe(1);
});