diff --git a/Makefile b/Makefile index c62778426..7d1089b3a 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,7 @@ GIT_SUBMODULE_UPDATE := git submodule update --init --recursive else # "variables.mk" was included. Business as usual until the end of this file. # default target, because it's the first one that doesn't start with '.' -all: | wakunode1 sim1 example1 wakunode2 sim2 example2 +all: | wakunode1 sim1 example1 wakunode2 sim2 example2 chat2 # must be included after the default target -include $(BUILD_SYSTEM_DIR)/makefiles/targets.mk @@ -69,6 +69,8 @@ update: | update-common $(MAKE) waku.nims $(HANDLE_OUTPUT) # a phony target, because teaching `make` how to do conditional recompilation of Nim projects is too complicated + +# Waku v1 targets wakunode1: | build deps echo -e $(BUILD_MSG) "build/$@" && \ $(ENV_SCRIPT) nim wakunode1 $(NIM_PARAMS) waku.nims @@ -81,10 +83,11 @@ example1: | build deps echo -e $(BUILD_MSG) "build/$@" && \ $(ENV_SCRIPT) nim example1 $(NIM_PARAMS) waku.nims -example2: | build deps +test1: | build deps echo -e $(BUILD_MSG) "build/$@" && \ - $(ENV_SCRIPT) nim example2 $(NIM_PARAMS) waku.nims + $(ENV_SCRIPT) nim test1 $(NIM_PARAMS) waku.nims +# Waku v2 targets wakunode2: | build deps echo -e $(BUILD_MSG) "build/$@" && \ $(ENV_SCRIPT) nim wakunode2 $(NIM_PARAMS) waku.nims @@ -93,22 +96,25 @@ sim2: | build deps wakunode2 echo -e $(BUILD_MSG) "build/$@" && \ $(ENV_SCRIPT) nim sim2 $(NIM_PARAMS) waku.nims +example2: | build deps + echo -e $(BUILD_MSG) "build/$@" && \ + $(ENV_SCRIPT) nim example2 $(NIM_PARAMS) waku.nims + +test2: | build deps + echo -e $(BUILD_MSG) "build/$@" && \ + $(ENV_SCRIPT) nim test2 $(NIM_PARAMS) waku.nims + scripts2: | build deps wakunode2 echo -e $(BUILD_MSG) "build/$@" && \ $(ENV_SCRIPT) nim scripts2 $(NIM_PARAMS) waku.nims -protocol2: - echo -e $(BUILD_MSG) "build/$@" && \ - $(ENV_SCRIPT) nim protocol2 $(NIM_PARAMS) waku.nims - -test2: - echo -e $(BUILD_MSG) "build/$@" && \ - $(ENV_SCRIPT) nim test2 $(NIM_PARAMS) waku.nims - -chat2: +chat2: | build deps echo -e $(BUILD_MSG) "build/$@" && \ $(ENV_SCRIPT) nim chat2 $(NIM_PARAMS) waku.nims +# Builds and run the test suite (Waku v1 + v2) +test: | test1 test2 + # symlink waku.nims: ln -s waku.nimble $@ @@ -130,11 +136,6 @@ docker-image: docker-push: docker push $(DOCKER_IMAGE_NAME) -# builds and runs the test suite -test: | build deps - $(ENV_SCRIPT) nim test $(NIM_PARAMS) waku.nims - $(ENV_SCRIPT) nim test2 $(NIM_PARAMS) waku.nims - # usual cleaning clean: | clean-common rm -rf build diff --git a/examples/v2/chat2.nim b/examples/v2/chat2.nim index 58be2eed5..84b60531a 100644 --- a/examples/v2/chat2.nim +++ b/examples/v2/chat2.nim @@ -7,10 +7,8 @@ import confutils, chronicles, chronos, stew/shims/net as stewNet, import libp2p/[switch, # manage transports, a single entry point for dialing and listening multistream, # tag stream with short header to identify it crypto/crypto, # cryptographic functions - errors, # error handling utilities protocols/identify, # identify the peer info of a peer stream/connection, # create and close stream read / write connections - transports/transport, # listen and dial to other peers using p2p protocol transports/tcptransport, # listen and dial to other peers using client-server protocol multiaddress, # encode different addressing schemes. For example, /ip4/7.7.7.7/tcp/6543 means it is using IPv4 protocol and TCP peerinfo, # manage the information of a peer, such as peer ID and public / private key diff --git a/tests/all_tests.nim b/tests/all_tests_v1.nim similarity index 100% rename from tests/all_tests.nim rename to tests/all_tests_v1.nim diff --git a/tests/v1/test_rpc_waku.nim b/tests/v1/test_rpc_waku.nim index 753508782..072831967 100644 --- a/tests/v1/test_rpc_waku.nim +++ b/tests/v1/test_rpc_waku.nim @@ -1,6 +1,8 @@ +{.used.} + import - unittest, options, os, stew/byteutils, strutils, - json_rpc/[rpcserver, rpcclient], + std/[unittest, options, os, strutils], + stew/byteutils, json_rpc/[rpcserver, rpcclient], eth/common as eth_common, eth/[rlp, keys, p2p], ../../waku/protocol/v1/waku_protocol, ../../waku/node/v1/rpc/[hexstrings, rpc_types, waku, key_storage] diff --git a/tests/v1/test_waku_bridge.nim b/tests/v1/test_waku_bridge.nim index 125dd823f..f935e9962 100644 --- a/tests/v1/test_waku_bridge.nim +++ b/tests/v1/test_waku_bridge.nim @@ -6,9 +6,11 @@ # Licensed under either of # Apache License, version 2.0, (LICENSE-APACHEv2) # MIT license (LICENSE-MIT) +{.used.} import - sequtils, unittest, tables, chronos, eth/p2p, eth/p2p/peer_pool, + std/[sequtils, unittest, tables], + chronos, eth/p2p, eth/p2p/peer_pool, eth/p2p/rlpx_protocols/whisper_protocol as whisper, ../../waku/protocol/v1/waku_protocol as waku, ../../waku/protocol/v1/waku_bridge, diff --git a/tests/v1/test_waku_config.nim b/tests/v1/test_waku_config.nim index 4ced21e5f..0bc3010f0 100644 --- a/tests/v1/test_waku_config.nim +++ b/tests/v1/test_waku_config.nim @@ -6,9 +6,10 @@ # Licensed under either of # Apache License, version 2.0, (LICENSE-APACHEv2) # MIT license (LICENSE-MIT) +{.used.} import - sequtils, options, unittest, times, + std/[sequtils, options, unittest, times], ../../waku/protocol/v1/waku_protocol suite "Waku envelope validation": diff --git a/tests/v1/test_waku_connect.nim b/tests/v1/test_waku_connect.nim index 22f89b76b..583627552 100644 --- a/tests/v1/test_waku_connect.nim +++ b/tests/v1/test_waku_connect.nim @@ -6,9 +6,11 @@ # Licensed under either of # Apache License, version 2.0, (LICENSE-APACHEv2) # MIT license (LICENSE-MIT) +{.used.} import - sequtils, tables, unittest, chronos, eth/[keys, p2p], eth/p2p/peer_pool, + std/[sequtils, tables, unittest], + chronos, eth/[keys, p2p], eth/p2p/peer_pool, ../../waku/protocol/v1/waku_protocol, ../test_helpers diff --git a/tests/v1/test_waku_mail.nim b/tests/v1/test_waku_mail.nim index 62cbed0b8..80e12ad20 100644 --- a/tests/v1/test_waku_mail.nim +++ b/tests/v1/test_waku_mail.nim @@ -1,6 +1,8 @@ +{.used.} + import - unittest, chronos, tables, sequtils, times, - eth/[p2p, async_utils], eth/p2p/peer_pool, + std/[unittest, tables, sequtils, times], + chronos, eth/[p2p, async_utils], eth/p2p/peer_pool, ../../waku/protocol/v1/[waku_protocol, waku_mail], ../test_helpers diff --git a/waku.nimble b/waku.nimble index ac70cf7de..c6edf1ddf 100644 --- a/waku.nimble +++ b/waku.nimble @@ -20,7 +20,7 @@ requires "nim >= 1.2.0", "stew", "stint", "metrics", - "libp2p" # For wakunode v2 + "libp2p" # Only for Waku v2 ### Helper functions proc buildBinary(name: string, srcDir = "./", params = "", lang = "c") = @@ -40,13 +40,7 @@ proc test(name: string, lang = "c") = #buildBinary name, "tests/", "-d:chronicles_log_level=ERROR" exec "build/" & name -### Tasks -task test, "Run waku v1 tests": - test "all_tests" - -task test2, "Run waku v2 tests": - test "all_tests_v2" - +### Waku v1 tasks task wakunode1, "Build Waku v1 cli node": buildBinary "wakunode", "waku/node/v1/", "-d:chronicles_log_level=TRACE" @@ -57,28 +51,31 @@ task sim1, "Build Waku v1 simulation tools": task example1, "Build Waku v1 example": buildBinary "example", "examples/v1/", "-d:chronicles_log_level=DEBUG" -# TODO Also build Waku store and filter protocols here -task protocol2, "Build the experimental Waku protocol": - buildBinary "waku_relay", "waku/protocol/v2/", "-d:chronicles_log_level=TRACE" +task test1, "Build & run Waku v1 tests": + test "all_tests_v1" -task wakunode2, "Build Experimental Waku cli": +### Waku v2 tasks +task wakunode2, "Build Waku v2 (experimental) cli node": buildBinary "wakunode2", "waku/node/v2/", "-d:chronicles_log_level=TRACE" -task sim2, "Build Experimental Waku simulation tools": +task sim2, "Build Waku v2 simulation tools": buildBinary "quicksim2", "waku/node/v2/", "-d:chronicles_log_level=DEBUG" buildBinary "start_network2", "waku/node/v2/", "-d:chronicles_log_level=TRACE" +task example2, "Build Waku v2 example": + let name = "basic2" + buildBinary name, "examples/v2/", "-d:chronicles_log_level=DEBUG" + +task test2, "Build & run Waku v2 tests": + test "all_tests_v2" + task scripts2, "Build Waku v2 scripts": buildBinary "rpc_publish", "waku/node/v2/rpc/", "-d:chronicles_log_level=DEBUG" buildBinary "rpc_subscribe", "waku/node/v2/rpc/", "-d:chronicles_log_level=DEBUG" buildBinary "rpc_query", "waku/node/v2/rpc/", "-d:chronicles_log_level=DEBUG" buildBinary "rpc_info", "waku/node/v2/rpc/", "-d:chronicles_log_level=DEBUG" -task example2, "Build example Waku usage": - let name = "basic2" - buildBinary name, "examples/v2/", "-d:chronicles_log_level=DEBUG" - -task chat2, "Build example Waku chat usage": +task chat2, "Build example Waku v2 chat usage": let name = "chat2" # NOTE For debugging, set debug level. For chat usage we want minimal log # output to STDOUT. Can be fixed by redirecting logs to file (e.g.) diff --git a/waku/node/v1/config.nim b/waku/node/v1/config.nim index 34ccf7847..1e9b1a261 100644 --- a/waku/node/v1/config.nim +++ b/waku/node/v1/config.nim @@ -153,7 +153,7 @@ proc parseCmdArg*(T: type KeyPair, p: TaintedString): T = try: let privkey = PrivateKey.fromHex(string(p)).tryGet() result = privkey.toKeyPair() - except CatchableError as e: + except CatchableError: raise newException(ConfigurationError, "Invalid private key") proc completeCmdArg*(T: type KeyPair, val: TaintedString): seq[string] = @@ -162,7 +162,7 @@ proc completeCmdArg*(T: type KeyPair, val: TaintedString): seq[string] = proc parseCmdArg*(T: type IpAddress, p: TaintedString): T = try: result = parseIpAddress(p) - except CatchableError as e: + except CatchableError: raise newException(ConfigurationError, "Invalid IP address") proc completeCmdArg*(T: type IpAddress, val: TaintedString): seq[string] = diff --git a/waku/node/v1/rpc/wakusim.nim b/waku/node/v1/rpc/wakusim.nim index 08446ad2b..255115e7b 100644 --- a/waku/node/v1/rpc/wakusim.nim +++ b/waku/node/v1/rpc/wakusim.nim @@ -4,7 +4,6 @@ import ../../../protocol/v1/waku_protocol proc generateTraffic(node: EthereumNode, amount = 100) {.async.} = - var topicNumber = 0'u32 let payload = @[byte 0] for i in 0..