2022-09-08 21:18:59 +00:00
|
|
|
{.used.}
|
|
|
|
|
|
|
|
import
|
2023-02-13 10:43:49 +00:00
|
|
|
stew/shims/net as stewNet,
|
2022-09-08 21:18:59 +00:00
|
|
|
testutils/unittests,
|
2022-11-22 07:13:51 +00:00
|
|
|
chronicles,
|
2023-02-13 10:43:49 +00:00
|
|
|
chronos,
|
2022-09-08 21:18:59 +00:00
|
|
|
libp2p/crypto/crypto,
|
2022-10-21 13:01:39 +00:00
|
|
|
libp2p/switch
|
|
|
|
import
|
2023-08-09 17:11:50 +00:00
|
|
|
../../waku/waku_core,
|
|
|
|
../../waku/waku_lightpush,
|
|
|
|
../../waku/node/peer_manager,
|
|
|
|
../../waku/waku_node,
|
2023-02-13 10:43:49 +00:00
|
|
|
./testlib/common,
|
2023-04-05 14:01:51 +00:00
|
|
|
./testlib/wakucore,
|
|
|
|
./testlib/wakunode
|
2022-09-21 16:27:40 +00:00
|
|
|
|
2022-09-08 21:18:59 +00:00
|
|
|
|
2023-02-14 08:19:06 +00:00
|
|
|
suite "WakuNode - Lightpush":
|
2022-09-08 21:18:59 +00:00
|
|
|
asyncTest "Lightpush message return success":
|
2022-09-21 16:27:40 +00:00
|
|
|
## Setup
|
2022-09-08 21:18:59 +00:00
|
|
|
let
|
2023-02-13 10:43:49 +00:00
|
|
|
lightNodeKey = generateSecp256k1Key()
|
2023-04-05 14:01:51 +00:00
|
|
|
lightNode = newTestWakuNode(lightNodeKey, ValidIpAddress.init("0.0.0.0"), Port(0))
|
2023-02-13 10:43:49 +00:00
|
|
|
bridgeNodeKey = generateSecp256k1Key()
|
2023-04-05 14:01:51 +00:00
|
|
|
bridgeNode = newTestWakuNode(bridgeNodeKey, ValidIpAddress.init("0.0.0.0"), Port(0))
|
2023-02-13 10:43:49 +00:00
|
|
|
destNodeKey = generateSecp256k1Key()
|
2023-04-05 14:01:51 +00:00
|
|
|
destNode = newTestWakuNode(destNodeKey, ValidIpAddress.init("0.0.0.0"), Port(0))
|
2022-09-08 21:18:59 +00:00
|
|
|
|
2022-09-21 16:27:40 +00:00
|
|
|
await allFutures(destNode.start(), bridgeNode.start(), lightNode.start())
|
2022-09-08 21:18:59 +00:00
|
|
|
|
2022-09-21 16:27:40 +00:00
|
|
|
await destNode.mountRelay(@[DefaultPubsubTopic])
|
|
|
|
await bridgeNode.mountRelay(@[DefaultPubsubTopic])
|
|
|
|
await bridgeNode.mountLightPush()
|
2022-10-28 14:30:01 +00:00
|
|
|
lightNode.mountLightPushClient()
|
2023-02-13 10:43:49 +00:00
|
|
|
|
2022-09-21 16:27:40 +00:00
|
|
|
discard await lightNode.peerManager.dialPeer(bridgeNode.peerInfo.toRemotePeerInfo(), WakuLightPushCodec)
|
|
|
|
await sleepAsync(100.milliseconds)
|
|
|
|
await destNode.connectToNodes(@[bridgeNode.peerInfo.toRemotePeerInfo()])
|
2022-09-08 21:18:59 +00:00
|
|
|
|
2022-09-21 16:27:40 +00:00
|
|
|
## Given
|
|
|
|
let message = fakeWakuMessage()
|
2022-09-08 21:18:59 +00:00
|
|
|
|
|
|
|
var completionFutRelay = newFuture[bool]()
|
2023-06-06 17:28:47 +00:00
|
|
|
proc relayHandler(topic: PubsubTopic, msg: WakuMessage): Future[void] {.async, gcsafe.} =
|
2022-09-21 16:27:40 +00:00
|
|
|
check:
|
2023-06-06 17:28:47 +00:00
|
|
|
topic == DefaultPubsubTopic
|
2022-09-21 16:27:40 +00:00
|
|
|
msg == message
|
2022-09-08 21:18:59 +00:00
|
|
|
completionFutRelay.complete(true)
|
2022-09-21 16:27:40 +00:00
|
|
|
destNode.subscribe(DefaultPubsubTopic, relayHandler)
|
2022-09-08 21:18:59 +00:00
|
|
|
|
2022-09-21 16:27:40 +00:00
|
|
|
# Wait for subscription to take effect
|
|
|
|
await sleepAsync(100.millis)
|
2022-09-08 21:18:59 +00:00
|
|
|
|
2022-09-21 16:27:40 +00:00
|
|
|
## When
|
2022-10-28 14:30:01 +00:00
|
|
|
await lightNode.lightpushPublish(DefaultPubsubTopic, message)
|
2022-09-08 21:18:59 +00:00
|
|
|
|
2022-09-21 16:27:40 +00:00
|
|
|
## Then
|
2022-10-28 14:30:01 +00:00
|
|
|
check await completionFutRelay.withTimeout(5.seconds)
|
2022-09-08 21:18:59 +00:00
|
|
|
|
2022-09-21 16:27:40 +00:00
|
|
|
## Cleanup
|
|
|
|
await allFutures(lightNode.stop(), bridgeNode.stop(), destNode.stop())
|