Remove std requirement for bitcoin merkle_tree tests
What changed, and why it matters
This commit only changes test code in the rust-bitcoin project. It removes feature gates so that some merkle tree tests can run without the 'std' (standard library) feature. There is no change to production code, no security fix, and no vulnerability introduced.
No security action needed. This is a routine test infrastructure cleanup.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit removes #[cfg(feature = “std”)] guards from test-only code in bitcoin/src/merkle_tree/block.rs. The affected items (a PRNG, constants, macros, and test helper functions) were previously gated behind std only because they used format!(), but that dependency has been removed. The change enables these tests to run in no_std test configurations. It does not alter any runtime, public API, or consensus-critical code.
Changed components
bitcoin/src/merkle_tree/block.rs (test module only)Inspect captured patch +0 / −9
diff --git a/bitcoin/src/merkle_tree/block.rs b/bitcoin/src/merkle_tree/block.rs
index 0c9572ac..0fdcf89b 100644
--- a/bitcoin/src/merkle_tree/block.rs
+++ b/bitcoin/src/merkle_tree/block.rs
@@ -532,7 +532,6 @@ impl<'a> Arbitrary<'a> for MerkleBlock {
mod tests {
use hex::{DisplayHex, FromHex};
use hex_lit::hex;
- #[cfg(feature = "std")]
use core::cmp;
use super::*;
@@ -541,16 +540,13 @@ mod tests {
use crate::Txid;
// `bloc` in hex.
- #[cfg(feature = "std")]
const PRNG_SEED: usize = 0x626C6F63;
// Simple and deterministic PRNG, not suitable for cryptographic use cases.
- #[cfg(feature = "std")]
struct LcgPrng {
state: usize,
}
- #[cfg(feature = "std")]
impl LcgPrng {
const P: usize = 1039;
const Q: usize = 677;
@@ -578,7 +574,6 @@ mod tests {
}
}
- #[cfg(feature = "std")]
macro_rules! pmt_tests {
($($name:ident),* $(,)?) => {
$(
@@ -590,7 +585,6 @@ mod tests {
}
}
- #[cfg(feature = "std")]
pmt_tests!(
pmt_test_1,
pmt_test_4,
@@ -607,10 +601,8 @@ mod tests {
);
/// Parses the transaction count out of `name` with form: `pmt_test_$num`.
- #[cfg(feature = "std")]
fn pmt_test_from_name(name: &str) { pmt_test(name[9..].parse().unwrap()) }
- #[cfg(feature = "std")]
fn pmt_test(tx_count: usize) {
let mut rng = LcgPrng::new(PRNG_SEED ^ tx_count);
// Create some fake tx ids
@@ -780,7 +772,6 @@ mod tests {
assert_eq!(index.len(), 0);
}
- #[cfg(feature = "std")]
impl PartialMerkleTree {
/// Flip one bit in one of the hashes - this should break the authentication
fn damage(&mut self, rng: &mut LcgPrng) {
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.