Skip to content

Commit

Permalink
Merge rust-bitcoin#3274: Add Arbitrary to SignedAmount type
Browse files Browse the repository at this point in the history
3f244db Add Arbitrary to SignedAmount type (yancy)

Pull request description:

  While proptesting, I've found Arbitrary for SingedAmount to be useful.  Would appreciate adding this as well.

ACKs for top commit:
  tcharding:
    ACK 3f244db
  Kixunil:
    ACK 3f244db

Tree-SHA512: f293215505db85998135c75e147f4cb0031a08c7db619b706e6c7d632c6f23783af56992531396aecc6e3da55b107a7f2c7ec4d68a3e5737ebcf4225f306ed29
  • Loading branch information
apoelstra committed Aug 30, 2024
2 parents 904fefb + 3f244db commit c2e3e86
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions units/src/amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1593,6 +1593,14 @@ impl core::iter::Sum for SignedAmount {
}
}

#[cfg(feature = "arbitrary")]
impl<'a> Arbitrary<'a> for SignedAmount {
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
let s = i64::arbitrary(u)?;
Ok(SignedAmount(s))
}
}

/// Calculates the sum over the iterator using checked arithmetic.
pub trait CheckedSum<R>: private::SumSeal<R> {
/// Calculates the sum over the iterator using checked arithmetic. If an over or underflow would
Expand Down

0 comments on commit c2e3e86

Please sign in to comment.