Skip to content

Commit

Permalink
External solver support in e2e tests (#2515)
Browse files Browse the repository at this point in the history
# Description
A new function `start_protocol_external_solver` is created which allows
e2e tests to easily setup the protocol with an external solver that uses
the new solver API.

# Changes
- Add a `start_protocol_external_solver` function 
- Add a `run_baseline` flag to the `start_protocol` functions that use
external solvers, which if set to true will also run a baseline solver
alongside the external solver.

## How to test
- CI will run, but as I'm not a contributor, forked tests can't run
until merge. I've run them locally and they pass.
 - Enso CI tests run and pass against this commit hash.

---------

Co-authored-by: Haris Angelidakis <64154020+harisang@users.noreply.github.com>
Co-authored-by: Martin Beckmann <martin.beckmann@protonmail.com>
  • Loading branch information
3 people authored Mar 27, 2024
1 parent 9e1eb58 commit 36ceefc
Showing 1 changed file with 48 additions and 39 deletions.
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

0 comments on commit 36ceefc

Please sign in to comment.