Skip to content

Commit

Permalink
rework comments
Browse files Browse the repository at this point in the history
  • Loading branch information
m-lord-renkse committed Oct 15, 2024
1 parent 4fd630b commit 53f6487
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 40 deletions.
9 changes: 4 additions & 5 deletions crates/driver/src/tests/setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1237,18 +1237,17 @@ impl<'a> SolveOk<'a> {
// Since JIT orders don't have UID at creation time, we need to search for
// matching token pair
for expected in jit_orders.iter() {
let mut exist = false;
for trade in trades.values() {
exist |= self.exist_jit_order(trade, expected)
}
let exist = trades
.values()
.any(|trade| self.trade_matches(trade, expected));
assert!(exist, "JIT order {expected:?} not found");
}
self
}

/// Find for a JIT order, given specific token pair and buy/sell amount,
/// return true if the JIT order was found
fn exist_jit_order(&self, trade: &serde_json::Value, expected: &JitOrder) -> bool {
fn trade_matches(&self, trade: &serde_json::Value, expected: &JitOrder) -> bool {
let u256 =
|value: &serde_json::Value| eth::U256::from_dec_str(value.as_str().unwrap()).unwrap();
let sell_token = trade.get("sellToken").unwrap().to_string();
Expand Down
66 changes: 31 additions & 35 deletions crates/driver/src/tests/setup/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,24 +197,22 @@ impl Solver {
})
},
));
assert!(prices_json
.insert(
config
.blockchain
.get_token_wrapped(fulfillment.quoted_order.order.sell_token),
fulfillment.execution.buy.to_string(),
)
.is_none());
assert!(prices_json
.insert(
config
.blockchain
.get_token_wrapped(fulfillment.quoted_order.order.buy_token),
(fulfillment.execution.sell
- fulfillment.quoted_order.order.surplus_fee())
.to_string(),
)
.is_none());
let previous_value = prices_json.insert(
config
.blockchain
.get_token_wrapped(fulfillment.quoted_order.order.sell_token),
fulfillment.execution.buy.to_string(),
);
assert_eq!(previous_value, None, "existing price overwritten");
let previous_value = prices_json.insert(
config
.blockchain
.get_token_wrapped(fulfillment.quoted_order.order.buy_token),
(fulfillment.execution.sell
- fulfillment.quoted_order.order.surplus_fee())
.to_string(),
);
assert_eq!(previous_value, None, "existing price overwritten");
{
// trades have optional field `fee`
let order = if config.quote {
Expand Down Expand Up @@ -279,23 +277,21 @@ impl Solver {
.expected_surplus_capturing_jit_order_owners
.contains(&jit.quoted_order.order.owner)
{
assert!(prices_json
.insert(
config
.blockchain
.get_token_wrapped(jit.quoted_order.order.sell_token),
jit.execution.buy.to_string(),
)
.is_none());
assert!(prices_json
.insert(
config
.blockchain
.get_token_wrapped(jit.quoted_order.order.buy_token),
(jit.execution.sell - jit.quoted_order.order.surplus_fee())
.to_string(),
)
.is_none());
let previous_value = prices_json.insert(
config
.blockchain
.get_token_wrapped(jit.quoted_order.order.sell_token),
jit.execution.buy.to_string(),
);
assert_eq!(previous_value, None, "existing price overwritten");
let previous_value = prices_json.insert(
config
.blockchain
.get_token_wrapped(jit.quoted_order.order.buy_token),
(jit.execution.sell - jit.quoted_order.order.surplus_fee())
.to_string(),
);
assert_eq!(previous_value, None, "existing price overwritten");
}
{
let executed_amount = match jit.quoted_order.order.executed {
Expand Down

0 comments on commit 53f6487

Please sign in to comment.