fix: logs handling
This commit is contained in:
@@ -24,7 +24,7 @@ services:
|
||||
db:
|
||||
condition: service_healthy
|
||||
environment:
|
||||
RUST_LOG: "protocol_testing=info"
|
||||
RUST_LOG: "${RUST_LOG:-protocol_testing=info}"
|
||||
DATABASE_URL: postgres://postgres:mypassword@db:5432/tycho_indexer_0
|
||||
RPC_URL: "${RPC_URL}"
|
||||
SUBSTREAMS_API_TOKEN: "${SUBSTREAMS_API_TOKEN}"
|
||||
|
||||
@@ -32,10 +32,6 @@ struct Args {
|
||||
#[arg(long)]
|
||||
match_test: Option<String>,
|
||||
|
||||
/// Enable tycho logs
|
||||
#[arg(long, default_value_t = false)]
|
||||
tycho_logs: bool,
|
||||
|
||||
/// Postgres database URL for the Tycho indexer
|
||||
#[arg(long, default_value = "postgres://postgres:mypassword@localhost:5431/tycho_indexer_0")]
|
||||
db_url: String,
|
||||
@@ -94,7 +90,6 @@ fn main() -> miette::Result<()> {
|
||||
args.root_path()?,
|
||||
args.package,
|
||||
args.match_test,
|
||||
args.tycho_logs,
|
||||
args.db_url,
|
||||
args.vm_traces,
|
||||
);
|
||||
|
||||
@@ -42,7 +42,6 @@ use crate::{
|
||||
};
|
||||
|
||||
pub struct TestRunner {
|
||||
tycho_logs: bool,
|
||||
db_url: String,
|
||||
vm_traces: bool,
|
||||
substreams_path: PathBuf,
|
||||
@@ -55,7 +54,6 @@ impl TestRunner {
|
||||
root_path: PathBuf,
|
||||
protocol: String,
|
||||
match_test: Option<String>,
|
||||
tycho_logs: bool,
|
||||
db_url: String,
|
||||
vm_traces: bool,
|
||||
) -> Self {
|
||||
@@ -65,14 +63,7 @@ impl TestRunner {
|
||||
let evm_path = root_path.join("evm");
|
||||
let adapter_contract_builder =
|
||||
AdapterContractBuilder::new(evm_path.to_string_lossy().to_string());
|
||||
Self {
|
||||
tycho_logs,
|
||||
db_url,
|
||||
vm_traces,
|
||||
substreams_path,
|
||||
adapter_contract_builder,
|
||||
match_test,
|
||||
}
|
||||
Self { db_url, vm_traces, substreams_path, adapter_contract_builder, match_test }
|
||||
}
|
||||
|
||||
pub fn run_tests(&self) -> miette::Result<()> {
|
||||
@@ -191,8 +182,7 @@ impl TestRunner {
|
||||
let spkg_path =
|
||||
build_spkg(&substreams_yaml_path, test.start_block).wrap_err("Failed to build spkg")?;
|
||||
|
||||
let tycho_runner =
|
||||
TychoRunner::new(self.db_url.clone(), initialized_accounts, self.tycho_logs);
|
||||
let tycho_runner = TychoRunner::new(self.db_url.clone(), initialized_accounts);
|
||||
|
||||
tycho_runner
|
||||
.run_tycho(
|
||||
|
||||
@@ -6,23 +6,21 @@ use std::{
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use dotenv::dotenv;
|
||||
use miette::{IntoDiagnostic, WrapErr};
|
||||
use tracing::debug;
|
||||
use tracing::{debug, info};
|
||||
|
||||
use crate::config::ProtocolComponentWithTestConfig;
|
||||
|
||||
pub struct TychoRunner {
|
||||
db_url: String,
|
||||
initialized_accounts: Vec<String>,
|
||||
with_binary_logs: bool,
|
||||
}
|
||||
|
||||
// TODO: Currently Tycho-Indexer cannot be run as a lib. We need to expose the entrypoints to allow
|
||||
// running it as a lib
|
||||
impl TychoRunner {
|
||||
pub fn new(db_url: String, initialized_accounts: Vec<String>, with_binary_logs: bool) -> Self {
|
||||
Self { db_url, initialized_accounts, with_binary_logs }
|
||||
pub fn new(db_url: String, initialized_accounts: Vec<String>) -> Self {
|
||||
Self { db_url, initialized_accounts }
|
||||
}
|
||||
|
||||
pub fn run_tycho(
|
||||
@@ -33,8 +31,7 @@ impl TychoRunner {
|
||||
protocol_type_names: &[String],
|
||||
protocol_system: &str,
|
||||
) -> miette::Result<()> {
|
||||
// Expects a .env present in the same folder as package root (where Cargo.toml is)
|
||||
dotenv().ok();
|
||||
info!("Running Tycho indexer from block {start_block} to {end_block}...");
|
||||
|
||||
let mut cmd = Command::new("tycho-indexer");
|
||||
cmd.env("RUST_LOG", std::env::var("RUST_LOG").unwrap_or("tycho_indexer=info".to_string()))
|
||||
@@ -79,9 +76,7 @@ impl TychoRunner {
|
||||
.into_diagnostic()
|
||||
.wrap_err("Error running Tycho indexer")?;
|
||||
|
||||
if self.with_binary_logs {
|
||||
Self::handle_process_output(&mut process);
|
||||
}
|
||||
Self::handle_process_output(&mut process);
|
||||
|
||||
let status = process
|
||||
.wait()
|
||||
@@ -110,7 +105,6 @@ impl TychoRunner {
|
||||
{
|
||||
let (tx, rx): (Sender<bool>, Receiver<bool>) = mpsc::channel();
|
||||
let db_url = self.db_url.clone();
|
||||
let with_binary_logs = self.with_binary_logs;
|
||||
|
||||
// Start the RPC server in a separate thread
|
||||
let rpc_thread = thread::spawn(move || {
|
||||
@@ -126,9 +120,7 @@ impl TychoRunner {
|
||||
.spawn()
|
||||
.expect("Failed to start RPC server");
|
||||
|
||||
if with_binary_logs {
|
||||
Self::handle_process_output(&mut cmd);
|
||||
}
|
||||
Self::handle_process_output(&mut cmd);
|
||||
|
||||
match rx.recv() {
|
||||
Ok(_) => {
|
||||
|
||||
@@ -86,6 +86,7 @@ pub fn build_spkg(yaml_file_path: &PathBuf, initial_block: u64) -> miette::Resul
|
||||
// Restore the original YAML from backup
|
||||
fs::copy(&backup_file_path, yaml_file_path).into_diagnostic()?;
|
||||
fs::remove_file(&backup_file_path).into_diagnostic()?;
|
||||
info!("Spkg built successfully: {}", spkg_name);
|
||||
|
||||
Ok(spkg_name)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user