Reference
referenceSelects the first matching tier and rounds with integer numerator arithmetic.
09 · Fees
Price a payment at one tier selected by an inclusive upper bound, then round and clamp the fee.
referenceSelects the first matching tier and rounds with integer numerator arithmetic.
alt_validDecimal quantization with tier selection by first matching record, versus integer numerator rounding.
wrong_exclusive_boundaryUses an exclusive upper tier boundary.
wrong_float_bpsBinary percentage multiplication mis-rounds exact half-unit ties.
wrong_marginalCharges each band separately instead of selecting one rate.
schedule_unvalidatedExpect: rejectObserved: rejectedDoes not validate schedules inside compute_fee, violating validation on every call whatever the amount.
amount_type_uncheckedExpect: rejectObserved: rejectedAccepts bool and float amounts, violating nonnegative integer amounts never bool.
Each row groups a test’s parameterized cases; any failing case marks the row as Fail. * marks a wrong solution’s declared must_fail test.
| Test | Starter | Reference | Alternative | exclusive boundary | float bps | marginal |
|---|---|---|---|---|---|---|
| Inclusive boundaries | Fail | Pass | Pass | Fail * | Pass | Fail |
| Discovered float ties | Fail | Pass | Pass | Pass | Fail * | Pass |
| Non marginal | Fail | Pass | Pass | Pass | Pass | Fail * |
| Clamps and zero | Fail | Pass | Pass | Pass | Pass | Pass |
| Fee properties | Fail | Pass | Pass | Pass | Pass | Pass |
| Invalid schedule raises for any amount | Fail | Pass | Pass | Pass | Pass | Pass |
| Schedule revalidated after tier list mutation | Fail | Pass | Pass | Pass | Pass | Pass |
| Invalid amount type | Fail | Pass | Pass | Pass | Pass | Pass |
| Test | Starter | Reference | Alternative | exclusive boundary | float bps | marginal |
|---|---|---|---|---|---|---|
| Tier midpoints | Fail | Pass | Pass | Pass | Pass | Fail |
| Ticket worked example with clamps | Fail | Pass | Pass | Pass | Pass | Fail |
| Negative amount rejected | Fail | Pass | Pass | Pass | Pass | Pass |
fees.schedule.compute_fee(amount_minor:int,schedule:Schedule)->int returns integer minor units. Public frozen dataclasses: Tier(up_to_minor:int|None,bps:int,fixed_minor:int) and Schedule(tiers:list[Tier],min_fee_minor:int,max_fee_minor:int).
Amounts are nonnegative ints, never bool; negative/noninteger -> ValueError. Schedule tiers are ordered by strictly increasing nonnegative upper bounds, ending with exactly one None (infinity). Bps/fixed/min/max are nonnegative ints, min <= max. compute_fee raises ValueError for an invalid schedule (checked on every call, whatever the amount).
Worked example: tiers [Tier(10000, 100, 10), Tier(20000, 50, 20), Tier(None, 25, 30)] with min_fee_minor=25, max_fee_minor=100. An amount of 5000 uses the first tier: 5000 x 100 bps = 50, plus 10, so 60. An amount of 15000 uses the second tier on the whole amount: 75 + 20 = 95. An amount of 100 would cost 11 and is raised to the minimum, 25. An amount of 30000 would cost 75 + 30 = 105 and is capped at 100.
Run from starter: python -m pytest tests -q. No real fees, networks or institutions are represented.