diff --git a/tests/v1/test_rpc_waku.nim b/tests/v1/test_rpc_waku.nim index 761a40d4e..49590ba79 100644 --- a/tests/v1/test_rpc_waku.nim +++ b/tests/v1/test_rpc_waku.nim @@ -1,8 +1,8 @@ {.used.} import - std/[unittest, options, os, strutils], - stew/byteutils, json_rpc/[rpcserver, rpcclient], + std/[options, os, strutils], + testutils/unittests, stew/byteutils, json_rpc/[rpcserver, rpcclient], eth/common as eth_common, eth/[rlp, keys, p2p], ../../waku/v1/protocol/waku_protocol, ../../waku/v1/node/rpc/[hexstrings, rpc_types, waku, key_storage] @@ -26,28 +26,25 @@ proc setupNode(capabilities: varargs[ProtocolInfo, `protocolInfo`], result.addCapability capability proc doTests {.async.} = - let rng = keys.newRng() - var ethNode = setupNode(Waku, rng) - - # Create Ethereum RPCs - let rpcPort = 8545 - var - rpcServer = newRpcSocketServer(["localhost:" & $rpcPort]) - client = newRpcSocketClient() - let keys = newKeyStorage() - setupWakuRPC(ethNode, keys, rpcServer, rng) - - # Begin tests - rpcServer.start() - await client.connect("localhost", Port(rpcPort)) - suite "Waku Remote Procedure Calls": - test "waku_version": + let + rng = keys.newRng() + ethNode = setupNode(Waku, rng) + rpcPort = 8545 + rpcServer = newRpcSocketServer(["localhost:" & $rpcPort]) + client = newRpcSocketClient() + keys = newKeyStorage() + + setupWakuRPC(ethNode, keys, rpcServer, rng) + rpcServer.start() + await client.connect("localhost", Port(rpcPort)) + + asyncTest "waku_version": check await(client.waku_version()) == wakuVersionStr - test "waku_info": + asyncTest "waku_info": let info = await client.waku_info() check info.maxMessageSize == defaultMaxMsgSize - test "waku_setMaxMessageSize": + asyncTest "waku_setMaxMessageSize": let testValue = 1024'u64 check await(client.waku_setMaxMessageSize(testValue)) == true var info = await client.waku_info() @@ -56,14 +53,14 @@ proc doTests {.async.} = discard await(client.waku_setMaxMessageSize(defaultMaxMsgSize + 1)) info = await client.waku_info() check info.maxMessageSize == testValue - test "waku_setMinPoW": + asyncTest "waku_setMinPoW": let testValue = 0.0001 check await(client.waku_setMinPoW(testValue)) == true let info = await client.waku_info() check info.minPow == testValue # test "waku_markTrustedPeer": # TODO: need to connect a peer to test - test "waku asymKey tests": + asyncTest "waku asymKey tests": let keyID = await client.waku_newKeyPair() check: await(client.waku_hasKeyPair(keyID)) == true @@ -83,7 +80,7 @@ proc doTests {.async.} = await(client.waku_hasKeyPair(keyID2)) == false expect ValueError: discard await(client.waku_deleteKeyPair(keyID2)) - test "waku symKey tests": + asyncTest "waku symKey tests": let keyID = await client.waku_newSymKey() check: await(client.waku_hasSymKey(keyID)) == true @@ -126,7 +123,7 @@ proc doTests {.async.} = powTarget = 0.001 powTime = 1.0 - test "waku filter create and delete": + asyncTest "waku filter create and delete": let topic = topicStr.toTopic() symKeyID = await client.waku_newSymKey() @@ -140,7 +137,7 @@ proc doTests {.async.} = expect ValueError: discard await(client.waku_deleteMessageFilter(filterID)) - test "waku symKey post and filter loop": + asyncTest "waku symKey post and filter loop": let topic = topicStr.toTopic() symKeyID = await client.waku_newSymKey() @@ -170,7 +167,7 @@ proc doTests {.async.} = await(client.waku_deleteMessageFilter(filterID)) == true - test "waku asymKey post and filter loop": + asyncTest "waku asymKey post and filter loop": let topic = topicStr.toTopic() privateKeyID = await client.waku_newKeyPair() @@ -200,7 +197,7 @@ proc doTests {.async.} = await(client.waku_deleteMessageFilter(filterID)) == true - test "waku signature in post and filter loop": + asyncTest "waku signature in post and filter loop": let topic = topicStr.toTopic() symKeyID = await client.waku_newSymKey() @@ -234,7 +231,7 @@ proc doTests {.async.} = await(client.waku_deleteMessageFilter(filterID)) == true - rpcServer.stop() - rpcServer.close() + rpcServer.stop() + rpcServer.close() waitFor doTests() diff --git a/tests/v1/test_waku_connect.nim b/tests/v1/test_waku_connect.nim index 06ef897d9..baeee6b67 100644 --- a/tests/v1/test_waku_connect.nim +++ b/tests/v1/test_waku_connect.nim @@ -25,8 +25,8 @@ proc resetMessageQueues(nodes: varargs[EthereumNode]) = # check on a condition until true or return a future containing false # if timeout expires first -proc eventually(timeout: Duration, condition: proc(): bool {.gcsafe.}): - Future[bool] = +proc eventually(timeout: Duration, + condition: proc(): bool {.gcsafe, raises: [Defect].}): Future[bool] = let wrappedCondition = proc(): Future[bool] {.async.} = let f = newFuture[bool]() while not condition(): diff --git a/vendor/nim-libbacktrace/vendor/libbacktrace-upstream/libtool b/vendor/nim-libbacktrace/vendor/libbacktrace-upstream/libtool index ddbf1b1d3..578e6536a 100755 --- a/vendor/nim-libbacktrace/vendor/libbacktrace-upstream/libtool +++ b/vendor/nim-libbacktrace/vendor/libbacktrace-upstream/libtool @@ -2,7 +2,7 @@ # libtool - Provide generalized library-building support services. # Generated automatically by config.status (libbacktrace) version-unused -# Libtool was configured on host fv-az129-187: +# Libtool was configured on host fv-az275-346: # NOTE: Changes made to this file will be lost: look at ltmain.sh. # # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, diff --git a/waku.nimble b/waku.nimble index 78a9318a1..4a4a1919b 100644 --- a/waku.nimble +++ b/waku.nimble @@ -34,27 +34,30 @@ proc buildBinary(name: string, srcDir = "./", params = "", lang = "c") = extra_params &= " " & paramStr(i) exec "nim " & lang & " --out:build/" & name & " " & extra_params & " " & srcDir & name & ".nim" -proc test(name: string, lang = "c") = +proc test(name: string, params = "-d:chronicles_log_level=DEBUG", lang = "c") = # XXX: When running `> NIM_PARAMS="-d:chronicles_log_level=INFO" make test2` # I expect compiler flag to be overridden, however it stays with whatever is # specified here. - buildBinary name, "tests/", "-d:chronicles_log_level=DEBUG" - #buildBinary name, "tests/", "-d:chronicles_log_level=ERROR" + buildBinary name, "tests/", params exec "build/" & name ### Waku v1 tasks task wakunode1, "Build Waku v1 cli node": - buildBinary "wakunode1", "waku/v1/node/", "-d:chronicles_log_level=DEBUG" + buildBinary "wakunode1", "waku/v1/node/", + "-d:chronicles_log_level=DEBUG -d:chronosStrictException" task sim1, "Build Waku v1 simulation tools": - buildBinary "quicksim", "waku/v1/node/", "-d:chronicles_log_level=INFO" - buildBinary "start_network", "waku/v1/node/", "-d:chronicles_log_level=DEBUG" + buildBinary "quicksim", "waku/v1/node/", + "-d:chronicles_log_level=INFO -d:chronosStrictException" + buildBinary "start_network", "waku/v1/node/", + "-d:chronicles_log_level=DEBUG -d:chronosStrictException" task example1, "Build Waku v1 example": - buildBinary "example", "examples/v1/", "-d:chronicles_log_level=DEBUG" + buildBinary "example", "examples/v1/", + "-d:chronicles_log_level=DEBUG -d:chronosStrictException" task test1, "Build & run Waku v1 tests": - test "all_tests_v1" + test "all_tests_v1", "-d:chronicles_log_level=WARN -d:chronosStrictException" ### Waku v2 tasks task wakunode2, "Build Waku v2 (experimental) cli node": diff --git a/waku/common/wakubridge.nim b/waku/common/wakubridge.nim index 1076b8350..d31e00cce 100644 --- a/waku/common/wakubridge.nim +++ b/waku/common/wakubridge.nim @@ -161,9 +161,9 @@ proc start*(bridge: WakuBridge) {.async.} = # Bridging # Handle messages on Waku v1 and bridge to Waku v2 - proc handleEnvReceived(envelope: Envelope) {.gcsafe.} = + proc handleEnvReceived(envelope: Envelope) {.gcsafe, raises: [Defect].} = trace "Bridging envelope from V1 to V2", envelope=envelope - waitFor bridge.toWakuV2(envelope) + asyncSpawn bridge.toWakuV2(envelope) bridge.nodev1.registerEnvReceivedHandler(handleEnvReceived) diff --git a/waku/v1/protocol/waku_protocol.nim b/waku/v1/protocol/waku_protocol.nim index 7fd07b777..9e073c0f2 100644 --- a/waku/v1/protocol/waku_protocol.nim +++ b/waku/v1/protocol/waku_protocol.nim @@ -85,9 +85,10 @@ type received: HashSet[Hash] accounting*: Accounting - P2PRequestHandler* = proc(peer: Peer, envelope: Envelope) {.gcsafe.} + P2PRequestHandler* = proc(peer: Peer, envelope: Envelope) + {.gcsafe, raises: [Defect].} - EnvReceivedHandler* = proc(envelope: Envelope) {.gcsafe.} + EnvReceivedHandler* = proc(envelope: Envelope) {.gcsafe, raises: [Defect].} WakuNetwork = ref object queue*: ref Queue @@ -227,7 +228,7 @@ proc initProtocolState*(network: WakuNetwork, node: EthereumNode) {.gcsafe.} = network.config.rateLimits = none(RateLimits) network.config.maxMsgSize = defaultMaxMsgSize network.config.topics = none(seq[Topic]) - asyncCheck node.run(network) + asyncSpawn node.run(network) p2pProtocol Waku(version = wakuVersion, rlpxName = "waku", @@ -274,7 +275,7 @@ p2pProtocol Waku(version = wakuVersion, # No timer based queue processing for a light node. if not wakuNet.config.isLightNode: - traceAsyncErrors peer.run() + asyncSpawn peer.run() debug "Waku peer initialized", peer @@ -461,7 +462,13 @@ proc sendP2PMessage(node: EthereumNode, peerId: NodeId, envelopes: openarray[Envelope]): bool = for peer in node.peers(Waku): if peer.remote.id == peerId: - asyncCheck peer.p2pMessage(envelopes) + let f = peer.p2pMessage(envelopes) + # Can't make p2pMessage not raise so this is the "best" option I can think + # of instead of using asyncSpawn and still keeping the call not async. + f.callback = proc(data: pointer) {.gcsafe, raises: [Defect].} = + if f.failed: + warn "P2PMessage send failed", msg = f.readError.msg + return true proc queueMessage(node: EthereumNode, msg: Message): bool =