Add Weight::to_kwu_ceil
It is not immediately obvious why we have floor and ceil versions of `to_vbytes` but not for `to_kwu`. Add a conversion function to get weight by kilo weight units rounding up.
This commit is contained in:
parent
4d0f80f1fc
commit
75594c7299
|
@ -92,6 +92,9 @@ impl Weight {
|
|||
/// Converts to kilo weight units rounding down.
|
||||
pub const fn to_kwu_floor(self) -> u64 { self.0 / 1000 }
|
||||
|
||||
/// Converts to kilo weight units rounding up.
|
||||
pub const fn to_kwu_ceil(self) -> u64 { (self.0 + 999) / 1000 }
|
||||
|
||||
/// Converts to vB rounding down.
|
||||
pub const fn to_vbytes_floor(self) -> u64 { self.0 / Self::WITNESS_SCALE_FACTOR }
|
||||
|
||||
|
@ -298,6 +301,13 @@ mod tests {
|
|||
#[test]
|
||||
fn to_kwu_floor() {
|
||||
assert_eq!(1, Weight(1_000).to_kwu_floor());
|
||||
assert_eq!(1, Weight(1_999).to_kwu_floor());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn to_kwu_ceil() {
|
||||
assert_eq!(1, Weight(1_000).to_kwu_ceil());
|
||||
assert_eq!(2, Weight(1_001).to_kwu_ceil());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in New Issue