Skip to content

Commit

Permalink
Fix scarb execute outputs (#1918)
Browse files Browse the repository at this point in the history
Update config to prepare trace and memory files for standard output

- Fixes empty memory output for bootloader target
- Don't generate trace for cairo-pie output
  • Loading branch information
DelevoXDG authored Jan 27, 2025
1 parent 9c9625a commit 18f1ca1
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 10 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions extensions/scarb-execute/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ enum OutputFormat {
Standard,
}
impl OutputFormat {
pub fn is_standard(&self) -> bool {
matches!(self, OutputFormat::Standard)
}
pub fn is_cairo_pie(&self) -> bool {
matches!(self, OutputFormat::CairoPie)
}
Expand Down Expand Up @@ -218,9 +221,9 @@ fn main_inner(args: Args, ui: Ui) -> Result<(), anyhow::Error> {
allow_missing_builtins: Some(true),
layout: LayoutName::all_cairo,
proof_mode: args.run.target.is_standalone(),
relocate_mem: args.run.target.is_standalone(),
secure_run: None,
trace_enabled: true,
relocate_mem: args.run.output.is_standard(),
trace_enabled: args.run.output.is_standard(),
..Default::default()
};

Expand Down
45 changes: 37 additions & 8 deletions extensions/scarb-execute/tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use assert_fs::assert::PathAssert;
use assert_fs::fixture::PathChild;
use assert_fs::TempDir;
use indoc::indoc;
use predicates::prelude::*;
use scarb_test_support::command::Scarb;
use scarb_test_support::fsx::ChildPathEx;
use scarb_test_support::predicates::is_file_empty;
use scarb_test_support::project_builder::ProjectBuilder;
use snapbox::cmd::OutputAssert;

Expand Down Expand Up @@ -41,13 +44,13 @@ fn can_execute_default_main_function_from_executable() {
"#});

t.child("target/execute/hello/air_private_input.json")
.assert(predicates::path::exists());
.assert_is_json::<serde_json::Value>();
t.child("target/execute/hello/air_public_input.json")
.assert(predicates::path::exists());
.assert_is_json::<serde_json::Value>();
t.child("target/execute/hello/memory.bin")
.assert(predicates::path::exists());
.assert(predicates::path::exists().and(is_file_empty().not()));
t.child("target/execute/hello/trace.bin")
.assert(predicates::path::exists());
.assert(predicates::path::exists().and(is_file_empty().not()));
}

#[test]
Expand All @@ -66,13 +69,39 @@ fn can_execute_prebuilt_executable() {
"#});

t.child("target/execute/hello/air_private_input.json")
.assert(predicates::path::exists());
.assert_is_json::<serde_json::Value>();
t.child("target/execute/hello/air_public_input.json")
.assert(predicates::path::exists());
.assert_is_json::<serde_json::Value>();
t.child("target/execute/hello/memory.bin")
.assert(predicates::path::exists());
.assert(predicates::path::exists().and(is_file_empty().not()));
t.child("target/execute/hello/trace.bin")
.assert(predicates::path::exists());
.assert(predicates::path::exists().and(is_file_empty().not()));
}

#[test]
fn can_execute_bootloader_target() {
let t = build_executable_project();
Scarb::quick_snapbox()
.arg("execute")
.arg("--target=bootloader")
.current_dir(&t)
.assert()
.success()
.stdout_matches(indoc! {r#"
[..]Compiling hello v0.1.0 ([..]Scarb.toml)
[..]Finished `dev` profile target(s) in [..]
[..]Executing hello
Saving output to: target/execute/hello
"#});

t.child("target/execute/hello/air_private_input.json")
.assert_is_json::<serde_json::Value>();
t.child("target/execute/hello/air_public_input.json")
.assert_is_json::<serde_json::Value>();
t.child("target/execute/hello/memory.bin")
.assert(predicates::path::exists().and(is_file_empty().not()));
t.child("target/execute/hello/trace.bin")
.assert(predicates::path::exists().and(is_file_empty().not()));
}

#[test]
Expand Down
2 changes: 2 additions & 0 deletions utils/scarb-test-support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ tokio.workspace = true
toml_edit.workspace = true
tower-http.workspace = true
url.workspace = true
predicates.workspace = true

1 change: 1 addition & 0 deletions utils/scarb-test-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod filesystem;
pub mod fsx;
pub mod gitx;
pub mod manifest_edit;
pub mod predicates;
pub mod proc_macro_server;
pub mod project_builder;
pub mod registry;
Expand Down
8 changes: 8 additions & 0 deletions utils/scarb-test-support/src/predicates.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use predicates::function::function;
use predicates::Predicate;
use std::fs;
use std::path::Path;

pub fn is_file_empty() -> impl Predicate<Path> {
function(|path| fs::metadata(path).map(|m| m.len() == 0).unwrap_or(true))
}

0 comments on commit 18f1ca1

Please sign in to comment.