fix(tests): use HmacDrbgContext.new() instead of crypto.newRng()

libp2p v2.0.0's `crypto.newRng()` returns the new `Rng` wrapper type,
which can't be assigned to a `ref HmacDrbgContext` field. The two test
helper modules (tests/testlib/common.nim and tests/test_helpers.nim)
both fall in this pattern; rest of the codebase migrated in the prior
sweep but these two test-only files were missed because they don't
compile during the wakunode2 / chat2mix builds — only when the test
target is built (which CI does, locally we didn't until this PR).

Same fix pattern as the other newRng → HmacDrbgContext.new() migrations.
This commit is contained in:
Prem Chaitanya Prathi 2026-06-04 17:32:25 +05:30
parent d8bbef0c5b
commit 2f24448abd
No known key found for this signature in database
2 changed files with 8 additions and 2 deletions

View File

@ -39,7 +39,10 @@ proc getRng(): ref rand.HmacDrbgContext =
# purpose of the tests, it's ok as long as we only use a single thread
{.gcsafe.}:
if rngVar.rng.isNil:
rngVar.rng = crypto.newRng()
# libp2p v2.0.0: crypto.newRng() returns the new `Rng` wrapper type;
# construct an HmacDrbgContext directly so the field type stays as
# `ref HmacDrbgContext` (what bearssl-style consumers expect).
rngVar.rng = HmacDrbgContext.new()
rngVar.rng
template rng*(): ref rand.HmacDrbgContext =

View File

@ -24,7 +24,10 @@ proc getRng(): ref HmacDrbgContext =
# purpose of the tests, it's ok as long as we only use a single thread
{.gcsafe.}:
if rngVar.rng.isNil():
rngVar.rng = crypto.newRng()
# libp2p v2.0.0: crypto.newRng() returns the new `Rng` wrapper type;
# construct an HmacDrbgContext directly so the field type stays as
# `ref HmacDrbgContext` (what bearssl-style consumers expect).
rngVar.rng = HmacDrbgContext.new()
rngVar.rng