fix(tests): replace removed newStandardSwitch with SwitchBuilder

libp2p v2.0.0 dropped the `newStandardSwitch` convenience constructor.
Update `wakucore.newTestSwitch` to use the equivalent SwitchBuilder
chain (`withRng(...).withPrivateKey(...).withAddress(...).withTcp
Transport().withMplex().withNoise().build()`) and replace direct
`newStandardSwitch(...)` call sites in tests with `newTestSwitch(...)`.

Files:
  - tests/testlib/wakucore.nim: rewrite `newTestSwitch` body.
  - tests/waku_filter_v2/test_waku_filter_dos_protection.nim (2 sites)
  - tests/waku_filter_v2/test_waku_client.nim (6 sites)
  - tests/wakunode_rest/test_rest_store.nim (6 sites, also rewrite
    `Opt.some(key)` → `some(key)` since `newTestSwitch` takes
    `std/options.Option`).
This commit is contained in:
Prem Chaitanya Prathi 2026-06-04 18:34:43 +05:30
parent 97a2722201
commit 5561fcb532
No known key found for this signature in database
4 changed files with 28 additions and 17 deletions

View File

@ -40,9 +40,20 @@ proc ethSecp256k1Key*(hex: string): eth_keys.PrivateKey =
proc newTestSwitch*(
key = none(libp2p_keys.PrivateKey), address = none(MultiAddress)
): Switch =
# libp2p v2.0.0 dropped the `newStandardSwitch` convenience constructor;
# callers now compose a `SwitchBuilder` explicitly with the same transport/
# muxer/security defaults the v1.x helper used (TCP + Mplex + Noise).
let peerKey = key.get(generateSecp256k1Key())
let peerAddr = address.get(MultiAddress.init("/ip4/127.0.0.1/tcp/0").get())
return newStandardSwitch(privKey = Opt.some(peerKey), addrs = peerAddr)
return SwitchBuilder
.new()
.withRng(newBearSslRng(common.rng()))
.withPrivateKey(peerKey)
.withAddress(peerAddr)
.withTcpTransport()
.withMplex()
.withNoise()
.build()
# Waku message

View File

@ -37,8 +37,8 @@ suite "Waku Filter - End to End":
pubsubTopic = DefaultPubsubTopic
contentTopic = DefaultContentTopic
contentTopicSeq = @[contentTopic]
serverSwitch = newStandardSwitch()
clientSwitch = newStandardSwitch()
serverSwitch = newTestSwitch()
clientSwitch = newTestSwitch()
wakuFilter = await newTestWakuFilter(serverSwitch)
wakuFilterClient = await newTestWakuFilterClient(clientSwitch)
@ -104,7 +104,7 @@ suite "Waku Filter - End to End":
suite "Subscribe":
asyncTest "Server remote peer info doesn't match an online server":
# Given an offline service node
let offlineServerSwitch = newStandardSwitch()
let offlineServerSwitch = newTestSwitch()
let offlineServerRemotePeerInfo =
offlineServerSwitch.peerInfo.toRemotePeerInfo()
@ -719,7 +719,7 @@ suite "Waku Filter - End to End":
# Given a WakuFilterClient list of size MaxFilterPeers
var clients: seq[(WakuFilterClient, Switch)] = @[]
for i in 0 ..< MaxFilterPeers:
let standardSwitch = newStandardSwitch()
let standardSwitch = newTestSwitch()
let wakuFilterClient = await newTestWakuFilterClient(standardSwitch)
clients.add((wakuFilterClient, standardSwitch))
@ -736,7 +736,7 @@ suite "Waku Filter - End to End":
wakuFilter.subscriptions.subscribedPeerCount() == MaxFilterPeers
# When initialising a new WakuFilterClient and subscribing it to the same service
let standardSwitch = newStandardSwitch()
let standardSwitch = newTestSwitch()
let wakuFilterClient = await newTestWakuFilterClient(standardSwitch)
await standardSwitch.start()
let subscribeResponse = await wakuFilterClient.subscribe(
@ -750,7 +750,7 @@ suite "Waku Filter - End to End":
asyncTest "Multiple Subscriptions":
# Given a second service node
let serverSwitch2 = newStandardSwitch()
let serverSwitch2 = newTestSwitch()
let wakuFilter2 = await newTestWakuFilter(serverSwitch2)
await allFutures(serverSwitch2.start())
let serverRemotePeerInfo2 = serverSwitch2.peerInfo.toRemotePeerInfo()

View File

@ -24,7 +24,7 @@ type AFilterClient = ref object of RootObj
proc init(T: type[AFilterClient]): T =
var r = T(
clientSwitch: newStandardSwitch(),
clientSwitch: newTestSwitch(),
msgSeq: @[],
pushHandlerFuture: newPushHandlerFuture(),
)
@ -93,7 +93,7 @@ suite "Waku Filter - DOS protection":
pubsubTopic = DefaultPubsubTopic
contentTopic = DefaultContentTopic
contentTopicSeq = @[contentTopic]
serverSwitch = newStandardSwitch()
serverSwitch = newTestSwitch()
wakuFilter = await newTestWakuFilter(
serverSwitch, rateLimitSetting = some((3, 1000.milliseconds))
)

View File

@ -107,7 +107,7 @@ procSuite "Waku Rest API - Store v3":
node.mountStoreClient()
let key = generateEcdsaKey()
var peerSwitch = newStandardSwitch(Opt.some(key))
var peerSwitch = newTestSwitch(some(key))
await peerSwitch.start()
peerSwitch.mount(node.wakuStore)
@ -184,7 +184,7 @@ procSuite "Waku Rest API - Store v3":
node.mountStoreClient()
let key = generateEcdsaKey()
var peerSwitch = newStandardSwitch(Opt.some(key))
var peerSwitch = newTestSwitch(some(key))
await peerSwitch.start()
peerSwitch.mount(node.wakuStore)
@ -253,7 +253,7 @@ procSuite "Waku Rest API - Store v3":
node.mountStoreClient()
let key = generateEcdsaKey()
var peerSwitch = newStandardSwitch(Opt.some(key))
var peerSwitch = newTestSwitch(some(key))
await peerSwitch.start()
peerSwitch.mount(node.wakuStore)
@ -348,7 +348,7 @@ procSuite "Waku Rest API - Store v3":
node.mountStoreClient()
let key = generateEcdsaKey()
var peerSwitch = newStandardSwitch(Opt.some(key))
var peerSwitch = newTestSwitch(some(key))
await peerSwitch.start()
peerSwitch.mount(node.wakuStore)
@ -421,7 +421,7 @@ procSuite "Waku Rest API - Store v3":
node.mountStoreClient()
let key = generateEcdsaKey()
var peerSwitch = newStandardSwitch(Opt.some(key))
var peerSwitch = newTestSwitch(some(key))
await peerSwitch.start()
peerSwitch.mount(node.wakuStore)
@ -510,7 +510,7 @@ procSuite "Waku Rest API - Store v3":
node.mountStoreClient()
let key = generateEcdsaKey()
var peerSwitch = newStandardSwitch(Opt.some(key))
var peerSwitch = newTestSwitch(some(key))
await peerSwitch.start()
peerSwitch.mount(node.wakuStore)
@ -560,7 +560,7 @@ procSuite "Waku Rest API - Store v3":
node.mountStoreClient()
let key = generateEcdsaKey()
var peerSwitch = newStandardSwitch(Opt.some(key))
var peerSwitch = newTestSwitch(some(key))
await peerSwitch.start()
let client = newRestHttpClient(initTAddress(restAddress, restPort))
@ -742,7 +742,7 @@ procSuite "Waku Rest API - Store v3":
node.mountStoreClient()
let key = generateEcdsaKey()
var peerSwitch = newStandardSwitch(Opt.some(key))
var peerSwitch = newTestSwitch(some(key))
await peerSwitch.start()
peerSwitch.mount(node.wakuStore)