Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions getBlocksForRange.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ async function getBlocksForRange({ provider, fromBlock, toBlock }) {
const missingBlockNumbers = Array(blockCountToQuery).fill()
.map((_,index) => fromBlockNumber + index)
.map(intToHex)
const blockBodies = await Promise.all(
let blockBodies = await Promise.all(
missingBlockNumbers.map(blockNum => query(provider, 'eth_getBlockByNumber', [blockNum, false]))
)
blockBodies = blockBodies.filter(block => block !== null);
return blockBodies
}

Expand Down Expand Up @@ -64,5 +65,5 @@ async function query(provider, method, params) {
);
}
}
throw new Error(`Block not found for params: ${JSON.stringify(params)}`);
return null;
}
8 changes: 4 additions & 4 deletions test/getBlocksForRange.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ test("return block number if there is no error", async (t) => {
t.end();
});

test("looks for a block number 3 times until throwing", async (t) => {
test("not throw error even if it is not found and filter out null", async (t) => {
const sendAsync = sinon
.stub()
.withArgs({
Expand All @@ -45,10 +45,10 @@ test("looks for a block number 3 times until throwing", async (t) => {
.callsArgWith(1, null, { result: null });
const provider = { sendAsync };
try {
await getBlocksForRange({ provider, fromBlock: "0x1", toBlock: "0x1" });
t.fail("Promise resolved when it was not supposed to");
const result = await getBlocksForRange({ provider, fromBlock: "0x1", toBlock: "0x1" });
t.deepEquals(result, []);
} catch (error) {
t.equal(error.message, 'Block not found for params: ["0x1",false]');
t.fail("Should not throw error if result is obtained");
}
t.end();
});