2021-11-01 18:02:39 +00:00
|
|
|
{.used.}
|
|
|
|
|
|
|
|
import
|
2022-06-28 23:59:38 +00:00
|
|
|
std/tables,
|
2021-11-01 18:02:39 +00:00
|
|
|
chronicles,
|
|
|
|
chronos,
|
|
|
|
testutils/unittests,
|
|
|
|
stew/byteutils,
|
|
|
|
stew/shims/net,
|
|
|
|
libp2p/crypto/crypto,
|
|
|
|
eth/keys,
|
|
|
|
eth/p2p/discoveryv5/enr,
|
2022-09-06 22:18:56 +00:00
|
|
|
../../waku/v2/protocol/waku_message,
|
2021-11-01 18:02:39 +00:00
|
|
|
../../waku/v2/node/discv5/waku_discv5,
|
2022-10-18 14:05:53 +00:00
|
|
|
../../waku/v2/node/waku_node,
|
2021-11-01 18:02:39 +00:00
|
|
|
../test_helpers
|
|
|
|
|
|
|
|
procSuite "Waku Discovery v5":
|
|
|
|
asyncTest "Waku Discovery v5 end-to-end":
|
|
|
|
## Tests integrated discovery v5
|
|
|
|
let
|
|
|
|
bindIp = ValidIpAddress.init("0.0.0.0")
|
|
|
|
extIp = ValidIpAddress.init("127.0.0.1")
|
|
|
|
|
|
|
|
nodeKey1 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
2022-11-03 13:47:56 +00:00
|
|
|
nodeTcpPort1 = Port(61500)
|
2021-11-01 18:02:39 +00:00
|
|
|
nodeUdpPort1 = Port(9000)
|
|
|
|
node1 = WakuNode.new(nodeKey1, bindIp, nodeTcpPort1)
|
|
|
|
|
|
|
|
nodeKey2 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
2022-11-03 13:47:56 +00:00
|
|
|
nodeTcpPort2 = Port(61502)
|
2021-11-01 18:02:39 +00:00
|
|
|
nodeUdpPort2 = Port(9002)
|
|
|
|
node2 = WakuNode.new(nodeKey2, bindIp, nodeTcpPort2)
|
|
|
|
|
|
|
|
nodeKey3 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
2022-11-03 13:47:56 +00:00
|
|
|
nodeTcpPort3 = Port(61504)
|
2021-11-01 18:02:39 +00:00
|
|
|
nodeUdpPort3 = Port(9004)
|
|
|
|
node3 = WakuNode.new(nodeKey3, bindIp, nodeTcpPort3)
|
|
|
|
|
2021-11-12 14:10:54 +00:00
|
|
|
flags = initWakuFlags(lightpush = false,
|
|
|
|
filter = false,
|
|
|
|
store = false,
|
|
|
|
relay = true)
|
|
|
|
|
2021-11-01 18:02:39 +00:00
|
|
|
# E2E relay test paramaters
|
|
|
|
pubSubTopic = "/waku/2/default-waku/proto"
|
|
|
|
contentTopic = ContentTopic("/waku/2/default-content/proto")
|
|
|
|
payload = "Can you see me?".toBytes()
|
|
|
|
message = WakuMessage(payload: payload, contentTopic: contentTopic)
|
|
|
|
|
|
|
|
# Mount discv5
|
|
|
|
node1.wakuDiscv5 = WakuDiscoveryV5.new(
|
|
|
|
some(extIp), some(nodeTcpPort1), some(nodeUdpPort1),
|
|
|
|
bindIp,
|
|
|
|
nodeUdpPort1,
|
2022-03-17 16:33:17 +00:00
|
|
|
newSeq[string](),
|
2021-11-01 18:02:39 +00:00
|
|
|
false,
|
|
|
|
keys.PrivateKey(nodeKey1.skkey),
|
2021-11-12 14:10:54 +00:00
|
|
|
flags,
|
2021-11-01 18:02:39 +00:00
|
|
|
[], # Empty enr fields, for now
|
|
|
|
node1.rng
|
|
|
|
)
|
|
|
|
|
|
|
|
node2.wakuDiscv5 = WakuDiscoveryV5.new(
|
|
|
|
some(extIp), some(nodeTcpPort2), some(nodeUdpPort2),
|
|
|
|
bindIp,
|
|
|
|
nodeUdpPort2,
|
|
|
|
@[node1.wakuDiscv5.protocol.localNode.record.toURI()], # Bootstrap with node1
|
|
|
|
false,
|
|
|
|
keys.PrivateKey(nodeKey2.skkey),
|
2021-11-12 14:10:54 +00:00
|
|
|
flags,
|
2021-11-01 18:02:39 +00:00
|
|
|
[], # Empty enr fields, for now
|
|
|
|
node2.rng
|
|
|
|
)
|
|
|
|
|
|
|
|
node3.wakuDiscv5 = WakuDiscoveryV5.new(
|
|
|
|
some(extIp), some(nodeTcpPort3), some(nodeUdpPort3),
|
|
|
|
bindIp,
|
|
|
|
nodeUdpPort3,
|
|
|
|
@[node2.wakuDiscv5.protocol.localNode.record.toURI()], # Bootstrap with node2
|
|
|
|
false,
|
|
|
|
keys.PrivateKey(nodeKey3.skkey),
|
2021-11-12 14:10:54 +00:00
|
|
|
flags,
|
2021-11-01 18:02:39 +00:00
|
|
|
[], # Empty enr fields, for now
|
|
|
|
node3.rng
|
|
|
|
)
|
|
|
|
|
2022-09-07 15:31:27 +00:00
|
|
|
await node1.mountRelay()
|
|
|
|
await node2.mountRelay()
|
|
|
|
await node3.mountRelay()
|
2021-11-01 18:02:39 +00:00
|
|
|
|
|
|
|
await allFutures([node1.start(), node2.start(), node3.start()])
|
|
|
|
|
|
|
|
await allFutures([node1.startDiscv5(), node2.startDiscv5(), node3.startDiscv5()])
|
|
|
|
|
|
|
|
await sleepAsync(3000.millis) # Give the algorithm some time to work its magic
|
|
|
|
check:
|
|
|
|
node1.wakuDiscv5.protocol.nodesDiscovered > 0
|
|
|
|
node2.wakuDiscv5.protocol.nodesDiscovered > 0
|
|
|
|
node3.wakuDiscv5.protocol.nodesDiscovered > 0
|
|
|
|
|
|
|
|
# Let's see if we can deliver a message end-to-end
|
2021-11-03 10:59:51 +00:00
|
|
|
# var completionFut = newFuture[bool]()
|
|
|
|
# proc relayHandler(topic: string, data: seq[byte]) {.async, gcsafe.} =
|
|
|
|
# let msg = WakuMessage.init(data)
|
|
|
|
# if msg.isOk():
|
|
|
|
# let val = msg.value()
|
|
|
|
# check:
|
|
|
|
# topic == pubSubTopic
|
|
|
|
# val.contentTopic == contentTopic
|
|
|
|
# val.payload == payload
|
|
|
|
# completionFut.complete(true)
|
2021-11-01 18:02:39 +00:00
|
|
|
|
2021-11-03 10:59:51 +00:00
|
|
|
# node3.subscribe(pubSubTopic, relayHandler)
|
|
|
|
# await sleepAsync(2000.millis)
|
2021-11-01 18:02:39 +00:00
|
|
|
|
2021-11-03 10:59:51 +00:00
|
|
|
# await node1.publish(pubSubTopic, message)
|
2021-11-01 18:02:39 +00:00
|
|
|
|
2021-11-03 10:59:51 +00:00
|
|
|
# check:
|
|
|
|
# (await completionFut.withTimeout(6.seconds)) == true
|
2021-11-01 18:02:39 +00:00
|
|
|
|
|
|
|
await allFutures([node1.stop(), node2.stop(), node3.stop()])
|