From 2d1eb2e9662c69d6578d15f328411ce0191e9127 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Wed, 28 Aug 2024 09:03:15 -0300 Subject: [PATCH 01/33] Migrate unit tests --- .github/workflows/ci-core-reusable.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-core-reusable.yml b/.github/workflows/ci-core-reusable.yml index 51550f87a34b..e3f40a7b1cbc 100644 --- a/.github/workflows/ci-core-reusable.yml +++ b/.github/workflows/ci-core-reusable.yml @@ -58,13 +58,14 @@ jobs: ci_run zk db setup ci_run zk compiler all ci_run zk contract build + ci_run ./bin/zkt - name: Contracts unit tests run: ci_run yarn l1-contracts test - name: Rust unit tests run: | - ci_run zk test rust + ci_run zk_supervisor test rust # Benchmarks are not tested by `cargo nextest` unless specified explicitly, and even then `criterion` harness is incompatible # with how `cargo nextest` runs tests. Thus, we run criterion-based benchmark tests manually. ci_run zk f cargo test --release -p vm-benchmark --bench oneshot --bench batch From 1b24aed89e1ad364aa511b8054c756a50fa1bd92 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Wed, 28 Aug 2024 10:19:34 -0300 Subject: [PATCH 02/33] Add options to RustArgs --- .../src/commands/test/args/rust.rs | 6 ++ .../zk_supervisor/src/commands/test/rust.rs | 67 ++++++++++++------- 2 files changed, 47 insertions(+), 26 deletions(-) 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 index 2d94adc3f6a7..a40c544a4c92 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/args/rust.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/test/args/rust.rs @@ -6,4 +6,10 @@ use crate::messages::MSG_TEST_RUST_OPTIONS_HELP; pub struct RustArgs { #[clap(long, help = MSG_TEST_RUST_OPTIONS_HELP)] pub options: Option, + #[clap(long)] + pub link_to_code: Option, + #[clap(long)] + pub test_server_url: Option, + #[clap(long)] + pub test_prover_url: Option, } 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 9134ad08246e..331f66f42c79 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs @@ -1,3 +1,5 @@ +use std::path::{Path, PathBuf}; + use anyhow::Context; use common::{cmd::Cmd, db::wait_for_db, logger}; use config::EcosystemConfig; @@ -14,19 +16,43 @@ use crate::{ }; 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)?; + let link_to_code = if let Some(link_to_code) = args.link_to_code { + PathBuf::from(link_to_code) + } else { + EcosystemConfig::from_file(shell)?.link_to_code + }; + + let (test_server_url, test_prover_url) = + if args.test_prover_url.is_none() || args.test_server_url.is_none() { + 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)?; + + ( + args.test_server_url.unwrap_or( + postgres + .test_server_url + .context(MSG_POSTGRES_CONFIG_NOT_FOUND_ERR)?, + ), + args.test_prover_url.unwrap_or( + postgres + .test_prover_url + .context(MSG_POSTGRES_CONFIG_NOT_FOUND_ERR)?, + ), + ) + } else { + (args.test_server_url.unwrap(), args.test_prover_url.unwrap()) + }; - reset_test_databases(shell).await?; + reset_test_databases(shell, &link_to_code).await?; - let _dir_guard = shell.push_dir(&ecosystem.link_to_code); + let _dir_guard = shell.push_dir(&link_to_code); let cmd = if nextest_is_installed(shell)? { logger::info(MSG_USING_CARGO_NEXTEST); @@ -43,18 +69,8 @@ pub async fn run(shell: &Shell, args: RustArgs) -> anyhow::Result<()> { }; 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)?, - ); + .env("TEST_DATABASE_URL", test_server_url) + .env("TEST_PROVER_DATABASE_URL", test_prover_url); cmd.run()?; logger::outro(MSG_UNIT_TESTS_RUN_SUCCESS); @@ -70,9 +86,8 @@ fn nextest_is_installed(shell: &Shell) -> anyhow::Result { Ok(out.contains("cargo-nextest")) } -async fn reset_test_databases(shell: &Shell) -> anyhow::Result<()> { +async fn reset_test_databases(shell: &Shell, link_to_code: &Path) -> anyhow::Result<()> { logger::info(MSG_RESETTING_TEST_DATABASES); - let ecosystem = EcosystemConfig::from_file(shell)?; Cmd::new(cmd!( shell, @@ -89,7 +104,7 @@ async fn reset_test_databases(shell: &Shell) -> anyhow::Result<()> { 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?; + database::reset::reset_database(shell, link_to_code, dal.clone()).await?; } Ok(()) From a315e674ac4f56202f020a339908879187157b1a Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Wed, 28 Aug 2024 10:22:01 -0300 Subject: [PATCH 03/33] Add help messages --- .../zk_supervisor/src/commands/test/args/rust.rs | 11 +++++++---- zk_toolbox/crates/zk_supervisor/src/messages.rs | 3 +++ 2 files changed, 10 insertions(+), 4 deletions(-) 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 index a40c544a4c92..eb9d02df6ac6 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/args/rust.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/test/args/rust.rs @@ -1,15 +1,18 @@ use clap::Parser; -use crate::messages::MSG_TEST_RUST_OPTIONS_HELP; +use crate::messages::{ + MSG_TEST_PROVER_URL_HELP, MSG_TEST_RUST_LINK_TO_CODE_HELP, MSG_TEST_RUST_OPTIONS_HELP, + MSG_TEST_SERVER_URL_HELP, +}; #[derive(Debug, Parser)] pub struct RustArgs { #[clap(long, help = MSG_TEST_RUST_OPTIONS_HELP)] pub options: Option, - #[clap(long)] + #[clap(long, help = MSG_TEST_RUST_LINK_TO_CODE_HELP)] pub link_to_code: Option, - #[clap(long)] + #[clap(long, help = MSG_TEST_SERVER_URL_HELP)] pub test_server_url: Option, - #[clap(long)] + #[clap(long, help = MSG_TEST_PROVER_URL_HELP)] pub test_prover_url: Option, } diff --git a/zk_toolbox/crates/zk_supervisor/src/messages.rs b/zk_toolbox/crates/zk_supervisor/src/messages.rs index 00e49131de77..fec3b4c9901f 100644 --- a/zk_toolbox/crates/zk_supervisor/src/messages.rs +++ b/zk_toolbox/crates/zk_supervisor/src/messages.rs @@ -84,6 +84,9 @@ 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 cargo test flags"; pub(super) const MSG_TEST_RUST_OPTIONS_HELP: &str = "Cargo test flags"; +pub(super) const MSG_TEST_RUST_LINK_TO_CODE_HELP: &str = "Link to code"; +pub(super) const MSG_TEST_SERVER_URL_HELP: &str = "Test database URL"; +pub(super) const MSG_TEST_PROVER_URL_HELP: &str = "Test prover database URL"; 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 b736c36d8bd1f923bb97fbc6e8b1f84e8ca2ecde Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Wed, 28 Aug 2024 10:24:37 -0300 Subject: [PATCH 04/33] Add options to ci --- .github/workflows/ci-core-reusable.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-core-reusable.yml b/.github/workflows/ci-core-reusable.yml index e3f40a7b1cbc..10cf3a25e3a3 100644 --- a/.github/workflows/ci-core-reusable.yml +++ b/.github/workflows/ci-core-reusable.yml @@ -65,7 +65,7 @@ jobs: - name: Rust unit tests run: | - ci_run zk_supervisor test rust + ci_run zk_supervisor test rust --link-to-code /usr/src/zksync --test_server_url postgres://postgres:notsecurepassword@localhost:5433/zksync_local_test --test_prover_url postgres://postgres:notsecurepassword@localhost:5433/prover_local_test # Benchmarks are not tested by `cargo nextest` unless specified explicitly, and even then `criterion` harness is incompatible # with how `cargo nextest` runs tests. Thus, we run criterion-based benchmark tests manually. ci_run zk f cargo test --release -p vm-benchmark --bench oneshot --bench batch From 86fbf9069e0dd5f8bc189c33fb0b290e9a86811a Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Wed, 28 Aug 2024 10:37:08 -0300 Subject: [PATCH 05/33] Fix options --- .github/workflows/ci-core-reusable.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-core-reusable.yml b/.github/workflows/ci-core-reusable.yml index 10cf3a25e3a3..e696a6356358 100644 --- a/.github/workflows/ci-core-reusable.yml +++ b/.github/workflows/ci-core-reusable.yml @@ -65,7 +65,7 @@ jobs: - name: Rust unit tests run: | - ci_run zk_supervisor test rust --link-to-code /usr/src/zksync --test_server_url postgres://postgres:notsecurepassword@localhost:5433/zksync_local_test --test_prover_url postgres://postgres:notsecurepassword@localhost:5433/prover_local_test + ci_run zk_supervisor test rust --link-to-code /usr/src/zksync --test-server-url postgres://postgres:notsecurepassword@localhost:5433/zksync_local_test --test-prover-url postgres://postgres:notsecurepassword@localhost:5433/prover_local_test # Benchmarks are not tested by `cargo nextest` unless specified explicitly, and even then `criterion` harness is incompatible # with how `cargo nextest` runs tests. Thus, we run criterion-based benchmark tests manually. ci_run zk f cargo test --release -p vm-benchmark --bench oneshot --bench batch From 8d0bbd7fe03d72bb806ec2b69caa3f5f5cf65561 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Wed, 28 Aug 2024 10:57:03 -0300 Subject: [PATCH 06/33] Remove `get_dals` --- .../zk_supervisor/src/commands/test/rust.rs | 29 ++++++++-- zk_toolbox/crates/zk_supervisor/src/dals.rs | 55 +------------------ 2 files changed, 26 insertions(+), 58 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 331f66f42c79..d8e90abaebb7 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,18 @@ -use std::path::{Path, PathBuf}; +use std::{ + path::{Path, PathBuf}, + str::FromStr, +}; use anyhow::Context; use common::{cmd::Cmd, db::wait_for_db, logger}; use config::EcosystemConfig; +use url::Url; use xshell::{cmd, Shell}; use super::args::rust::RustArgs; use crate::{ commands::database, - dals::get_test_dals, + dals::{Dal, CORE_DAL_PATH, PROVER_DAL_PATH}, 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, @@ -50,7 +54,18 @@ pub async fn run(shell: &Shell, args: RustArgs) -> anyhow::Result<()> { (args.test_server_url.unwrap(), args.test_prover_url.unwrap()) }; - reset_test_databases(shell, &link_to_code).await?; + let dals = vec![ + Dal { + url: Url::from_str(&test_server_url.clone())?, + path: CORE_DAL_PATH.to_string(), + }, + Dal { + url: Url::from_str(&test_prover_url.clone())?, + path: PROVER_DAL_PATH.to_string(), + }, + ]; + + reset_test_databases(shell, &link_to_code, dals).await?; let _dir_guard = shell.push_dir(&link_to_code); @@ -86,7 +101,11 @@ fn nextest_is_installed(shell: &Shell) -> anyhow::Result { Ok(out.contains("cargo-nextest")) } -async fn reset_test_databases(shell: &Shell, link_to_code: &Path) -> anyhow::Result<()> { +async fn reset_test_databases( + shell: &Shell, + link_to_code: &Path, + dals: Vec, +) -> anyhow::Result<()> { logger::info(MSG_RESETTING_TEST_DATABASES); Cmd::new(cmd!( @@ -100,7 +119,7 @@ async fn reset_test_databases(shell: &Shell, link_to_code: &Path) -> anyhow::Res )) .run()?; - for dal in get_test_dals(shell)? { + for dal in dals { let mut url = dal.url.clone(); url.set_path(""); wait_for_db(&url, 3).await?; diff --git a/zk_toolbox/crates/zk_supervisor/src/dals.rs b/zk_toolbox/crates/zk_supervisor/src/dals.rs index 8a68d443ef3d..00bf7e54996c 100644 --- a/zk_toolbox/crates/zk_supervisor/src/dals.rs +++ b/zk_toolbox/crates/zk_supervisor/src/dals.rs @@ -1,5 +1,3 @@ -use std::str::FromStr; - use anyhow::{anyhow, Context}; use common::config::global_config; use config::{EcosystemConfig, SecretsConfig}; @@ -8,8 +6,8 @@ use xshell::Shell; use crate::messages::{MSG_CHAIN_NOT_FOUND_ERR, MSG_DATABASE_MUST_BE_PRESENTED}; -const CORE_DAL_PATH: &str = "core/lib/dal"; -const PROVER_DAL_PATH: &str = "prover/crates/lib/prover_dal"; +pub const CORE_DAL_PATH: &str = "core/lib/dal"; +pub const PROVER_DAL_PATH: &str = "prover/crates/lib/prover_dal"; #[derive(Debug, Clone)] pub struct SelectedDals { @@ -43,10 +41,6 @@ pub fn get_dals(shell: &Shell, selected_dals: &SelectedDals) -> anyhow::Result anyhow::Result> { - Ok(vec![get_test_prover_dal(shell)?, get_test_core_dal(shell)?]) -} - pub fn get_prover_dal(shell: &Shell) -> anyhow::Result { let secrets = get_secrets(shell)?; @@ -77,51 +71,6 @@ 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 From 5a1923e195cbc409a3707af5d6a9f4512c45cc19 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Wed, 28 Aug 2024 11:44:48 -0300 Subject: [PATCH 07/33] Increase tries --- zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs | 2 +- 1 file changed, 1 insertion(+), 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 d8e90abaebb7..385c7bb89ade 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs @@ -122,7 +122,7 @@ async fn reset_test_databases( for dal in dals { let mut url = dal.url.clone(); url.set_path(""); - wait_for_db(&url, 3).await?; + wait_for_db(&url, 10).await?; database::reset::reset_database(shell, link_to_code, dal.clone()).await?; } From 6f8250f560a0c4a52b1e3ff481a8a5fb2d1b2154 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Wed, 28 Aug 2024 12:00:52 -0300 Subject: [PATCH 08/33] Activate db before tests --- .github/workflows/ci-core-reusable.yml | 1 + zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-core-reusable.yml b/.github/workflows/ci-core-reusable.yml index e696a6356358..65d0323e35cd 100644 --- a/.github/workflows/ci-core-reusable.yml +++ b/.github/workflows/ci-core-reusable.yml @@ -65,6 +65,7 @@ jobs: - name: Rust unit tests run: | + ci_run docker compose -f docker-compose-unit-tests.yml up -d ci_run zk_supervisor test rust --link-to-code /usr/src/zksync --test-server-url postgres://postgres:notsecurepassword@localhost:5433/zksync_local_test --test-prover-url postgres://postgres:notsecurepassword@localhost:5433/prover_local_test # Benchmarks are not tested by `cargo nextest` unless specified explicitly, and even then `criterion` harness is incompatible # with how `cargo nextest` runs tests. Thus, we run criterion-based benchmark tests manually. 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 385c7bb89ade..d8e90abaebb7 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs @@ -122,7 +122,7 @@ async fn reset_test_databases( for dal in dals { let mut url = dal.url.clone(); url.set_path(""); - wait_for_db(&url, 10).await?; + wait_for_db(&url, 3).await?; database::reset::reset_database(shell, link_to_code, dal.clone()).await?; } From 80dcb2ba4d07aca1735a1107022d217326743d60 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Wed, 28 Aug 2024 12:12:11 -0300 Subject: [PATCH 09/33] Add dbg msg --- .github/workflows/ci-core-reusable.yml | 1 - zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-core-reusable.yml b/.github/workflows/ci-core-reusable.yml index 65d0323e35cd..e696a6356358 100644 --- a/.github/workflows/ci-core-reusable.yml +++ b/.github/workflows/ci-core-reusable.yml @@ -65,7 +65,6 @@ jobs: - name: Rust unit tests run: | - ci_run docker compose -f docker-compose-unit-tests.yml up -d ci_run zk_supervisor test rust --link-to-code /usr/src/zksync --test-server-url postgres://postgres:notsecurepassword@localhost:5433/zksync_local_test --test-prover-url postgres://postgres:notsecurepassword@localhost:5433/prover_local_test # Benchmarks are not tested by `cargo nextest` unless specified explicitly, and even then `criterion` harness is incompatible # with how `cargo nextest` runs tests. Thus, we run criterion-based benchmark tests manually. 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 d8e90abaebb7..a0e08028d0f5 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs @@ -122,6 +122,7 @@ async fn reset_test_databases( for dal in dals { let mut url = dal.url.clone(); url.set_path(""); + logger::debug(&format!("Waiting for database: {}", url)); wait_for_db(&url, 3).await?; database::reset::reset_database(shell, link_to_code, dal.clone()).await?; } From 6a11e4b50db1e8149a4c1bd23dfd2d10ac01b739 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Wed, 28 Aug 2024 12:27:56 -0300 Subject: [PATCH 10/33] Update db url --- .github/workflows/ci-core-reusable.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-core-reusable.yml b/.github/workflows/ci-core-reusable.yml index e696a6356358..38061b660f94 100644 --- a/.github/workflows/ci-core-reusable.yml +++ b/.github/workflows/ci-core-reusable.yml @@ -65,7 +65,7 @@ jobs: - name: Rust unit tests run: | - ci_run zk_supervisor test rust --link-to-code /usr/src/zksync --test-server-url postgres://postgres:notsecurepassword@localhost:5433/zksync_local_test --test-prover-url postgres://postgres:notsecurepassword@localhost:5433/prover_local_test + ci_run zk_supervisor test rust --link-to-code=/usr/src/zksync --test-server-url=postgres://postgres:notsecurepassword@postgres:5433/zksync_local_test --test-prover-url=postgres://postgres:notsecurepassword@postgres:5433/prover_local_test # Benchmarks are not tested by `cargo nextest` unless specified explicitly, and even then `criterion` harness is incompatible # with how `cargo nextest` runs tests. Thus, we run criterion-based benchmark tests manually. ci_run zk f cargo test --release -p vm-benchmark --bench oneshot --bench batch From 396e51c0b3a47a9bfbc1b2da4e7fc6c93b40a5d9 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Fri, 30 Aug 2024 08:41:02 -0300 Subject: [PATCH 11/33] fmt --- core/node/external_proof_integration_api/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/node/external_proof_integration_api/src/lib.rs b/core/node/external_proof_integration_api/src/lib.rs index 4ad8e2595a01..4355896e2a2e 100644 --- a/core/node/external_proof_integration_api/src/lib.rs +++ b/core/node/external_proof_integration_api/src/lib.rs @@ -4,8 +4,6 @@ mod middleware; mod processor; mod types; -pub use crate::processor::Processor; - use std::net::SocketAddr; use anyhow::Context; @@ -20,6 +18,7 @@ use tokio::sync::watch; use types::{ExternalProof, ProofGenerationDataResponse}; use zksync_basic_types::L1BatchNumber; +pub use crate::processor::Processor; use crate::{ metrics::{CallOutcome, Method}, middleware::MetricsMiddleware, From 93b0175460f85e9ec55ee27631d4054c3dc02613 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Fri, 30 Aug 2024 08:41:59 -0300 Subject: [PATCH 12/33] Update db host --- .github/workflows/ci-core-reusable.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-core-reusable.yml b/.github/workflows/ci-core-reusable.yml index a29ae324b2e2..3c983fc02120 100644 --- a/.github/workflows/ci-core-reusable.yml +++ b/.github/workflows/ci-core-reusable.yml @@ -65,7 +65,7 @@ jobs: - name: Rust unit tests run: | - ci_run zk_supervisor test rust --link-to-code=/usr/src/zksync --test-server-url=postgres://postgres:notsecurepassword@postgres:5433/zksync_local_test --test-prover-url=postgres://postgres:notsecurepassword@postgres:5433/prover_local_test + ci_run zk_supervisor test rust --link-to-code=/usr/src/zksync --test-server-url=postgres://postgres:notsecurepassword@localhost:5433/zksync_local_test --test-prover-url=postgres://postgres:notsecurepassword@localhost:5433/prover_local_test # Benchmarks are not tested by `cargo nextest` unless specified explicitly, and even then `criterion` harness is incompatible # with how `cargo nextest` runs tests. Thus, we run criterion-based benchmark tests manually. ci_run zk f cargo test --release -p vm-benchmark --bench oneshot --bench batch From 6102996e33cab21cb4899b83e620958d33c53ebd Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Fri, 30 Aug 2024 08:59:42 -0300 Subject: [PATCH 13/33] Update genesis --- etc/env/file_based/genesis.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/env/file_based/genesis.yaml b/etc/env/file_based/genesis.yaml index 6d7a6ba3c338..220a75944e02 100644 --- a/etc/env/file_based/genesis.yaml +++ b/etc/env/file_based/genesis.yaml @@ -1,7 +1,7 @@ genesis_root: 0xabdb766b18a479a5c783a4b80e12686bc8ea3cc2d8a3050491b701d72370ebb5 genesis_rollup_leaf_index: 54 genesis_batch_commitment: 0x2d00e5f8d77afcebf58a6b82ae56ba967566fe7dfbcb6760319fb0d215d18ffd -genesis_protocol_semantic_version: '0.24.1' +genesis_protocol_semantic_version: '0.24.2' # deprecated genesis_protocol_version: 24 default_aa_hash: 0x01000563374c277a2c1e34659a2a1e87371bb6d852ce142022d497bfb50b9e32 From a8be678928fe9f6cee0906c1f34e39b598478da6 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Fri, 30 Aug 2024 09:00:59 -0300 Subject: [PATCH 14/33] Undo genesis --- etc/env/file_based/genesis.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/env/file_based/genesis.yaml b/etc/env/file_based/genesis.yaml index 220a75944e02..6d7a6ba3c338 100644 --- a/etc/env/file_based/genesis.yaml +++ b/etc/env/file_based/genesis.yaml @@ -1,7 +1,7 @@ genesis_root: 0xabdb766b18a479a5c783a4b80e12686bc8ea3cc2d8a3050491b701d72370ebb5 genesis_rollup_leaf_index: 54 genesis_batch_commitment: 0x2d00e5f8d77afcebf58a6b82ae56ba967566fe7dfbcb6760319fb0d215d18ffd -genesis_protocol_semantic_version: '0.24.2' +genesis_protocol_semantic_version: '0.24.1' # deprecated genesis_protocol_version: 24 default_aa_hash: 0x01000563374c277a2c1e34659a2a1e87371bb6d852ce142022d497bfb50b9e32 From 8d5b51f38d0c7ae635db423dd407d3b52313726a Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Fri, 30 Aug 2024 12:15:59 -0300 Subject: [PATCH 15/33] Use defaults --- .github/workflows/ci-core-reusable.yml | 2 +- .../src/commands/test/args/rust.rs | 11 +--- .../zk_supervisor/src/commands/test/rust.rs | 63 ++++++++----------- .../crates/zk_supervisor/src/defaults.rs | 2 + zk_toolbox/crates/zk_supervisor/src/main.rs | 1 + .../crates/zk_supervisor/src/messages.rs | 3 - 6 files changed, 31 insertions(+), 51 deletions(-) create mode 100644 zk_toolbox/crates/zk_supervisor/src/defaults.rs diff --git a/.github/workflows/ci-core-reusable.yml b/.github/workflows/ci-core-reusable.yml index 3c983fc02120..706ab97c236c 100644 --- a/.github/workflows/ci-core-reusable.yml +++ b/.github/workflows/ci-core-reusable.yml @@ -65,7 +65,7 @@ jobs: - name: Rust unit tests run: | - ci_run zk_supervisor test rust --link-to-code=/usr/src/zksync --test-server-url=postgres://postgres:notsecurepassword@localhost:5433/zksync_local_test --test-prover-url=postgres://postgres:notsecurepassword@localhost:5433/prover_local_test + ci_run zk_supervisor test rust # Benchmarks are not tested by `cargo nextest` unless specified explicitly, and even then `criterion` harness is incompatible # with how `cargo nextest` runs tests. Thus, we run criterion-based benchmark tests manually. ci_run zk f cargo test --release -p vm-benchmark --bench oneshot --bench batch 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 index eb9d02df6ac6..2d94adc3f6a7 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/args/rust.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/test/args/rust.rs @@ -1,18 +1,9 @@ use clap::Parser; -use crate::messages::{ - MSG_TEST_PROVER_URL_HELP, MSG_TEST_RUST_LINK_TO_CODE_HELP, MSG_TEST_RUST_OPTIONS_HELP, - MSG_TEST_SERVER_URL_HELP, -}; +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, - #[clap(long, help = MSG_TEST_RUST_LINK_TO_CODE_HELP)] - pub link_to_code: Option, - #[clap(long, help = MSG_TEST_SERVER_URL_HELP)] - pub test_server_url: Option, - #[clap(long, help = MSG_TEST_PROVER_URL_HELP)] - pub test_prover_url: Option, } 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 4b73e870fbf4..fb76ee12a6de 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs @@ -1,10 +1,7 @@ -use std::{ - path::{Path, PathBuf}, - str::FromStr, -}; +use std::{path::Path, str::FromStr}; use anyhow::Context; -use common::{cmd::Cmd, config::global_config, db::wait_for_db, logger}; +use common::{cmd::Cmd, db::wait_for_db, logger}; use config::EcosystemConfig; use url::Url; use xshell::{cmd, Shell}; @@ -13,47 +10,39 @@ use super::args::rust::RustArgs; use crate::{ commands::database, dals::{Dal, CORE_DAL_PATH, PROVER_DAL_PATH}, + defaults::{TEST_DATABASE_PROVER_URL, TEST_DATABASE_SERVER_URL}, messages::{ - MSG_CARGO_NEXTEST_MISSING_ERR, MSG_CHAIN_NOT_FOUND_ERR, MSG_POSTGRES_CONFIG_NOT_FOUND_ERR, + MSG_CARGO_NEXTEST_MISSING_ERR, MSG_POSTGRES_CONFIG_NOT_FOUND_ERR, MSG_RESETTING_TEST_DATABASES, MSG_UNIT_TESTS_RUN_SUCCESS, MSG_USING_CARGO_NEXTEST, }, }; pub async fn run(shell: &Shell, args: RustArgs) -> anyhow::Result<()> { - let link_to_code = if let Some(link_to_code) = args.link_to_code { - PathBuf::from(link_to_code) + let ecosystem = EcosystemConfig::from_file(shell)?; + let chain = ecosystem.clone().load_chain(Some(ecosystem.default_chain)); + let link_to_code = ecosystem.link_to_code; + + let (test_server_url, test_prover_url) = if let Some(chain) = chain { + let general_config = chain.get_general_config()?; + let postgres = general_config + .postgres_config + .context(MSG_POSTGRES_CONFIG_NOT_FOUND_ERR)?; + + ( + postgres + .test_server_url + .context(MSG_POSTGRES_CONFIG_NOT_FOUND_ERR)?, + postgres + .test_prover_url + .context(MSG_POSTGRES_CONFIG_NOT_FOUND_ERR)?, + ) } else { - EcosystemConfig::from_file(shell)?.link_to_code + ( + TEST_DATABASE_SERVER_URL.to_string(), + TEST_DATABASE_PROVER_URL.to_string(), + ) }; - let (test_server_url, test_prover_url) = - if args.test_prover_url.is_none() || args.test_server_url.is_none() { - 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)?; - - ( - args.test_server_url.unwrap_or( - postgres - .test_server_url - .context(MSG_POSTGRES_CONFIG_NOT_FOUND_ERR)?, - ), - args.test_prover_url.unwrap_or( - postgres - .test_prover_url - .context(MSG_POSTGRES_CONFIG_NOT_FOUND_ERR)?, - ), - ) - } else { - (args.test_server_url.unwrap(), args.test_prover_url.unwrap()) - }; - let dals = vec![ Dal { url: Url::from_str(&test_server_url.clone())?, diff --git a/zk_toolbox/crates/zk_supervisor/src/defaults.rs b/zk_toolbox/crates/zk_supervisor/src/defaults.rs new file mode 100644 index 000000000000..4cbdb8b3ee7d --- /dev/null +++ b/zk_toolbox/crates/zk_supervisor/src/defaults.rs @@ -0,0 +1,2 @@ +pub const TEST_DATABASE_SERVER_URL: &str = "postgres://postgres:notsecurepassword@localhost:5433"; +pub const TEST_DATABASE_PROVER_URL: &str = "postgres://postgres:notsecurepassword@localhost:5433"; diff --git a/zk_toolbox/crates/zk_supervisor/src/main.rs b/zk_toolbox/crates/zk_supervisor/src/main.rs index 9a1c1ad74bcd..192c27195a5b 100644 --- a/zk_toolbox/crates/zk_supervisor/src/main.rs +++ b/zk_toolbox/crates/zk_supervisor/src/main.rs @@ -20,6 +20,7 @@ use crate::commands::{clean::CleanCommands, fmt::FmtArgs}; mod commands; mod dals; +mod defaults; mod messages; #[derive(Parser, Debug)] diff --git a/zk_toolbox/crates/zk_supervisor/src/messages.rs b/zk_toolbox/crates/zk_supervisor/src/messages.rs index 79d527010e7f..2374cd69f0e6 100644 --- a/zk_toolbox/crates/zk_supervisor/src/messages.rs +++ b/zk_toolbox/crates/zk_supervisor/src/messages.rs @@ -88,9 +88,6 @@ 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 cargo test flags"; pub(super) const MSG_TEST_RUST_OPTIONS_HELP: &str = "Cargo test flags"; -pub(super) const MSG_TEST_RUST_LINK_TO_CODE_HELP: &str = "Link to code"; -pub(super) const MSG_TEST_SERVER_URL_HELP: &str = "Test database URL"; -pub(super) const MSG_TEST_PROVER_URL_HELP: &str = "Test prover database URL"; pub(super) const MSG_BUILD_ABOUT: &str = "Build all test dependencies"; pub(super) const MSG_TESTS_EXTERNAL_NODE_HELP: &str = "Run tests for external node"; pub(super) const MSG_NO_DEPS_HELP: &str = "Do not install or build dependencies"; From c499942846855cedfe0394af88a5a340d23d6af0 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Fri, 30 Aug 2024 12:54:55 -0300 Subject: [PATCH 16/33] Fix chain not initialized --- .../crates/zk_supervisor/src/commands/test/rust.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 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 fb76ee12a6de..a4e757c4f6a4 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs @@ -12,18 +12,21 @@ use crate::{ dals::{Dal, CORE_DAL_PATH, PROVER_DAL_PATH}, defaults::{TEST_DATABASE_PROVER_URL, TEST_DATABASE_SERVER_URL}, messages::{ - MSG_CARGO_NEXTEST_MISSING_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, }, }; 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)); + let chain = ecosystem + .clone() + .load_chain(Some(ecosystem.default_chain)) + .context(MSG_CHAIN_NOT_FOUND_ERR)?; + let general_config = chain.get_general_config(); let link_to_code = ecosystem.link_to_code; - let (test_server_url, test_prover_url) = if let Some(chain) = chain { - let general_config = chain.get_general_config()?; + let (test_server_url, test_prover_url) = if let Ok(general_config) = general_config { let postgres = general_config .postgres_config .context(MSG_POSTGRES_CONFIG_NOT_FOUND_ERR)?; From de90c3c8aadbd9793efe22992aeb2f1b055c4807 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Fri, 30 Aug 2024 13:08:33 -0300 Subject: [PATCH 17/33] Fix default dbs --- zk_toolbox/crates/zk_supervisor/src/defaults.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/zk_toolbox/crates/zk_supervisor/src/defaults.rs b/zk_toolbox/crates/zk_supervisor/src/defaults.rs index 4cbdb8b3ee7d..f4bae739c2d1 100644 --- a/zk_toolbox/crates/zk_supervisor/src/defaults.rs +++ b/zk_toolbox/crates/zk_supervisor/src/defaults.rs @@ -1,2 +1,4 @@ -pub const TEST_DATABASE_SERVER_URL: &str = "postgres://postgres:notsecurepassword@localhost:5433"; -pub const TEST_DATABASE_PROVER_URL: &str = "postgres://postgres:notsecurepassword@localhost:5433"; +pub const TEST_DATABASE_SERVER_URL: &str = + "postgres://postgres:notsecurepassword@localhost:5433/zksync_local_test"; +pub const TEST_DATABASE_PROVER_URL: &str = + "postgres://postgres:notsecurepassword@localhost:5433/prover_local_test"; From c19545f8a4087a7637b83df89d057abc691576e7 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Fri, 30 Aug 2024 15:07:59 -0300 Subject: [PATCH 18/33] Remove zk from benchmark test --- .github/workflows/ci-core-reusable.yml | 2 +- zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci-core-reusable.yml b/.github/workflows/ci-core-reusable.yml index 706ab97c236c..caff669d3a8c 100644 --- a/.github/workflows/ci-core-reusable.yml +++ b/.github/workflows/ci-core-reusable.yml @@ -68,7 +68,7 @@ jobs: ci_run zk_supervisor test rust # Benchmarks are not tested by `cargo nextest` unless specified explicitly, and even then `criterion` harness is incompatible # with how `cargo nextest` runs tests. Thus, we run criterion-based benchmark tests manually. - ci_run zk f cargo test --release -p vm-benchmark --bench oneshot --bench batch + ci_run cargo test --release -p vm-benchmark --bench oneshot --bench batch loadtest: runs-on: [ matterlabs-ci-runner-high-performance ] 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 a4e757c4f6a4..ad1318cfa768 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs @@ -114,7 +114,6 @@ async fn reset_test_databases( for dal in dals { let mut url = dal.url.clone(); url.set_path(""); - logger::debug(&format!("Waiting for database: {}", url)); wait_for_db(&url, 3).await?; database::reset::reset_database(shell, link_to_code, dal.clone()).await?; } From 75917202d636dcbf1077a6180c7bf8ba0cc6cfec Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Fri, 30 Aug 2024 15:08:47 -0300 Subject: [PATCH 19/33] Remove zk installation --- .github/workflows/ci-core-reusable.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/ci-core-reusable.yml b/.github/workflows/ci-core-reusable.yml index caff669d3a8c..2bf5c76ee2c7 100644 --- a/.github/workflows/ci-core-reusable.yml +++ b/.github/workflows/ci-core-reusable.yml @@ -52,12 +52,7 @@ jobs: - name: Init run: | - ci_run zk ci_run run_retried rustup show - ci_run zk run yarn - ci_run zk db setup - ci_run zk compiler all - ci_run zk contract build ci_run ./bin/zkt - name: Contracts unit tests From 798d3f11b06a59576c62c3831e9f1e6c3ba1b510 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Fri, 30 Aug 2024 15:18:42 -0300 Subject: [PATCH 20/33] Remove Contracts unit tests --- .github/workflows/ci-core-reusable.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/ci-core-reusable.yml b/.github/workflows/ci-core-reusable.yml index 2bf5c76ee2c7..a1ffb491566f 100644 --- a/.github/workflows/ci-core-reusable.yml +++ b/.github/workflows/ci-core-reusable.yml @@ -55,9 +55,6 @@ jobs: ci_run run_retried rustup show ci_run ./bin/zkt - - name: Contracts unit tests - run: ci_run yarn l1-contracts test - - name: Rust unit tests run: | ci_run zk_supervisor test rust From 4aee39396c49df36bac204462674481e79716006 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Fri, 30 Aug 2024 16:12:20 -0300 Subject: [PATCH 21/33] Compile contracts --- .github/workflows/ci-core-reusable.yml | 2 ++ infrastructure/zk/src/contract.ts | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-core-reusable.yml b/.github/workflows/ci-core-reusable.yml index a1ffb491566f..da977d6b9bef 100644 --- a/.github/workflows/ci-core-reusable.yml +++ b/.github/workflows/ci-core-reusable.yml @@ -53,6 +53,8 @@ jobs: - name: Init run: | ci_run run_retried rustup show + yarn l1-contracts build + yarn l2-contracts build ci_run ./bin/zkt - name: Rust unit tests diff --git a/infrastructure/zk/src/contract.ts b/infrastructure/zk/src/contract.ts index ba9fe08041db..bde745353e69 100644 --- a/infrastructure/zk/src/contract.ts +++ b/infrastructure/zk/src/contract.ts @@ -99,8 +99,7 @@ export async function deployL2ThroughL1({ } await utils.spawn( - `yarn l2-contracts deploy-shared-bridge-on-l2-through-l1 ${args.join(' ')} ${ - localLegacyBridgeTesting ? '--local-legacy-bridge-testing' : '' + `yarn l2-contracts deploy-shared-bridge-on-l2-through-l1 ${args.join(' ')} ${localLegacyBridgeTesting ? '--local-legacy-bridge-testing' : '' } | tee deployL2.log` ); From e85121fd0c563bba36e6d548d669c37b6aa993c0 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Fri, 30 Aug 2024 16:14:00 -0300 Subject: [PATCH 22/33] fmt --- infrastructure/zk/src/contract.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/infrastructure/zk/src/contract.ts b/infrastructure/zk/src/contract.ts index bde745353e69..ba9fe08041db 100644 --- a/infrastructure/zk/src/contract.ts +++ b/infrastructure/zk/src/contract.ts @@ -99,7 +99,8 @@ export async function deployL2ThroughL1({ } await utils.spawn( - `yarn l2-contracts deploy-shared-bridge-on-l2-through-l1 ${args.join(' ')} ${localLegacyBridgeTesting ? '--local-legacy-bridge-testing' : '' + `yarn l2-contracts deploy-shared-bridge-on-l2-through-l1 ${args.join(' ')} ${ + localLegacyBridgeTesting ? '--local-legacy-bridge-testing' : '' } | tee deployL2.log` ); From af98f970ed5fb99c7db817b62687eab92d3dedcc Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Fri, 30 Aug 2024 16:28:20 -0300 Subject: [PATCH 23/33] Add ci_run --- .github/workflows/ci-core-reusable.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-core-reusable.yml b/.github/workflows/ci-core-reusable.yml index da977d6b9bef..13837a4ce939 100644 --- a/.github/workflows/ci-core-reusable.yml +++ b/.github/workflows/ci-core-reusable.yml @@ -53,8 +53,8 @@ jobs: - name: Init run: | ci_run run_retried rustup show - yarn l1-contracts build - yarn l2-contracts build + ci_run yarn l1-contracts build + ci_run yarn l2-contracts build ci_run ./bin/zkt - name: Rust unit tests From 49e0c0aca2ff3d29d3b0247ed8b1f59eb430adb1 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Mon, 2 Sep 2024 11:27:52 -0300 Subject: [PATCH 24/33] Add zks contracts --- .../zk_supervisor/src/commands/contracts.rs | 41 +++++++++++++++++++ .../crates/zk_supervisor/src/commands/mod.rs | 1 + zk_toolbox/crates/zk_supervisor/src/main.rs | 9 ++-- .../crates/zk_supervisor/src/messages.rs | 9 ++++ 4 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 zk_toolbox/crates/zk_supervisor/src/commands/contracts.rs diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/contracts.rs b/zk_toolbox/crates/zk_supervisor/src/commands/contracts.rs new file mode 100644 index 000000000000..a265bbde1579 --- /dev/null +++ b/zk_toolbox/crates/zk_supervisor/src/commands/contracts.rs @@ -0,0 +1,41 @@ +use common::{cmd::Cmd, logger, spinner::Spinner}; +use config::EcosystemConfig; +use xshell::{cmd, Shell}; + +use crate::messages::{ + MSG_BUILDING_CONTRACTS, MSG_BUILDING_CONTRACTS_SUCCESS, MSG_BUILDING_L1_CONTRACTS_SPINNER, + MSG_BUILDING_L2_CONTRACTS_SPINNER, MSG_BUILDING_SYSTEM_CONTRACTS_SPINNER, + MSG_CONTRACTS_DEPS_SPINNER, +}; + +pub fn run(shell: &Shell) -> anyhow::Result<()> { + logger::info(MSG_BUILDING_CONTRACTS); + + let ecosystem = EcosystemConfig::from_file(shell)?; + let link_to_code = ecosystem.link_to_code.clone(); + + let spinner = Spinner::new(MSG_CONTRACTS_DEPS_SPINNER); + let _dir_guard = shell.push_dir(&link_to_code); + Cmd::new(cmd!(shell, "yarn install")).run()?; + spinner.finish(); + + let spinner = Spinner::new(MSG_BUILDING_L1_CONTRACTS_SPINNER); + let foundry_contracts_path = ecosystem.path_to_foundry(); + let _dir_guard = shell.push_dir(&foundry_contracts_path); + Cmd::new(cmd!(shell, "forge build")).run()?; + spinner.finish(); + + let spinner = Spinner::new(MSG_BUILDING_SYSTEM_CONTRACTS_SPINNER); + let _dir_guard = shell.push_dir(link_to_code.join("contracts")); + Cmd::new(cmd!(shell, "yarn sc build")).run()?; + spinner.finish(); + + let spinner = Spinner::new(MSG_BUILDING_L2_CONTRACTS_SPINNER); + let _dir_guard = shell.push_dir(&link_to_code); + Cmd::new(cmd!(shell, "yarn l2-contracts build")).run()?; + spinner.finish(); + + logger::outro(MSG_BUILDING_CONTRACTS_SUCCESS); + + Ok(()) +} diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/mod.rs b/zk_toolbox/crates/zk_supervisor/src/commands/mod.rs index 181ce50c2134..e45512d50d89 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/mod.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/mod.rs @@ -1,4 +1,5 @@ pub mod clean; +pub mod contracts; pub mod database; pub mod fmt; pub mod lint; diff --git a/zk_toolbox/crates/zk_supervisor/src/main.rs b/zk_toolbox/crates/zk_supervisor/src/main.rs index 9a1c1ad74bcd..31bcd67cf71e 100644 --- a/zk_toolbox/crates/zk_supervisor/src/main.rs +++ b/zk_toolbox/crates/zk_supervisor/src/main.rs @@ -10,9 +10,9 @@ use common::{ }; use config::EcosystemConfig; use messages::{ - msg_global_chain_does_not_exist, MSG_PROVER_VERSION_ABOUT, MSG_SUBCOMMAND_CLEAN, - MSG_SUBCOMMAND_DATABASE_ABOUT, MSG_SUBCOMMAND_FMT_ABOUT, MSG_SUBCOMMAND_LINT_ABOUT, - MSG_SUBCOMMAND_SNAPSHOTS_CREATOR_ABOUT, MSG_SUBCOMMAND_TESTS_ABOUT, + msg_global_chain_does_not_exist, MSG_CONTRACTS_ABOUT, MSG_PROVER_VERSION_ABOUT, + MSG_SUBCOMMAND_CLEAN, MSG_SUBCOMMAND_DATABASE_ABOUT, MSG_SUBCOMMAND_FMT_ABOUT, + MSG_SUBCOMMAND_LINT_ABOUT, MSG_SUBCOMMAND_SNAPSHOTS_CREATOR_ABOUT, MSG_SUBCOMMAND_TESTS_ABOUT, }; use xshell::Shell; @@ -49,6 +49,8 @@ enum SupervisorSubcommands { Markdown, #[command(about = MSG_PROVER_VERSION_ABOUT)] ProverVersion, + #[command(about = MSG_CONTRACTS_ABOUT)] + Contracts, } #[derive(Parser, Debug)] @@ -106,6 +108,7 @@ async fn run_subcommand(args: Supervisor, shell: &Shell) -> anyhow::Result<()> { SupervisorSubcommands::Lint(args) => commands::lint::run(shell, args)?, SupervisorSubcommands::Fmt(args) => commands::fmt::run(shell.clone(), args).await?, SupervisorSubcommands::ProverVersion => commands::prover_version::run(shell).await?, + SupervisorSubcommands::Contracts => commands::contracts::run(shell)?, } Ok(()) } diff --git a/zk_toolbox/crates/zk_supervisor/src/messages.rs b/zk_toolbox/crates/zk_supervisor/src/messages.rs index 2374cd69f0e6..8587bcdb1801 100644 --- a/zk_toolbox/crates/zk_supervisor/src/messages.rs +++ b/zk_toolbox/crates/zk_supervisor/src/messages.rs @@ -13,6 +13,7 @@ pub(super) const MSG_SUBCOMMAND_DATABASE_ABOUT: &str = "Database related command pub(super) const MSG_SUBCOMMAND_TESTS_ABOUT: &str = "Run tests"; pub(super) const MSG_SUBCOMMAND_CLEAN: &str = "Clean artifacts"; pub(super) const MSG_SUBCOMMAND_LINT_ABOUT: &str = "Lint code"; +pub(super) const MSG_CONTRACTS_ABOUT: &str = "Build contracts"; pub(super) const MSG_SUBCOMMAND_FMT_ABOUT: &str = "Format code"; @@ -104,6 +105,14 @@ 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"; +// Contract building related messages +pub(super) const MSG_BUILDING_CONTRACTS: &str = "Building contracts"; +pub(super) const MSG_CONTRACTS_DEPS_SPINNER: &str = "Installing dependencies.."; +pub(super) const MSG_BUILDING_L2_CONTRACTS_SPINNER: &str = "Building L2 contracts.."; +pub(super) const MSG_BUILDING_L1_CONTRACTS_SPINNER: &str = "Building L1 contracts.."; +pub(super) const MSG_BUILDING_SYSTEM_CONTRACTS_SPINNER: &str = "Building system contracts.."; +pub(super) const MSG_BUILDING_CONTRACTS_SUCCESS: &str = "Contracts built successfully"; + // Integration tests related messages pub(super) fn msg_integration_tests_run(external_node: bool) -> String { let base = "Running integration tests"; From 8bc88ff7a18d8d51234091d9b745faacb263d1cd Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Mon, 2 Sep 2024 11:29:27 -0300 Subject: [PATCH 25/33] fmt --- core/node/external_proof_integration_api/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/node/external_proof_integration_api/src/lib.rs b/core/node/external_proof_integration_api/src/lib.rs index 4ad8e2595a01..4355896e2a2e 100644 --- a/core/node/external_proof_integration_api/src/lib.rs +++ b/core/node/external_proof_integration_api/src/lib.rs @@ -4,8 +4,6 @@ mod middleware; mod processor; mod types; -pub use crate::processor::Processor; - use std::net::SocketAddr; use anyhow::Context; @@ -20,6 +18,7 @@ use tokio::sync::watch; use types::{ExternalProof, ProofGenerationDataResponse}; use zksync_basic_types::L1BatchNumber; +pub use crate::processor::Processor; use crate::{ metrics::{CallOutcome, Method}, middleware::MetricsMiddleware, From 512668fd79fa7206fba27852217acdf80799dd52 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Mon, 2 Sep 2024 11:31:03 -0300 Subject: [PATCH 26/33] Add readme --- zk_toolbox/README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/zk_toolbox/README.md b/zk_toolbox/README.md index b35d4c8d56f1..469e36a65f64 100644 --- a/zk_toolbox/README.md +++ b/zk_toolbox/README.md @@ -320,6 +320,14 @@ Create a snapshot of the current chain: zks snapshot create ``` +### Contracts + +Build contracts: + +```bash +zks contracts +``` + ### Format Format code: From 2af07dd4fc092917e2d82b43b6c105e99487fc50 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Mon, 2 Sep 2024 13:29:29 -0300 Subject: [PATCH 27/33] Add Contracts Args --- .../zk_supervisor/src/commands/contracts.rs | 96 +++++++++++++++---- zk_toolbox/crates/zk_supervisor/src/main.rs | 7 +- 2 files changed, 84 insertions(+), 19 deletions(-) diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/contracts.rs b/zk_toolbox/crates/zk_supervisor/src/commands/contracts.rs index a265bbde1579..26799ea8c4af 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/contracts.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/contracts.rs @@ -1,5 +1,9 @@ +use std::path::PathBuf; + +use clap::{Parser, ValueEnum}; use common::{cmd::Cmd, logger, spinner::Spinner}; use config::EcosystemConfig; +use strum::EnumIter; use xshell::{cmd, Shell}; use crate::messages::{ @@ -8,32 +12,92 @@ use crate::messages::{ MSG_CONTRACTS_DEPS_SPINNER, }; -pub fn run(shell: &Shell) -> anyhow::Result<()> { +#[derive(Debug, Parser)] +pub struct ContractsArgs { + #[clap(long, short = 'c')] + pub contracts: Vec, +} + +#[derive(Debug, ValueEnum, EnumIter, strum::Display, PartialEq, Eq, Clone, Copy)] +#[strum(serialize_all = "lowercase")] +pub enum ContractType { + L1, + L2, + SystemContracts, +} + +#[derive(Debug)] +struct ContractBuilder { + dir: PathBuf, + cmd: String, + msg: String, +} + +impl ContractBuilder { + fn new(ecosystem: &EcosystemConfig, contract_type: ContractType) -> Self { + match contract_type { + ContractType::L1 => Self { + dir: ecosystem.path_to_foundry(), + cmd: "forge build".to_string(), + msg: MSG_BUILDING_L1_CONTRACTS_SPINNER.to_string(), + }, + ContractType::L2 => Self { + dir: ecosystem.link_to_code.clone(), + cmd: "yarn l2-contracts build".to_string(), + msg: MSG_BUILDING_L2_CONTRACTS_SPINNER.to_string(), + }, + ContractType::SystemContracts => Self { + dir: ecosystem.link_to_code.join("contracts"), + cmd: "yarn sc build".to_string(), + msg: MSG_BUILDING_SYSTEM_CONTRACTS_SPINNER.to_string(), + }, + } + } + + fn build(&self, shell: &Shell) -> anyhow::Result<()> { + let spinner = Spinner::new(&self.msg); + let _dir_guard = shell.push_dir(&self.dir); + + let mut args = self.cmd.split_whitespace().collect::>(); + let command = args.remove(0); // It's safe to unwrap here because we know that the vec is not empty + let mut cmd = cmd!(shell, "{command}"); + + for arg in args { + cmd = cmd.arg(arg); + } + + Cmd::new(cmd).run()?; + + spinner.finish(); + Ok(()) + } +} + +pub fn run(shell: &Shell, args: ContractsArgs) -> anyhow::Result<()> { logger::info(MSG_BUILDING_CONTRACTS); let ecosystem = EcosystemConfig::from_file(shell)?; let link_to_code = ecosystem.link_to_code.clone(); + let contracts = if args.contracts.is_empty() { + vec![ + ContractType::L1, + ContractType::L2, + ContractType::SystemContracts, + ] + } else { + args.contracts.clone() + }; + let spinner = Spinner::new(MSG_CONTRACTS_DEPS_SPINNER); let _dir_guard = shell.push_dir(&link_to_code); Cmd::new(cmd!(shell, "yarn install")).run()?; spinner.finish(); - let spinner = Spinner::new(MSG_BUILDING_L1_CONTRACTS_SPINNER); - let foundry_contracts_path = ecosystem.path_to_foundry(); - let _dir_guard = shell.push_dir(&foundry_contracts_path); - Cmd::new(cmd!(shell, "forge build")).run()?; - spinner.finish(); - - let spinner = Spinner::new(MSG_BUILDING_SYSTEM_CONTRACTS_SPINNER); - let _dir_guard = shell.push_dir(link_to_code.join("contracts")); - Cmd::new(cmd!(shell, "yarn sc build")).run()?; - spinner.finish(); - - let spinner = Spinner::new(MSG_BUILDING_L2_CONTRACTS_SPINNER); - let _dir_guard = shell.push_dir(&link_to_code); - Cmd::new(cmd!(shell, "yarn l2-contracts build")).run()?; - spinner.finish(); + contracts + .iter() + .map(|contract| ContractBuilder::new(&ecosystem, *contract)) + .try_for_each(|builder| builder.build(shell))?; logger::outro(MSG_BUILDING_CONTRACTS_SUCCESS); diff --git a/zk_toolbox/crates/zk_supervisor/src/main.rs b/zk_toolbox/crates/zk_supervisor/src/main.rs index 31bcd67cf71e..6b5bfa46943e 100644 --- a/zk_toolbox/crates/zk_supervisor/src/main.rs +++ b/zk_toolbox/crates/zk_supervisor/src/main.rs @@ -1,6 +1,7 @@ use clap::{Parser, Subcommand}; use commands::{ - database::DatabaseCommands, lint::LintArgs, snapshot::SnapshotCommands, test::TestCommands, + contracts::ContractsArgs, database::DatabaseCommands, lint::LintArgs, + snapshot::SnapshotCommands, test::TestCommands, }; use common::{ check_general_prerequisites, @@ -50,7 +51,7 @@ enum SupervisorSubcommands { #[command(about = MSG_PROVER_VERSION_ABOUT)] ProverVersion, #[command(about = MSG_CONTRACTS_ABOUT)] - Contracts, + Contracts(ContractsArgs), } #[derive(Parser, Debug)] @@ -108,7 +109,7 @@ async fn run_subcommand(args: Supervisor, shell: &Shell) -> anyhow::Result<()> { SupervisorSubcommands::Lint(args) => commands::lint::run(shell, args)?, SupervisorSubcommands::Fmt(args) => commands::fmt::run(shell.clone(), args).await?, SupervisorSubcommands::ProverVersion => commands::prover_version::run(shell).await?, - SupervisorSubcommands::Contracts => commands::contracts::run(shell)?, + SupervisorSubcommands::Contracts(args) => commands::contracts::run(shell, args)?, } Ok(()) } From 276aff7fd5e1ceaecfae37a702a83aa8c3b5196e Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Tue, 3 Sep 2024 11:58:45 -0300 Subject: [PATCH 28/33] Replace vec with option bools --- .../zk_supervisor/src/commands/contracts.rs | 56 ++++++++++++++----- .../crates/zk_supervisor/src/messages.rs | 4 ++ 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/contracts.rs b/zk_toolbox/crates/zk_supervisor/src/commands/contracts.rs index 26799ea8c4af..de6a3600e3b8 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/contracts.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/contracts.rs @@ -9,13 +9,47 @@ use xshell::{cmd, Shell}; use crate::messages::{ MSG_BUILDING_CONTRACTS, MSG_BUILDING_CONTRACTS_SUCCESS, MSG_BUILDING_L1_CONTRACTS_SPINNER, MSG_BUILDING_L2_CONTRACTS_SPINNER, MSG_BUILDING_SYSTEM_CONTRACTS_SPINNER, - MSG_CONTRACTS_DEPS_SPINNER, + MSG_BUILD_L1_CONTRACTS_HELP, MSG_BUILD_L2_CONTRACTS_HELP, MSG_BUILD_SYSTEM_CONTRACTS_HELP, + MSG_CONTRACTS_DEPS_SPINNER, MSG_NOTHING_TO_BUILD_MSG, }; #[derive(Debug, Parser)] pub struct ContractsArgs { - #[clap(long, short = 'c')] - pub contracts: Vec, + #[clap(long, help = MSG_BUILD_L1_CONTRACTS_HELP, default_missing_value = "true", num_args = 0..=1)] + pub l1_contracts: Option, + #[clap(long, help = MSG_BUILD_L2_CONTRACTS_HELP, default_missing_value = "true", num_args = 0..=1)] + pub l2_contracts: Option, + #[clap(long, help = MSG_BUILD_SYSTEM_CONTRACTS_HELP, default_missing_value = "true", num_args = 0..=1)] + pub system_contracts: Option, +} + +impl ContractsArgs { + fn contracts(&self) -> Vec { + if self.l1_contracts.is_none() + && self.l2_contracts.is_none() + && self.system_contracts.is_none() + { + return vec![ + ContractType::L1, + ContractType::L2, + ContractType::SystemContracts, + ]; + } + + let mut contracts = vec![]; + + if self.l1_contracts.unwrap_or(false) { + contracts.push(ContractType::L1); + } + if self.l2_contracts.unwrap_or(false) { + contracts.push(ContractType::L2); + } + if self.system_contracts.unwrap_or(false) { + contracts.push(ContractType::SystemContracts); + } + + contracts + } } #[derive(Debug, ValueEnum, EnumIter, strum::Display, PartialEq, Eq, Clone, Copy)] @@ -74,21 +108,17 @@ impl ContractBuilder { } pub fn run(shell: &Shell, args: ContractsArgs) -> anyhow::Result<()> { + let contracts = args.contracts(); + if contracts.is_empty() { + logger::outro(MSG_NOTHING_TO_BUILD_MSG); + return Ok(()); + } + logger::info(MSG_BUILDING_CONTRACTS); let ecosystem = EcosystemConfig::from_file(shell)?; let link_to_code = ecosystem.link_to_code.clone(); - let contracts = if args.contracts.is_empty() { - vec![ - ContractType::L1, - ContractType::L2, - ContractType::SystemContracts, - ] - } else { - args.contracts.clone() - }; - let spinner = Spinner::new(MSG_CONTRACTS_DEPS_SPINNER); let _dir_guard = shell.push_dir(&link_to_code); Cmd::new(cmd!(shell, "yarn install")).run()?; diff --git a/zk_toolbox/crates/zk_supervisor/src/messages.rs b/zk_toolbox/crates/zk_supervisor/src/messages.rs index 8587bcdb1801..17f01e664678 100644 --- a/zk_toolbox/crates/zk_supervisor/src/messages.rs +++ b/zk_toolbox/crates/zk_supervisor/src/messages.rs @@ -106,12 +106,16 @@ pub(super) const MSG_POSTGRES_CONFIG_NOT_FOUND_ERR: &str = "Postgres config not pub(super) const MSG_RESETTING_TEST_DATABASES: &str = "Resetting test databases"; // Contract building related messages +pub(super) const MSG_NOTHING_TO_BUILD_MSG: &str = "Nothing to build!"; pub(super) const MSG_BUILDING_CONTRACTS: &str = "Building contracts"; pub(super) const MSG_CONTRACTS_DEPS_SPINNER: &str = "Installing dependencies.."; pub(super) const MSG_BUILDING_L2_CONTRACTS_SPINNER: &str = "Building L2 contracts.."; pub(super) const MSG_BUILDING_L1_CONTRACTS_SPINNER: &str = "Building L1 contracts.."; pub(super) const MSG_BUILDING_SYSTEM_CONTRACTS_SPINNER: &str = "Building system contracts.."; pub(super) const MSG_BUILDING_CONTRACTS_SUCCESS: &str = "Contracts built successfully"; +pub(super) const MSG_BUILD_L1_CONTRACTS_HELP: &str = "Build L1 contracts"; +pub(super) const MSG_BUILD_L2_CONTRACTS_HELP: &str = "Build L2 contracts"; +pub(super) const MSG_BUILD_SYSTEM_CONTRACTS_HELP: &str = "Build system contracts"; // Integration tests related messages pub(super) fn msg_integration_tests_run(external_node: bool) -> String { From 34c1f94099b44de707b1986ff0cb83b254384148 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Tue, 3 Sep 2024 12:07:33 -0300 Subject: [PATCH 29/33] Add alias --- zk_toolbox/crates/zk_supervisor/src/commands/contracts.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/contracts.rs b/zk_toolbox/crates/zk_supervisor/src/commands/contracts.rs index de6a3600e3b8..0c635b2b0d34 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/contracts.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/contracts.rs @@ -15,11 +15,11 @@ use crate::messages::{ #[derive(Debug, Parser)] pub struct ContractsArgs { - #[clap(long, help = MSG_BUILD_L1_CONTRACTS_HELP, default_missing_value = "true", num_args = 0..=1)] + #[clap(long, alias = "l1", help = MSG_BUILD_L1_CONTRACTS_HELP, default_missing_value = "true", num_args = 0..=1)] pub l1_contracts: Option, - #[clap(long, help = MSG_BUILD_L2_CONTRACTS_HELP, default_missing_value = "true", num_args = 0..=1)] + #[clap(long, alias = "l2", help = MSG_BUILD_L2_CONTRACTS_HELP, default_missing_value = "true", num_args = 0..=1)] pub l2_contracts: Option, - #[clap(long, help = MSG_BUILD_SYSTEM_CONTRACTS_HELP, default_missing_value = "true", num_args = 0..=1)] + #[clap(long, alias = "sc", help = MSG_BUILD_SYSTEM_CONTRACTS_HELP, default_missing_value = "true", num_args = 0..=1)] pub system_contracts: Option, } From f8f11016162be481ddc4e665db179114b97ea9eb Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Tue, 3 Sep 2024 12:37:19 -0300 Subject: [PATCH 30/33] Integrate zks contracts --- .github/workflows/ci-core-reusable.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-core-reusable.yml b/.github/workflows/ci-core-reusable.yml index 13837a4ce939..28bf7012dc85 100644 --- a/.github/workflows/ci-core-reusable.yml +++ b/.github/workflows/ci-core-reusable.yml @@ -53,9 +53,11 @@ jobs: - name: Init run: | ci_run run_retried rustup show - ci_run yarn l1-contracts build - ci_run yarn l2-contracts build ci_run ./bin/zkt + ci_run zks contracts + + - name: Contracts unit tests + run: ci_run yarn l1-contracts test - name: Rust unit tests run: | From bb07b1d7cef480142e5a2a1ad2799a0b5c866b89 Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Tue, 3 Sep 2024 12:47:20 -0300 Subject: [PATCH 31/33] Use full command --- .github/workflows/ci-core-reusable.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-core-reusable.yml b/.github/workflows/ci-core-reusable.yml index 28bf7012dc85..c6e3dc31d65e 100644 --- a/.github/workflows/ci-core-reusable.yml +++ b/.github/workflows/ci-core-reusable.yml @@ -54,7 +54,7 @@ jobs: run: | ci_run run_retried rustup show ci_run ./bin/zkt - ci_run zks contracts + ci_run zk_supervisor contracts - name: Contracts unit tests run: ci_run yarn l1-contracts test From e78130d69945a206c6af98ff822d0f93b79e43ff Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Tue, 3 Sep 2024 13:37:07 -0300 Subject: [PATCH 32/33] Add zks contracts --test --- .github/workflows/ci-core-reusable.yml | 2 +- infrastructure/zk/src/prover_setup.ts | 6 +++-- .../zk_supervisor/src/commands/contracts.rs | 24 ++++++++++++++----- .../crates/zk_supervisor/src/messages.rs | 2 ++ 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci-core-reusable.yml b/.github/workflows/ci-core-reusable.yml index c6e3dc31d65e..30b87b2e1a72 100644 --- a/.github/workflows/ci-core-reusable.yml +++ b/.github/workflows/ci-core-reusable.yml @@ -54,7 +54,7 @@ jobs: run: | ci_run run_retried rustup show ci_run ./bin/zkt - ci_run zk_supervisor contracts + ci_run zk_supervisor contracts --l1 --test - name: Contracts unit tests run: ci_run yarn l1-contracts test diff --git a/infrastructure/zk/src/prover_setup.ts b/infrastructure/zk/src/prover_setup.ts index b5bd4c828aec..0ef3515cc750 100644 --- a/infrastructure/zk/src/prover_setup.ts +++ b/infrastructure/zk/src/prover_setup.ts @@ -30,7 +30,8 @@ export async function setupProver(proverType: ProverType) { } else { env.modify( 'FRI_PROVER_SETUP_DATA_PATH', - `${process.env.ZKSYNC_HOME}/etc/hyperchains/prover-keys/${process.env.ZKSYNC_ENV}/${proverType === ProverType.GPU ? 'gpu' : 'cpu' + `${process.env.ZKSYNC_HOME}/etc/hyperchains/prover-keys/${process.env.ZKSYNC_ENV}/${ + proverType === ProverType.GPU ? 'gpu' : 'cpu' }/`, process.env.ENV_FILE! ); @@ -97,7 +98,8 @@ async function setupProverKeys(proverType: ProverType) { env.modify( 'FRI_PROVER_SETUP_DATA_PATH', - `${process.env.ZKSYNC_HOME}/etc/hyperchains/prover-keys/${process.env.ZKSYNC_ENV}/${proverType === ProverType.GPU ? 'gpu' : 'cpu' + `${process.env.ZKSYNC_HOME}/etc/hyperchains/prover-keys/${process.env.ZKSYNC_ENV}/${ + proverType === ProverType.GPU ? 'gpu' : 'cpu' }/`, process.env.ENV_FILE! ); diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/contracts.rs b/zk_toolbox/crates/zk_supervisor/src/commands/contracts.rs index 0c635b2b0d34..bab4205cd66f 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/contracts.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/contracts.rs @@ -1,16 +1,16 @@ use std::path::PathBuf; -use clap::{Parser, ValueEnum}; +use clap::Parser; use common::{cmd::Cmd, logger, spinner::Spinner}; use config::EcosystemConfig; -use strum::EnumIter; use xshell::{cmd, Shell}; use crate::messages::{ MSG_BUILDING_CONTRACTS, MSG_BUILDING_CONTRACTS_SUCCESS, MSG_BUILDING_L1_CONTRACTS_SPINNER, MSG_BUILDING_L2_CONTRACTS_SPINNER, MSG_BUILDING_SYSTEM_CONTRACTS_SPINNER, - MSG_BUILD_L1_CONTRACTS_HELP, MSG_BUILD_L2_CONTRACTS_HELP, MSG_BUILD_SYSTEM_CONTRACTS_HELP, - MSG_CONTRACTS_DEPS_SPINNER, MSG_NOTHING_TO_BUILD_MSG, + MSG_BUILDING_TEST_CONTRACTS_SPINNER, MSG_BUILD_L1_CONTRACTS_HELP, MSG_BUILD_L2_CONTRACTS_HELP, + MSG_BUILD_SYSTEM_CONTRACTS_HELP, MSG_BUILD_TEST_CONTRACTS_HELP, MSG_CONTRACTS_DEPS_SPINNER, + MSG_NOTHING_TO_BUILD_MSG, }; #[derive(Debug, Parser)] @@ -21,6 +21,8 @@ pub struct ContractsArgs { pub l2_contracts: Option, #[clap(long, alias = "sc", help = MSG_BUILD_SYSTEM_CONTRACTS_HELP, default_missing_value = "true", num_args = 0..=1)] pub system_contracts: Option, + #[clap(long, alias = "test", help = MSG_BUILD_TEST_CONTRACTS_HELP, default_missing_value = "true", num_args = 0..=1)] + pub test_contracts: Option, } impl ContractsArgs { @@ -28,11 +30,13 @@ impl ContractsArgs { if self.l1_contracts.is_none() && self.l2_contracts.is_none() && self.system_contracts.is_none() + && self.test_contracts.is_none() { return vec![ ContractType::L1, ContractType::L2, ContractType::SystemContracts, + ContractType::TestContracts, ]; } @@ -47,17 +51,20 @@ impl ContractsArgs { if self.system_contracts.unwrap_or(false) { contracts.push(ContractType::SystemContracts); } + if self.test_contracts.unwrap_or(false) { + contracts.push(ContractType::TestContracts); + } contracts } } -#[derive(Debug, ValueEnum, EnumIter, strum::Display, PartialEq, Eq, Clone, Copy)] -#[strum(serialize_all = "lowercase")] +#[derive(Debug, PartialEq, Eq, Clone, Copy)] pub enum ContractType { L1, L2, SystemContracts, + TestContracts, } #[derive(Debug)] @@ -85,6 +92,11 @@ impl ContractBuilder { cmd: "yarn sc build".to_string(), msg: MSG_BUILDING_SYSTEM_CONTRACTS_SPINNER.to_string(), }, + ContractType::TestContracts => Self { + dir: ecosystem.link_to_code.join("etc/contracts-test-data"), + cmd: "yarn build".to_string(), + msg: MSG_BUILDING_TEST_CONTRACTS_SPINNER.to_string(), + }, } } diff --git a/zk_toolbox/crates/zk_supervisor/src/messages.rs b/zk_toolbox/crates/zk_supervisor/src/messages.rs index 17f01e664678..ff9cc104a505 100644 --- a/zk_toolbox/crates/zk_supervisor/src/messages.rs +++ b/zk_toolbox/crates/zk_supervisor/src/messages.rs @@ -112,10 +112,12 @@ pub(super) const MSG_CONTRACTS_DEPS_SPINNER: &str = "Installing dependencies.."; pub(super) const MSG_BUILDING_L2_CONTRACTS_SPINNER: &str = "Building L2 contracts.."; pub(super) const MSG_BUILDING_L1_CONTRACTS_SPINNER: &str = "Building L1 contracts.."; pub(super) const MSG_BUILDING_SYSTEM_CONTRACTS_SPINNER: &str = "Building system contracts.."; +pub(super) const MSG_BUILDING_TEST_CONTRACTS_SPINNER: &str = "Building test contracts.."; pub(super) const MSG_BUILDING_CONTRACTS_SUCCESS: &str = "Contracts built successfully"; pub(super) const MSG_BUILD_L1_CONTRACTS_HELP: &str = "Build L1 contracts"; pub(super) const MSG_BUILD_L2_CONTRACTS_HELP: &str = "Build L2 contracts"; pub(super) const MSG_BUILD_SYSTEM_CONTRACTS_HELP: &str = "Build system contracts"; +pub(super) const MSG_BUILD_TEST_CONTRACTS_HELP: &str = "Build test contracts"; // Integration tests related messages pub(super) fn msg_integration_tests_run(external_node: bool) -> String { From 17ca5c06cc3ed918e46adadc3c1b2ffb3dac97fe Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Tue, 3 Sep 2024 13:56:31 -0300 Subject: [PATCH 33/33] Compile all contracts --- .github/workflows/ci-core-reusable.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-core-reusable.yml b/.github/workflows/ci-core-reusable.yml index 30b87b2e1a72..c6e3dc31d65e 100644 --- a/.github/workflows/ci-core-reusable.yml +++ b/.github/workflows/ci-core-reusable.yml @@ -54,7 +54,7 @@ jobs: run: | ci_run run_retried rustup show ci_run ./bin/zkt - ci_run zk_supervisor contracts --l1 --test + ci_run zk_supervisor contracts - name: Contracts unit tests run: ci_run yarn l1-contracts test