-
Notifications
You must be signed in to change notification settings - Fork 2
fix(#2): [$40 BOUNTY] [Go] Add order book cancellation depth tests #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| // orderbook_test.go | ||
|
|
||
| package orderbook | ||
|
|
||
| import ( | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestCancelBid(t *testing.T) { | ||
| ob := NewOrderBook() | ||
| orderID := ob.AddBid(100, 1) | ||
| ob.CancelOrder(orderID) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assert Both tests ignore the returned error from Also applies to: 22-22 🤖 Prompt for AI Agents |
||
|
|
||
| if _, exists := ob.bids[orderID]; exists { | ||
| t.Fatalf("expected bid to be removed, but it still exists") | ||
|
Comment on lines
+14
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The tests index Also applies to: 24-25, 55-56 🤖 Prompt for AI Agents |
||
| } | ||
| } | ||
|
|
||
| func TestCancelAsk(t *testing.T) { | ||
| ob := NewOrderBook() | ||
| orderID := ob.AddAsk(100, 1) | ||
| ob.CancelOrder(orderID) | ||
|
|
||
| if _, exists := ob.asks[orderID]; exists { | ||
| t.Fatalf("expected ask to be removed, but it still exists") | ||
| } | ||
| } | ||
|
|
||
| func TestCancelUnknownOrder(t *testing.T) { | ||
| ob := NewOrderBook() | ||
| err := ob.CancelOrder("unknownID") | ||
|
|
||
| if err != ErrOrderNotFound { | ||
| t.Fatalf("expected ErrOrderNotFound, got %v", err) | ||
| } | ||
| } | ||
|
|
||
| func TestClosedBookRejectsOperations(t *testing.T) { | ||
| ob := NewOrderBook() | ||
| ob.Close() | ||
| err := ob.AddBid(100, 1) | ||
|
|
||
| if err != ErrBookClosed { | ||
| t.Fatalf("expected ErrBookClosed, got %v", err) | ||
| } | ||
| } | ||
|
|
||
| func TestSnapshotImmutability(t *testing.T) { | ||
| ob := NewOrderBook() | ||
| ob.AddBid(100, 1) | ||
| snapshot := ob.Snapshot() | ||
|
|
||
| snapshot.Bids[0].Price = 200 // Attempt to mutate snapshot | ||
|
|
||
| if ob.bids[1].Price == 200 { | ||
| t.Fatalf("expected internal bids to be immutable") | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AddBidis asserted with incompatible return types (compile blocker).Line 11 treats
AddBidas returning an order ID, but Line 41 treats the same call as returning anerror. Both cannot be true for one method signature, so this test file won’t compile as written.Also applies to: 41-44
🤖 Prompt for AI Agents