use std::sync::Arc;
use ek_core::audit::shape_audit;
use ek_core::plugin::Plugin;
use ek_ctp::EVENT_CONTRACT_FINISH;
use ek_data::constant::{Asset, Exchange, InstrumentType};
use ek_data::contract::ContractData;
use ek_data::event::{EVENT_BAR, EVENT_CONTRACT, EVENT_LOG, EVENT_TICK};
use ek_data::log::LogData;
use ek_data::tick::TickData;
use ek_event::Event;
use ek_oms::wire::{EVENT_ORDER as W_ORDER, EVENT_POSITION as W_POSITION, EVENT_TRADE as W_TRADE};
use ek_ui::plugin::UiPlugin;
use ek_ui::state::UiShared;
fn ui() -> (Arc<UiShared>, UiPlugin) {
let shared = Arc::new(UiShared::new());
let plugin = UiPlugin::new(Arc::clone(&shared));
(shared, plugin)
}
#[test]
fn f9_shape_audit_is_ok_for_pure_subscriber() {
let (_, _) = ui();
let p = UiPlugin::new(Arc::new(UiShared::new()));
let rep = shape_audit(&p, env!("CARGO_PKG_VERSION"));
assert!(rep.is_ok(), "纯订阅件应零 finding: {:?}", rep.findings);
}
#[test]
fn subscription_matrix_every_route_lands_state() {
let (shared, plg) = ui();
let count_before = shared.logs_len();
let log = LogData::info("gateway_test", "链上一拍");
plg.on_mail(&Event::with_data(EVENT_LOG, Arc::new(log)));
assert!(shared.logs_len() > count_before, "eLog 必须进日志窗");
let mut tick = TickData {
gateway_name: "gateway_test".to_string(),
..TickData::default()
};
tick.symbol = "AG2601".to_string();
tick.last_price = 8000.0;
plg.on_mail(&Event::with_data(EVENT_TICK, Arc::new(tick)));
assert_eq!(shared.tick_count(), 1, "eTick 必须入行情快照");
let contract = ContractData {
gateway_name: "gateway_test".to_string(),
symbol: "AG2601".to_string(),
exchange: Exchange::SHFE,
name: "白银2601".to_string(),
asset: Asset::FUTURES,
instrument_type: Some(InstrumentType::FUTURES_CONTRACT),
size: 15.0,
price_tick: 1.0,
product_id: Some("AG".to_string()),
max_limit_order_volume: None,
min_limit_order_volume: None,
max_market_order_volume: None,
min_market_order_volume: None,
delivery_year: Some(2026),
delivery_month: Some(1),
open_date: None,
pre_close: None,
up_stop_price: None,
down_stop_price: None,
float_volume: None,
total_volume: None,
instrument_status: None,
is_trading: Some(true),
};
plg.on_mail(&Event::with_data(EVENT_CONTRACT, Arc::new(contract)));
assert!(shared.contract_count() >= 1, "eContract 必须入合约表");
let before = shared.logs_len();
plg.on_mail(&Event::with_data(
EVENT_CONTRACT_FINISH,
Arc::new("gateway_test".to_string()),
));
assert!(shared.logs_len() > before, "eContractFinish 必须显形日志");
let drop_before = shared.bad_payload_count(W_ORDER);
plg.on_mail(&Event::with_data(W_ORDER, Arc::new(String::from("bad"))));
assert_eq!(
shared.bad_payload_count(W_ORDER),
drop_before + 1,
"W_ORDER 坏载荷必须计数"
);
plg.on_mail(&Event::with_data(W_TRADE, Arc::new(String::from("bad"))));
plg.on_mail(&Event::with_data(W_POSITION, Arc::new(String::from("bad"))));
assert_eq!(shared.bad_payload_count(W_TRADE), 1);
assert_eq!(shared.bad_payload_count(W_POSITION), 1);
plg.on_mail(&Event::with_data(
EVENT_BAR,
Arc::new(String::from("nonsense")),
));
}
#[test]
fn cross_crate_addressing_is_constant_sourced() {
assert_eq!(ek_oms::NAME, "oms");
assert_eq!(ek_oms::SVC_PIPELINE_STATUS, "oms.pipeline_status");
assert_eq!(EVENT_CONTRACT_FINISH, "eContractFinish");
}