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/trace_resources/tests/test_call.cairo b/crates/forge/tests/data/trace_resources/tests/test_call.cairo index 9802913257..4d5c56f377 100644 --- a/crates/forge/tests/data/trace_resources/tests/test_call.cairo +++ b/crates/forge/tests/data/trace_resources/tests/test_call.cairo @@ -17,7 +17,7 @@ fn test_call() { 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([].span()).unwrap(); 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 24ee4a0e05..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 @@ -18,7 +18,7 @@ fn test_failed_call() { 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_l1_handler.cairo b/crates/forge/tests/data/trace_resources/tests/test_l1_handler.cairo index 636218ae0b..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 @@ -12,7 +12,7 @@ fn test_l1_handler() { 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/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..45972b111f 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_at([].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();