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:
    ACK f8edbd1f45
  Kixunil:
    ACK f8edbd1f45

Tree-SHA512: b886f78285b5cd06b2531a1e53272cad623a8e43e76e8108abe90668b45d00674b6a867c5ff980ee7f0a34919e1d6bb534624bd0bc67a53c8c9a41ea2ed504e8
This commit is contained in:
merge-script 2024-08-28 23:02:13 +00:00
commit cfb53c7866
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
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::*;