What changed, and why it matters
This commit only adds new unit tests for an existing Sum implementation. It does not change any production code, fix a bug, or introduce new functionality. There is no security relevance.
Recommended action
No action needed; this is a test-only change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds four test cases in units/src/amount/result.rs under a #[cfg(test)] module. The tests verify that NumOpResult
Changed components
Not specified
Inspect captured patch +52 / −0
diff --git a/units/src/amount/result.rs b/units/src/amount/result.rs
index ef3735e6..86291bde 100644
--- a/units/src/amount/result.rs
+++ b/units/src/amount/result.rs
@@ -298,3 +298,55 @@ impl<'a> core::iter::Sum<&'a NumOpResult<SignedAmount>> for NumOpResult<SignedAm
})
}
}
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn test_sum_amount_results() {
+ let amounts = [
+ NumOpResult::Valid(Amount::from_sat_u32(100)),
+ NumOpResult::Valid(Amount::from_sat_u32(200)),
+ NumOpResult::Valid(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_with_references() {
+ let amounts = [
+ NumOpResult::Valid(Amount::from_sat_u32(100)),
+ NumOpResult::Valid(Amount::from_sat_u32(200)),
+ NumOpResult::Valid(Amount::from_sat_u32(300)),
+ ];
+
+ let sum: NumOpResult<Amount> = amounts.iter().sum();
+ assert_eq!(sum, NumOpResult::Valid(Amount::from_sat_u32(600)));
+ }
+
+ #[test]
+ fn test_sum_signed_amount_results() {
+ let amounts = [
+ NumOpResult::Valid(SignedAmount::from_sat_i32(100)),
+ NumOpResult::Valid(SignedAmount::from_sat_i32(-50)),
+ NumOpResult::Valid(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_with_error_propagation() {
+ let amounts = [
+ NumOpResult::Valid(Amount::from_sat_u32(100)),
+ NumOpResult::Error(NumOpError::while_doing(MathOp::Add)),
+ NumOpResult::Valid(Amount::from_sat_u32(200)),
+ ];
+
+ let sum: NumOpResult<Amount> = amounts.into_iter().sum();
+ assert!(matches!(sum, NumOpResult::Error(_)));
+ }
+}
Risk score
Our methodology →Why this scored 15/100
Human-validated context
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
No validated notes yet.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.