Skip to content

Commit 4dc424d

Browse files
feat(apollo_starknet_os_program): add test contracts, add dumper in CLI (#5946)
1 parent 781af83 commit 4dc424d

File tree

8 files changed

+24
-2
lines changed

8 files changed

+24
-2
lines changed

crates/apollo_starknet_os_program/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ build = "build/main.rs"
99

1010
[features]
1111
dump_source_files = []
12+
test_programs = []
1213

1314
[lints]
1415
workspace = true

crates/apollo_starknet_os_program/build/compile_program.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ pub async fn compile_and_output_program(
3535
});
3636
}
3737

38+
#[cfg(feature = "test_programs")]
39+
pub async fn compile_test_contracts(out_dir: PathBuf) {
40+
let mut task_set = tokio::task::JoinSet::new();
41+
task_set.spawn(compile_and_output_program(
42+
out_dir,
43+
"starkware/starknet/core/os/state/aliases_test.cairo",
44+
"aliases_test",
45+
));
46+
task_set.join_all().await;
47+
}
48+
3849
fn cairo_root_path() -> PathBuf {
3950
PathBuf::from(compile_time_cargo_manifest_dir!()).join("src/cairo")
4051
}

crates/apollo_starknet_os_program/build/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ async fn main() {
1515
dump_source::dump_source_files(&out_dir.join("cairo_files_map.json"));
1616

1717
let mut task_set = tokio::task::JoinSet::new();
18+
#[cfg(feature = "test_programs")]
19+
task_set.spawn(compile_program::compile_test_contracts(out_dir.clone()));
1820
task_set.spawn(compile_program::compile_and_output_program(
1921
out_dir.clone(),
2022
"starkware/starknet/core/os/os.cairo",

crates/apollo_starknet_os_program/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use crate::program_hash::ProgramHashes;
99
#[cfg(test)]
1010
mod constants_test;
1111
pub mod program_hash;
12+
#[cfg(feature = "test_programs")]
13+
pub mod test_programs;
1214

1315
#[cfg(feature = "dump_source_files")]
1416
pub static CAIRO_FILES_MAP: LazyLock<HashMap<String, String>> = LazyLock::new(|| {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub const ALIASES_TEST_BYTES: &[u8] =
2+
include_bytes!(concat!(env!("OUT_DIR"), "/aliases_test_bytes"));

crates/starknet_committer_and_os_cli/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ tempfile.workspace = true
1818

1919
# TODO(Amos): Add `testing` feature and move Python test dependencies under it.
2020
[dependencies]
21-
# The 'dump_source_files' feature should be moved under `testing` feature, when it exists.
22-
apollo_starknet_os_program = { workspace = true, features = ["dump_source_files"] }
21+
# The 'dump_source_files' and 'test_programs' features should be moved under `testing` feature, when
22+
# it exists.
23+
apollo_starknet_os_program = { workspace = true, features = ["dump_source_files", "test_programs"] }
2324
blake2s.workspace = true
2425
cairo-lang-starknet-classes.workspace = true
2526
cairo-vm = { workspace = true, features = [

crates/starknet_committer_and_os_cli/src/os_cli/commands.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::fs;
22
use std::path::Path;
33

4+
use apollo_starknet_os_program::test_programs::ALIASES_TEST_BYTES;
45
use apollo_starknet_os_program::{
56
AGGREGATOR_PROGRAM_BYTES,
67
CAIRO_FILES_MAP,
@@ -115,6 +116,7 @@ pub(crate) fn dump_source_files(output_path: String) {
115116
pub(crate) fn dump_program(output_path: String, program: ProgramToDump) {
116117
let bytes = match program {
117118
ProgramToDump::Aggregator => AGGREGATOR_PROGRAM_BYTES,
119+
ProgramToDump::AliasesTest => ALIASES_TEST_BYTES,
118120
ProgramToDump::Os => OS_PROGRAM_BYTES,
119121
};
120122
// Dumping the `Program` struct won't work - it is not deserializable via cairo-lang's Program

crates/starknet_committer_and_os_cli/src/os_cli/run_os_cli.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub struct OsCliCommand {
2828
#[serde(rename_all = "kebab-case")]
2929
pub enum ProgramToDump {
3030
Aggregator,
31+
AliasesTest,
3132
Os,
3233
}
3334

0 commit comments

Comments
 (0)