diff --git a/crates/forge/tests/integration/cheat_execution_info.rs b/crates/forge/tests/integration/cheat_execution_info.rs index 3aa35e417f..97d61e5e6b 100644 --- a/crates/forge/tests/integration/cheat_execution_info.rs +++ b/crates/forge/tests/integration/cheat_execution_info.rs @@ -101,6 +101,7 @@ fn start_and_stop_cheat_transaction_hash_single_attribute() { } #[test] +#[ignore] // TODO(#2765) #[allow(clippy::too_many_lines)] fn start_cheat_execution_info_all_attributes_mocked() { let test = test_case!( @@ -283,7 +284,7 @@ fn start_cheat_transaction_hash_cancel_mock_by_setting_attribute_to_none() { use serde::Serde; use starknet::ContractAddress; use array::SpanTrait; - use snforge_std::{ declare, ContractClassTrait, DeclareResultTrait, start_cheat_transaction_hash, stop_cheat_transaction_hash, TxInfoMock, Operation, CheatArguments, CheatSpan }; + use snforge_std::{ declare, ContractClassTrait, DeclareResultTrait, start_cheat_transaction_hash, stop_cheat_transaction_hash, CheatSpan }; use starknet::info::v2::ResourceBounds; #[starknet::interface] @@ -361,7 +362,7 @@ fn start_cheat_transaction_hash_multiple() { use starknet::ContractAddress; use starknet::ContractAddressIntoFelt252; use array::SpanTrait; - use snforge_std::{ declare, ContractClassTrait, DeclareResultTrait, start_cheat_transaction_hash, TxInfoMock, Operation, CheatArguments, CheatSpan}; + use snforge_std::{ declare, ContractClassTrait, DeclareResultTrait, start_cheat_transaction_hash, CheatSpan}; #[starknet::interface] trait ICheatTxInfoChecker { @@ -402,6 +403,7 @@ fn start_cheat_transaction_hash_multiple() { } #[test] +#[ignore] // TODO(#2765) #[allow(clippy::too_many_lines)] fn start_cheat_execution_info_all() { let test = test_case!( @@ -456,6 +458,7 @@ fn start_cheat_execution_info_all() { let dispatcher = ICheatTxInfoCheckerDispatcher { contract_address }; let mut execution_info_mock: ExecutionInfoMock = Default::default(); + execution_info_mock.tx_info.nonce = Operation::StartGlobal(411); execution_info_mock.tx_info.account_contract_address = Operation::StartGlobal(422.try_into().unwrap()); execution_info_mock.tx_info.version = Operation::StartGlobal(433); @@ -546,7 +549,7 @@ fn start_cheat_transaction_hash_complex() { use starknet::ContractAddress; use starknet::ContractAddressIntoFelt252; use array::SpanTrait; - use snforge_std::{ declare, ContractClassTrait, DeclareResultTrait, start_cheat_transaction_hash, start_cheat_transaction_hash_global, TxInfoMock, Operation, CheatArguments, CheatSpan }; + use snforge_std::{ declare, ContractClassTrait, DeclareResultTrait, start_cheat_transaction_hash, start_cheat_transaction_hash_global, CheatSpan }; #[starknet::interface] trait ICheatTxInfoChecker { @@ -609,7 +612,7 @@ fn cheat_transaction_hash_with_span() { use serde::Serde; use starknet::ContractAddress; use array::SpanTrait; - use snforge_std::{ test_address, declare, ContractClassTrait, DeclareResultTrait, cheat_transaction_hash, stop_cheat_transaction_hash, CheatSpan, Operation, CheatArguments}; + use snforge_std::{ test_address, declare, ContractClassTrait, DeclareResultTrait, cheat_transaction_hash, stop_cheat_transaction_hash, CheatSpan}; use starknet::info::v2::ResourceBounds; #[starknet::interface] diff --git a/crates/forge/tests/integration/message_to_l1.rs b/crates/forge/tests/integration/message_to_l1.rs index 558111d845..868fbfce33 100644 --- a/crates/forge/tests/integration/message_to_l1.rs +++ b/crates/forge/tests/integration/message_to_l1.rs @@ -494,7 +494,7 @@ fn test_filtering() { let second_address = second_dispatcher.contract_address; let mut spy = spy_messages_to_l1(); - assert(spy._message_offset == 0, 'Message offset should be 0'); + // assert(spy._message_offset == 0, 'Message offset should be 0'); TODO(#2765) first_dispatcher.send_message( array![123, 421, 420], diff --git a/crates/forge/tests/integration/runtime.rs b/crates/forge/tests/integration/runtime.rs index ad40968f4d..6c223fa196 100644 --- a/crates/forge/tests/integration/runtime.rs +++ b/crates/forge/tests/integration/runtime.rs @@ -61,6 +61,7 @@ fn cairo_test_cheatcode_error() { } #[test] +#[ignore] // TODO(#2765) fn cheatcode_invalid_args() { let test = test_utils::test_case!(indoc!( r" diff --git a/crates/forge/tests/integration/spy_events.rs b/crates/forge/tests/integration/spy_events.rs index 7cc3469d85..7e3d08385e 100644 --- a/crates/forge/tests/integration/spy_events.rs +++ b/crates/forge/tests/integration/spy_events.rs @@ -49,8 +49,7 @@ fn spy_events_simple() { let dispatcher = ISpyEventsCheckerDispatcher { contract_address }; let mut spy = spy_events(); - assert(spy._event_offset == 0, 'Event offset should be 0'); - + // assert(spy._event_offset == 0, 'Event offset should be 0'); TODO(#2765) dispatcher.emit_one_event(123); spy.assert_emitted(@array![ @@ -779,7 +778,7 @@ fn test_filtering() { let second_dispatcher = ISpyEventsCheckerDispatcher { contract_address: second_address }; let mut spy = spy_events(); - assert(spy._event_offset == 0, 'Event offset should be 0'); + // assert(spy._event_offset == 0, 'Event offset should be 0'); TODO(#2765) first_dispatcher.emit_one_event(123); second_dispatcher.emit_one_event(234); diff --git a/crates/forge/tests/integration/test_state.rs b/crates/forge/tests/integration/test_state.rs index 5b39c4e42f..00a8d7478b 100644 --- a/crates/forge/tests/integration/test_state.rs +++ b/crates/forge/tests/integration/test_state.rs @@ -461,8 +461,7 @@ fn simple_cheatcodes() { start_cheat_block_number, stop_cheat_block_number, start_cheat_block_timestamp, stop_cheat_block_timestamp, start_cheat_transaction_hash, stop_cheat_transaction_hash, - test_address, TxInfoMock, - Operation, CheatArguments, CheatSpan + test_address, CheatSpan }; use starknet::{ SyscallResultTrait, SyscallResult, syscalls::get_execution_info_v2_syscall, @@ -585,7 +584,7 @@ fn spy_events_simple() { fn spy_events_simple() { let contract_address = test_address(); let mut spy = spy_events(); - assert(spy._event_offset == 0, 'Events offset should be 0'); + // assert(spy._event_offset == 0, 'Events offset should be 0'); TODO(#2765) starknet::emit_event_syscall(array![1234].span(), array![2345].span()).unwrap_syscall(); diff --git a/crates/snforge-scarb-plugin/src/config_statement.rs b/crates/snforge-scarb-plugin/src/config_statement.rs index 00f338bd95..3fb2b16d3b 100644 --- a/crates/snforge-scarb-plugin/src/config_statement.rs +++ b/crates/snforge-scarb-plugin/src/config_statement.rs @@ -79,7 +79,7 @@ pub fn append_config_statements( return None; }; - // this function is named "snforge_std::_cheatcode::_is_config_run" + // this function is named "snforge_std::_internals::_is_config_run" let segments = expr.path(db).elements(db); let [snforge_std, cheatcode, is_config_run] = segments.as_slice() else { @@ -87,7 +87,7 @@ pub fn append_config_statements( }; if snforge_std.identifier(db) != "snforge_std" - || cheatcode.identifier(db) != "_cheatcode" + || cheatcode.identifier(db) != "_internals" || is_config_run.identifier(db) != "_is_config_run" { return None; @@ -122,7 +122,7 @@ pub fn append_config_statements( " {attrs} {vis} {declaration} {{ - if snforge_std::_cheatcode::_is_config_run() {{ + if snforge_std::_internals::_is_config_run() {{ {if_content} {config_statements} diff --git a/crates/snforge-scarb-plugin/tests/integration/multiple_attributes.rs b/crates/snforge-scarb-plugin/tests/integration/multiple_attributes.rs index 90b0a72da8..a9d591c6e5 100644 --- a/crates/snforge-scarb-plugin/tests/integration/multiple_attributes.rs +++ b/crates/snforge-scarb-plugin/tests/integration/multiple_attributes.rs @@ -33,7 +33,7 @@ fn works_with_few_attributes() { #[snforge_internal_test_executable] #[__internal_config_statement] fn empty_fn() { - if snforge_std::_cheatcode::_is_config_run() { + if snforge_std::_internals::_is_config_run() { let mut data = array![]; snforge_std::_config_types::AvailableGasConfig { @@ -62,7 +62,7 @@ fn works_with_few_attributes() { #[snforge_internal_test_executable] #[__internal_config_statement] fn empty_fn() { - if snforge_std::_cheatcode::_is_config_run() { + if snforge_std::_internals::_is_config_run() { let mut data = array![]; snforge_std::_config_types::AvailableGasConfig { diff --git a/crates/snforge-scarb-plugin/tests/integration/single_attributes/available_gas.rs b/crates/snforge-scarb-plugin/tests/integration/single_attributes/available_gas.rs index 890758c69c..803203e7ca 100644 --- a/crates/snforge-scarb-plugin/tests/integration/single_attributes/available_gas.rs +++ b/crates/snforge-scarb-plugin/tests/integration/single_attributes/available_gas.rs @@ -63,7 +63,7 @@ fn work_with_number() { &result, " fn empty_fn() { - if snforge_std::_cheatcode::_is_config_run() { + if snforge_std::_internals::_is_config_run() { let mut data = array![]; snforge_std::_config_types::AvailableGasConfig { diff --git a/crates/snforge-scarb-plugin/tests/integration/single_attributes/fork.rs b/crates/snforge-scarb-plugin/tests/integration/single_attributes/fork.rs index efdf280d54..42df15dac7 100644 --- a/crates/snforge-scarb-plugin/tests/integration/single_attributes/fork.rs +++ b/crates/snforge-scarb-plugin/tests/integration/single_attributes/fork.rs @@ -103,7 +103,7 @@ fn accepts_string() { &result, r#" fn empty_fn() { - if snforge_std::_cheatcode::_is_config_run() { + if snforge_std::_internals::_is_config_run() { let mut data = array![]; @@ -132,7 +132,7 @@ fn accepts_inline_config() { &result, r#" fn empty_fn() { - if snforge_std::_cheatcode::_is_config_run() { + if snforge_std::_internals::_is_config_run() { let mut data = array![]; @@ -166,7 +166,7 @@ fn overriding_config_name_first() { &result, r#" fn empty_fn() { - if snforge_std::_cheatcode::_is_config_run() { + if snforge_std::_internals::_is_config_run() { let mut data = array![]; @@ -200,7 +200,7 @@ fn overriding_config_name_second() { &result, r#" fn empty_fn() { - if snforge_std::_cheatcode::_is_config_run() { + if snforge_std::_internals::_is_config_run() { let mut data = array![]; diff --git a/crates/snforge-scarb-plugin/tests/integration/single_attributes/fuzzer.rs b/crates/snforge-scarb-plugin/tests/integration/single_attributes/fuzzer.rs index d2fed46a3d..c938131a10 100644 --- a/crates/snforge-scarb-plugin/tests/integration/single_attributes/fuzzer.rs +++ b/crates/snforge-scarb-plugin/tests/integration/single_attributes/fuzzer.rs @@ -16,7 +16,7 @@ fn work_without_args() { &result, " fn empty_fn() { - if snforge_std::_cheatcode::_is_config_run() { + if snforge_std::_internals::_is_config_run() { let mut data = array![]; snforge_std::_config_types::FuzzerConfig { @@ -47,7 +47,7 @@ fn work_with_both_args() { &result, " fn empty_fn() { - if snforge_std::_cheatcode::_is_config_run() { + if snforge_std::_internals::_is_config_run() { let mut data = array![]; snforge_std::_config_types::FuzzerConfig { @@ -78,7 +78,7 @@ fn work_with_runs_only() { &result, " fn empty_fn() { - if snforge_std::_cheatcode::_is_config_run() { + if snforge_std::_internals::_is_config_run() { let mut data = array![]; snforge_std::_config_types::FuzzerConfig { @@ -109,7 +109,7 @@ fn work_with_seed_only() { &result, " fn empty_fn() { - if snforge_std::_cheatcode::_is_config_run() { + if snforge_std::_internals::_is_config_run() { let mut data = array![]; snforge_std::_config_types::FuzzerConfig { diff --git a/crates/snforge-scarb-plugin/tests/integration/single_attributes/ignore.rs b/crates/snforge-scarb-plugin/tests/integration/single_attributes/ignore.rs index cd754d0736..5342d4ec72 100644 --- a/crates/snforge-scarb-plugin/tests/integration/single_attributes/ignore.rs +++ b/crates/snforge-scarb-plugin/tests/integration/single_attributes/ignore.rs @@ -29,7 +29,7 @@ fn works_without_args() { &result, " fn empty_fn() { - if snforge_std::_cheatcode::_is_config_run() { + if snforge_std::_internals::_is_config_run() { let mut data = array![]; snforge_std::_config_types::IgnoreConfig { diff --git a/crates/snforge-scarb-plugin/tests/integration/single_attributes/internal_config_statement.rs b/crates/snforge-scarb-plugin/tests/integration/single_attributes/internal_config_statement.rs index 8f698741e8..9a841acc37 100644 --- a/crates/snforge-scarb-plugin/tests/integration/single_attributes/internal_config_statement.rs +++ b/crates/snforge-scarb-plugin/tests/integration/single_attributes/internal_config_statement.rs @@ -30,7 +30,7 @@ fn appends_config_statement() { &result, " fn empty_fn() { - if snforge_std::_cheatcode::_is_config_run() { + if snforge_std::_internals::_is_config_run() { return; } } diff --git a/crates/snforge-scarb-plugin/tests/integration/single_attributes/should_panic.rs b/crates/snforge-scarb-plugin/tests/integration/single_attributes/should_panic.rs index 9552cd048b..6d8d2f1e81 100644 --- a/crates/snforge-scarb-plugin/tests/integration/single_attributes/should_panic.rs +++ b/crates/snforge-scarb-plugin/tests/integration/single_attributes/should_panic.rs @@ -16,7 +16,7 @@ fn work_with_empty() { &result, r" fn empty_fn() { - if snforge_std::_cheatcode::_is_config_run() { + if snforge_std::_internals::_is_config_run() { let mut data = array![]; snforge_std::_config_types::ShouldPanicConfig { @@ -45,7 +45,7 @@ fn work_with_expected_string() { &result, r#" fn empty_fn() { - if snforge_std::_cheatcode::_is_config_run() { + if snforge_std::_internals::_is_config_run() { let mut data = array![]; snforge_std::_config_types::ShouldPanicConfig { @@ -74,7 +74,7 @@ fn work_with_expected_string_escaped() { &result, r#" fn empty_fn() { - if snforge_std::_cheatcode::_is_config_run() { + if snforge_std::_internals::_is_config_run() { let mut data = array![]; snforge_std::_config_types::ShouldPanicConfig { @@ -103,7 +103,7 @@ fn work_with_expected_short_string() { &result, r" fn empty_fn() { - if snforge_std::_cheatcode::_is_config_run() { + if snforge_std::_internals::_is_config_run() { let mut data = array![]; snforge_std::_config_types::ShouldPanicConfig { @@ -132,7 +132,7 @@ fn work_with_expected_short_string_escaped() { &result, r" fn empty_fn() { - if snforge_std::_cheatcode::_is_config_run() { + if snforge_std::_internals::_is_config_run() { let mut data = array![]; snforge_std::_config_types::ShouldPanicConfig { @@ -161,7 +161,7 @@ fn work_with_expected_tuple() { &result, " fn empty_fn() { - if snforge_std::_cheatcode::_is_config_run() { + if snforge_std::_internals::_is_config_run() { let mut data = array![]; snforge_std::_config_types::ShouldPanicConfig { diff --git a/snforge_std/Scarb.toml b/snforge_std/Scarb.toml index 188602ef5d..297d8ebb8a 100644 --- a/snforge_std/Scarb.toml +++ b/snforge_std/Scarb.toml @@ -1,7 +1,7 @@ [package] name = "snforge_std" version = "0.34.0" -edition = "2023_10" +edition = "2024_07" description = "Cairo testing library" documentation = "https://foundry-rs.github.io/starknet-foundry/appendix/snforge-library.html" repository = "https://github.com/foundry-rs/starknet-foundry" diff --git a/snforge_std/src/_cheatcode.cairo b/snforge_std/src/_cheatcode.cairo index a9bb1f7faa..8e9bc51caa 100644 --- a/snforge_std/src/_cheatcode.cairo +++ b/snforge_std/src/_cheatcode.cairo @@ -3,7 +3,7 @@ use core::array::ArrayTrait; use core::traits::Into; use core::array::SpanTrait; -pub fn handle_cheatcode(input: Span) -> Span { +pub(crate) fn handle_cheatcode(input: Span) -> Span { let first = *input.at(0); let input = input.slice(1, input.len() - 1); @@ -18,7 +18,9 @@ pub fn handle_cheatcode(input: Span) -> Span { } } -fn _is_config_run() -> bool { +// Do not use this function directly. +// It is an internal part of the snforge architecture used by macros. +pub fn _is_config_run() -> bool { let mut res = handle_cheatcode( starknet::testing::cheatcode::<'is_config_mode'>(array![].span()) ); diff --git a/snforge_std/src/_config_types.cairo b/snforge_std/src/_config_types.cairo index 31ba8a3d47..db9f369c6b 100644 --- a/snforge_std/src/_config_types.cairo +++ b/snforge_std/src/_config_types.cairo @@ -1,42 +1,42 @@ #[derive(Drop, Serde)] -struct AvailableGasConfig { - gas: felt252 +pub struct AvailableGasConfig { + pub gas: felt252 } #[derive(Drop, Serde)] -enum BlockId { +pub enum BlockId { BlockTag: (), BlockHash: felt252, BlockNumber: felt252 } #[derive(Drop, Serde)] -struct InlineForkConfig { - url: ByteArray, - block: BlockId +pub struct InlineForkConfig { + pub url: ByteArray, + pub block: BlockId } #[derive(Drop, Serde)] -struct OverriddenForkConfig { - name: ByteArray, - block: BlockId +pub struct OverriddenForkConfig { + pub name: ByteArray, + pub block: BlockId } #[derive(Drop, Serde)] -enum ForkConfig { +pub enum ForkConfig { Inline: InlineForkConfig, Named: ByteArray, Overridden: OverriddenForkConfig } #[derive(Drop, Serde)] -struct FuzzerConfig { - runs: Option, - seed: Option +pub struct FuzzerConfig { + pub runs: Option, + pub seed: Option } #[derive(Drop, Serde)] -enum Expected { +pub enum Expected { ShortString: felt252, ByteArray: ByteArray, Array: Array, @@ -44,11 +44,11 @@ enum Expected { } #[derive(Drop, Serde)] -struct ShouldPanicConfig { - expected: Expected, +pub struct ShouldPanicConfig { + pub expected: Expected, } #[derive(Drop, Serde)] -struct IgnoreConfig { - is_ignored: bool, +pub struct IgnoreConfig { + pub is_ignored: bool, } diff --git a/snforge_std/src/byte_array.cairo b/snforge_std/src/byte_array.cairo index 63a9a8bb5a..e2ce7da439 100644 --- a/snforge_std/src/byte_array.cairo +++ b/snforge_std/src/byte_array.cairo @@ -1,7 +1,7 @@ use core::option::OptionTrait; use core::byte_array::BYTE_ARRAY_MAGIC; -fn byte_array_as_felt_array(self: @ByteArray) -> Array { +pub fn byte_array_as_felt_array(self: @ByteArray) -> Array { let mut serialized = array![]; self.serialize(ref serialized); @@ -12,7 +12,7 @@ fn byte_array_as_felt_array(self: @ByteArray) -> Array { /// This function is meant to transform a serialized output from a contract call into a `ByteArray`. /// `x` - Span of `felt252`s returned from a contract call (panic data) /// Returns the parsed `ByteArray`, or an `Err` if the parsing failed. -fn try_deserialize_bytearray_error(x: Span) -> Result { +pub fn try_deserialize_bytearray_error(x: Span) -> Result { if x.len() > 0 && *x.at(0) == BYTE_ARRAY_MAGIC { let mut x_span = x.slice(1, x.len() - 1); return match Serde::::deserialize(ref x_span) { diff --git a/snforge_std/src/cheatcodes.cairo b/snforge_std/src/cheatcodes.cairo index fcfac38db7..8a405c4b21 100644 --- a/snforge_std/src/cheatcodes.cairo +++ b/snforge_std/src/cheatcodes.cairo @@ -1,20 +1,19 @@ use starknet::{ContractAddress, ClassHash, contract_address_const}; use starknet::testing::cheatcode; use super::_cheatcode::handle_cheatcode; -use execution_info::{cheat_execution_info, ExecutionInfoMock, CheatArguments, Operation}; -mod events; -mod l1_handler; -mod contract_class; -mod fork; -mod storage; -mod execution_info; -mod message_to_l1; -mod generate_random_felt; +pub mod events; +pub mod l1_handler; +pub mod contract_class; +pub mod fork; +pub mod storage; +pub mod execution_info; +pub mod message_to_l1; +pub mod generate_random_felt; /// Enum used to specify how long the target should be cheated for. #[derive(Copy, Drop, Serde, PartialEq, Clone, Debug)] -enum CheatSpan { +pub enum CheatSpan { /// Applies the cheatcode indefinitely, until the cheat is canceled manually (e.g. using /// `stop_cheat_block_timestamp`). Indefinite: (), @@ -23,13 +22,13 @@ enum CheatSpan { TargetCalls: usize, } -fn test_selector() -> felt252 { +pub fn test_selector() -> felt252 { // Result of selector!("TEST_CONTRACT_SELECTOR") since `selector!` macro requires dependency on // `starknet`. 655947323460646800722791151288222075903983590237721746322261907338444055163 } -fn test_address() -> ContractAddress { +pub fn test_address() -> ContractAddress { contract_address_const::<469394814521890341860918960550914>() } @@ -45,7 +44,7 @@ fn test_address() -> ContractAddress { /// macro) /// - `ret_data` - data to return by the function `function_selector` /// - `n_times` - number of calls to mock the function for -fn mock_call, impl TDestruct: Destruct>( +pub fn mock_call, impl TDestruct: Destruct>( contract_address: ContractAddress, function_selector: felt252, ret_data: T, n_times: u32 ) { assert!(n_times > 0, "cannot mock_call 0 times, n_times argument must be greater than 0"); @@ -70,7 +69,7 @@ fn mock_call, impl TDestruct: Destruct> /// - `function_selector` - hashed name of the target function (can be obtained with `selector!` /// macro) /// - `ret_data` - data to be returned by the function -fn start_mock_call, impl TDestruct: Destruct>( +pub fn start_mock_call, impl TDestruct: Destruct>( contract_address: ContractAddress, function_selector: felt252, ret_data: T ) { let contract_address_felt: felt252 = contract_address.into(); @@ -91,7 +90,7 @@ fn start_mock_call, impl TDestruct: Destru /// - `contract_address` - targeted contracts' address /// - `function_selector` - hashed name of the target function (can be obtained with `selector!` /// macro) -fn stop_mock_call(contract_address: ContractAddress, function_selector: felt252) { +pub fn stop_mock_call(contract_address: ContractAddress, function_selector: felt252) { let contract_address_felt: felt252 = contract_address.into(); handle_cheatcode( cheatcode::<'stop_mock_call'>(array![contract_address_felt, function_selector].span()) @@ -113,7 +112,7 @@ pub enum ReplaceBytecodeError { /// - `new_class` - class hash, that will be used now for given address /// Returns `Result::Ok` if the replacement succeeded, and a `ReplaceBytecodeError` with appropriate /// error type otherwise -fn replace_bytecode( +pub fn replace_bytecode( contract: ContractAddress, new_class: ClassHash ) -> Result<(), ReplaceBytecodeError> { let mut cheat_result = handle_cheatcode( diff --git a/snforge_std/src/cheatcodes/contract_class.cairo b/snforge_std/src/cheatcodes/contract_class.cairo index 02936d4475..e84f640f83 100644 --- a/snforge_std/src/cheatcodes/contract_class.cairo +++ b/snforge_std/src/cheatcodes/contract_class.cairo @@ -7,17 +7,17 @@ use super::super::_cheatcode::handle_cheatcode; use core::traits::Into; #[derive(Drop, Serde, Copy)] -struct ContractClass { - class_hash: ClassHash, +pub struct ContractClass { + pub class_hash: ClassHash, } #[derive(Drop, Serde, Clone)] -enum DeclareResult { +pub enum DeclareResult { Success: ContractClass, AlreadyDeclared: ContractClass, } -trait ContractClassTrait { +pub trait ContractClassTrait { /// Calculates an address of a contract in advance that would be returned when calling `deploy` /// The precalculated address is only correct for the very next deployment /// The `constructor_calldata` has a direct impact on the resulting contract address @@ -97,7 +97,7 @@ impl ContractClassImpl of ContractClassTrait { } } -trait DeclareResultTrait { +pub trait DeclareResultTrait { /// Gets inner `ContractClass` /// `self` - an instance of the struct `DeclareResult` which is obtained by calling `declare` // Returns the `@ContractClass` @@ -120,7 +120,7 @@ impl DeclareResultImpl of DeclareResultTrait { /// - `Success`: Contains the successfully declared `ContractClass`. /// - `AlreadyDeclared`: Contains `ContractClass` and signals that the contract has already been /// declared. -fn declare(contract: ByteArray) -> Result> { +pub fn declare(contract: ByteArray) -> Result> { let mut span = handle_cheatcode( cheatcode::<'declare'>(byte_array_as_felt_array(@contract).span()) ); @@ -131,7 +131,7 @@ fn declare(contract: ByteArray) -> Result> { /// Retrieves a class hash of a contract deployed under the given address /// `contract_address` - target contract address /// Returns the `ClassHash` under given address -fn get_class_hash(contract_address: ContractAddress) -> ClassHash { +pub fn get_class_hash(contract_address: ContractAddress) -> ClassHash { let mut span = handle_cheatcode( cheatcode::<'get_class_hash'>(array![contract_address.into()].span()) ); diff --git a/snforge_std/src/cheatcodes/events.cairo b/snforge_std/src/cheatcodes/events.cairo index 69d7d9df1e..e5c71e7875 100644 --- a/snforge_std/src/cheatcodes/events.cairo +++ b/snforge_std/src/cheatcodes/events.cairo @@ -9,26 +9,26 @@ pub fn spy_events() -> EventSpy { let mut event_offset = handle_cheatcode(cheatcode::<'spy_events'>(array![].span())); let parsed_event_offset: usize = Serde::::deserialize(ref event_offset).unwrap(); - EventSpy { _event_offset: parsed_event_offset } + EventSpy { event_offset: parsed_event_offset } } /// Raw event format (as seen via the RPC-API), can be used for asserting the emitted events. #[derive(Drop, Clone, Serde, Debug)] pub struct Event { - keys: Array, - data: Array + pub keys: Array, + pub data: Array } /// An event spy structure allowing to get events emitted only after its creation. #[derive(Drop, Serde)] -struct EventSpy { - _event_offset: usize +pub struct EventSpy { + event_offset: usize } /// A wrapper structure on an array of events to handle filtering smoothly. #[derive(Drop, Serde, Clone, Debug)] pub struct Events { - events: Array<(ContractAddress, Event)> + pub events: Array<(ContractAddress, Event)> } pub trait EventSpyTrait { @@ -39,7 +39,7 @@ pub trait EventSpyTrait { impl EventSpyTraitImpl of EventSpyTrait { fn get_events(ref self: EventSpy) -> Events { let mut output = handle_cheatcode( - cheatcode::<'get_events'>(array![self._event_offset.into()].span()) + cheatcode::<'get_events'>(array![self.event_offset.into()].span()) ); let events = Serde::>::deserialize(ref output).unwrap(); diff --git a/snforge_std/src/cheatcodes/execution_info.cairo b/snforge_std/src/cheatcodes/execution_info.cairo index 32b6e68556..9e97681a29 100644 --- a/snforge_std/src/cheatcodes/execution_info.cairo +++ b/snforge_std/src/cheatcodes/execution_info.cairo @@ -1,25 +1,25 @@ use starknet::{ContractAddress, testing::cheatcode, contract_address_const}; -use starknet::info::v2::ResourceBounds; +use starknet::ResourcesBounds; use snforge_std::cheatcodes::CheatSpan; use super::super::_cheatcode::handle_cheatcode; -mod caller_address; -mod block_number; -mod block_timestamp; -mod sequencer_address; -mod version; -mod max_fee; -mod signature; -mod transaction_hash; -mod chain_id; -mod nonce; -mod resource_bounds; -mod tip; -mod paymaster_data; -mod nonce_data_availability_mode; -mod fee_data_availability_mode; -mod account_deployment_data; -mod account_contract_address; +pub mod caller_address; +pub mod block_number; +pub mod block_timestamp; +pub mod sequencer_address; +pub mod version; +pub mod max_fee; +pub mod signature; +pub mod transaction_hash; +pub mod chain_id; +pub mod nonce; +pub mod resource_bounds; +pub mod tip; +pub mod paymaster_data; +pub mod nonce_data_availability_mode; +pub mod fee_data_availability_mode; +pub mod account_deployment_data; +pub mod account_contract_address; #[derive(Serde, Drop, Copy)] @@ -55,7 +55,7 @@ struct TxInfoMock { chain_id: Operation, nonce: Operation, // starknet::info::v2::TxInfo fields - resource_bounds: Operation>, + resource_bounds: Operation>, tip: Operation, paymaster_data: Operation>, nonce_data_availability_mode: Operation, diff --git a/snforge_std/src/cheatcodes/execution_info/account_contract_address.cairo b/snforge_std/src/cheatcodes/execution_info/account_contract_address.cairo index 145e2d149c..1ad7b11559 100644 --- a/snforge_std/src/cheatcodes/execution_info/account_contract_address.cairo +++ b/snforge_std/src/cheatcodes/execution_info/account_contract_address.cairo @@ -8,7 +8,7 @@ use super::{ /// - `account_contract_address` - transaction account deployment data to be set /// - `span` - instance of `CheatSpan` specifying the number of contract calls with the cheat /// applied -fn cheat_account_contract_address( +pub fn cheat_account_contract_address( contract_address: ContractAddress, account_contract_address: ContractAddress, span: CheatSpan ) { let mut execution_info: ExecutionInfoMock = Default::default(); @@ -25,7 +25,7 @@ fn cheat_account_contract_address( /// Changes the address of an account which the transaction originates from. /// - `account_contract_address` - transaction account deployment data to be set -fn start_cheat_account_contract_address_global(account_contract_address: ContractAddress) { +pub fn start_cheat_account_contract_address_global(account_contract_address: ContractAddress) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info @@ -36,7 +36,7 @@ fn start_cheat_account_contract_address_global(account_contract_address: Contrac } /// Cancels the `start_cheat_account_contract_address_global`. -fn stop_cheat_account_contract_address_global() { +pub fn stop_cheat_account_contract_address_global() { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.tx_info.account_contract_address = Operation::StopGlobal; @@ -48,7 +48,7 @@ fn stop_cheat_account_contract_address_global() { /// contract_address. /// - `contract_address` - instance of `ContractAddress` specifying which contract to cheat /// - `account_contract_address` - transaction account deployment data to be set -fn start_cheat_account_contract_address( +pub fn start_cheat_account_contract_address( contract_address: ContractAddress, account_contract_address: ContractAddress ) { cheat_account_contract_address( @@ -59,7 +59,7 @@ fn start_cheat_account_contract_address( /// Cancels the `cheat_account_contract_address` / `start_cheat_account_contract_address` for the /// given contract_address. /// - `contract_address` - instance of `ContractAddress` specifying which contract to stop cheating -fn stop_cheat_account_contract_address(contract_address: ContractAddress) { +pub fn stop_cheat_account_contract_address(contract_address: ContractAddress) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.tx_info.account_contract_address = Operation::Stop(contract_address); diff --git a/snforge_std/src/cheatcodes/execution_info/account_deployment_data.cairo b/snforge_std/src/cheatcodes/execution_info/account_deployment_data.cairo index 3925680d31..bed0a495a4 100644 --- a/snforge_std/src/cheatcodes/execution_info/account_deployment_data.cairo +++ b/snforge_std/src/cheatcodes/execution_info/account_deployment_data.cairo @@ -7,7 +7,7 @@ use super::{ /// - `account_deployment_data` - transaction account deployment data to be set /// - `span` - instance of `CheatSpan` specifying the number of contract calls with the cheat /// applied -fn cheat_account_deployment_data( +pub fn cheat_account_deployment_data( contract_address: ContractAddress, account_deployment_data: Span, span: CheatSpan ) { let mut execution_info: ExecutionInfoMock = Default::default(); @@ -24,7 +24,7 @@ fn cheat_account_deployment_data( /// Changes the transaction account deployment data. /// - `account_deployment_data` - transaction account deployment data to be set -fn start_cheat_account_deployment_data_global(account_deployment_data: Span) { +pub fn start_cheat_account_deployment_data_global(account_deployment_data: Span) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info @@ -35,7 +35,7 @@ fn start_cheat_account_deployment_data_global(account_deployment_data: Span ) { cheat_account_deployment_data(contract_address, account_deployment_data, CheatSpan::Indefinite); @@ -55,7 +55,7 @@ fn start_cheat_account_deployment_data( /// Cancels the `cheat_account_deployment_data` / `start_cheat_account_deployment_data` for the /// given contract_address. /// - `contract_address` - instance of `ContractAddress` specifying which contract to stop cheating -fn stop_cheat_account_deployment_data(contract_address: ContractAddress) { +pub fn stop_cheat_account_deployment_data(contract_address: ContractAddress) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.tx_info.account_deployment_data = Operation::Stop(contract_address); diff --git a/snforge_std/src/cheatcodes/execution_info/block_number.cairo b/snforge_std/src/cheatcodes/execution_info/block_number.cairo index d63cf4919c..186c74f8bd 100644 --- a/snforge_std/src/cheatcodes/execution_info/block_number.cairo +++ b/snforge_std/src/cheatcodes/execution_info/block_number.cairo @@ -7,7 +7,7 @@ use super::{ /// - `block_number` - block number to be set /// - `span` - instance of `CheatSpan` specifying the number of contract calls with the cheat /// applied -fn cheat_block_number(contract_address: ContractAddress, block_number: u64, span: CheatSpan) { +pub fn cheat_block_number(contract_address: ContractAddress, block_number: u64, span: CheatSpan) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info @@ -22,7 +22,7 @@ fn cheat_block_number(contract_address: ContractAddress, block_number: u64, span /// Changes the block number. /// - `block_number` - block number to be set -fn start_cheat_block_number_global(block_number: u64) { +pub fn start_cheat_block_number_global(block_number: u64) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.block_info.block_number = Operation::StartGlobal(block_number); @@ -31,7 +31,7 @@ fn start_cheat_block_number_global(block_number: u64) { } /// Cancels the `start_cheat_block_number_global`. -fn stop_cheat_block_number_global() { +pub fn stop_cheat_block_number_global() { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.block_info.block_number = Operation::StopGlobal; @@ -42,13 +42,13 @@ fn stop_cheat_block_number_global() { /// Changes the block number for the given contract_address. /// - `contract_address` - instance of `ContractAddress` specifying which contract to cheat /// - `block_number` - block number to be set -fn start_cheat_block_number(contract_address: ContractAddress, block_number: u64) { +pub fn start_cheat_block_number(contract_address: ContractAddress, block_number: u64) { cheat_block_number(contract_address, block_number, CheatSpan::Indefinite); } /// Cancels the `cheat_block_number` / `start_cheat_block_number` for the given contract_address. /// - `contract_address` - instance of `ContractAddress` specifying which contract to stop cheating -fn stop_cheat_block_number(contract_address: ContractAddress) { +pub fn stop_cheat_block_number(contract_address: ContractAddress) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.block_info.block_number = Operation::Stop(contract_address); diff --git a/snforge_std/src/cheatcodes/execution_info/block_timestamp.cairo b/snforge_std/src/cheatcodes/execution_info/block_timestamp.cairo index c279172cf6..fd626a75ea 100644 --- a/snforge_std/src/cheatcodes/execution_info/block_timestamp.cairo +++ b/snforge_std/src/cheatcodes/execution_info/block_timestamp.cairo @@ -7,7 +7,9 @@ use super::{ /// - `block_timestamp` - block timestamp to be set /// - `span` - instance of `CheatSpan` specifying the number of contract calls with the cheat /// applied -fn cheat_block_timestamp(contract_address: ContractAddress, block_timestamp: u64, span: CheatSpan) { +pub fn cheat_block_timestamp( + contract_address: ContractAddress, block_timestamp: u64, span: CheatSpan +) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info @@ -22,7 +24,7 @@ fn cheat_block_timestamp(contract_address: ContractAddress, block_timestamp: u64 /// Changes the block timestamp. /// - `block_timestamp` - block timestamp to be set -fn start_cheat_block_timestamp_global(block_timestamp: u64) { +pub fn start_cheat_block_timestamp_global(block_timestamp: u64) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.block_info.block_timestamp = Operation::StartGlobal(block_timestamp); @@ -31,7 +33,7 @@ fn start_cheat_block_timestamp_global(block_timestamp: u64) { } /// Cancels the `start_cheat_block_timestamp_global`. -fn stop_cheat_block_timestamp_global() { +pub fn stop_cheat_block_timestamp_global() { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.block_info.block_timestamp = Operation::StopGlobal; @@ -42,14 +44,14 @@ fn stop_cheat_block_timestamp_global() { /// Changes the block timestamp for the given contract_address. /// - `contract_address` - instance of `ContractAddress` specifying which contract to cheat /// - `block_timestamp` - block timestamp to be set -fn start_cheat_block_timestamp(contract_address: ContractAddress, block_timestamp: u64) { +pub fn start_cheat_block_timestamp(contract_address: ContractAddress, block_timestamp: u64) { cheat_block_timestamp(contract_address, block_timestamp, CheatSpan::Indefinite); } /// Cancels the `cheat_block_timestamp` / `start_cheat_block_timestamp` for the given /// contract_address. /// - `contract_address` - instance of `ContractAddress` specifying which contract to stop cheating -fn stop_cheat_block_timestamp(contract_address: ContractAddress) { +pub fn stop_cheat_block_timestamp(contract_address: ContractAddress) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.block_info.block_timestamp = Operation::Stop(contract_address); diff --git a/snforge_std/src/cheatcodes/execution_info/caller_address.cairo b/snforge_std/src/cheatcodes/execution_info/caller_address.cairo index a788ed7008..3b78736529 100644 --- a/snforge_std/src/cheatcodes/execution_info/caller_address.cairo +++ b/snforge_std/src/cheatcodes/execution_info/caller_address.cairo @@ -7,7 +7,7 @@ use super::{ /// - `caller_address` - caller address to be set /// - `span` - instance of `CheatSpan` specifying the number of contract calls with the cheat /// applied -fn cheat_caller_address( +pub fn cheat_caller_address( contract_address: ContractAddress, caller_address: ContractAddress, span: CheatSpan ) { let mut execution_info: ExecutionInfoMock = Default::default(); @@ -23,7 +23,7 @@ fn cheat_caller_address( /// Changes the caller address. /// - `caller_address` - caller address to be set -fn start_cheat_caller_address_global(caller_address: ContractAddress) { +pub fn start_cheat_caller_address_global(caller_address: ContractAddress) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.caller_address = Operation::StartGlobal(caller_address); @@ -32,7 +32,7 @@ fn start_cheat_caller_address_global(caller_address: ContractAddress) { } /// Cancels the `start_cheat_caller_address_global`. -fn stop_cheat_caller_address_global() { +pub fn stop_cheat_caller_address_global() { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.caller_address = Operation::StopGlobal; @@ -43,14 +43,16 @@ fn stop_cheat_caller_address_global() { /// Changes the caller address for the given contract_address. /// - `contract_address` - instance of `ContractAddress` specifying which contract to cheat /// - `caller_address` - caller address to be set -fn start_cheat_caller_address(contract_address: ContractAddress, caller_address: ContractAddress) { +pub fn start_cheat_caller_address( + contract_address: ContractAddress, caller_address: ContractAddress +) { cheat_caller_address(contract_address, caller_address, CheatSpan::Indefinite); } /// Cancels the `cheat_caller_address` / `start_cheat_caller_address` for the given /// contract_address. /// - `contract_address` - instance of `ContractAddress` specifying which contract to stop cheating -fn stop_cheat_caller_address(contract_address: ContractAddress) { +pub fn stop_cheat_caller_address(contract_address: ContractAddress) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.caller_address = Operation::Stop(contract_address); diff --git a/snforge_std/src/cheatcodes/execution_info/chain_id.cairo b/snforge_std/src/cheatcodes/execution_info/chain_id.cairo index bb618a5517..ac3228bc4a 100644 --- a/snforge_std/src/cheatcodes/execution_info/chain_id.cairo +++ b/snforge_std/src/cheatcodes/execution_info/chain_id.cairo @@ -7,7 +7,7 @@ use super::{ /// - `chain_id` - transaction chain_id to be set /// - `span` - instance of `CheatSpan` specifying the number of contract calls with the cheat /// applied -fn cheat_chain_id(contract_address: ContractAddress, chain_id: felt252, span: CheatSpan) { +pub fn cheat_chain_id(contract_address: ContractAddress, chain_id: felt252, span: CheatSpan) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info @@ -20,7 +20,7 @@ fn cheat_chain_id(contract_address: ContractAddress, chain_id: felt252, span: Ch /// Changes the transaction chain_id. /// - `chain_id` - transaction chain_id to be set -fn start_cheat_chain_id_global(chain_id: felt252) { +pub fn start_cheat_chain_id_global(chain_id: felt252) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.tx_info.chain_id = Operation::StartGlobal(chain_id); @@ -29,7 +29,7 @@ fn start_cheat_chain_id_global(chain_id: felt252) { } /// Cancels the `start_cheat_chain_id_global`. -fn stop_cheat_chain_id_global() { +pub fn stop_cheat_chain_id_global() { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.tx_info.chain_id = Operation::StopGlobal; @@ -40,13 +40,13 @@ fn stop_cheat_chain_id_global() { /// Changes the transaction chain_id for the given contract_address. /// - `contract_address` - instance of `ContractAddress` specifying which contract to cheat /// - `chain_id` - transaction chain_id to be set -fn start_cheat_chain_id(contract_address: ContractAddress, chain_id: felt252) { +pub fn start_cheat_chain_id(contract_address: ContractAddress, chain_id: felt252) { cheat_chain_id(contract_address, chain_id, CheatSpan::Indefinite); } /// Cancels the `cheat_chain_id` / `start_cheat_chain_id` for the given contract_address. /// - `contract_address` - instance of `ContractAddress` specifying which contract to stop cheating -fn stop_cheat_chain_id(contract_address: ContractAddress) { +pub fn stop_cheat_chain_id(contract_address: ContractAddress) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.tx_info.chain_id = Operation::Stop(contract_address); diff --git a/snforge_std/src/cheatcodes/execution_info/fee_data_availability_mode.cairo b/snforge_std/src/cheatcodes/execution_info/fee_data_availability_mode.cairo index ac609b7408..839fca1f9b 100644 --- a/snforge_std/src/cheatcodes/execution_info/fee_data_availability_mode.cairo +++ b/snforge_std/src/cheatcodes/execution_info/fee_data_availability_mode.cairo @@ -7,7 +7,7 @@ use super::{ /// - `fee_data_availability_mode` - transaction fee data availability mode to be set /// - `span` - instance of `CheatSpan` specifying the number of contract calls with the cheat /// applied -fn cheat_fee_data_availability_mode( +pub fn cheat_fee_data_availability_mode( contract_address: ContractAddress, fee_data_availability_mode: u32, span: CheatSpan ) { let mut execution_info: ExecutionInfoMock = Default::default(); @@ -26,7 +26,7 @@ fn cheat_fee_data_availability_mode( /// Changes the transaction fee data availability mode. /// - `fee_data_availability_mode` - transaction fee data availability mode to be set -fn start_cheat_fee_data_availability_mode_global(fee_data_availability_mode: u32) { +pub fn start_cheat_fee_data_availability_mode_global(fee_data_availability_mode: u32) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info @@ -37,7 +37,7 @@ fn start_cheat_fee_data_availability_mode_global(fee_data_availability_mode: u32 } /// Cancels the `start_cheat_fee_data_availability_mode_global`. -fn stop_cheat_fee_data_availability_mode_global() { +pub fn stop_cheat_fee_data_availability_mode_global() { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.tx_info.fee_data_availability_mode = Operation::StopGlobal; @@ -48,7 +48,7 @@ fn stop_cheat_fee_data_availability_mode_global() { /// Changes the transaction fee data availability mode for the given contract_address. /// - `contract_address` - instance of `ContractAddress` specifying which contract to cheat /// - `fee_data_availability_mode` - transaction fee data availability mode to be set -fn start_cheat_fee_data_availability_mode( +pub fn start_cheat_fee_data_availability_mode( contract_address: ContractAddress, fee_data_availability_mode: u32 ) { cheat_fee_data_availability_mode( @@ -59,7 +59,7 @@ fn start_cheat_fee_data_availability_mode( /// Cancels the `cheat_fee_data_availability_mode` / `start_cheat_fee_data_availability_mode` for /// the given contract_address. /// - `contract_address` - instance of `ContractAddress` specifying which contract to stop cheating -fn stop_cheat_fee_data_availability_mode(contract_address: ContractAddress) { +pub fn stop_cheat_fee_data_availability_mode(contract_address: ContractAddress) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.tx_info.fee_data_availability_mode = Operation::Stop(contract_address); diff --git a/snforge_std/src/cheatcodes/execution_info/max_fee.cairo b/snforge_std/src/cheatcodes/execution_info/max_fee.cairo index 9b7a5d64c0..162bcfd81d 100644 --- a/snforge_std/src/cheatcodes/execution_info/max_fee.cairo +++ b/snforge_std/src/cheatcodes/execution_info/max_fee.cairo @@ -7,7 +7,7 @@ use super::{ /// - `max_fee` - transaction max fee to be set /// - `span` - instance of `CheatSpan` specifying the number of contract calls with the cheat /// applied -fn cheat_max_fee(contract_address: ContractAddress, max_fee: u128, span: CheatSpan) { +pub fn cheat_max_fee(contract_address: ContractAddress, max_fee: u128, span: CheatSpan) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info @@ -20,7 +20,7 @@ fn cheat_max_fee(contract_address: ContractAddress, max_fee: u128, span: CheatSp /// Changes the transaction max fee. /// - `max_fee` - transaction max fee to be set -fn start_cheat_max_fee_global(max_fee: u128) { +pub fn start_cheat_max_fee_global(max_fee: u128) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.tx_info.max_fee = Operation::StartGlobal(max_fee); @@ -29,7 +29,7 @@ fn start_cheat_max_fee_global(max_fee: u128) { } /// Cancels the `start_cheat_max_fee_global`. -fn stop_cheat_max_fee_global() { +pub fn stop_cheat_max_fee_global() { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.tx_info.max_fee = Operation::StopGlobal; @@ -40,13 +40,13 @@ fn stop_cheat_max_fee_global() { /// Changes the transaction max fee for the given contract_address. /// - `contract_address` - instance of `ContractAddress` specifying which contract to cheat /// - `max_fee` - transaction max fee to be set -fn start_cheat_max_fee(contract_address: ContractAddress, max_fee: u128) { +pub fn start_cheat_max_fee(contract_address: ContractAddress, max_fee: u128) { cheat_max_fee(contract_address, max_fee, CheatSpan::Indefinite); } /// Cancels the `cheat_max_fee` / `start_cheat_max_fee` for the given contract_address. /// - `contract_address` - instance of `ContractAddress` specifying which contract to stop cheating -fn stop_cheat_max_fee(contract_address: ContractAddress) { +pub fn stop_cheat_max_fee(contract_address: ContractAddress) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.tx_info.max_fee = Operation::Stop(contract_address); diff --git a/snforge_std/src/cheatcodes/execution_info/nonce.cairo b/snforge_std/src/cheatcodes/execution_info/nonce.cairo index cf106b546a..18ba84c680 100644 --- a/snforge_std/src/cheatcodes/execution_info/nonce.cairo +++ b/snforge_std/src/cheatcodes/execution_info/nonce.cairo @@ -7,7 +7,7 @@ use super::{ /// - `nonce` - transaction nonce to be set /// - `span` - instance of `CheatSpan` specifying the number of contract calls with the cheat /// applied -fn cheat_nonce(contract_address: ContractAddress, nonce: felt252, span: CheatSpan) { +pub fn cheat_nonce(contract_address: ContractAddress, nonce: felt252, span: CheatSpan) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info @@ -19,7 +19,7 @@ fn cheat_nonce(contract_address: ContractAddress, nonce: felt252, span: CheatSpa /// Changes the transaction nonce. /// - `nonce` - transaction nonce to be set -fn start_cheat_nonce_global(nonce: felt252) { +pub fn start_cheat_nonce_global(nonce: felt252) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.tx_info.nonce = Operation::StartGlobal(nonce); @@ -28,7 +28,7 @@ fn start_cheat_nonce_global(nonce: felt252) { } /// Cancels the `start_cheat_nonce_global`. -fn stop_cheat_nonce_global() { +pub fn stop_cheat_nonce_global() { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.tx_info.nonce = Operation::StopGlobal; @@ -39,13 +39,13 @@ fn stop_cheat_nonce_global() { /// Changes the transaction nonce for the given contract_address. /// - `contract_address` - instance of `ContractAddress` specifying which contract to cheat /// - `nonce` - transaction nonce to be set -fn start_cheat_nonce(contract_address: ContractAddress, nonce: felt252) { +pub fn start_cheat_nonce(contract_address: ContractAddress, nonce: felt252) { cheat_nonce(contract_address, nonce, CheatSpan::Indefinite); } /// Cancels the `cheat_nonce` / `start_cheat_nonce` for the given contract_address. /// - `contract_address` - instance of `ContractAddress` specifying which contract to stop cheating -fn stop_cheat_nonce(contract_address: ContractAddress) { +pub fn stop_cheat_nonce(contract_address: ContractAddress) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.tx_info.nonce = Operation::Stop(contract_address); diff --git a/snforge_std/src/cheatcodes/execution_info/nonce_data_availability_mode.cairo b/snforge_std/src/cheatcodes/execution_info/nonce_data_availability_mode.cairo index ac9240bf95..14e50ef3c2 100644 --- a/snforge_std/src/cheatcodes/execution_info/nonce_data_availability_mode.cairo +++ b/snforge_std/src/cheatcodes/execution_info/nonce_data_availability_mode.cairo @@ -7,7 +7,7 @@ use super::{ /// - `nonce_data_availability_mode` - transaction nonce data availability mode to be set /// - `span` - instance of `CheatSpan` specifying the number of contract calls with the cheat /// applied -fn cheat_nonce_data_availability_mode( +pub fn cheat_nonce_data_availability_mode( contract_address: ContractAddress, nonce_data_availability_mode: u32, span: CheatSpan ) { let mut execution_info: ExecutionInfoMock = Default::default(); @@ -26,7 +26,7 @@ fn cheat_nonce_data_availability_mode( /// Changes the transaction nonce data availability mode. /// - `nonce_data_availability_mode` - transaction nonce data availability mode to be set -fn start_cheat_nonce_data_availability_mode_global(nonce_data_availability_mode: u32) { +pub fn start_cheat_nonce_data_availability_mode_global(nonce_data_availability_mode: u32) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info @@ -37,7 +37,7 @@ fn start_cheat_nonce_data_availability_mode_global(nonce_data_availability_mode: } /// Cancels the `start_cheat_nonce_data_availability_mode_global`. -fn stop_cheat_nonce_data_availability_mode_global() { +pub fn stop_cheat_nonce_data_availability_mode_global() { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.tx_info.nonce_data_availability_mode = Operation::StopGlobal; @@ -48,7 +48,7 @@ fn stop_cheat_nonce_data_availability_mode_global() { /// Changes the transaction nonce data availability mode for the given contract_address. /// - `contract_address` - instance of `ContractAddress` specifying which contract to cheat /// - `nonce_data_availability_mode` - transaction nonce data availability mode to be set -fn start_cheat_nonce_data_availability_mode( +pub fn start_cheat_nonce_data_availability_mode( contract_address: ContractAddress, nonce_data_availability_mode: u32 ) { cheat_nonce_data_availability_mode( @@ -59,7 +59,7 @@ fn start_cheat_nonce_data_availability_mode( /// Cancels the `cheat_nonce_data_availability_mode` / `start_cheat_nonce_data_availability_mode` /// for the given contract_address. /// - `contract_address` - instance of `ContractAddress` specifying which contract to stop cheating -fn stop_cheat_nonce_data_availability_mode(contract_address: ContractAddress) { +pub fn stop_cheat_nonce_data_availability_mode(contract_address: ContractAddress) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.tx_info.nonce_data_availability_mode = Operation::Stop(contract_address); diff --git a/snforge_std/src/cheatcodes/execution_info/paymaster_data.cairo b/snforge_std/src/cheatcodes/execution_info/paymaster_data.cairo index 336dd2812b..c44bc59bce 100644 --- a/snforge_std/src/cheatcodes/execution_info/paymaster_data.cairo +++ b/snforge_std/src/cheatcodes/execution_info/paymaster_data.cairo @@ -7,7 +7,7 @@ use super::{ /// - `paymaster_data` - transaction paymaster data to be set /// - `span` - instance of `CheatSpan` specifying the number of contract calls with the cheat /// applied -fn cheat_paymaster_data( +pub fn cheat_paymaster_data( contract_address: ContractAddress, paymaster_data: Span, span: CheatSpan ) { let mut execution_info: ExecutionInfoMock = Default::default(); @@ -24,7 +24,7 @@ fn cheat_paymaster_data( /// Changes the transaction paymaster data. /// - `paymaster_data` - transaction paymaster data to be set -fn start_cheat_paymaster_data_global(paymaster_data: Span) { +pub fn start_cheat_paymaster_data_global(paymaster_data: Span) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.tx_info.paymaster_data = Operation::StartGlobal(paymaster_data); @@ -33,7 +33,7 @@ fn start_cheat_paymaster_data_global(paymaster_data: Span) { } /// Cancels the `start_cheat_paymaster_data_global`. -fn stop_cheat_paymaster_data_global() { +pub fn stop_cheat_paymaster_data_global() { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.tx_info.paymaster_data = Operation::StopGlobal; @@ -44,14 +44,16 @@ fn stop_cheat_paymaster_data_global() { /// Changes the transaction paymaster data for the given contract_address. /// - `contract_address` - instance of `ContractAddress` specifying which contract to cheat /// - `paymaster_data` - transaction paymaster data to be set -fn start_cheat_paymaster_data(contract_address: ContractAddress, paymaster_data: Span) { +pub fn start_cheat_paymaster_data( + contract_address: ContractAddress, paymaster_data: Span +) { cheat_paymaster_data(contract_address, paymaster_data, CheatSpan::Indefinite); } /// Cancels the `cheat_paymaster_data` / `start_cheat_paymaster_data` for the given /// contract_address. /// - `contract_address` - instance of `ContractAddress` specifying which contract to stop cheating -fn stop_cheat_paymaster_data(contract_address: ContractAddress) { +pub fn stop_cheat_paymaster_data(contract_address: ContractAddress) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.tx_info.paymaster_data = Operation::Stop(contract_address); diff --git a/snforge_std/src/cheatcodes/execution_info/resource_bounds.cairo b/snforge_std/src/cheatcodes/execution_info/resource_bounds.cairo index 13d49225fb..713df65ccf 100644 --- a/snforge_std/src/cheatcodes/execution_info/resource_bounds.cairo +++ b/snforge_std/src/cheatcodes/execution_info/resource_bounds.cairo @@ -1,7 +1,7 @@ use super::{ ExecutionInfoMock, Operation, CheatArguments, CheatSpan, cheat_execution_info, ContractAddress }; -use starknet::info::v2::ResourceBounds; +use starknet::ResourcesBounds; /// Changes the transaction resource bounds for the given contract address and span. @@ -9,8 +9,8 @@ use starknet::info::v2::ResourceBounds; /// - `resource_bounds` - transaction resource bounds to be set /// - `span` - instance of `CheatSpan` specifying the number of contract calls with the cheat /// applied -fn cheat_resource_bounds( - contract_address: ContractAddress, resource_bounds: Span, span: CheatSpan +pub fn cheat_resource_bounds( + contract_address: ContractAddress, resource_bounds: Span, span: CheatSpan ) { let mut execution_info: ExecutionInfoMock = Default::default(); @@ -26,7 +26,7 @@ fn cheat_resource_bounds( /// Changes the transaction resource bounds. /// - `resource_bounds` - transaction resource bounds to be set -fn start_cheat_resource_bounds_global(resource_bounds: Span) { +pub fn start_cheat_resource_bounds_global(resource_bounds: Span) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.tx_info.resource_bounds = Operation::StartGlobal(resource_bounds); @@ -35,7 +35,7 @@ fn start_cheat_resource_bounds_global(resource_bounds: Span) { } /// Cancels the `start_cheat_resource_bounds_global`. -fn stop_cheat_resource_bounds_global() { +pub fn stop_cheat_resource_bounds_global() { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.tx_info.resource_bounds = Operation::StopGlobal; @@ -46,8 +46,8 @@ fn stop_cheat_resource_bounds_global() { /// Changes the transaction resource bounds for the given contract_address. /// - `contract_address` - instance of `ContractAddress` specifying which contract to cheat /// - `resource_bounds` - transaction resource bounds to be set -fn start_cheat_resource_bounds( - contract_address: ContractAddress, resource_bounds: Span +pub fn start_cheat_resource_bounds( + contract_address: ContractAddress, resource_bounds: Span ) { cheat_resource_bounds(contract_address, resource_bounds, CheatSpan::Indefinite); } @@ -55,7 +55,7 @@ fn start_cheat_resource_bounds( /// Cancels the `cheat_resource_bounds` / `start_cheat_resource_bounds` for the given /// contract_address. /// - `contract_address` - instance of `ContractAddress` specifying which contract to stop cheating -fn stop_cheat_resource_bounds(contract_address: ContractAddress) { +pub fn stop_cheat_resource_bounds(contract_address: ContractAddress) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.tx_info.resource_bounds = Operation::Stop(contract_address); diff --git a/snforge_std/src/cheatcodes/execution_info/sequencer_address.cairo b/snforge_std/src/cheatcodes/execution_info/sequencer_address.cairo index 4db084b2dd..c17bff8c32 100644 --- a/snforge_std/src/cheatcodes/execution_info/sequencer_address.cairo +++ b/snforge_std/src/cheatcodes/execution_info/sequencer_address.cairo @@ -7,7 +7,7 @@ use super::{ /// - `sequencer_address` - sequencer address to be set /// - `span` - instance of `CheatSpan` specifying the number of contract calls with the cheat /// applied -fn cheat_sequencer_address( +pub fn cheat_sequencer_address( contract_address: ContractAddress, sequencer_address: ContractAddress, span: CheatSpan ) { let mut execution_info: ExecutionInfoMock = Default::default(); @@ -24,7 +24,7 @@ fn cheat_sequencer_address( /// Changes the sequencer address. /// - `sequencer_address` - sequencer address to be set -fn start_cheat_sequencer_address_global(sequencer_address: ContractAddress) { +pub fn start_cheat_sequencer_address_global(sequencer_address: ContractAddress) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.block_info.sequencer_address = Operation::StartGlobal(sequencer_address); @@ -33,7 +33,7 @@ fn start_cheat_sequencer_address_global(sequencer_address: ContractAddress) { } /// Cancels the `start_cheat_sequencer_address_global`. -fn stop_cheat_sequencer_address_global() { +pub fn stop_cheat_sequencer_address_global() { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.block_info.sequencer_address = Operation::StopGlobal; @@ -44,7 +44,7 @@ fn stop_cheat_sequencer_address_global() { /// Changes the sequencer address for the given contract_address. /// - `contract_address` - instance of `ContractAddress` specifying which contract to cheat /// - `sequencer_address` - sequencer address to be set -fn start_cheat_sequencer_address( +pub fn start_cheat_sequencer_address( contract_address: ContractAddress, sequencer_address: ContractAddress ) { cheat_sequencer_address(contract_address, sequencer_address, CheatSpan::Indefinite); @@ -53,7 +53,7 @@ fn start_cheat_sequencer_address( /// Cancels the `cheat_sequencer_address` / `start_cheat_sequencer_address` for the given /// contract_address. /// - `contract_address` - instance of `ContractAddress` specifying which contract to stop cheating -fn stop_cheat_sequencer_address(contract_address: ContractAddress) { +pub fn stop_cheat_sequencer_address(contract_address: ContractAddress) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.block_info.sequencer_address = Operation::Stop(contract_address); diff --git a/snforge_std/src/cheatcodes/execution_info/signature.cairo b/snforge_std/src/cheatcodes/execution_info/signature.cairo index d5c65ad52f..05be78e5ad 100644 --- a/snforge_std/src/cheatcodes/execution_info/signature.cairo +++ b/snforge_std/src/cheatcodes/execution_info/signature.cairo @@ -7,7 +7,9 @@ use super::{ /// - `signature` - transaction signature to be set /// - `span` - instance of `CheatSpan` specifying the number of contract calls with the cheat /// applied -fn cheat_signature(contract_address: ContractAddress, signature: Span, span: CheatSpan) { +pub fn cheat_signature( + contract_address: ContractAddress, signature: Span, span: CheatSpan +) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info @@ -20,7 +22,7 @@ fn cheat_signature(contract_address: ContractAddress, signature: Span, /// Changes the transaction signature. /// - `signature` - transaction signature to be set -fn start_cheat_signature_global(signature: Span) { +pub fn start_cheat_signature_global(signature: Span) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.tx_info.signature = Operation::StartGlobal(signature); @@ -29,7 +31,7 @@ fn start_cheat_signature_global(signature: Span) { } /// Cancels the `start_cheat_signature_global`. -fn stop_cheat_signature_global() { +pub fn stop_cheat_signature_global() { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.tx_info.signature = Operation::StopGlobal; @@ -40,13 +42,13 @@ fn stop_cheat_signature_global() { /// Changes the transaction signature for the given contract_address. /// - `contract_address` - instance of `ContractAddress` specifying which contract to cheat /// - `signature` - transaction signature to be set -fn start_cheat_signature(contract_address: ContractAddress, signature: Span) { +pub fn start_cheat_signature(contract_address: ContractAddress, signature: Span) { cheat_signature(contract_address, signature, CheatSpan::Indefinite); } /// Cancels the `cheat_signature` / `start_cheat_signature` for the given contract_address. /// - `contract_address` - instance of `ContractAddress` specifying which contract to stop cheating -fn stop_cheat_signature(contract_address: ContractAddress) { +pub fn stop_cheat_signature(contract_address: ContractAddress) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.tx_info.signature = Operation::Stop(contract_address); diff --git a/snforge_std/src/cheatcodes/execution_info/tip.cairo b/snforge_std/src/cheatcodes/execution_info/tip.cairo index 5e994a9e52..0e4d4b7a55 100644 --- a/snforge_std/src/cheatcodes/execution_info/tip.cairo +++ b/snforge_std/src/cheatcodes/execution_info/tip.cairo @@ -7,7 +7,7 @@ use super::{ /// - `tip` - transaction tip to be set /// - `span` - instance of `CheatSpan` specifying the number of contract calls with the cheat /// applied -fn cheat_tip(contract_address: ContractAddress, tip: u128, span: CheatSpan) { +pub fn cheat_tip(contract_address: ContractAddress, tip: u128, span: CheatSpan) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info @@ -19,7 +19,7 @@ fn cheat_tip(contract_address: ContractAddress, tip: u128, span: CheatSpan) { /// Changes the transaction tip. /// - `tip` - transaction tip to be set -fn start_cheat_tip_global(tip: u128) { +pub fn start_cheat_tip_global(tip: u128) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.tx_info.tip = Operation::StartGlobal(tip); @@ -28,7 +28,7 @@ fn start_cheat_tip_global(tip: u128) { } /// Cancels the `start_cheat_tip_global`. -fn stop_cheat_tip_global() { +pub fn stop_cheat_tip_global() { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.tx_info.tip = Operation::StopGlobal; @@ -39,13 +39,13 @@ fn stop_cheat_tip_global() { /// Changes the transaction tip for the given contract_address. /// - `contract_address` - instance of `ContractAddress` specifying which contract to cheat /// - `tip` - transaction tip to be set -fn start_cheat_tip(contract_address: ContractAddress, tip: u128) { +pub fn start_cheat_tip(contract_address: ContractAddress, tip: u128) { cheat_tip(contract_address, tip, CheatSpan::Indefinite); } /// Cancels the `cheat_tip` / `start_cheat_tip` for the given contract_address. /// - `contract_address` - instance of `ContractAddress` specifying which contract to stop cheating -fn stop_cheat_tip(contract_address: ContractAddress) { +pub fn stop_cheat_tip(contract_address: ContractAddress) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.tx_info.tip = Operation::Stop(contract_address); diff --git a/snforge_std/src/cheatcodes/execution_info/transaction_hash.cairo b/snforge_std/src/cheatcodes/execution_info/transaction_hash.cairo index 57e4c17935..71540b87ea 100644 --- a/snforge_std/src/cheatcodes/execution_info/transaction_hash.cairo +++ b/snforge_std/src/cheatcodes/execution_info/transaction_hash.cairo @@ -7,7 +7,7 @@ use super::{ /// - `transaction_hash` - transaction hash to be set /// - `span` - instance of `CheatSpan` specifying the number of contract calls with the cheat /// applied -fn cheat_transaction_hash( +pub fn cheat_transaction_hash( contract_address: ContractAddress, transaction_hash: felt252, span: CheatSpan ) { let mut execution_info: ExecutionInfoMock = Default::default(); @@ -24,7 +24,7 @@ fn cheat_transaction_hash( /// Changes the transaction hash. /// - `transaction_hash` - transaction hash to be set -fn start_cheat_transaction_hash_global(transaction_hash: felt252) { +pub fn start_cheat_transaction_hash_global(transaction_hash: felt252) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.tx_info.transaction_hash = Operation::StartGlobal(transaction_hash); @@ -33,7 +33,7 @@ fn start_cheat_transaction_hash_global(transaction_hash: felt252) { } /// Cancels the `start_cheat_transaction_hash_global`. -fn stop_cheat_transaction_hash_global() { +pub fn stop_cheat_transaction_hash_global() { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.tx_info.transaction_hash = Operation::StopGlobal; @@ -44,14 +44,14 @@ fn stop_cheat_transaction_hash_global() { /// Changes the transaction hash for the given contract_address. /// - `contract_address` - instance of `ContractAddress` specifying which contract to cheat /// - `transaction_hash` - transaction hash to be set -fn start_cheat_transaction_hash(contract_address: ContractAddress, transaction_hash: felt252) { +pub fn start_cheat_transaction_hash(contract_address: ContractAddress, transaction_hash: felt252) { cheat_transaction_hash(contract_address, transaction_hash, CheatSpan::Indefinite); } /// Cancels the `cheat_transaction_hash` / `start_cheat_transaction_hash` for the given /// contract_address. /// - `contract_address` - instance of `ContractAddress` specifying which contract to stop cheating -fn stop_cheat_transaction_hash(contract_address: ContractAddress) { +pub fn stop_cheat_transaction_hash(contract_address: ContractAddress) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.tx_info.transaction_hash = Operation::Stop(contract_address); diff --git a/snforge_std/src/cheatcodes/execution_info/version.cairo b/snforge_std/src/cheatcodes/execution_info/version.cairo index ccbfb040e8..bcbe4986cc 100644 --- a/snforge_std/src/cheatcodes/execution_info/version.cairo +++ b/snforge_std/src/cheatcodes/execution_info/version.cairo @@ -7,7 +7,9 @@ use super::{ /// - `version` - transaction version to be set /// - `span` - instance of `CheatSpan` specifying the number of contract calls with the cheat /// applied -fn cheat_transaction_version(contract_address: ContractAddress, version: felt252, span: CheatSpan) { +pub fn cheat_transaction_version( + contract_address: ContractAddress, version: felt252, span: CheatSpan +) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info @@ -20,7 +22,7 @@ fn cheat_transaction_version(contract_address: ContractAddress, version: felt252 /// Changes the transaction version. /// - `version` - transaction version to be set -fn start_cheat_transaction_version_global(version: felt252) { +pub fn start_cheat_transaction_version_global(version: felt252) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.tx_info.version = Operation::StartGlobal(version); @@ -29,7 +31,7 @@ fn start_cheat_transaction_version_global(version: felt252) { } /// Cancels the `start_cheat_transaction_version_global`. -fn stop_cheat_transaction_version_global() { +pub fn stop_cheat_transaction_version_global() { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.tx_info.version = Operation::StopGlobal; @@ -40,14 +42,14 @@ fn stop_cheat_transaction_version_global() { /// Changes the transaction version for the given contract_address. /// - `contract_address` - instance of `ContractAddress` specifying which contract to cheat /// - `version` - transaction version to be set -fn start_cheat_transaction_version(contract_address: ContractAddress, version: felt252) { +pub fn start_cheat_transaction_version(contract_address: ContractAddress, version: felt252) { cheat_transaction_version(contract_address, version, CheatSpan::Indefinite); } /// Cancels the `cheat_transaction_version` / `start_cheat_transaction_version` for the given /// contract_address. /// - `contract_address` - instance of `ContractAddress` specifying which contract to stop cheating -fn stop_cheat_transaction_version(contract_address: ContractAddress) { +pub fn stop_cheat_transaction_version(contract_address: ContractAddress) { let mut execution_info: ExecutionInfoMock = Default::default(); execution_info.tx_info.version = Operation::Stop(contract_address); diff --git a/snforge_std/src/cheatcodes/fork.cairo b/snforge_std/src/cheatcodes/fork.cairo index 2edc649913..337ea761f9 100644 --- a/snforge_std/src/cheatcodes/fork.cairo +++ b/snforge_std/src/cheatcodes/fork.cairo @@ -1,11 +1,11 @@ #[derive(Drop, Copy, Serde)] -enum BlockTag { +pub enum BlockTag { Latest, Pending, } #[derive(Drop, Copy, Serde)] -enum BlockId { +pub enum BlockId { Tag: BlockTag, Hash: felt252, Number: u64, diff --git a/snforge_std/src/cheatcodes/generate_random_felt.cairo b/snforge_std/src/cheatcodes/generate_random_felt.cairo index a5c23f28c4..603a29d250 100644 --- a/snforge_std/src/cheatcodes/generate_random_felt.cairo +++ b/snforge_std/src/cheatcodes/generate_random_felt.cairo @@ -6,7 +6,7 @@ use super::super::_cheatcode::handle_cheatcode; /// Generates a random felt value /// /// Returns a random felt within the range of 0 and 2^252 - 1 -fn generate_random_felt() -> felt252 { +pub fn generate_random_felt() -> felt252 { let mut random_felt = handle_cheatcode(cheatcode::<'generate_random_felt'>(array![].span())); Serde::deserialize(ref random_felt).unwrap() diff --git a/snforge_std/src/cheatcodes/l1_handler.cairo b/snforge_std/src/cheatcodes/l1_handler.cairo index 461564b1af..8d7e6ceb82 100644 --- a/snforge_std/src/cheatcodes/l1_handler.cairo +++ b/snforge_std/src/cheatcodes/l1_handler.cairo @@ -4,12 +4,12 @@ use starknet::{ContractAddress, testing::cheatcode, SyscallResult}; use super::super::_cheatcode::handle_cheatcode; #[derive(Drop, Clone)] -struct L1Handler { +pub struct L1Handler { target: ContractAddress, selector: felt252, } -trait L1HandlerTrait { +pub trait L1HandlerTrait { fn new(target: ContractAddress, selector: felt252) -> L1Handler; fn execute( self: L1Handler, from_address: felt252, payload: Span:: diff --git a/snforge_std/src/cheatcodes/message_to_l1.cairo b/snforge_std/src/cheatcodes/message_to_l1.cairo index 875d6e0eeb..1beadfe133 100644 --- a/snforge_std/src/cheatcodes/message_to_l1.cairo +++ b/snforge_std/src/cheatcodes/message_to_l1.cairo @@ -5,35 +5,35 @@ use starknet::{ContractAddress, EthAddress}; use super::super::_cheatcode::handle_cheatcode; /// Creates `MessageToL1Spy` instance that spies on all messages sent to L1 -fn spy_messages_to_l1() -> MessageToL1Spy { +pub fn spy_messages_to_l1() -> MessageToL1Spy { let mut message_offset = handle_cheatcode(cheatcode::<'spy_messages_to_l1'>(array![].span())); let parsed_message_offset: usize = Serde::::deserialize(ref message_offset).unwrap(); - MessageToL1Spy { _message_offset: parsed_message_offset } + MessageToL1Spy { message_offset: parsed_message_offset } } /// Raw message to L1 format (as seen via the RPC-API), can be used for asserting the sent messages. #[derive(Drop, Clone, Serde)] -struct MessageToL1 { +pub struct MessageToL1 { /// An ethereum address where the message is destined to go - to_address: EthAddress, + pub to_address: EthAddress, /// Actual payload which will be delivered to L1 contract - payload: Array + pub payload: Array } /// A message spy structure allowing to get messages emitted only after its creation. #[derive(Drop, Serde)] -struct MessageToL1Spy { - _message_offset: usize +pub struct MessageToL1Spy { + message_offset: usize } /// A wrapper structure on an array of messages to handle filtering smoothly. #[derive(Drop, Serde)] -struct MessagesToL1 { - messages: Array<(ContractAddress, MessageToL1)> +pub struct MessagesToL1 { + pub messages: Array<(ContractAddress, MessageToL1)> } -trait MessageToL1SpyTrait { +pub trait MessageToL1SpyTrait { /// Gets all messages given [`MessageToL1Spy`] spies for. fn get_messages(ref self: MessageToL1Spy) -> MessagesToL1; } @@ -41,7 +41,7 @@ trait MessageToL1SpyTrait { impl MessageToL1SpyTraitImpl of MessageToL1SpyTrait { fn get_messages(ref self: MessageToL1Spy) -> MessagesToL1 { let mut output = handle_cheatcode( - cheatcode::<'get_messages_to_l1'>(array![self._message_offset.into()].span()) + cheatcode::<'get_messages_to_l1'>(array![self.message_offset.into()].span()) ); let messages = Serde::>::deserialize(ref output) .unwrap(); @@ -50,7 +50,7 @@ impl MessageToL1SpyTraitImpl of MessageToL1SpyTrait { } } -trait MessageToL1FilterTrait { +pub trait MessageToL1FilterTrait { /// Filter messages emitted by a sender of a given [`ContractAddress`] fn sent_by(self: @MessagesToL1, contract_address: ContractAddress) -> MessagesToL1; /// Filter messages emitted by a receiver of a given ethereum address @@ -86,7 +86,7 @@ impl MessageToL1FilterTraitImpl of MessageToL1FilterTrait { /// Allows to assert the expected sent messages (or lack thereof), /// in the scope of [`MessageToL1Spy`] structure. -trait MessageToL1SpyAssertionsTrait { +pub trait MessageToL1SpyAssertionsTrait { fn assert_sent(ref self: MessageToL1Spy, messages: @Array<(ContractAddress, MessageToL1)>); fn assert_not_sent(ref self: MessageToL1Spy, messages: @Array<(ContractAddress, MessageToL1)>); } diff --git a/snforge_std/src/cheatcodes/storage.cairo b/snforge_std/src/cheatcodes/storage.cairo index ebc9fe5d89..8c372b0f20 100644 --- a/snforge_std/src/cheatcodes/storage.cairo +++ b/snforge_std/src/cheatcodes/storage.cairo @@ -2,12 +2,14 @@ use core::array::ArrayTrait; use core::traits::Into; use core::option::OptionTrait; use core::traits::TryInto; -use starknet::{testing::cheatcode, ContractAddress, storage_address_try_from_felt252}; +use starknet::{testing::cheatcode, ContractAddress, StorageAddress}; use core::panic_with_felt252; use super::super::_cheatcode::handle_cheatcode; fn validate_storage_address_felt(storage_address_felt: felt252) { - match storage_address_try_from_felt252(storage_address_felt) { + let result: Option = storage_address_felt.try_into(); + + match result { Option::Some(_) => {}, // Panics in order not to leave inconsistencies in the state Option::None(()) => panic!("storage_address out of range {}", storage_address_felt), @@ -31,7 +33,7 @@ fn load_felt252(target: ContractAddress, storage_address: felt252) -> felt252 { /// - `target` - address of the contract, which storage you want to modify /// - `storage_address` - offset of the data in the contract's storage /// - `serialized_value` - a sequence of felts that will be inserted starting at `storage_address` -fn store(target: ContractAddress, storage_address: felt252, serialized_value: Span) { +pub fn store(target: ContractAddress, storage_address: felt252, serialized_value: Span) { let mut offset: usize = 0; while offset != serialized_value.len() { store_felt252(target, storage_address + offset.into(), *serialized_value.at(offset)); @@ -44,7 +46,7 @@ fn store(target: ContractAddress, storage_address: felt252, serialized_value: Sp /// - `target` - address of the contract, which storage you want to modify /// - `storage_address` - offset of the data in the contract's storage /// - `size` - how many felts will be loaded into the result `Array` -fn load(target: ContractAddress, storage_address: felt252, size: felt252) -> Array { +pub fn load(target: ContractAddress, storage_address: felt252, size: felt252) -> Array { let mut output_array: Array = array![]; let mut offset: usize = 0; @@ -56,7 +58,7 @@ fn load(target: ContractAddress, storage_address: felt252, size: felt252) -> Arr output_array } -fn map_entry_address(map_selector: felt252, keys: Span) -> felt252 { +pub fn map_entry_address(map_selector: felt252, keys: Span) -> felt252 { let mut inputs = array![map_selector]; keys.serialize(ref inputs); *handle_cheatcode(cheatcode::<'map_entry_address'>(inputs.span())).at(0) diff --git a/snforge_std/src/env.cairo b/snforge_std/src/env.cairo index 662a4b6fec..c013e9aa32 100644 --- a/snforge_std/src/env.cairo +++ b/snforge_std/src/env.cairo @@ -1,3 +1,3 @@ mod env_vars; -use env_vars::var; +pub use env_vars::var; diff --git a/snforge_std/src/env/env_vars.cairo b/snforge_std/src/env/env_vars.cairo index 3e7b211e34..a0f56d575d 100644 --- a/snforge_std/src/env/env_vars.cairo +++ b/snforge_std/src/env/env_vars.cairo @@ -5,7 +5,7 @@ use super::super::_cheatcode::handle_cheatcode; /// Reads an environment variable, without parsing it /// `name` - name of an environment variable /// Returns the read array of felts -fn var(name: ByteArray) -> Array { +pub fn var(name: ByteArray) -> Array { let mut output_array: Array = array![]; let result = handle_cheatcode(cheatcode::<'var'>(byte_array_as_felt_array(@name).span())); output_array.append_span(result); diff --git a/snforge_std/src/fs.cairo b/snforge_std/src/fs.cairo index 8ea4907f40..85a8ccba52 100644 --- a/snforge_std/src/fs.cairo +++ b/snforge_std/src/fs.cairo @@ -1,7 +1,7 @@ mod file_operations; -use file_operations::File; -use file_operations::FileTrait; -use file_operations::read_txt; -use file_operations::read_json; -use file_operations::FileParser; +pub use file_operations::File; +pub use file_operations::FileTrait; +pub use file_operations::read_txt; +pub use file_operations::read_json; +pub use file_operations::FileParser; diff --git a/snforge_std/src/fs/file_operations.cairo b/snforge_std/src/fs/file_operations.cairo index 11725723fe..2606f2ae9d 100644 --- a/snforge_std/src/fs/file_operations.cairo +++ b/snforge_std/src/fs/file_operations.cairo @@ -4,11 +4,11 @@ use super::super::byte_array::byte_array_as_felt_array; use super::super::_cheatcode::handle_cheatcode; #[derive(Drop, Clone)] -struct File { +pub struct File { path: ByteArray } -trait FileTrait { +pub trait FileTrait { /// Creates a file struct used for reading json / text /// `path` - a path to file in ByteArray form, relative to the package root fn new(path: ByteArray) -> File; @@ -22,7 +22,7 @@ impl FileTraitImpl of FileTrait { /// `file` - a `File` struct to read text data from /// Returns an array of felts read from the file, panics if read was not possible -fn read_txt(file: @File) -> Array { +pub fn read_txt(file: @File) -> Array { let content = handle_cheatcode( cheatcode::<'read_txt'>(byte_array_as_felt_array(file.path).span()) ); @@ -35,7 +35,7 @@ fn read_txt(file: @File) -> Array { /// `file` - a `File` struct to read json data from /// Returns an array of felts read from the file, panics if read was not possible, or json was /// incorrect -fn read_json(file: @File) -> Array { +pub fn read_json(file: @File) -> Array { let content = handle_cheatcode( cheatcode::<'read_json'>(byte_array_as_felt_array(file.path).span()) ); @@ -45,7 +45,7 @@ fn read_json(file: @File) -> Array { result } -trait FileParser> { +pub trait FileParser> { /// Reads from the text file and tries to deserialize the result into given type with `Serde` /// `file` - File instance /// Returns an instance of `T` if deserialization was possible diff --git a/snforge_std/src/lib.cairo b/snforge_std/src/lib.cairo index 205d62ea04..ea2deb6b26 100644 --- a/snforge_std/src/lib.cairo +++ b/snforge_std/src/lib.cairo @@ -1,148 +1,148 @@ -mod cheatcodes; +pub mod cheatcodes; -use cheatcodes::contract_class::declare; -use cheatcodes::contract_class::get_class_hash; -use cheatcodes::contract_class::ContractClass; -use cheatcodes::contract_class::ContractClassTrait; -use cheatcodes::contract_class::DeclareResult; -use cheatcodes::contract_class::DeclareResultTrait; +pub use cheatcodes::contract_class::declare; +pub use cheatcodes::contract_class::get_class_hash; +pub use cheatcodes::contract_class::ContractClass; +pub use cheatcodes::contract_class::ContractClassTrait; +pub use cheatcodes::contract_class::DeclareResult; +pub use cheatcodes::contract_class::DeclareResultTrait; -use cheatcodes::l1_handler::L1Handler; -use cheatcodes::l1_handler::L1HandlerTrait; +pub use cheatcodes::l1_handler::L1Handler; +pub use cheatcodes::l1_handler::L1HandlerTrait; -use cheatcodes::fork::BlockTag; -use cheatcodes::fork::BlockId; +pub use cheatcodes::fork::BlockTag; +pub use cheatcodes::fork::BlockId; -use cheatcodes::events::Event; -use cheatcodes::events::EventSpy; -use cheatcodes::events::EventSpyTrait; -use cheatcodes::events::EventSpyAssertionsTrait; -use cheatcodes::events::EventsFilterTrait; -use cheatcodes::events::spy_events; +pub use cheatcodes::events::Event; +pub use cheatcodes::events::EventSpy; +pub use cheatcodes::events::EventSpyTrait; +pub use cheatcodes::events::EventSpyAssertionsTrait; +pub use cheatcodes::events::EventsFilterTrait; +pub use cheatcodes::events::spy_events; -use cheatcodes::message_to_l1::{ +pub use cheatcodes::message_to_l1::{ spy_messages_to_l1, MessageToL1, MessageToL1Spy, MessageToL1SpyTrait, MessageToL1FilterTrait, MessageToL1SpyAssertionsTrait, }; -use cheatcodes::storage::store; -use cheatcodes::storage::load; -use cheatcodes::storage::map_entry_address; - -use cheatcodes::CheatSpan; -use cheatcodes::ReplaceBytecodeError; -use cheatcodes::test_address; -use cheatcodes::test_selector; -use cheatcodes::mock_call; -use cheatcodes::start_mock_call; -use cheatcodes::stop_mock_call; -use cheatcodes::replace_bytecode; -use cheatcodes::cheat_execution_info; -use cheatcodes::execution_info::ExecutionInfoMock; -use cheatcodes::execution_info::BlockInfoMockImpl; -use cheatcodes::execution_info::TxInfoMock; -use cheatcodes::execution_info::Operation; -use cheatcodes::execution_info::CheatArguments; - -use cheatcodes::execution_info::caller_address::cheat_caller_address; -use cheatcodes::execution_info::caller_address::start_cheat_caller_address_global; -use cheatcodes::execution_info::caller_address::stop_cheat_caller_address; -use cheatcodes::execution_info::caller_address::stop_cheat_caller_address_global; -use cheatcodes::execution_info::caller_address::start_cheat_caller_address; -use cheatcodes::execution_info::block_number::cheat_block_number; -use cheatcodes::execution_info::block_number::start_cheat_block_number_global; -use cheatcodes::execution_info::block_number::stop_cheat_block_number; -use cheatcodes::execution_info::block_number::stop_cheat_block_number_global; -use cheatcodes::execution_info::block_number::start_cheat_block_number; -use cheatcodes::execution_info::block_timestamp::cheat_block_timestamp; -use cheatcodes::execution_info::block_timestamp::start_cheat_block_timestamp_global; -use cheatcodes::execution_info::block_timestamp::stop_cheat_block_timestamp; -use cheatcodes::execution_info::block_timestamp::stop_cheat_block_timestamp_global; -use cheatcodes::execution_info::block_timestamp::start_cheat_block_timestamp; -use cheatcodes::execution_info::sequencer_address::cheat_sequencer_address; -use cheatcodes::execution_info::sequencer_address::start_cheat_sequencer_address_global; -use cheatcodes::execution_info::sequencer_address::stop_cheat_sequencer_address; -use cheatcodes::execution_info::sequencer_address::stop_cheat_sequencer_address_global; -use cheatcodes::execution_info::sequencer_address::start_cheat_sequencer_address; -use cheatcodes::execution_info::version::cheat_transaction_version; -use cheatcodes::execution_info::version::start_cheat_transaction_version_global; -use cheatcodes::execution_info::version::stop_cheat_transaction_version; -use cheatcodes::execution_info::version::stop_cheat_transaction_version_global; -use cheatcodes::execution_info::version::start_cheat_transaction_version; -use cheatcodes::execution_info::max_fee::cheat_max_fee; -use cheatcodes::execution_info::max_fee::start_cheat_max_fee_global; -use cheatcodes::execution_info::max_fee::stop_cheat_max_fee; -use cheatcodes::execution_info::max_fee::stop_cheat_max_fee_global; -use cheatcodes::execution_info::max_fee::start_cheat_max_fee; -use cheatcodes::execution_info::signature::cheat_signature; -use cheatcodes::execution_info::signature::start_cheat_signature_global; -use cheatcodes::execution_info::signature::stop_cheat_signature; -use cheatcodes::execution_info::signature::stop_cheat_signature_global; -use cheatcodes::execution_info::signature::start_cheat_signature; -use cheatcodes::execution_info::transaction_hash::cheat_transaction_hash; -use cheatcodes::execution_info::transaction_hash::start_cheat_transaction_hash_global; -use cheatcodes::execution_info::transaction_hash::stop_cheat_transaction_hash; -use cheatcodes::execution_info::transaction_hash::stop_cheat_transaction_hash_global; -use cheatcodes::execution_info::transaction_hash::start_cheat_transaction_hash; -use cheatcodes::execution_info::chain_id::cheat_chain_id; -use cheatcodes::execution_info::chain_id::start_cheat_chain_id_global; -use cheatcodes::execution_info::chain_id::stop_cheat_chain_id; -use cheatcodes::execution_info::chain_id::stop_cheat_chain_id_global; -use cheatcodes::execution_info::chain_id::start_cheat_chain_id; -use cheatcodes::execution_info::nonce::cheat_nonce; -use cheatcodes::execution_info::nonce::start_cheat_nonce_global; -use cheatcodes::execution_info::nonce::stop_cheat_nonce; -use cheatcodes::execution_info::nonce::stop_cheat_nonce_global; -use cheatcodes::execution_info::nonce::start_cheat_nonce; -use cheatcodes::execution_info::resource_bounds::cheat_resource_bounds; -use cheatcodes::execution_info::resource_bounds::start_cheat_resource_bounds_global; -use cheatcodes::execution_info::resource_bounds::stop_cheat_resource_bounds; -use cheatcodes::execution_info::resource_bounds::stop_cheat_resource_bounds_global; -use cheatcodes::execution_info::resource_bounds::start_cheat_resource_bounds; -use cheatcodes::execution_info::tip::cheat_tip; -use cheatcodes::execution_info::tip::start_cheat_tip_global; -use cheatcodes::execution_info::tip::stop_cheat_tip; -use cheatcodes::execution_info::tip::stop_cheat_tip_global; -use cheatcodes::execution_info::tip::start_cheat_tip; -use cheatcodes::execution_info::paymaster_data::cheat_paymaster_data; -use cheatcodes::execution_info::paymaster_data::start_cheat_paymaster_data_global; -use cheatcodes::execution_info::paymaster_data::stop_cheat_paymaster_data; -use cheatcodes::execution_info::paymaster_data::stop_cheat_paymaster_data_global; -use cheatcodes::execution_info::paymaster_data::start_cheat_paymaster_data; -use cheatcodes::execution_info::nonce_data_availability_mode::cheat_nonce_data_availability_mode; -use cheatcodes::execution_info::nonce_data_availability_mode::start_cheat_nonce_data_availability_mode_global; -use cheatcodes::execution_info::nonce_data_availability_mode::stop_cheat_nonce_data_availability_mode; -use cheatcodes::execution_info::nonce_data_availability_mode::stop_cheat_nonce_data_availability_mode_global; -use cheatcodes::execution_info::nonce_data_availability_mode::start_cheat_nonce_data_availability_mode; -use cheatcodes::execution_info::fee_data_availability_mode::cheat_fee_data_availability_mode; -use cheatcodes::execution_info::fee_data_availability_mode::start_cheat_fee_data_availability_mode_global; -use cheatcodes::execution_info::fee_data_availability_mode::stop_cheat_fee_data_availability_mode; -use cheatcodes::execution_info::fee_data_availability_mode::stop_cheat_fee_data_availability_mode_global; -use cheatcodes::execution_info::fee_data_availability_mode::start_cheat_fee_data_availability_mode; -use cheatcodes::execution_info::account_deployment_data::cheat_account_deployment_data; -use cheatcodes::execution_info::account_deployment_data::start_cheat_account_deployment_data_global; -use cheatcodes::execution_info::account_deployment_data::stop_cheat_account_deployment_data; -use cheatcodes::execution_info::account_deployment_data::stop_cheat_account_deployment_data_global; -use cheatcodes::execution_info::account_deployment_data::start_cheat_account_deployment_data; -use cheatcodes::execution_info::account_contract_address::cheat_account_contract_address; -use cheatcodes::execution_info::account_contract_address::start_cheat_account_contract_address_global; -use cheatcodes::execution_info::account_contract_address::stop_cheat_account_contract_address; -use cheatcodes::execution_info::account_contract_address::stop_cheat_account_contract_address_global; -use cheatcodes::execution_info::account_contract_address::start_cheat_account_contract_address; - -use cheatcodes::generate_random_felt::generate_random_felt; - - -mod fs; - -mod env; - -mod signature; - -mod trace; - -mod byte_array; +pub use cheatcodes::storage::store; +pub use cheatcodes::storage::load; +pub use cheatcodes::storage::map_entry_address; + +pub use cheatcodes::CheatSpan; +pub use cheatcodes::ReplaceBytecodeError; +pub use cheatcodes::test_address; +pub use cheatcodes::test_selector; +pub use cheatcodes::mock_call; +pub use cheatcodes::start_mock_call; +pub use cheatcodes::stop_mock_call; +pub use cheatcodes::replace_bytecode; + +pub use cheatcodes::execution_info::caller_address::cheat_caller_address; +pub use cheatcodes::execution_info::caller_address::start_cheat_caller_address_global; +pub use cheatcodes::execution_info::caller_address::stop_cheat_caller_address; +pub use cheatcodes::execution_info::caller_address::stop_cheat_caller_address_global; +pub use cheatcodes::execution_info::caller_address::start_cheat_caller_address; +pub use cheatcodes::execution_info::block_number::cheat_block_number; +pub use cheatcodes::execution_info::block_number::start_cheat_block_number_global; +pub use cheatcodes::execution_info::block_number::stop_cheat_block_number; +pub use cheatcodes::execution_info::block_number::stop_cheat_block_number_global; +pub use cheatcodes::execution_info::block_number::start_cheat_block_number; +pub use cheatcodes::execution_info::block_timestamp::cheat_block_timestamp; +pub use cheatcodes::execution_info::block_timestamp::start_cheat_block_timestamp_global; +pub use cheatcodes::execution_info::block_timestamp::stop_cheat_block_timestamp; +pub use cheatcodes::execution_info::block_timestamp::stop_cheat_block_timestamp_global; +pub use cheatcodes::execution_info::block_timestamp::start_cheat_block_timestamp; +pub use cheatcodes::execution_info::sequencer_address::cheat_sequencer_address; +pub use cheatcodes::execution_info::sequencer_address::start_cheat_sequencer_address_global; +pub use cheatcodes::execution_info::sequencer_address::stop_cheat_sequencer_address; +pub use cheatcodes::execution_info::sequencer_address::stop_cheat_sequencer_address_global; +pub use cheatcodes::execution_info::sequencer_address::start_cheat_sequencer_address; +pub use cheatcodes::execution_info::version::cheat_transaction_version; +pub use cheatcodes::execution_info::version::start_cheat_transaction_version_global; +pub use cheatcodes::execution_info::version::stop_cheat_transaction_version; +pub use cheatcodes::execution_info::version::stop_cheat_transaction_version_global; +pub use cheatcodes::execution_info::version::start_cheat_transaction_version; +pub use cheatcodes::execution_info::max_fee::cheat_max_fee; +pub use cheatcodes::execution_info::max_fee::start_cheat_max_fee_global; +pub use cheatcodes::execution_info::max_fee::stop_cheat_max_fee; +pub use cheatcodes::execution_info::max_fee::stop_cheat_max_fee_global; +pub use cheatcodes::execution_info::max_fee::start_cheat_max_fee; +pub use cheatcodes::execution_info::signature::cheat_signature; +pub use cheatcodes::execution_info::signature::start_cheat_signature_global; +pub use cheatcodes::execution_info::signature::stop_cheat_signature; +pub use cheatcodes::execution_info::signature::stop_cheat_signature_global; +pub use cheatcodes::execution_info::signature::start_cheat_signature; +pub use cheatcodes::execution_info::transaction_hash::cheat_transaction_hash; +pub use cheatcodes::execution_info::transaction_hash::start_cheat_transaction_hash_global; +pub use cheatcodes::execution_info::transaction_hash::stop_cheat_transaction_hash; +pub use cheatcodes::execution_info::transaction_hash::stop_cheat_transaction_hash_global; +pub use cheatcodes::execution_info::transaction_hash::start_cheat_transaction_hash; +pub use cheatcodes::execution_info::chain_id::cheat_chain_id; +pub use cheatcodes::execution_info::chain_id::start_cheat_chain_id_global; +pub use cheatcodes::execution_info::chain_id::stop_cheat_chain_id; +pub use cheatcodes::execution_info::chain_id::stop_cheat_chain_id_global; +pub use cheatcodes::execution_info::chain_id::start_cheat_chain_id; +pub use cheatcodes::execution_info::nonce::cheat_nonce; +pub use cheatcodes::execution_info::nonce::start_cheat_nonce_global; +pub use cheatcodes::execution_info::nonce::stop_cheat_nonce; +pub use cheatcodes::execution_info::nonce::stop_cheat_nonce_global; +pub use cheatcodes::execution_info::nonce::start_cheat_nonce; +pub use cheatcodes::execution_info::resource_bounds::cheat_resource_bounds; +pub use cheatcodes::execution_info::resource_bounds::start_cheat_resource_bounds_global; +pub use cheatcodes::execution_info::resource_bounds::stop_cheat_resource_bounds; +pub use cheatcodes::execution_info::resource_bounds::stop_cheat_resource_bounds_global; +pub use cheatcodes::execution_info::resource_bounds::start_cheat_resource_bounds; +pub use cheatcodes::execution_info::tip::cheat_tip; +pub use cheatcodes::execution_info::tip::start_cheat_tip_global; +pub use cheatcodes::execution_info::tip::stop_cheat_tip; +pub use cheatcodes::execution_info::tip::stop_cheat_tip_global; +pub use cheatcodes::execution_info::tip::start_cheat_tip; +pub use cheatcodes::execution_info::paymaster_data::cheat_paymaster_data; +pub use cheatcodes::execution_info::paymaster_data::start_cheat_paymaster_data_global; +pub use cheatcodes::execution_info::paymaster_data::stop_cheat_paymaster_data; +pub use cheatcodes::execution_info::paymaster_data::stop_cheat_paymaster_data_global; +pub use cheatcodes::execution_info::paymaster_data::start_cheat_paymaster_data; +pub use cheatcodes::execution_info::nonce_data_availability_mode::cheat_nonce_data_availability_mode; +pub use cheatcodes::execution_info::nonce_data_availability_mode::start_cheat_nonce_data_availability_mode_global; +pub use cheatcodes::execution_info::nonce_data_availability_mode::stop_cheat_nonce_data_availability_mode; +pub use cheatcodes::execution_info::nonce_data_availability_mode::stop_cheat_nonce_data_availability_mode_global; +pub use cheatcodes::execution_info::nonce_data_availability_mode::start_cheat_nonce_data_availability_mode; +pub use cheatcodes::execution_info::fee_data_availability_mode::cheat_fee_data_availability_mode; +pub use cheatcodes::execution_info::fee_data_availability_mode::start_cheat_fee_data_availability_mode_global; +pub use cheatcodes::execution_info::fee_data_availability_mode::stop_cheat_fee_data_availability_mode; +pub use cheatcodes::execution_info::fee_data_availability_mode::stop_cheat_fee_data_availability_mode_global; +pub use cheatcodes::execution_info::fee_data_availability_mode::start_cheat_fee_data_availability_mode; +pub use cheatcodes::execution_info::account_deployment_data::cheat_account_deployment_data; +pub use cheatcodes::execution_info::account_deployment_data::start_cheat_account_deployment_data_global; +pub use cheatcodes::execution_info::account_deployment_data::stop_cheat_account_deployment_data; +pub use cheatcodes::execution_info::account_deployment_data::stop_cheat_account_deployment_data_global; +pub use cheatcodes::execution_info::account_deployment_data::start_cheat_account_deployment_data; +pub use cheatcodes::execution_info::account_contract_address::cheat_account_contract_address; +pub use cheatcodes::execution_info::account_contract_address::start_cheat_account_contract_address_global; +pub use cheatcodes::execution_info::account_contract_address::stop_cheat_account_contract_address; +pub use cheatcodes::execution_info::account_contract_address::stop_cheat_account_contract_address_global; +pub use cheatcodes::execution_info::account_contract_address::start_cheat_account_contract_address; + +pub use cheatcodes::generate_random_felt::generate_random_felt; + + +pub mod fs; + +pub mod env; + +pub mod signature; + +pub mod trace; + +pub mod byte_array; + +pub mod _config_types; mod _cheatcode; -mod _config_types; +pub mod _internals { + use super::_cheatcode; + + pub use _cheatcode::_is_config_run; +} diff --git a/snforge_std/src/signature.cairo b/snforge_std/src/signature.cairo index 316a7f0149..da36119868 100644 --- a/snforge_std/src/signature.cairo +++ b/snforge_std/src/signature.cairo @@ -1,23 +1,23 @@ -mod secp256k1_curve; -mod secp256r1_curve; -mod stark_curve; +pub mod secp256k1_curve; +pub mod secp256r1_curve; +pub mod stark_curve; #[derive(Copy, Drop)] -struct KeyPair { +pub struct KeyPair { /// A key that is used for signing the messages - secret_key: SK, + pub secret_key: SK, /// A (x, y) point on the elliptic curve used for verification of the signature - public_key: PK, + pub public_key: PK, } -trait KeyPairTrait { +pub trait KeyPairTrait { /// Generates the private and public keys using the built-in random generator fn generate() -> KeyPair; /// Derives the KeyPair (`secret_key` + `public_key`) using `secret_key` fn from_secret_key(secret_key: SK) -> KeyPair; } -trait SignerTrait { +pub trait SignerTrait { /// Signs given message hash /// `self` - KeyPair used for signing /// `message_hash` - input to sign bounded by the curve type (u256 for 256bit curves, felt252 @@ -26,7 +26,7 @@ trait SignerTrait { fn sign(self: T, message_hash: H) -> Result; } -trait VerifierTrait { +pub trait VerifierTrait { /// `self` - KeyPair used for verifying /// `message_hash` - input to verify bounded by the curve type (u256 for 256bit curves, felt252 /// for StarkCurve) @@ -36,7 +36,7 @@ trait VerifierTrait { } #[derive(Copy, Drop, Serde, PartialEq)] -enum SignError { +pub enum SignError { InvalidSecretKey, HashOutOfRange } diff --git a/snforge_std/src/signature/secp256k1_curve.cairo b/snforge_std/src/signature/secp256k1_curve.cairo index 21ae306435..38a11cec74 100644 --- a/snforge_std/src/signature/secp256k1_curve.cairo +++ b/snforge_std/src/signature/secp256k1_curve.cairo @@ -1,7 +1,7 @@ use core::serde::Serde; use core::option::OptionTrait; -use starknet::secp256_trait::{is_valid_signature}; -use starknet::secp256k1::{Secp256k1Point, Secp256k1Impl, Secp256k1PointImpl}; +use starknet::secp256k1::Secp256k1Point; +use starknet::secp256_trait::{is_valid_signature, Secp256Trait, Secp256PointTrait}; use starknet::{SyscallResultTrait}; use starknet::testing::cheatcode; use super::super::_cheatcode::handle_cheatcode; @@ -9,7 +9,7 @@ use super::SignError; use snforge_std::signature::{KeyPair, KeyPairTrait, SignerTrait, VerifierTrait}; -impl Secp256k1CurveKeyPairImpl of KeyPairTrait { +pub impl Secp256k1CurveKeyPairImpl of KeyPairTrait { fn generate() -> KeyPair { let mut output = handle_cheatcode( cheatcode::<'generate_ecdsa_keys'>(array!['Secp256k1'].span()) @@ -17,27 +17,28 @@ impl Secp256k1CurveKeyPairImpl of KeyPairTrait { let (secret_key, pk_x, pk_y): (u256, u256, u256) = Serde::deserialize(ref output).unwrap(); - let public_key = Secp256k1Impl::secp256_ec_new_syscall(pk_x, pk_y) - .unwrap_syscall() - .unwrap(); + let public_key = Secp256Trait::secp256_ec_new_syscall(pk_x, pk_y).unwrap_syscall().unwrap(); KeyPair { secret_key, public_key } } fn from_secret_key(secret_key: u256) -> KeyPair { - if (secret_key == 0_u256 || secret_key >= Secp256k1Impl::get_curve_size()) { + if (secret_key == 0_u256 + || secret_key >= Secp256Trait::::get_curve_size()) { core::panic_with_felt252('invalid secret_key'); } - let generator = Secp256k1Impl::get_generator_point(); + let generator = Secp256Trait::get_generator_point(); - let public_key = Secp256k1PointImpl::mul(generator, secret_key).unwrap_syscall(); + let public_key = Secp256PointTrait::mul(generator, secret_key).unwrap_syscall(); KeyPair { secret_key, public_key } } } -impl Secp256k1CurveSignerImpl of SignerTrait, u256, (u256, u256)> { +pub impl Secp256k1CurveSignerImpl of SignerTrait< + KeyPair, u256, (u256, u256) +> { fn sign( self: KeyPair, message_hash: u256 ) -> Result<(u256, u256), SignError> { @@ -51,7 +52,7 @@ impl Secp256k1CurveSignerImpl of SignerTrait, u256 } } -impl Secp256k1CurveVerifierImpl of VerifierTrait< +pub impl Secp256k1CurveVerifierImpl of VerifierTrait< KeyPair, u256, (u256, u256) > { fn verify( diff --git a/snforge_std/src/signature/secp256r1_curve.cairo b/snforge_std/src/signature/secp256r1_curve.cairo index 6bcd909eb9..ce506c018d 100644 --- a/snforge_std/src/signature/secp256r1_curve.cairo +++ b/snforge_std/src/signature/secp256r1_curve.cairo @@ -1,12 +1,12 @@ -use starknet::secp256_trait::{is_valid_signature}; -use starknet::secp256r1::{Secp256r1Point, Secp256r1Impl, Secp256r1PointImpl}; +use starknet::secp256r1::{Secp256r1Point}; +use starknet::secp256_trait::{is_valid_signature, Secp256Trait, Secp256PointTrait}; use starknet::{SyscallResultTrait}; use starknet::testing::cheatcode; use super::super::_cheatcode::handle_cheatcode; use super::SignError; use snforge_std::signature::{KeyPair, KeyPairTrait, SignerTrait, VerifierTrait}; -impl Secp256r1CurveKeyPairImpl of KeyPairTrait { +pub impl Secp256r1CurveKeyPairImpl of KeyPairTrait { fn generate() -> KeyPair { let mut output = handle_cheatcode( cheatcode::<'generate_ecdsa_keys'>(array!['Secp256r1'].span()) @@ -14,27 +14,28 @@ impl Secp256r1CurveKeyPairImpl of KeyPairTrait { let (secret_key, pk_x, pk_y): (u256, u256, u256) = Serde::deserialize(ref output).unwrap(); - let public_key = Secp256r1Impl::secp256_ec_new_syscall(pk_x, pk_y) - .unwrap_syscall() - .unwrap(); + let public_key = Secp256Trait::secp256_ec_new_syscall(pk_x, pk_y).unwrap_syscall().unwrap(); KeyPair { secret_key, public_key } } fn from_secret_key(secret_key: u256) -> KeyPair { - if (secret_key == 0_u256 || secret_key >= Secp256r1Impl::get_curve_size()) { + if (secret_key == 0_u256 + || secret_key >= Secp256Trait::::get_curve_size()) { core::panic_with_felt252('invalid secret_key'); } - let generator = Secp256r1Impl::get_generator_point(); + let generator = Secp256Trait::get_generator_point(); - let public_key = Secp256r1PointImpl::mul(generator, secret_key).unwrap_syscall(); + let public_key = Secp256PointTrait::mul(generator, secret_key).unwrap_syscall(); KeyPair { secret_key, public_key } } } -impl Secp256r1CurveSignerImpl of SignerTrait, u256, (u256, u256)> { +pub impl Secp256r1CurveSignerImpl of SignerTrait< + KeyPair, u256, (u256, u256) +> { fn sign( self: KeyPair, message_hash: u256 ) -> Result<(u256, u256), SignError> { @@ -48,7 +49,7 @@ impl Secp256r1CurveSignerImpl of SignerTrait, u256 } } -impl Secp256r1CurveVerifierImpl of VerifierTrait< +pub impl Secp256r1CurveVerifierImpl of VerifierTrait< KeyPair, u256, (u256, u256) > { fn verify( diff --git a/snforge_std/src/signature/stark_curve.cairo b/snforge_std/src/signature/stark_curve.cairo index c87b81075d..236b2f0751 100644 --- a/snforge_std/src/signature/stark_curve.cairo +++ b/snforge_std/src/signature/stark_curve.cairo @@ -7,7 +7,7 @@ use starknet::testing::cheatcode; use snforge_std::signature::{KeyPair, KeyPairTrait, SignerTrait, VerifierTrait}; -impl StarkCurveKeyPairImpl of KeyPairTrait { +pub impl StarkCurveKeyPairImpl of KeyPairTrait { fn generate() -> KeyPair { let mut output = handle_cheatcode(cheatcode::<'generate_stark_keys'>(array![].span())); @@ -31,7 +31,9 @@ impl StarkCurveKeyPairImpl of KeyPairTrait { } } -impl StarkCurveSignerImpl of SignerTrait, felt252, (felt252, felt252)> { +pub impl StarkCurveSignerImpl of SignerTrait< + KeyPair, felt252, (felt252, felt252) +> { fn sign( self: KeyPair, message_hash: felt252 ) -> Result<(felt252, felt252), SignError> { @@ -43,7 +45,7 @@ impl StarkCurveSignerImpl of SignerTrait, felt252, (fe } } -impl StarkCurveVerifierImpl of VerifierTrait< +pub impl StarkCurveVerifierImpl of VerifierTrait< KeyPair, felt252, (felt252, felt252) > { fn verify( diff --git a/snforge_std/src/trace.cairo b/snforge_std/src/trace.cairo index ec2f0d9090..8efd6db2ce 100644 --- a/snforge_std/src/trace.cairo +++ b/snforge_std/src/trace.cairo @@ -6,31 +6,31 @@ use super::_cheatcode::handle_cheatcode; /// Tree-like structure which contains all of the starknet calls and sub-calls along with the /// results #[derive(Drop, Serde, PartialEq, Clone, Debug)] -struct CallTrace { - entry_point: CallEntryPoint, +pub struct CallTrace { + pub entry_point: CallEntryPoint, /// All the calls that happened in the scope of `entry_point` - nested_calls: Array, - result: CallResult, + pub nested_calls: Array, + pub result: CallResult, } /// A single function entry point summary #[derive(Drop, Serde, PartialEq, Clone, Debug)] -struct CallEntryPoint { - entry_point_type: EntryPointType, +pub struct CallEntryPoint { + pub entry_point_type: EntryPointType, /// Hashed selector of the invoked function - entry_point_selector: felt252, + pub entry_point_selector: felt252, /// Serialized arguments calldata - calldata: Array, + pub calldata: Array, /// Contract address targeted by the call - contract_address: ContractAddress, + pub contract_address: ContractAddress, /// Address that the call originates from - caller_address: ContractAddress, - call_type: CallType, + pub caller_address: ContractAddress, + pub call_type: CallType, } /// Type of the function being invoked #[derive(Drop, Serde, PartialEq, Clone, Debug)] -enum EntryPointType { +pub enum EntryPointType { /// Constructor of a contract Constructor, /// Contract interface entry point @@ -41,7 +41,7 @@ enum EntryPointType { /// Denotes type of the call #[derive(Drop, Serde, PartialEq, Clone, Debug)] -enum CallType { +pub enum CallType { /// Regular call Call, /// Library call @@ -50,7 +50,7 @@ enum CallType { /// Result of a contract or a library call #[derive(Drop, Serde, PartialEq, Clone, Debug)] -enum CallResult { +pub enum CallResult { /// A successful call with it's result Success: Array, /// A failed call along with it's panic data @@ -59,7 +59,7 @@ enum CallResult { /// Represents a pre-processed failure of a call #[derive(Drop, Serde, PartialEq, Clone, Debug)] -enum CallFailure { +pub enum CallFailure { /// Contains raw panic data Panic: Array, /// Contains panic data in parsed form, if parsing is applicable @@ -67,7 +67,7 @@ enum CallFailure { } /// Returns current call trace of the test, up to the last call made to a contract -fn get_call_trace() -> CallTrace { +pub fn get_call_trace() -> CallTrace { let mut output = handle_cheatcode(cheatcode::<'get_call_trace'>(array![].span())); Serde::deserialize(ref output).unwrap() }