Fabiana Cecin 549834203d
Bump to nim-libp2p 2.0.0
* bump libp2p pin to release/v2.0.0 (c43199378)
* pin nimble.lock: lsquic/websock/boringssl/protobuf_serialization/npeg/jwt
* add libp2p_mix dep and point libp2p/protocols/mix -> libp2p_mix
* migrate rng to libp2p Rng type (prod, channels, noise, tests)
* noise: take Rng, extract bearSslDrbg internally
* waku_switch: TransportConfig factory; withMaxInOut; local MaxConnections
* waku_relay/rendezvous/discv5/kademlia: v2.0.0 API (rng, config, ServiceDiscovery)
* tests: newStandardSwitch shim; PeerId.random(rng); common.rng()/crypto.newRng()
* drop libp2p/utils/semaphore (use chronos AsyncSemaphore)
* add waku/compat/option_valueor shim where needed
* add std/options where transitive re-export dropped
2026-06-02 15:42:58 -03:00

145 lines
3.8 KiB
Nim

import waku/compat/option_valueor
{.used.}
import
std/json,
testutils/unittests,
chronicles,
chronos,
libp2p/[crypto/crypto, crypto/secp, multiaddress, switch],
tests/testlib/[wakucore, wakunode],
waku/factory/conf_builder/conf_builder
include waku/factory/waku, waku/common/enr/typed_record
suite "Wakunode2 - Waku":
test "compilation version should be reported":
## Given
let conf = defaultTestWakuConf()
let waku = (waitFor Waku.new(conf)).valueOr:
raiseAssert error
## When
let version = waku.stateInfo.getNodeInfoItem(NodeInfoId.Version)
## Then
check:
version == git_version
suite "Wakunode2 - Waku initialization":
test "peer persistence setup should be successfully mounted":
## Given
var conf = defaultTestWakuConf()
conf.peerPersistence = true
let waku = (waitFor Waku.new(conf)).valueOr:
raiseAssert error
check:
not waku.node.peerManager.storage.isNil()
test "node setup is successful with default configuration":
## Given
var conf = defaultTestWakuConf()
## When
var waku = (waitFor Waku.new(conf)).valueOr:
raiseAssert error
(waitFor startWaku(addr waku)).isOkOr:
raiseAssert error
## Then
let node = waku.node
check:
not node.isNil()
node.wakuArchive.isNil()
node.wakuStore.isNil()
not node.wakuStoreClient.isNil()
not node.wakuRendezvous.isNil()
## Cleanup
(waitFor waku.stop()).isOkOr:
raiseAssert error
test "app properly handles dynamic port configuration":
## Given
var conf = defaultTestWakuConf()
conf.endpointConf.p2pTcpPort = Port(0)
## When
var waku = (waitFor Waku.new(conf)).valueOr:
raiseAssert error
(waitFor startWaku(addr waku)).isOkOr:
raiseAssert error
## Then
let
node = waku.node
typedNodeEnr = node.enr.toTyped()
assert typedNodeEnr.isOk(), $typedNodeEnr.error
let tcpPort = typedNodeEnr.value.tcp()
assert tcpPort.isSome()
check tcpPort.get() != 0
check:
# Waku started properly
not node.isNil()
node.wakuArchive.isNil()
node.wakuStore.isNil()
not node.wakuStoreClient.isNil()
not node.wakuRendezvous.isNil()
# DS structures are updated with dynamic ports
typedNodeEnr.get().tcp.get() != 0
## Cleanup
(waitFor waku.stop()).isOkOr:
raiseAssert error
test "explicit port=0 triggers auto-bind across all services":
var builder = defaultTestWakuConfBuilder()
builder.withP2pTcpPort(Port(0))
builder.discv5Conf.withEnabled(true)
builder.discv5Conf.withUdpPort(Port(0))
builder.restServerConf.withEnabled(true)
builder.restServerConf.withRelayCacheCapacity(50'u32)
builder.restServerConf.withPort(Port(0))
builder.metricsServerConf.withEnabled(true)
builder.metricsServerConf.withHttpPort(Port(0))
builder.webSocketConf.withEnabled(true)
builder.webSocketConf.withWebSocketPort(Port(0))
let conf = builder.build().valueOr:
raiseAssert error
check:
conf.endpointConf.p2pTcpPort == Port(0)
conf.discv5Conf.get().udpPort == Port(0)
conf.restServerConf.get().port == Port(0)
conf.metricsServerConf.get().httpPort == Port(0)
conf.webSocketConf.get().port == Port(0)
var waku = (waitFor Waku.new(conf)).valueOr:
raiseAssert error
defer:
(waitFor waku.stop()).isOkOr:
raiseAssert error
(waitFor startWaku(addr waku)).isOkOr:
raiseAssert error
let portsJson = waku.stateInfo.getNodeInfoItem(NodeInfoId.MyBoundPorts)
let parsed = parseJson(portsJson)
check:
parsed.kind == JObject
parsed["tcp"].getInt() != 0
parsed["webSocket"].getInt() != 0
parsed["rest"].getInt() != 0
parsed["discv5Udp"].getInt() != 0
parsed["metrics"].getInt() != 0