mirror of
https://github.com/codex-storage/nim-codex.git
synced 2025-01-09 12:35:51 +00:00
d1658d7b77
* market: use `pending` blocktag when querying onchain state * clock: use wall clock in integration tests reason: we'll need to wait for the next period in integration tests, and we can't do that if the time doesn't advance * clock: remove unused field * integration: use pending block time to get current time * clock: fix on-chain clock for hardhat Only use 'latest' block for updates Only update the first time you see a block * integration: do not start tests with a very outdated block * integration: allow for longer expiry period
32 lines
941 B
Nim
32 lines
941 B
Nim
import std/json
|
|
import pkg/ethers
|
|
|
|
import ./asynctest
|
|
import ./checktest
|
|
|
|
## Unit testing suite that sets up an Ethereum testing environment.
|
|
## Injects a `ethProvider` instance, and a list of `accounts`.
|
|
## Calls the `evm_snapshot` and `evm_revert` methods to ensure that any
|
|
## changes to the blockchain do not persist.
|
|
template ethersuite*(name, body) =
|
|
asyncchecksuite name:
|
|
|
|
var ethProvider {.inject, used.}: JsonRpcProvider
|
|
var accounts {.inject, used.}: seq[Address]
|
|
var snapshot: JsonNode
|
|
|
|
setup:
|
|
ethProvider = JsonRpcProvider.new("ws://localhost:8545")
|
|
snapshot = await send(ethProvider, "evm_snapshot")
|
|
# ensure that we have a recent block with a fresh timestamp
|
|
discard await send(ethProvider, "evm_mine")
|
|
accounts = await ethProvider.listAccounts()
|
|
|
|
teardown:
|
|
discard await send(ethProvider, "evm_revert", @[snapshot])
|
|
|
|
body
|
|
|
|
export unittest
|
|
export ethers except `%`
|