diff --git a/src/analytics/enrich_account_funding.rs b/src/analytics/enrich_account_funding.rs index 07e70a5..f0d0882 100644 --- a/src/analytics/enrich_account_funding.rs +++ b/src/analytics/enrich_account_funding.rs @@ -61,9 +61,12 @@ impl BalanceTracker { pub fn process_transaction(&mut self, order: &ExchangeOrder) { let date = order.created_at; let (buyer_id, seller_id, amount) = match order.order_type.as_str() { - "BUY" => (order.user, order.accepter, order.amount * order.price), - "SELL" => (order.accepter, order.user, order.amount * order.price), - _ => return, + "Buy" => (order.user, order.accepter, order.amount * order.price), + "Sell" => (order.accepter, order.user, order.amount * order.price), + _ => { + println!("ERROR: not a valid Buy/Sell order, {:?}", &order); + return + }, }; self.update_balance_and_flows(seller_id, date, -amount, false); @@ -170,6 +173,7 @@ pub fn replay_transactions(orders: &mut [ExchangeOrder]) -> BalanceTracker { let mut tracker = BalanceTracker::new(); let sorted_orders = orders; sorted_orders.sort_by_key(|order| order.created_at); + dbg!(&sorted_orders.len()); for order in sorted_orders { tracker.process_transaction(order); } @@ -180,6 +184,7 @@ pub fn replay_transactions(orders: &mut [ExchangeOrder]) -> BalanceTracker { pub async fn submit_ledger(balances: &BalanceTracker, pool: &Graph) -> Result<()> { let query_literal = balances.generate_cypher_query(); println!("Cypher Query:\n{}", &query_literal); + dbg!(&balances.accounts.len()); for (id, acc) in balances.accounts.iter() { let data = acc.to_cypher_map(*id); diff --git a/tests/test_enrich_exchange.rs b/tests/test_enrich_exchange.rs index 5fffcf4..392fdb2 100644 --- a/tests/test_enrich_exchange.rs +++ b/tests/test_enrich_exchange.rs @@ -6,7 +6,7 @@ use std::path::PathBuf; use anyhow::Result; use libra_forensic_db::{ - analytics::enrich_rms, + analytics::{enrich_account_funding, enrich_rms}, extract_exchange_orders, load_exchange_orders, neo4j_init::{get_neo4j_localhost_pool, maybe_create_indexes}, schema_exchange_orders::ExchangeOrder, @@ -66,6 +66,17 @@ fn test_sell_order_shill() { assert!(orders.len() == 25450); } +#[test] +fn test_enrich_account_funding() { + let path = env!("CARGO_MANIFEST_DIR"); + let buf = PathBuf::from(path).join("tests/fixtures/savedOlOrders2.json"); + let mut orders = extract_exchange_orders::read_orders_from_file(buf).unwrap(); + + let balance = enrich_account_funding::replay_transactions(&mut orders); + + dbg!(balance.accounts.len()); +} + #[test] fn test_enrich_buy_shill() { let path = env!("CARGO_MANIFEST_DIR");