Skip to content

Commit 8fa04a4

Browse files
committed
Remove cairo-lang-runner dependency from forge runner
commit-id:a1c233ca
1 parent 02c32f9 commit 8fa04a4

File tree

6 files changed

+38
-16
lines changed

6 files changed

+38
-16
lines changed

Cargo.lock

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

crates/conversions/src/felt.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,32 @@ impl FromShortString<Felt> for Felt {
7979
}
8080
}
8181

82+
#[derive(Debug)]
83+
pub struct ToStrErr;
84+
85+
pub trait ToShortString<T>: Sized {
86+
fn to_short_string(&self) -> Result<String, ToStrErr>;
87+
}
88+
89+
impl ToShortString<Felt> for Felt {
90+
fn to_short_string(&self) -> Result<String, ToStrErr> {
91+
let mut as_string = String::default();
92+
let mut is_end = false;
93+
for byte in self.to_biguint().to_bytes_be() {
94+
if byte == 0 {
95+
is_end = true;
96+
} else if is_end {
97+
return Err(ToStrErr);
98+
} else if byte.is_ascii_graphic() || byte.is_ascii_whitespace() {
99+
as_string.push(byte as char);
100+
} else {
101+
return Err(ToStrErr);
102+
}
103+
}
104+
Ok(as_string)
105+
}
106+
}
107+
82108
pub trait TryInferFormat: Sized {
83109
/// Parses value from `hex string`, `dec string`, `quotted cairo shortstring `and `quotted cairo string`
84110
fn infer_format_and_parse(value: &str) -> Result<Vec<Self>, FromStrError>;

crates/forge-runner/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ edition.workspace = true
77

88
[dependencies]
99
anyhow.workspace = true
10-
cairo-lang-runner.workspace = true
11-
cairo-lang-runnable-utils.workspace = true
1210
cairo-lang-casm.workspace = true
1311
cairo-lang-sierra.workspace = true
1412
cairo-lang-utils.workspace = true

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use crate::{forge_config::ForgeTrackedResource, package_tests::TestDetails};
77
use anyhow::Result;
88
use blockifier::execution::contract_class::TrackedResource;
99
use blockifier::state::{cached_state::CachedState, state_api::StateReader};
10-
use cairo_lang_runner::Arg;
1110
use cheatnet::runtime_extensions::forge_config_extension::{
1211
ForgeConfigExtension, config::RawForgeConfig,
1312
};
@@ -106,12 +105,7 @@ pub fn run_config_pass(
106105
},
107106
extended_runtime: StarknetRuntime {
108107
hint_handler: syscall_handler,
109-
// Max gas is no longer set by `create_entry_code_from_params`
110-
// Instead, call to `ExternalHint::WriteRunParam` is added by it, and we need to
111-
// store the gas value to be read by logic handling the hint
112-
// TODO(#2966) we should subtract initial cost of the function from this value to be more exact.
113-
// But as a workaround it should be good enough.
114-
user_args: vec![vec![Arg::Value(Felt::from(i64::MAX))]],
108+
user_args: vec![],
115109
panic_traceback: None,
116110
},
117111
};

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use cairo_lang_casm::hints::Hint;
2-
use cairo_lang_runner::casm_run::hint_to_hint_params;
3-
use cairo_vm::serde::deserialize_program::HintParams;
2+
use cairo_vm::serde::deserialize_program::{ApTracking, FlowTrackingData, HintParams};
43
use std::collections::HashMap;
54
use universal_sierra_compiler_api::AssembledCairoProgramWithSerde;
65

@@ -27,7 +26,14 @@ pub fn hints_to_params(
2726
*offset,
2827
hints
2928
.iter()
30-
.map(hint_to_hint_params)
29+
.map(|hint| HintParams {
30+
code: hint.representing_string(),
31+
accessible_scopes: vec![],
32+
flow_tracking_data: FlowTrackingData {
33+
ap_tracking: ApTracking::new(),
34+
reference_ids: HashMap::new(),
35+
},
36+
})
3137
.collect::<Vec<HintParams>>(),
3238
)
3339
})

crates/forge-runner/src/test_case_summary.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ use crate::gas::check_available_gas;
55
use crate::package_tests::with_config_resolved::TestCaseWithResolvedConfig;
66
use crate::running::{RunCompleted, RunStatus};
77
use cairo_annotations::trace_data::VersionedCallTrace as VersionedProfilerCallTrace;
8-
use cairo_lang_runner::short_string::as_cairo_short_string;
98
use camino::Utf8Path;
109
use cheatnet::runtime_extensions::call_to_blockifier_runtime_extension::rpc::UsedResources;
1110
use cheatnet::runtime_extensions::forge_runtime_extension::contracts_data::ContractsData;
1211
use conversions::byte_array::ByteArray;
12+
use conversions::felt::ToShortString;
1313
use num_traits::Pow;
1414
use shared::utils::build_readable_text;
1515
use starknet_api::execution_resources::GasVector;
@@ -400,7 +400,7 @@ impl TestCaseSummary<Single> {
400400

401401
fn join_short_strings(data: &[Felt]) -> String {
402402
data.iter()
403-
.map(|felt| as_cairo_short_string(felt).unwrap_or_default())
403+
.map(|felt| felt.to_short_string().unwrap_or_default())
404404
.collect::<Vec<String>>()
405405
.join(", ")
406406
}

0 commit comments

Comments
 (0)