Skip to content

Commit

Permalink
more unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sunce86 committed Mar 28, 2024
1 parent 79617b9 commit b191ada
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion crates/shared/src/order_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2356,7 +2356,7 @@ mod tests {
}

#[test]
fn detects_market_orders() {
fn detects_market_orders_buy() {
let quote = Quote {
sell_amount: 90.into(),
buy_amount: 100.into(),
Expand Down Expand Up @@ -2407,4 +2407,58 @@ mod tests {
model::order::OrderKind::Buy,
));
}

#[test]
fn detects_market_orders_sell() {
// 1 to 1 conversion
let quote = Quote {
sell_amount: 100.into(),
buy_amount: 100.into(),
fee_amount: 10.into(),
..Default::default()
};

// at market price
assert!(!is_order_outside_market_price(
&Amounts {
sell: 100.into(),
buy: 90.into(),
fee: 0.into(),
},
&Amounts {
sell: quote.sell_amount,
buy: quote.buy_amount,
fee: quote.fee_amount,
},
model::order::OrderKind::Sell,
));
// willing to buy less than market price
assert!(!is_order_outside_market_price(
&Amounts {
sell: 100.into(),
buy: 80.into(),
fee: 0.into(),
},
&Amounts {
sell: quote.sell_amount,
buy: quote.buy_amount,
fee: quote.fee_amount,
},
model::order::OrderKind::Sell,
));
// wanting to buy more than market price
assert!(is_order_outside_market_price(
&Amounts {
sell: 100.into(),
buy: 1000.into(),
fee: 0.into(),
},
&Amounts {
sell: quote.sell_amount,
buy: quote.buy_amount,
fee: quote.fee_amount,
},
model::order::OrderKind::Sell,
));
}
}

0 comments on commit b191ada

Please sign in to comment.