logos-messaging-nim/tests/test_waku_keepalive.nim
Ivan FB 9f68c83fed chore: bump dependencies for v0.36 (#3410)
* properly pass userMessageLimit to OnchainGroupManager
* waku.nimble 2.2.4 Nim compiler
* rm stew/shims/net import
* change ValidIpAddress.init with parseIpAddress
* fix serialize for zerokit
* group_manager: separate if statements
* protocol_types: add encode UInt32 with zeros up to 32 bytes
* windows build: skip libunwind build and rm libunwind.a inlcusion step
* bump nph to overcome the compilation issues with 2.2.x
* bump nim-libp2p to v1.10.1
2025-05-26 21:58:02 +02:00

54 lines
1.4 KiB
Nim

{.used.}
import
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()).isOkOr:
assert false, "Failed to mount relay"
await node1.mountLibp2pPing()
await node2.start()
(await node2.mountRelay()).isOkOr:
assert false, "Failed to mount relay"
let pingProto = Ping.new(handler = pingHandler)
await pingProto.start()
node2.switch.mount(pingProto)
await node1.connectToNodes(@[node2.switch.peerInfo.toRemotePeerInfo()])
node1.startKeepalive(2.seconds)
check:
(await completionFut.withTimeout(5.seconds)) == true
await node2.stop()
await node1.stop()