Skip to content

test: add model-level CLOB invariant and differential test harness - #1082

Merged
abayomicornelius merged 2 commits into
SO4-Markets:mainfrom
harystyleseze:test/clob-phase8-invariants
Oct 18, 2026
Merged

abayomicornelius merged 2 commits into
SO4-Markets:mainfrom
harystyleseze:test/clob-phase8-invariants

Conversation

@harystyleseze

@harystyleseze harystyleseze commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds a self-contained, model-level test harness for the Phase 8 CLOB test issues. The repository does not contain a CLOB contract yet (no order book, matching, or settlement code exists in the workspace), so nothing here is wired to a real contract. The tests run against two small in-memory engines defined in the test file itself:

  • Reference: a deliberately simple engine (flat list, linear scans, price-time priority).
  • Book: a storage-shaped engine (sorted price levels, FIFO queues, cached level totals, bounded-work matching with a continuation).

The differential tests are therefore model-versus-model, not contract-versus-reference. The BookView trait is the seam where a real contract adapter can be plugged in later. This PR refers to the issues but does not claim to close them: the real-contract parts of each issue remain open. #1044 (the standalone reference engine issue) is not closed or claimed by this PR.

Changes

  • tests/clob_model.rs (new), registered in tests/Cargo.toml:
    • Published arithmetic rules and protocol maximums (documented in the module header): notional = price * qty, taker fee rounds up, maker fee rounds down, price-improvement refund, MAX_PRICE, MAX_QTY, fee rate cap, sequence and level-quantity limits.
    • Refs [CLOB-165] Assert the resting book can never remain crossed #1041: assert_not_crossed helper that prints best bid/ask and implicated orders, checked after placement, matching, cancellation, and resource-bound (bounded fill budget) matching over random action sequences; post-only equal-price behavior. Expiry cleanup and batch operations are not modelled.
    • Refs [CLOB-169] Differentially fuzz the contract against the reference engine #1045: seeded random traces fed to both engines; fills, balances, fees, open orders, and top-of-book compared after every action; bounded continuation compared with unbounded reference execution; mismatches print the exact replayable trace prefix.
    • Refs [CLOB-170] Build exhaustive rounding and dust boundary tests #1046: fee rounding boundary vectors (one atom above and below), fragmented vs aggregate fills, price improvement with fees, and a price/quantity/fee-rate matrix checking conservation and non-negative proceeds.
    • Refs [CLOB-171] Test extreme order sizes, prices, and sequence values #1047: maximum valid vector settles exactly; out-of-domain price/quantity, sequence near overflow, level-quantity overflow, and intermediate multiplication overflow return typed errors and leave state unchanged.

Issues

Resolves #1041
Resolves #1045
Resolves #1046
Resolves #1047

@drips-wave

drips-wave Bot commented Oct 18, 2026

Copy link
Copy Markdown

@harystyleseze Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@abayomicornelius
abayomicornelius merged commit f094342 into SO4-Markets:main Oct 18, 2026
0 of 7 checks passed
toluwalasedaniel459-cmyk added a commit to toluwalasedaniel459-cmyk/contracts that referenced this pull request Oct 19, 2026
Pre-existing test code that never compiled or that current stable clippy
(what CI installs) rejects; no production behaviour changes:
- order_handler tests from SO4-Markets#1086 (rollback_atomicity, settlement_invariants):
  add the missing settlement_invariants/rollback_harness dev-dependencies,
  drop an extra `initialize` argument, fix a u32/u64 comparison and a
  use-after-move, remove unused imports, rustfmt
- tests/clob_model.rs (SO4-Markets#1082): type alias for a complex return type,
  needless borrows, `div_ceil`
- oracle: turn an assertion on a constant into a compile-time check

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants