nwaku/tests/test_waku_keepalive.nim

60 lines
1.3 KiB
Nim
Raw Normal View History

{.used.}
import
2022-11-04 09:52:08 +00:00
std/options,
stew/shims/net as stewNet,
testutils/unittests,
chronos,
2022-11-04 09:52:08 +00:00
chronicles,
libp2p/switch,
libp2p/protocols/ping,
libp2p/stream/bufferstream,
2022-11-04 09:52:08 +00:00
libp2p/stream/connection,
libp2p/crypto/crypto
import
../../waku/waku_core,
../../waku/waku_node,
./testlib/wakucore,
./testlib/wakunode
2022-11-04 09:52:08 +00:00
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)
2022-01-10 15:07:35 +00:00
await node1.connectToNodes(@[node2.switch.peerInfo.toRemotePeerInfo()])
node1.startKeepalive()
check:
(await completionFut.withTimeout(5.seconds)) == true
2022-05-20 10:57:19 +00:00
await node2.stop()
await node1.stop()