nwaku/tests/test_waku_keepalive.nim
Ivan FB 385daf16be
chore: vendor bump for 0.23.0 (#2274)
* on_chain/group_manager: use .async: (raises:[Exception]).
* bump nim-dnsdisc
* update nim-chronos to the latest state
* chat2.nim: catch any possible exception when stopping
* chat2bridge.nim: make it to compile after vendor bump
* ValidIpAddress (deprecated) -> IpAddress
* vendor/nim-libp2p additional bump
* libwaku: adapt to vendor bump
* testlib/wakunode.nim: adapt to vendor bump (ValidIpAddress -> IpAddress)
* waku_node: avoid throwing any exception from stop*(node: WakuNode)
* test_confutils_envvar.nim: ValidIpAddress -> IpAddress
* test_jsonrpc_store: capture exception
* test_rln*: handling exceptions
* adaptation to make test_rln_* to work properly
* signature enhancement of group_manager methods
2023-12-14 07:16:39 +01:00

60 lines
1.3 KiB
Nim

{.used.}
import
std/options,
stew/shims/net as stewNet,
testutils/unittests,
chronos,
chronicles,
libp2p/switch,
libp2p/protocols/ping,
libp2p/stream/bufferstream,
libp2p/stream/connection,
libp2p/crypto/crypto
import
../../waku/waku_core,
../../waku/waku_node,
./testlib/wakucore,
./testlib/wakunode
suite "Waku Keepalive":
asyncTest "handle ping keepalives":
let
nodeKey1 = generateSecp256k1Key()
node1 = newTestWakuNode(nodeKey1, parseIpAddress("0.0.0.0"), Port(0))
nodeKey2 = generateSecp256k1Key()
node2 = newTestWakuNode(nodeKey2, parseIpAddress("0.0.0.0"), Port(0))
var completionFut = newFuture[bool]()
proc pingHandler(peerId: PeerID) {.async, gcsafe.} =
debug "Ping received"
check:
peerId == node1.switch.peerInfo.peerId
completionFut.complete(true)
await node1.start()
await node1.mountRelay()
await node1.mountLibp2pPing()
await node2.start()
await node2.mountRelay()
let pingProto = Ping.new(handler = pingHandler)
await pingProto.start()
node2.switch.mount(pingProto)
await node1.connectToNodes(@[node2.switch.peerInfo.toRemotePeerInfo()])
node1.startKeepalive()
check:
(await completionFut.withTimeout(5.seconds)) == true
await node2.stop()
await node1.stop()