Merge rust-bitcoin/rust-bitcoin#3284: Add a few unit tests for Sequence
4a8e2c3704
Add tests for sequence (Shing Him Ng) Pull request description: Add a few unit tests for Sequence ACKs for top commit: apoelstra: ACK4a8e2c3704
successfully ran local tests; sure tcharding: ACK4a8e2c3704
Tree-SHA512: fb793a6a94a9d3f1522357f98a73a87618ba70776875b3ce051631970ca6c15998401dece47e426f7040770b8d24ee1b72f206d3164b7ca76492e12e86116677
This commit is contained in:
commit
7e5911923f
|
@ -284,3 +284,35 @@ impl<'a> Arbitrary<'a> for Sequence {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
#[cfg(feature = "alloc")]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
const MAXIMUM_ENCODABLE_SECONDS: u32 = u16::MAX as u32 * 512;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn from_seconds_floor_success() {
|
||||||
|
let expected = Sequence::from_hex("0x0040ffff").unwrap();
|
||||||
|
let actual = Sequence::from_seconds_floor(MAXIMUM_ENCODABLE_SECONDS + 511).unwrap();
|
||||||
|
assert_eq!(actual, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn from_seconds_floor_causes_overflow_error() {
|
||||||
|
assert!(Sequence::from_seconds_floor(MAXIMUM_ENCODABLE_SECONDS + 512).is_err());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn from_seconds_ceil_success() {
|
||||||
|
let expected = Sequence::from_hex("0x0040ffff").unwrap();
|
||||||
|
let actual = Sequence::from_seconds_ceil(MAXIMUM_ENCODABLE_SECONDS - 511).unwrap();
|
||||||
|
assert_eq!(actual, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn from_seconds_ceil_causes_overflow_error() {
|
||||||
|
assert!(Sequence::from_seconds_ceil(MAXIMUM_ENCODABLE_SECONDS + 1).is_err());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue