2023-12-22 21:09:18 -05:00
|
|
|
use std::time::Duration;
|
2023-08-27 18:37:12 -04:00
|
|
|
|
2023-12-22 21:09:18 -05:00
|
|
|
use serai_client::Serai;
|
2023-08-27 18:37:12 -04:00
|
|
|
|
2023-12-22 21:09:18 -05:00
|
|
|
use dockertest::DockerOperations;
|
|
|
|
|
|
|
|
|
|
use serai_processor_tests::{RPC_USER, RPC_PASS};
|
2023-08-27 18:37:12 -04:00
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests;
|
|
|
|
|
|
|
|
|
|
#[allow(unused)]
|
2023-08-28 16:18:11 -04:00
|
|
|
#[derive(Clone, Debug)]
|
2023-08-27 18:37:12 -04:00
|
|
|
pub struct Handles {
|
|
|
|
|
bitcoin: (String, u32),
|
|
|
|
|
bitcoin_processor: String,
|
|
|
|
|
monero: (String, u32),
|
|
|
|
|
monero_processor: String,
|
|
|
|
|
message_queue: String,
|
|
|
|
|
serai: String,
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-28 16:18:11 -04:00
|
|
|
impl Handles {
|
|
|
|
|
pub async fn serai(&self, ops: &DockerOperations) -> Serai {
|
|
|
|
|
let serai_rpc = ops.handle(&self.serai).host_port(9944).unwrap();
|
2023-11-28 02:29:50 -05:00
|
|
|
let serai_rpc = format!("http://{}:{}", serai_rpc.0, serai_rpc.1);
|
2023-08-28 16:18:11 -04:00
|
|
|
|
|
|
|
|
// If the RPC server has yet to start, sleep for up to 60s until it does
|
|
|
|
|
for _ in 0 .. 60 {
|
|
|
|
|
tokio::time::sleep(Duration::from_secs(1)).await;
|
2023-11-28 02:29:50 -05:00
|
|
|
let Ok(client) = Serai::new(serai_rpc.clone()).await else { continue };
|
|
|
|
|
if client.latest_finalized_block_hash().await.is_err() {
|
2023-08-28 16:18:11 -04:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
return client;
|
|
|
|
|
}
|
|
|
|
|
panic!("serai RPC server wasn't available after 60s");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub async fn bitcoin(&self, ops: &DockerOperations) -> bitcoin_serai::rpc::Rpc {
|
|
|
|
|
let rpc = ops.handle(&self.bitcoin.0).host_port(self.bitcoin.1).unwrap();
|
|
|
|
|
let rpc = format!("http://{RPC_USER}:{RPC_PASS}@{}:{}", rpc.0, rpc.1);
|
|
|
|
|
|
|
|
|
|
// If the RPC server has yet to start, sleep for up to 60s until it does
|
|
|
|
|
for _ in 0 .. 60 {
|
|
|
|
|
tokio::time::sleep(Duration::from_secs(1)).await;
|
|
|
|
|
let Ok(client) = bitcoin_serai::rpc::Rpc::new(rpc.clone()).await else { continue };
|
|
|
|
|
return client;
|
|
|
|
|
}
|
|
|
|
|
panic!("bitcoin RPC server wasn't available after 60s");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub async fn monero(
|
|
|
|
|
&self,
|
|
|
|
|
ops: &DockerOperations,
|
|
|
|
|
) -> monero_serai::rpc::Rpc<monero_serai::rpc::HttpRpc> {
|
|
|
|
|
use monero_serai::rpc::HttpRpc;
|
|
|
|
|
|
|
|
|
|
let rpc = ops.handle(&self.monero.0).host_port(self.monero.1).unwrap();
|
|
|
|
|
let rpc = format!("http://{RPC_USER}:{RPC_PASS}@{}:{}", rpc.0, rpc.1);
|
|
|
|
|
|
|
|
|
|
// If the RPC server has yet to start, sleep for up to 60s until it does
|
|
|
|
|
for _ in 0 .. 60 {
|
|
|
|
|
tokio::time::sleep(Duration::from_secs(1)).await;
|
2023-11-06 23:45:39 -05:00
|
|
|
let Ok(client) = HttpRpc::new(rpc.clone()).await else { continue };
|
2023-08-28 16:18:11 -04:00
|
|
|
if client.get_height().await.is_err() {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
return client;
|
|
|
|
|
}
|
|
|
|
|
panic!("monero RPC server wasn't available after 60s");
|
|
|
|
|
}
|
|
|
|
|
}
|