replace all unittest usage with unittest2

- test_graphql
- test_rpc
- test_hexstrings

fixes #691
This commit is contained in:
jangko 2021-06-21 16:54:55 +07:00
parent 41c4d186b5
commit 3a826b8406
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
4 changed files with 232 additions and 204 deletions

32
tests/asynctest.nim Normal file
View File

@ -0,0 +1,32 @@
## nim-ws
## Copyright (c) 2021 Status Research & Development GmbH
## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
## at your option.
## This file may not be copied, modified, or distributed except according to
## those terms.
import unittest2
export unittest2 except suite, test
template suite*(name, body) =
suite name:
template setup(setupBody) {.used.} =
setup:
let asyncproc = proc {.async.} = setupBody
waitFor asyncproc()
template teardown(teardownBody) {.used.} =
teardown:
let asyncproc = proc {.async.} = teardownBody
waitFor asyncproc()
let suiteproc = proc = body # Avoids GcUnsafe2 warnings with chronos
suiteproc()
template test*(name, body) =
test name:
let asyncproc = proc {.async.} = body
waitFor asyncproc()

View File

@ -7,7 +7,7 @@
# Separated from main tests for brevity # Separated from main tests for brevity
import unittest, ../../nimbus/rpc/hexstrings, json import unittest2, ../../nimbus/rpc/hexstrings, json
proc doHexStrTests* = proc doHexStrTests* =
suite "[RPC] Hex quantity": suite "[RPC] Hex quantity":

View File

@ -8,8 +8,8 @@
# those terms. # those terms.
import import
std/[os, json, unittest], std/[os, json],
stew/byteutils, stew/byteutils, unittest2,
eth/[p2p, common, trie/db, rlp, trie], eth/[p2p, common, trie/db, rlp, trie],
eth/p2p/rlpx_protocols/eth_protocol, eth/p2p/rlpx_protocols/eth_protocol,
graphql, ../nimbus/graphql/ethapi, graphql/test_common, graphql, ../nimbus/graphql/ethapi, graphql/test_common,

View File

@ -6,7 +6,7 @@
# at your option. This file may not be copied, modified, or distributed except according to those terms. # at your option. This file may not be copied, modified, or distributed except according to those terms.
import import
unittest, json, strformat, strutils, options, tables, os, asynctest, json, strformat, strutils, options, tables, os,
nimcrypto, stew/byteutils, times, nimcrypto, stew/byteutils, times,
json_rpc/[rpcserver, rpcclient], eth/common as eth_common, json_rpc/[rpcserver, rpcclient], eth/common as eth_common,
eth/[rlp, keys], eth/trie/db, eth/p2p/rlpx_protocols/eth_protocol, eth/[rlp, keys], eth/trie/db, eth/p2p/rlpx_protocols/eth_protocol,
@ -114,8 +114,7 @@ proc setupEnv(chain: BaseChainDB, signer, ks2: EthAddress, conf: NimbusConfigura
blockHash: header.hash blockHash: header.hash
) )
suite "Remote Procedure Calls":
proc doTests {.async.} =
# TODO: Include other transports such as Http # TODO: Include other transports such as Http
var var
ethNode = setupEthNode(eth) ethNode = setupEthNode(eth)
@ -154,10 +153,9 @@ proc doTests {.async.} =
# Begin tests # Begin tests
rpcServer.start() rpcServer.start()
await client.connect("localhost", Port(RPC_PORT)) waitFor client.connect("localhost", Port(RPC_PORT))
# TODO: add more tests here # TODO: add more tests here
suite "Remote Procedure Calls":
test "web3_clientVersion": test "web3_clientVersion":
let res = await client.web3_clientVersion() let res = await client.web3_clientVersion()
check res == NimbusIdent check res == NimbusIdent
@ -401,5 +399,3 @@ proc doTests {.async.} =
rpcServer.stop() rpcServer.stop()
rpcServer.close() rpcServer.close()
waitFor doTests()