Skip to content

Commit 2a1f07c

Browse files
committed
Refactor universal-sierra-compiler-api
1 parent 403eb8e commit 2a1f07c

File tree

27 files changed

+291
-267
lines changed

27 files changed

+291
-267
lines changed

Cargo.lock

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cheatnet/src/forking/state.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use std::cell::{Ref, RefCell};
2828
use std::collections::HashMap;
2929
use std::io::Read;
3030
use std::sync::Arc;
31-
use universal_sierra_compiler_api::{SierraType, compile_sierra};
31+
use universal_sierra_compiler_api::compile_contract_sierra;
3232
use url::Url;
3333

3434
#[derive(Debug)]
@@ -239,13 +239,10 @@ impl StateReader for ForkStateReader {
239239
SierraVersion::extract_from_program(&flattened_class.sierra_program)
240240
.expect("Unable to extract Sierra version from Sierra program");
241241

242-
match compile_sierra::<String>(&sierra_contract_class, &SierraType::Contract) {
242+
match compile_contract_sierra(&sierra_contract_class) {
243243
Ok(casm_contract_class_raw) => Ok(RunnableCompiledClass::V1(
244-
CompiledClassV1::try_from_json_string(
245-
&casm_contract_class_raw,
246-
sierra_version,
247-
)
248-
.expect("Unable to create RunnableCompiledClass::V1"),
244+
CompiledClassV1::try_from((casm_contract_class_raw, sierra_version))
245+
.expect("Unable to create RunnableCompiledClass::V1"),
249246
)),
250247
Err(err) => Err(StateReadError(err.to_string())),
251248
}

crates/cheatnet/src/runtime_extensions/forge_runtime_extension/cheatcodes/declare.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,9 @@ pub fn get_class_hash(sierra_class: &SierraClass) -> Result<ClassHash> {
6868
}
6969

7070
fn get_contract_class(contract_artifact: &StarknetContractArtifacts) -> RunnableCompiledClass {
71-
let contract_class = CompiledClassV1::try_from_json_string(
72-
&contract_artifact.casm,
73-
get_current_sierra_version(),
74-
)
75-
.expect("Failed to read contract class from json");
71+
let contract_class =
72+
CompiledClassV1::try_from((contract_artifact.casm.clone(), get_current_sierra_version()))
73+
.expect("Failed to read contract class from json");
7674

7775
#[cfg(feature = "cairo-native")]
7876
return match &contract_artifact.executor {

crates/forge-runner/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use std::sync::{Arc, Mutex};
2222
use test_case_summary::{AnyTestCaseSummary, Fuzzing};
2323
use tokio::sync::mpsc::{Sender, channel};
2424
use tokio::task::JoinHandle;
25-
use universal_sierra_compiler_api::AssembledProgramWithDebugInfo;
25+
use universal_sierra_compiler_api::representation::RawCasmProgram;
2626

2727
pub mod build_trace_data;
2828
pub mod coverage_api;
@@ -106,7 +106,7 @@ pub fn maybe_generate_coverage(
106106
#[tracing::instrument(skip_all, level = "debug")]
107107
pub fn run_for_test_case(
108108
case: Arc<TestCaseWithResolvedConfig>,
109-
casm_program: Arc<AssembledProgramWithDebugInfo>,
109+
casm_program: Arc<RawCasmProgram>,
110110
forge_config: Arc<ForgeConfig>,
111111
versioned_program_path: Arc<Utf8PathBuf>,
112112
send: Sender<()>,
@@ -141,7 +141,7 @@ pub fn run_for_test_case(
141141
#[tracing::instrument(skip_all, level = "debug")]
142142
fn run_with_fuzzing(
143143
case: Arc<TestCaseWithResolvedConfig>,
144-
casm_program: Arc<AssembledProgramWithDebugInfo>,
144+
casm_program: Arc<RawCasmProgram>,
145145
forge_config: Arc<ForgeConfig>,
146146
versioned_program_path: Arc<Utf8PathBuf>,
147147
send: Sender<()>,

crates/forge-runner/src/package_tests.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use serde::Serialize;
1919
use starknet_types_core::felt::Felt;
2020
use std::collections::HashMap;
2121
use std::sync::Arc;
22-
use universal_sierra_compiler_api::AssembledProgramWithDebugInfo;
22+
use universal_sierra_compiler_api::representation::RawCasmProgram;
2323

2424
pub mod raw;
2525
pub mod with_config;
@@ -66,10 +66,7 @@ impl TestDetails {
6666
builtins
6767
}
6868

69-
pub fn try_into_program(
70-
&self,
71-
casm_program: &AssembledProgramWithDebugInfo,
72-
) -> Result<Program> {
69+
pub fn try_into_program(&self, casm_program: &RawCasmProgram) -> Result<Program> {
7370
let builtins = self.builtins();
7471

7572
let assembled_program = &casm_program.assembled_cairo_program;
@@ -102,7 +99,7 @@ pub struct TestTarget<C> {
10299
pub tests_location: TestTargetLocation,
103100
pub sierra_program: ProgramArtifact,
104101
pub sierra_program_path: Arc<Utf8PathBuf>,
105-
pub casm_program: Arc<AssembledProgramWithDebugInfo>,
102+
pub casm_program: Arc<RawCasmProgram>,
106103
pub test_cases: Vec<TestCase<C>>,
107104
}
108105

crates/forge-runner/src/package_tests/with_config_resolved.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use cheatnet::runtime_extensions::forge_config_extension::config::{
66
RawAvailableResourceBoundsConfig, RawFuzzerConfig,
77
};
88
use starknet_api::block::BlockNumber;
9-
use universal_sierra_compiler_api::AssembledProgramWithDebugInfo;
9+
use universal_sierra_compiler_api::representation::RawCasmProgram;
1010
use url::Url;
1111

1212
pub type TestTargetWithResolvedConfig = TestTarget<TestCaseResolvedConfig>;
@@ -29,10 +29,7 @@ impl TestCaseWithResolvedConfig {
2929
}
3030
}
3131

32-
pub fn try_into_program(
33-
&self,
34-
casm_program: &AssembledProgramWithDebugInfo,
35-
) -> Result<Program> {
32+
pub fn try_into_program(&self, casm_program: &RawCasmProgram) -> Result<Program> {
3633
self.test_details.try_into_program(casm_program)
3734
}
3835
}

crates/forge-runner/src/running.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use std::rc::Rc;
4343
use std::sync::{Arc, Mutex};
4444
use tokio::sync::mpsc::Sender;
4545
use tokio::task::JoinHandle;
46-
use universal_sierra_compiler_api::AssembledProgramWithDebugInfo;
46+
use universal_sierra_compiler_api::representation::RawCasmProgram;
4747

4848
pub mod config_run;
4949
mod execution;
@@ -62,7 +62,7 @@ pub use syscall_handler::syscall_handler_offset;
6262
#[tracing::instrument(skip_all, level = "debug")]
6363
pub fn run_test(
6464
case: Arc<TestCaseWithResolvedConfig>,
65-
casm_program: Arc<AssembledProgramWithDebugInfo>,
65+
casm_program: Arc<RawCasmProgram>,
6666
forge_config: Arc<ForgeConfig>,
6767
versioned_program_path: Arc<Utf8PathBuf>,
6868
send: Sender<()>,
@@ -93,7 +93,7 @@ pub fn run_test(
9393
#[tracing::instrument(skip_all, level = "debug")]
9494
pub(crate) fn run_fuzz_test(
9595
case: Arc<TestCaseWithResolvedConfig>,
96-
casm_program: Arc<AssembledProgramWithDebugInfo>,
96+
casm_program: Arc<RawCasmProgram>,
9797
forge_config: Arc<ForgeConfig>,
9898
versioned_program_path: Arc<Utf8PathBuf>,
9999
send: Sender<()>,
@@ -159,7 +159,7 @@ pub enum RunResult {
159159
#[tracing::instrument(skip_all, level = "debug")]
160160
pub fn run_test_case(
161161
case: &TestCaseWithResolvedConfig,
162-
casm_program: &AssembledProgramWithDebugInfo,
162+
casm_program: &RawCasmProgram,
163163
runtime_config: &RuntimeConfig,
164164
fuzzer_rng: Option<Arc<Mutex<StdRng>>>,
165165
versioned_program_path: &Utf8Path,

crates/forge-runner/src/running/config_run.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use starknet_api::block::{
1818
};
1919
use starknet_types_core::felt::Felt;
2020
use std::default::Default;
21-
use universal_sierra_compiler_api::AssembledProgramWithDebugInfo;
21+
use universal_sierra_compiler_api::representation::RawCasmProgram;
2222

2323
struct PhantomStateReader;
2424

@@ -61,7 +61,7 @@ impl StateReader for PhantomStateReader {
6161
#[tracing::instrument(skip_all, level = "debug")]
6262
pub fn run_config_pass(
6363
test_details: &TestDetails,
64-
casm_program: &AssembledProgramWithDebugInfo,
64+
casm_program: &RawCasmProgram,
6565
tracked_resource: &ForgeTrackedResource,
6666
) -> Result<RawForgeConfig> {
6767
let program = test_details.try_into_program(casm_program)?;

crates/forge-runner/src/running/hints.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use cairo_lang_casm::hints::Hint;
22
use cairo_vm::serde::deserialize_program::{ApTracking, FlowTrackingData, HintParams};
33
use std::collections::HashMap;
4-
use universal_sierra_compiler_api::AssembledCairoProgramWithSerde;
4+
use universal_sierra_compiler_api::representation::AssembledCairoProgramWithSerde;
55

66
pub fn hints_by_representation(
77
assembled_program: &AssembledCairoProgramWithSerde,

crates/forge-runner/src/running/setup.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use cairo_vm::vm::runners::cairo_runner::CairoRunner;
1515
use cheatnet::constants::build_test_entry_point;
1616
use starknet_api::deprecated_contract_class::EntryPointOffset;
1717
use std::collections::HashMap;
18-
use universal_sierra_compiler_api::AssembledProgramWithDebugInfo;
18+
use universal_sierra_compiler_api::representation::RawCasmProgram;
1919

2020
// Based on structure from https://github.com/starkware-libs/sequencer/blob/e417a9e7d50cbd78065d357763df2fbc2ad41f7c/crates/blockifier/src/execution/entry_point_execution.rs#L39
2121
// Logic of `initialize_execution_context` had to be modified so this struct ended up modified as well.
@@ -96,7 +96,7 @@ pub fn entry_point_initial_budget(syscall_hint_processor: &SyscallHintProcessor)
9696

9797
pub fn build_test_call_and_entry_point(
9898
test_details: &TestDetails,
99-
casm_program: &AssembledProgramWithDebugInfo,
99+
casm_program: &RawCasmProgram,
100100
program: &Program,
101101
) -> (ExecutableCallEntryPoint, EntryPointV1) {
102102
let sierra_instruction_idx = test_details.sierra_entry_point_statement_idx;

0 commit comments

Comments
 (0)