fee_rate: add test for mul_by_weight rounding
What changed, and why it matters
This commit only adds a new unit test that checks how a fee rate multiplied by a transaction weight rounds up. It does not change any production code, so it cannot introduce or fix a security vulnerability by itself. It may be related to a prior bug fix, but the commit alone is just a test.
No security action needed. Review the related production code and any prior commits if you suspect the rounding behavior itself is incorrect, but this commit is only a test addition.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds a single test, mul_by_weight_round_up, in units/src/fee_rate/mod.rs. It verifies that FeeRate::from_sat_per_kvb(10).mul_by_weight(Weight::from_wu(500)) returns Amount::from_sat(2). This tests rounding behavior (10 sats/kvB * 0.5 vB = 5 sats/kvB? Actually weight units: 500 WU = 0.5 vBytes, fee rate 10 sats per 1000 vB -> 10500/1000 = 5? Wait, the expected is 2. Let me re-check. Actually from_sat_per_kvb(10) means 10 satoshis per 1000 weight units? No, per kvb. 500 WU is 0.5 vB. 10 sats per 1000 vB = 0.01 sats/vB. 0.5 vB * 0.01 = 0.005 sats. That doesn’t match 2. Let me reconsider: maybe mul_by_weight computes fee_rate (sats/kwu) * weight / 1000? 10 sats/kvb = 10 sats per 1000 vB. Weight 500 WU. The formula might be (fee_rate * weight + 999)/1000 to round up. (10500 + 999)/1000 = 5999/1000 = 5. Still not 2. Hmm. Maybe from_sat_per_kvb(10) stores as 10 sats per 1000 weight units, and weight 500 -> 10*500/1000 = 5. The expected 2 is puzzling. Wait, maybe the test name is ‘round up’ and the expected is 2 because of integer division? Let me not overthink. The point is: this is a test-only change. No production code is modified. The test documents/verifies existing rounding behavior. It is not a security patch.
Changed components
units/src/fee_rate/mod.rsInspect captured patch +8 / −0
diff --git a/units/src/fee_rate/mod.rs b/units/src/fee_rate/mod.rs
index 5d814a99..0f82096c 100644
--- a/units/src/fee_rate/mod.rs
+++ b/units/src/fee_rate/mod.rs
@@ -454,4 +454,12 @@ mod tests {
let got = fee_rate.to_sat_per_mvb();
assert_eq!(got, 1_234_567);
}
+
+ #[test]
+ fn mul_by_weight_round_up() {
+ let fee_rate = FeeRate::from_sat_per_kvb(10);
+ let weight = Weight::from_wu(500);
+ let fee = fee_rate.mul_by_weight(weight).expect("expected fee amount");
+ assert_eq!(fee, Amount::from_sat(2).unwrap());
+ }
}
Why this scored 12/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.