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
|
|
|
|
../../waku/waku_node,
|
2023-10-30 20:58:15 +00:00
|
|
|
../../waku/waku_core/topics,
|
2023-10-11 06:58:45 +00:00
|
|
|
../../waku/node/peer_manager,
|
|
|
|
../../waku/waku_discv5,
|
|
|
|
../../waku/waku_metadata,
|
|
|
|
./testlib/wakucore,
|
|
|
|
./testlib/wakunode
|
|
|
|
|
|
|
|
procSuite "Waku Metadata Protocol":
|
|
|
|
asyncTest "request() returns the supported metadata of the peer":
|
|
|
|
let clusterId = 10.uint32
|
|
|
|
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)]
|