diff --git a/CHANGELOG.md b/CHANGELOG.md index 25f0ee0e08..a64c370b94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ #### Upcoming Changes +* feat: unify `arbitrary`, `hooks`, `print` and `skip_next_instruction_hint` features as a single `test_utils` feature [#1755](https://github.com/lambdaclass/cairo-vm/pull/1755) + * BREAKING: removed the above features + * bugfix: cairo1-run CLI: Set finalize_builtins to true when using --air_public_input flag [#1744](https://github.com/lambdaclass/cairo-vm/pull/1752) * feat: Add hint `U256InvModN` to `Cairo1HintProcessor` [#1744](https://github.com/lambdaclass/cairo-vm/pull/1744) diff --git a/cairo-vm-tracer/Cargo.toml b/cairo-vm-tracer/Cargo.toml index e8f933f4b0..e19f692542 100644 --- a/cairo-vm-tracer/Cargo.toml +++ b/cairo-vm-tracer/Cargo.toml @@ -12,7 +12,7 @@ std = [] alloc = [] [dependencies] -cairo-vm = { workspace = true, features = ["arbitrary", "std"] } +cairo-vm = { workspace = true, features = ["test_utils"] } thiserror-no-std = { workspace = true } num-bigint = { workspace = true } num-traits = { workspace = true } diff --git a/fuzzer/Cargo.toml b/fuzzer/Cargo.toml index ea7f163360..fd04920b37 100644 --- a/fuzzer/Cargo.toml +++ b/fuzzer/Cargo.toml @@ -13,7 +13,7 @@ members = ["."] [dependencies] arbitrary = { version = "1.3.0", features = ["derive"] } -cairo-vm = { path = "../vm", features = ["arbitrary"] } +cairo-vm = { path = "../vm", features = ["test_utils"] } honggfuzz = "0.5.55" libfuzzer-sys = "0.4" num-bigint = "0.4" diff --git a/vm/Cargo.toml b/vm/Cargo.toml index a6bc143d75..5f6bc49c16 100644 --- a/vm/Cargo.toml +++ b/vm/Cargo.toml @@ -31,18 +31,10 @@ tracer = [] mod_builtin = [] # Note that these features are not retro-compatible with the cairo Python VM. -test_utils = [ - "skip_next_instruction_hint", - "hooks", - "print", -] # This feature will reference every test-oriented feature -skip_next_instruction_hint = [] -hooks = [] -arbitrary = ["dep:arbitrary", "std", "starknet-types-core/arbitrary", "starknet-types-core/std"] +test_utils = ["std", "dep:arbitrary", "starknet-types-core/arbitrary", "starknet-types-core/std"] # This feature will reference every test-oriented feature # Allows extending the set of hints for the current vm run from within a hint. # For a usage example checkout vm/src/tests/run_deprecated_contract_class_simplified.rs extensive_hints = [] -print = ["std"] [dependencies] zip = {version = "0.6.6", optional = true } diff --git a/vm/src/cairo_run.rs b/vm/src/cairo_run.rs index 4a245dc1b1..b43b6f4187 100644 --- a/vm/src/cairo_run.rs +++ b/vm/src/cairo_run.rs @@ -16,12 +16,12 @@ use bincode::enc::write::Writer; use thiserror_no_std::Error; -#[cfg(feature = "arbitrary")] +#[cfg(feature = "test_utils")] use arbitrary::{self, Arbitrary}; -#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[cfg_attr(feature = "test_utils", derive(Arbitrary))] pub struct CairoRunConfig<'a> { - #[cfg_attr(feature = "arbitrary", arbitrary(value = "main"))] + #[cfg_attr(feature = "test_utils", arbitrary(value = "main"))] pub entrypoint: &'a str, pub trace_enabled: bool, pub relocate_mem: bool, @@ -177,7 +177,7 @@ pub fn cairo_run_pie( Ok((cairo_runner, vm)) } -#[cfg(feature = "arbitrary")] +#[cfg(feature = "test_utils")] pub fn cairo_run_fuzzed_program( program: Program, cairo_run_config: &CairoRunConfig, diff --git a/vm/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs b/vm/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs index 19b6a77099..67d288f926 100644 --- a/vm/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs +++ b/vm/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs @@ -114,10 +114,10 @@ use crate::{ vm::{errors::hint_errors::HintError, vm_core::VirtualMachine}, }; -#[cfg(feature = "skip_next_instruction_hint")] +#[cfg(feature = "test_utils")] use crate::hint_processor::builtin_hint_processor::skip_next_instruction::skip_next_instruction; -#[cfg(feature = "print")] +#[cfg(feature = "test_utils")] use crate::hint_processor::builtin_hint_processor::print::{print_array, print_dict, print_felt}; use crate::hint_processor::builtin_hint_processor::secp::secp_utils::{ SECP256R1_ALPHA, SECP256R1_P, @@ -856,13 +856,13 @@ impl HintProcessorLogic for BuiltinHintProcessor { constants, ) } - #[cfg(feature = "skip_next_instruction_hint")] + #[cfg(feature = "test_utils")] hint_code::SKIP_NEXT_INSTRUCTION => skip_next_instruction(vm), - #[cfg(feature = "print")] + #[cfg(feature = "test_utils")] hint_code::PRINT_FELT => print_felt(vm, &hint_data.ids_data, &hint_data.ap_tracking), - #[cfg(feature = "print")] + #[cfg(feature = "test_utils")] hint_code::PRINT_ARR => print_array(vm, &hint_data.ids_data, &hint_data.ap_tracking), - #[cfg(feature = "print")] + #[cfg(feature = "test_utils")] hint_code::PRINT_DICT => { print_dict(vm, exec_scopes, &hint_data.ids_data, &hint_data.ap_tracking) } diff --git a/vm/src/hint_processor/builtin_hint_processor/hint_code.rs b/vm/src/hint_processor/builtin_hint_processor/hint_code.rs index 03bab59189..c6752c58a2 100644 --- a/vm/src/hint_processor/builtin_hint_processor/hint_code.rs +++ b/vm/src/hint_processor/builtin_hint_processor/hint_code.rs @@ -1427,15 +1427,18 @@ if x % 2 != 0: x = PRIME - x ids.x.low = x & ((1<<128)-1) ids.x.high = x >> 128"; -#[cfg(feature = "skip_next_instruction_hint")] +#[cfg(feature = "test_utils")] pub const SKIP_NEXT_INSTRUCTION: &str = "skip_next_instruction()"; +#[cfg(feature = "test_utils")] pub const PRINT_FELT: &str = "print(ids.x)"; +#[cfg(feature = "test_utils")] pub const PRINT_ARR: &str = r#"print(bytes.fromhex(f"{ids.name:062x}").decode().replace('\x00','')) arr = [memory[ids.arr + i] for i in range(ids.arr_len)] print(arr)"#; +#[cfg(feature = "test_utils")] pub const PRINT_DICT: &str = r#"print(bytes.fromhex(f"{ids.name:062x}").decode().replace('\x00','')) data = __dict_manager.get_dict(ids.dict_ptr) print( diff --git a/vm/src/hint_processor/builtin_hint_processor/mod.rs b/vm/src/hint_processor/builtin_hint_processor/mod.rs index a890ad6ebe..15f6481315 100644 --- a/vm/src/hint_processor/builtin_hint_processor/mod.rs +++ b/vm/src/hint_processor/builtin_hint_processor/mod.rs @@ -19,15 +19,16 @@ pub mod memset_utils; mod mod_circuit; pub mod poseidon_utils; pub mod pow_utils; -#[cfg(feature = "print")] +#[cfg(feature = "test_utils")] +#[cfg_attr(docsrs, doc(cfg(feature = "test_utils")))] pub mod print; pub mod secp; pub mod segments; pub mod set; pub mod sha256_utils; pub mod signature; -#[cfg(feature = "skip_next_instruction_hint")] -#[cfg_attr(docsrs, doc(cfg(feature = "skip_next_instruction_hint")))] +#[cfg(feature = "test_utils")] +#[cfg_attr(docsrs, doc(cfg(feature = "test_utils")))] pub mod skip_next_instruction; pub mod squash_dict_utils; pub mod uint256_utils; diff --git a/vm/src/hint_processor/hint_processor_definition.rs b/vm/src/hint_processor/hint_processor_definition.rs index fbf3050b89..496e8b1428 100644 --- a/vm/src/hint_processor/hint_processor_definition.rs +++ b/vm/src/hint_processor/hint_processor_definition.rs @@ -15,7 +15,7 @@ use crate::vm::vm_core::VirtualMachine; use super::builtin_hint_processor::builtin_hint_processor_definition::HintProcessorData; use crate::Felt252; -#[cfg(feature = "arbitrary")] +#[cfg(feature = "test_utils")] use arbitrary::Arbitrary; pub trait HintProcessorLogic { @@ -98,7 +98,7 @@ fn get_ids_data( Ok(ids_data) } -#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[cfg_attr(feature = "test_utils", derive(Arbitrary))] #[derive(Debug, PartialEq, Eq, Clone)] pub struct HintReference { pub offset1: OffsetValue, diff --git a/vm/src/lib.rs b/vm/src/lib.rs index c4cfbd1334..5d78058f13 100644 --- a/vm/src/lib.rs +++ b/vm/src/lib.rs @@ -2,11 +2,12 @@ //! //! ## Feature Flags //! - `std`: Enables usage of the [`std`] standard library. Enabled by default. -//! - `skip_next_instruction_hint`: Enable the `skip_next_instruction()` hint. Not enabled by default. -//! - `hooks`: Enable [`Hooks`](crate::vm::hooks::Hooks) support for the [VirtualMachine](vm::vm_core::VirtualMachine). Not enabled by default. -//! - `test_utils`: Enables test utils (`hooks` and `skip_next_instruction` features). Not enabled by default. +//! - `test_utils`: Enables the following to help with tests (not enabled by default): +//! - [`Hooks`](crate::vm::hooks::Hooks) support for the [VirtualMachine](vm::vm_core::VirtualMachine); +//! - the `print_*` family of hints; +//! - the `skip_next_instruction()` hints; +//! - implementations of [`arbitrary::Arbitrary`](https://docs.rs/arbitrary/latest/arbitrary/) for some structs. //! - `cairo-1-hints`: Enable hints that were introduced in Cairo 1. Not enabled by default. -//! - `arbitrary`: Enables implementations of [`arbitrary::Arbitrary`](https://docs.rs/arbitrary/latest/arbitrary/) for some structs. Not enabled by default. #![cfg_attr(docsrs, feature(doc_cfg))] #![deny(warnings)] diff --git a/vm/src/serde/deserialize_program.rs b/vm/src/serde/deserialize_program.rs index 6eea8b84c5..6fbca14a22 100644 --- a/vm/src/serde/deserialize_program.rs +++ b/vm/src/serde/deserialize_program.rs @@ -33,10 +33,10 @@ use num_traits::{float::FloatCore, Num}; use serde::{de, de::MapAccess, de::SeqAccess, Deserialize, Deserializer, Serialize}; use serde_json::Number; -#[cfg(all(feature = "arbitrary", feature = "std"))] +#[cfg(feature = "test_utils")] use arbitrary::{self, Arbitrary, Unstructured}; -#[cfg_attr(all(feature = "arbitrary", feature = "std"), derive(Arbitrary, Clone))] +#[cfg_attr(feature = "test_utils", derive(Arbitrary, Clone))] #[derive(Deserialize, Debug)] pub struct ProgramJson { pub prime: String, @@ -51,7 +51,7 @@ pub struct ProgramJson { pub debug_info: Option, } -#[cfg_attr(all(feature = "arbitrary", feature = "std"), derive(Arbitrary))] +#[cfg_attr(feature = "test_utils", derive(Arbitrary))] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)] pub struct HintParams { pub code: String, @@ -59,7 +59,7 @@ pub struct HintParams { pub flow_tracking_data: FlowTrackingData, } -#[cfg_attr(all(feature = "arbitrary", feature = "std"), derive(Arbitrary))] +#[cfg_attr(feature = "test_utils", derive(Arbitrary))] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)] pub struct FlowTrackingData { pub ap_tracking: ApTracking, @@ -67,7 +67,7 @@ pub struct FlowTrackingData { pub reference_ids: HashMap, } -#[cfg_attr(all(feature = "arbitrary", feature = "std"), derive(Arbitrary))] +#[cfg_attr(feature = "test_utils", derive(Arbitrary))] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)] pub struct ApTracking { pub group: usize, @@ -89,7 +89,7 @@ impl Default for ApTracking { } } -#[cfg_attr(all(feature = "arbitrary", feature = "std"), derive(Arbitrary))] +#[cfg_attr(feature = "test_utils", derive(Arbitrary))] #[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)] pub struct Identifier { pub pc: Option, @@ -104,24 +104,21 @@ pub struct Identifier { pub cairo_type: Option, } -#[cfg_attr(all(feature = "arbitrary", feature = "std"), derive(Arbitrary))] +#[cfg_attr(feature = "test_utils", derive(Arbitrary))] #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] pub struct Member { pub cairo_type: String, pub offset: usize, } -#[cfg_attr(all(feature = "arbitrary", feature = "std"), derive(Arbitrary))] +#[cfg_attr(feature = "test_utils", derive(Arbitrary))] #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] pub struct Attribute { pub name: String, pub start_pc: usize, pub end_pc: usize, pub value: String, - #[cfg_attr( - all(feature = "arbitrary", feature = "std"), - serde(skip_serializing_if = "Option::is_none") - )] + #[cfg_attr(feature = "test_utils", serde(skip_serializing_if = "Option::is_none"))] pub flow_tracking_data: Option, } @@ -135,14 +132,14 @@ pub struct Location { pub start_col: u32, } -#[cfg(all(feature = "arbitrary", feature = "std"))] +#[cfg(feature = "test_utils")] impl<'a> Arbitrary<'a> for Location { fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result { arbitrary_parent_location(u, 20) } } -#[cfg(all(feature = "arbitrary", feature = "std"))] +#[cfg(feature = "test_utils")] fn arbitrary_parent_location(u: &mut Unstructured, depth: u8) -> arbitrary::Result { let parent_location = if depth > 0 { Some(( @@ -162,7 +159,7 @@ fn arbitrary_parent_location(u: &mut Unstructured, depth: u8) -> arbitrary::Resu }) } -#[cfg_attr(all(feature = "arbitrary", feature = "std"), derive(Arbitrary, Clone))] +#[cfg_attr(feature = "test_utils", derive(Arbitrary, Clone))] #[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] pub struct DebugInfo { pub(crate) instruction_locations: HashMap, @@ -179,14 +176,14 @@ impl DebugInfo { } } -#[cfg_attr(all(feature = "arbitrary", feature = "std"), derive(Arbitrary))] +#[cfg_attr(feature = "test_utils", derive(Arbitrary))] #[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)] pub struct InstructionLocation { pub inst: Location, pub hints: Vec, } -#[cfg_attr(all(feature = "arbitrary", feature = "std"), derive(Arbitrary))] +#[cfg_attr(feature = "test_utils", derive(Arbitrary))] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] pub struct InputFile { pub filename: String, @@ -203,7 +200,7 @@ impl InputFile { } } -#[cfg_attr(all(feature = "arbitrary", feature = "std"), derive(Arbitrary))] +#[cfg_attr(feature = "test_utils", derive(Arbitrary))] #[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)] pub struct HintLocation { pub location: Location, @@ -251,13 +248,13 @@ fn deserialize_scientific_notation(n: Number) -> Option { } } -#[cfg_attr(all(feature = "arbitrary", feature = "std"), derive(Arbitrary))] +#[cfg_attr(feature = "test_utils", derive(Arbitrary))] #[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone, Default)] pub struct ReferenceManager { pub references: Vec, } -#[cfg_attr(all(feature = "arbitrary", feature = "std"), derive(Arbitrary))] +#[cfg_attr(feature = "test_utils", derive(Arbitrary))] #[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)] pub struct Reference { pub ap_tracking_data: ApTracking, @@ -267,7 +264,7 @@ pub struct Reference { pub value_address: ValueAddress, } -#[cfg_attr(all(feature = "arbitrary", feature = "std"), derive(Arbitrary))] +#[cfg_attr(feature = "test_utils", derive(Arbitrary))] #[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)] pub enum OffsetValue { Immediate(Felt252), @@ -275,7 +272,7 @@ pub enum OffsetValue { Reference(Register, i32, bool), } -#[cfg_attr(all(feature = "arbitrary", feature = "std"), derive(Arbitrary))] +#[cfg_attr(feature = "test_utils", derive(Arbitrary))] #[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)] pub struct ValueAddress { pub offset1: OffsetValue, // A in cast(A + B, type) diff --git a/vm/src/tests/cairo_run_test.rs b/vm/src/tests/cairo_run_test.rs index dec10e63eb..4fb9b4d691 100644 --- a/vm/src/tests/cairo_run_test.rs +++ b/vm/src/tests/cairo_run_test.rs @@ -1043,28 +1043,28 @@ fn divmod_igcdex_not_one() { } #[test] -#[cfg(feature = "print")] +#[cfg(feature = "test_utils")] fn cairo_run_print_felt() { let program_data = include_bytes!("../../../cairo_programs/print_feature/print_felt.json"); run_program_simple(program_data); } #[test] -#[cfg(feature = "print")] +#[cfg(feature = "test_utils")] fn cairo_run_print_array() { let program_data = include_bytes!("../../../cairo_programs/print_feature/print_array.json"); run_program_simple(program_data); } #[test] -#[cfg(feature = "print")] +#[cfg(feature = "test_utils")] fn cairo_run_print_dict_felt() { let program_data = include_bytes!("../../../cairo_programs/print_feature/print_dict_felt.json"); run_program_simple(program_data); } #[test] -#[cfg(feature = "print")] +#[cfg(feature = "test_utils")] fn cairo_run_print_dict_array() { let program_data = include_bytes!("../../../cairo_programs/print_feature/print_dict_array.json"); diff --git a/vm/src/tests/mod.rs b/vm/src/tests/mod.rs index 4d1e37bde1..7f3fa1cbd9 100644 --- a/vm/src/tests/mod.rs +++ b/vm/src/tests/mod.rs @@ -42,7 +42,7 @@ mod pedersen_test; mod struct_test; mod cairo_pie_test; -#[cfg(feature = "skip_next_instruction_hint")] +#[cfg(feature = "test_utils")] mod skip_instruction_test; //For simple programs that should just succeed and have no special needs. diff --git a/vm/src/types/builtin_name.rs b/vm/src/types/builtin_name.rs index e904a1f335..af5bc2bfbe 100644 --- a/vm/src/types/builtin_name.rs +++ b/vm/src/types/builtin_name.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -#[cfg(all(feature = "arbitrary", feature = "std"))] +#[cfg(feature = "test_utils")] use arbitrary::{self, Arbitrary}; // Internal constants @@ -31,7 +31,7 @@ const ADD_MOD_BUILTIN_NAME_WITH_SUFFIX: &str = "add_mod_builtin"; const MUL_MOD_BUILTIN_NAME_WITH_SUFFIX: &str = "mul_mod_builtin"; /// Enum representing the name of a cairo builtin -#[cfg_attr(all(feature = "arbitrary", feature = "std"), derive(Arbitrary))] +#[cfg_attr(feature = "test_utils", derive(Arbitrary))] #[derive(Serialize, Deserialize, Debug, PartialEq, Copy, Clone, Eq, Hash)] #[allow(non_camel_case_types)] pub enum BuiltinName { diff --git a/vm/src/types/instruction.rs b/vm/src/types/instruction.rs index 49ecb19311..133c691302 100644 --- a/vm/src/types/instruction.rs +++ b/vm/src/types/instruction.rs @@ -4,10 +4,10 @@ use serde::{Deserialize, Serialize}; use crate::vm::decoding::decoder::decode_instruction; -#[cfg(feature = "arbitrary")] +#[cfg(feature = "test_utils")] use arbitrary::Arbitrary; -#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] +#[cfg_attr(feature = "test_utils", derive(Arbitrary))] #[derive(Serialize, Deserialize, Copy, Clone, Debug, PartialEq, Eq)] pub enum Register { AP, diff --git a/vm/src/types/layout_name.rs b/vm/src/types/layout_name.rs index 1c957fbf90..8cfd792dc0 100644 --- a/vm/src/types/layout_name.rs +++ b/vm/src/types/layout_name.rs @@ -1,4 +1,4 @@ -#[cfg(all(feature = "arbitrary", feature = "std"))] +#[cfg(feature = "test_utils")] use arbitrary::{self, Arbitrary}; #[cfg(all(feature = "clap", feature = "std"))] use clap::{builder::PossibleValue, ValueEnum}; @@ -6,7 +6,7 @@ use core::fmt::{self, Display}; use serde::{Deserialize, Serialize}; /// Enum representing the name of a Cairo Layout -#[cfg_attr(all(feature = "arbitrary", feature = "std"), derive(Arbitrary))] +#[cfg_attr(feature = "test_utils", derive(Arbitrary))] #[derive(Serialize, Deserialize, Debug, PartialEq, Copy, Clone, Eq, Hash)] #[allow(non_camel_case_types)] pub enum LayoutName { diff --git a/vm/src/types/program.rs b/vm/src/types/program.rs index e8b14fd877..0fc8c6dc83 100644 --- a/vm/src/types/program.rs +++ b/vm/src/types/program.rs @@ -35,7 +35,7 @@ use std::path::Path; use super::builtin_name::BuiltinName; #[cfg(feature = "extensive_hints")] use super::relocatable::Relocatable; -#[cfg(all(feature = "arbitrary", feature = "std"))] +#[cfg(feature = "test_utils")] use arbitrary::{Arbitrary, Unstructured}; // NOTE: `Program` has been split in two containing some data that will be deep-copied @@ -73,7 +73,7 @@ pub(crate) struct SharedProgramData { pub(crate) reference_manager: Vec, } -#[cfg(all(feature = "arbitrary", feature = "std"))] +#[cfg(feature = "test_utils")] impl<'a> Arbitrary<'a> for SharedProgramData { /// Create an arbitary [`SharedProgramData`] using `HintsCollection::new` to generate `hints` and /// `hints_ranges` @@ -197,7 +197,7 @@ type HintRange = Option<(usize, NonZeroUsize)>; #[cfg(feature = "extensive_hints")] pub type HintRange = (usize, NonZeroUsize); -#[cfg_attr(all(feature = "arbitrary", feature = "std"), derive(Arbitrary))] +#[cfg_attr(feature = "test_utils", derive(Arbitrary))] #[derive(Clone, Debug, PartialEq, Eq)] pub struct Program { pub(crate) shared_program_data: Arc, diff --git a/vm/src/types/relocatable.rs b/vm/src/types/relocatable.rs index 790dae895b..4631a79b4b 100644 --- a/vm/src/types/relocatable.rs +++ b/vm/src/types/relocatable.rs @@ -11,10 +11,10 @@ use crate::{ use num_traits::ToPrimitive; use serde::{Deserialize, Serialize}; -#[cfg(all(feature = "arbitrary", feature = "std"))] +#[cfg(feature = "test_utils")] use arbitrary::Arbitrary; -#[cfg_attr(all(feature = "arbitrary", feature = "std"), derive(Arbitrary))] +#[cfg_attr(feature = "test_utils", derive(Arbitrary))] #[derive( Eq, Ord, Hash, PartialEq, PartialOrd, Clone, Copy, Debug, Serialize, Deserialize, Default, )] @@ -23,7 +23,7 @@ pub struct Relocatable { pub offset: usize, } -#[cfg_attr(all(feature = "arbitrary", feature = "std"), derive(Arbitrary))] +#[cfg_attr(feature = "test_utils", derive(Arbitrary))] #[derive(Eq, Ord, Hash, PartialEq, PartialOrd, Clone, Serialize, Deserialize)] pub enum MaybeRelocatable { RelocatableValue(Relocatable), diff --git a/vm/src/vm/mod.rs b/vm/src/vm/mod.rs index 69c524736b..2acb933afd 100644 --- a/vm/src/vm/mod.rs +++ b/vm/src/vm/mod.rs @@ -7,6 +7,6 @@ pub mod trace; pub mod vm_core; pub mod vm_memory; -#[cfg(feature = "hooks")] -#[cfg_attr(docsrs, doc(cfg(feature = "hooks")))] +#[cfg(feature = "test_utils")] +#[cfg_attr(docsrs, doc(cfg(feature = "test_utils")))] pub mod hooks; diff --git a/vm/src/vm/runners/cairo_runner.rs b/vm/src/vm/runners/cairo_runner.rs index 6e622002bf..9592d77f2a 100644 --- a/vm/src/vm/runners/cairo_runner.rs +++ b/vm/src/vm/runners/cairo_runner.rs @@ -672,7 +672,7 @@ impl CairoRunner { .hints_collection .hints_ranges .clone(); - #[cfg(feature = "hooks")] + #[cfg(feature = "test_utils")] vm.execute_before_first_step(self, &hint_data)?; while vm.run_context.pc != address && !hint_processor.consumed() { vm.step( diff --git a/vm/src/vm/vm_core.rs b/vm/src/vm/vm_core.rs index d22a1a8aeb..34cccf7438 100644 --- a/vm/src/vm/vm_core.rs +++ b/vm/src/vm/vm_core.rs @@ -90,7 +90,7 @@ pub struct VirtualMachine { skip_instruction_execution: bool, run_finished: bool, instruction_cache: Vec>, - #[cfg(feature = "hooks")] + #[cfg(feature = "test_utils")] pub(crate) hooks: crate::vm::hooks::Hooks, pub(crate) relocation_table: Option>, } @@ -119,7 +119,7 @@ impl VirtualMachine { rc_limits: None, run_finished: false, instruction_cache: Vec::new(), - #[cfg(feature = "hooks")] + #[cfg(feature = "test_utils")] hooks: Default::default(), relocation_table: None, } @@ -562,10 +562,10 @@ impl VirtualMachine { constants, )?; - #[cfg(feature = "hooks")] + #[cfg(feature = "test_utils")] self.execute_pre_step_instruction(hint_processor, exec_scopes, hint_datas, constants)?; self.step_instruction()?; - #[cfg(feature = "hooks")] + #[cfg(feature = "test_utils")] self.execute_post_step_instruction(hint_processor, exec_scopes, hint_datas, constants)?; Ok(()) @@ -1165,7 +1165,7 @@ pub struct VirtualMachineBuilder { pub(crate) current_step: usize, skip_instruction_execution: bool, run_finished: bool, - #[cfg(feature = "hooks")] + #[cfg(feature = "test_utils")] pub(crate) hooks: crate::vm::hooks::Hooks, } @@ -1185,7 +1185,7 @@ impl Default for VirtualMachineBuilder { skip_instruction_execution: false, segments: MemorySegmentManager::new(), run_finished: false, - #[cfg(feature = "hooks")] + #[cfg(feature = "test_utils")] hooks: Default::default(), } } @@ -1230,7 +1230,7 @@ impl VirtualMachineBuilder { self } - #[cfg(feature = "hooks")] + #[cfg(feature = "test_utils")] pub fn hooks(mut self, hooks: crate::vm::hooks::Hooks) -> VirtualMachineBuilder { self.hooks = hooks; self @@ -1247,7 +1247,7 @@ impl VirtualMachineBuilder { rc_limits: None, run_finished: self.run_finished, instruction_cache: Vec::new(), - #[cfg(feature = "hooks")] + #[cfg(feature = "test_utils")] hooks: self.hooks, relocation_table: None, } @@ -4384,7 +4384,7 @@ mod tests { fp: 1, }])); - #[cfg(feature = "hooks")] + #[cfg(feature = "test_utils")] fn before_first_step_hook( _vm: &mut VirtualMachine, _runner: &mut CairoRunner, @@ -4392,7 +4392,7 @@ mod tests { ) -> Result<(), VirtualMachineError> { Err(VirtualMachineError::Unexpected) } - #[cfg(feature = "hooks")] + #[cfg(feature = "test_utils")] let virtual_machine_builder = virtual_machine_builder.hooks(crate::vm::hooks::Hooks::new( Some(std::sync::Arc::new(before_first_step_hook)), None, @@ -4426,7 +4426,7 @@ mod tests { fp: 1, }]) ); - #[cfg(feature = "hooks")] + #[cfg(feature = "test_utils")] { let program = crate::types::program::Program::from_bytes( include_bytes!("../../../cairo_programs/sqrt.json"),