diff --git a/.tool-versions b/.tool-versions index 045dc3e7cc..9c09384422 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1,2 @@ scarb 2.7.0 +starknet-foundry 0.28.0 diff --git a/crates/forge/tests/data/component_macros/tests/test_contract.cairo b/crates/forge/tests/data/component_macros/tests/test_contract.cairo index 35a498062f..e375b5e3e5 100644 --- a/crates/forge/tests/data/component_macros/tests/test_contract.cairo +++ b/crates/forge/tests/data/component_macros/tests/test_contract.cairo @@ -14,7 +14,7 @@ use component_macros::example::{IMyContractDispatcherTrait, IMyContractDispatche #[test] fn test_mint() { let contract = declare("MyContract").unwrap().contract_class(); - let (address, _) = contract.deploy(@array!['minter']).unwrap(); + let (address, _) = contract.deploy(['minter'].span()).unwrap(); let minter: ContractAddress = 'minter'.try_into().unwrap(); let dispatcher = IMyContractDispatcher { contract_address: address }; diff --git a/crates/forge/tests/data/contract_printing/tests/test_contract.cairo b/crates/forge/tests/data/contract_printing/tests/test_contract.cairo index 2b269c991a..affc23d692 100644 --- a/crates/forge/tests/data/contract_printing/tests/test_contract.cairo +++ b/crates/forge/tests/data/contract_printing/tests/test_contract.cairo @@ -15,7 +15,7 @@ use contract_printing::IHelloStarknetDispatcherTrait; fn deploy_contract(name: ByteArray) -> ContractAddress { let contract = declare(name).unwrap().contract_class(); - let (address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (address, _) = contract.deploy([].span()).unwrap(); address } diff --git a/crates/forge/tests/data/contracts/benchmarks/test_declare_deploy_interact.cairo b/crates/forge/tests/data/contracts/benchmarks/test_declare_deploy_interact.cairo index cd2705486e..d99d56bd58 100644 --- a/crates/forge/tests/data/contracts/benchmarks/test_declare_deploy_interact.cairo +++ b/crates/forge/tests/data/contracts/benchmarks/test_declare_deploy_interact.cairo @@ -3,7 +3,10 @@ use traits::Into; use starknet::ClassHashIntoFelt252; use starknet::ContractAddress; use starknet::Felt252TryIntoContractAddress; -use snforge_std::{declare, ContractAddress, ContractClassTrait, start_cheat_caller_address, start_cheat_block_number, start_cheat_block_timestamp}; +use snforge_std::{ + declare, ContractClassTrait, start_cheat_caller_address, + start_cheat_block_number, start_cheat_block_timestamp +}; #[starknet::interface] trait IHelloStarknet { @@ -17,7 +20,7 @@ trait IHelloStarknet { fn declare_and_interact() { assert(1 == 1, 'simple check'); let contract = declare("HelloStarknet").unwrap(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = IHelloStarknetDispatcher { contract_address }; dispatcher.get_balance(); diff --git a/crates/forge/tests/data/erc20_package/tests/test_complex.cairo b/crates/forge/tests/data/erc20_package/tests/test_complex.cairo index a8eeaa2742..d2e2ef16bb 100644 --- a/crates/forge/tests/data/erc20_package/tests/test_complex.cairo +++ b/crates/forge/tests/data/erc20_package/tests/test_complex.cairo @@ -27,7 +27,7 @@ fn deploy_erc20( constructor_calldata.append_span(initial_supply_serialized.span()); constructor_calldata.append(recipient.into()); - let (address, _) = contract.deploy(@constructor_calldata).unwrap(); + let (address, _) = contract.deploy(constructor_calldata.span()).unwrap(); address } diff --git a/crates/forge/tests/data/simple_package/tests/contract.cairo b/crates/forge/tests/data/simple_package/tests/contract.cairo index 93d781a13a..b82afd00da 100644 --- a/crates/forge/tests/data/simple_package/tests/contract.cairo +++ b/crates/forge/tests/data/simple_package/tests/contract.cairo @@ -14,7 +14,7 @@ use simple_package::hello_starknet::IHelloStarknetDispatcherTrait; #[test] fn call_and_invoke() { let contract = declare("HelloStarknet").unwrap().contract_class(); - let constructor_calldata = @ArrayTrait::new(); + let constructor_calldata = [].span(); let (contract_address, _) = contract.deploy(constructor_calldata).unwrap(); let dispatcher = IHelloStarknetDispatcher { contract_address }; diff --git a/crates/forge/tests/data/trace/tests/test_trace.cairo b/crates/forge/tests/data/trace/tests/test_trace.cairo index c3f9eef49e..e3496bda83 100644 --- a/crates/forge/tests/data/trace/tests/test_trace.cairo +++ b/crates/forge/tests/data/trace/tests/test_trace.cairo @@ -12,9 +12,9 @@ use trace_info::{ fn test_trace() { let sc = declare("SimpleContract").unwrap().contract_class(); - let (contract_address_A, _) = sc.deploy(@array![]).unwrap(); - let (contract_address_B, _) = sc.deploy(@array![]).unwrap(); - let (contract_address_C, _) = sc.deploy(@array![]).unwrap(); + let (contract_address_A, _) = sc.deploy([].span()).unwrap(); + let (contract_address_B, _) = sc.deploy([].span()).unwrap(); + let (contract_address_C, _) = sc.deploy([].span()).unwrap(); let calls = array![ RecursiveCall { diff --git a/crates/forge/tests/data/trace_resources/tests/test_call.cairo b/crates/forge/tests/data/trace_resources/tests/test_call.cairo index 54ca981613..4d5c56f377 100644 --- a/crates/forge/tests/data/trace_resources/tests/test_call.cairo +++ b/crates/forge/tests/data/trace_resources/tests/test_call.cairo @@ -15,11 +15,11 @@ fn test_call() { trace_resources::use_builtins_and_syscalls(empty_hash, 7); - let (checker_address, _) = checker.deploy(@array![]).unwrap(); + let (checker_address, _) = checker.deploy([].span()).unwrap(); let (proxy_address, _) = proxy - .deploy(@array![checker_address.into(), empty_hash.into(), 5]) + .deploy([checker_address.into(), empty_hash.into(), 5].span()) .unwrap(); - let (dummy_address, _) = dummy.deploy(@array![]).unwrap(); + let (dummy_address, _) = dummy.deploy([].span()).unwrap(); let proxy_dispatcher = ITraceInfoProxyDispatcher { contract_address: proxy_address }; proxy_dispatcher.regular_call(checker_address, empty_hash, 1); diff --git a/crates/forge/tests/data/trace_resources/tests/test_deploy.cairo b/crates/forge/tests/data/trace_resources/tests/test_deploy.cairo index 3e068063f5..9590606e77 100644 --- a/crates/forge/tests/data/trace_resources/tests/test_deploy.cairo +++ b/crates/forge/tests/data/trace_resources/tests/test_deploy.cairo @@ -11,9 +11,9 @@ fn test_deploy() { trace_resources::use_builtins_and_syscalls(empty_hash, 7); - let (checker_address, _) = checker.deploy(@array![]).unwrap(); + let (checker_address, _) = checker.deploy([].span()).unwrap(); - proxy.deploy(@array![checker_address.into(), empty_hash.into(), 1]).unwrap(); + proxy.deploy([checker_address.into(), empty_hash.into(), 1].span()).unwrap(); deploy_syscall( proxy.class_hash, 0, array![checker_address.into(), empty_hash.into(), 2].span(), false @@ -21,7 +21,7 @@ fn test_deploy() { .unwrap_syscall(); proxy - .deploy_at(@array![checker_address.into(), empty_hash.into(), 3], 123.try_into().unwrap()) + .deploy_at([checker_address.into(), empty_hash.into(), 3].span(), 123.try_into().unwrap()) .unwrap(); deploy_syscall( diff --git a/crates/forge/tests/data/trace_resources/tests/test_failed_call.cairo b/crates/forge/tests/data/trace_resources/tests/test_failed_call.cairo index 52a29495ce..02cf4fc7a5 100644 --- a/crates/forge/tests/data/trace_resources/tests/test_failed_call.cairo +++ b/crates/forge/tests/data/trace_resources/tests/test_failed_call.cairo @@ -16,9 +16,9 @@ fn test_failed_call() { trace_resources::use_builtins_and_syscalls(empty_hash, 7); - let (checker_address, _) = checker.deploy(@array![]).unwrap(); + let (checker_address, _) = checker.deploy([].span()).unwrap(); let (proxy_address, _) = proxy - .deploy(@array![checker_address.into(), empty_hash.into(), 1]) + .deploy([checker_address.into(), empty_hash.into(), 1].span()) .unwrap(); let proxy_dispatcher = ITraceInfoProxySafeDispatcher { contract_address: proxy_address }; diff --git a/crates/forge/tests/data/trace_resources/tests/test_failed_lib_call.cairo b/crates/forge/tests/data/trace_resources/tests/test_failed_lib_call.cairo index 1d82e4bacf..794c346e7a 100644 --- a/crates/forge/tests/data/trace_resources/tests/test_failed_lib_call.cairo +++ b/crates/forge/tests/data/trace_resources/tests/test_failed_lib_call.cairo @@ -15,7 +15,7 @@ fn test_failed_lib_call() { let empty_hash = declare("Empty").unwrap().contract_class().class_hash.clone(); let proxy_hash = declare("TraceInfoProxy").unwrap().contract_class().class_hash.clone(); let checker = declare("TraceInfoChecker").unwrap().contract_class().clone(); - let (checker_address, _) = checker.deploy(@array![]).unwrap(); + let (checker_address, _) = checker.deploy([].span()).unwrap(); trace_resources::use_builtins_and_syscalls(empty_hash, 7); diff --git a/crates/forge/tests/data/trace_resources/tests/test_l1_handler.cairo b/crates/forge/tests/data/trace_resources/tests/test_l1_handler.cairo index 7f7b79e919..3b43adfe28 100644 --- a/crates/forge/tests/data/trace_resources/tests/test_l1_handler.cairo +++ b/crates/forge/tests/data/trace_resources/tests/test_l1_handler.cairo @@ -10,9 +10,9 @@ fn test_l1_handler() { trace_resources::use_builtins_and_syscalls(empty_hash, 7); - let (checker_address, _) = checker.deploy(@array![]).unwrap(); + let (checker_address, _) = checker.deploy([].span()).unwrap(); let (proxy_address, _) = proxy - .deploy(@array![checker_address.into(), empty_hash.into(), 1]) + .deploy([checker_address.into(), empty_hash.into(), 1].span()) .unwrap(); let mut l1_handler = L1HandlerTrait::new(checker_address, selector!("handle_l1_message")); diff --git a/crates/forge/tests/data/trace_resources/tests/test_lib_call.cairo b/crates/forge/tests/data/trace_resources/tests/test_lib_call.cairo index 880d7a2b4f..a3fdf0bf61 100644 --- a/crates/forge/tests/data/trace_resources/tests/test_lib_call.cairo +++ b/crates/forge/tests/data/trace_resources/tests/test_lib_call.cairo @@ -16,8 +16,8 @@ fn test_lib_call() { trace_resources::use_builtins_and_syscalls(empty_hash, 7); - let (checker_address, _) = checker.deploy(@array![]).unwrap(); - let (dummy_address, _) = dummy.deploy(@array![]).unwrap(); + let (checker_address, _) = checker.deploy([].span()).unwrap(); + let (dummy_address, _) = dummy.deploy([].span()).unwrap(); let proxy_lib_dispatcher = ITraceInfoProxyLibraryDispatcher { class_hash: proxy_hash }; diff --git a/crates/forge/tests/integration/cheat_block_number.rs b/crates/forge/tests/integration/cheat_block_number.rs index 35145518a0..142a6574e4 100644 --- a/crates/forge/tests/integration/cheat_block_number.rs +++ b/crates/forge/tests/integration/cheat_block_number.rs @@ -28,7 +28,7 @@ fn cheat_block_number_basic() { #[test] fn test_stop_cheat_block_number() { let contract = declare("CheatBlockNumberChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = ICheatBlockNumberCheckerDispatcher { contract_address }; let old_block_number = dispatcher.get_block_number(); @@ -48,8 +48,8 @@ fn cheat_block_number_basic() { fn test_cheat_block_number_multiple() { let contract = declare("CheatBlockNumberChecker").unwrap().contract_class(); - let (contract_address1, _) = contract.deploy(@ArrayTrait::new()).unwrap(); - let (contract_address2, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address1, _) = contract.deploy([].span()).unwrap(); + let (contract_address2, _) = contract.deploy([].span()).unwrap(); let cheat_block_number_checker1 = ICheatBlockNumberCheckerDispatcher { contract_address: contract_address1 }; let cheat_block_number_checker2 = ICheatBlockNumberCheckerDispatcher { contract_address: contract_address2 }; @@ -77,8 +77,8 @@ fn cheat_block_number_basic() { fn test_cheat_block_number_all() { let contract = declare("CheatBlockNumberChecker").unwrap().contract_class(); - let (contract_address1, _) = contract.deploy(@ArrayTrait::new()).unwrap(); - let (contract_address2, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address1, _) = contract.deploy([].span()).unwrap(); + let (contract_address2, _) = contract.deploy([].span()).unwrap(); let cheat_block_number_checker1 = ICheatBlockNumberCheckerDispatcher { contract_address: contract_address1 }; let cheat_block_number_checker2 = ICheatBlockNumberCheckerDispatcher { contract_address: contract_address2 }; @@ -106,7 +106,7 @@ fn cheat_block_number_basic() { #[test] fn test_cheat_block_number_all_stop_one() { let contract = declare("CheatBlockNumberChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = ICheatBlockNumberCheckerDispatcher { contract_address }; let old_block_number = dispatcher.get_block_number(); @@ -155,7 +155,7 @@ fn cheat_block_number_complex() { fn deploy_cheat_block_number_checker() -> ICheatBlockNumberCheckerDispatcher { let contract = declare("CheatBlockNumberChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); ICheatBlockNumberCheckerDispatcher { contract_address } } @@ -163,8 +163,8 @@ fn cheat_block_number_complex() { fn cheat_block_number_complex() { let contract = declare("CheatBlockNumberChecker").unwrap().contract_class(); - let (contract_address1, _) = contract.deploy(@ArrayTrait::new()).unwrap(); - let (contract_address2, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address1, _) = contract.deploy([].span()).unwrap(); + let (contract_address2, _) = contract.deploy([].span()).unwrap(); let cheat_block_number_checker1 = ICheatBlockNumberCheckerDispatcher { contract_address: contract_address1 }; let cheat_block_number_checker2 = ICheatBlockNumberCheckerDispatcher { contract_address: contract_address2 }; @@ -237,7 +237,7 @@ fn cheat_block_number_with_span() { } fn deploy_cheat_block_number_checker() -> ICheatBlockNumberCheckerDispatcher { - let (contract_address, _) = declare("CheatBlockNumberChecker").unwrap().contract_class().deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = declare("CheatBlockNumberChecker").unwrap().contract_class().deploy([].span()).unwrap(); ICheatBlockNumberCheckerDispatcher { contract_address } } diff --git a/crates/forge/tests/integration/cheat_block_timestamp.rs b/crates/forge/tests/integration/cheat_block_timestamp.rs index 3712710b6c..1ac778406f 100644 --- a/crates/forge/tests/integration/cheat_block_timestamp.rs +++ b/crates/forge/tests/integration/cheat_block_timestamp.rs @@ -27,7 +27,7 @@ fn cheat_block_timestamp_basic() { fn deploy_cheat_block_timestamp_checker() -> ICheatBlockTimestampCheckerDispatcher { let contract = declare("CheatBlockTimestampChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); ICheatBlockTimestampCheckerDispatcher { contract_address } } @@ -69,8 +69,8 @@ fn cheat_block_timestamp_basic() { fn cheat_block_timestamp_multiple() { let contract = declare("CheatBlockTimestampChecker").unwrap().contract_class(); - let (contract_address1, _) = contract.deploy(@ArrayTrait::new()).unwrap(); - let (contract_address2, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address1, _) = contract.deploy([].span()).unwrap(); + let (contract_address2, _) = contract.deploy([].span()).unwrap(); let cheat_block_timestamp_checker1 = ICheatBlockTimestampCheckerDispatcher { contract_address: contract_address1 }; let cheat_block_timestamp_checker2 = ICheatBlockTimestampCheckerDispatcher { contract_address: contract_address2 }; @@ -101,8 +101,8 @@ fn cheat_block_timestamp_basic() { fn cheat_block_timestamp_all() { let contract = declare("CheatBlockTimestampChecker").unwrap().contract_class(); - let (contract_address1, _) = contract.deploy(@ArrayTrait::new()).unwrap(); - let (contract_address2, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address1, _) = contract.deploy([].span()).unwrap(); + let (contract_address2, _) = contract.deploy([].span()).unwrap(); let cheat_block_timestamp_checker1 = ICheatBlockTimestampCheckerDispatcher { contract_address: contract_address1 }; let cheat_block_timestamp_checker2 = ICheatBlockTimestampCheckerDispatcher { contract_address: contract_address2 }; @@ -163,7 +163,7 @@ fn cheat_block_timestamp_complex() { fn deploy_cheat_block_timestamp_checker() -> ICheatBlockTimestampCheckerDispatcher { let contract = declare("CheatBlockTimestampChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); ICheatBlockTimestampCheckerDispatcher { contract_address } } @@ -171,8 +171,8 @@ fn cheat_block_timestamp_complex() { fn cheat_block_timestamp_complex() { let contract = declare("CheatBlockTimestampChecker").unwrap().contract_class(); - let (contract_address1, _) = contract.deploy(@ArrayTrait::new()).unwrap(); - let (contract_address2, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address1, _) = contract.deploy([].span()).unwrap(); + let (contract_address2, _) = contract.deploy([].span()).unwrap(); let cheat_block_timestamp_checker1 = ICheatBlockTimestampCheckerDispatcher { contract_address: contract_address1 }; let cheat_block_timestamp_checker2 = ICheatBlockTimestampCheckerDispatcher { contract_address: contract_address2 }; @@ -245,7 +245,7 @@ fn cheat_block_timestamp_with_span() { } fn deploy_cheat_block_timestamp_checker() -> ICheatBlockTimestampCheckerDispatcher { - let (contract_address, _) = declare("CheatBlockTimestampChecker").unwrap().contract_class().deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = declare("CheatBlockTimestampChecker").unwrap().contract_class().deploy([].span()).unwrap(); ICheatBlockTimestampCheckerDispatcher { contract_address } } diff --git a/crates/forge/tests/integration/cheat_caller_address.rs b/crates/forge/tests/integration/cheat_caller_address.rs index 21ab5f9195..fd5db62bf4 100644 --- a/crates/forge/tests/integration/cheat_caller_address.rs +++ b/crates/forge/tests/integration/cheat_caller_address.rs @@ -25,7 +25,7 @@ fn cheat_caller_address() { #[test] fn test_stop_cheat_caller_address() { let contract = declare("CheatCallerAddressChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = ICheatCallerAddressCheckerDispatcher { contract_address }; let target_caller_address: felt252 = 123; @@ -47,7 +47,7 @@ fn cheat_caller_address() { #[test] fn test_cheat_caller_address_all() { let contract = declare("CheatCallerAddressChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = ICheatCallerAddressCheckerDispatcher { contract_address }; let target_caller_address: felt252 = 123; @@ -69,7 +69,7 @@ fn cheat_caller_address() { #[test] fn test_cheat_caller_address_all_stop_one() { let contract = declare("CheatCallerAddressChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = ICheatCallerAddressCheckerDispatcher { contract_address }; let target_caller_address: felt252 = 123; @@ -92,8 +92,8 @@ fn cheat_caller_address() { fn test_cheat_caller_address_multiple() { let contract = declare("CheatCallerAddressChecker").unwrap().contract_class(); - let (contract_address1, _) = contract.deploy(@ArrayTrait::new()).unwrap(); - let (contract_address2, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address1, _) = contract.deploy([].span()).unwrap(); + let (contract_address2, _) = contract.deploy([].span()).unwrap(); let dispatcher1 = ICheatCallerAddressCheckerDispatcher { contract_address: contract_address1 }; let dispatcher2 = ICheatCallerAddressCheckerDispatcher { contract_address: contract_address2 }; @@ -155,7 +155,7 @@ fn cheat_caller_address_with_span() { } fn deploy_cheat_caller_address_checker() -> ICheatCallerAddressCheckerDispatcher { - let (contract_address, _) = declare("CheatCallerAddressChecker").unwrap().contract_class().deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = declare("CheatCallerAddressChecker").unwrap().contract_class().deploy([].span()).unwrap(); ICheatCallerAddressCheckerDispatcher { contract_address } } diff --git a/crates/forge/tests/integration/cheat_execution_info.rs b/crates/forge/tests/integration/cheat_execution_info.rs index 3aa35e417f..599712de6a 100644 --- a/crates/forge/tests/integration/cheat_execution_info.rs +++ b/crates/forge/tests/integration/cheat_execution_info.rs @@ -26,7 +26,7 @@ fn start_and_stop_cheat_transaction_hash_single_attribute() { #[test] fn start_cheat_transaction_hash_single_attribute() { let contract = declare("CheatTxInfoChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = ICheatTxInfoCheckerDispatcher { contract_address }; let tx_info_before = dispatcher.get_tx_info(); @@ -46,7 +46,7 @@ fn start_and_stop_cheat_transaction_hash_single_attribute() { #[test] fn test_cheat_transaction_hash_all_stop_one() { let contract = declare("CheatTxInfoChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = ICheatTxInfoCheckerDispatcher { contract_address }; let tx_info_before = dispatcher.get_tx_info(); @@ -138,7 +138,7 @@ fn start_cheat_execution_info_all_attributes_mocked() { #[test] fn start_cheat_execution_info_all_attributes_mocked() { let contract = declare("CheatTxInfoChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = ICheatTxInfoCheckerDispatcher { contract_address }; let mut execution_info_mock: ExecutionInfoMock = Default::default(); @@ -294,7 +294,7 @@ fn start_cheat_transaction_hash_cancel_mock_by_setting_attribute_to_none() { #[test] fn start_cheat_transaction_hash_cancel_mock_by_setting_attribute_to_none() { let contract = declare("CheatTxInfoChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = ICheatTxInfoCheckerDispatcher { contract_address }; let tx_info_before_mock = dispatcher.get_tx_info(); @@ -372,10 +372,10 @@ fn start_cheat_transaction_hash_multiple() { fn start_cheat_transaction_hash_multiple() { let contract = declare("CheatTxInfoChecker").unwrap().contract_class(); - let (contract_address_1, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address_1, _) = contract.deploy([].span()).unwrap(); let dispatcher_1 = ICheatTxInfoCheckerDispatcher { contract_address: contract_address_1 }; - let (contract_address_2, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address_2, _) = contract.deploy([].span()).unwrap(); let dispatcher_2 = ICheatTxInfoCheckerDispatcher { contract_address: contract_address_2 }; start_cheat_transaction_hash(contract_address_1, 421); @@ -438,7 +438,7 @@ fn start_cheat_execution_info_all() { #[test] fn start_cheat_execution_info_all_one_param() { let contract = declare("CheatTxInfoChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = ICheatTxInfoCheckerDispatcher { contract_address }; let mut execution_info_mock: ExecutionInfoMock = Default::default(); @@ -452,7 +452,7 @@ fn start_cheat_execution_info_all() { #[test] fn start_cheat_execution_info_all_multiple_params() { let contract = declare("CheatTxInfoChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = ICheatTxInfoCheckerDispatcher { contract_address }; let mut execution_info_mock: ExecutionInfoMock = Default::default(); @@ -556,8 +556,8 @@ fn start_cheat_transaction_hash_complex() { #[test] fn start_cheat_transaction_hash_complex() { let contract = declare("CheatTxInfoChecker").unwrap().contract_class(); - let (contract_address_1, _) = contract.deploy(@array![]).unwrap(); - let (contract_address_2, _) = contract.deploy(@array![]).unwrap(); + let (contract_address_1, _) = contract.deploy([].span()).unwrap(); + let (contract_address_2, _) = contract.deploy([].span()).unwrap(); let dispatcher_1 = ICheatTxInfoCheckerDispatcher { contract_address: contract_address_1 }; let dispatcher_2 = ICheatTxInfoCheckerDispatcher { contract_address: contract_address_2 }; @@ -618,7 +618,7 @@ fn cheat_transaction_hash_with_span() { } fn deploy_cheat_transaction_hash_checker() -> ICheatTxInfoCheckerDispatcher { - let (contract_address, _) = declare("CheatTxInfoChecker").unwrap().contract_class().deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = declare("CheatTxInfoChecker").unwrap().contract_class().deploy([].span()).unwrap(); ICheatTxInfoCheckerDispatcher { contract_address } } diff --git a/crates/forge/tests/integration/cheat_sequencer_address.rs b/crates/forge/tests/integration/cheat_sequencer_address.rs index 967b352831..4d6b5e76d6 100644 --- a/crates/forge/tests/integration/cheat_sequencer_address.rs +++ b/crates/forge/tests/integration/cheat_sequencer_address.rs @@ -25,7 +25,7 @@ fn cheat_sequencer_address_basic() { #[test] fn test_stop_cheat_sequencer_address() { let contract = declare("CheatSequencerAddressChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = ICheatSequencerAddressCheckerDispatcher { contract_address }; let old_sequencer_address = dispatcher.get_sequencer_address(); @@ -45,8 +45,8 @@ fn cheat_sequencer_address_basic() { fn test_cheat_sequencer_address_multiple() { let contract = declare("CheatSequencerAddressChecker").unwrap().contract_class(); - let (contract_address1, _) = contract.deploy(@ArrayTrait::new()).unwrap(); - let (contract_address2, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address1, _) = contract.deploy([].span()).unwrap(); + let (contract_address2, _) = contract.deploy([].span()).unwrap(); let cheat_sequencer_address_checker1 = ICheatSequencerAddressCheckerDispatcher { contract_address: contract_address1 }; let cheat_sequencer_address_checker2 = ICheatSequencerAddressCheckerDispatcher { contract_address: contract_address2 }; @@ -76,8 +76,8 @@ fn cheat_sequencer_address_basic() { fn test_cheat_sequencer_address_all() { let contract = declare("CheatSequencerAddressChecker").unwrap().contract_class(); - let (contract_address1, _) = contract.deploy(@ArrayTrait::new()).unwrap(); - let (contract_address2, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address1, _) = contract.deploy([].span()).unwrap(); + let (contract_address2, _) = contract.deploy([].span()).unwrap(); let cheat_sequencer_address_checker1 = ICheatSequencerAddressCheckerDispatcher { contract_address: contract_address1 }; let cheat_sequencer_address_checker2 = ICheatSequencerAddressCheckerDispatcher { contract_address: contract_address2 }; @@ -105,7 +105,7 @@ fn cheat_sequencer_address_basic() { #[test] fn test_cheat_sequencer_address_all_stop_one() { let contract = declare("CheatSequencerAddressChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = ICheatSequencerAddressCheckerDispatcher { contract_address }; let target_seq_addr: felt252 = 123; @@ -159,8 +159,8 @@ fn cheat_sequencer_address_complex() { fn test_cheat_sequencer_address_complex() { let contract = declare("CheatSequencerAddressChecker").unwrap().contract_class(); - let (contract_address1, _) = contract.deploy(@ArrayTrait::new()).unwrap(); - let (contract_address2, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address1, _) = contract.deploy([].span()).unwrap(); + let (contract_address2, _) = contract.deploy([].span()).unwrap(); let cheat_sequencer_address_checker1 = ICheatSequencerAddressCheckerDispatcher { contract_address: contract_address1 }; let cheat_sequencer_address_checker2 = ICheatSequencerAddressCheckerDispatcher { contract_address: contract_address2 }; @@ -233,7 +233,7 @@ fn cheat_sequencer_address_with_span() { } fn deploy_cheat_sequencer_address_checker() -> ICheatSequencerAddressCheckerDispatcher { - let (contract_address, _) = declare("CheatSequencerAddressChecker").unwrap().contract_class().deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = declare("CheatSequencerAddressChecker").unwrap().contract_class().deploy([].span()).unwrap(); ICheatSequencerAddressCheckerDispatcher { contract_address } } diff --git a/crates/forge/tests/integration/deploy.rs b/crates/forge/tests/integration/deploy.rs index da640a95fc..cc4acc0720 100644 --- a/crates/forge/tests/integration/deploy.rs +++ b/crates/forge/tests/integration/deploy.rs @@ -17,7 +17,7 @@ fn error_handling() { fn error_handling() { let contract = declare("PanickingConstructor").unwrap().contract_class(); - match contract.deploy(@ArrayTrait::new()) { + match contract.deploy([].span()) { Result::Ok(_) => panic_with_felt252('Should have panicked'), Result::Err(panic_data) => { assert(*panic_data.at(0_usize) == 'PANIK', *panic_data.at(0_usize)); @@ -97,7 +97,7 @@ fn constructor_retdata_span() { fn constructor_retdata_span() { let contract = declare("ConstructorRetdata").unwrap().contract_class(); - let (_contract_address, retdata) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (_contract_address, retdata) = contract.deploy([].span()).unwrap(); assert_eq!(retdata, array![3, 2, 3, 4].span()); } "# @@ -109,10 +109,10 @@ fn constructor_retdata_span() { #[starknet::contract] mod ConstructorRetdata { use array::ArrayTrait; - + #[storage] struct Storage {} - + #[constructor] fn constructor(ref self: ContractState) -> Span { array![2, 3, 4].span() @@ -141,7 +141,7 @@ fn constructor_retdata_felt() { fn constructor_retdata_felt() { let contract = declare("ConstructorRetdata").unwrap().contract_class(); - let (_contract_address, retdata) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (_contract_address, retdata) = contract.deploy([].span()).unwrap(); assert_eq!(retdata, array![5].span()); } "# @@ -153,10 +153,10 @@ fn constructor_retdata_felt() { #[starknet::contract] mod ConstructorRetdata { use array::ArrayTrait; - + #[storage] struct Storage {} - + #[constructor] fn constructor(ref self: ContractState) -> felt252 { 5 @@ -185,7 +185,7 @@ fn constructor_retdata_struct() { fn constructor_retdata_struct() { let contract = declare("ConstructorRetdata").unwrap().contract_class(); - let (_contract_address, retdata) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (_contract_address, retdata) = contract.deploy([].span()).unwrap(); assert_eq!(retdata, array![0, 6, 2, 7, 8, 9].span()); } "# @@ -197,10 +197,10 @@ fn constructor_retdata_struct() { #[starknet::contract] mod ConstructorRetdata { use array::ArrayTrait; - + #[storage] struct Storage {} - + #[derive(Serde, Drop)] struct Retdata { a: felt252, diff --git a/crates/forge/tests/integration/deploy_at.rs b/crates/forge/tests/integration/deploy_at.rs index 27716fa446..844c35b729 100644 --- a/crates/forge/tests/integration/deploy_at.rs +++ b/crates/forge/tests/integration/deploy_at.rs @@ -20,12 +20,12 @@ fn deploy_at_correct_address() { #[test] fn deploy_at_correct_address() { let contract = declare("CheatCallerAddressChecker").unwrap().contract_class(); - let (cheat_caller_address_checker, _) = contract.deploy(@array![]).unwrap(); + let (cheat_caller_address_checker, _) = contract.deploy([].span()).unwrap(); let contract = declare("Proxy").unwrap().contract_class(); let deploy_at_address = 123; - let (contract_address, _) = contract.deploy_at(@array![], deploy_at_address.try_into().unwrap()).unwrap(); + let (contract_address, _) = contract.deploy_at([].span()), deploy_at_address.try_into().unwrap()).unwrap(); assert(deploy_at_address == contract_address.into(), 'addresses should be the same'); let real_address = IProxyDispatcher{ contract_address }.get_caller_address(cheat_caller_address_checker); @@ -47,7 +47,7 @@ fn deploy_at_correct_address() { #[starknet::contract] mod Proxy { use starknet::ContractAddress; - + #[storage] struct Storage {} @@ -55,7 +55,7 @@ fn deploy_at_correct_address() { trait ICheatCallerAddressChecker { fn get_caller_address(ref self: TContractState) -> felt252; } - + #[abi(embed_v0)] impl ProxyImpl of super::IProxy { fn get_caller_address(ref self: ContractState, checker_address: ContractAddress) -> felt252 { @@ -91,9 +91,9 @@ fn deploy_two_at_the_same_address() { let contract_address = 123; let contract = declare("HelloStarknet").unwrap().contract_class(); - let (real_address, _) = contract.deploy_at(@array![], contract_address.try_into().unwrap()).unwrap(); + let (real_address, _) = contract.deploy_at([].span()), contract_address.try_into().unwrap()).unwrap(); assert(real_address.into() == contract_address, 'addresses should be the same'); - contract.deploy_at(@array![], contract_address.try_into().unwrap()).unwrap(); + contract.deploy_at([].span()), contract_address.try_into().unwrap()).unwrap(); } "# ), @@ -128,7 +128,7 @@ fn deploy_at_error_handling() { let contract_address = 123; let contract = declare("PanickingConstructor").unwrap().contract_class(); - match contract.deploy_at(@array![], contract_address.try_into().unwrap()) { + match contract.deploy_at([].span()), contract_address.try_into().unwrap()) { Result::Ok(_) => panic_with_felt252('shouldve panicked'), Result::Err(panic_data) => { assert(*panic_data.at(0) == 'PANIK', 'wrong 1st panic datum'); diff --git a/crates/forge/tests/integration/dict.rs b/crates/forge/tests/integration/dict.rs index bb8b5caa56..2de2909248 100644 --- a/crates/forge/tests/integration/dict.rs +++ b/crates/forge/tests/integration/dict.rs @@ -25,7 +25,7 @@ fn using_dict() { let mut inputs: Array = array![]; numbers.serialize(ref inputs); - let (contract_address, _) = contract.deploy(@inputs).unwrap(); + let (contract_address, _) = contract.deploy(inputs.span()).unwrap(); let dispatcher = IDictUsingContractDispatcher { contract_address }; let unq = dispatcher.get_unique(); diff --git a/crates/forge/tests/integration/dispatchers.rs b/crates/forge/tests/integration/dispatchers.rs index 77f83a6bc7..1bb98c452f 100644 --- a/crates/forge/tests/integration/dispatchers.rs +++ b/crates/forge/tests/integration/dispatchers.rs @@ -28,7 +28,7 @@ fn simple_call_and_invoke() { #[test] fn simple_call_and_invoke() { let contract = declare("HelloStarknet").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = IHelloStarknetDispatcher { contract_address }; let balance = dispatcher.get_balance(); @@ -96,7 +96,7 @@ fn advanced_types() { calldata.append(1234); // recipient let contract = declare("ERC20").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@calldata).unwrap(); + let (contract_address, _) = contract.deploy(calldata.span()).unwrap(); let dispatcher = IERC20Dispatcher { contract_address }; let user_address: ContractAddress = 1234.try_into().unwrap(); let other_user_address: ContractAddress = 9999.try_into().unwrap(); @@ -152,7 +152,7 @@ fn handling_errors() { #[feature("safe_dispatcher")] fn handling_execution_errors() { let contract = declare("HelloStarknet").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let safe_dispatcher = IHelloStarknetSafeDispatcher { contract_address }; match safe_dispatcher.do_a_panic() { @@ -230,7 +230,7 @@ fn handling_bytearray_based_errors() { #[feature("safe_dispatcher")] fn handling_errors() { let contract = declare("HelloStarknet").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let safe_dispatcher = IHelloStarknetSafeDispatcher { contract_address }; let panic_data = safe_dispatcher.do_a_panic_with_bytearray().unwrap_err(); @@ -305,7 +305,7 @@ fn serding() { #[test] fn serding() { let contract = declare("Serding").unwrap().contract_class(); - let (contract_address, _) = contract.deploy( @ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = ISerdingDispatcher { contract_address @@ -363,7 +363,7 @@ fn proxy_storage() { fn deploy_contract(name: ByteArray) -> ContractAddress { let contract = declare(name).unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); contract_address } @@ -527,7 +527,7 @@ fn proxy_dispatcher_panic() { fn deploy_contract(name: ByteArray, constructor_calldata: @Array) -> ContractAddress { let contract = declare(name).unwrap(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); contract_address } @@ -643,7 +643,7 @@ fn nonexistent_method_call() { fn deploy_contract(name: ByteArray, constructor_calldata: @Array) -> ContractAddress { let contract = declare(name).unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); contract_address } @@ -704,7 +704,7 @@ fn nonexistent_libcall_function() { fn deploy_contract(name: ByteArray) -> ContractAddress { let contract = declare(name).unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); contract_address } @@ -831,7 +831,7 @@ fn nonexistent_class_libcall() { fn deploy_contract(name: ByteArray) -> ContractAddress { let contract = declare(name).unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); contract_address } diff --git a/crates/forge/tests/integration/gas.rs b/crates/forge/tests/integration/gas.rs index 49fff13648..f2099786f5 100644 --- a/crates/forge/tests/integration/gas.rs +++ b/crates/forge/tests/integration/gas.rs @@ -78,7 +78,7 @@ fn snforge_std_deploy_cost() { #[test] fn deploy_cost() { let contract = declare("GasConstructorChecker").unwrap().contract_class(); - let (address, _) = contract.deploy(@array![]).unwrap(); + let (address, _) = contract.deploy([].span()).unwrap(); assert(address != 0.try_into().unwrap(), 'wrong deployed addr'); } "# @@ -130,7 +130,7 @@ fn contract_keccak_cost() { #[test] fn contract_keccak_cost() { let contract = declare("GasChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = IGasCheckerDispatcher { contract_address }; dispatcher.keccak(5); @@ -187,7 +187,7 @@ fn contract_range_check_cost() { #[test] fn contract_range_check_cost() { let contract = declare("GasChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = IGasCheckerDispatcher { contract_address }; dispatcher.range_check(); @@ -243,7 +243,7 @@ fn contract_bitwise_cost() { #[test] fn contract_bitwise_cost() { let contract = declare("GasChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = IGasCheckerDispatcher { contract_address }; dispatcher.bitwise(300); @@ -299,7 +299,7 @@ fn contract_pedersen_cost() { #[test] fn contract_pedersen_cost() { let contract = declare("GasChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = IGasCheckerDispatcher { contract_address }; dispatcher.pedersen(); @@ -355,7 +355,7 @@ fn contract_poseidon_cost() { #[test] fn contract_poseidon_cost() { let contract = declare("GasChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = IGasCheckerDispatcher { contract_address }; dispatcher.poseidon(); @@ -413,7 +413,7 @@ fn contract_ec_op_cost() { #[test] fn contract_ec_op_cost() { let contract = declare("GasChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = IGasCheckerDispatcher { contract_address }; dispatcher.ec_op(10); @@ -450,7 +450,7 @@ fn storage_write_cost() { #[test] fn storage_write_cost() { let contract = declare("GasChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = IGasCheckerDispatcher { contract_address }; dispatcher.change_balance(1); @@ -521,7 +521,7 @@ fn multiple_storage_writes_cost() { #[test] fn multiple_storage_writes_cost() { let contract = declare("GasChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = IGasCheckerDispatcher { contract_address }; dispatcher.change_balance(1); @@ -565,7 +565,7 @@ fn l1_message_cost() { #[test] fn l1_message_cost() { let contract = declare("GasChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = IGasCheckerDispatcher { contract_address }; dispatcher.send_l1_message(); @@ -627,10 +627,10 @@ fn l1_message_cost_for_proxy() { #[test] fn l1_message_cost_for_proxy() { let contract = declare("GasChecker").unwrap().contract_class(); - let (gas_checker_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (gas_checker_address, _) = contract.deploy([].span()).unwrap(); let contract = declare("GasCheckerProxy").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = IGasCheckerProxyDispatcher { contract_address }; dispatcher.send_l1_message_from_gas_checker(gas_checker_address); @@ -672,7 +672,7 @@ fn l1_handler_cost() { #[test] fn l1_handler_cost() { let contract = declare("GasChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@array![]).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let mut l1_handler = L1HandlerTrait::new(contract_address, selector!("handle_l1_message")); @@ -740,7 +740,7 @@ fn events_contract_cost() { #[test] fn event_emission_cost() { - let (contract_address, _) = declare("GasChecker").unwrap().contract_class().deploy(@array![]).unwrap(); + let (contract_address, _) = declare("GasChecker").unwrap().contract_class().deploy([].span()).unwrap(); let dispatcher = IGasCheckerDispatcher { contract_address }; dispatcher.emit_event(50); diff --git a/crates/forge/tests/integration/get_class_hash.rs b/crates/forge/tests/integration/get_class_hash.rs index 15acc1dac1..709e18cc4a 100644 --- a/crates/forge/tests/integration/get_class_hash.rs +++ b/crates/forge/tests/integration/get_class_hash.rs @@ -17,7 +17,7 @@ fn get_class_hash_cheatcode() { #[test] fn get_class_hash_cheatcode() { let contract = declare("HelloStarknet").unwrap().contract_class().clone(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); assert(get_class_hash(contract_address) == contract.class_hash, 'Incorrect class hash'); } "# diff --git a/crates/forge/tests/integration/l1_handler_executor.rs b/crates/forge/tests/integration/l1_handler_executor.rs index 7a8e7dc7a1..e561556760 100644 --- a/crates/forge/tests/integration/l1_handler_executor.rs +++ b/crates/forge/tests/integration/l1_handler_executor.rs @@ -32,7 +32,7 @@ fn l1_handler_execute() { let calldata = array![0x123]; let contract = declare("l1_handler_executor").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@calldata).unwrap(); + let (contract_address, _) = contract.deploy(calldata.span()).unwrap(); let l1_data = L1Data { balance: 42, @@ -59,7 +59,7 @@ fn l1_handler_execute() { let calldata = array![0x123]; let contract = declare("l1_handler_executor").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@calldata).unwrap(); + let (contract_address, _) = contract.deploy(calldata.span()).unwrap(); let mut l1_handler = L1HandlerTrait::new( @@ -81,7 +81,7 @@ fn l1_handler_execute() { let calldata = array![0x123]; let contract = declare("l1_handler_executor").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@calldata).unwrap(); + let (contract_address, _) = contract.deploy(calldata.span()).unwrap(); let mut l1_handler = L1HandlerTrait::new( diff --git a/crates/forge/tests/integration/message_to_l1.rs b/crates/forge/tests/integration/message_to_l1.rs index 558111d845..341a548877 100644 --- a/crates/forge/tests/integration/message_to_l1.rs +++ b/crates/forge/tests/integration/message_to_l1.rs @@ -25,7 +25,7 @@ fn spy_messages_to_l1_simple() { fn deploy_message_to_l1_checker() -> IMessageToL1CheckerDispatcher { let declared = declare("MessageToL1Checker").unwrap().contract_class(); - let (contract_address, _) = declared.deploy(@array![]).unwrap(); + let (contract_address, _) = declared.deploy([].span()).unwrap(); IMessageToL1CheckerDispatcher { contract_address } } @@ -74,11 +74,11 @@ fn spy_messages_to_l1_fails() { use result::ResultTrait; use starknet::ContractAddress; use snforge_std::{ - declare, ContractClassTrait, - spy_messages_to_l1, + declare, ContractClassTrait, + spy_messages_to_l1, MessageToL1, MessageToL1SpyAssertionsTrait }; - + #[test] fn assert_sent_fails() { @@ -88,7 +88,7 @@ fn spy_messages_to_l1_fails() { ( 0x123.try_into().unwrap(), MessageToL1 { - to_address: 0x123.try_into().unwrap(), + to_address: 0x123.try_into().unwrap(), payload: array![0x123, 0x420] } ) @@ -134,7 +134,7 @@ fn expect_three_messages_while_two_sent() { fn deploy_message_to_l1_checker() -> IMessageToL1CheckerDispatcher { let declared = declare("MessageToL1Checker").unwrap().contract_class(); - let (contract_address, _) = declared.deploy(@array![]).unwrap(); + let (contract_address, _) = declared.deploy([].span()).unwrap(); IMessageToL1CheckerDispatcher { contract_address } } @@ -223,7 +223,7 @@ fn expect_two_messages_while_three_sent() { fn deploy_message_to_l1_checker() -> IMessageToL1CheckerDispatcher { let declared = declare("MessageToL1Checker").unwrap().contract_class(); - let (contract_address, _) = declared.deploy(@array![]).unwrap(); + let (contract_address, _) = declared.deploy([].span()).unwrap(); IMessageToL1CheckerDispatcher { contract_address } } @@ -299,7 +299,7 @@ fn message_sent_but_wrong_data_asserted() { fn deploy_message_to_l1_checker() -> IMessageToL1CheckerDispatcher { let declared = declare("MessageToL1Checker").unwrap().contract_class(); - let (contract_address, _) = declared.deploy(@array![]).unwrap(); + let (contract_address, _) = declared.deploy([].span()).unwrap(); IMessageToL1CheckerDispatcher { contract_address } } @@ -410,7 +410,7 @@ fn assert_not_sent_fails() { fn deploy_message_to_l1_checker() -> IMessageToL1CheckerDispatcher { let declared = declare("MessageToL1Checker").unwrap().contract_class(); - let (contract_address, _) = declared.deploy(@array![]).unwrap(); + let (contract_address, _) = declared.deploy([].span()).unwrap(); IMessageToL1CheckerDispatcher { contract_address } } @@ -473,8 +473,8 @@ fn test_filtering() { fn deploy_message_to_l1_checkers() -> (IMessageToL1CheckerDispatcher, IMessageToL1CheckerDispatcher) { let declared = declare("MessageToL1Checker").unwrap().contract_class(); - let (contract_address_1, _) = declared.deploy(@array![]).unwrap(); - let (contract_address_2, _) = declared.deploy(@array![]).unwrap(); + let (contract_address_1, _) = declared.deploy([].span()).unwrap(); + let (contract_address_2, _) = declared.deploy([].span()).unwrap(); ( IMessageToL1CheckerDispatcher { contract_address: contract_address_1 }, diff --git a/crates/forge/tests/integration/mock_call.rs b/crates/forge/tests/integration/mock_call.rs index 6205e110fc..1cd6f0831b 100644 --- a/crates/forge/tests/integration/mock_call.rs +++ b/crates/forge/tests/integration/mock_call.rs @@ -22,7 +22,7 @@ fn mock_call_simple() { let calldata = array![420]; let contract = declare("MockChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@calldata).unwrap(); + let (contract_address, _) = contract.deploy(calldata.span()).unwrap(); let dispatcher = IMockCheckerDispatcher { contract_address }; @@ -42,7 +42,7 @@ fn mock_call_simple() { let calldata = array![420]; let contract = declare("MockChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@calldata).unwrap(); + let (contract_address, _) = contract.deploy(calldata.span()).unwrap(); let mock_ret_data = 421; start_mock_call(contract_address, selector!("get_thing"), mock_ret_data); @@ -92,7 +92,7 @@ fn mock_call_complex_types() { let calldata = array![420]; let contract = declare("MockChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@calldata).unwrap(); + let (contract_address, _) = contract.deploy(calldata.span()).unwrap(); let dispatcher = IMockCheckerDispatcher { contract_address }; @@ -110,7 +110,7 @@ fn mock_call_complex_types() { let calldata = array![420]; let contract = declare("MockChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@calldata).unwrap(); + let (contract_address, _) = contract.deploy(calldata.span()).unwrap(); let dispatcher = IMockCheckerDispatcher { contract_address }; @@ -158,7 +158,7 @@ fn mock_calls() { let calldata = array![420]; let contract = declare("MockChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@calldata).unwrap(); + let (contract_address, _) = contract.deploy(calldata.span()).unwrap(); let dispatcher = IMockCheckerDispatcher { contract_address }; @@ -178,7 +178,7 @@ fn mock_calls() { let calldata = array![420]; let contract = declare("MockChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@calldata).unwrap(); + let (contract_address, _) = contract.deploy(calldata.span()).unwrap(); let dispatcher = IMockCheckerDispatcher { contract_address }; diff --git a/crates/forge/tests/integration/precalculate_address.rs b/crates/forge/tests/integration/precalculate_address.rs index 81ee7d375e..c2b58ce419 100644 --- a/crates/forge/tests/integration/precalculate_address.rs +++ b/crates/forge/tests/integration/precalculate_address.rs @@ -21,10 +21,10 @@ fn precalculate_address() { let mut calldata = ArrayTrait::new(); let contract = declare("HelloStarknet").unwrap().contract_class(); - let contract_address_pre = contract.precalculate_address(@calldata); - let (contract_address, _) = contract.deploy(@calldata).unwrap(); - let contract_address_pre2 = contract.precalculate_address(@calldata); - let (contract_address2, _) = contract.deploy(@calldata).unwrap(); + let contract_address_pre = contract.precalculate_address(calldata.span()); + let (contract_address, _) = contract.deploy(calldata.span()).unwrap(); + let contract_address_pre2 = contract.precalculate_address(calldata.span()); + let (contract_address2, _) = contract.deploy(calldata.span()).unwrap(); assert(contract_address_pre == contract_address, 'must be eq'); assert(contract_address_pre2 == contract_address2, 'must be eq'); diff --git a/crates/forge/tests/integration/replace_bytecode.rs b/crates/forge/tests/integration/replace_bytecode.rs index 716d2b5919..0d8ffb3b29 100644 --- a/crates/forge/tests/integration/replace_bytecode.rs +++ b/crates/forge/tests/integration/replace_bytecode.rs @@ -21,7 +21,7 @@ fn override_entrypoint() { fn override_entrypoint() { let contract = declare("ReplaceBytecodeA").unwrap().contract_class(); let contract_b_class = declare("ReplaceBytecodeB").unwrap().contract_class().class_hash.clone(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = IReplaceBytecodeDispatcher { contract_address }; assert(dispatcher.get() == 2137, ''); @@ -72,7 +72,7 @@ fn libcall_in_cheated() { let contract = declare("ReplaceBytecodeA").unwrap().contract_class(); let contract_b_class = declare("ReplaceBytecodeB").unwrap().contract_class().clone().class_hash; let lib = declare("Lib").unwrap().contract_class().clone().class_hash; - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = IReplaceBytecodeDispatcher { contract_address }; assert(dispatcher.libcall(lib) == 123456789, ''); @@ -154,7 +154,7 @@ fn class_hash_not_declared() { fn class_hash_not_declared() { let contract = declare("ReplaceBytecodeA").unwrap().contract_class(); let undeclared_class_hash: ClassHash = 0x5.try_into().unwrap(); - let (contract_address, _) = contract.deploy(@array![]).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); match replace_bytecode(contract_address, undeclared_class_hash) { Result::Ok(()) => { diff --git a/crates/forge/tests/integration/resources.rs b/crates/forge/tests/integration/resources.rs index 9f2ecf23ae..7ed7df7db5 100644 --- a/crates/forge/tests/integration/resources.rs +++ b/crates/forge/tests/integration/resources.rs @@ -165,7 +165,7 @@ fn accumulate_syscalls() { #[test] fn single_write() { let contract = declare("GasChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = IGasCheckerDispatcher { contract_address }; dispatcher.change_balance(1); @@ -174,7 +174,7 @@ fn accumulate_syscalls() { #[test] fn double_write() { let contract = declare("GasChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = IGasCheckerDispatcher { contract_address }; dispatcher.change_balance(1); diff --git a/crates/forge/tests/integration/setup_fork.rs b/crates/forge/tests/integration/setup_fork.rs index e0eca83869..c7d83b5d92 100644 --- a/crates/forge/tests/integration/setup_fork.rs +++ b/crates/forge/tests/integration/setup_fork.rs @@ -255,7 +255,7 @@ fn get_block_info_in_forked_block() { #[fork(url: "{node_rpc_url}", block_number: 54060)] fn test_fork_get_block_info_contract_deployed() {{ let contract = declare("BlockInfoChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = IBlockInfoCheckerDispatcher {{ contract_address }}; let timestamp = dispatcher.read_block_timestamp(); diff --git a/crates/forge/tests/integration/should_panic.rs b/crates/forge/tests/integration/should_panic.rs index 8efa0e24f1..ffefc843f1 100644 --- a/crates/forge/tests/integration/should_panic.rs +++ b/crates/forge/tests/integration/should_panic.rs @@ -54,7 +54,7 @@ fn should_panic_unknown_entry_point() { #[should_panic] fn should_panic_with_no_expected_data() { let contract = declare("HelloStarknet").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); match call_contract_syscall( contract_address, diff --git a/crates/forge/tests/integration/spy_events.rs b/crates/forge/tests/integration/spy_events.rs index 7cc3469d85..6d58f528c2 100644 --- a/crates/forge/tests/integration/spy_events.rs +++ b/crates/forge/tests/integration/spy_events.rs @@ -45,7 +45,7 @@ fn spy_events_simple() { #[test] fn spy_events_simple() { let contract = declare("SpyEventsChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = ISpyEventsCheckerDispatcher { contract_address }; let mut spy = spy_events(); @@ -117,7 +117,7 @@ fn assert_emitted_fails() { #[test] fn assert_emitted_fails() { let contract = declare("SpyEventsChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = ISpyEventsCheckerDispatcher { contract_address }; let mut spy = spy_events(); @@ -210,7 +210,7 @@ fn expect_three_events_while_two_emitted() { #[test] fn expect_three_events_while_two_emitted() { let contract = declare("SpyEventsChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@array![]).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = ISpyEventsCheckerDispatcher { contract_address }; let some_data = 456; @@ -320,7 +320,7 @@ fn expect_two_events_while_three_emitted() { #[test] fn expect_two_events_while_three_emitted() { let contract = declare("SpyEventsChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@array![]).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = ISpyEventsCheckerDispatcher { contract_address }; let some_data = 456; @@ -399,7 +399,7 @@ fn event_emitted_wrong_data_asserted() { #[test] fn event_emitted_wrong_data_asserted() { let contract = declare("SpyEventsChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = ISpyEventsCheckerDispatcher { contract_address }; let mut spy = spy_events(); @@ -461,7 +461,7 @@ fn emit_unnamed_event() { #[test] fn emit_unnamed_event() { let contract = declare("SpyEventsChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@array![]).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = ISpyEventsCheckerDispatcher { contract_address }; let mut spy = spy_events(); @@ -528,7 +528,7 @@ fn assert_not_emitted_pass() { #[test] fn assert_not_emitted_pass() { let contract = declare("SpyEventsChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = ISpyEventsCheckerDispatcher { contract_address }; let mut spy = spy_events(); @@ -597,7 +597,7 @@ fn assert_not_emitted_fails() { #[test] fn assert_not_emitted_fails() { let contract = declare("SpyEventsChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = ISpyEventsCheckerDispatcher { contract_address }; let mut spy = spy_events(); @@ -681,7 +681,7 @@ fn capture_cairo0_event() { fn capture_cairo0_event() {{ let cairo0_contract_address = contract_address_const::<0x2c77ca97586968c6651a533bd5f58042c368b14cf5f526d2f42f670012e10ac>(); let contract = declare("SpyEventsChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = ISpyEventsCheckerDispatcher {{ contract_address }}; let mut spy = spy_events(); @@ -772,8 +772,8 @@ fn test_filtering() { #[test] fn filter_events() { let contract = declare("SpyEventsChecker").unwrap().contract_class(); - let (first_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); - let (second_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (first_address, _) = contract.deploy([].span()).unwrap(); + let (second_address, _) = contract.deploy([].span()).unwrap(); let first_dispatcher = ISpyEventsCheckerDispatcher { contract_address: first_address }; let second_dispatcher = ISpyEventsCheckerDispatcher { contract_address: second_address }; diff --git a/crates/forge/tests/integration/store_load.rs b/crates/forge/tests/integration/store_load.rs index 3c3d289257..069107f395 100644 --- a/crates/forge/tests/integration/store_load.rs +++ b/crates/forge/tests/integration/store_load.rs @@ -20,7 +20,7 @@ fn store_load_simple() { fn deploy_contract() -> IHelloStarknetDispatcher { let contract = declare("HelloStarknet").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@array![]).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); IHelloStarknetDispatcher { contract_address } } @@ -71,7 +71,7 @@ fn store_load_wrong_selector() { fn deploy_contract() -> IHelloStarknetDispatcher { let contract = declare("HelloStarknet").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@array![]).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); IHelloStarknetDispatcher { contract_address } } @@ -121,7 +121,7 @@ fn store_load_wrong_data_length() { fn deploy_contract() -> IHelloStarknetDispatcher { let contract = declare("HelloStarknet").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@array![]).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); IHelloStarknetDispatcher { contract_address } } @@ -168,7 +168,7 @@ fn store_load_max_boundaries_input() { fn deploy_contract() -> IHelloStarknetDispatcher { let contract = declare("HelloStarknet").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@array![]).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); IHelloStarknetDispatcher { contract_address } } @@ -288,7 +288,7 @@ fn store_load_structure() { fn deploy_contract() -> IStorageTesterDispatcher { let contract = declare("StorageTester").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@array![]).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); IStorageTesterDispatcher { contract_address } } @@ -369,7 +369,7 @@ fn store_load_felt_to_structure() { fn deploy_contract() -> IStorageTesterDispatcher { let contract = declare("StorageTester").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@array![]).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); IStorageTesterDispatcher { contract_address } } @@ -424,7 +424,7 @@ fn store_load_structure_to_felt() { r#" use starknet::ContractAddress; use snforge_std::{ declare, ContractClassTrait, store, load, map_entry_address, DeclareResultTrait }; - + #[derive(Serde, Copy, Drop, starknet::Store, Hash)] struct NestedKey { c: felt252 @@ -451,7 +451,7 @@ fn store_load_structure_to_felt() { fn deploy_contract() -> IStorageTesterDispatcher { let contract = declare("StorageTester").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@array![]).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); IStorageTesterDispatcher { contract_address } } @@ -513,7 +513,7 @@ fn store_load_felt_to_felt() { fn deploy_contract() -> IStorageTesterDispatcher { let contract = declare("StorageTester").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@array![]).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); IStorageTesterDispatcher { contract_address } } @@ -580,7 +580,7 @@ fn fork_store_load() { assert(balance == 0, 'Balance should be 0'); let result = load(dispatcher.contract_address, selector!("balance"), 1); assert(*result.at(0) == 0, 'Wrong balance loaded'); - + store(dispatcher.contract_address, selector!("balance"), array![100].span()); let balance = dispatcher.get_balance(); diff --git a/crates/forge/tests/integration/syscalls.rs b/crates/forge/tests/integration/syscalls.rs index 9df7f2951e..6bde078549 100644 --- a/crates/forge/tests/integration/syscalls.rs +++ b/crates/forge/tests/integration/syscalls.rs @@ -30,7 +30,7 @@ fn library_call_syscall_is_usable() { fn deploy_contract(name: ByteArray) -> ContractAddress { let contract = declare(name).unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); contract_address } @@ -44,7 +44,7 @@ fn library_call_syscall_is_usable() { let executor_contract = declare("Executor").unwrap().contract_class(); let executor_class_hash = executor_contract.class_hash.clone(); - let (executor_address, _) = executor_contract.deploy(@ArrayTrait::new()).unwrap(); + let (executor_address, _) = executor_contract.deploy([].span()).unwrap(); let executor_safe_dispatcher = IExecutorDispatcher { contract_address: executor_address }; @@ -262,7 +262,7 @@ fn keccak_syscall_in_contract() { #[test] fn keccak_syscall_in_contract() { let contract = declare("HelloKeccak").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = IHelloKeccakDispatcher { contract_address }; let res = dispatcher.run_keccak(array![1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]); @@ -307,7 +307,7 @@ fn compare_keccak_from_contract_with_plain_keccak() { #[test] fn compare_keccak_from_contract_with_plain_keccak() { let contract = declare("HelloKeccak").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = IHelloKeccakDispatcher { contract_address }; let input = array![1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]; diff --git a/crates/forge/tests/integration/test_state.rs b/crates/forge/tests/integration/test_state.rs index 64f9aa45a5..28e883c612 100644 --- a/crates/forge/tests/integration/test_state.rs +++ b/crates/forge/tests/integration/test_state.rs @@ -12,9 +12,9 @@ fn storage_access_from_tests() { mod Contract { #[storage] struct Storage { - balance: felt252, + balance: felt252, } - + #[generate_trait] impl InternalImpl of InternalTrait { fn internal_function(self: @ContractState) -> felt252 { @@ -28,7 +28,7 @@ fn storage_access_from_tests() { fn storage_access_from_tests() { let mut state = Contract::contract_state_for_testing(); state.balance.write(10); - + let value = Contract::InternalImpl::internal_function(@state); assert(value == 10, 'Incorrect storage value'); } @@ -89,15 +89,15 @@ fn simple_syscalls() { let block_info = exec_info.block_info.unbox(); let contract_cheat_block_number = declare("CheatBlockNumberChecker").unwrap().contract_class(); - let (contract_address_cheat_block_number, _) = contract_cheat_block_number.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address_cheat_block_number, _) = contract_cheat_block_number.deploy([].span()).unwrap(); let dispatcher_cheat_block_number = ICheatBlockNumberCheckerDispatcher { contract_address: contract_address_cheat_block_number }; let contract_cheat_block_timestamp = declare("CheatBlockTimestampChecker").unwrap().contract_class(); - let (contract_address_cheat_block_timestamp, _) = contract_cheat_block_timestamp.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address_cheat_block_timestamp, _) = contract_cheat_block_timestamp.deploy([].span()).unwrap(); let dispatcher_cheat_block_timestamp = ICheatBlockTimestampCheckerDispatcher { contract_address: contract_address_cheat_block_timestamp }; let contract_cheat_sequencer_address = declare("CheatSequencerAddressChecker").unwrap().contract_class(); - let (contract_address_cheat_sequencer_address, _) = contract_cheat_sequencer_address.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address_cheat_sequencer_address, _) = contract_cheat_sequencer_address.deploy([].span()).unwrap(); let dispatcher_cheat_sequencer_address = ICheatSequencerAddressCheckerDispatcher { contract_address: contract_address_cheat_sequencer_address }; assert(dispatcher_cheat_block_number.get_block_number() == block_info.block_number, 'Invalid block number'); @@ -105,7 +105,7 @@ fn simple_syscalls() { assert(dispatcher_cheat_sequencer_address.get_sequencer_address() == block_info.sequencer_address, 'Invalid sequencer address'); let contract = declare("CheatTxInfoChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = ICheatTxInfoCheckerDispatcher { contract_address }; let tx_info = exec_info.tx_info.unbox(); @@ -168,7 +168,7 @@ fn get_block_hash_syscall_in_dispatcher() { #[test] fn get_block_hash_syscall_in_dispatcher() { let block_hash_checker = declare("BlockHashChecker").unwrap().contract_class(); - let (block_hash_checker_address, _) = block_hash_checker.deploy(@ArrayTrait::new()).unwrap(); + let (block_hash_checker_address, _) = block_hash_checker.deploy([].span()).unwrap(); let block_hash_checker_dispatcher = BlockHashCheckerDispatcher { contract_address: block_hash_checker_address }; block_hash_checker_dispatcher.write_block(); @@ -284,7 +284,7 @@ fn disabled_syscalls() { use result::ResultTrait; use starknet::{ClassHash, deploy_syscall, replace_class_syscall, get_block_hash_syscall}; use snforge_std::declare; - + #[test] fn disabled_syscalls() { let value : ClassHash = 'xd'.try_into().unwrap(); @@ -348,7 +348,7 @@ fn cant_call_test_contract() { #[test] fn cant_call_test_contract() { let contract = declare("CallsBack").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = ICallsBackDispatcher { contract_address: contract_address }; dispatcher.call_back(test_address()); } @@ -379,7 +379,7 @@ fn cant_call_test_contract() { trait IDontExist { fn test_calling_test_fails(ref self: TContractState); } - + #[abi(embed_v0)] impl CallsBackImpl of super::ICallsBack { @@ -539,7 +539,7 @@ fn simple_cheatcodes() { assert(new_tx_info.transaction_hash == 421, 'Wrong transaction_hash'); stop_cheat_transaction_hash(test_address); - + let new_tx_info = starknet::get_tx_info().unbox(); let new_tx_info_v2 = get_tx_info_v2().unbox(); @@ -616,23 +616,23 @@ fn spy_struct_events() { trait IEmitter { fn emit_event(ref self: TContractState); } - + #[starknet::contract] mod Emitter { use result::ResultTrait; use starknet::ClassHash; - + #[event] #[derive(Drop, starknet::Event)] enum Event { ThingEmitted: ThingEmitted } - + #[derive(Drop, starknet::Event)] struct ThingEmitted { thing: felt252 } - + #[storage] struct Storage {} @@ -650,7 +650,7 @@ fn spy_struct_events() { fn spy_struct_events() { let contract_address = test_address(); let mut spy = spy_events(); - + let mut testing_state = Emitter::contract_state_for_testing(); Emitter::EmitterImpl::emit_event(ref testing_state); @@ -726,14 +726,14 @@ fn caller_address_in_called_contract() { #[test] fn caller_address_in_called_contract() { let cheat_caller_address_checker = declare("CheatCallerAddressChecker").unwrap().contract_class(); - let (contract_address_cheat_caller_address_checker, _) = cheat_caller_address_checker.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address_cheat_caller_address_checker, _) = cheat_caller_address_checker.deploy([].span()).unwrap(); let dispatcher_cheat_caller_address_checker = ICheatCallerAddressCheckerDispatcher { contract_address: contract_address_cheat_caller_address_checker }; assert(dispatcher_cheat_caller_address_checker.get_caller_address() == test_address().into(), 'Incorrect caller address'); let constructor_cheat_caller_address_checker = declare("ConstructorCheatCallerAddressChecker").unwrap().contract_class(); - let (contract_address_constructor_cheat_caller_address_checker, _) = constructor_cheat_caller_address_checker.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address_constructor_cheat_caller_address_checker, _) = constructor_cheat_caller_address_checker.deploy([].span()).unwrap(); let dispatcher_constructor_cheat_caller_address_checker = IConstructorCheatCallerAddressCheckerDispatcher { contract_address: contract_address_constructor_cheat_caller_address_checker }; assert(dispatcher_constructor_cheat_caller_address_checker.get_stored_caller_address() == test_address(), 'Incorrect caller address'); @@ -795,7 +795,7 @@ fn felt252_dict_usage() { #[starknet::contract] mod DictUsingContract { use core::num::traits::{One}; - + fn unique_count(mut ary: Array) -> u32 { let mut dict: Felt252Dict = Default::default(); let mut counter = 0; @@ -819,12 +819,12 @@ fn felt252_dict_usage() { struct Storage { unique_count: u32 } - + #[constructor] fn constructor(ref self: ContractState, values: Array) { self.unique_count.write(unique_count(values)); } - + #[external(v0)] fn get_unique(self: @ContractState) -> u32 { self.unique_count.read() @@ -834,22 +834,22 @@ fn felt252_dict_usage() { self.unique_count.write(unique_count(values)); } } - + #[test] fn test_dict_in_constructor() { let mut testing_state = DictUsingContract::contract_state_for_testing(); DictUsingContract::constructor( - ref testing_state, + ref testing_state, array![1, 2, 3, 3, 3, 3 ,3, 4, 4, 4, 4, 4, 5, 5, 5, 5] ); - + assert(DictUsingContract::get_unique(@testing_state) == 5_u32, 'wrong unq ctor'); - + DictUsingContract::write_unique( - ref testing_state, + ref testing_state, array![1, 2, 3, 3, 3, 3 ,3, 4, 4, 4, 4, 4] ); - + assert(DictUsingContract::get_unique(@testing_state) == 4_u32, ' wrote wrong unq'); } " diff --git a/crates/forge/tests/integration/too_many_events.rs b/crates/forge/tests/integration/too_many_events.rs index 36ef2c26cf..77e6dc210f 100644 --- a/crates/forge/tests/integration/too_many_events.rs +++ b/crates/forge/tests/integration/too_many_events.rs @@ -27,7 +27,7 @@ fn ok_events() { fn deploy_contract() -> ITooManyEventsDispatcher {{ let contract = declare("TooManyEvents").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@array![]).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); ITooManyEventsDispatcher {{ contract_address }} }} @@ -95,7 +95,7 @@ fn too_many_events() { fn deploy_contract() -> ITooManyEventsDispatcher {{ let contract = declare("TooManyEvents").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@array![]).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); ITooManyEventsDispatcher {{ contract_address }} }} diff --git a/crates/forge/tests/integration/trace.rs b/crates/forge/tests/integration/trace.rs index 26ae52f343..2b70ba4cde 100644 --- a/crates/forge/tests/integration/trace.rs +++ b/crates/forge/tests/integration/trace.rs @@ -21,9 +21,9 @@ fn trace_deploy() { let proxy = declare("TraceInfoProxy").unwrap().contract_class().clone(); let checker = declare("TraceInfoChecker").unwrap().contract_class(); - let (checker_address, _) = checker.deploy(@array![]).unwrap(); + let (checker_address, _) = checker.deploy([].span()).unwrap(); - let (proxy_address1, _) = proxy.deploy(@array![checker_address.into()]).unwrap(); + let (proxy_address1, _) = proxy.deploy([checker_address.into()].span()).unwrap(); let (proxy_address2, _) = deploy_syscall( proxy.class_hash, 0, array![checker_address.into()].span(), false @@ -31,7 +31,7 @@ fn trace_deploy() { .unwrap_syscall(); let (proxy_address_3, _) = proxy - .deploy_at(@array![checker_address.into()], 123.try_into().unwrap()) + .deploy_at([checker_address.into()].span()), 123.try_into().unwrap()) .unwrap(); assert_trace( @@ -193,9 +193,9 @@ fn trace_call() { let checker = declare("TraceInfoChecker").unwrap().contract_class().clone(); let dummy = declare("TraceDummy").unwrap().contract_class(); - let (checker_address, _) = checker.deploy(@array![]).unwrap(); - let (proxy_address, _) = proxy.deploy(@array![checker_address.into()]).unwrap(); - let (dummy_address, _) = dummy.deploy(@array![]).unwrap(); + let (checker_address, _) = checker.deploy([].span()).unwrap(); + let (proxy_address, _) = proxy.deploy([checker_address.into()].span()).unwrap(); + let (dummy_address, _) = dummy.deploy([].span()).unwrap(); let proxy_dispatcher = ITraceInfoProxyDispatcher { contract_address: proxy_address }; @@ -412,8 +412,8 @@ fn trace_failed_call() { let proxy = declare("TraceInfoProxy").unwrap().contract_class(); let checker = declare("TraceInfoChecker").unwrap().contract_class(); - let (checker_address, _) = checker.deploy(@array![]).unwrap(); - let (proxy_address, _) = proxy.deploy(@array![checker_address.into()]).unwrap(); + let (checker_address, _) = checker.deploy([].span()).unwrap(); + let (proxy_address, _) = proxy.deploy([checker_address.into()].span()).unwrap(); let proxy_dispatcher = ITraceInfoProxySafeDispatcher { contract_address: proxy_address }; match proxy_dispatcher.with_panic(checker_address) { @@ -567,8 +567,8 @@ fn trace_library_call_from_test() { let checker = declare("TraceInfoChecker").unwrap().contract_class().clone(); let dummy = declare("TraceDummy").unwrap().contract_class(); - let (checker_address, _) = checker.deploy(@array![]).unwrap(); - let (dummy_address, _) = dummy.deploy(@array![]).unwrap(); + let (checker_address, _) = checker.deploy([].span()).unwrap(); + let (dummy_address, _) = dummy.deploy([].span()).unwrap(); let proxy_lib_dispatcher = ITraceInfoProxyLibraryDispatcher { class_hash: proxy_hash }; @@ -760,8 +760,8 @@ fn trace_failed_library_call_from_test() { let proxy = declare("TraceInfoProxy").unwrap().contract_class(); let checker = declare("TraceInfoChecker").unwrap().contract_class(); - let (checker_address, _) = checker.deploy(@array![]).unwrap(); - let (proxy_address, _) = proxy.deploy(@array![checker_address.into()]).unwrap(); + let (checker_address, _) = checker.deploy([].span()).unwrap(); + let (proxy_address, _) = proxy.deploy([checker_address.into()].span()).unwrap(); let proxy_dispatcher = ITraceInfoProxySafeDispatcher { contract_address: proxy_address }; match proxy_dispatcher.with_panic(checker_address) { @@ -894,8 +894,8 @@ fn trace_l1_handler() { let proxy = declare("TraceInfoProxy").unwrap().contract_class(); let checker = declare("TraceInfoChecker").unwrap().contract_class(); - let (checker_address, _) = checker.deploy(@array![]).unwrap(); - let (proxy_address, _) = proxy.deploy(@array![checker_address.into()]).unwrap(); + let (checker_address, _) = checker.deploy([].span()).unwrap(); + let (proxy_address, _) = proxy.deploy([checker_address.into()].span()).unwrap(); let mut l1_handler = L1HandlerTrait::new(checker_address, selector!("handle_l1_message")); diff --git a/design_documents/prepare_cheatcode.md b/design_documents/prepare_cheatcode.md index b976931577..c1a1df84c5 100644 --- a/design_documents/prepare_cheatcode.md +++ b/design_documents/prepare_cheatcode.md @@ -86,7 +86,7 @@ This could be remedied by having separate counters for all `class_hashe`es, but ```cairo mod HelloStarknet { // ... - + #[constructor] fn constructor(ref self: ContractState) { let timestamp = starknet::get_block_timestamp(); @@ -98,16 +98,16 @@ mod HelloStarknet { fn call_and_invoke() { // Declare the contract let class_hash = declare("HelloStarknet"); - + // Prepare contract for deployment let prepared = PreparedContract { class_hash: class_hash, constructor_calldata: @ArrayTrait::new() }; - + // Precalculate the address let contract_address = precalulucate_address(prepared); - + // Warp the address start_warp(contract_address, 1234); - + // Deploy with warped constructor let contract_address = deploy(prepared).unwrap(); let dispatcher = IHelloStarknetDispatcher { contract_address }; @@ -122,10 +122,10 @@ any steps introduced. fn call_and_invoke() { // Declare the contract let class_hash = declare("HelloStarknet"); - + // Prepare contract for deployment let prepared = PreparedContract { class_hash: class_hash, constructor_calldata: @ArrayTrait::new() }; - + // Deploy let contract_address = deploy(prepared).unwrap(); let dispatcher = IHelloStarknetDispatcher { contract_address }; @@ -176,7 +176,7 @@ Same problems as [indicated here](#known-problems-with-this-solution) apply to P ```cairo mod HelloStarknet { // ... - + #[constructor] fn constructor(ref self: ContractState) { let timestamp = starknet::get_block_timestamp(); @@ -188,15 +188,15 @@ mod HelloStarknet { fn call_and_invoke() { // Declare the contract let contract = declare("HelloStarknet"); - + // Precalculate the address let contract_address = contract.precalulucate_address(@ArrayTrait::new()); - + // Warp the address start_warp(contract_address, 1234); - + // Deploy with warped constructor - let contract_address = contract.deploy(@ArrayTrait::new()).unwrap(); + let contract_address = contract.deploy([].span()).unwrap(); let dispatcher = IHelloStarknetDispatcher { contract_address }; } ``` diff --git a/design_documents/store_load_cheatcodes.md b/design_documents/store_load_cheatcodes.md index 58d8956b19..80c833a236 100644 --- a/design_documents/store_load_cheatcodes.md +++ b/design_documents/store_load_cheatcodes.md @@ -2,25 +2,25 @@ ## Context People might want to manipulate the storage of contracts from the test context. -For example: we might want to modify the `authority` of the contract, without actually having an exposed endpoint in the contract, +For example: we might want to modify the `authority` of the contract, without actually having an exposed endpoint in the contract, since it might impose some security issues. Having the function, to modify the stored `authority` will allow to change it, without re-deploying the contract. -Also - some specific storage variables may not be exposed directly to the user via the contracts' interface, since it +Also - some specific storage variables may not be exposed directly to the user via the contracts' interface, since it would bloat the interface and would not be needed for anything but tests (which is generally an antipattern in programming). ## Existing solutions The [store](https://book.getfoundry.sh/cheatcodes/store) and [load](https://book.getfoundry.sh/cheatcodes/load) cheatcodes known from foundry, -provide the functionality to store and load memory in the VM for the given contract. +provide the functionality to store and load memory in the VM for the given contract. Having the correct format of data (conversion), is up to the user, since the interface accepts bytes, and returns bytes as well. ## Proposed solution -My proposal would be to use the generated `contract_state_for_testing` and leverage it's typed structure, to -enable the users to get the address of the variable, via the `.address()` function, and -implement a `store/load` functions, which use the: +My proposal would be to use the generated `contract_state_for_testing` and leverage it's typed structure, to +enable the users to get the address of the variable, via the `.address()` function, and +implement a `store/load` functions, which use the: - Contract address - Calculated variable address - Value (in case of `store`) @@ -43,7 +43,7 @@ mod HelloStarknet { #[storage] struct Storage { - balance: felt252, + balance: felt252, map: LegacyMap, custom_struct: CustomStruct, } @@ -66,7 +66,7 @@ use pkg::HelloStarknet::{balanceContractMemberStateTrait, CustomStruct}; fn deploy_hello_contract() -> ContractAddress { let contract_class = declare("HelloStarknet"); - contract_class.deploy(@array![]).unwrap() + contract_class.deploy([].span()).unwrap() } #[test] @@ -74,45 +74,45 @@ fn test_felt252() { let contract_address = deploy_hello_contract(); let state = HelloStarknet::contract_state_for_testing(); let variable_address = state.balance.address(); - + let new_balance = 420; store::(contract_address, variable_address, new_balance); let stored_value = load::(contract_address, variable_address); - - assert(stored_value == 420, 'Wrong balance stored'); + + assert(stored_value == 420, 'Wrong balance stored'); } #[test] fn test_legacy_map() { let contract_address = deploy_hello_contract(); let state = HelloStarknet::contract_state_for_testing(); - - + + let key = 420; let value = 69; let variable_address = state.map.address(key); - + store::(contract_address, variable_address, value); let stored_value = load::(contract_address, variable_address); - - assert(stored_value == 69, 'Wrong k:v stored'); + + assert(stored_value == 69, 'Wrong k:v stored'); } #[test] fn test_custom_struct() { let contract_address = deploy_hello_contract(); let state = HelloStarknet::contract_state_for_testing(); - - + + let a = 420; let b = 69; let value = CustomStruct {a, b}; let variable_address = state.custom_struct.address(); - + store::(contract_address, variable_address, value); let stored_value = load::(contract_address, variable_address); - + assert(stored_value.a == 420, 'Wrong custom_struct.a stored'); - assert(stored_value.b == 69, 'Wrong custom_struct.a stored'); + assert(stored_value.b == 69, 'Wrong custom_struct.a stored'); } ``` diff --git a/docs/src/testing/contracts.md b/docs/src/testing/contracts.md index 22344f2726..dc7459791f 100644 --- a/docs/src/testing/contracts.md +++ b/docs/src/testing/contracts.md @@ -1,7 +1,7 @@ # Testing Smart Contracts > ℹī¸ **Info** -> +> > To use the library functions designed for testing smart contracts, > you need to add `snforge_std` package as a dependency in > your [`Scarb.toml`](https://docs.swmansion.com/scarb/docs/guides/dependencies.html#development-dependencies) @@ -62,7 +62,7 @@ fn call_and_invoke() { // First declare and deploy a contract let contract = declare("HelloStarknet").unwrap().contract_class(); // Alternatively we could use `deploy_syscall` here - let (contract_address, _) = contract.deploy(@array![]).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); // Create a Dispatcher object that will allow interacting with the deployed contract let dispatcher = IHelloStarknetDispatcher { contract_address }; @@ -82,9 +82,9 @@ fn call_and_invoke() { ``` > 📝 **Note** -> +> > Notice that the arguments to the contract's constructor (the `deploy`'s `calldata` argument) need to be serialized with `Serde`. -> +> > `HelloStarknet` contract has no constructor, so the calldata remains empty in the example above. ```shell @@ -141,7 +141,7 @@ If we called this function in a test, it would result in a failure. #[test] fn failing() { let contract = declare("HelloStarknet").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@array![]).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = IHelloStarknetDispatcher { contract_address }; dispatcher.do_a_panic(); @@ -167,10 +167,10 @@ Failures: ### `SafeDispatcher` Using `SafeDispatcher` we can test that the function in fact panics with an expected message. -Safe dispatcher is a special kind of dispatcher, which are not allowed in contracts themselves, +Safe dispatcher is a special kind of dispatcher, which are not allowed in contracts themselves, but are available for testing purposes. -They allow using the contract without automatically unwrapping the result, which allows to catch the error like shown below. +They allow using the contract without automatically unwrapping the result, which allows to catch the error like shown below. ```rust // Add those to import safe dispatchers, which are autogenerated, like regular dispatchers @@ -181,7 +181,7 @@ use using_dispatchers::{ IHelloStarknetSafeDispatcher, IHelloStarknetSafeDispatc fn handling_errors() { // ... let contract = declare("HelloStarknet").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@calldata).unwrap().contract_class(); + let (contract_address, _) = contract.deploy(calldata.span()).unwrap().contract_class(); let safe_dispatcher = IHelloStarknetSafeDispatcher { contract_address }; match safe_dispatcher.do_a_panic() { @@ -217,7 +217,7 @@ use snforge_std::{declare, DeclareResultTrait}; fn handling_string_errors() { // ... let contract = declare("HelloStarknet").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@array![]).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let safe_dispatcher = IHelloStarknetSafeDispatcher { contract_address }; match safe_dispatcher.do_a_string_panic() { @@ -232,22 +232,22 @@ fn handling_string_errors() { }; } ``` -You also could skip the de-serialization of the `panic_data`, and not use `try_deserialize_bytearray_error`, but this way you can actually use assertions on the `ByteArray` that was used to panic. +You also could skip the de-serialization of the `panic_data`, and not use `try_deserialize_bytearray_error`, but this way you can actually use assertions on the `ByteArray` that was used to panic. > 📝 **Note** -> +> > To operate with `SafeDispatcher` it's required to annotate its usage with `#[feature("safe_dispatcher")]`. -> +> > There are 3 options: > - module-level declaration > ```rust > #[feature("safe_dispatcher")] -> mod my_module; +> mod my_module; > ``` > - function-level declaration > ```rust > #[feature("safe_dispatcher")] -> fn my_function() { ... } +> fn my_function() { ... } > ``` > - directly before the usage > ```rust diff --git a/docs/src/testing/testing-events.md b/docs/src/testing/testing-events.md index 4fa24c5445..4528b2b121 100644 --- a/docs/src/testing/testing-events.md +++ b/docs/src/testing/testing-events.md @@ -7,7 +7,7 @@ pub mod SpyEventsChecker { // ... #[storage] struct Storage {} - + #[event] #[derive(Drop, starknet::Event)] pub enum Event { @@ -18,7 +18,7 @@ pub mod SpyEventsChecker { pub struct FirstEvent { pub some_data: felt252 } - + #[external(v0)] fn emit_one_event(ref self: ContractState, some_data: felt252) { self.emit(FirstEvent { some_data }); @@ -37,7 +37,7 @@ See the below code for reference: use snforge_std::{ declare, ContractClassTrait, DeclareResultTrait spy_events, - EventSpyAssertionsTrait, // Add for assertions on the EventSpy + EventSpyAssertionsTrait, // Add for assertions on the EventSpy }; use SpyEventsChecker; @@ -50,7 +50,7 @@ trait ISpyEventsChecker { #[test] fn test_simple_assertions() { let contract = declare("SpyEventsChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@array![]).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = ISpyEventsCheckerDispatcher { contract_address }; let mut spy = spy_events(); // Ad. 1 @@ -70,7 +70,7 @@ fn test_simple_assertions() { Let's go through the code: -1. After contract deployment, we created the spy using `spy_events` cheatcode. From this moment all emitted events +1. After contract deployment, we created the spy using `spy_events` cheatcode. From this moment all emitted events will be spied. 2. Asserting is done using the `assert_emitted` method. It takes an array snapshot of `(ContractAddress, event)` tuples we expect that were emitted. @@ -97,11 +97,11 @@ spy.assert_not_emitted(@array![ ]); ``` -Note that both the event name and event data are checked. +Note that both the event name and event data are checked. If a function emitted an event with the same name but a different payload, the `assert_not_emitted` function will pass. ## Asserting the events manually -If you wish to assert the data manually, you can do that on the `Events` structure. +If you wish to assert the data manually, you can do that on the `Events` structure. Simply call `get_events()` on your `EventSpy` and access `events` field on the returned `Events` value. Then, you can access the events and assert data by yourself. @@ -110,7 +110,7 @@ use snforge_std::{ declare, ContractClassTrait, DeclareResultTrait, spy_events, EventSpyAssertionsTrait, - EventSpyTrait, // Add for fetching events directly + EventSpyTrait, // Add for fetching events directly Event, // A structure describing a raw `Event` }; @@ -122,7 +122,7 @@ trait ISpyEventsChecker { #[test] fn test_complex_assertions() { let contract = declare("SpyEventsChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@array![]).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = ISpyEventsCheckerDispatcher { contract_address }; let mut spy = spy_events(); // Ad 1. @@ -158,7 +158,7 @@ Since `events` is an array holding a tuple of `ContractAddress` and `Event`, we ## Filtering Events Sometimes, when you assert the events manually, you might not want to get all the events, but only ones from -a particular address. You can address that by using the method `emitted_by` on the `Events` structure. +a particular address. You can address that by using the method `emitted_by` on the `Events` structure. ```rust use snforge_std::{ @@ -167,7 +167,7 @@ use snforge_std::{ EventSpyAssertionsTrait, EventSpyTrait, Event, - EventsFilterTrait, // Add for filtering the Events object (result of `get_events`) + EventsFilterTrait, // Add for filtering the Events object (result of `get_events`) }; use SpyEventsChecker; @@ -180,8 +180,8 @@ trait ISpyEventsChecker { #[test] fn test_assertions_with_filtering() { let contract = declare("SpyEventsChecker").unwrap().contract_class(); - let (first_address, _) = contract.deploy(@array![]).unwrap(); - let (second_address, _) = contract.deploy(@array![]).unwrap(); + let (first_address, _) = contract.deploy([].span()).unwrap(); + let (second_address, _) = contract.deploy([].span()).unwrap(); let first_dispatcher = ISpyEventsCheckerDispatcher { contract_address: first_address }; let second_dispatcher = ISpyEventsCheckerDispatcher { contract_address: second_address }; @@ -250,7 +250,7 @@ trait ISpyEventsChecker { #[test] fn test_nonstandard_events() { let contract = declare("SpyEventsChecker").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@array![]).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = ISpyEventsCheckerDispatcher { contract_address }; let mut spy = spy_events(); diff --git a/docs/src/testing/using-cheatcodes.md b/docs/src/testing/using-cheatcodes.md index d2bc09f63a..935fd9af09 100644 --- a/docs/src/testing/using-cheatcodes.md +++ b/docs/src/testing/using-cheatcodes.md @@ -132,7 +132,7 @@ use snforge_std::{ declare, ContractClassTrait, DeclareResultTrait, start_cheat_ #[test] fn call_and_invoke() { let contract = declare("HelloStarknet").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let dispatcher = IHelloStarknetDispatcher { contract_address }; let balance = dispatcher.get_balance(); @@ -229,7 +229,7 @@ fn mock_constructor_with_cheat_caller_address() { ### Setting Cheatcode Span -Sometimes it's useful to have a cheatcode work only for a certain number of target calls. +Sometimes it's useful to have a cheatcode work only for a certain number of target calls. That's where [`CheatSpan`](../appendix/cheatcodes/cheat_span.md) comes in handy. @@ -266,7 +266,7 @@ use snforge_std::{ #[feature("safe_dispatcher")] fn call_and_invoke() { let contract = declare("HelloStarknet").unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); let safe_dispatcher = IHelloStarknetSafeDispatcher { contract_address }; let balance = safe_dispatcher.get_balance().unwrap(); diff --git a/snforge_std/src/cheatcodes/contract_class.cairo b/snforge_std/src/cheatcodes/contract_class.cairo index 02936d4475..475a46a43f 100644 --- a/snforge_std/src/cheatcodes/contract_class.cairo +++ b/snforge_std/src/cheatcodes/contract_class.cairo @@ -7,16 +7,22 @@ use super::super::_cheatcode::handle_cheatcode; use core::traits::Into; #[derive(Drop, Serde, Copy)] -struct ContractClass { +pub struct ContractClass { class_hash: ClassHash, } -#[derive(Drop, Serde, Clone)] -enum DeclareResult { +#[derive(Drop, Serde, Copy)] +pub enum DeclareResult { Success: ContractClass, AlreadyDeclared: ContractClass, } +impl ContractClassIntoClassHash of Into { + fn into(self: ContractClass) -> ClassHash { + self.class_hash + } +} + 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 @@ -26,7 +32,7 @@ trait ContractClassTrait { /// `constructor_calldata` - serialized calldata for the deploy constructor /// Returns the precalculated `ContractAddress` fn precalculate_address( - self: @ContractClass, constructor_calldata: @Array:: + self: @ContractClass, constructor_calldata: Span ) -> ContractAddress; /// Deploys a contract @@ -36,7 +42,7 @@ trait ContractClassTrait { /// Returns the address the contract was deployed at and serialized constructor return data, or /// panic data if it failed fn deploy( - self: @ContractClass, constructor_calldata: @Array:: + self: @ContractClass, constructor_calldata: Span ) -> SyscallResult<(ContractAddress, Span)>; /// Deploys a contract at a given address @@ -47,20 +53,21 @@ trait ContractClassTrait { /// Returns the address the contract was deployed at and serialized constructor return data, or /// panic data if it failed fn deploy_at( - self: @ContractClass, - constructor_calldata: @Array::, - contract_address: ContractAddress + self: @ContractClass, constructor_calldata: Span, contract_address: ContractAddress ) -> SyscallResult<(ContractAddress, Span)>; /// Utility method for creating a new `ContractClass` instance /// `class_hash` - a numeric value that can be converted into the class hash of `ContractClass` /// Returns the created `ContractClass` fn new>(class_hash: T) -> ContractClass; + + /// Returns the class hash of the contract + fn class_hash(self: @ContractClass) -> ClassHash; } impl ContractClassImpl of ContractClassTrait { fn precalculate_address( - self: @ContractClass, constructor_calldata: @Array:: + self: @ContractClass, constructor_calldata: Span ) -> ContractAddress { let mut inputs = _prepare_calldata(self.class_hash, constructor_calldata); @@ -70,7 +77,7 @@ impl ContractClassImpl of ContractClassTrait { } fn deploy( - self: @ContractClass, constructor_calldata: @Array:: + self: @ContractClass, constructor_calldata: Span ) -> SyscallResult<(ContractAddress, Span)> { let mut inputs = _prepare_calldata(self.class_hash, constructor_calldata); @@ -80,9 +87,7 @@ impl ContractClassImpl of ContractClassTrait { } fn deploy_at( - self: @ContractClass, - constructor_calldata: @Array::, - contract_address: ContractAddress + self: @ContractClass, constructor_calldata: Span, contract_address: ContractAddress ) -> SyscallResult<(ContractAddress, Span)> { let mut inputs = _prepare_calldata(self.class_hash, constructor_calldata); inputs.append(contract_address.into()); @@ -95,6 +100,10 @@ impl ContractClassImpl of ContractClassTrait { fn new>(class_hash: T) -> ContractClass { ContractClass { class_hash: class_hash.into() } } + + fn class_hash(self: @ContractClass) -> ClassHash { + *self.class_hash + } } trait DeclareResultTrait { @@ -133,16 +142,16 @@ fn declare(contract: ByteArray) -> Result> { /// Returns the `ClassHash` under given address fn get_class_hash(contract_address: ContractAddress) -> ClassHash { let mut span = handle_cheatcode( - cheatcode::<'get_class_hash'>(array![contract_address.into()].span()) + cheatcode::<'get_class_hash'>([contract_address.into()].span()) ); Serde::deserialize(ref span).unwrap() } fn _prepare_calldata( - class_hash: @ClassHash, constructor_calldata: @Array:: -) -> Array:: { - let class_hash: felt252 = class_hash.clone().into(); + class_hash: @ClassHash, constructor_calldata: Span +) -> Array { + let class_hash: felt252 = (*class_hash).into(); let mut inputs: Array:: = array![class_hash]; constructor_calldata.serialize(ref inputs); inputs diff --git a/snforge_std/src/cheatcodes/events.cairo b/snforge_std/src/cheatcodes/events.cairo index 7c5cdddc08..460ecad73e 100644 --- a/snforge_std/src/cheatcodes/events.cairo +++ b/snforge_std/src/cheatcodes/events.cairo @@ -1,11 +1,11 @@ use core::array::ArrayTrait; use core::option::OptionTrait; -use starknet::testing::cheatcode; -use starknet::ContractAddress; +use core::starknet::testing::cheatcode; +use core::starknet::ContractAddress; use super::super::_cheatcode::handle_cheatcode; /// Creates `EventSpy` instance that spies on all events emitted after its creation. -fn spy_events() -> EventSpy { +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(); @@ -13,8 +13,8 @@ fn spy_events() -> EventSpy { } /// Raw event format (as seen via the RPC-API), can be used for asserting the emitted events. -#[derive(Drop, Clone, Serde)] -struct Event { +#[derive(Drop, Clone, Serde, Debug)] +pub struct Event { keys: Array, data: Array } @@ -26,12 +26,12 @@ struct EventSpy { } /// A wrapper structure on an array of events to handle filtering smoothly. -#[derive(Drop, Serde)] -struct Events { +#[derive(Drop, Serde, Clone, Debug)] +pub struct Events { events: Array<(ContractAddress, Event)> } -trait EventSpyTrait { +pub trait EventSpyTrait { /// Gets all events given [`EventSpy`] spies for. fn get_events(ref self: EventSpy) -> Events; } @@ -47,7 +47,7 @@ impl EventSpyTraitImpl of EventSpyTrait { } } -trait EventsFilterTrait { +pub trait EventsFilterTrait { /// Filter events emitted by a given [`ContractAddress`]. fn emitted_by(self: @Events, contract_address: ContractAddress) -> Events; } @@ -70,7 +70,7 @@ impl EventsFilterTraitImpl of EventsFilterTrait { /// Allows to assert the expected events emission (or lack thereof), /// in the scope of [`EventSpy`] structure. -trait EventSpyAssertionsTrait, impl TDrop: Drop> { +pub trait EventSpyAssertionsTrait, impl TDrop: Drop> { fn assert_emitted(ref self: EventSpy, events: @Array<(ContractAddress, T)>); fn assert_not_emitted(ref self: EventSpy, events: @Array<(ContractAddress, T)>); } diff --git a/snforge_std/src/cheatcodes/l1_handler.cairo b/snforge_std/src/cheatcodes/l1_handler.cairo index 461564b1af..b417dce075 100644 --- a/snforge_std/src/cheatcodes/l1_handler.cairo +++ b/snforge_std/src/cheatcodes/l1_handler.cairo @@ -3,7 +3,7 @@ use core::serde::Serde; use starknet::{ContractAddress, testing::cheatcode, SyscallResult}; use super::super::_cheatcode::handle_cheatcode; -#[derive(Drop, Clone)] +#[derive(Drop, Copy)] struct L1Handler { target: ContractAddress, selector: felt252, diff --git a/starknet_forge_template/tests/test_contract.cairo b/starknet_forge_template/tests/test_contract.cairo index 494b36e114..2bace96a5b 100644 --- a/starknet_forge_template/tests/test_contract.cairo +++ b/starknet_forge_template/tests/test_contract.cairo @@ -9,7 +9,7 @@ use {{ PROJECT_NAME }}::IHelloStarknetDispatcherTrait; fn deploy_contract(name: ByteArray) -> ContractAddress { let contract = declare(name).unwrap().contract_class(); - let (contract_address, _) = contract.deploy(@ArrayTrait::new()).unwrap(); + let (contract_address, _) = contract.deploy([].span()).unwrap(); contract_address }