Merge rust-bitcoin/rust-bitcoin#3062: Add more unit test coverage for relative LockTime
a76c13f675
Add more unit test coverage for relative LockTime (Shing Him Ng) Pull request description: Adding some test cases for `from_seconds_floor` and one more for `from_seconds_ceil` ACKs for top commit: tcharding: ACKa76c13f675
Kixunil: ACKa76c13f675
Tree-SHA512: 5d773a30fa56842af21109d232ec3eae7fde7ce38aca93dadccc7bfbf14d5207ea329ef737f847e45ba755fd22e1862c3e78e7e64a8a0babebcb0e27a2bb7a90
This commit is contained in:
commit
a28f11c9fb
|
@ -157,6 +157,8 @@ impl std::error::Error for TimeOverflowError {}
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
const MAXIMUM_ENCODABLE_SECONDS: u32 = u16::MAX as u32 * 512;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn from_seconds_ceil_success() {
|
fn from_seconds_ceil_success() {
|
||||||
let actual = Time::from_seconds_ceil(100).unwrap();
|
let actual = Time::from_seconds_ceil(100).unwrap();
|
||||||
|
@ -166,16 +168,41 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn from_seconds_ceil_with_maximum_encodable_seconds_success() {
|
fn from_seconds_ceil_with_maximum_encodable_seconds_success() {
|
||||||
let maximum_encodable_seconds = u16::MAX as u32 * 512;
|
let actual = Time::from_seconds_ceil(MAXIMUM_ENCODABLE_SECONDS).unwrap();
|
||||||
let actual = Time::from_seconds_ceil(maximum_encodable_seconds).unwrap();
|
|
||||||
let expected = Time(u16::MAX);
|
let expected = Time(u16::MAX);
|
||||||
assert_eq!(actual, expected);
|
assert_eq!(actual, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn from_seconds_ceil_causes_time_overflow_error() {
|
fn from_seconds_ceil_causes_time_overflow_error() {
|
||||||
let maximum_encodable_seconds = u16::MAX as u32 * 512;
|
let result = Time::from_seconds_ceil(MAXIMUM_ENCODABLE_SECONDS + 1);
|
||||||
let result = Time::from_seconds_ceil(maximum_encodable_seconds + 1);
|
assert!(result.is_err());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn from_seconds_floor_success() {
|
||||||
|
let actual = Time::from_seconds_floor(100).unwrap();
|
||||||
|
let expected = Time(0_u16);
|
||||||
|
assert_eq!(actual, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn from_seconds_floor_with_exact_interval() {
|
||||||
|
let actual = Time::from_seconds_floor(512).unwrap();
|
||||||
|
let expected = Time(1_u16);
|
||||||
|
assert_eq!(actual, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn from_seconds_floor_with_maximum_encodable_seconds_success() {
|
||||||
|
let actual = Time::from_seconds_floor(MAXIMUM_ENCODABLE_SECONDS + 511).unwrap();
|
||||||
|
let expected = Time(u16::MAX);
|
||||||
|
assert_eq!(actual, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn from_seconds_floor_causes_time_overflow_error() {
|
||||||
|
let result = Time::from_seconds_floor(MAXIMUM_ENCODABLE_SECONDS + 512);
|
||||||
assert!(result.is_err());
|
assert!(result.is_err());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue