From 9194a42813db48ade12e864f78dfb940d5fa1742 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Wed, 7 Aug 2024 13:59:00 +0300 Subject: [PATCH 01/13] Add command test boilerplate --- .../crates/zk_inception/src/commands/mod.rs | 1 + .../crates/zk_inception/src/commands/test/mod.rs | 16 ++++++++++++++++ .../zk_inception/src/commands/test/rust.rs | 6 ++++++ zk_toolbox/crates/zk_inception/src/main.rs | 5 +++++ 4 files changed, 28 insertions(+) create mode 100644 zk_toolbox/crates/zk_inception/src/commands/test/mod.rs create mode 100644 zk_toolbox/crates/zk_inception/src/commands/test/rust.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/mod.rs b/zk_toolbox/crates/zk_inception/src/commands/mod.rs index 5eea6e8a5a1a..e85143382332 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/mod.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/mod.rs @@ -6,4 +6,5 @@ pub mod ecosystem; pub mod external_node; pub mod prover; pub mod server; +pub mod test; pub mod update; diff --git a/zk_toolbox/crates/zk_inception/src/commands/test/mod.rs b/zk_toolbox/crates/zk_inception/src/commands/test/mod.rs new file mode 100644 index 000000000000..532c41d8d3fc --- /dev/null +++ b/zk_toolbox/crates/zk_inception/src/commands/test/mod.rs @@ -0,0 +1,16 @@ +use clap::Subcommand; +use xshell::Shell; + +mod rust; + +#[derive(Subcommand, Debug)] +pub enum TestCommands { + /// Run unit-tests. Runs all tests in all rust bins and libs by default. Accepts optional arbitrary cargo test flags. + Rust, +} + +pub fn run(shell: &Shell, args: TestCommands) -> anyhow::Result<()> { + match args { + TestCommands::Rust => rust::run(shell), + } +} diff --git a/zk_toolbox/crates/zk_inception/src/commands/test/rust.rs b/zk_toolbox/crates/zk_inception/src/commands/test/rust.rs new file mode 100644 index 000000000000..6eeb1b5eb72f --- /dev/null +++ b/zk_toolbox/crates/zk_inception/src/commands/test/rust.rs @@ -0,0 +1,6 @@ +use xshell::Shell; + +pub fn run(shell: &Shell) -> anyhow::Result<()> { + println!("Running test rust command"); + Ok(()) +} diff --git a/zk_toolbox/crates/zk_inception/src/main.rs b/zk_toolbox/crates/zk_inception/src/main.rs index 2b5bdeb9c1a5..623a77c21653 100644 --- a/zk_toolbox/crates/zk_inception/src/main.rs +++ b/zk_toolbox/crates/zk_inception/src/main.rs @@ -2,6 +2,7 @@ use clap::{command, Parser, Subcommand}; use commands::{ args::{ContainersArgs, UpdateArgs}, contract_verifier::ContractVerifierCommands, + test::TestCommands, }; use common::{ check_general_prerequisites, @@ -59,6 +60,9 @@ pub enum InceptionSubcommands { /// Update zkSync #[command(alias = "u")] Update(UpdateArgs), + /// Run tests + #[command(subcommand, alias = "t")] + Test(TestCommands), #[command(hide = true)] Markdown, } @@ -119,6 +123,7 @@ async fn run_subcommand(inception_args: Inception, shell: &Shell) -> anyhow::Res commands::contract_verifier::run(shell, args).await? } InceptionSubcommands::Update(args) => commands::update::run(shell, args)?, + InceptionSubcommands::Test(args) => commands::test::run(shell, args)?, InceptionSubcommands::Markdown => { clap_markdown::print_help_markdown::(); } From eccf003b76f7844c16521c951a32a66b5434b9d2 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Wed, 7 Aug 2024 14:18:58 +0300 Subject: [PATCH 02/13] Most test command to supervisor --- .../crates/zk_inception/src/commands/mod.rs | 1 - .../crates/zk_inception/src/commands/test/mod.rs | 16 ---------------- zk_toolbox/crates/zk_inception/src/main.rs | 5 ----- .../zk_supervisor/src/commands/test/mod.rs | 6 +++++- .../src/commands/test/rust.rs | 1 - zk_toolbox/crates/zk_supervisor/src/messages.rs | 2 ++ 6 files changed, 7 insertions(+), 24 deletions(-) delete mode 100644 zk_toolbox/crates/zk_inception/src/commands/test/mod.rs rename zk_toolbox/crates/{zk_inception => zk_supervisor}/src/commands/test/rust.rs (65%) diff --git a/zk_toolbox/crates/zk_inception/src/commands/mod.rs b/zk_toolbox/crates/zk_inception/src/commands/mod.rs index e85143382332..5eea6e8a5a1a 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/mod.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/mod.rs @@ -6,5 +6,4 @@ pub mod ecosystem; pub mod external_node; pub mod prover; pub mod server; -pub mod test; pub mod update; diff --git a/zk_toolbox/crates/zk_inception/src/commands/test/mod.rs b/zk_toolbox/crates/zk_inception/src/commands/test/mod.rs deleted file mode 100644 index 532c41d8d3fc..000000000000 --- a/zk_toolbox/crates/zk_inception/src/commands/test/mod.rs +++ /dev/null @@ -1,16 +0,0 @@ -use clap::Subcommand; -use xshell::Shell; - -mod rust; - -#[derive(Subcommand, Debug)] -pub enum TestCommands { - /// Run unit-tests. Runs all tests in all rust bins and libs by default. Accepts optional arbitrary cargo test flags. - Rust, -} - -pub fn run(shell: &Shell, args: TestCommands) -> anyhow::Result<()> { - match args { - TestCommands::Rust => rust::run(shell), - } -} diff --git a/zk_toolbox/crates/zk_inception/src/main.rs b/zk_toolbox/crates/zk_inception/src/main.rs index 623a77c21653..2b5bdeb9c1a5 100644 --- a/zk_toolbox/crates/zk_inception/src/main.rs +++ b/zk_toolbox/crates/zk_inception/src/main.rs @@ -2,7 +2,6 @@ use clap::{command, Parser, Subcommand}; use commands::{ args::{ContainersArgs, UpdateArgs}, contract_verifier::ContractVerifierCommands, - test::TestCommands, }; use common::{ check_general_prerequisites, @@ -60,9 +59,6 @@ pub enum InceptionSubcommands { /// Update zkSync #[command(alias = "u")] Update(UpdateArgs), - /// Run tests - #[command(subcommand, alias = "t")] - Test(TestCommands), #[command(hide = true)] Markdown, } @@ -123,7 +119,6 @@ async fn run_subcommand(inception_args: Inception, shell: &Shell) -> anyhow::Res commands::contract_verifier::run(shell, args).await? } InceptionSubcommands::Update(args) => commands::update::run(shell, args)?, - InceptionSubcommands::Test(args) => commands::test::run(shell, args)?, InceptionSubcommands::Markdown => { clap_markdown::print_help_markdown::(); } diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/mod.rs b/zk_toolbox/crates/zk_supervisor/src/commands/test/mod.rs index b66a7eaefc4c..91ef25317971 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/mod.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/test/mod.rs @@ -4,13 +4,14 @@ use xshell::Shell; use crate::messages::{ MSG_INTEGRATION_TESTS_ABOUT, MSG_RECOVERY_TEST_ABOUT, MSG_REVERT_TEST_ABOUT, - MSG_UPGRADE_TEST_ABOUT, + MSG_RUST_TEST_ABOUT, MSG_UPGRADE_TEST_ABOUT, }; mod args; mod integration; mod recovery; mod revert; +mod rust; mod upgrade; #[derive(Subcommand, Debug)] @@ -23,6 +24,8 @@ pub enum TestCommands { Recovery(RecoveryArgs), #[clap(about = MSG_UPGRADE_TEST_ABOUT, alias = "u")] Upgrade, + #[clap(about = MSG_RUST_TEST_ABOUT, alias = "unit")] + Rust, } pub fn run(shell: &Shell, args: TestCommands) -> anyhow::Result<()> { @@ -31,5 +34,6 @@ pub fn run(shell: &Shell, args: TestCommands) -> anyhow::Result<()> { TestCommands::Revert(args) => revert::run(shell, args), TestCommands::Recovery(args) => recovery::run(shell, args), TestCommands::Upgrade => upgrade::run(shell), + TestCommands::Rust => rust::run(shell), } } diff --git a/zk_toolbox/crates/zk_inception/src/commands/test/rust.rs b/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs similarity index 65% rename from zk_toolbox/crates/zk_inception/src/commands/test/rust.rs rename to zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs index 6eeb1b5eb72f..d3573725be22 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/test/rust.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs @@ -1,6 +1,5 @@ use xshell::Shell; pub fn run(shell: &Shell) -> anyhow::Result<()> { - println!("Running test rust command"); Ok(()) } diff --git a/zk_toolbox/crates/zk_supervisor/src/messages.rs b/zk_toolbox/crates/zk_supervisor/src/messages.rs index 116775072594..e751fff45e46 100644 --- a/zk_toolbox/crates/zk_supervisor/src/messages.rs +++ b/zk_toolbox/crates/zk_supervisor/src/messages.rs @@ -74,6 +74,8 @@ pub(super) const MSG_INTEGRATION_TESTS_ABOUT: &str = "Run integration tests"; pub(super) const MSG_REVERT_TEST_ABOUT: &str = "Run revert tests"; pub(super) const MSG_RECOVERY_TEST_ABOUT: &str = "Run recovery tests"; pub(super) const MSG_UPGRADE_TEST_ABOUT: &str = "Run upgrade tests"; +pub(super) const MSG_RUST_TEST_ABOUT: &str = + "Run unit-tests, accepts optional arbitrary cargo test flags"; pub(super) const MSG_TESTS_EXTERNAL_NODE_HELP: &str = "Run tests for external node"; pub(super) const MSG_TESTS_RECOVERY_SNAPSHOT_HELP: &str = "Run recovery from a snapshot instead of genesis"; From 961e8921b9e2f1d901c0a15adeb21f35e79efe30 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Wed, 7 Aug 2024 14:59:05 +0300 Subject: [PATCH 03/13] Implement run unit test --- .../zk_supervisor/src/commands/test/rust.rs | 36 ++++++++++++++++++- .../crates/zk_supervisor/src/messages.rs | 4 +++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs b/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs index d3573725be22..ee6b3a768ea2 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs @@ -1,5 +1,39 @@ -use xshell::Shell; +use common::{cmd::Cmd, logger, spinner::Spinner}; +use config::EcosystemConfig; +use xshell::{cmd, Shell}; + +use crate::messages::{ + MSG_CARGO_NEXTEST_MISSING_ERR, MSG_RUNNING_UNIT_TESTS_SPINNER, MSG_UNIT_TESTS_RUN_SUCCESS, + MSG_USING_CARGO_NEXTEST, +}; pub fn run(shell: &Shell) -> anyhow::Result<()> { + let ecosystem = EcosystemConfig::from_file(shell)?; + let _dir_guard = shell.push_dir(&ecosystem.link_to_code); + let spinner; + if nextest_is_installed(shell)? { + logger::info(MSG_USING_CARGO_NEXTEST); + spinner = Spinner::new(MSG_RUNNING_UNIT_TESTS_SPINNER); + Cmd::new(cmd!(shell, "cargo nextest run --release")) + .with_force_run() + .run()?; + } else { + logger::error(MSG_CARGO_NEXTEST_MISSING_ERR); + spinner = Spinner::new(MSG_RUNNING_UNIT_TESTS_SPINNER); + Cmd::new(cmd!(shell, "cargo test --release")) + .with_force_run() + .run()?; + } + spinner.finish(); + logger::outro(MSG_UNIT_TESTS_RUN_SUCCESS); Ok(()) } + +fn nextest_is_installed(shell: &Shell) -> anyhow::Result { + let out = String::from_utf8( + Cmd::new(cmd!(shell, "cargo install --list")) + .run_with_output()? + .stdout, + )?; + Ok(out.contains("cargo-nextest")) +} diff --git a/zk_toolbox/crates/zk_supervisor/src/messages.rs b/zk_toolbox/crates/zk_supervisor/src/messages.rs index e751fff45e46..db835a26dec1 100644 --- a/zk_toolbox/crates/zk_supervisor/src/messages.rs +++ b/zk_toolbox/crates/zk_supervisor/src/messages.rs @@ -79,6 +79,10 @@ pub(super) const MSG_RUST_TEST_ABOUT: &str = pub(super) const MSG_TESTS_EXTERNAL_NODE_HELP: &str = "Run tests for external node"; pub(super) const MSG_TESTS_RECOVERY_SNAPSHOT_HELP: &str = "Run recovery from a snapshot instead of genesis"; +pub(super) const MSG_RUNNING_UNIT_TESTS_SPINNER: &str = "Running unit tests"; +pub(super) const MSG_UNIT_TESTS_RUN_SUCCESS: &str = "Unit tests ran successfully"; +pub(super) const MSG_USING_CARGO_NEXTEST: &str = "Using cargo-nextest for running tests"; +pub(super) const MSG_CARGO_NEXTEST_MISSING_ERR: &str = "cargo-nextest is missing, please run 'cargo install cargo-nextest'. Falling back to 'cargo test'"; // Integration tests related messages pub(super) fn msg_integration_tests_run(external_node: bool) -> String { From f8d91d9e5004d60da6ab9a2e354a4d2cb4d1d1a7 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Wed, 7 Aug 2024 15:13:38 +0300 Subject: [PATCH 04/13] Add optional cargo test flags --- .../src/commands/test/args/mod.rs | 1 + .../src/commands/test/args/rust.rs | 9 +++++++ .../zk_supervisor/src/commands/test/mod.rs | 8 +++--- .../zk_supervisor/src/commands/test/rust.rs | 26 +++++++++++-------- .../crates/zk_supervisor/src/messages.rs | 4 +-- 5 files changed, 32 insertions(+), 16 deletions(-) create mode 100644 zk_toolbox/crates/zk_supervisor/src/commands/test/args/rust.rs diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/args/mod.rs b/zk_toolbox/crates/zk_supervisor/src/commands/test/args/mod.rs index fc6098488971..ddd5c5588a0c 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/args/mod.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/test/args/mod.rs @@ -1,3 +1,4 @@ pub mod integration; pub mod recovery; pub mod revert; +pub mod rust; diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/args/rust.rs b/zk_toolbox/crates/zk_supervisor/src/commands/test/args/rust.rs new file mode 100644 index 000000000000..2d94adc3f6a7 --- /dev/null +++ b/zk_toolbox/crates/zk_supervisor/src/commands/test/args/rust.rs @@ -0,0 +1,9 @@ +use clap::Parser; + +use crate::messages::MSG_TEST_RUST_OPTIONS_HELP; + +#[derive(Debug, Parser)] +pub struct RustArgs { + #[clap(long, help = MSG_TEST_RUST_OPTIONS_HELP)] + pub options: Option, +} diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/mod.rs b/zk_toolbox/crates/zk_supervisor/src/commands/test/mod.rs index 91ef25317971..912bd6598d1c 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/mod.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/test/mod.rs @@ -1,4 +1,6 @@ -use args::{integration::IntegrationArgs, recovery::RecoveryArgs, revert::RevertArgs}; +use args::{ + integration::IntegrationArgs, recovery::RecoveryArgs, revert::RevertArgs, rust::RustArgs, +}; use clap::Subcommand; use xshell::Shell; @@ -25,7 +27,7 @@ pub enum TestCommands { #[clap(about = MSG_UPGRADE_TEST_ABOUT, alias = "u")] Upgrade, #[clap(about = MSG_RUST_TEST_ABOUT, alias = "unit")] - Rust, + Rust(RustArgs), } pub fn run(shell: &Shell, args: TestCommands) -> anyhow::Result<()> { @@ -34,6 +36,6 @@ pub fn run(shell: &Shell, args: TestCommands) -> anyhow::Result<()> { TestCommands::Revert(args) => revert::run(shell, args), TestCommands::Recovery(args) => recovery::run(shell, args), TestCommands::Upgrade => upgrade::run(shell), - TestCommands::Rust => rust::run(shell), + TestCommands::Rust(args) => rust::run(shell, args), } } diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs b/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs index ee6b3a768ea2..0f2499a9d429 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs @@ -7,24 +7,28 @@ use crate::messages::{ MSG_USING_CARGO_NEXTEST, }; -pub fn run(shell: &Shell) -> anyhow::Result<()> { +use super::args::rust::RustArgs; + +pub fn run(shell: &Shell, args: RustArgs) -> anyhow::Result<()> { let ecosystem = EcosystemConfig::from_file(shell)?; let _dir_guard = shell.push_dir(&ecosystem.link_to_code); - let spinner; - if nextest_is_installed(shell)? { + + let cmd = if nextest_is_installed(shell)? { logger::info(MSG_USING_CARGO_NEXTEST); - spinner = Spinner::new(MSG_RUNNING_UNIT_TESTS_SPINNER); - Cmd::new(cmd!(shell, "cargo nextest run --release")) - .with_force_run() - .run()?; + cmd!(shell, "cargo nextest run --release") } else { logger::error(MSG_CARGO_NEXTEST_MISSING_ERR); - spinner = Spinner::new(MSG_RUNNING_UNIT_TESTS_SPINNER); - Cmd::new(cmd!(shell, "cargo test --release")) - .with_force_run() - .run()?; + cmd!(shell, "cargo test --release") + }; + + let spinner = Spinner::new(MSG_RUNNING_UNIT_TESTS_SPINNER); + if let Some(options) = args.options { + Cmd::new(cmd.args(options.split_whitespace())).run()?; + } else { + Cmd::new(cmd).run()?; } spinner.finish(); + logger::outro(MSG_UNIT_TESTS_RUN_SUCCESS); Ok(()) } diff --git a/zk_toolbox/crates/zk_supervisor/src/messages.rs b/zk_toolbox/crates/zk_supervisor/src/messages.rs index db835a26dec1..28da94f9a638 100644 --- a/zk_toolbox/crates/zk_supervisor/src/messages.rs +++ b/zk_toolbox/crates/zk_supervisor/src/messages.rs @@ -74,8 +74,8 @@ pub(super) const MSG_INTEGRATION_TESTS_ABOUT: &str = "Run integration tests"; pub(super) const MSG_REVERT_TEST_ABOUT: &str = "Run revert tests"; pub(super) const MSG_RECOVERY_TEST_ABOUT: &str = "Run recovery tests"; pub(super) const MSG_UPGRADE_TEST_ABOUT: &str = "Run upgrade tests"; -pub(super) const MSG_RUST_TEST_ABOUT: &str = - "Run unit-tests, accepts optional arbitrary cargo test flags"; +pub(super) const MSG_RUST_TEST_ABOUT: &str = "Run unit-tests, accepts optional cargo test flags"; +pub(super) const MSG_TEST_RUST_OPTIONS_HELP: &str = "Cargo test flags"; pub(super) const MSG_TESTS_EXTERNAL_NODE_HELP: &str = "Run tests for external node"; pub(super) const MSG_TESTS_RECOVERY_SNAPSHOT_HELP: &str = "Run recovery from a snapshot instead of genesis"; From fedbb6e25b98d9c4d2c3d253d4f221f54b5f981c Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Wed, 7 Aug 2024 15:14:01 +0300 Subject: [PATCH 05/13] fmt --- zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs b/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs index 0f2499a9d429..a85c493d65f2 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs @@ -2,13 +2,12 @@ use common::{cmd::Cmd, logger, spinner::Spinner}; use config::EcosystemConfig; use xshell::{cmd, Shell}; +use super::args::rust::RustArgs; use crate::messages::{ MSG_CARGO_NEXTEST_MISSING_ERR, MSG_RUNNING_UNIT_TESTS_SPINNER, MSG_UNIT_TESTS_RUN_SUCCESS, MSG_USING_CARGO_NEXTEST, }; -use super::args::rust::RustArgs; - pub fn run(shell: &Shell, args: RustArgs) -> anyhow::Result<()> { let ecosystem = EcosystemConfig::from_file(shell)?; let _dir_guard = shell.push_dir(&ecosystem.link_to_code); From bf07c8662a0445086931105deff360071f033a66 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Mon, 12 Aug 2024 10:37:29 +0300 Subject: [PATCH 06/13] Add with_force_run --- .../crates/zk_supervisor/src/commands/test/rust.rs | 13 ++++++------- zk_toolbox/crates/zk_supervisor/src/messages.rs | 1 - 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs b/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs index a85c493d65f2..ec288e798a25 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs @@ -1,11 +1,10 @@ -use common::{cmd::Cmd, logger, spinner::Spinner}; +use common::{cmd::Cmd, logger}; use config::EcosystemConfig; use xshell::{cmd, Shell}; use super::args::rust::RustArgs; use crate::messages::{ - MSG_CARGO_NEXTEST_MISSING_ERR, MSG_RUNNING_UNIT_TESTS_SPINNER, MSG_UNIT_TESTS_RUN_SUCCESS, - MSG_USING_CARGO_NEXTEST, + MSG_CARGO_NEXTEST_MISSING_ERR, MSG_UNIT_TESTS_RUN_SUCCESS, MSG_USING_CARGO_NEXTEST, }; pub fn run(shell: &Shell, args: RustArgs) -> anyhow::Result<()> { @@ -20,13 +19,13 @@ pub fn run(shell: &Shell, args: RustArgs) -> anyhow::Result<()> { cmd!(shell, "cargo test --release") }; - let spinner = Spinner::new(MSG_RUNNING_UNIT_TESTS_SPINNER); if let Some(options) = args.options { - Cmd::new(cmd.args(options.split_whitespace())).run()?; + Cmd::new(cmd.args(options.split_whitespace())) + .with_force_run() + .run()?; } else { - Cmd::new(cmd).run()?; + Cmd::new(cmd).with_force_run().run()?; } - spinner.finish(); logger::outro(MSG_UNIT_TESTS_RUN_SUCCESS); Ok(()) diff --git a/zk_toolbox/crates/zk_supervisor/src/messages.rs b/zk_toolbox/crates/zk_supervisor/src/messages.rs index 28da94f9a638..a42b3d693d23 100644 --- a/zk_toolbox/crates/zk_supervisor/src/messages.rs +++ b/zk_toolbox/crates/zk_supervisor/src/messages.rs @@ -79,7 +79,6 @@ pub(super) const MSG_TEST_RUST_OPTIONS_HELP: &str = "Cargo test flags"; pub(super) const MSG_TESTS_EXTERNAL_NODE_HELP: &str = "Run tests for external node"; pub(super) const MSG_TESTS_RECOVERY_SNAPSHOT_HELP: &str = "Run recovery from a snapshot instead of genesis"; -pub(super) const MSG_RUNNING_UNIT_TESTS_SPINNER: &str = "Running unit tests"; pub(super) const MSG_UNIT_TESTS_RUN_SUCCESS: &str = "Unit tests ran successfully"; pub(super) const MSG_USING_CARGO_NEXTEST: &str = "Using cargo-nextest for running tests"; pub(super) const MSG_CARGO_NEXTEST_MISSING_ERR: &str = "cargo-nextest is missing, please run 'cargo install cargo-nextest'. Falling back to 'cargo test'"; From bdcd1cb1cf740eca6b998f8375a35bdc6ddd80d3 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Mon, 19 Aug 2024 12:20:55 +0300 Subject: [PATCH 07/13] Add reset test databases --- .../src/commands/database/mod.rs | 2 +- .../src/commands/database/reset.rs | 2 +- .../zk_supervisor/src/commands/test/mod.rs | 4 +- .../zk_supervisor/src/commands/test/rust.rs | 84 +++++++++++++++++-- zk_toolbox/crates/zk_supervisor/src/dals.rs | 55 ++++++++++++ zk_toolbox/crates/zk_supervisor/src/main.rs | 2 +- .../crates/zk_supervisor/src/messages.rs | 2 + 7 files changed, 137 insertions(+), 14 deletions(-) diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/database/mod.rs b/zk_toolbox/crates/zk_supervisor/src/commands/database/mod.rs index 74c4063a6974..e942e6f3f4f8 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/database/mod.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/database/mod.rs @@ -14,7 +14,7 @@ mod drop; mod migrate; mod new_migration; mod prepare; -mod reset; +pub mod reset; mod setup; #[derive(Subcommand, Debug)] diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/database/reset.rs b/zk_toolbox/crates/zk_supervisor/src/commands/database/reset.rs index aa813a155510..d25f2a8cd54b 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/database/reset.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/database/reset.rs @@ -35,7 +35,7 @@ pub async fn run(shell: &Shell, args: DatabaseCommonArgs) -> anyhow::Result<()> Ok(()) } -async fn reset_database( +pub async fn reset_database( shell: &Shell, link_to_code: impl AsRef, dal: Dal, diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/mod.rs b/zk_toolbox/crates/zk_supervisor/src/commands/test/mod.rs index e88d48a8ae23..70177888d1d5 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/mod.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/test/mod.rs @@ -36,13 +36,13 @@ pub enum TestCommands { Prover, } -pub fn run(shell: &Shell, args: TestCommands) -> anyhow::Result<()> { +pub async fn run(shell: &Shell, args: TestCommands) -> anyhow::Result<()> { match args { TestCommands::Integration(args) => integration::run(shell, args), TestCommands::Revert(args) => revert::run(shell, args), TestCommands::Recovery(args) => recovery::run(shell, args), TestCommands::Upgrade => upgrade::run(shell), - TestCommands::Rust(args) => rust::run(shell, args), + TestCommands::Rust(args) => rust::run(shell, args).await, TestCommands::L1Contracts => l1_contracts::run(shell), TestCommands::Prover => prover::run(shell), } diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs b/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs index ec288e798a25..f894c2085a44 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs @@ -1,14 +1,31 @@ +use anyhow::Context; use common::{cmd::Cmd, logger}; use config::EcosystemConfig; use xshell::{cmd, Shell}; use super::args::rust::RustArgs; -use crate::messages::{ - MSG_CARGO_NEXTEST_MISSING_ERR, MSG_UNIT_TESTS_RUN_SUCCESS, MSG_USING_CARGO_NEXTEST, +use crate::{ + commands::database, + dals::{get_test_dals, Dal}, + messages::{ + MSG_CARGO_NEXTEST_MISSING_ERR, MSG_CHAIN_NOT_FOUND_ERR, MSG_POSTGRES_CONFIG_NOT_FOUND_ERR, + MSG_RESETTING_TEST_DATABASES, MSG_UNIT_TESTS_RUN_SUCCESS, MSG_USING_CARGO_NEXTEST, + }, }; -pub fn run(shell: &Shell, args: RustArgs) -> anyhow::Result<()> { +pub async fn run(shell: &Shell, args: RustArgs) -> anyhow::Result<()> { let ecosystem = EcosystemConfig::from_file(shell)?; + let chain = ecosystem + .clone() + .load_chain(Some(ecosystem.default_chain)) + .context(MSG_CHAIN_NOT_FOUND_ERR)?; + let general_config = chain.get_general_config()?; + let postgres = general_config + .postgres_config + .context(MSG_POSTGRES_CONFIG_NOT_FOUND_ERR)?; + + reset_test_databases(shell).await?; + let _dir_guard = shell.push_dir(&ecosystem.link_to_code); let cmd = if nextest_is_installed(shell)? { @@ -19,13 +36,26 @@ pub fn run(shell: &Shell, args: RustArgs) -> anyhow::Result<()> { cmd!(shell, "cargo test --release") }; - if let Some(options) = args.options { - Cmd::new(cmd.args(options.split_whitespace())) - .with_force_run() - .run()?; + let cmd = if let Some(options) = args.options { + Cmd::new(cmd.args(options.split_whitespace())).with_force_run() } else { - Cmd::new(cmd).with_force_run().run()?; - } + Cmd::new(cmd).with_force_run() + }; + + let cmd = cmd + .env( + "TEST_DATABASE_URL", + postgres + .test_server_url + .context(MSG_POSTGRES_CONFIG_NOT_FOUND_ERR)?, + ) + .env( + "TEST_PROVER_DATABASE_URL", + postgres + .test_prover_url + .context(MSG_POSTGRES_CONFIG_NOT_FOUND_ERR)?, + ); + cmd.run()?; logger::outro(MSG_UNIT_TESTS_RUN_SUCCESS); Ok(()) @@ -39,3 +69,39 @@ fn nextest_is_installed(shell: &Shell) -> anyhow::Result { )?; Ok(out.contains("cargo-nextest")) } + +fn wait_for_dal(shell: &Shell, dal: &Dal) -> anyhow::Result<()> { + let url = dal.url.as_str(); + for _ in 0..10 { + if let Ok(out) = Cmd::new(cmd!(shell, "pg_isready -d {url}")).run_with_output() { + if out.status.success() { + return Ok(()); + } + } + std::thread::sleep(std::time::Duration::from_secs(1)); + } + anyhow::bail!("Failed to connect to the database"); +} + +async fn reset_test_databases(shell: &Shell) -> anyhow::Result<()> { + logger::info(MSG_RESETTING_TEST_DATABASES); + let ecosystem = EcosystemConfig::from_file(shell)?; + + Cmd::new(cmd!( + shell, + "docker compose -f docker-compose-unit-tests.yml down" + )) + .run()?; + Cmd::new(cmd!( + shell, + "docker compose -f docker-compose-unit-tests.yml up -d" + )) + .run()?; + + for dal in get_test_dals(shell)? { + wait_for_dal(shell, &dal)?; + database::reset::reset_database(shell, ecosystem.link_to_code.clone(), dal.clone()).await?; + } + + Ok(()) +} diff --git a/zk_toolbox/crates/zk_supervisor/src/dals.rs b/zk_toolbox/crates/zk_supervisor/src/dals.rs index 2d2af41500b4..c16b03ae577b 100644 --- a/zk_toolbox/crates/zk_supervisor/src/dals.rs +++ b/zk_toolbox/crates/zk_supervisor/src/dals.rs @@ -1,3 +1,5 @@ +use std::str::FromStr; + use anyhow::{anyhow, Context}; use common::config::global_config; use config::{EcosystemConfig, SecretsConfig}; @@ -41,6 +43,14 @@ pub fn get_dals(shell: &Shell, selected_dals: &SelectedDals) -> anyhow::Result anyhow::Result> { + let mut dals = vec![]; + dals.push(get_test_prover_dal(shell)?); + dals.push(get_test_core_dal(shell)?); + + Ok(dals) +} + pub fn get_prover_dal(shell: &Shell) -> anyhow::Result { let secrets = get_secrets(shell)?; @@ -71,6 +81,51 @@ pub fn get_core_dal(shell: &Shell) -> anyhow::Result { }) } +pub fn get_test_core_dal(shell: &Shell) -> anyhow::Result { + let general_config = get_general_config(shell)?; + let postgres = general_config + .postgres_config + .context(MSG_DATABASE_MUST_BE_PRESENTED)?; + + let url = Url::from_str( + &postgres + .test_server_url + .clone() + .context(MSG_DATABASE_MUST_BE_PRESENTED)?, + )?; + Ok(Dal { + path: CORE_DAL_PATH.to_string(), + url, + }) +} + +pub fn get_test_prover_dal(shell: &Shell) -> anyhow::Result { + let general_config = get_general_config(shell)?; + let postgres = general_config + .postgres_config + .context(MSG_DATABASE_MUST_BE_PRESENTED)?; + + let url = Url::from_str( + &postgres + .test_prover_url + .clone() + .context(MSG_DATABASE_MUST_BE_PRESENTED)?, + )?; + + Ok(Dal { + path: PROVER_DAL_PATH.to_string(), + url, + }) +} + +fn get_general_config(shell: &Shell) -> anyhow::Result { + let ecosystem_config = EcosystemConfig::from_file(shell)?; + let chain_config = ecosystem_config + .load_chain(global_config().chain_name.clone()) + .context(MSG_CHAIN_NOT_FOUND_ERR)?; + chain_config.get_general_config() +} + fn get_secrets(shell: &Shell) -> anyhow::Result { let ecosystem_config = EcosystemConfig::from_file(shell)?; let chain_config = ecosystem_config diff --git a/zk_toolbox/crates/zk_supervisor/src/main.rs b/zk_toolbox/crates/zk_supervisor/src/main.rs index 2976fb554184..97179e31796a 100644 --- a/zk_toolbox/crates/zk_supervisor/src/main.rs +++ b/zk_toolbox/crates/zk_supervisor/src/main.rs @@ -88,7 +88,7 @@ async fn main() -> anyhow::Result<()> { async fn run_subcommand(args: Supervisor, shell: &Shell) -> anyhow::Result<()> { match args.command { SupervisorSubcommands::Database(command) => commands::database::run(shell, command).await?, - SupervisorSubcommands::Test(command) => commands::test::run(shell, command)?, + SupervisorSubcommands::Test(command) => commands::test::run(shell, command).await?, SupervisorSubcommands::Clean(command) => commands::clean::run(shell, command)?, SupervisorSubcommands::Snapshot(command) => commands::snapshot::run(shell, command).await?, SupervisorSubcommands::Markdown => { diff --git a/zk_toolbox/crates/zk_supervisor/src/messages.rs b/zk_toolbox/crates/zk_supervisor/src/messages.rs index f9f66c3800f4..bb1c2021c363 100644 --- a/zk_toolbox/crates/zk_supervisor/src/messages.rs +++ b/zk_toolbox/crates/zk_supervisor/src/messages.rs @@ -86,6 +86,8 @@ pub(super) const MSG_L1_CONTRACTS_ABOUT: &str = "Run L1 contracts tests"; pub(super) const MSG_L1_CONTRACTS_TEST_SUCCESS: &str = "L1 contracts tests ran successfully"; pub(super) const MSG_PROVER_TEST_ABOUT: &str = "Run prover tests"; pub(super) const MSG_PROVER_TEST_SUCCESS: &str = "Prover tests ran successfully"; +pub(super) const MSG_POSTGRES_CONFIG_NOT_FOUND_ERR: &str = "Postgres config not found"; +pub(super) const MSG_RESETTING_TEST_DATABASES: &str = "Resetting test databases"; // Integration tests related messages pub(super) fn msg_integration_tests_run(external_node: bool) -> String { From cda00606f3f69f535feea73c554f854185c785d0 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Mon, 19 Aug 2024 12:21:48 +0300 Subject: [PATCH 08/13] Move msg to const --- zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs | 5 +++-- zk_toolbox/crates/zk_supervisor/src/messages.rs | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs b/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs index f894c2085a44..d172ffb3343d 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs @@ -8,7 +8,8 @@ use crate::{ commands::database, dals::{get_test_dals, Dal}, messages::{ - MSG_CARGO_NEXTEST_MISSING_ERR, MSG_CHAIN_NOT_FOUND_ERR, MSG_POSTGRES_CONFIG_NOT_FOUND_ERR, + MSG_CARGO_NEXTEST_MISSING_ERR, MSG_CHAIN_NOT_FOUND_ERR, + MSG_FAILED_TO_CONNECT_TO_DATABASE_ERR, MSG_POSTGRES_CONFIG_NOT_FOUND_ERR, MSG_RESETTING_TEST_DATABASES, MSG_UNIT_TESTS_RUN_SUCCESS, MSG_USING_CARGO_NEXTEST, }, }; @@ -80,7 +81,7 @@ fn wait_for_dal(shell: &Shell, dal: &Dal) -> anyhow::Result<()> { } std::thread::sleep(std::time::Duration::from_secs(1)); } - anyhow::bail!("Failed to connect to the database"); + anyhow::bail!(MSG_FAILED_TO_CONNECT_TO_DATABASE_ERR); } async fn reset_test_databases(shell: &Shell) -> anyhow::Result<()> { diff --git a/zk_toolbox/crates/zk_supervisor/src/messages.rs b/zk_toolbox/crates/zk_supervisor/src/messages.rs index bb1c2021c363..7ebb38c53108 100644 --- a/zk_toolbox/crates/zk_supervisor/src/messages.rs +++ b/zk_toolbox/crates/zk_supervisor/src/messages.rs @@ -88,6 +88,7 @@ pub(super) const MSG_PROVER_TEST_ABOUT: &str = "Run prover tests"; pub(super) const MSG_PROVER_TEST_SUCCESS: &str = "Prover tests ran successfully"; pub(super) const MSG_POSTGRES_CONFIG_NOT_FOUND_ERR: &str = "Postgres config not found"; pub(super) const MSG_RESETTING_TEST_DATABASES: &str = "Resetting test databases"; +pub(super) const MSG_FAILED_TO_CONNECT_TO_DATABASE_ERR: &str = "Failed to connect to database"; // Integration tests related messages pub(super) fn msg_integration_tests_run(external_node: bool) -> String { From bd493031886a31788eab9a87088bba49a46d95e5 Mon Sep 17 00:00:00 2001 From: Danil Date: Mon, 19 Aug 2024 12:45:50 +0200 Subject: [PATCH 09/13] Small env fixes in tests Signed-off-by: Danil --- core/lib/env_config/src/chain.rs | 1 + core/lib/env_config/src/eth_sender.rs | 2 ++ core/lib/env_config/src/house_keeper.rs | 1 + 3 files changed, 4 insertions(+) diff --git a/core/lib/env_config/src/chain.rs b/core/lib/env_config/src/chain.rs index f62f8b859caa..a25c593bd881 100644 --- a/core/lib/env_config/src/chain.rs +++ b/core/lib/env_config/src/chain.rs @@ -131,6 +131,7 @@ mod tests { CHAIN_STATE_KEEPER_BATCH_OVERHEAD_L1_GAS="800000" CHAIN_STATE_KEEPER_MAX_GAS_PER_BATCH="200000000" CHAIN_STATE_KEEPER_MAX_PUBDATA_PER_BATCH="100000" + CHAIN_STATE_KEEPER_MAX_CIRCUITS_PER_BATCH="24100" CHAIN_STATE_KEEPER_FEE_MODEL_VERSION="V2" CHAIN_STATE_KEEPER_VALIDATION_COMPUTATIONAL_GAS_LIMIT="10000000" CHAIN_STATE_KEEPER_SAVE_CALL_TRACES="false" diff --git a/core/lib/env_config/src/eth_sender.rs b/core/lib/env_config/src/eth_sender.rs index 18a661099b61..b3c1aacae64a 100644 --- a/core/lib/env_config/src/eth_sender.rs +++ b/core/lib/env_config/src/eth_sender.rs @@ -132,6 +132,8 @@ mod tests { ETH_SENDER_SENDER_L1_BATCH_MIN_AGE_BEFORE_EXECUTE_SECONDS="1000" ETH_SENDER_SENDER_MAX_ACCEPTABLE_PRIORITY_FEE_IN_GWEI="100000000000" ETH_SENDER_SENDER_PUBDATA_SENDING_MODE="Calldata" + ETH_WATCH_CONFIRMATIONS_FOR_ETH_EVENT="0" + ETH_WATCH_ETH_NODE_POLL_INTERVAL="300" ETH_CLIENT_WEB3_URL="http://127.0.0.1:8545" "#; diff --git a/core/lib/env_config/src/house_keeper.rs b/core/lib/env_config/src/house_keeper.rs index f23d2705bd0b..25eeda793937 100644 --- a/core/lib/env_config/src/house_keeper.rs +++ b/core/lib/env_config/src/house_keeper.rs @@ -45,6 +45,7 @@ mod tests { HOUSE_KEEPER_PROVER_JOB_RETRYING_INTERVAL_MS="10000" HOUSE_KEEPER_WITNESS_JOB_MOVING_INTERVAL_MS="30000" HOUSE_KEEPER_WITNESS_GENERATOR_STATS_REPORTING_INTERVAL_MS="10000" + HOUSE_KEEPER_WITNESS_GENERATOR_JOB_RETRYING_INTERVAL_MS="30000" HOUSE_KEEPER_FRI_WITNESS_JOB_MOVING_INTERVAL_MS="40000" HOUSE_KEEPER_FRI_PROVER_JOB_RETRYING_INTERVAL_MS="30000" HOUSE_KEEPER_FRI_WITNESS_GENERATOR_JOB_RETRYING_INTERVAL_MS="30000" From b15c5d493c554debfc624d94783ed022720ed5f0 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Mon, 19 Aug 2024 18:47:39 +0300 Subject: [PATCH 10/13] Fix wait_for_db --- zk_toolbox/crates/common/src/db.rs | 13 ++++++----- .../zk_supervisor/src/commands/test/rust.rs | 22 ++++--------------- .../crates/zk_supervisor/src/messages.rs | 1 - 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/zk_toolbox/crates/common/src/db.rs b/zk_toolbox/crates/common/src/db.rs index eda5471170dd..479d09f66823 100644 --- a/zk_toolbox/crates/common/src/db.rs +++ b/zk_toolbox/crates/common/src/db.rs @@ -7,9 +7,9 @@ use sqlx::{ Connection, PgConnection, }; use url::Url; -use xshell::Shell; +use xshell::{cmd, Shell}; -use crate::{config::global_config, logger}; +use crate::{cmd::Cmd, config::global_config, logger}; /// Database configuration. #[derive(Debug, Clone, Serialize, Deserialize)] @@ -148,10 +148,13 @@ pub async fn migrate_db( Ok(()) } -pub async fn wait_for_db(db_url: &Url, tries: u32) -> anyhow::Result<()> { +pub async fn wait_for_db(shell: &Shell, db_url: &Url, tries: u32) -> anyhow::Result<()> { + let url = db_url.as_str(); for i in 0..tries { - if PgConnection::connect(db_url.as_str()).await.is_ok() { - return Ok(()); + if let Ok(out) = Cmd::new(cmd!(shell, "pg_isready -d {url}")).run_with_output() { + if out.status.success() { + return Ok(()); + } } if i < tries - 1 { tokio::time::sleep(std::time::Duration::from_secs(1)).await; diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs b/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs index d172ffb3343d..c12b2e7706d7 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs @@ -1,15 +1,14 @@ use anyhow::Context; -use common::{cmd::Cmd, logger}; +use common::{cmd::Cmd, db::wait_for_db, logger}; use config::EcosystemConfig; use xshell::{cmd, Shell}; use super::args::rust::RustArgs; use crate::{ commands::database, - dals::{get_test_dals, Dal}, + dals::get_test_dals, messages::{ - MSG_CARGO_NEXTEST_MISSING_ERR, MSG_CHAIN_NOT_FOUND_ERR, - MSG_FAILED_TO_CONNECT_TO_DATABASE_ERR, MSG_POSTGRES_CONFIG_NOT_FOUND_ERR, + MSG_CARGO_NEXTEST_MISSING_ERR, MSG_CHAIN_NOT_FOUND_ERR, MSG_POSTGRES_CONFIG_NOT_FOUND_ERR, MSG_RESETTING_TEST_DATABASES, MSG_UNIT_TESTS_RUN_SUCCESS, MSG_USING_CARGO_NEXTEST, }, }; @@ -71,19 +70,6 @@ fn nextest_is_installed(shell: &Shell) -> anyhow::Result { Ok(out.contains("cargo-nextest")) } -fn wait_for_dal(shell: &Shell, dal: &Dal) -> anyhow::Result<()> { - let url = dal.url.as_str(); - for _ in 0..10 { - if let Ok(out) = Cmd::new(cmd!(shell, "pg_isready -d {url}")).run_with_output() { - if out.status.success() { - return Ok(()); - } - } - std::thread::sleep(std::time::Duration::from_secs(1)); - } - anyhow::bail!(MSG_FAILED_TO_CONNECT_TO_DATABASE_ERR); -} - async fn reset_test_databases(shell: &Shell) -> anyhow::Result<()> { logger::info(MSG_RESETTING_TEST_DATABASES); let ecosystem = EcosystemConfig::from_file(shell)?; @@ -100,7 +86,7 @@ async fn reset_test_databases(shell: &Shell) -> anyhow::Result<()> { .run()?; for dal in get_test_dals(shell)? { - wait_for_dal(shell, &dal)?; + wait_for_db(shell, &dal.url.clone(), 3).await?; database::reset::reset_database(shell, ecosystem.link_to_code.clone(), dal.clone()).await?; } diff --git a/zk_toolbox/crates/zk_supervisor/src/messages.rs b/zk_toolbox/crates/zk_supervisor/src/messages.rs index 99a7ba9deef4..db370d13615f 100644 --- a/zk_toolbox/crates/zk_supervisor/src/messages.rs +++ b/zk_toolbox/crates/zk_supervisor/src/messages.rs @@ -91,7 +91,6 @@ pub(super) const MSG_PROVER_TEST_ABOUT: &str = "Run prover tests"; pub(super) const MSG_PROVER_TEST_SUCCESS: &str = "Prover tests ran successfully"; pub(super) const MSG_POSTGRES_CONFIG_NOT_FOUND_ERR: &str = "Postgres config not found"; pub(super) const MSG_RESETTING_TEST_DATABASES: &str = "Resetting test databases"; -pub(super) const MSG_FAILED_TO_CONNECT_TO_DATABASE_ERR: &str = "Failed to connect to database"; // Integration tests related messages pub(super) fn msg_integration_tests_run(external_node: bool) -> String { From 54fd7dc1d28bfd674af63f345fd1dcc6337045fc Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Tue, 20 Aug 2024 10:07:44 +0300 Subject: [PATCH 11/13] Fix reset_test_databases --- zk_toolbox/crates/common/src/db.rs | 15 ++++++--------- .../zk_supervisor/src/commands/test/rust.rs | 4 +++- zk_toolbox/crates/zk_supervisor/src/dals.rs | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/zk_toolbox/crates/common/src/db.rs b/zk_toolbox/crates/common/src/db.rs index 479d09f66823..5b42c01309e4 100644 --- a/zk_toolbox/crates/common/src/db.rs +++ b/zk_toolbox/crates/common/src/db.rs @@ -4,12 +4,12 @@ use anyhow::anyhow; use serde::{Deserialize, Serialize}; use sqlx::{ migrate::{Migrate, MigrateError, Migrator}, - Connection, PgConnection, + ConnectOptions, Connection, PgConnection, }; use url::Url; -use xshell::{cmd, Shell}; +use xshell::Shell; -use crate::{cmd::Cmd, config::global_config, logger}; +use crate::{config::global_config, logger}; /// Database configuration. #[derive(Debug, Clone, Serialize, Deserialize)] @@ -148,13 +148,10 @@ pub async fn migrate_db( Ok(()) } -pub async fn wait_for_db(shell: &Shell, db_url: &Url, tries: u32) -> anyhow::Result<()> { - let url = db_url.as_str(); +pub async fn wait_for_db(db_url: &Url, tries: u32) -> anyhow::Result<()> { for i in 0..tries { - if let Ok(out) = Cmd::new(cmd!(shell, "pg_isready -d {url}")).run_with_output() { - if out.status.success() { - return Ok(()); - } + if PgConnection::connect(db_url.as_str()).await.is_ok() { + return Ok(()); } if i < tries - 1 { tokio::time::sleep(std::time::Duration::from_secs(1)).await; diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs b/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs index c12b2e7706d7..9134ad08246e 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs @@ -86,7 +86,9 @@ async fn reset_test_databases(shell: &Shell) -> anyhow::Result<()> { .run()?; for dal in get_test_dals(shell)? { - wait_for_db(shell, &dal.url.clone(), 3).await?; + let mut url = dal.url.clone(); + url.set_path(""); + wait_for_db(&url, 3).await?; database::reset::reset_database(shell, ecosystem.link_to_code.clone(), dal.clone()).await?; } diff --git a/zk_toolbox/crates/zk_supervisor/src/dals.rs b/zk_toolbox/crates/zk_supervisor/src/dals.rs index c16b03ae577b..ecffab2f75a6 100644 --- a/zk_toolbox/crates/zk_supervisor/src/dals.rs +++ b/zk_toolbox/crates/zk_supervisor/src/dals.rs @@ -45,7 +45,7 @@ pub fn get_dals(shell: &Shell, selected_dals: &SelectedDals) -> anyhow::Result anyhow::Result> { let mut dals = vec![]; - dals.push(get_test_prover_dal(shell)?); + //dals.push(get_test_prover_dal(shell)?); dals.push(get_test_core_dal(shell)?); Ok(dals) From 83b3fc5e565b49f46005456a9b224f05ace298e3 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Tue, 20 Aug 2024 10:07:59 +0300 Subject: [PATCH 12/13] Remove unused import --- zk_toolbox/crates/common/src/db.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zk_toolbox/crates/common/src/db.rs b/zk_toolbox/crates/common/src/db.rs index 5b42c01309e4..eda5471170dd 100644 --- a/zk_toolbox/crates/common/src/db.rs +++ b/zk_toolbox/crates/common/src/db.rs @@ -4,7 +4,7 @@ use anyhow::anyhow; use serde::{Deserialize, Serialize}; use sqlx::{ migrate::{Migrate, MigrateError, Migrator}, - ConnectOptions, Connection, PgConnection, + Connection, PgConnection, }; use url::Url; use xshell::Shell; From 965656de1d1d771f6875de597e40a8f3ce014ca8 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Tue, 20 Aug 2024 13:30:02 +0300 Subject: [PATCH 13/13] Fix get_test_dals --- zk_toolbox/crates/zk_supervisor/src/dals.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/zk_toolbox/crates/zk_supervisor/src/dals.rs b/zk_toolbox/crates/zk_supervisor/src/dals.rs index ecffab2f75a6..8a68d443ef3d 100644 --- a/zk_toolbox/crates/zk_supervisor/src/dals.rs +++ b/zk_toolbox/crates/zk_supervisor/src/dals.rs @@ -44,11 +44,7 @@ pub fn get_dals(shell: &Shell, selected_dals: &SelectedDals) -> anyhow::Result anyhow::Result> { - let mut dals = vec![]; - //dals.push(get_test_prover_dal(shell)?); - dals.push(get_test_core_dal(shell)?); - - Ok(dals) + Ok(vec![get_test_prover_dal(shell)?, get_test_core_dal(shell)?]) } pub fn get_prover_dal(shell: &Shell) -> anyhow::Result {