Skip to content

Add orderbook cancellation depth tests#3

Open
poorandhungrybutbuthappy wants to merge 1 commit into
jackjin1997:mainfrom
poorandhungrybutbuthappy:bounty-2-orderbook-tests
Open

Add orderbook cancellation depth tests#3
poorandhungrybutbuthappy wants to merge 1 commit into
jackjin1997:mainfrom
poorandhungrybutbuthappy:bounty-2-orderbook-tests

Conversation

@poorandhungrybutbuthappy

@poorandhungrybutbuthappy poorandhungrybutbuthappy commented Jun 19, 2026

Copy link
Copy Markdown

Summary

Adds focused Go coverage for the orderbook cancellation and snapshot-depth behavior requested in #2.

Changes

  • Adds bid cancellation coverage that verifies depth removal and order-index deletion.
  • Adds ask cancellation, unknown-order, and closed-book error coverage.
  • Adds snapshot immutability coverage for bid and ask level copies.

Testing

  • go test ./orderbook from market/ - passed.
  • python build.py -m market - passed locally with market build success.
  • python3 build.py -m market exited without output in this Windows shell, so I used the same Python 3.12 runtime via python.
  • The diagnostic step generated large encrypted split .logd artifacts containing local absolute paths, so I did not commit them publicly. I can provide regenerated diagnostics if the maintainer requires them.

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

Summary by CodeRabbit

  • Tests
    • Added unit tests for OrderBook operations, including order cancellation, error handling for invalid and closed books, and snapshot data integrity verification.

@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 689c3ac8-292e-43a8-b7bc-da8cb5d8e374

📥 Commits

Reviewing files that changed from the base of the PR and between 2b54872 and 4162088.

📒 Files selected for processing (1)
  • market/orderbook/orderbook_test.go

📝 Walkthrough

Walkthrough

Adds market/orderbook/orderbook_test.go with five unit tests covering CancelOrder (bid/ask level removal, order index cleanup, status update), ErrOrderNotFound for unknown IDs, ErrBookClosed after Close(), and snapshot immutability via GetSnapshot(). Two local helpers construct test OrderBook and *types.Order instances.

Changes

OrderBook Unit Tests

Layer / File(s) Summary
Test helpers
market/orderbook/orderbook_test.go
newTestOrderBook() builds an OrderBook with fixed decimal config; newTestOrder() constructs limit *types.Order values with RemainingQty initialized from the full quantity string.
CancelOrder and closed-book tests
market/orderbook/orderbook_test.go
Four tests: cancelling a bid removes the bid level and sets order status to types.Cancelled; cancelling an ask removes the ask level; cancelling an unknown ID returns ErrOrderNotFound; after Close(), both AddOrder and CancelOrder return ErrBookClosed.
Snapshot immutability test
market/orderbook/orderbook_test.go
Mutates prices and quantities on a returned snapshot and asserts that a subsequent GetSnapshot() still returns the original values, confirming bid/ask level slices are deep copies.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Poem

🐇 Hoppity-hop through the order book rows,
A bid here cancelled, an ask level goes,
The snapshot stays fresh, no mutation in sight,
ErrBookClosed guards when the market shuts tight.
Each test a small burrow, each assert a seed —
The order book's tidy, precisely agreed! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding unit tests for orderbook cancellation and snapshot depth behavior.
Description check ✅ Passed The description covers all required sections with adequate detail: Summary explains the purpose, Changes lists specific test coverage areas, Testing documents local validation results, and the Checklist is substantially complete with clear justification for omissions.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@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.

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