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:
Tobin C. Harding 2024-12-12 11:08:59 +11:00
parent 4d0f80f1fc
commit 75594c7299
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
1 changed files with 10 additions and 0 deletions

View File

@ -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]