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
|
2022-09-06 22:18:56 +00:00
|
|
|
../../waku/v2/protocol/waku_message,
|
2022-09-08 21:18:59 +00:00
|
|
|
../../waku/v2/protocol/waku_lightpush,
|
2023-02-06 09:03:30 +00:00
|
|
|
../../waku/v2/node/peer_manager,
|
2022-09-08 21:18:59 +00:00
|
|
|
../../waku/v2/utils/peers,
|
2022-10-21 13:01:39 +00:00
|
|
|
../../waku/v2/node/waku_node,
|
2023-02-13 10:43:49 +00:00
|
|
|
./testlib/common,
|
|
|
|
./testlib/waku2
|
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-02-13 11:27:49 +00:00
|
|
|
lightNode = WakuNode.new(lightNodeKey, ValidIpAddress.init("0.0.0.0"), Port(0))
|
2023-02-13 10:43:49 +00:00
|
|
|
bridgeNodeKey = generateSecp256k1Key()
|
2023-02-13 11:27:49 +00:00
|
|
|
bridgeNode = WakuNode.new(bridgeNodeKey, ValidIpAddress.init("0.0.0.0"), Port(0))
|
2023-02-13 10:43:49 +00:00
|
|
|
destNodeKey = generateSecp256k1Key()
|
2023-02-13 11:27:49 +00:00
|
|
|
destNode = WakuNode.new(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]()
|
2022-11-09 08:55:47 +00:00
|
|
|
proc relayHandler(pubsubTopic: PubsubTopic, data: seq[byte]) {.async, gcsafe.} =
|
2022-11-07 15:24:16 +00:00
|
|
|
let msg = WakuMessage.decode(data).get()
|
2022-09-21 16:27:40 +00:00
|
|
|
check:
|
|
|
|
pubsubTopic == DefaultPubsubTopic
|
|
|
|
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())
|