From 1dc6023ae260e710d71a066a2f0c52309996ae52 Mon Sep 17 00:00:00 2001 From: Alexander Golovanov Date: Thu, 12 Dec 2024 02:15:49 +0100 Subject: [PATCH] Change the test so that it's now not a workflow --- .github/workflows/cli-e2e.yml | 58 ------------------- crates/cargo-axiom/src/lib.rs | 3 + crates/cargo-axiom/src/tests.rs | 99 +++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+), 58 deletions(-) delete mode 100644 .github/workflows/cli-e2e.yml create mode 100644 crates/cargo-axiom/src/tests.rs diff --git a/.github/workflows/cli-e2e.yml b/.github/workflows/cli-e2e.yml deleted file mode 100644 index 8f45db8fe8..0000000000 --- a/.github/workflows/cli-e2e.yml +++ /dev/null @@ -1,58 +0,0 @@ -name: CLI e2e test - -on: - push: - branches: ["main"] - pull_request: - branches: ["**"] - paths: - - "crates/stark-backend/**" - - "crates/circuits/primitives/**" - - "crates/vm/**" - - "crates/cargo-axiom/**" - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} - cancel-in-progress: true - -env: - CARGO_TERM_COLOR: always - AXIOM_FAST_TEST: "1" - -jobs: - tests: - runs-on: - - runs-on=${{ github.run_id }} - - runner=32cpu-linux-arm64 - - steps: - - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@nightly - - uses: Swatinem/rust-cache@v2 - with: - cache-on-failure: true - - uses: taiki-e/install-action@nextest - - - name: Install cargo-axiom - working-directory: crates/cargo-axiom - run: | - rustup component add rust-src --toolchain nightly-2024-10-30-aarch64-unknown-linux-gnu - cargo install --force --locked --path . - - - name: E2E CLI test - working-directory: crates/cargo-axiom - run: | - if [[ "${{ github.event_name }}" == "push" ]]; then - RUN_E2E=true - fi - if [[ "${{ github.event_name }}" == "pull_request" ]]; then - LABELS='${{ toJson(github.event.pull_request.labels) }}' - RUN_E2E=$(echo "$LABELS" | jq 'any(.name == "run-cli-e2e")') - fi - if [ ! -z $RUN_E2E ]; then - cargo axiom build --manifest-dir ../axvm-sdk/example --transpile --transpiler-config example/app_config.toml --transpile-to /tmp/example.axvmexe - cargo axiom keygen --config example/app_config.toml --output /tmp/example.pk --vk-output /tmp/example.vk - cargo axiom run --exe /tmp/example.axvmexe --config example/app_config.toml - cargo axiom prove app --app-pk /tmp/example.pk --exe /tmp/example.axvmexe --output /tmp/example.apppf - cargo axiom verify app --app-vk /tmp/example.vk --proof /tmp/example.apppf - fi diff --git a/crates/cargo-axiom/src/lib.rs b/crates/cargo-axiom/src/lib.rs index a4c5666ab6..a465ac3531 100644 --- a/crates/cargo-axiom/src/lib.rs +++ b/crates/cargo-axiom/src/lib.rs @@ -52,3 +52,6 @@ pub fn is_supported_target() -> bool { pub fn get_target() -> String { target_lexicon::HOST.to_string() } + +#[cfg(test)] +mod tests; diff --git a/crates/cargo-axiom/src/tests.rs b/crates/cargo-axiom/src/tests.rs new file mode 100644 index 0000000000..9f2dafeb70 --- /dev/null +++ b/crates/cargo-axiom/src/tests.rs @@ -0,0 +1,99 @@ +use std::{env, process::Command}; + +use eyre::Result; +use tempfile::tempdir; + +#[test] +fn test_cli_e2e() -> Result<()> { + let temp_dir = tempdir()?; + let package_dir = env::current_dir()?; + let prefix = "[test cli e2e]"; + let run_cmd = |program: &str, args: &[&str]| { + println!("{prefix} Running command: {} {} ...", program, args[0]); + let mut cmd = Command::new(program); + cmd.args(args); + cmd.current_dir(&package_dir); + let output = cmd.output().unwrap(); + println!("{prefix} Finished!"); + println!("{prefix} stdout:"); + println!("{}", std::str::from_utf8(&output.stdout).unwrap()); + println!("{prefix} stderr:"); + println!("{}", std::str::from_utf8(&output.stderr).unwrap()); + }; + run_cmd("cargo", &["install", "--path", ".", "--force"]); + let temp_exe = temp_dir.path().join("example.axvmexe"); + let temp_pk = temp_dir.path().join("example.pk"); + let temp_vk = temp_dir.path().join("example.vk"); + let temp_proof = temp_dir.path().join("example.apppf"); + + run_cmd( + "cargo", + &[ + "axiom", + "build", + "--manifest-dir", + "../axvm-sdk/example", + "--transpile", + "--transpiler-config", + "example/app_config.toml", + "--transpile-to", + temp_exe.to_str().unwrap(), + ], + ); + + run_cmd( + "cargo", + &[ + "axiom", + "keygen", + "--config", + "example/app_config.toml", + "--output", + temp_pk.to_str().unwrap(), + "--vk-output", + temp_vk.to_str().unwrap(), + ], + ); + + run_cmd( + "cargo", + &[ + "axiom", + "run", + "--exe", + temp_exe.to_str().unwrap(), + "--config", + "example/app_config.toml", + ], + ); + + run_cmd( + "cargo", + &[ + "axiom", + "prove", + "app", + "--app-pk", + temp_pk.to_str().unwrap(), + "--exe", + temp_exe.to_str().unwrap(), + "--output", + temp_proof.to_str().unwrap(), + ], + ); + + run_cmd( + "cargo", + &[ + "axiom", + "verify", + "app", + "--app-vk", + temp_vk.to_str().unwrap(), + "--proof", + temp_proof.to_str().unwrap(), + ], + ); + + Ok(()) +}