Skip to content

Commit 26ea9f8

Browse files
Create infrastructure_test.rs
1 parent 8ad3ac0 commit 26ea9f8

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
//! Test to verify the test infrastructure is working correctly
2+
3+
mod common;
4+
5+
use aggregator_core::Exchange;
6+
use common::{assert_arbitrage_opportunity, assert_no_arbitrage_opportunities, TestDataFactory};
7+
8+
#[tokio::test]
9+
async fn test_infrastructure_basic_functionality() {
10+
// Test TestDataFactory
11+
let summary =
12+
TestDataFactory::create_summary("BTCUSDT", Exchange::Binance, 50000.0, 50100.0, 1.0, 1.0);
13+
14+
assert_eq!(summary.symbol, "BTCUSDT");
15+
assert_eq!(summary.bids.len(), 1);
16+
assert_eq!(summary.asks.len(), 1);
17+
assert_eq!(summary.bids[0].price, 50000.0);
18+
assert_eq!(summary.asks[0].price, 50100.0);
19+
assert_eq!(summary.spread, 100.0);
20+
}
21+
22+
#[tokio::test]
23+
async fn test_arbitrage_scenario_creation() {
24+
let scenarios = TestDataFactory::create_arbitrage_scenario(
25+
"BTCUSDT",
26+
Exchange::Bybit, // Buy here (lower price)
27+
Exchange::Binance, // Sell here (higher price)
28+
49950.0, // Buy price
29+
50050.0, // Sell price
30+
1.0, // Volume
31+
);
32+
33+
assert_eq!(scenarios.len(), 1);
34+
let summaries = scenarios.values().next().unwrap();
35+
assert_eq!(summaries.len(), 2);
36+
}
37+
38+
#[tokio::test]
39+
async fn test_no_arbitrage_scenario() {
40+
let scenarios = TestDataFactory::create_no_arbitrage_scenario("BTCUSDT");
41+
42+
assert_eq!(scenarios.len(), 1);
43+
let summaries = scenarios.values().next().unwrap();
44+
assert_eq!(summaries.len(), 2);
45+
46+
// Verify no arbitrage exists (first exchange ask > second exchange bid)
47+
let summary1 = &summaries[0];
48+
let summary2 = &summaries[1];
49+
50+
let ask1 = summary1.asks.first().unwrap().price;
51+
let bid2 = summary2.bids.first().unwrap().price;
52+
53+
assert!(ask1 > bid2, "Should not have arbitrage opportunity");
54+
}
55+
56+
#[tokio::test]
57+
async fn test_assertion_helpers() {
58+
// Test empty opportunities assertion
59+
let empty_opportunities = vec![];
60+
assert_no_arbitrage_opportunities(&empty_opportunities);
61+
62+
// This test verifies our assertion helpers work without actually
63+
// creating arbitrage opportunities (which would require the full detector)
64+
}
65+
66+
#[tokio::test]
67+
async fn test_edge_case_scenarios() {
68+
// Test empty scenario
69+
let empty = TestDataFactory::create_empty_scenario();
70+
assert!(empty.is_empty());
71+
72+
// Test single exchange scenario
73+
let single = TestDataFactory::create_single_exchange_scenario("BTCUSDT");
74+
assert_eq!(single.len(), 1);
75+
let summaries = single.values().next().unwrap();
76+
assert_eq!(summaries.len(), 1);
77+
78+
// Test missing bid scenario
79+
let missing_bid = TestDataFactory::create_missing_bid_scenario("BTCUSDT");
80+
assert!(missing_bid.bids.is_empty());
81+
assert!(!missing_bid.asks.is_empty());
82+
83+
// Test missing ask scenario
84+
let missing_ask = TestDataFactory::create_missing_ask_scenario("BTCUSDT");
85+
assert!(!missing_ask.bids.is_empty());
86+
assert!(missing_ask.asks.is_empty());
87+
88+
// Test zero quantity scenario
89+
let zero_qty = TestDataFactory::create_zero_quantity_scenario("BTCUSDT");
90+
assert_eq!(zero_qty.bids[0].quantity, 0.0);
91+
assert_eq!(zero_qty.asks[0].quantity, 0.0);
92+
}
93+
94+
#[tokio::test]
95+
async fn test_realistic_market_scenario() {
96+
let market = TestDataFactory::create_realistic_market_scenario("BTCUSDT");
97+
98+
assert_eq!(market.len(), 1);
99+
let summaries = market.values().next().unwrap();
100+
assert_eq!(summaries.len(), 3); // Binance, Bybit, Coinbase
101+
102+
// Verify each summary has multiple price levels
103+
for summary in summaries {
104+
assert!(summary.bids.len() >= 3);
105+
assert!(summary.asks.len() >= 3);
106+
}
107+
}
108+
109+
#[tokio::test]
110+
async fn test_config_creation() {
111+
let default_config = TestDataFactory::create_test_config();
112+
assert_eq!(default_config.profit_threshold, 0.1);
113+
assert_eq!(default_config.volume_threshold, 0.01);
114+
115+
let custom_config = TestDataFactory::create_custom_test_config(0.5, 0.1, 0.001, 200);
116+
assert_eq!(custom_config.profit_threshold, 0.5);
117+
assert_eq!(custom_config.volume_threshold, 0.1);
118+
assert_eq!(custom_config.time_tolerance.as_millis(), 200);
119+
}

0 commit comments

Comments
 (0)