2022-03-17 13:15:04 +00:00
|
|
|
import pkg/ethers
|
2024-10-30 10:40:17 +00:00
|
|
|
import pkg/serde/json
|
2022-03-17 13:15:04 +00:00
|
|
|
|
2024-11-25 11:23:04 +00:00
|
|
|
proc blockTime*(provider: Provider, tag: BlockTag): Future[UInt256] {.async.} =
|
|
|
|
return (!await provider.getBlock(tag)).timestamp
|
|
|
|
|
2022-03-17 13:15:04 +00:00
|
|
|
proc currentTime*(provider: Provider): Future[UInt256] {.async.} =
|
2024-11-25 11:23:04 +00:00
|
|
|
return await provider.blockTime(BlockTag.pending)
|
2022-03-17 13:15:04 +00:00
|
|
|
|
|
|
|
proc advanceTime*(provider: JsonRpcProvider, seconds: UInt256) {.async.} =
|
2023-06-21 05:46:18 +00:00
|
|
|
discard await provider.send("evm_increaseTime", @[%("0x" & seconds.toHex)])
|
2022-03-17 13:15:04 +00:00
|
|
|
discard await provider.send("evm_mine")
|
|
|
|
|
|
|
|
proc advanceTimeTo*(provider: JsonRpcProvider, timestamp: UInt256) {.async.} =
|
|
|
|
if (await provider.currentTime()) != timestamp:
|
2023-06-21 05:46:18 +00:00
|
|
|
discard await provider.send("evm_setNextBlockTimestamp", @[%("0x" & timestamp.toHex)])
|
2022-03-17 13:15:04 +00:00
|
|
|
discard await provider.send("evm_mine")
|