Skip to content

Commit

Permalink
Merge rust-bitcoin#3257: Add Arbitrary to Weight
Browse files Browse the repository at this point in the history
f8edbd1 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 f8edbd1
  Kixunil:
    ACK f8edbd1

Tree-SHA512: b886f78285b5cd06b2531a1e53272cad623a8e43e76e8108abe90668b45d00674b6a867c5ff980ee7f0a34919e1d6bb534624bd0bc67a53c8c9a41ea2ed504e8
  • Loading branch information
apoelstra committed Aug 28, 2024
2 parents 98252f3 + f8edbd1 commit cfb53c7
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions units/src/weight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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::*;
Expand Down

0 comments on commit cfb53c7

Please sign in to comment.