What changed, and why it matters
This commit only adds new unit tests for summing Amount and SignedAmount values into a NumOpResult. It does not change any production code, fix a bug, or alter behavior. There is no security issue here.
No action needed; this is a test-only change with no security relevance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds two test functions, test_sum_amounts and test_sum_signed_amounts, to units/src/amount/result.rs. They verify that iterators of Amount and SignedAmount can be summed into NumOpResult
Changed components
units/src/amount/result.rs (tests only)Inspect captured patch +24 / −0
diff --git a/units/src/amount/result.rs b/units/src/amount/result.rs
index 7f8c5631..0d4e6edb 100644
--- a/units/src/amount/result.rs
+++ b/units/src/amount/result.rs
@@ -263,6 +263,18 @@ impl<'a> core::iter::Sum<&'a Self> for NumOpResult<SignedAmount> {
mod tests {
use super::*;
+ #[test]
+ fn test_sum_amounts() {
+ let amounts = [
+ Amount::from_sat_u32(100),
+ Amount::from_sat_u32(200),
+ Amount::from_sat_u32(300),
+ ];
+
+ let sum: NumOpResult<Amount> = amounts.into_iter().sum();
+ assert_eq!(sum, NumOpResult::Valid(Amount::from_sat_u32(600)));
+ }
+
#[test]
fn test_sum_amount_results() {
let amounts = [
@@ -299,6 +311,18 @@ mod tests {
assert!(matches!(sum, NumOpResult::Error(_)));
}
+ #[test]
+ fn test_sum_signed_amounts() {
+ let amounts = [
+ SignedAmount::from_sat_i32(100),
+ SignedAmount::from_sat_i32(-50),
+ SignedAmount::from_sat_i32(200),
+ ];
+
+ let sum: NumOpResult<SignedAmount> = amounts.into_iter().sum();
+ assert_eq!(sum, NumOpResult::Valid(SignedAmount::from_sat_i32(250)));
+ }
+
#[test]
fn test_sum_signed_amount_results() {
let amounts = [
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.