2022-09-08 21:18:59 +00:00
|
|
|
{.used.}
|
|
|
|
|
|
|
|
import
|
|
|
|
stew/shims/net as stewNet,
|
|
|
|
testutils/unittests,
|
2022-11-22 07:13:51 +00:00
|
|
|
chronicles,
|
2022-09-08 21:18:59 +00:00
|
|
|
chronos,
|
|
|
|
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,
|
|
|
|
./testlib/common
|
2022-09-21 16:27:40 +00:00
|
|
|
|
2022-09-08 21:18:59 +00:00
|
|
|
|
|
|
|
procSuite "WakuNode - Lightpush":
|
|
|
|
let rng = crypto.newRng()
|
|
|
|
|
|
|
|
asyncTest "Lightpush message return success":
|
2022-09-21 16:27:40 +00:00
|
|
|
## Setup
|
2022-09-08 21:18:59 +00:00
|
|
|
let
|
2022-09-21 16:27:40 +00:00
|
|
|
lightNodeKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
|
|
|
lightNode = WakuNode.new(lightNodeKey, ValidIpAddress.init("0.0.0.0"), Port(60010))
|
|
|
|
bridgeNodeKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
|
|
|
bridgeNode = WakuNode.new(bridgeNodeKey, ValidIpAddress.init("0.0.0.0"), Port(60012))
|
|
|
|
destNodeKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
|
|
|
destNode = WakuNode.new(destNodeKey, ValidIpAddress.init("0.0.0.0"), Port(60013))
|
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()
|
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())
|
2022-09-08 21:18:59 +00:00
|
|
|
|