Add Arbitrary to Weight

This commit is contained in:
yancy 2024-08-27 12:25:08 -05:00
parent d7ac6af5b4
commit f8edbd1f45
1 changed files with 11 additions and 0 deletions

View File

@ -8,6 +8,9 @@ use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[cfg(feature = "arbitrary")]
use arbitrary::{Arbitrary, Unstructured};
/// The factor that non-witness serialization data is multiplied by during weight calculation.
pub const WITNESS_SCALE_FACTOR: usize = 4;
@ -204,6 +207,14 @@ impl<'a> core::iter::Sum<&'a Weight> for Weight {
crate::impl_parse_str_from_int_infallible!(Weight, u64, from_wu);
#[cfg(feature = "arbitrary")]
impl<'a> Arbitrary<'a> for Weight {
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
let w = u64::arbitrary(u)?;
Ok(Weight(w))
}
}
#[cfg(test)]
mod tests {
use super::*;