Skip to content

Commit 69ea9d5

Browse files
feat(apollo_starknet_os_program): add test contracts, add dumper in CLI
1 parent 32cb04d commit 69ea9d5

File tree

7 files changed

+25
-1
lines changed

7 files changed

+25
-1
lines changed

crates/apollo_starknet_os_program/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ description = "The source (Cairo) code of the Starknet OS."
99
[lints]
1010
workspace = true
1111

12+
[features]
13+
test_programs = []
14+
1215
[dependencies]
1316
apollo_infra_utils.workspace = true
1417
cairo-vm.workspace = true

crates/apollo_starknet_os_program/build.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ async fn main() {
1010
let out_dir = PathBuf::from(std::env::var("OUT_DIR").expect("OUT_DIR not set."));
1111

1212
let mut task_set = tokio::task::JoinSet::new();
13+
#[cfg(feature = "test_programs")]
14+
task_set.spawn(compile_test_contracts(out_dir.clone()));
1315
task_set.spawn(compile_and_output_program(
1416
out_dir.clone(),
1517
"starkware/starknet/core/os/os.cairo",
@@ -55,6 +57,17 @@ async fn compile_and_output_program(
5557
});
5658
}
5759

60+
#[cfg(feature = "test_programs")]
61+
async fn compile_test_contracts(out_dir: PathBuf) {
62+
let mut task_set = tokio::task::JoinSet::new();
63+
task_set.spawn(compile_and_output_program(
64+
out_dir,
65+
"starkware/starknet/core/os/state/aliases_test.cairo",
66+
"aliases_test",
67+
));
68+
task_set.join_all().await;
69+
}
70+
5871
fn cairo_root_path() -> PathBuf {
5972
PathBuf::from(compile_time_cargo_manifest_dir!()).join("src/cairo")
6073
}

crates/apollo_starknet_os_program/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use cairo_vm::types::program::Program;
66
use crate::program_hash::{ProgramHash, PROGRAM_HASH_PATH};
77

88
pub mod program_hash;
9+
#[cfg(feature = "test_programs")]
10+
pub mod test_programs;
911

1012
pub const OS_PROGRAM_BYTES: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/starknet_os_bytes"));
1113
pub const AGGREGATOR_PROGRAM_BYTES: &[u8] =
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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ tempfile.workspace = true
1818

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

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::{AGGREGATOR_PROGRAM_BYTES, OS_PROGRAM_BYTES, PROGRAM_HASH};
56
use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass;
67
use cairo_vm::types::layout_name::LayoutName;
@@ -105,6 +106,7 @@ pub(crate) fn serialize_os_runner_output(
105106
pub(crate) fn dump_program(output_path: String, program: ProgramToDump) {
106107
let bytes = match program {
107108
ProgramToDump::Aggregator => AGGREGATOR_PROGRAM_BYTES,
109+
ProgramToDump::AliasesTest => ALIASES_TEST_BYTES,
108110
ProgramToDump::Os => OS_PROGRAM_BYTES,
109111
};
110112
// 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
@@ -20,6 +20,7 @@ pub struct OsCliCommand {
2020
#[serde(rename_all = "kebab-case")]
2121
pub enum ProgramToDump {
2222
Aggregator,
23+
AliasesTest,
2324
Os,
2425
}
2526

0 commit comments

Comments
 (0)