import pkg/chronos import codex/contracts import ../asynctest import ../ethertest import ./time import ./helpers/mockprovider # to see supportive information in the test output # use `-d:"chronicles_enabled_topics:testProvider:DEBUG` option # when compiling the test file logScope: topics = "testProvider" suite "Provider (Mock)": test "blockNumberForEpoch returns the earliest block when its timestamp " & "is greater than the given epoch time and the earliest block is not " & "block number 0 (genesis block)": let mockProvider = newMockProvider( numberOfBlocks = 10, earliestBlockNumber = 1, earliestBlockTimestamp = 10, timeIntervalBetweenBlocks = 10 ) let (earliestBlockNumber, earliestTimestamp) = await mockProvider.blockNumberAndTimestamp(BlockTag.earliest) let epochTime = earliestTimestamp - 1 let actual = await mockProvider.blockNumberForEpoch( epochTime.truncate(SecondsSince1970)) check actual == earliestBlockNumber test "blockNumberForEpoch returns the earliest block when its timestamp " & "is equal to the given epoch time": let mockProvider = newMockProvider( numberOfBlocks = 10, earliestBlockNumber = 0, earliestBlockTimestamp = 10, timeIntervalBetweenBlocks = 10 ) let (earliestBlockNumber, earliestTimestamp) = await mockProvider.blockNumberAndTimestamp(BlockTag.earliest) let epochTime = earliestTimestamp let actual = await mockProvider.blockNumberForEpoch( epochTime.truncate(SecondsSince1970)) check earliestBlockNumber == 0.u256 check actual == earliestBlockNumber test "blockNumberForEpoch returns the latest block when its timestamp " & "is equal to the given epoch time": let mockProvider = newMockProvider( numberOfBlocks = 10, earliestBlockNumber = 0, earliestBlockTimestamp = 10, timeIntervalBetweenBlocks = 10 ) let (latestBlockNumber, latestTimestamp) = await mockProvider.blockNumberAndTimestamp(BlockTag.latest) let epochTime = latestTimestamp let actual = await mockProvider.blockNumberForEpoch( epochTime.truncate(SecondsSince1970)) check actual == latestBlockNumber ethersuite "Provider": proc mineNBlocks(provider: JsonRpcProvider, n: int) {.async.} = for _ in 0.. 291 # 1728436104 => 291 # 1728436105 => 292 # 1728436106 => 292 # 1728436110 => 292 proc generateExpectations( blocks: seq[(UInt256, UInt256)]): seq[Expectations] = var expectations: seq[Expectations] = @[] for i in 0..