Skip to content

feat: Add WebSocket order book delta validation tests (#4)#6

Open
BERT70293 wants to merge 1 commit into
Peter7896:mainfrom
BERT70293:feat/websocket-delta-validation-tests
Open

feat: Add WebSocket order book delta validation tests (#4)#6
BERT70293 wants to merge 1 commit into
Peter7896:mainfrom
BERT70293:feat/websocket-delta-validation-tests

Conversation

@BERT70293

Copy link
Copy Markdown

Summary

Add comprehensive WebSocket order book delta validation tests and supporting delta infrastructure, satisfying all acceptance criteria in #4.

Changes

market/orderbook/orderbook.go

  • Added Delta struct representing a single-side order book level change via WebSocket
  • Added ValidateDelta() function — validates symbol, side, price, quantity, and sequence ordering
  • Added ApplyDelta() — validates then atomically applies a delta; leaves book unchanged on error
  • Added ApplySnapshot() — applies a full depth snapshot with validation
  • Added GetSequence() and GetOrdersCount() helpers
  • Added upsertLevel() for insert-or-update level semantics
  • Added error sentinels: ErrSymbolMismatch, ErrInvalidSide, ErrStaleSequence, ErrInvalidPrice, ErrInvalidQuantity

market/orderbook/orderbook_test.go (new, 650+ lines)

  • Malformed payload rejection: negative/zero price, negative quantity, out-of-range side, symbol mismatch
  • Sequence validation: stale (equal/lower) sequence rejection, valid increment acceptance
  • State preservation: book unchanged after invalid delta (wrong symbol, stale seq, bad price, bad quantity)
  • Snapshot integrity: symbol mismatch and negative price snapshots preserve previous state
  • Recovery path: valid snapshot → valid deltas → correct final state
  • Edge cases: zero-quantity removal, new price level insertion, closed book rejection, sequence tracking
  • All tests are deterministic (no network, no random, no time-dependent logic)

market/matching/engine_test.go (new, 300+ lines)

  • Order validation: zero/negative quantity, zero/negative limit price, market order acceptance
  • Symbol-not-found errors for place/cancel/delta
  • Delta validation through engine-owned order books
  • State preservation on bad deltas
  • Cancel order updates book
  • Shorting disabled enforcement
  • Trade count and empty trades

market/ws/server_test.go (new, 590+ lines)

  • Hub register/unregister/broadcast lifecycle
  • Slow consumer disconnect behavior
  • Delta JSON message round-trip validation (valid, malformed price string, missing fields, non-numeric sequence)
  • HTTP handlers: /health, /depth
  • WebSocket upgrade and message echo (via httptest)
  • Concurrent access safety: 50 concurrent writers + 50 concurrent readers
  • Full integration test: snapshot → delta stream (update, insert, remove) → stale rejection → state preserved → snapshot integrity verified

Testing

  • Packages: market/orderbook, market/matching, market/ws
  • All tests are self-contained, deterministic, and require no live services
  • Cross-platform compatible (Windows/Unix)

Checklist

  • Relevant modules affected by these changes build locally
  • Tests pass locally
  • Diagnostic build log is committed in this PR
  • Documentation has been updated, if applicable
  • Configuration or schema changes are documented, if applicable
  • No generated build artifacts are committed, except the required diagnostic build log
  • Changes are scoped to the PR purpose and avoid unrelated cleanup
  • Security, privacy, and error-handling implications have been considered

  • I would like to request that my diagnostic build log is removed before merging

…4w-dotcom#4)

- Add Delta type, ValidateDelta, ApplyDelta, and ApplySnapshot to orderbook
- Add comprehensive orderbook tests: malformed price/quantity/side/symbol,
  stale/out-of-order sequence rejection, state preservation after invalid
  deltas, snapshot-delta recovery path, concurrent access safety
- Add matching engine tests: order validation edge cases, delta validation
  through engine, state preservation, shorting disabled
- Add WebSocket server tests: hub lifecycle, delta message JSON
  round-trip validation, malformed payload handling, full snapshot+delta
  lifecycle integration test
- All tests are deterministic (no network, no random) for cross-platform reliability

Closes cuentaprueba244w-dotcom#4

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. I don't see the encrypted build diagnostic log artifact (*.logd / builds.compact) committed on this branch yet. Please rerun the build diagnostic/encryption step with the fixed encryptly tooling and commit the generated encrypted log artifact to this PR (typically under diagnostic/).

Blocking review until the encrypted diagnostic log artifact is present.

Notime02 added a commit to Notime02/zeroeye that referenced this pull request Jun 19, 2026
Notime02 added a commit to Notime02/zeroeye that referenced this pull request Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant