Repository navigation
cargo mutant test cases. - #36
Conversation
Exchange calls the inherent `check_*_with_market` methods in Cross mode, so the trait impl was never reached. Its `check_maintenance_margin` duplicated the isolated engine's static entry-price check, and 10 mutants in it survived `cargo mutants` (including an inverted liquidation condition). Removing the dead code is better than testing behaviour no caller can reach.
Cross-mode limit orders had no test, so even inverting the excess check in `check_limit_order_with_market` survived `cargo mutants`. The flip path of `check_market_order_with_market` was also untested. The new tests pin the admission boundaries (zero excess, exactly enough post-flip equity) and make the uPnL, fees and the realized pnl of the closed leg decide the outcome. The repeated contract specs, configs and `Bba` literals are replaced by helpers, and the `bba` helper duplicated in two test files moves to `tests/mod.rs`.
The "both quotes are positive" check was written out three times (twice in `Exchange::reconcile_margin`, once in the portfolio's `MarketSlot`). It now lives on `MarketState`, so one set of tests covers every caller. The cross branch of `reconcile_margin` had no test where the uPnL or a missing quote decided the outcome; `cargo mutants` could ignore the uPnL, flip its sign or invert the quote check unnoticed. New tests cover a margin call caused by an unrealized loss, orders kept because an unrealized profit covers them exactly, and the entry-notional maintenance fallback for a one-sided book.
Only the sell side of `clamp_reduce_only_quantity` was tested, so making the buy guard always true (clamping a reduce-only buy to a long and increasing it) survived `cargo mutants`. Also assert that zero is neither positive nor negative for both currencies, because the guard relies on it for a flat position.
`remove_by_id`, `remove_by_user_id` and both bulk cancels each repeated the `notional_sum` and `num_reduce_only` updates. They now share `untrack`, which also asserts that the reduce-only counter cannot underflow. `cargo mutants` showed that removing by user id or cancelling oversized plain orders could add the notional instead of subtracting it (overstating order margin) without a failing test, and that the reduce-only counter could drift. New tests pin the bookkeeping of every removal path, a reduce-only cap equal to the resting total, and the maker fee reserve of a new limit order, which only had positive-fee coverage away from the admission boundary.
`Ledger` had no unit tests, and integration tests only asserted that `reconciles_to` holds, so replacing it with `true` survived `cargo mutants`. The new unit tests check that it rejects off-by-one-ulp equities, that `record_flows` skips zero flows and tracks the running equity, and that a bad-debt debit panics. The bad-debt delta in `Exchange::record_ledger_flows` was only exercised with zero prior bad debt. A funding payment that bankrupts a profitable short, followed by its liquidation, now journals a settlement that starts with existing bad debt. `total_by_kind` and `net_cashflow` share `sum_deltas`.
`MaintenanceMarginSchedule::from_brackets` re-checked each rate and cap, which `MaintenanceMarginTier::new` validates anyway. `cargo mutants` could disable these copies without a failing test because they were dead. The existing `from_brackets_rejects_*` tests still cover both bounds through `new`. The first-tier guard on the rate-decrease check goes too: a first rate below zero is rejected either way. New tests pin the trail-distance bounds of `StopOrder::trailing_stop` for both sides. Before, a non-positive callback rate, or a rate of 1 on a buy stop, was accepted when the rate check was disabled. A liquidation fee of zero is now tested as valid.
SummaryVersion bump 0.143.2 → 0.143.3 that extracts IssuesNone |
No description provided.