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