What changed, and why it matters
This commit only adds new unit tests for the SignedAmount type. It does not change any production code, fix a bug, or alter behavior. There is no security relevance.
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 two test functions in units/src/amount/result.rs: test_sum_signed_amount_results_with_references and test_sum_signed_amount_with_error_propagation. These mirror existing Amount tests for NumOpResult
Changed components
units/src/amount/result.rs (test module only)Inspect captured patch +24 / −0
diff --git a/units/src/amount/result.rs b/units/src/amount/result.rs
index 607fd8a0..a47ecb02 100644
--- a/units/src/amount/result.rs
+++ b/units/src/amount/result.rs
@@ -349,4 +349,28 @@ mod tests {
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_with_references() {
+ 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.iter().sum();
+ assert_eq!(sum, NumOpResult::Valid(SignedAmount::from_sat_i32(250)));
+ }
+
+ #[test]
+ fn test_sum_signed_amount_with_error_propagation() {
+ let amounts = [
+ NumOpResult::Valid(SignedAmount::from_sat_i32(100)),
+ NumOpResult::Error(NumOpError::while_doing(MathOp::Add)),
+ NumOpResult::Valid(SignedAmount::from_sat_i32(200)),
+ ];
+
+ let sum: NumOpResult<SignedAmount> = amounts.into_iter().sum();
+ assert!(matches!(sum, NumOpResult::Error(_)));
+ }
}
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.