Skip to content

Commit

Permalink
Fix driver tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sunce86 committed Mar 29, 2024
1 parent 80ea4ca commit c77fdd7
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 83 deletions.
6 changes: 0 additions & 6 deletions crates/driver/src/tests/cases/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pub mod negative_scores;
pub mod order_prioritization;
pub mod protocol_fees;
pub mod quote;
pub mod score_competition;
pub mod settle;
pub mod solver_balance;

Expand All @@ -44,11 +43,6 @@ pub const CD_ORDER_AMOUNT: u64 = 40;

pub const ETH_ORDER_AMOUNT: u64 = 40;

/// With the default amounts defined above, this is the expected score range for
/// both buy and sell orders.
pub const DEFAULT_SCORE_MIN: u64 = 2;
pub const DEFAULT_SCORE_MAX: u64 = 500000000000;

/// The default solver fee for limit orders.
pub const DEFAULT_SOLVER_FEE: &str = "1e-16";

Expand Down
4 changes: 2 additions & 2 deletions crates/driver/src/tests/cases/multiple_solutions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async fn valid() {
.done()
.await;

test.solve().await.ok().default_score().orders(&[order]);
test.solve().await.ok().orders(&[order]);
test.reveal().await.ok().calldata();
}

Expand All @@ -35,6 +35,6 @@ async fn invalid() {
.done()
.await;

test.solve().await.ok().default_score().orders(&[order]);
test.solve().await.ok().orders(&[order]);
test.reveal().await.ok().calldata();
}
2 changes: 1 addition & 1 deletion crates/driver/src/tests/cases/negative_scores.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ async fn one_valid_solution() {
})
.done()
.await;
test.solve().await.ok().default_score().orders(&[order]);
test.solve().await.ok().orders(&[order]);
test.reveal().await.ok().calldata();
}
46 changes: 0 additions & 46 deletions crates/driver/src/tests/cases/score_competition.rs

This file was deleted.

4 changes: 2 additions & 2 deletions crates/driver/src/tests/cases/settle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async fn matrix() {
.done()
.await;

test.solve().await.ok().default_score();
test.solve().await.ok();
test.settle().await.ok().await.ab_order_executed().await;
}
}
Expand Down Expand Up @@ -70,7 +70,7 @@ async fn private_rpc_with_high_risk_solution() {
.done()
.await;

test.solve().await.ok().default_score();
test.solve().await.ok();
// Public cannot be used and private RPC is not available
let err = test.settle().await.err();
err.kind("FailedToSubmit");
Expand Down
27 changes: 1 addition & 26 deletions crates/driver/src/tests/setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ use {
DEFAULT_POOL_AMOUNT_B,
DEFAULT_POOL_AMOUNT_C,
DEFAULT_POOL_AMOUNT_D,
DEFAULT_SCORE_MAX,
DEFAULT_SCORE_MIN,
DEFAULT_SURPLUS_FACTOR,
ETH_ORDER_AMOUNT,
},
Expand Down Expand Up @@ -69,6 +67,7 @@ pub enum Partial {
#[derive(Debug, Clone, serde::Serialize)]
#[serde(rename_all = "camelCase", tag = "kind")]
pub enum Score {
#[allow(dead_code)]
Solver {
#[serde_as(as = "serialize::U256")]
score: eth::U256,
Expand Down Expand Up @@ -561,11 +560,6 @@ impl Solution {
..self
}
}

/// Set the solution score to the specified value.
pub fn score(self, score: Score) -> Self {
Self { score, ..self }
}
}

impl Default for Solution {
Expand Down Expand Up @@ -1084,25 +1078,6 @@ impl<'a> SolveOk<'a> {
eth::U256::from_dec_str(score).unwrap()
}

/// Ensure that the score in the response is within a certain range. The
/// reason why this is a range is because small timing differences in
/// the test can lead to the settlement using slightly different amounts
/// of gas, which in turn leads to different scores.
pub fn score_in_range(self, min: eth::U256, max: eth::U256) -> Self {
let score = self.score();
assert!(score >= min, "score less than min {score} < {min}");
assert!(score <= max, "score more than max {score} > {max}");
self
}

/// Ensure that the score is within the default expected range.
pub fn default_score(self) -> Self {
self.score_in_range(
DEFAULT_SCORE_MIN.ether().into_wei(),
DEFAULT_SCORE_MAX.ether().into_wei(),
)
}

/// Ensures that `/solve` returns no solutions.
pub fn empty(self) {
assert!(self.solutions().is_empty());
Expand Down

0 comments on commit c77fdd7

Please sign in to comment.