Skip to content

Commit a671834

Browse files
committed
Merge rust-bitcoin#4689: Add Arbitrary impl for relative::LockTime
d1f3976 Add Arbitrary impl for relative::LockTime (Shing Him Ng) Pull request description: Closes rust-bitcoin#4685 ACKs for top commit: tcharding: ACK d1f3976 apoelstra: ACK d1f3976; successfully ran local tests Tree-SHA512: 2560726cbc9c4013a5ebf23b1447c5fb78195a4915d1bd01c608c677a90a63d261bace15a3b60172aa4d66f23ed288e8c0ef92497a2e1277d4568ada113e9039
2 parents 44a4a77 + d1f3976 commit a671834

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

primitives/src/locktime/relative.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
88
use core::{convert, fmt};
99

10+
#[cfg(feature = "arbitrary")]
11+
use arbitrary::{Arbitrary, Unstructured};
12+
1013
use internals::write_err;
1114

1215
use crate::Sequence;
@@ -517,6 +520,16 @@ impl std::error::Error for IsSatisfiedByTimeError {
517520
}
518521
}
519522

523+
#[cfg(feature = "arbitrary")]
524+
impl<'a> Arbitrary<'a> for LockTime {
525+
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
526+
match bool::arbitrary(u)? {
527+
true => Ok(LockTime::Blocks(NumberOfBlocks::arbitrary(u)?)),
528+
false => Ok(LockTime::Time(NumberOf512Seconds::arbitrary(u)?))
529+
}
530+
}
531+
}
532+
520533
#[cfg(test)]
521534
mod tests {
522535
use units::{BlockHeight, BlockTime};

0 commit comments

Comments
 (0)