fix(tests): libp2p v2.0.0 API migrations across test suite

Three small classes of fix across 12 test files (uncovered by a local
`nim c` sweep of tests/all_tests_common.nim + tests/all_tests_waku.nim):

1. `rng` no longer auto-calls when used as an argument: libp2p v2.0.0
   exports its own `rng` symbol (SwitchBuilder field), so Nim's resolver
   sees the testlib `common.rng` template ambiguously and stops auto-
   calling it. Add explicit `()`:
   - tests/test_helpers.nim
   - tests/waku_filter_v2/waku_filter_utils.nim
   - tests/waku_lightpush/lightpush_utils.nim
   - tests/waku_lightpush_legacy/lightpush_utils.nim
   - tests/node/test_wakunode_filter.nim
   - tests/waku_store/store_utils.nim

2. `PeerId.random()` zero-arg form removed in v2.0.0; new signature
   takes `rng: Rng`. Add `newRng()` + `libp2p/crypto/crypto` import:
   - tests/common/test_requestratelimiter.nim
   - tests/common/test_ratelimit_setting.nim

3. `some()` ambiguity vs `Opt.some` — files that don't directly
   `import std/options` get `Opt.some` template only, breaking calls
   intended for `Option[T]`. Add `std/options` to imports:
   - tests/waku_store/test_wakunode_store.nim
   - tests/waku_relay/test_wakunode_relay.nim

4. Two more API removals:
   - tests/testlib/wakunode.nim — `builders.MaxConnections` was removed;
     use `DefaultMaxConnections` from `libp2p/connmanager`.
   - tests/waku_rln_relay/utils_onchain.nim — `keys.PrivateKey.random
     (rng[])` `rng` ambiguous between testlib/common and eth/keys
     exports; qualify as `common.rng()[]`.

There are still more test-compile errors past this point — this is
incremental progress, not a complete v2.0.0 test-suite migration.
This commit is contained in:
Prem Chaitanya Prathi 2026-06-04 18:55:26 +05:30
parent 5561fcb532
commit ba39ee4a37
No known key found for this signature in database
13 changed files with 24 additions and 23 deletions

BIN
tests/all_tests_common Executable file

Binary file not shown.

View File

@ -9,7 +9,7 @@
{.used.}
import testutils/unittests
import chronos, libp2p/stream/connection
import chronos, libp2p/stream/connection, libp2p/crypto/crypto
import std/[options, tables]
import ../../waku/common/rate_limit/request_limiter
@ -17,9 +17,9 @@ import ../../waku/common/rate_limit/timed_map
let proto = "ProtocolDescriptor"
let conn1 = Connection(peerId: PeerId.random().tryGet())
let conn2 = Connection(peerId: PeerId.random().tryGet())
let conn3 = Connection(peerId: PeerId.random().tryGet())
let conn1 = Connection(peerId: PeerId.random(newRng()).tryGet())
let conn2 = Connection(peerId: PeerId.random(newRng()).tryGet())
let conn3 = Connection(peerId: PeerId.random(newRng()).tryGet())
suite "RateLimitSetting":
test "Parse rate limit setting - ok":

View File

@ -9,7 +9,7 @@
{.used.}
import testutils/unittests
import chronos, libp2p/stream/connection
import chronos, libp2p/stream/connection, libp2p/crypto/crypto
import std/options
import ../../waku/common/rate_limit/request_limiter
@ -17,9 +17,9 @@ import ../../waku/common/rate_limit/timed_map
let proto = "ProtocolDescriptor"
let conn1 = Connection(peerId: PeerId.random().tryGet())
let conn2 = Connection(peerId: PeerId.random().tryGet())
let conn3 = Connection(peerId: PeerId.random().tryGet())
let conn1 = Connection(peerId: PeerId.random(newRng()).tryGet())
let conn2 = Connection(peerId: PeerId.random(newRng()).tryGet())
let conn3 = Connection(peerId: PeerId.random(newRng()).tryGet())
suite "RequestRateLimiter":
test "RequestRateLimiter Allow up to main bucket":

View File

@ -5,7 +5,8 @@ import
testutils/unittests,
chronos,
chronicles,
libp2p/[peerstore, crypto/crypto]
libp2p/[peerstore, crypto/crypto],
bearssl/rand
import
waku/[
@ -31,7 +32,7 @@ proc createRequest(
pubsubTopic = none(PubsubTopic),
contentTopics = newSeq[ContentTopic](),
): FilterSubscribeRequest =
let requestId = generateRequestId(rng)
let requestId = generateRequestId(rng())
return FilterSubscribeRequest(
requestId: requestId,

View File

@ -21,7 +21,7 @@ proc setupTestNode*(
addAllCapabilities = false,
bindUdpPort = address.udpPort, # Assume same as external
bindTcpPort = address.tcpPort, # Assume same as external
rng = rng,
rng = rng(),
)
nextPort.inc
for capability in capabilities:

View File

@ -55,7 +55,7 @@ proc newTestWakuNode*(
extPort = none(Port),
extMultiAddrs = newSeq[MultiAddress](),
peerStorage: PeerStorage = nil,
maxConnections = builders.MaxConnections,
maxConnections = DefaultMaxConnections,
wsBindPort: Port = (Port) 8000,
wsEnabled: bool = false,
wssEnabled: bool = false,

View File

@ -36,7 +36,7 @@ proc newTestWakuFilter*(
proc newTestWakuFilterClient*(switch: Switch): Future[WakuFilterClient] {.async.} =
let
peerManager = PeerManager.new(switch)
proto = WakuFilterClient.new(peerManager, rng)
proto = WakuFilterClient.new(peerManager, rng())
await proto.start()
switch.mount(proto)

View File

@ -20,7 +20,7 @@ proc newTestWakuLightpushNode*(
peerManager = PeerManager.new(switch)
wakuAutoSharding = Sharding(clusterId: 1, shardCountGenZero: 8)
proto = WakuLightPush.new(
peerManager, rng, handler, some(wakuAutoSharding), rateLimitSetting
peerManager, rng(), handler, some(wakuAutoSharding), rateLimitSetting
)
await proto.start()
@ -30,4 +30,4 @@ proc newTestWakuLightpushNode*(
proc newTestWakuLightpushClient*(switch: Switch): WakuLightPushClient =
let peerManager = PeerManager.new(switch)
WakuLightPushClient.new(peerManager, rng)
WakuLightPushClient.new(peerManager, rng())

View File

@ -19,7 +19,7 @@ proc newTestWakuLegacyLightpushNode*(
): Future[WakuLegacyLightPush] {.async.} =
let
peerManager = PeerManager.new(switch)
proto = WakuLegacyLightPush.new(peerManager, rng, handler, rateLimitSetting)
proto = WakuLegacyLightPush.new(peerManager, rng(), handler, rateLimitSetting)
await proto.start()
switch.mount(proto)
@ -28,4 +28,4 @@ proc newTestWakuLegacyLightpushNode*(
proc newTestWakuLegacyLightpushClient*(switch: Switch): WakuLegacyLightPushClient =
let peerManager = PeerManager.new(switch)
WakuLegacyLightPushClient.new(peerManager, rng)
WakuLegacyLightPushClient.new(peerManager, rng())

View File

@ -1,7 +1,7 @@
{.used.}
import
std/[os, strutils, sequtils, sysrand, math],
std/[os, options, strutils, sequtils, sysrand, math],
stew/byteutils,
testutils/unittests,
chronos,

View File

@ -446,7 +446,7 @@ proc createEthAccount*(
let gasPrice = Quantity(await web3.provider.eth_gasPrice())
web3.defaultAccount = accounts[0]
let pk = keys.PrivateKey.random(rng[])
let pk = keys.PrivateKey.random(common.rng()[])
let acc = Address(toCanonicalAddress(pk.toPublicKey()))
var tx: TransactionArgs
@ -464,7 +464,7 @@ proc createEthAccount*(
return (pk, acc)
proc createEthAccount*(web3: Web3): (keys.PrivateKey, Address) =
let pk = keys.PrivateKey.random(rng[])
let pk = keys.PrivateKey.random(common.rng()[])
let acc = Address(toCanonicalAddress(pk.toPublicKey()))
return (pk, acc)

View File

@ -10,7 +10,7 @@ proc newTestWakuStore*(
): Future[WakuStore] {.async.} =
let
peerManager = PeerManager.new(switch)
proto = WakuStore.new(peerManager, rng, handler)
proto = WakuStore.new(peerManager, rng(), handler)
await proto.start()
switch.mount(proto)
@ -19,4 +19,4 @@ proc newTestWakuStore*(
proc newTestWakuStoreClient*(switch: Switch): WakuStoreClient {.gcsafe.} =
let peerManager = PeerManager.new(switch)
WakuStoreClient.new(peerManager, rng)
WakuStoreClient.new(peerManager, rng())

View File

@ -1,7 +1,7 @@
{.used.}
import
std/sequtils,
std/[options, sequtils],
testutils/unittests,
chronicles,
chronos,