From 6bfb49951eedd0293b39cfab758c0378967b7448 Mon Sep 17 00:00:00 2001 From: aon <21188659+aon@users.noreply.github.com> Date: Fri, 31 May 2024 16:08:04 -0300 Subject: [PATCH] feat: add integration test ci for zk_toolbox --- .github/workflows/ci-zk-toolbox-reusable.yml | 81 +++++++++++++++++++ .github/workflows/ci.yml | 11 +++ core/tests/ts-integration/src/env.ts | 6 +- zk_toolbox/.gitignore | 1 + .../forge_interface/deploy_ecosystem/input.rs | 7 ++ .../src/commands/integration_tests.rs | 25 ++++++ .../crates/zk_supervisor/src/commands/mod.rs | 1 + zk_toolbox/crates/zk_supervisor/src/main.rs | 11 ++- .../crates/zk_supervisor/src/messages.rs | 9 +++ 9 files changed, 148 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/ci-zk-toolbox-reusable.yml create mode 100644 zk_toolbox/.gitignore create mode 100644 zk_toolbox/crates/zk_supervisor/src/commands/integration_tests.rs diff --git a/.github/workflows/ci-zk-toolbox-reusable.yml b/.github/workflows/ci-zk-toolbox-reusable.yml new file mode 100644 index 000000000000..3afa7eede4fa --- /dev/null +++ b/.github/workflows/ci-zk-toolbox-reusable.yml @@ -0,0 +1,81 @@ +name: Workflow template for CI jobs for Core Components +on: + workflow_call: + +jobs: + lint: + name: lint + uses: ./.github/workflows/ci-core-lint-reusable.yml + + build: + runs-on: [matterlabs-ci-runner] + + steps: + - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4 + with: + submodules: "recursive" + fetch-depth: 0 + + - name: Setup environment + run: | + echo ZKSYNC_HOME=$(pwd) >> $GITHUB_ENV + echo $(pwd)/bin >> $GITHUB_PATH + echo IN_DOCKER=1 >> .env + + - name: Start services + run: | + ci_localnet_up + + - name: Build + run: | + ci_run bash -c "cd zk_toolbox && cargo build --release" + + # Compress with tar to avoid permission loss + # https://github.com/actions/upload-artifact?tab=readme-ov-file#permission-loss + - name: Tar zk_toolbox binaries + run: | + tar -C ./zk_toolbox/target/release -cvf zk_toolbox.tar zk_inception zk_supervisor + + - name: Upload zk_toolbox binaries + uses: actions/upload-artifact@v4 + with: + name: zk_toolbox + path: zk_toolbox.tar + compression-level: 0 + + integration_test: + runs-on: [matterlabs-ci-runner] + needs: [build] + + steps: + - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4 + with: + submodules: "recursive" + fetch-depth: 0 + + - name: Download zk_toolbox binaries + uses: actions/download-artifact@v4 + with: + name: zk_toolbox + path: . + + - name: Extract zk_toolbox binaries + run: | + tar -xvf zk_toolbox.tar -C ./bin + + - name: Setup environment + run: | + echo ZKSYNC_HOME=$(pwd) >> $GITHUB_ENV + echo $(pwd)/bin >> $GITHUB_PATH + echo IN_DOCKER=1 >> .env + + - name: Run tests + run: | + ci_run zk_inception ecosystem init --deploy-paymaster --deploy-erc20 \ + --deploy-ecosystem --l1-rpc-url=http://localhost:8545 \ + --server-db-url=postgres://postgres:notsecurepassword@localhost:5432 \ + --server-db-name=zksync_server_localhost_era \ + --prover-db-url=postgres://postgres:notsecurepassword@localhost:5432 \ + --prover-db-name=zksync_prover_localhost_era + ci_run zk_inception server & + ci_run zk_supervisor integration-tests diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 21e3104a5dcd..31b388b4cfa1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,6 +20,7 @@ jobs: outputs: core: ${{ steps.changed-files.outputs.core_any_changed }} prover: ${{ steps.changed-files.outputs.prover_any_changed }} + zk_toolbox: ${{ steps.changed-files.outputs.zk_toolbox_any_changed }} docs: ${{ steps.changed-files.outputs.docs_any_changed }} all: ${{ steps.changed-files.outputs.all_any_changed }} steps: @@ -60,6 +61,10 @@ jobs: - '!**/*.md' - '!**/*.MD' - 'docker-compose.yml' + zk_toolbox: + - 'zk_toolbox/**' + - '!**/*.md' + - '!**/*.MD' docs: - '**/*.md' - '**/*.MD' @@ -91,6 +96,12 @@ jobs: name: CI for Prover Components uses: ./.github/workflows/ci-prover-reusable.yml + ci-for-zk-toolbox: + needs: changed_files + if: ${{ (needs.changed_files.outputs.zk_toolbox == 'true' || needs.changed_files.outputs.all == 'true') && !contains(github.ref_name, 'release-please--branches') }} + name: CI for zk_toolbox + uses: ./.github/workflows/ci-zk-toolbox-reusable.yml + ci-for-docs: needs: changed_files if: needs.changed_files.outputs.docs == 'true' diff --git a/core/tests/ts-integration/src/env.ts b/core/tests/ts-integration/src/env.ts index ada8a695e0aa..60175d621da9 100644 --- a/core/tests/ts-integration/src/env.ts +++ b/core/tests/ts-integration/src/env.ts @@ -80,9 +80,12 @@ async function loadTestEnvironmentFromFile(chain: string): Promise anyhow::Result<()> { + let ecosystem_config = EcosystemConfig::from_file(shell)?; + let _dir_guard = shell.push_dir(ecosystem_config.link_to_code.join(TS_INTEGRATION_PATH)); + + logger::info(MSG_INTEGRATION_TESTS_RUN_INFO); + + Cmd::new( + cmd!(shell, "yarn jest --forceExit --testTimeout 60000") + .env("CHAIN_NAME", ecosystem_config.default_chain), + ) + .with_force_run() + .run()?; + + logger::outro(MSG_INTEGRATION_TESTS_RUN_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 8fd0a6be869b..98d4cdfe990d 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/mod.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/mod.rs @@ -1 +1,2 @@ pub mod database; +pub mod integration_tests; diff --git a/zk_toolbox/crates/zk_supervisor/src/main.rs b/zk_toolbox/crates/zk_supervisor/src/main.rs index 24daaba35347..ab5629465a88 100644 --- a/zk_toolbox/crates/zk_supervisor/src/main.rs +++ b/zk_toolbox/crates/zk_supervisor/src/main.rs @@ -6,7 +6,10 @@ use common::{ init_prompt_theme, logger, }; use config::EcosystemConfig; -use messages::msg_global_chain_does_not_exist; +use messages::{ + msg_global_chain_does_not_exist, MSG_SUBCOMMAND_DATABASE_ABOUT, + MSG_SUBCOMMAND_INTEGRATION_TESTS_ABOUT, +}; use xshell::Shell; mod commands; @@ -24,9 +27,10 @@ struct Supervisor { #[derive(Subcommand, Debug)] enum SupervisorSubcommands { - /// Database related commands - #[command(subcommand)] + #[command(subcommand, about = MSG_SUBCOMMAND_DATABASE_ABOUT)] Database(DatabaseCommands), + #[command(about = MSG_SUBCOMMAND_INTEGRATION_TESTS_ABOUT)] + IntegrationTests, } #[derive(Parser, Debug)] @@ -89,6 +93,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::IntegrationTests => commands::integration_tests::run(shell)?, } Ok(()) } diff --git a/zk_toolbox/crates/zk_supervisor/src/messages.rs b/zk_toolbox/crates/zk_supervisor/src/messages.rs index 97152396b5e5..fa3c1ae19206 100644 --- a/zk_toolbox/crates/zk_supervisor/src/messages.rs +++ b/zk_toolbox/crates/zk_supervisor/src/messages.rs @@ -4,6 +4,10 @@ pub(super) fn msg_global_chain_does_not_exist(chain: &str, available_chains: &st format!("Chain with name {chain} doesnt exist, please choose one of: {available_chains}") } +// Subcommands help +pub(super) const MSG_SUBCOMMAND_DATABASE_ABOUT: &str = "Database related commands"; +pub(super) const MSG_SUBCOMMAND_INTEGRATION_TESTS_ABOUT: &str = "Run integration tests"; + // Database related messages pub(super) const MSG_NO_DATABASES_SELECTED: &str = "No databases selected"; pub(super) fn msg_database_info(gerund_verb: &str) -> String { @@ -57,3 +61,8 @@ pub(super) fn msg_database_new_migration_loading(dal: &str) -> String { format!("Creating new database migration for dal {}...", dal) } pub(super) const MSG_DATABASE_NEW_MIGRATION_SUCCESS: &str = "Migration created successfully"; + +// Integration tests related messages +pub(super) const MSG_INTEGRATION_TESTS_RUN_ABOUT: &str = "Run integration tests"; +pub(super) const MSG_INTEGRATION_TESTS_RUN_INFO: &str = "Running integration tests"; +pub(super) const MSG_INTEGRATION_TESTS_RUN_SUCCESS: &str = "Integration tests ran successfully";