From 2f24448abda22c67003aac5e777eebbd7b0dbf4a Mon Sep 17 00:00:00 2001 From: Prem Chaitanya Prathi Date: Thu, 4 Jun 2026 17:32:25 +0530 Subject: [PATCH] fix(tests): use HmacDrbgContext.new() instead of crypto.newRng() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- tests/test_helpers.nim | 5 ++++- tests/testlib/common.nim | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/test_helpers.nim b/tests/test_helpers.nim index bd1d837b6..e46a8c894 100644 --- a/tests/test_helpers.nim +++ b/tests/test_helpers.nim @@ -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 = diff --git a/tests/testlib/common.nim b/tests/testlib/common.nim index 216320692..6d5340668 100644 --- a/tests/testlib/common.nim +++ b/tests/testlib/common.nim @@ -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