-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add new metadata protocol (#2062)
- Loading branch information
1 parent
25d6e52
commit d5c3ade
Showing
12 changed files
with
408 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{.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, | ||
../../waku/node/peer_manager, | ||
../../waku/waku_discv5, | ||
../../waku/waku_metadata, | ||
./testlib/wakucore, | ||
./testlib/wakunode | ||
|
||
|
||
procSuite "Waku Metadata Protocol": | ||
|
||
# TODO: Add tests with shards when ready | ||
asyncTest "request() returns the supported metadata of the peer": | ||
let clusterId = 10.uint32 | ||
let | ||
node1 = newTestWakuNode(generateSecp256k1Key(), ValidIpAddress.init("0.0.0.0"), Port(0), clusterId = clusterId) | ||
node2 = newTestWakuNode(generateSecp256k1Key(), ValidIpAddress.init("0.0.0.0"), Port(0), clusterId = clusterId) | ||
|
||
# Start nodes | ||
await allFutures([node1.start(), node2.start()]) | ||
|
||
# Create connection | ||
let connOpt = await node2.peerManager.dialPeer(node1.switch.peerInfo.toRemotePeerInfo(), WakuMetadataCodec) | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{.used.} | ||
|
||
import | ||
std/[options, sequtils, tables], | ||
testutils/unittests, | ||
chronos, | ||
chronicles | ||
import | ||
../../waku/waku_metadata, | ||
../../waku/waku_metadata/rpc, | ||
./testlib/wakucore, | ||
./testlib/wakunode | ||
|
||
|
||
procSuite "Waku Protobufs": | ||
# TODO: Missing test coverage in many encode/decode protobuf functions | ||
|
||
test "WakuMetadataResponse": | ||
let res = WakuMetadataResponse( | ||
clusterId: some(7), | ||
shards: @[10, 23, 33], | ||
) | ||
|
||
let buffer = res.encode() | ||
|
||
let decodedBuff = WakuMetadataResponse.decode(buffer.buffer) | ||
check: | ||
decodedBuff.isOk() | ||
decodedBuff.get().clusterId.get() == res.clusterId.get() | ||
decodedBuff.get().shards == res.shards | ||
|
||
test "WakuMetadataRequest": | ||
let req = WakuMetadataRequest( | ||
clusterId: some(5), | ||
shards: @[100, 2, 0], | ||
) | ||
|
||
let buffer = req.encode() | ||
|
||
let decodedBuff = WakuMetadataRequest.decode(buffer.buffer) | ||
check: | ||
decodedBuff.isOk() | ||
decodedBuff.get().clusterId.get() == req.clusterId.get() | ||
decodedBuff.get().shards == req.shards | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.