Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

External solver support in e2e tests #2515

Merged
87 changes: 48 additions & 39 deletions crates/e2e/src/setup/services.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use {
super::{colocation::start_legacy_solver, TestAccount},
super::TestAccount,
crate::setup::{
colocation::{self, SolverEngine},
wait_for_condition,
Expand All @@ -9,7 +9,7 @@ use {
app_data::{AppDataDocument, AppDataHash},
autopilot::infra::persistence::dto,
clap::Parser,
ethcontract::{H256, U256},
ethcontract::H256,
model::{
order::{Order, OrderCreation, OrderUid},
quote::{OrderQuoteRequest, OrderQuoteResponse},
Expand Down Expand Up @@ -209,52 +209,61 @@ impl<'a> Services<'a> {
.await;
}

/// Starts a basic version of the protocol with a single legacy solver and
/// quoter.
pub async fn start_protocol_legacy_solver(
/// Starts a basic version of the protocol with a single external solver.
/// Optionally starts a baseline solver and uses it for price estimation.
pub async fn start_protocol_external_solver(
&self,
solver: TestAccount,
solver_endpoint: Option<Url>,
quoter_endpoint: Option<Url>,
chain_id: Option<U256>,
run_baseline: bool,
) {
let external_solver_endpoint =
solver_endpoint.unwrap_or("http://localhost:8000/solve".parse().unwrap());
let colocated_solver_endpoint =
start_legacy_solver(external_solver_endpoint, chain_id).await;
solver_endpoint.unwrap_or("http://localhost:8000/".parse().unwrap());

let external_quoter_endpoint =
quoter_endpoint.unwrap_or("http://localhost:8000/quote".parse().unwrap());
let colocated_quoter_endpoint =
start_legacy_solver(external_quoter_endpoint, chain_id).await;
let mut solvers = vec![SolverEngine {
name: "test_solver".into(),
account: solver.clone(),
endpoint: external_solver_endpoint,
}];

colocation::start_driver(
self.contracts,
vec![
SolverEngine {
name: "test_solver".into(),
account: solver.clone(),
endpoint: colocated_solver_endpoint,
},
SolverEngine {
name: "test_quoter".into(),
account: solver,
endpoint: colocated_quoter_endpoint,
},
],
);
self.start_autopilot(
Some(Duration::from_secs(11)),
vec![
let (autopilot_args, api_args) = if run_baseline {
let baseline_solver_endpoint =
colocation::start_baseline_solver(self.contracts.weth.address()).await;

solvers.push(SolverEngine {
name: "baseline_solver".into(),
account: solver,
endpoint: baseline_solver_endpoint,
});

// Here we call the baseline_solver "test_quoter" to make the native price
// estimation use the baseline_solver instead of the test_quoter
let autopilot_args = vec![
"--drivers=test_solver|http://localhost:11088/test_solver".to_string(),
"--price-estimation-drivers=test_quoter|http://localhost:11088/baseline_solver,test_solver|http://localhost:11088/test_solver".to_string(),
];
let api_args = vec![
"--price-estimation-drivers=test_quoter|http://localhost:11088/baseline_solver,test_solver|http://localhost:11088/test_solver".to_string(),
];
(autopilot_args, api_args)
} else {
let autopilot_args = vec![
"--drivers=test_solver|http://localhost:11088/test_solver".to_string(),
"--price-estimation-drivers=test_quoter|http://localhost:11088/test_quoter"
"--price-estimation-drivers=test_quoter|http://localhost:11088/test_solver"
.to_string(),
],
);
self.start_api(vec![
"--price-estimation-drivers=test_quoter|http://localhost:11088/test_quoter".to_string(),
])
.await;
];

let api_args = vec![
"--price-estimation-drivers=test_quoter|http://localhost:11088/test_solver"
.to_string(),
];
(autopilot_args, api_args)
};

colocation::start_driver(self.contracts, solvers);

self.start_autopilot(Some(Duration::from_secs(11)), autopilot_args);
self.start_api(api_args).await;
}

async fn wait_for_api_to_come_up() {
Expand Down
Loading