Add Arbitrary to Weight
This commit is contained in:
parent
d7ac6af5b4
commit
f8edbd1f45
|
@ -8,6 +8,9 @@ use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[cfg(feature = "arbitrary")]
|
||||||
|
use arbitrary::{Arbitrary, Unstructured};
|
||||||
|
|
||||||
/// The factor that non-witness serialization data is multiplied by during weight calculation.
|
/// The factor that non-witness serialization data is multiplied by during weight calculation.
|
||||||
pub const WITNESS_SCALE_FACTOR: usize = 4;
|
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);
|
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
Loading…
Reference in New Issue