Skip to content

Commit

Permalink
fixes to testlib
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmer committed Aug 26, 2024
1 parent 96cdfb9 commit bc60fa6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
21 changes: 9 additions & 12 deletions tests/testlib/wakunode.nim
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ proc defaultTestWakuNodeConf*(): WakuNodeConf =
maxConnections: 50,
maxMessageSize: "1024 KiB",
clusterId: 0,
pubsubTopics: @["/waku/2/rs/0/0"],
shards: @[uint16(0)],
relay: true,
storeMessageDbUrl: "sqlite://store.sqlite3",
)
Expand All @@ -63,8 +63,9 @@ proc newTestWakuNode*(
dns4DomainName = none(string),
discv5UdpPort = none(Port),
agentString = none(string),
pubsubTopics: seq[string] = @["/waku/2/rs/1/0"],
peerStoreCapacity = none(int),
clusterId = DefaultClusterId,
shards = @[DefaultShardId],
): WakuNode =
var resolvedExtIp = extIp

Expand All @@ -77,14 +78,8 @@ proc newTestWakuNode*(

var conf = defaultTestWakuNodeConf()

let clusterId =
if pubsubTopics.len() > 0:
RelayShard.parse(pubsubTopics[0]).get().clusterId
else:
1.uint16

conf.clusterId = clusterId
conf.pubsubTopics = pubsubTopics
conf.shards = shards

if dns4DomainName.isSome() and extIp.isNone():
# If there's an error resolving the IP, an exception is thrown and test fails
Expand All @@ -95,7 +90,7 @@ proc newTestWakuNode*(

let netConf = NetConfig.init(
bindIp = bindIp,
clusterId = clusterId,
clusterId = conf.clusterId,
bindPort = bindPort,
extIp = resolvedExtIp,
extPort = extPort,
Expand All @@ -111,8 +106,10 @@ proc newTestWakuNode*(

var enrBuilder = EnrBuilder.init(nodeKey)

enrBuilder.withShardedTopics(pubsubTopics).isOkOr:
raise newException(Defect, "Invalid record: " & error)
enrBuilder.withWakuRelaySharding(
RelayShards(clusterId: conf.clusterId, shardIds: conf.shards)
).isOkOr:
raise newException(Defect, "Invalid record: " & $error)

enrBuilder.withIpAddressAndPorts(
ipAddr = netConf.enrIp, tcpPort = netConf.enrPort, udpPort = netConf.discv5UdpPort
Expand Down
3 changes: 2 additions & 1 deletion waku/waku_core/topics/pubsub_topic.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export parsing

type PubsubTopic* = string

const DefaultPubsubTopic* = PubsubTopic("/waku/2/rs/0/0")
const DefaultShardId* = uint16(0)
const DefaultClusterId* = uint16(0)

## Namespaced pub-sub topic

Expand Down

0 comments on commit bc60fa6

Please sign in to comment.