Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions market/ws/ws_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ws

import (
"encoding/json"
"testing"
)

func TestWebSocketOrderBookDeltaValidation(t *testing.T) {
// Test valid snapshot followed by valid deltas
validSnapshot := `{"snapshot": {"bids": [{"price": 10, "quantity": 100}], "asks": [{"price": 20, "quantity": 200}]}}`
var snapshot map[string]interface{}
json.Unmarshal([]byte(validSnapshot), &snapshot)
if _, ok := snapshot["snapshot"];(ok && snapshot["snapshot"] != nil) {
t.Errorf("Expected snapshot to be nil, but got %v", snapshot["snapshot"])
}

// Test recovery path and live update path
recoveryPath := `{"recovery": true}`
json.Unmarshal([]byte(recoveryPath), &snapshot)
if _, ok := snapshot["recovery"];(ok && snapshot["recovery"] != true) {
t.Errorf("Expected recovery to be true, but got %v", snapshot["recovery"])
}
}