Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
peak3d committed Mar 4, 2022
1 parent f9b0c72 commit 36cf6ff
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/gas/fetchBlockFeeHistory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,4 +369,37 @@ describe('fetchBlockFeeHistory', () => {
]);
});
});

describe('given a range which exceeds existing blocks', () => {
beforeEach(() => {
jest.resetAllMocks();
});

it('should adjust fetched numberOfBlocks', async () => {
const latestBlockNumber = 1024;
const numberOfRequestedBlocks = 2048;
const endBlock = new BN(latestBlockNumber);

when(mockedQuery)
.calledWith(ethQuery, 'eth_feeHistory', [
toHex(latestBlockNumber),
toHex(latestBlockNumber),
[],
])
.mockResolvedValue({
oldestBlock: toHex(0),
baseFeePerGas: [],
gasUsedRatio: [],
reward: [],
});

await fetchBlockFeeHistory({
ethQuery,
numberOfBlocks: numberOfRequestedBlocks,
endBlock,
});

expect(mockedQuery).toHaveBeenCalledTimes(1);
});
});
});

0 comments on commit 36cf6ff

Please sign in to comment.