2022-09-08 21:18:59 +00:00
|
|
|
{.used.}
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
import std/options, stew/shims/net as stewNet, testutils/unittests, chronos
|
2022-10-21 13:01:39 +00:00
|
|
|
import
|
2024-07-05 22:03:38 +00:00
|
|
|
waku/[waku_core, waku_lightpush/common, node/peer_manager, waku_node],
|
2023-04-05 14:01:51 +00:00
|
|
|
./testlib/wakucore,
|
|
|
|
./testlib/wakunode
|
2022-09-21 16:27:40 +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-12-14 06:16:39 +00:00
|
|
|
lightNode = newTestWakuNode(lightNodeKey, parseIpAddress("0.0.0.0"), Port(0))
|
2023-02-13 10:43:49 +00:00
|
|
|
bridgeNodeKey = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
bridgeNode = newTestWakuNode(bridgeNodeKey, parseIpAddress("0.0.0.0"), Port(0))
|
2023-02-13 10:43:49 +00:00
|
|
|
destNodeKey = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
destNode = newTestWakuNode(destNodeKey, parseIpAddress("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
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
discard await lightNode.peerManager.dialPeer(
|
|
|
|
bridgeNode.peerInfo.toRemotePeerInfo(), WakuLightPushCodec
|
|
|
|
)
|
2022-09-21 16:27:40 +00:00
|
|
|
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]()
|
2024-03-15 23:08: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)
|
2024-03-15 23:08:47 +00:00
|
|
|
|
2023-09-26 11:33:52 +00:00
|
|
|
destNode.subscribe((kind: PubsubSub, topic: DefaultPubsubTopic), some(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
|
2024-01-18 12:49:13 +00:00
|
|
|
let res = await lightNode.lightpushPublish(some(DefaultPubsubTopic), message)
|
|
|
|
assert res.isOk(), $res.error
|
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())
|