test: repair web3.js getBlocks tests (#24813)
This commit is contained in:
parent
b4503d4110
commit
8f6e469d92
|
@ -2386,50 +2386,72 @@ describe('Connection', function () {
|
||||||
it('get blocks between two slots', async () => {
|
it('get blocks between two slots', async () => {
|
||||||
await mockRpcResponse({
|
await mockRpcResponse({
|
||||||
method: 'getBlocks',
|
method: 'getBlocks',
|
||||||
params: [0, 10],
|
params: [0, 9],
|
||||||
value: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
value: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
|
||||||
|
});
|
||||||
|
await mockRpcResponse({
|
||||||
|
method: 'getFirstAvailableBlock',
|
||||||
|
params: [],
|
||||||
|
value: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
await mockRpcResponse({
|
await mockRpcResponse({
|
||||||
method: 'getSlot',
|
method: 'getSlot',
|
||||||
params: [],
|
params: [],
|
||||||
value: 10,
|
value: 9,
|
||||||
});
|
});
|
||||||
|
|
||||||
const latestSlot = await connection.getSlot();
|
while ((await connection.getSlot()) <= 1) {
|
||||||
const blocks = await connection.getBlocks(0, latestSlot);
|
continue;
|
||||||
expect(blocks).to.have.length(latestSlot);
|
}
|
||||||
expect(blocks).to.contain(1);
|
|
||||||
|
const [startSlot, latestSlot] = await Promise.all([
|
||||||
|
connection.getFirstAvailableBlock(),
|
||||||
|
connection.getSlot(),
|
||||||
|
]);
|
||||||
|
const blocks = await connection.getBlocks(startSlot, latestSlot);
|
||||||
|
expect(blocks).to.have.length(latestSlot - startSlot + 1);
|
||||||
|
expect(blocks[0]).to.eq(startSlot);
|
||||||
expect(blocks).to.contain(latestSlot);
|
expect(blocks).to.contain(latestSlot);
|
||||||
});
|
}).timeout(20 * 1000);
|
||||||
|
|
||||||
it('get blocks from starting slot', async () => {
|
it('get blocks from starting slot', async () => {
|
||||||
await mockRpcResponse({
|
await mockRpcResponse({
|
||||||
method: 'getBlocks',
|
method: 'getBlocks',
|
||||||
params: [0],
|
params: [0],
|
||||||
value: [
|
value: [
|
||||||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
|
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
|
||||||
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
|
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
|
||||||
39, 40, 41, 42,
|
38, 39, 40, 41, 42,
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
await mockRpcResponse({
|
||||||
|
method: 'getFirstAvailableBlock',
|
||||||
|
params: [],
|
||||||
|
value: 0,
|
||||||
|
});
|
||||||
await mockRpcResponse({
|
await mockRpcResponse({
|
||||||
method: 'getSlot',
|
method: 'getSlot',
|
||||||
params: [],
|
params: [],
|
||||||
value: 20,
|
value: 20,
|
||||||
});
|
});
|
||||||
|
|
||||||
while ((await connection.getSlot()) <= 0) {
|
while ((await connection.getSlot()) <= 1) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const blocks = await connection.getBlocks(0);
|
const startSlot = await connection.getFirstAvailableBlock();
|
||||||
const latestSlot = await connection.getSlot();
|
const [blocks, latestSlot] = await Promise.all([
|
||||||
expect(blocks).to.have.lengthOf.greaterThanOrEqual(latestSlot);
|
connection.getBlocks(startSlot),
|
||||||
expect(blocks).to.contain(1);
|
connection.getSlot(),
|
||||||
|
]);
|
||||||
|
if (mockServer) {
|
||||||
|
expect(blocks).to.have.length(43);
|
||||||
|
} else {
|
||||||
|
expect(blocks).to.have.length(latestSlot - startSlot + 1);
|
||||||
|
}
|
||||||
|
expect(blocks[0]).to.eq(startSlot);
|
||||||
expect(blocks).to.contain(latestSlot);
|
expect(blocks).to.contain(latestSlot);
|
||||||
});
|
}).timeout(20 * 1000);
|
||||||
|
|
||||||
describe('get block signatures', function () {
|
describe('get block signatures', function () {
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
|
|
Loading…
Reference in New Issue