2023-10-11 06:58:45 +00:00
|
|
|
{.used.}
|
|
|
|
|
|
|
|
import
|
|
|
|
std/[options, sequtils, tables],
|
|
|
|
testutils/unittests,
|
|
|
|
chronos,
|
|
|
|
chronicles,
|
|
|
|
stew/shims/net,
|
|
|
|
libp2p/switch,
|
|
|
|
libp2p/peerId,
|
|
|
|
libp2p/crypto/crypto,
|
|
|
|
libp2p/multistream,
|
|
|
|
libp2p/muxers/muxer,
|
|
|
|
eth/keys,
|
|
|
|
eth/p2p/discoveryv5/enr
|
|
|
|
import
|
2024-07-05 22:03:38 +00:00
|
|
|
waku/
|
|
|
|
[
|
|
|
|
waku_node,
|
|
|
|
waku_core/topics,
|
|
|
|
node/peer_manager,
|
|
|
|
discovery/waku_discv5,
|
|
|
|
waku_metadata,
|
|
|
|
],
|
2023-10-11 06:58:45 +00:00
|
|
|
./testlib/wakucore,
|
|
|
|
./testlib/wakunode
|
|
|
|
|
|
|
|
procSuite "Waku Metadata Protocol":
|
|
|
|
asyncTest "request() returns the supported metadata of the peer":
|
2024-06-05 13:32:35 +00:00
|
|
|
let clusterId = 10.uint16
|
2023-10-11 06:58:45 +00:00
|
|
|
let
|
2024-03-15 23:08:47 +00:00
|
|
|
node1 = newTestWakuNode(
|
|
|
|
generateSecp256k1Key(),
|
|
|
|
parseIpAddress("0.0.0.0"),
|
|
|
|
Port(0),
|
|
|
|
clusterId = clusterId,
|
|
|
|
)
|
|
|
|
node2 = newTestWakuNode(
|
|
|
|
generateSecp256k1Key(),
|
|
|
|
parseIpAddress("0.0.0.0"),
|
|
|
|
Port(0),
|
|
|
|
clusterId = clusterId,
|
|
|
|
)
|
2023-10-11 06:58:45 +00:00
|
|
|
|
|
|
|
# Start nodes
|
|
|
|
await allFutures([node1.start(), node2.start()])
|
|
|
|
|
2023-10-30 20:58:15 +00:00
|
|
|
node1.topicSubscriptionQueue.emit((kind: PubsubSub, topic: "/waku/2/rs/10/7"))
|
|
|
|
node1.topicSubscriptionQueue.emit((kind: PubsubSub, topic: "/waku/2/rs/10/6"))
|
|
|
|
|
2023-10-11 06:58:45 +00:00
|
|
|
# Create connection
|
2024-03-15 23:08:47 +00:00
|
|
|
let connOpt = await node2.peerManager.dialPeer(
|
|
|
|
node1.switch.peerInfo.toRemotePeerInfo(), WakuMetadataCodec
|
|
|
|
)
|
2023-10-11 06:58:45 +00:00
|
|
|
require:
|
|
|
|
connOpt.isSome
|
|
|
|
|
|
|
|
# Request metadata
|
|
|
|
let response1 = await node2.wakuMetadata.request(connOpt.get())
|
|
|
|
|
|
|
|
# Check the response or dont even continue
|
|
|
|
require:
|
|
|
|
response1.isOk
|
|
|
|
|
|
|
|
check:
|
|
|
|
response1.get().clusterId.get() == clusterId
|
2023-10-30 20:58:15 +00:00
|
|
|
response1.get().shards == @[uint32(6), uint32(7)]
|