diff --git a/bitcoin/Cargo.toml b/bitcoin/Cargo.toml index b7b49f90..973fcc13 100644 --- a/bitcoin/Cargo.toml +++ b/bitcoin/Cargo.toml @@ -52,7 +52,7 @@ hashbrown = { version = "0.8", optional = true } serde_json = "1.0.0" serde_test = "1.0.19" serde_derive = "1.0.103" -secp256k1 = { version = "0.25.0", features = [ "recovery", "rand-std" ] } +secp256k1 = { version = "0.25.0", features = ["recovery"] } bincode = "1.3.1" [[example]] @@ -60,7 +60,7 @@ name = "bip32" [[example]] name = "handshake" -required-features = ["std"] +required-features = ["std", "rand-std"] [[example]] name = "ecdsa-psbt" @@ -68,4 +68,4 @@ required-features = ["std", "bitcoinconsensus"] [[example]] name = "taproot-psbt" -required-features = ["std", "bitcoinconsensus"] +required-features = ["std", "rand-std", "bitcoinconsensus"] diff --git a/bitcoin/contrib/test.sh b/bitcoin/contrib/test.sh index 68563062..efee8bf8 100755 --- a/bitcoin/contrib/test.sh +++ b/bitcoin/contrib/test.sh @@ -31,9 +31,9 @@ if [ "$DO_LINT" = true ] then cargo clippy --all-features --all-targets -- -D warnings cargo clippy --example bip32 -- -D warnings - cargo clippy --example handshake -- -D warnings + cargo clippy --example handshake --features=rand-std -- -D warnings cargo clippy --example ecdsa-psbt --features=bitcoinconsensus -- -D warnings - cargo clippy --example taproot-psbt --features=bitcoinconsensus -- -D warnings + cargo clippy --example taproot-psbt --features=rand-std,bitcoinconsensus -- -D warnings fi echo "********* Testing std *************" @@ -77,7 +77,7 @@ do done cargo run --example ecdsa-psbt --features=bitcoinconsensus -cargo run --example taproot-psbt --features=bitcoinconsensus +cargo run --example taproot-psbt --features=rand-std,bitcoinconsensus # Build the docs if told to (this only works with the nightly toolchain) if [ "$DO_DOCS" = true ]; then diff --git a/bitcoin/src/consensus/encode.rs b/bitcoin/src/consensus/encode.rs index 1d2311a4..30200d3f 100644 --- a/bitcoin/src/consensus/encode.rs +++ b/bitcoin/src/consensus/encode.rs @@ -816,7 +816,6 @@ mod tests { use super::{deserialize, serialize, Error, CheckedData, VarInt}; use super::{Transaction, BlockHash, FilterHash, TxMerkleNode, TxOut, TxIn}; use crate::consensus::{Encodable, deserialize_partial, Decodable}; - use secp256k1::rand::{thread_rng, Rng}; #[cfg(feature = "std")] use crate::network::{Address, message_blockdata::Inventory}; @@ -1088,7 +1087,10 @@ mod tests { } #[test] + #[cfg(feature = "rand-std")] fn serialization_round_trips() { + use secp256k1::rand::{thread_rng, Rng}; + macro_rules! round_trip { ($($val_type:ty),*) => { $( diff --git a/bitcoin/src/merkle_tree/block.rs b/bitcoin/src/merkle_tree/block.rs index 39abae83..685ef962 100644 --- a/bitcoin/src/merkle_tree/block.rs +++ b/bitcoin/src/merkle_tree/block.rs @@ -499,20 +499,23 @@ impl Decodable for MerkleBlock { #[cfg(test)] mod tests { - use core::cmp::min; - + #[cfg(feature = "rand-std")] use secp256k1::rand::prelude::*; use super::*; use crate::consensus::encode::{deserialize, serialize}; - use crate::hash_types::{TxMerkleNode, Txid}; + #[cfg(feature = "rand-std")] + use crate::hash_types::TxMerkleNode; use crate::hashes::hex::{FromHex, ToHex}; + #[cfg(feature = "rand-std")] use crate::hashes::Hash; - use crate::{merkle_tree, Block}; + use crate::{Block, Txid}; /// accepts `pmt_test_$num` + #[cfg(feature = "rand-std")] fn pmt_test_from_name(name: &str) { pmt_test(name[9..].parse().unwrap()) } + #[cfg(feature = "rand-std")] macro_rules! pmt_tests { ($($name:ident),* $(,)?) => { $( @@ -523,6 +526,7 @@ mod tests { )* } } + #[cfg(feature = "rand-std")] pmt_tests!( pmt_test_1, pmt_test_4, @@ -538,7 +542,11 @@ mod tests { pmt_test_4095 ); + #[cfg(feature = "rand-std")] fn pmt_test(tx_count: usize) { + use core::cmp::min; + use crate::merkle_tree; + let mut rng = thread_rng(); // Create some fake tx ids let tx_ids = (1..=tx_count) @@ -713,6 +721,7 @@ mod tests { assert_eq!(index.len(), 0); } + #[cfg(feature = "rand-std")] impl PartialMerkleTree { /// Flip one bit in one of the hashes - this should break the authentication fn damage(&mut self, rng: &mut ThreadRng) { diff --git a/bitcoin/src/sign_message.rs b/bitcoin/src/sign_message.rs index c5676286..6ec20175 100644 --- a/bitcoin/src/sign_message.rs +++ b/bitcoin/src/sign_message.rs @@ -225,7 +225,7 @@ mod tests { } #[test] - #[cfg(all(feature = "secp-recovery", feature = "base64"))] + #[cfg(all(feature = "secp-recovery", feature = "base64", feature = "rand-std"))] fn test_message_signature() { use core::str::FromStr;