Skip to content

Commit

Permalink
Tests adjustement
Browse files Browse the repository at this point in the history
  • Loading branch information
squadgazzz committed Feb 8, 2024
1 parent a11312c commit afc761c
Showing 1 changed file with 57 additions and 8 deletions.
65 changes: 57 additions & 8 deletions crates/driver/src/domain/competition/solution/fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ mod tests {
fee: to_wei(1),
};

let (sell_amount, buy_amount) = adjusted_price_improvement_amounts(
let (sell_amount, _) = adjusted_price_improvement_amounts(
order_sell_amount,
order_buy_amount,
Side::Sell,
Expand All @@ -310,10 +310,6 @@ mod tests {
sell_amount, order_sell_amount,
"Sell amount should match order sell amount for sell orders."
);
assert_eq!(
buy_amount, order_buy_amount,
"Buy amount should match order buy amount for sell orders."
);
}

#[test]
Expand All @@ -326,21 +322,74 @@ mod tests {
fee: to_wei(1),
};

let (sell_amount, buy_amount) = adjusted_price_improvement_amounts(
let (_, buy_amount) = adjusted_price_improvement_amounts(
order_sell_amount,
order_buy_amount,
Side::Buy,
&quote,
)
.unwrap();

assert_eq!(
buy_amount, order_buy_amount,
"Buy amount should match order buy amount for buy orders."
);
}

#[test]
fn test_sell_order_with_quote_in_market_price() {
let order_sell_amount = to_wei(10);
let order_buy_amount = to_wei(20);
let quote = order::fees::Quote {
sell_amount: to_wei(9),
buy_amount: to_wei(25),
fee: to_wei(1),
};

let (sell_amount, buy_amount) = adjusted_price_improvement_amounts(
order_sell_amount,
order_buy_amount,
Side::Sell,
&quote,
)
.unwrap();

assert_eq!(
sell_amount, order_sell_amount,
"Sell amount should match order sell amount for buy orders."
"Sell amount should be taken from the quote for sell orders in market price."
);
assert_eq!(
buy_amount, quote.buy_amount,
"Buy amount should reflect the improved market condition from the quote."
);
}

#[test]
fn test_buy_order_with_quote_in_market_price() {
let order_sell_amount = to_wei(20);
let order_buy_amount = to_wei(10);
let quote = order::fees::Quote {
sell_amount: to_wei(17),
buy_amount: to_wei(10),
fee: to_wei(1),
};

let (sell_amount, buy_amount) = adjusted_price_improvement_amounts(
order_sell_amount,
order_buy_amount,
Side::Buy,
&quote,
)
.unwrap();

assert_eq!(
sell_amount, quote.sell_amount + quote.fee,
"Sell amount should reflect the improved market condition from the quote for buy \
orders."
);
assert_eq!(
buy_amount, order_buy_amount,
"Buy amount should match order buy amount for buy orders."
"Buy amount should be taken from the quote for buy orders in market price."
);
}

Expand Down

0 comments on commit afc761c

Please sign in to comment.