Commit message · Andrew PoelstraMerge rust-bitcoin/rust-bitcoin#7081: units: Finish using amount test helpers
782f83ce6f28fb7948ad045cebce79b418024eda units: Document amount test helpers (PeterXMR)
2226fdfc01bf555110ee2d9e03895fe09e96314b units: Finish using amount test helpers (PeterXMR)
Pull request description:
#6988 switched most of the amount tests over to the `sat`, `ssat`, `res` and `sres` helpers. This finishes the job across all amount test code:
- the `add` and `sub` tests built the expected `NumOpResult` with `sat(n).into()` / `ssat(n).into()`; they now use `res(n)` / `sres(n)`.
- the `check_res!` macro defined its own `from_sat(..).unwrap()` closure and wrapped amounts with `NumOpResult::from`; it now takes the helper names (`check_res!(sat, res, ..)`) instead of the amount type.
- a few remaining `NumOpResult::Valid(..)` / `NumOpResult::from(..)` wrappers in `tests.rs`, including around `Amount::ZERO` / `SignedAmount::ZERO`, now use `res` / `sres`.
- the tests in `amount/ops.rs` called `Amount::from_sat_u32` / `SignedAmount::from_sat_i32` directly because the helpers were private to `amount/tests.rs`. The helpers are now `pub(super)` and imported there. The `sat`, `ssat` and `res` locals in those tests are renamed so they don't shadow the helpers.
The second commit adds a short doc comment to each of `sat`, `ssat`, `res` and `sres`.
Tests outside the `amount` module (`fee.rs`, `fee_rate/mod.rs`, `result.rs`) are intentionally left as they are, since the helper names are too terse to use outside `amount`.
I went with `pub(super)` rather than moving the `ops` tests into `tests.rs` to keep the diff small; happy to move them instead if preferred.
After this, the only direct constructor calls left in amount test code are inside the helpers. `NumOpResult::from` is still used around `MAX_MONEY` constants, which the integer helpers don't cover.
Test refactor only.
Closes #4211
This patch was written with the assistance of an LLM (Claude Opus 5.5) and reviewed by me.
ACKs for top commit:
apoelstra:
ACK 782f83ce6f28fb7948ad045cebce79b418024eda; successfully ran local tests
tcharding:
ACK 782f83ce6f28fb7948ad045cebce79b418024eda
satsfy:
ACK 782f83ce6f28fb7948ad045cebce79b418024eda
Tree-SHA512: 3aa6273482abc573e9416d6bff4d775aec2f18da2224f3e6ba31c368eb5e93b168032868ae2b51f46d727ffb69852d339d26dc7443c4d84f385398d66a02c647
100/100 · StrongMessage clarity
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode✓ Mentions testing or verification✓ Links an issue, advisory, or supporting reference
Why it was queuedmerge-commit duplicate discount