From 5b402c994d645052d93a47e275bc64c6937d56ac Mon Sep 17 00:00:00 2001 From: Itay Tsabary Date: Sun, 24 Nov 2024 21:03:31 +0200 Subject: [PATCH] wip commit-id:4d9607d8 --- Cargo.lock | 1 + crates/starknet_integration_tests/Cargo.toml | 1 + .../tests/end_to_end_integration_test.rs | 52 +++++++++++++++---- .../src/test_utils/compilation.rs | 13 +++-- 4 files changed, 51 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c312f12818..6e5f4bafbb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10307,6 +10307,7 @@ dependencies = [ "cairo-lang-starknet-classes", "futures", "indexmap 2.6.0", + "infra_utils", "mempool_test_utils", "papyrus_common", "papyrus_consensus", diff --git a/crates/starknet_integration_tests/Cargo.toml b/crates/starknet_integration_tests/Cargo.toml index 2a77b40534..8b3b43ef64 100644 --- a/crates/starknet_integration_tests/Cargo.toml +++ b/crates/starknet_integration_tests/Cargo.toml @@ -46,6 +46,7 @@ tracing.workspace = true [dev-dependencies] futures.workspace = true +infra_utils.workspace = true pretty_assertions.workspace = true rstest.workspace = true starknet_sequencer_infra.workspace = true diff --git a/crates/starknet_integration_tests/tests/end_to_end_integration_test.rs b/crates/starknet_integration_tests/tests/end_to_end_integration_test.rs index 1602e1f87c..e3f3abfb84 100644 --- a/crates/starknet_integration_tests/tests/end_to_end_integration_test.rs +++ b/crates/starknet_integration_tests/tests/end_to_end_integration_test.rs @@ -3,6 +3,7 @@ use std::path::PathBuf; use std::process::Stdio; use std::time::Duration; +use infra_utils::path::resolve_project_relative_path; use mempool_test_utils::starknet_api_test_utils::{AccountId, MultiAccountTransactionGenerator}; use papyrus_execution::execution_utils::get_nonce_at; use papyrus_storage::state::StateStorageReader; @@ -14,6 +15,7 @@ use starknet_api::state::StateNumber; use starknet_integration_tests::integration_test_setup::IntegrationTestSetup; use starknet_integration_tests::utils::{create_integration_test_tx_generator, send_account_txs}; use starknet_sequencer_infra::trace_util::configure_tracing; +use starknet_sequencer_node::test_utils::compilation::compile_node_result; use starknet_types_core::felt::Felt; use tokio::process::{Child, Command}; use tokio::task::{self, JoinHandle}; @@ -28,18 +30,28 @@ fn tx_generator() -> MultiAccountTransactionGenerator { // TODO(Tsabary): Move to a suitable util location. async fn spawn_node_child_task(node_config_path: PathBuf) -> Child { // Get the current working directory for the project - let project_path = env::current_dir().expect("Failed to get current directory").join("../.."); - - // TODO(Tsabary): Capture output to a log file, and present it in case of a failure. - // TODO(Tsabary): Change invocation from "cargo run" to separate compilation and invocation - // (build, and then invoke the binary). - Command::new("cargo") - .arg("run") - .arg("--bin") - .arg("starknet_sequencer_node") - .arg("--quiet") + // let project_path = env::current_dir().expect("Failed to get current + // directory").join("../.."); + + let compile_result = compile_node_result(); + info!("Compilation result {:?}.", compile_result); + + assert!(compile_result.is_ok(), "Compilation failed."); + // let compilation_result = Command::new("cargo") + // .arg("build") + // .arg("--bin") + // .arg("starknet_sequencer_node") + // .arg("--quiet") + // .current_dir(&project_path) + // .status().await; + + info!("Compiling the starknet_sequencer_node binary"); + let project_path = resolve_project_relative_path(".").expect("Failed to resolve project path"); + info!("project_path {:?}", project_path); + + // Run `cargo build` to compile the project + Command::new("target/debug/starknet_sequencer_node") .current_dir(&project_path) - .arg("--") .arg("--config_file") .arg(node_config_path.to_str().unwrap()) .stderr(Stdio::inherit()) @@ -47,6 +59,24 @@ async fn spawn_node_child_task(node_config_path: PathBuf) -> Child { .kill_on_drop(true) // Required for stopping the node when the handle is dropped. .spawn() .expect("Failed to spawn the sequencer node.") + + // // TODO(Tsabary): Capture output to a log file, and present it in case of a failure. + // // TODO(Tsabary): Change invocation from "cargo run" to separate compilation and invocation + // // (build, and then invoke the binary). + // Command::new("cargo") + // .arg("run") + // .arg("--bin") + // .arg("starknet_sequencer_node") + // .arg("--quiet") + // .current_dir(&project_path) + // .arg("--") + // .arg("--config_file") + // .arg(node_config_path.to_str().unwrap()) + // .stderr(Stdio::inherit()) + // .stdout(Stdio::null()) + // .kill_on_drop(true) // Required for stopping the node when the handle is dropped. + // .spawn() + // .expect("Failed to spawn the sequencer node.") } async fn spawn_run_node(node_config_path: PathBuf) -> JoinHandle<()> { diff --git a/crates/starknet_sequencer_node/src/test_utils/compilation.rs b/crates/starknet_sequencer_node/src/test_utils/compilation.rs index 645fe536ae..8fc3e8ff70 100644 --- a/crates/starknet_sequencer_node/src/test_utils/compilation.rs +++ b/crates/starknet_sequencer_node/src/test_utils/compilation.rs @@ -1,6 +1,7 @@ +use std::io; use std::process::{Command, ExitStatus, Stdio}; -use std::{env, io}; +use infra_utils::path::resolve_project_relative_path; use tracing::info; #[cfg(test)] @@ -17,15 +18,17 @@ pub enum NodeCompilationError { /// Compiles the node using `cargo build` for testing purposes. fn compile_node() -> io::Result { - info!("Compiling the project"); - // Get the current working directory for the project - let project_path = env::current_dir().expect("Failed to get current directory"); + info!("Compiling the starknet_sequencer_node binary"); + let project_path = resolve_project_relative_path(".").expect("Failed to resolve project path"); + info!("project_path {:?}", project_path); // Run `cargo build` to compile the project let compilation_result = Command::new("cargo") .arg("build") + .arg("--bin") + .arg("starknet_sequencer_node") .current_dir(&project_path) - .arg("--quiet") + // .arg("--quiet") .stderr(Stdio::inherit()) .stdout(Stdio::inherit()) .status();