mirror of
https://github.com/status-im/nim-dagger.git
synced 2025-01-11 23:24:43 +00:00
7a0a48e4a5
* [build] disable XCannotRaiseY hint There are too many {.raises:[Defect].} in the libraries that we use, drowning out all other warnings and hints * [build] disable BareExcept warning Not yet enabled in a released version of Nim, so libraries that we depend on have not fixed this yet, drowning out our own hints and warnings * [build] disable DotLikeOps warning dot-like ops were an experiment that is not going land in Nim * [build] compile log statements in tests When running tests, all log statements are compiled. They are filtered out at runtime during a test run. * [build] do not build executable when running unit test It's already built in the integration test * [build] Fix warnings - remove unused code - remove unused imports - stop using deprecated stuff * [build] Put compiler flags behind nim version checks * [CI] remove Nim 1.2 compatibility
49 lines
1.2 KiB
Nim
49 lines
1.2 KiB
Nim
import std/times
|
|
import pkg/chronos
|
|
import codex/contracts/clock
|
|
import ../ethertest
|
|
|
|
ethersuite "On-Chain Clock":
|
|
|
|
var clock: OnChainClock
|
|
|
|
setup:
|
|
clock = OnChainClock.new(provider)
|
|
await clock.start()
|
|
|
|
teardown:
|
|
await clock.stop()
|
|
|
|
test "returns the current time of the EVM":
|
|
let latestBlock = (!await provider.getBlock(BlockTag.latest))
|
|
let timestamp = latestBlock.timestamp.truncate(int64)
|
|
check clock.now() == timestamp
|
|
|
|
test "updates time with timestamp of new blocks":
|
|
let future = (getTime() + 42.years).toUnix
|
|
discard await provider.send("evm_setNextBlockTimestamp", @[%future])
|
|
discard await provider.send("evm_mine")
|
|
check clock.now() == future
|
|
|
|
test "updates time using wall-clock in-between blocks":
|
|
let past = clock.now()
|
|
await sleepAsync(chronos.seconds(1))
|
|
check clock.now() > past
|
|
|
|
test "raises when not started":
|
|
expect AssertionDefect:
|
|
discard OnChainClock.new(provider).now()
|
|
|
|
test "raises when stopped":
|
|
await clock.stop()
|
|
expect AssertionDefect:
|
|
discard clock.now()
|
|
|
|
test "handles starting multiple times":
|
|
await clock.start()
|
|
await clock.start()
|
|
|
|
test "handles stopping multiple times":
|
|
await clock.stop()
|
|
await clock.stop()
|