Skip to content

Commit d95500b

Browse files
authored
936 block number range test (#1279)
* 936 Added a max block number range. Signed-off-by: ebadiere <[email protected]> * Removed .only. Signed-off-by: ebadiere <[email protected]> * Added !EthImpl.blockTagIsLatestOrPending(blockNumberOrTag) to the max block evaluation. Signed-off-by: ebadiere <[email protected]> * Added passing conditions to the latest block test. Signed-off-by: ebadiere <[email protected]> * Applied suggested update. Signed-off-by: ebadiere <[email protected]> * Fixed sonar issue. Signed-off-by: ebadiere <[email protected]> --------- Signed-off-by: ebadiere <[email protected]>
1 parent f400b85 commit d95500b

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

packages/relay/src/lib/eth.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,8 @@ export class EthImpl implements Eth {
16091609
return null;
16101610
}
16111611

1612-
if (blockNumberOrTag != null && blockNumberOrTag.length < 32 && !EthImpl.blockTagIsEarliestOrPending(blockNumberOrTag)) {
1612+
const blockNumber = Number(blockNumberOrTag);
1613+
if (blockNumberOrTag != null && blockNumberOrTag.length < 32 && !isNaN(blockNumber)) {
16131614
const latestBlockResponse = await this.mirrorNodeClient.getLatestBlock(requestId);
16141615
const latestBlock = latestBlockResponse.blocks[0];
16151616
if (Number(blockNumberOrTag) > latestBlock.number + maxBlockRange) {

packages/relay/tests/lib/eth.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,12 @@ describe('Eth calls using MirrorNode', async function () {
998998
expect(result).to.exist;
999999
if (result == null) return;
10001000

1001+
// check that we only made the expected number of requests with the expected urls
1002+
expect(restMock.history.get.length).equal(3);
1003+
expect(restMock.history.get[0].url).equal('blocks?limit=1&order=desc');
1004+
expect(restMock.history.get[1].url).equal('contracts/results?timestamp=gte:1651560386.060890949&timestamp=lte:1651560389.060890949&limit=100&order=asc');
1005+
expect(restMock.history.get[2].url).equal('network/fees');
1006+
10011007
expect(result.number).equal(blockNumberHex);
10021008
});
10031009

0 commit comments

Comments
 (0)