Skip to content

Commit

Permalink
test: added unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Logan Nguyen <logan.nguyen@swirldslabs.com>
  • Loading branch information
quiet-node committed Jan 27, 2025
1 parent cf8685c commit 506fd91
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions packages/relay/tests/lib/eth/eth_getLogs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ import {
} from '../../helpers';
import {
BLOCK_HASH,
BLOCK_NUMBER_2,
BLOCK_NUMBER_3,
BLOCKS_LIMIT_ORDER_URL,
CONTRACT_ADDRESS_1,
CONTRACT_ADDRESS_2,
Expand Down Expand Up @@ -430,7 +432,7 @@ describe('@ethGetLogs using MirrorNode', async function () {
expect(result).to.be.empty;
});

it('with non-existing toBlock filter', async function () {
it('should return empty response if toBlock is not existed', async function () {
const filteredLogs = {
logs: [DEFAULT_LOGS.logs[0]],
};
Expand All @@ -446,7 +448,7 @@ describe('@ethGetLogs using MirrorNode', async function () {
const result = await ethImpl.getLogs(null, '0x5', '0x10', null, null, requestDetails);

expect(result).to.exist;
expectLogData1(result[0]);
expect(result).to.be.empty;
});

it('when fromBlock > toBlock', async function () {
Expand Down Expand Up @@ -608,4 +610,40 @@ describe('@ethGetLogs using MirrorNode', async function () {
expect(result.length).to.eq(0);
expect(result).to.deep.equal([]);
});

it('Should throw TIMESTAMP_RANGE_TOO_LARGE predefined error if timestamp range between fromBlock and toBlock exceed the maximum allowed duration of 7 days', async () => {
const mockedFromTimeStamp = 1651560389;
const mockedToTimeStamp = mockedFromTimeStamp + 604800 * 2 + 1; // 7 days (604800 seconds) and 1 second greater than mockedFromTimeStamp

restMock.onGet(BLOCKS_LIMIT_ORDER_URL).reply(200, { blocks: [latestBlock] });
restMock.onGet(`blocks/${BLOCK_NUMBER_2}`).reply(200, {
...DEFAULT_BLOCK,
timestamp: { ...DEFAULT_BLOCK.timestamp, from: mockedFromTimeStamp.toString() },
number: BLOCK_NUMBER_2,
});

restMock.onGet(`blocks/${BLOCK_NUMBER_3}`).reply(200, {
...DEFAULT_BLOCK,
timestamp: { ...DEFAULT_BLOCK.timestamp, to: mockedToTimeStamp.toString() },
number: BLOCK_NUMBER_3,
});

await expect(
ethImpl.getLogs(
null,
BLOCK_NUMBER_2.toString(16),
BLOCK_NUMBER_3.toString(16),
ethers.ZeroAddress,
DEFAULT_LOG_TOPICS,
requestDetails,
),
).to.be.rejectedWith(
predefined.TIMESTAMP_RANGE_TOO_LARGE(
`0x${BLOCK_NUMBER_2.toString(16)}`,
mockedFromTimeStamp,
`0x${BLOCK_NUMBER_3.toString(16)}`,
mockedToTimeStamp,
).message,
);
});
});

0 comments on commit 506fd91

Please sign in to comment.