2021-11-01 18:02:39 +00:00
|
|
|
{.used.}
|
|
|
|
|
|
|
|
import
|
2023-06-19 22:16:25 +00:00
|
|
|
std/[sequtils],
|
2023-06-06 14:36:20 +00:00
|
|
|
stew/results,
|
2023-04-05 07:46:13 +00:00
|
|
|
stew/shims/net,
|
2021-11-01 18:02:39 +00:00
|
|
|
chronos,
|
2023-08-23 13:53:17 +00:00
|
|
|
chronicles,
|
2021-11-01 18:02:39 +00:00
|
|
|
testutils/unittests,
|
2023-06-06 14:36:20 +00:00
|
|
|
libp2p/crypto/crypto as libp2p_keys,
|
|
|
|
eth/keys as eth_keys
|
2022-11-04 09:52:08 +00:00
|
|
|
import
|
2023-08-23 13:53:17 +00:00
|
|
|
../../waku/waku_core/topics,
|
2023-08-09 17:11:50 +00:00
|
|
|
../../waku/waku_enr,
|
|
|
|
../../waku/waku_discv5,
|
2023-02-13 10:43:49 +00:00
|
|
|
./testlib/common,
|
2023-04-05 14:01:51 +00:00
|
|
|
./testlib/wakucore,
|
|
|
|
./testlib/wakunode
|
2021-11-01 18:02:39 +00:00
|
|
|
|
2023-06-06 14:36:20 +00:00
|
|
|
|
|
|
|
proc newTestEnrRecord(privKey: libp2p_keys.PrivateKey,
|
|
|
|
extIp: string, tcpPort: uint16, udpPort: uint16,
|
|
|
|
flags = none(CapabilitiesBitfield)): waku_enr.Record =
|
|
|
|
var builder = EnrBuilder.init(privKey)
|
|
|
|
builder.withIpAddressAndPorts(
|
|
|
|
ipAddr = some(ValidIpAddress.init(extIp)),
|
|
|
|
tcpPort = some(Port(tcpPort)),
|
|
|
|
udpPort = some(Port(udpPort)),
|
|
|
|
)
|
|
|
|
|
|
|
|
if flags.isSome():
|
|
|
|
builder.withWakuCapabilities(flags.get())
|
|
|
|
|
|
|
|
builder.build().tryGet()
|
|
|
|
|
|
|
|
|
2023-11-21 20:15:39 +00:00
|
|
|
proc newTestDiscv5(
|
|
|
|
privKey: libp2p_keys.PrivateKey,
|
|
|
|
bindIp: string, tcpPort: uint16, udpPort: uint16,
|
|
|
|
record: waku_enr.Record,
|
|
|
|
bootstrapRecords = newSeq[waku_enr.Record](),
|
|
|
|
queue = newAsyncEventQueue[SubscriptionEvent](30),
|
|
|
|
): WakuDiscoveryV5 =
|
2023-06-06 14:36:20 +00:00
|
|
|
let config = WakuDiscoveryV5Config(
|
|
|
|
privateKey: eth_keys.PrivateKey(privKey.skkey),
|
|
|
|
address: ValidIpAddress.init(bindIp),
|
|
|
|
port: Port(udpPort),
|
|
|
|
bootstrapRecords: bootstrapRecords,
|
|
|
|
)
|
|
|
|
|
2023-11-21 20:15:39 +00:00
|
|
|
let discv5 = WakuDiscoveryV5.new(
|
|
|
|
rng = rng(),
|
|
|
|
conf = config,
|
|
|
|
record = some(record),
|
|
|
|
queue = queue,
|
|
|
|
)
|
2023-06-06 14:36:20 +00:00
|
|
|
|
2023-06-27 13:50:11 +00:00
|
|
|
return discv5
|
2023-06-06 14:36:20 +00:00
|
|
|
|
|
|
|
|
2021-11-01 18:02:39 +00:00
|
|
|
procSuite "Waku Discovery v5":
|
2023-06-06 14:36:20 +00:00
|
|
|
asyncTest "find random peers":
|
|
|
|
## Given
|
|
|
|
# Node 1
|
2021-11-01 18:02:39 +00:00
|
|
|
let
|
2023-06-06 14:36:20 +00:00
|
|
|
privKey1 = generateSecp256k1Key()
|
|
|
|
bindIp1 = "0.0.0.0"
|
|
|
|
extIp1 = "127.0.0.1"
|
|
|
|
tcpPort1 = 61500u16
|
|
|
|
udpPort1 = 9000u16
|
|
|
|
|
|
|
|
let record1 = newTestEnrRecord(
|
|
|
|
privKey = privKey1,
|
|
|
|
extIp = extIp1,
|
|
|
|
tcpPort = tcpPort1,
|
|
|
|
udpPort = udpPort1,
|
|
|
|
)
|
2023-06-27 13:50:11 +00:00
|
|
|
let node1 = newTestDiscv5(
|
2023-06-06 14:36:20 +00:00
|
|
|
privKey = privKey1,
|
|
|
|
bindIp = bindIp1,
|
|
|
|
tcpPort = tcpPort1,
|
|
|
|
udpPort = udpPort1,
|
|
|
|
record = record1
|
|
|
|
)
|
|
|
|
|
|
|
|
# Node 2
|
|
|
|
let
|
|
|
|
privKey2 = generateSecp256k1Key()
|
|
|
|
bindIp2 = "0.0.0.0"
|
|
|
|
extIp2 = "127.0.0.1"
|
|
|
|
tcpPort2 = 61502u16
|
|
|
|
udpPort2 = 9002u16
|
|
|
|
|
|
|
|
let record2 = newTestEnrRecord(
|
|
|
|
privKey = privKey2,
|
|
|
|
extIp = extIp2,
|
|
|
|
tcpPort = tcpPort2,
|
|
|
|
udpPort = udpPort2,
|
|
|
|
)
|
|
|
|
|
2023-06-27 13:50:11 +00:00
|
|
|
let node2 = newTestDiscv5(
|
2023-06-06 14:36:20 +00:00
|
|
|
privKey = privKey2,
|
|
|
|
bindIp = bindIp2,
|
|
|
|
tcpPort = tcpPort2,
|
|
|
|
udpPort = udpPort2,
|
|
|
|
record = record2,
|
|
|
|
)
|
|
|
|
|
|
|
|
# Node 3
|
|
|
|
let
|
|
|
|
privKey3 = generateSecp256k1Key()
|
|
|
|
bindIp3 = "0.0.0.0"
|
|
|
|
extIp3 = "127.0.0.1"
|
|
|
|
tcpPort3 = 61504u16
|
|
|
|
udpPort3 = 9004u16
|
|
|
|
|
|
|
|
let record3 = newTestEnrRecord(
|
|
|
|
privKey = privKey3,
|
|
|
|
extIp = extIp3,
|
|
|
|
tcpPort = tcpPort3,
|
|
|
|
udpPort = udpPort3,
|
|
|
|
)
|
|
|
|
|
2023-06-27 13:50:11 +00:00
|
|
|
let node3 = newTestDiscv5(
|
2023-06-06 14:36:20 +00:00
|
|
|
privKey = privKey3,
|
|
|
|
bindIp = bindIp3,
|
|
|
|
tcpPort = tcpPort3,
|
|
|
|
udpPort = udpPort3,
|
|
|
|
record = record3,
|
|
|
|
bootstrapRecords = @[record1, record2]
|
|
|
|
)
|
|
|
|
|
2023-11-21 20:15:39 +00:00
|
|
|
let res1 = await node1.start()
|
2023-06-27 19:16:59 +00:00
|
|
|
assert res1.isOk(), res1.error
|
|
|
|
|
2023-11-21 20:15:39 +00:00
|
|
|
let res2 = await node2.start()
|
2023-06-27 19:16:59 +00:00
|
|
|
assert res2.isOk(), res2.error
|
|
|
|
|
2023-11-21 20:15:39 +00:00
|
|
|
let res3 = await node3.start()
|
2023-06-27 19:16:59 +00:00
|
|
|
assert res3.isOk(), res3.error
|
2023-06-06 14:36:20 +00:00
|
|
|
|
|
|
|
## When
|
2023-06-27 13:50:11 +00:00
|
|
|
let res = await node3.findRandomPeers()
|
2023-06-06 14:36:20 +00:00
|
|
|
|
|
|
|
## Then
|
2021-11-01 18:02:39 +00:00
|
|
|
check:
|
2023-06-06 14:36:20 +00:00
|
|
|
res.len >= 1
|
|
|
|
|
|
|
|
## Cleanup
|
|
|
|
await allFutures(node1.stop(), node2.stop(), node3.stop())
|
|
|
|
|
|
|
|
asyncTest "find random peers with predicate":
|
|
|
|
## Setup
|
|
|
|
# Records
|
|
|
|
let
|
|
|
|
privKey1 = generateSecp256k1Key()
|
|
|
|
bindIp1 = "0.0.0.0"
|
|
|
|
extIp1 = "127.0.0.1"
|
|
|
|
tcpPort1 = 61500u16
|
|
|
|
udpPort1 = 9000u16
|
2023-02-07 13:06:50 +00:00
|
|
|
|
2023-06-06 14:36:20 +00:00
|
|
|
let record1 = newTestEnrRecord(
|
|
|
|
privKey = privKey1,
|
|
|
|
extIp = extIp1,
|
|
|
|
tcpPort = tcpPort1,
|
|
|
|
udpPort = udpPort1,
|
|
|
|
flags = some(CapabilitiesBitfield.init(Capabilities.Relay))
|
|
|
|
)
|
2021-11-01 18:02:39 +00:00
|
|
|
|
2023-06-06 14:36:20 +00:00
|
|
|
let
|
|
|
|
privKey2 = generateSecp256k1Key()
|
|
|
|
bindIp2 = "0.0.0.0"
|
|
|
|
extIp2 = "127.0.0.1"
|
|
|
|
tcpPort2 = 61502u16
|
|
|
|
udpPort2 = 9002u16
|
2021-11-01 18:02:39 +00:00
|
|
|
|
2023-06-06 14:36:20 +00:00
|
|
|
let record2 = newTestEnrRecord(
|
|
|
|
privKey = privKey2,
|
|
|
|
extIp = extIp2,
|
|
|
|
tcpPort = tcpPort2,
|
|
|
|
udpPort = udpPort2,
|
|
|
|
flags = some(CapabilitiesBitfield.init(Capabilities.Relay, Capabilities.Store))
|
|
|
|
)
|
2021-11-01 18:02:39 +00:00
|
|
|
|
2023-06-06 14:36:20 +00:00
|
|
|
let
|
|
|
|
privKey3 = generateSecp256k1Key()
|
|
|
|
bindIp3 = "0.0.0.0"
|
|
|
|
extIp3 = "127.0.0.1"
|
|
|
|
tcpPort3 = 61504u16
|
|
|
|
udpPort3 = 9004u16
|
2021-11-01 18:02:39 +00:00
|
|
|
|
2023-06-06 14:36:20 +00:00
|
|
|
let record3 = newTestEnrRecord(
|
|
|
|
privKey = privKey3,
|
|
|
|
extIp = extIp3,
|
|
|
|
tcpPort = tcpPort3,
|
|
|
|
udpPort = udpPort3,
|
|
|
|
flags = some(CapabilitiesBitfield.init(Capabilities.Relay, Capabilities.Filter))
|
|
|
|
)
|
2023-02-07 13:06:50 +00:00
|
|
|
|
|
|
|
let
|
2023-06-06 14:36:20 +00:00
|
|
|
privKey4 = generateSecp256k1Key()
|
|
|
|
bindIp4 = "0.0.0.0"
|
|
|
|
extIp4 = "127.0.0.1"
|
|
|
|
tcpPort4 = 61506u16
|
|
|
|
udpPort4 = 9006u16
|
|
|
|
|
|
|
|
let record4 = newTestEnrRecord(
|
|
|
|
privKey = privKey4,
|
|
|
|
extIp = extIp4,
|
|
|
|
tcpPort = tcpPort4,
|
|
|
|
udpPort = udpPort4,
|
|
|
|
flags = some(CapabilitiesBitfield.init(Capabilities.Relay, Capabilities.Store))
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# Nodes
|
2023-06-27 13:50:11 +00:00
|
|
|
let node1 = newTestDiscv5(
|
2023-06-06 14:36:20 +00:00
|
|
|
privKey = privKey1,
|
|
|
|
bindIp = bindIp1,
|
|
|
|
tcpPort = tcpPort1,
|
|
|
|
udpPort = udpPort1,
|
|
|
|
record = record1,
|
|
|
|
bootstrapRecords = @[record2]
|
|
|
|
)
|
2023-06-27 13:50:11 +00:00
|
|
|
let node2 = newTestDiscv5(
|
2023-06-06 14:36:20 +00:00
|
|
|
privKey = privKey2,
|
|
|
|
bindIp = bindIp2,
|
|
|
|
tcpPort = tcpPort2,
|
|
|
|
udpPort = udpPort2,
|
|
|
|
record = record2,
|
|
|
|
bootstrapRecords = @[record3, record4]
|
|
|
|
)
|
|
|
|
|
2023-06-27 13:50:11 +00:00
|
|
|
let node3 = newTestDiscv5(
|
2023-06-06 14:36:20 +00:00
|
|
|
privKey = privKey3,
|
|
|
|
bindIp = bindIp3,
|
|
|
|
tcpPort = tcpPort3,
|
|
|
|
udpPort = udpPort3,
|
|
|
|
record = record3
|
|
|
|
)
|
|
|
|
|
2023-06-27 13:50:11 +00:00
|
|
|
let node4 = newTestDiscv5(
|
2023-06-06 14:36:20 +00:00
|
|
|
privKey = privKey4,
|
|
|
|
bindIp = bindIp4,
|
|
|
|
tcpPort = tcpPort4,
|
|
|
|
udpPort = udpPort4,
|
|
|
|
record = record4
|
|
|
|
)
|
|
|
|
|
|
|
|
# Start nodes' discoveryV5 protocols
|
2023-11-21 20:15:39 +00:00
|
|
|
let res1 = await node1.start()
|
2023-06-27 19:16:59 +00:00
|
|
|
assert res1.isOk(), res1.error
|
|
|
|
|
2023-11-21 20:15:39 +00:00
|
|
|
let res2 = await node2.start()
|
2023-06-27 19:16:59 +00:00
|
|
|
assert res2.isOk(), res2.error
|
|
|
|
|
2023-11-21 20:15:39 +00:00
|
|
|
let res3 = await node3.start()
|
2023-06-27 19:16:59 +00:00
|
|
|
assert res3.isOk(), res3.error
|
|
|
|
|
2023-11-21 20:15:39 +00:00
|
|
|
let res4 = await node4.start()
|
2023-06-27 19:16:59 +00:00
|
|
|
assert res4.isOk(), res4.error
|
2023-06-06 14:36:20 +00:00
|
|
|
|
|
|
|
## Given
|
2023-06-20 16:08:10 +00:00
|
|
|
let recordPredicate: WakuDiscv5Predicate = proc(record: waku_enr.Record): bool =
|
2023-06-06 14:36:20 +00:00
|
|
|
let typedRecord = record.toTyped()
|
|
|
|
if typedRecord.isErr():
|
|
|
|
return false
|
|
|
|
|
|
|
|
let capabilities = typedRecord.value.waku2
|
|
|
|
if capabilities.isNone():
|
|
|
|
return false
|
|
|
|
|
|
|
|
return capabilities.get().supportsCapability(Capabilities.Store)
|
|
|
|
|
|
|
|
|
|
|
|
## When
|
2023-06-27 13:50:11 +00:00
|
|
|
let peers = await node1.findRandomPeers(some(recordPredicate))
|
2023-02-07 13:06:50 +00:00
|
|
|
|
2023-06-06 14:36:20 +00:00
|
|
|
## Then
|
2023-02-07 13:06:50 +00:00
|
|
|
check:
|
2023-06-06 14:36:20 +00:00
|
|
|
peers.len >= 1
|
|
|
|
peers.allIt(it.supportsCapability(Capabilities.Store))
|
2023-02-07 13:06:50 +00:00
|
|
|
|
2023-06-06 14:36:20 +00:00
|
|
|
# Cleanup
|
|
|
|
await allFutures(node1.stop(), node2.stop(), node3.stop(), node4.stop())
|
2023-06-19 22:16:25 +00:00
|
|
|
|
2023-10-05 12:37:05 +00:00
|
|
|
asyncTest "get shards from topics":
|
2023-06-19 22:16:25 +00:00
|
|
|
## Given
|
|
|
|
let mixedTopics = @["/waku/2/thisisatest", "/waku/2/rs/0/2", "/waku/2/rs/0/8"]
|
|
|
|
let shardedTopics = @["/waku/2/rs/0/2", "/waku/2/rs/0/4", "/waku/2/rs/0/8"]
|
|
|
|
let namedTopics = @["/waku/2/thisisatest", "/waku/2/atestthisis", "/waku/2/isthisatest"]
|
|
|
|
let gibberish = @["aedyttydcb/uioasduyio", "jhdfsjhlsdfjhk/sadjhk", "khfsd/hjfdsgjh/dfs"]
|
|
|
|
let empty: seq[string] = @[]
|
|
|
|
|
2023-10-05 12:37:05 +00:00
|
|
|
let shardsTopics = RelayShards.init(0, @[uint16(2), uint16(4), uint16(8)]).expect("Valid shardIds")
|
2023-06-19 22:16:25 +00:00
|
|
|
|
|
|
|
## When
|
|
|
|
|
|
|
|
let mixedRes = topicsToRelayShards(mixedTopics)
|
|
|
|
let shardedRes = topicsToRelayShards(shardedTopics)
|
|
|
|
let namedRes = topicsToRelayShards(namedTopics)
|
|
|
|
let gibberishRes = topicsToRelayShards(gibberish)
|
|
|
|
let emptyRes = topicsToRelayShards(empty)
|
|
|
|
|
|
|
|
## Then
|
|
|
|
assert mixedRes.isErr(), $mixedRes.value
|
|
|
|
assert shardedRes.isOk(), shardedRes.error
|
|
|
|
assert shardedRes.value.isSome()
|
2023-10-05 12:37:05 +00:00
|
|
|
assert shardedRes.value.get() == shardsTopics, $shardedRes.value.get()
|
2023-06-19 22:16:25 +00:00
|
|
|
assert namedRes.isOk(), namedRes.error
|
|
|
|
assert namedRes.value.isNone(), $namedRes.value
|
|
|
|
assert gibberishRes.isErr(), $gibberishRes.value
|
|
|
|
assert emptyRes.isOk(), emptyRes.error
|
|
|
|
assert emptyRes.value.isNone(), $emptyRes.value
|
|
|
|
|
2023-06-20 16:08:10 +00:00
|
|
|
asyncTest "filter peer per static shard":
|
|
|
|
## Given
|
|
|
|
let recordCluster21 = block:
|
|
|
|
let
|
|
|
|
enrSeqNum = 1u64
|
|
|
|
enrPrivKey = generatesecp256k1key()
|
|
|
|
|
|
|
|
let
|
2023-10-05 12:37:05 +00:00
|
|
|
clusterId: uint16 = 21
|
|
|
|
shardIds: seq[uint16] = @[1u16, 2u16, 5u16, 7u16, 9u16, 11u16]
|
2023-06-20 16:08:10 +00:00
|
|
|
|
2023-10-05 12:37:05 +00:00
|
|
|
let shardsTopics = RelayShards.init(clusterId, shardIds).expect("Valid shardIds")
|
2023-06-20 16:08:10 +00:00
|
|
|
|
|
|
|
var builder = EnrBuilder.init(enrPrivKey, seqNum = enrSeqNum)
|
2023-10-05 12:37:05 +00:00
|
|
|
require builder.withWakuRelaySharding(shardsTopics).isOk()
|
2023-11-06 12:31:36 +00:00
|
|
|
builder.withWakuCapabilities(Relay)
|
2023-06-20 16:08:10 +00:00
|
|
|
|
|
|
|
let recordRes = builder.build()
|
|
|
|
require recordRes.isOk()
|
|
|
|
recordRes.tryGet()
|
|
|
|
|
|
|
|
let recordCluster22Indices1 = block:
|
|
|
|
let
|
|
|
|
enrSeqNum = 1u64
|
|
|
|
enrPrivKey = generatesecp256k1key()
|
|
|
|
|
|
|
|
let
|
2023-10-05 12:37:05 +00:00
|
|
|
clusterId: uint16 = 22
|
|
|
|
shardIds: seq[uint16] = @[2u16, 4u16, 5u16, 8u16, 10u16, 12u16]
|
2023-06-20 16:08:10 +00:00
|
|
|
|
2023-10-05 12:37:05 +00:00
|
|
|
let shardsTopics = RelayShards.init(clusterId, shardIds).expect("Valid shardIds")
|
2023-06-20 16:08:10 +00:00
|
|
|
|
|
|
|
var builder = EnrBuilder.init(enrPrivKey, seqNum = enrSeqNum)
|
2023-10-05 12:37:05 +00:00
|
|
|
require builder.withWakuRelaySharding(shardsTopics).isOk()
|
2023-11-06 12:31:36 +00:00
|
|
|
builder.withWakuCapabilities(Relay)
|
2023-06-20 16:08:10 +00:00
|
|
|
|
|
|
|
let recordRes = builder.build()
|
|
|
|
require recordRes.isOk()
|
|
|
|
recordRes.tryGet()
|
|
|
|
|
|
|
|
let recordCluster22Indices2 = block:
|
|
|
|
let
|
|
|
|
enrSeqNum = 1u64
|
|
|
|
enrPrivKey = generatesecp256k1key()
|
|
|
|
|
|
|
|
let
|
2023-10-05 12:37:05 +00:00
|
|
|
clusterId: uint16 = 22
|
|
|
|
shardIds: seq[uint16] = @[1u16, 3u16, 6u16, 7u16, 9u16, 11u16]
|
2023-06-20 16:08:10 +00:00
|
|
|
|
2023-10-05 12:37:05 +00:00
|
|
|
let shardsTopics = RelayShards.init(clusterId, shardIds).expect("Valid shardIds")
|
2023-06-20 16:08:10 +00:00
|
|
|
|
|
|
|
var builder = EnrBuilder.init(enrPrivKey, seqNum = enrSeqNum)
|
2023-10-05 12:37:05 +00:00
|
|
|
require builder.withWakuRelaySharding(shardsTopics).isOk()
|
2023-11-06 12:31:36 +00:00
|
|
|
builder.withWakuCapabilities(Relay)
|
2023-06-20 16:08:10 +00:00
|
|
|
|
|
|
|
let recordRes = builder.build()
|
|
|
|
require recordRes.isOk()
|
|
|
|
recordRes.tryGet()
|
|
|
|
|
|
|
|
## When
|
|
|
|
let predicateCluster21Op = shardingPredicate(recordCluster21)
|
|
|
|
require predicateCluster21Op.isSome()
|
|
|
|
let predicateCluster21 = predicateCluster21Op.get()
|
|
|
|
|
|
|
|
let predicateCluster22Op = shardingPredicate(recordCluster22Indices1)
|
|
|
|
require predicateCluster22Op.isSome()
|
|
|
|
let predicateCluster22 = predicateCluster22Op.get()
|
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
predicateCluster21(recordCluster21) == true
|
|
|
|
predicateCluster21(recordCluster22Indices1) == false
|
|
|
|
predicateCluster21(recordCluster22Indices2) == false
|
|
|
|
predicateCluster22(recordCluster21) == false
|
|
|
|
predicateCluster22(recordCluster22Indices1) == true
|
|
|
|
predicateCluster22(recordCluster22Indices2) == false
|
|
|
|
|
2023-08-23 13:53:17 +00:00
|
|
|
asyncTest "update ENR from subscriptions":
|
|
|
|
## Given
|
|
|
|
let
|
|
|
|
shard1 = "/waku/2/rs/0/1"
|
|
|
|
shard2 = "/waku/2/rs/0/2"
|
|
|
|
shard3 = "/waku/2/rs/0/3"
|
|
|
|
privKey = generateSecp256k1Key()
|
|
|
|
bindIp = "0.0.0.0"
|
|
|
|
extIp = "127.0.0.1"
|
|
|
|
tcpPort = 61500u16
|
|
|
|
udpPort = 9000u16
|
|
|
|
|
|
|
|
let record = newTestEnrRecord(
|
|
|
|
privKey = privKey,
|
|
|
|
extIp = extIp,
|
|
|
|
tcpPort = tcpPort,
|
|
|
|
udpPort = udpPort,
|
|
|
|
)
|
|
|
|
|
2023-11-21 20:15:39 +00:00
|
|
|
let queue = newAsyncEventQueue[SubscriptionEvent](30)
|
|
|
|
|
2023-08-23 13:53:17 +00:00
|
|
|
let node = newTestDiscv5(
|
|
|
|
privKey = privKey,
|
|
|
|
bindIp = bindIp,
|
|
|
|
tcpPort = tcpPort,
|
|
|
|
udpPort = udpPort,
|
2023-11-21 20:15:39 +00:00
|
|
|
record = record,
|
|
|
|
queue = queue,
|
2023-08-23 13:53:17 +00:00
|
|
|
)
|
|
|
|
|
2023-11-21 20:15:39 +00:00
|
|
|
let res = await node.start()
|
2023-08-23 13:53:17 +00:00
|
|
|
assert res.isOk(), res.error
|
|
|
|
|
|
|
|
## Then
|
2023-09-26 11:33:52 +00:00
|
|
|
queue.emit((kind: PubsubSub, topic: shard1))
|
|
|
|
queue.emit((kind: PubsubSub, topic: shard2))
|
|
|
|
queue.emit((kind: PubsubSub, topic: shard3))
|
2023-08-23 13:53:17 +00:00
|
|
|
|
|
|
|
await sleepAsync(1.seconds)
|
|
|
|
|
|
|
|
check:
|
|
|
|
node.protocol.localNode.record.containsShard(shard1) == true
|
|
|
|
node.protocol.localNode.record.containsShard(shard2) == true
|
|
|
|
node.protocol.localNode.record.containsShard(shard3) == true
|
|
|
|
|
2023-09-26 11:33:52 +00:00
|
|
|
queue.emit((kind: PubsubSub, topic: shard1))
|
|
|
|
queue.emit((kind: PubsubSub, topic: shard2))
|
|
|
|
queue.emit((kind: PubsubSub, topic: shard3))
|
2023-08-23 13:53:17 +00:00
|
|
|
|
|
|
|
await sleepAsync(1.seconds)
|
|
|
|
|
|
|
|
check:
|
|
|
|
node.protocol.localNode.record.containsShard(shard1) == true
|
|
|
|
node.protocol.localNode.record.containsShard(shard2) == true
|
|
|
|
node.protocol.localNode.record.containsShard(shard3) == true
|
|
|
|
|
2023-09-26 11:33:52 +00:00
|
|
|
queue.emit((kind: PubsubUnsub, topic: shard1))
|
|
|
|
queue.emit((kind: PubsubUnsub, topic: shard2))
|
2023-08-23 13:53:17 +00:00
|
|
|
|
|
|
|
await sleepAsync(1.seconds)
|
|
|
|
|
|
|
|
check:
|
|
|
|
node.protocol.localNode.record.containsShard(shard1) == false
|
|
|
|
node.protocol.localNode.record.containsShard(shard2) == false
|
2023-11-21 20:15:39 +00:00
|
|
|
node.protocol.localNode.record.containsShard(shard3) == true
|
2023-08-23 13:53:17 +00:00
|
|
|
|
|
|
|
## Cleanup
|
|
|
|
await node.stop()
|
|
|
|
|
2023-06-20 16:08:10 +00:00
|
|
|
|