feat: getBlocks API is added (#19854)

This commit is contained in:
Furkan KAMACI
2021-09-21 06:08:12 +03:00
committed by GitHub
parent afa04f7abd
commit ea5fed937f
2 changed files with 68 additions and 0 deletions

View File

@ -2078,6 +2078,54 @@ describe('Connection', () => {
);
});
it('get blocks between two slots', async () => {
await mockRpcResponse({
method: 'getBlocks',
params: [0, 10],
value: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
});
await mockRpcResponse({
method: 'getSlot',
params: [],
value: 10,
});
const latestSlot = await connection.getSlot();
const blocks = await connection.getBlocks(0, latestSlot);
expect(blocks).to.have.length(latestSlot);
expect(blocks).to.contain(1);
expect(blocks).to.contain(latestSlot);
});
it('get blocks from starting slot', async () => {
await mockRpcResponse({
method: 'getBlocks',
params: [0],
value: [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
39, 40, 41, 42,
],
});
await mockRpcResponse({
method: 'getSlot',
params: [],
value: 20,
});
while ((await connection.getSlot()) <= 0) {
continue;
}
const blocks = await connection.getBlocks(0);
const latestSlot = await connection.getSlot();
expect(blocks).to.have.lengthOf.greaterThanOrEqual(latestSlot);
expect(blocks).to.contain(1);
expect(blocks).to.contain(latestSlot);
});
it('get confirmed block signatures', async () => {
await mockRpcResponse({
method: 'getSlot',