Merge rust-bitcoin/rust-bitcoin#3257: Add Arbitrary to Weight
f8edbd1f45
Add Arbitrary to Weight (yancy) Pull request description: Adds Arbitrary to the Weight type. I had meant to add this with the initial Arbitrary PR but I overlooked it. ACKs for top commit: tcharding: ACKf8edbd1f45
Kixunil: ACKf8edbd1f45
Tree-SHA512: b886f78285b5cd06b2531a1e53272cad623a8e43e76e8108abe90668b45d00674b6a867c5ff980ee7f0a34919e1d6bb534624bd0bc67a53c8c9a41ea2ed504e8
This commit is contained in:
commit
cfb53c7866
|
@ -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