Skip to content

Commit 7f3ae16

Browse files
committed
Merge rust-bitcoin#4720: Add Arbitrary impl for BlockHash, TxMerkleNode, and Wtxid
8cde2ca Add Arbitrary impl for BlockHash, TxMerkleNode, and Wtxid (Shing Him Ng) Pull request description: ACKs for top commit: apoelstra: ACK 8cde2ca; successfully ran local tests; sure Tree-SHA512: 3631dc8fa11b1c3a45378aaa3c652f33cf34d7a4383c6154b6b87c0ae71fcd89bb748b8901bf4455491f6a7403114f3e9d9052bb0c4bf67bf77fa673bce5613d
2 parents 8deeae0 + 8cde2ca commit 7f3ae16

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

primitives/src/block.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,13 @@ impl<'a> Arbitrary<'a> for Block {
354354
}
355355
}
356356

357+
#[cfg(feature = "arbitrary")]
358+
impl<'a> Arbitrary<'a> for BlockHash {
359+
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
360+
Ok(BlockHash::from_byte_array(u.arbitrary()?))
361+
}
362+
}
363+
357364
#[cfg(feature = "arbitrary")]
358365
impl<'a> Arbitrary<'a> for Header {
359366
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {

primitives/src/merkle_tree.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
//! Bitcoin Merkle tree functions.
44
5+
#[cfg(feature = "arbitrary")]
6+
use arbitrary::{Arbitrary, Unstructured};
57
use hashes::sha256d;
68

79
hashes::hash_newtype! {
@@ -17,3 +19,10 @@ hashes::impl_hex_for_newtype!(TxMerkleNode, WitnessMerkleNode);
1719
hashes::impl_debug_only_for_newtype!(TxMerkleNode, WitnessMerkleNode);
1820
#[cfg(feature = "serde")]
1921
hashes::impl_serde_for_newtype!(TxMerkleNode, WitnessMerkleNode);
22+
23+
#[cfg(feature = "arbitrary")]
24+
impl<'a> Arbitrary<'a> for TxMerkleNode {
25+
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
26+
Ok(TxMerkleNode::from_byte_array(u.arbitrary()?))
27+
}
28+
}

primitives/src/transaction.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,13 @@ impl<'a> Arbitrary<'a> for Txid {
652652
}
653653
}
654654

655+
#[cfg(feature = "arbitrary")]
656+
impl<'a> Arbitrary<'a> for Wtxid {
657+
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
658+
Ok(Wtxid::from_byte_array(u.arbitrary()?))
659+
}
660+
}
661+
655662
#[cfg(feature = "alloc")]
656663
#[cfg(test)]
657664
mod tests {

0 commit comments

Comments
 (0)