diff --git a/crates/starknet_os_flow_tests/src/test_manager.rs b/crates/starknet_os_flow_tests/src/test_manager.rs index 55783e87f7e..791f4b53586 100644 --- a/crates/starknet_os_flow_tests/src/test_manager.rs +++ b/crates/starknet_os_flow_tests/src/test_manager.rs @@ -119,7 +119,7 @@ pub(crate) static FUNDED_ACCOUNT_ADDRESS: LazyLock = LazyLock::new(|| get_initial_deploy_account_tx().contract_address); #[derive(Default)] -pub(crate) struct TestManagerConfig { +pub(crate) struct TestBuilderConfig { pub(crate) use_kzg_da: bool, pub(crate) full_output: bool, pub(crate) private_keys: Option>, @@ -390,7 +390,7 @@ impl TestRunner { let os_output = run_os_stateless(layout, self.os_hints).unwrap(); let decompressed_state_diff = - create_committer_state_diff(TestManager::::get_decompressed_state_diff( + create_committer_state_diff(TestBuilder::::get_decompressed_state_diff( &os_output, &final_state, entire_initial_reads.alias_keys(), @@ -407,8 +407,9 @@ impl TestRunner { } } -/// Manages the execution of flow tests by maintaining the initial state and transactions. -pub(crate) struct TestManager { +/// Builds flow tests by maintaining the initial state and transactions. +/// Use the builder methods to configure transactions, then call `build()` to get a `TestRunner`. +pub(crate) struct TestBuilder { pub(crate) initial_state: InitialState, pub(crate) nonce_manager: NonceManager, pub(crate) execution_contracts: OsExecutionContracts, @@ -420,11 +421,11 @@ pub(crate) struct TestManager { per_block_txs: Vec>, } -impl TestManager { - /// Creates a new `TestManager` with the provided initial state data. +impl TestBuilder { + /// Creates a new `TestBuilder` with the provided initial state data. pub(crate) fn new_with_initial_state_data( initial_state_data: InitialStateData, - config: TestManagerConfig, + config: TestBuilderConfig, ) -> Self { let public_keys = config.private_keys.as_ref().map(|private_keys| compute_public_keys(private_keys)); @@ -450,13 +451,12 @@ impl TestManager { } } - /// Creates a new `TestManager` with the default initial state. - /// Returns the manager and a nonce manager to help keep track of nonces. + /// Creates a new `TestBuilder` with the default initial state. /// Optionally provide an array of extra contracts to declare and deploy - the addresses of /// these contracts will be returned as an array of the same length. pub(crate) async fn new_with_default_initial_state( extra_contracts: [(FeatureContract, Calldata); N], - config: TestManagerConfig, + config: TestBuilderConfig, ) -> (Self, [ContractAddress; N]) { let (default_initial_state_data, extra_addresses) = create_default_initial_state_data::(extra_contracts).await; @@ -692,8 +692,10 @@ impl TestManager { decompress(&os_state_diff_maps, state, *ALIAS_CONTRACT_ADDRESS, alias_keys) } - // Executes the flow test. - pub(crate) async fn execute_flow_test(self) -> OsTestOutput { + /// Builds the test runner from the current state and transactions. + /// Returns a `TestRunner` that can be used to run the OS and get the test output. + pub(crate) async fn build(self) -> TestRunner { + // TODO(Yoni): make this func sync. let mut os_block_inputs = vec![]; let mut state = CachedState::new(self.initial_state.updatable_state); let mut map_storage = self.initial_state.commitment_storage; @@ -791,30 +793,34 @@ impl TestManager { let os_hints = OsHints { os_input: starknet_os_input, os_hints_config: self.os_hints_config }; - let test_runner = TestRunner { + TestRunner { os_hints, entire_cached_state: state, messages_to_l1: self.messages_to_l1, messages_to_l2: self.messages_to_l2, private_keys: self.private_keys, - }; - test_runner.run() + } + } + + /// Builds and runs the test, returning the test output. + pub(crate) async fn build_and_run(self) -> OsTestOutput { + self.build().await.run() } } -impl TestManager { +impl TestBuilder { pub(crate) async fn create_standard( extra_contracts: [(FeatureContract, Calldata); N], ) -> (Self, [ContractAddress; N]) { - Self::create_standard_with_config(extra_contracts, TestManagerConfig::default()).await + Self::create_standard_with_config(extra_contracts, TestBuilderConfig::default()).await } - /// Creates a new `TestManager` with the default initial state and the provided config. + /// Creates a new `TestBuilder` with the default initial state and the provided config. /// Uses `DictStateReader` as the state type. /// Returns the manager and an array of addresses for any extra contracts deployed. pub(crate) async fn create_standard_with_config( extra_contracts: [(FeatureContract, Calldata); N], - config: TestManagerConfig, + config: TestBuilderConfig, ) -> (Self, [ContractAddress; N]) { Self::new_with_default_initial_state(extra_contracts, config).await } diff --git a/crates/starknet_os_flow_tests/src/tests.rs b/crates/starknet_os_flow_tests/src/tests.rs index f0cf65694a6..d4f762bc4d1 100644 --- a/crates/starknet_os_flow_tests/src/tests.rs +++ b/crates/starknet_os_flow_tests/src/tests.rs @@ -100,8 +100,8 @@ use crate::special_contracts::{ V1_BOUND_CAIRO1_CONTRACT_SIERRA, }; use crate::test_manager::{ - TestManager, - TestManagerConfig, + TestBuilder, + TestBuilderConfig, FUNDED_ACCOUNT_ADDRESS, STRK_FEE_TOKEN_ADDRESS, }; @@ -165,12 +165,12 @@ async fn declare_deploy_scenario( // Initialize the test manager with a default initial state and get the nonce manager to help // keep track of nonces. - let (mut test_manager, _) = TestManager::create_standard_with_config( + let (mut test_builder, _) = TestBuilder::create_standard_with_config( [], - TestManagerConfig { use_kzg_da, full_output, ..Default::default() }, + TestBuilderConfig { use_kzg_da, full_output, ..Default::default() }, ) .await; - let chain_id = &test_manager.chain_id(); + let chain_id = &test_builder.chain_id(); // Declare a test contract. let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Casm)); @@ -182,13 +182,13 @@ async fn declare_deploy_scenario( class_hash, compiled_class_hash, resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS, - nonce: test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS), + nonce: test_builder.next_nonce(*FUNDED_ACCOUNT_ADDRESS), }; let account_declare_tx = declare_tx(declare_tx_args); let class_info = get_class_info_of_feature_contract(test_contract); let tx = DeclareTransaction::create(account_declare_tx, class_info, chain_id).unwrap(); // Add the transaction to the test manager. - test_manager.add_cairo1_declare_tx(tx, &test_contract_sierra); + test_builder.add_cairo1_declare_tx(tx, &test_contract_sierra); let arg1 = Felt::from(7); let arg2 = Felt::from(90); // Deploy the test contract using the deploy contract syscall. @@ -212,9 +212,9 @@ async fn declare_deploy_scenario( *FUNDED_ACCOUNT_ADDRESS, ) .unwrap(); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata: deploy_contract_calldata }); - test_manager.divide_transactions_into_n_blocks(n_blocks); - let test_output = test_manager.execute_flow_test().await; + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata: deploy_contract_calldata }); + test_builder.divide_transactions_into_n_blocks(n_blocks); + let test_output = test_builder.build_and_run().await; let partial_state_diff = StateDiff { // Deployed contract. @@ -258,9 +258,9 @@ async fn trivial_diff_scenario( // Initialize the test manager with a default initial state and get the nonce manager to help // keep track of nonces. - let (mut test_manager, [test_contract_address]) = TestManager::create_standard_with_config( + let (mut test_builder, [test_contract_address]) = TestBuilder::create_standard_with_config( [(test_contract, calldata![Felt::ONE, Felt::TWO])], - TestManagerConfig { use_kzg_da, full_output, ..Default::default() }, + TestBuilderConfig { use_kzg_da, full_output, ..Default::default() }, ) .await; @@ -269,15 +269,15 @@ async fn trivial_diff_scenario( let function_name = "test_storage_read_write"; // Invoke a function on the test contract that changes the key to the new value. let calldata = create_calldata(test_contract_address, function_name, &[key, value]); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Move to next block, and add an invoke that reverts the previous change. - test_manager.move_to_next_block(); + test_builder.move_to_next_block(); let calldata = create_calldata(test_contract_address, function_name, &[key, Felt::ZERO]); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Execute the test. - let test_output = test_manager.execute_flow_test().await; + let test_output = test_builder.build_and_run().await; // Explicitly check the test contract has no storage update. assert!( @@ -310,23 +310,23 @@ async fn test_reverted_invoke_tx( #[case] test_contract: FeatureContract, #[case] revert_reason: &str, ) { - let (mut test_manager, [test_contract_address]) = TestManager::create_standard_with_config( + let (mut test_builder, [test_contract_address]) = TestBuilder::create_standard_with_config( [(test_contract, calldata![Felt::ONE, Felt::TWO])], - TestManagerConfig { use_kzg_da: true, ..Default::default() }, + TestBuilderConfig { use_kzg_da: true, ..Default::default() }, ) .await; // Call a reverting function that changes the storage. let invoke_tx_args = invoke_tx_args! { sender_address: *FUNDED_ACCOUNT_ADDRESS, - nonce: test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS), + nonce: test_builder.next_nonce(*FUNDED_ACCOUNT_ADDRESS), calldata: create_calldata(test_contract_address, "write_and_revert", &[Felt::ONE, Felt::TWO]), resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS, }; - test_manager.add_invoke_tx_from_args(invoke_tx_args, Some(revert_reason.to_string())); + test_builder.add_invoke_tx_from_args(invoke_tx_args, Some(revert_reason.to_string())); // Execute the test. - let test_output = test_manager.execute_flow_test().await; + let test_output = test_builder.build_and_run().await; // Check that the storage was reverted (no change in test contract address). assert!( @@ -350,22 +350,22 @@ async fn test_encrypted_state_diff( Vec, >, ) { - let (mut test_manager, [test_contract_address]) = TestManager::create_standard_with_config( + let (mut test_builder, [test_contract_address]) = TestBuilder::create_standard_with_config( [( FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Casm)), calldata![Felt::ONE, Felt::TWO], )], - TestManagerConfig { use_kzg_da, full_output, private_keys: private_keys.clone() }, + TestBuilderConfig { use_kzg_da, full_output, private_keys: private_keys.clone() }, ) .await; // Invoke a function on the test contract that changes the storage. let (key, value) = (Felt::from(10u8), Felt::from(11u8)); let calldata = create_calldata(test_contract_address, "test_storage_read_write", &[key, value]); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Run the test and assert the diff is as expected. - let test_output = test_manager.execute_flow_test().await; + let test_output = test_builder.build_and_run().await; let perform_global_validations = true; let partial_state_diff = StateDiff { storage_updates: HashMap::from([( @@ -408,8 +408,8 @@ async fn test_reverted_l1_handler_tx( #[case] test_contract: FeatureContract, #[case] revert_reason: &str, ) { - let (mut test_manager, [test_contract_address]) = - TestManager::create_standard([(test_contract, calldata![Felt::ONE, Felt::TWO])]).await; + let (mut test_builder, [test_contract_address]) = + TestBuilder::create_standard([(test_contract, calldata![Felt::ONE, Felt::TWO])]).await; // Add a reverting L1 handler transaction that changes the storage. let tx = ExecutableL1HandlerTransaction::create( @@ -421,13 +421,13 @@ async fn test_reverted_l1_handler_tx( // from_address (L1 address), key, value. calldata: calldata![Felt::THREE, Felt::ONE, Felt::TWO], }, - &test_manager.chain_id(), + &test_builder.chain_id(), Fee(1_000_000), ) .unwrap(); - test_manager.add_l1_handler_tx(tx, Some(revert_reason.to_string())); + test_builder.add_l1_handler_tx(tx, Some(revert_reason.to_string())); - let test_output = test_manager.execute_flow_test().await; + let test_output = test_builder.build_and_run().await; // Check that the storage was reverted (no change in test contract address). assert!( @@ -446,8 +446,8 @@ async fn test_reverted_l1_handler_tx( async fn test_deprecated_call_contract_variants() { let test_contract = FeatureContract::TestContract(CairoVersion::Cairo0); let test_contract2 = FeatureContract::TestContract2; - let (mut test_manager, [test_contract_address, test_contract2_address]) = - TestManager::create_standard([ + let (mut test_builder, [test_contract_address, test_contract2_address]) = + TestBuilder::create_standard([ (test_contract, calldata![Felt::ZERO, Felt::ZERO]), (test_contract2, calldata![]), ]) @@ -465,7 +465,7 @@ async fn test_deprecated_call_contract_variants() { Felt::from(666), ], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); let calldata = create_calldata( test_contract_address, @@ -480,10 +480,10 @@ async fn test_deprecated_call_contract_variants() { ], ); let signature = TransactionSignature(Arc::new(vec![Felt::from(100)])); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata, signature }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata, signature }); // Run the test. - let test_output = test_manager.execute_flow_test().await; + let test_output = test_builder.build_and_run().await; test_output.perform_default_validations(); test_output.expect_hint_coverage("test_deprecated_call_contract_variants"); } @@ -494,12 +494,12 @@ async fn test_os_logic( #[values(1, 3)] n_blocks_in_multi_block: usize, #[values(None, Some(vec![Felt::ONE, Felt::TWO]))] private_keys: Option>, ) { - let (mut test_manager, _) = TestManager::create_standard_with_config( + let (mut test_builder, _) = TestBuilder::create_standard_with_config( [], - TestManagerConfig { private_keys: private_keys.clone(), ..Default::default() }, + TestBuilderConfig { private_keys: private_keys.clone(), ..Default::default() }, ) .await; - let chain_id = &test_manager.chain_id(); + let chain_id = &test_builder.chain_id(); let n_expected_txs = 31; let mut expected_storage_updates = HashMap::new(); @@ -515,7 +515,7 @@ async fn test_os_logic( let account_declare_tx = declare_tx(declare_args); let class_info = get_class_info_of_feature_contract(cairo0_test_contract); let tx = DeclareTransaction::create(account_declare_tx, class_info, chain_id).unwrap(); - test_manager + test_builder .add_cairo0_declare_tx(tx, get_class_hash_of_feature_contract(cairo0_test_contract)); // Deploy some instances of the deprecated (cairo0) test contract. @@ -527,12 +527,12 @@ async fn test_os_logic( let (deploy_tx, address) = get_deploy_contract_tx_and_address_with_salt( test_class_hash, Calldata(Arc::new(ctor_calldata.into_iter().map(Felt::from).collect())), - test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS), + test_builder.next_nonce(*FUNDED_ACCOUNT_ADDRESS), *NON_TRIVIAL_RESOURCE_BOUNDS, contract_address_salt, ); contract_addresses.push(address); - test_manager.add_invoke_tx(deploy_tx, None); + test_builder.add_invoke_tx(deploy_tx, None); // Update expected storage diff, if the ctor calldata writes a nonzero value. if ctor_calldata[1] != 0 { update_expected_storage( @@ -548,7 +548,7 @@ async fn test_os_logic( // Used to test normal value update and make sure it is written to on-chain data. let (key, value) = (Felt::from(85), Felt::from(47)); let calldata = create_calldata(contract_addresses[0], "test_storage_read_write", &[key, value]); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); update_expected_storage(&mut expected_storage_updates, contract_addresses[0], key, value); // Call set_value(address=81, value=0) on the first contract. @@ -559,7 +559,7 @@ async fn test_os_logic( "test_storage_read_write", &[Felt::from(81), Felt::ZERO], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Call set_value(address=97, value=0). // Used to test redundant value update (0 -> 0) in contract with only redundant updates @@ -569,10 +569,10 @@ async fn test_os_logic( "test_storage_read_write", &[Felt::from(97), Felt::ZERO], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); let calldata = create_calldata(contract_addresses[1], "read_write_read", &[]); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); update_expected_storage( &mut expected_storage_updates, contract_addresses[1], @@ -581,7 +581,7 @@ async fn test_os_logic( ); let calldata = create_calldata(contract_addresses[0], "test_builtins", &[]); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Call test_get_block_timestamp with the current (testing) block timestamp. let calldata = create_calldata( @@ -589,7 +589,7 @@ async fn test_os_logic( "test_get_block_timestamp", &[Felt::from(CURRENT_BLOCK_TIMESTAMP)], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // TODO(Yoni): test the effect of the event emission on the block hash, once calculated in the // OS. @@ -599,13 +599,13 @@ async fn test_os_logic( // n_events, keys_len, keys, data_len, data. &[Felt::ONE, Felt::ONE, Felt::from(1991), Felt::ONE, Felt::from(2021)], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Calculate the block number of the next transaction. let txs_per_block = n_expected_txs / n_blocks_in_multi_block; // Calculate the block number of tx 'len(txs) + 1' without the added empty block. - let mut block_number_offset = (test_manager.total_txs() + 1) / txs_per_block; - if block_number_offset * txs_per_block < test_manager.total_txs() + 1 { + let mut block_number_offset = (test_builder.total_txs() + 1) / txs_per_block; + if block_number_offset * txs_per_block < test_builder.total_txs() + 1 { block_number_offset += 1; } // If the block number is the last then we added an empty block before this block so its @@ -616,13 +616,13 @@ async fn test_os_logic( // Call test_get_block_number(expected_block_number). let expected_block_number = - test_manager.first_block_number().0 - 1 + u64::try_from(block_number_offset).unwrap(); + test_builder.first_block_number().0 - 1 + u64::try_from(block_number_offset).unwrap(); let calldata = create_calldata( contract_addresses[0], "test_get_block_number", &[Felt::from(expected_block_number)], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Call contract -> send message to L1. let inner_calldata = [Felt::from(85)]; @@ -636,8 +636,8 @@ async fn test_os_logic( inner_calldata[0], ], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); - test_manager.messages_to_l1.push(MessageToL1 { + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.messages_to_l1.push(MessageToL1 { from_address: contract_addresses[0], to_address: EthAddress::try_from(Felt::from(85)).unwrap(), payload: L2ToL1Payload(vec![Felt::from(12), Felt::from(34)]), @@ -654,14 +654,14 @@ async fn test_os_logic( **contract_addresses[0], // Expected caller address. ], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); let calldata = create_calldata( contract_addresses[0], "test_get_contract_address", &[**contract_addresses[0]], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Test get_sequencer_address syscall. let calldata = create_calldata( @@ -669,12 +669,12 @@ async fn test_os_logic( "test_get_sequencer_address", &[Felt::from_hex_unchecked(TEST_SEQUENCER_ADDRESS)], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Test tx_version syscall. let calldata = create_calldata(contract_addresses[0], "test_tx_version", &[TransactionVersion::THREE.0]); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Delegate proxy tests. @@ -690,22 +690,22 @@ async fn test_os_logic( }); let class_info = get_class_info_of_feature_contract(delegate_proxy_contract); let tx = DeclareTransaction::create(delegate_proxy_declare_tx, class_info, chain_id).unwrap(); - test_manager.add_cairo0_declare_tx(tx, delegate_proxy_class_hash); + test_builder.add_cairo0_declare_tx(tx, delegate_proxy_class_hash); let contract_address_salt = ContractAddressSalt(Felt::ZERO); let (deploy_tx, delegate_proxy_address) = get_deploy_contract_tx_and_address_with_salt( delegate_proxy_class_hash, Calldata::default(), - test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS), + test_builder.next_nonce(*FUNDED_ACCOUNT_ADDRESS), *NON_TRIVIAL_RESOURCE_BOUNDS, contract_address_salt, ); - test_manager.add_invoke_tx(deploy_tx, None); + test_builder.add_invoke_tx(deploy_tx, None); // Set implementation to the test contract. let calldata = create_calldata(delegate_proxy_address, "set_implementation_hash", &[test_class_hash.0]); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); update_expected_storage( &mut expected_storage_updates, delegate_proxy_address, @@ -720,13 +720,13 @@ async fn test_os_logic( "test_get_contract_address", &[**delegate_proxy_address], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Call set_value(address=123, value=456) through the delegate proxy. let (key, value) = (Felt::from(123), Felt::from(456)); let calldata = create_calldata(delegate_proxy_address, "test_storage_read_write", &[key, value]); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); update_expected_storage(&mut expected_storage_updates, delegate_proxy_address, key, value); // Call test_get_caller_address(expected_address=account_address) through the delegate proxy. @@ -735,7 +735,7 @@ async fn test_os_logic( "test_get_caller_address", &[***FUNDED_ACCOUNT_ADDRESS], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // call_contract -> get_sequencer_address. let calldata = create_calldata( @@ -748,7 +748,7 @@ async fn test_os_logic( Felt::from_hex_unchecked(TEST_SEQUENCER_ADDRESS), ], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Invoke the l1_handler deposit(from_address=85, amount=2) through the delegate proxy, and // define the expected consumed message. @@ -767,7 +767,7 @@ async fn test_os_logic( Fee(1_000_000), ) .unwrap(); - test_manager.add_l1_handler_tx(tx, None); + test_builder.add_l1_handler_tx(tx, None); update_expected_storage( &mut expected_storage_updates, delegate_proxy_address, @@ -782,7 +782,7 @@ async fn test_os_logic( "test_library_call_syntactic_sugar", &[test_class_hash.0], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); update_expected_storage( &mut expected_storage_updates, contract_addresses[0], @@ -794,7 +794,7 @@ async fn test_os_logic( let index = Felt::from(2021); let calldata = create_calldata(contract_addresses[0], "add_signature_to_counters", &[index]); let signature = TransactionSignature(Arc::new(vec![Felt::from(100), Felt::from(200)])); - test_manager + test_builder .add_funded_account_invoke(invoke_tx_args! { calldata, signature: signature.clone() }); update_expected_storage( &mut expected_storage_updates, @@ -820,7 +820,7 @@ async fn test_os_logic( }); let class_info = get_class_info_of_feature_contract(test_contract2); let tx = DeclareTransaction::create(test_contract2_declare_tx, class_info, chain_id).unwrap(); - test_manager.add_cairo0_declare_tx(tx, test_contract2_class_hash); + test_builder.add_cairo0_declare_tx(tx, test_contract2_class_hash); // Use library_call to call test_contract2.test_storage_write(address=555, value=888). let (key, value) = (Felt::from(555), Felt::from(888)); @@ -835,7 +835,7 @@ async fn test_os_logic( value, ], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); update_expected_storage(&mut expected_storage_updates, contract_addresses[1], key, value); // Use library_call_l1_handler to invoke test_contract2.test_l1_handler_storage_write with @@ -853,7 +853,7 @@ async fn test_os_logic( value, ], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); update_expected_storage(&mut expected_storage_updates, contract_addresses[1], key, value); // Replace the class of contract_addresses[0] to the class of test_contract2. @@ -862,15 +862,15 @@ async fn test_os_logic( "test_replace_class", &[test_contract2_class_hash.0], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Expected number of txs. - assert_eq!(test_manager.total_txs(), n_expected_txs); + assert_eq!(test_builder.total_txs(), n_expected_txs); // Run the test. - test_manager.divide_transactions_into_n_blocks(n_blocks_in_multi_block); + test_builder.divide_transactions_into_n_blocks(n_blocks_in_multi_block); let n_private_keys = private_keys.map(|keys| keys.len()).unwrap_or(0); - let test_output = test_manager.execute_flow_test().await; + let test_output = test_builder.build_and_run().await; // Perform validations. let perform_global_validations = true; @@ -888,8 +888,8 @@ async fn test_v1_bound_accounts_cairo0() { let test_contract = &V1_BOUND_CAIRO0_CONTRACT; let class_hash = ClassHash(compute_deprecated_class_hash(test_contract).unwrap()); let vc = VersionedConstants::latest_constants(); - let (mut test_manager, _) = TestManager::create_standard([]).await; - let chain_id = &test_manager.chain_id(); + let (mut test_builder, _) = TestBuilder::create_standard([]).await; + let chain_id = &test_builder.chain_id(); assert!(vc.os_constants.v1_bound_accounts_cairo0.contains(&class_hash)); @@ -903,25 +903,25 @@ async fn test_v1_bound_accounts_cairo0() { let account_declare_tx = declare_tx(declare_args); let class_info = get_class_info_of_cairo0_contract((**test_contract).clone()); let tx = DeclareTransaction::create(account_declare_tx, class_info, chain_id).unwrap(); - test_manager.add_cairo0_declare_tx(tx, class_hash); + test_builder.add_cairo0_declare_tx(tx, class_hash); // Deploy it. let salt = ContractAddressSalt(Felt::ZERO); let (deploy_tx, v1_bound_account_address) = get_deploy_contract_tx_and_address_with_salt( class_hash, Calldata::default(), - test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS), + test_builder.next_nonce(*FUNDED_ACCOUNT_ADDRESS), *NON_TRIVIAL_RESOURCE_BOUNDS, salt, ); - test_manager.add_invoke_tx(deploy_tx, None); + test_builder.add_invoke_tx(deploy_tx, None); // Initialize the account. let private_key = Felt::ONE; let public_key = get_public_key(&private_key); let guardian = Felt::ZERO; let calldata = create_calldata(v1_bound_account_address, "initialize", &[public_key, guardian]); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Create a validate tx and add signature to the transaction. The dummy account used to call // `__validate__` does not check the signature, so we can use the signature field for @@ -929,7 +929,7 @@ async fn test_v1_bound_accounts_cairo0() { // to the transaction hash. let validate_tx_args = invoke_tx_args! { sender_address: *FUNDED_ACCOUNT_ADDRESS, - nonce: test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS), + nonce: test_builder.next_nonce(*FUNDED_ACCOUNT_ADDRESS), calldata: create_calldata( v1_bound_account_address, "__validate__", &[Felt::ZERO, Felt::ZERO] ), @@ -944,10 +944,10 @@ async fn test_v1_bound_accounts_cairo0() { signature: TransactionSignature(Arc::new(vec![r, s])), ..validate_tx_args }; - test_manager.add_invoke_tx_from_args(validate_tx_args, None); + test_builder.add_invoke_tx_from_args(validate_tx_args, None); // Run test and verify the signer was set. - let test_output = test_manager.execute_flow_test().await; + let test_output = test_builder.build_and_run().await; let expected_storage_updates = HashMap::from([( v1_bound_account_address, @@ -973,13 +973,13 @@ async fn test_v1_bound_accounts_cairo1() { let vc = VersionedConstants::latest_constants(); let max_tip = vc.os_constants.v1_bound_accounts_max_tip; assert!(vc.os_constants.v1_bound_accounts_cairo1.contains(&class_hash)); - let (mut test_manager, _) = TestManager::create_standard([]).await; - let chain_id = &test_manager.chain_id(); + let (mut test_builder, _) = TestBuilder::create_standard([]).await; + let chain_id = &test_builder.chain_id(); // Declare the V1-bound account. let declare_args = declare_tx_args! { sender_address: *FUNDED_ACCOUNT_ADDRESS, - nonce: test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS), + nonce: test_builder.next_nonce(*FUNDED_ACCOUNT_ADDRESS), class_hash, compiled_class_hash, resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS, @@ -993,7 +993,7 @@ async fn test_v1_bound_accounts_cairo1() { sierra_version, }; let tx = DeclareTransaction::create(account_declare_tx, class_info, chain_id).unwrap(); - test_manager.add_cairo1_declare_tx(tx, test_contract_sierra); + test_builder.add_cairo1_declare_tx(tx, test_contract_sierra); // Deploy it (from funded account). let private_key = Felt::ONE; @@ -1002,20 +1002,20 @@ async fn test_v1_bound_accounts_cairo1() { let (deploy_tx, v1_bound_account_address) = get_deploy_contract_tx_and_address_with_salt( class_hash, Calldata(Arc::new(vec![public_key])), - test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS), + test_builder.next_nonce(*FUNDED_ACCOUNT_ADDRESS), *NON_TRIVIAL_RESOURCE_BOUNDS, salt, ); - test_manager.add_invoke_tx(deploy_tx, None); + test_builder.add_invoke_tx(deploy_tx, None); // Transfer funds to the account. let transfer_amount = 2 * NON_TRIVIAL_RESOURCE_BOUNDS.max_possible_fee(max_tip).0; - test_manager.add_fund_address_tx(v1_bound_account_address, transfer_amount); + test_builder.add_fund_address_tx(v1_bound_account_address, transfer_amount); // Create an invoke tx, compute the hash, sign the hash and update the signature on the tx. let invoke_tx_args = invoke_tx_args! { sender_address: v1_bound_account_address, - nonce: test_manager.next_nonce(v1_bound_account_address), + nonce: test_builder.next_nonce(v1_bound_account_address), calldata: Calldata(Arc::new(vec![Felt::ZERO])), resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS, }; @@ -1026,10 +1026,10 @@ async fn test_v1_bound_accounts_cairo1() { signature: TransactionSignature(Arc::new(vec![r, s])), ..invoke_tx_args }; - test_manager.add_invoke_tx_from_args(invoke_tx_args, None); + test_builder.add_invoke_tx_from_args(invoke_tx_args, None); // Run the test, and make sure the account storage has the expected changes. - let test_output = test_manager.execute_flow_test().await; + let test_output = test_builder.build_and_run().await; let isrc6_id = Felt::from_hex_unchecked( "0x2CECCEF7F994940B3962A6C67E0BA4FCD37DF7D131417C604F91E03CAECC1CD", ); @@ -1062,13 +1062,13 @@ async fn test_v1_bound_accounts_cairo1() { async fn test_new_class_execution_info(#[values(true, false)] use_kzg_da: bool) { let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Casm)); let test_class_hash = get_class_hash_of_feature_contract(test_contract); - let (mut test_manager, [main_contract_address]) = TestManager::create_standard_with_config( + let (mut test_builder, [main_contract_address]) = TestBuilder::create_standard_with_config( [(test_contract, calldata![Felt::ZERO, Felt::ZERO])], - TestManagerConfig { use_kzg_da, ..Default::default() }, + TestBuilderConfig { use_kzg_da, ..Default::default() }, ) .await; - let chain_id = &test_manager.chain_id(); - let current_block_number = test_manager.first_block_number(); + let chain_id = &test_builder.chain_id(); + let current_block_number = test_builder.first_block_number(); assert!( current_block_number.0 > STORED_BLOCK_HASH_BUFFER, @@ -1092,13 +1092,13 @@ async fn test_new_class_execution_info(#[values(true, false)] use_kzg_da: bool) BlockTimestamp(CURRENT_BLOCK_TIMESTAMP), contract_address!(TEST_SEQUENCER_ADDRESS), *NON_TRIVIAL_RESOURCE_BOUNDS, - test_manager.get_nonce(*FUNDED_ACCOUNT_ADDRESS), + test_builder.get_nonce(*FUNDED_ACCOUNT_ADDRESS), proof_facts.clone(), ) .to_syscall_result(); let invoke_tx_args = invoke_tx_args! { sender_address: *FUNDED_ACCOUNT_ADDRESS, - nonce: test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS), + nonce: test_builder.next_nonce(*FUNDED_ACCOUNT_ADDRESS), calldata: create_calldata( main_contract_address, test_execution_info_selector_name, &expected_execution_info ), @@ -1107,7 +1107,7 @@ async fn test_new_class_execution_info(#[values(true, false)] use_kzg_da: bool) }; // Put the tx hash in the signature. let tx = InvokeTransaction::create(invoke_tx(invoke_tx_args.clone()), chain_id).unwrap(); - test_manager.add_invoke_tx_from_args( + test_builder.add_invoke_tx_from_args( invoke_tx_args! { signature: TransactionSignature(Arc::new(vec![tx.tx_hash.0])), ..invoke_tx_args @@ -1131,7 +1131,7 @@ async fn test_new_class_execution_info(#[values(true, false)] use_kzg_da: bool) deploy_from_zero, ], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata, tip: Tip(1234) }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata, tip: Tip(1234) }); let contract_address2 = calculate_contract_address( ContractAddressSalt(salt), test_class_hash, @@ -1153,13 +1153,13 @@ async fn test_new_class_execution_info(#[values(true, false)] use_kzg_da: bool) BlockTimestamp(CURRENT_BLOCK_TIMESTAMP), contract_address!(TEST_SEQUENCER_ADDRESS), *NON_TRIVIAL_RESOURCE_BOUNDS, - test_manager.get_nonce(*FUNDED_ACCOUNT_ADDRESS), + test_builder.get_nonce(*FUNDED_ACCOUNT_ADDRESS), ProofFacts::default(), ) .to_syscall_result(); let invoke_tx_args = invoke_tx_args! { sender_address: *FUNDED_ACCOUNT_ADDRESS, - nonce: test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS), + nonce: test_builder.next_nonce(*FUNDED_ACCOUNT_ADDRESS), calldata: create_calldata( main_contract_address, test_call_contract_selector_name, @@ -1173,7 +1173,7 @@ async fn test_new_class_execution_info(#[values(true, false)] use_kzg_da: bool) }; // Put the tx hash in the signature. let invoke_tx = InvokeTransaction::create(invoke_tx(invoke_tx_args.clone()), chain_id).unwrap(); - test_manager.add_invoke_tx_from_args( + test_builder.add_invoke_tx_from_args( invoke_tx_args! { signature: TransactionSignature(Arc::new(vec![invoke_tx.tx_hash.0])), ..invoke_tx_args @@ -1182,7 +1182,7 @@ async fn test_new_class_execution_info(#[values(true, false)] use_kzg_da: bool) ); // Run the test. - let test_output = test_manager.execute_flow_test().await; + let test_output = test_builder.build_and_run().await; // Perform general validations and storage update validations. test_output.perform_default_validations(); @@ -1199,12 +1199,12 @@ async fn test_new_class_execution_info(#[values(true, false)] use_kzg_da: bool) #[rstest] #[tokio::test] async fn test_experimental_libfuncs_contract(#[values(true, false)] use_kzg_da: bool) { - let (mut test_manager, []) = TestManager::create_standard_with_config( + let (mut test_builder, []) = TestBuilder::create_standard_with_config( [], - TestManagerConfig { use_kzg_da, ..Default::default() }, + TestBuilderConfig { use_kzg_da, ..Default::default() }, ) .await; - let chain_id = &test_manager.chain_id(); + let chain_id = &test_builder.chain_id(); // Declare the experimental contract. // Test the bootstrap variant of the V3 transaction. @@ -1224,20 +1224,20 @@ async fn test_experimental_libfuncs_contract(#[values(true, false)] use_kzg_da: let account_declare_tx = declare_tx(declare_tx_args); let class_info = get_class_info_of_feature_contract(experimental_contract); let tx = DeclareTransaction::create(account_declare_tx, class_info, chain_id).unwrap(); - test_manager.add_cairo1_declare_tx(tx, &experimental_contract_sierra); + test_builder.add_cairo1_declare_tx(tx, &experimental_contract_sierra); // Deploy it. let salt = ContractAddressSalt(Felt::ZERO); let (deploy_tx, _experimental_contract_address) = get_deploy_contract_tx_and_address_with_salt( experimental_class_hash, Calldata::default(), - test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS), + test_builder.next_nonce(*FUNDED_ACCOUNT_ADDRESS), *NON_TRIVIAL_RESOURCE_BOUNDS, salt, ); - test_manager.add_invoke_tx(deploy_tx, None); + test_builder.add_invoke_tx(deploy_tx, None); - let test_output = test_manager.execute_flow_test().await; + let test_output = test_builder.build_and_run().await; test_output.perform_default_validations(); // Validate poseidon usage. @@ -1271,13 +1271,13 @@ async fn test_experimental_libfuncs_contract(#[values(true, false)] use_kzg_da: #[rstest] #[tokio::test] async fn test_new_account_flow(#[values(true, false)] use_kzg_da: bool) { - let (mut test_manager, []) = TestManager::create_standard_with_config( + let (mut test_builder, []) = TestBuilder::create_standard_with_config( [], - TestManagerConfig { use_kzg_da, ..Default::default() }, + TestBuilderConfig { use_kzg_da, ..Default::default() }, ) .await; - let chain_id = &test_manager.chain_id(); - let current_block_number = test_manager.first_block_number(); + let chain_id = &test_builder.chain_id(); + let current_block_number = test_builder.first_block_number(); assert!( current_block_number.0 > STORED_BLOCK_HASH_BUFFER, @@ -1296,12 +1296,12 @@ async fn test_new_account_flow(#[values(true, false)] use_kzg_da: bool) { class_hash: faulty_account_class_hash, compiled_class_hash: faulty_account_compiled_class_hash, resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS, - nonce: test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS), + nonce: test_builder.next_nonce(*FUNDED_ACCOUNT_ADDRESS), }; let account_declare_tx = declare_tx(declare_tx_args); let class_info = get_class_info_of_feature_contract(faulty_account); let tx = DeclareTransaction::create(account_declare_tx, class_info, chain_id).unwrap(); - test_manager.add_cairo1_declare_tx(tx, &faulty_account_sierra); + test_builder.add_cairo1_declare_tx(tx, &faulty_account_sierra); // Deploy it. let salt = ContractAddressSalt(Felt::ZERO); @@ -1310,11 +1310,11 @@ async fn test_new_account_flow(#[values(true, false)] use_kzg_da: bool) { let (deploy_tx, _) = get_deploy_contract_tx_and_address_with_salt( faulty_account_class_hash, ctor_calldata.clone(), - test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS), + test_builder.next_nonce(*FUNDED_ACCOUNT_ADDRESS), *NON_TRIVIAL_RESOURCE_BOUNDS, salt, ); - test_manager.add_invoke_tx(deploy_tx, None); + test_builder.add_invoke_tx(deploy_tx, None); // Prepare deploying an instance of the account by precomputing the address and funding it. let valid = Felt::ZERO; @@ -1327,7 +1327,7 @@ async fn test_new_account_flow(#[values(true, false)] use_kzg_da: bool) { ) .unwrap(); // Fund the address. - test_manager.add_fund_address_tx_with_default_amount(faulty_account_address); + test_builder.add_fund_address_tx_with_default_amount(faulty_account_address); // Create a DeployAccount transaction. let deploy_tx_args = deploy_account_tx_args! { @@ -1338,8 +1338,8 @@ async fn test_new_account_flow(#[values(true, false)] use_kzg_da: bool) { constructor_calldata: ctor_calldata, }; let deploy_account_tx = - deploy_account_tx(deploy_tx_args, test_manager.next_nonce(faulty_account_address)); - test_manager.add_deploy_account_tx( + deploy_account_tx(deploy_tx_args, test_builder.next_nonce(faulty_account_address)); + test_builder.add_deploy_account_tx( DeployAccountTransaction::create(deploy_account_tx, chain_id).unwrap(), ); @@ -1354,15 +1354,15 @@ async fn test_new_account_flow(#[values(true, false)] use_kzg_da: bool) { class_hash: empty_contract_class_hash, compiled_class_hash: empty_contract_compiled_class_hash, resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS, - nonce: test_manager.next_nonce(faulty_account_address), + nonce: test_builder.next_nonce(faulty_account_address), signature: TransactionSignature(Arc::new(vec![valid])), }; let account_declare_tx = declare_tx(declare_tx_args); let class_info = get_class_info_of_feature_contract(empty_contract); let tx = DeclareTransaction::create(account_declare_tx, class_info, chain_id).unwrap(); - test_manager.add_cairo1_declare_tx(tx, &empty_contract_sierra); + test_builder.add_cairo1_declare_tx(tx, &empty_contract_sierra); // The faulty account's __execute__ sends a message to L1. - test_manager.messages_to_l1.push(MessageToL1 { + test_builder.messages_to_l1.push(MessageToL1 { from_address: faulty_account_address, to_address: EthAddress::default(), payload: L2ToL1Payload::default(), @@ -1371,21 +1371,21 @@ async fn test_new_account_flow(#[values(true, false)] use_kzg_da: bool) { // Invoke a function on the new account. let invoke_tx_args = invoke_tx_args! { sender_address: faulty_account_address, - nonce: test_manager.next_nonce(faulty_account_address), + nonce: test_builder.next_nonce(faulty_account_address), calldata: create_calldata(faulty_account_address, "foo", &[]), resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS, signature: TransactionSignature(Arc::new(vec![valid])), }; - test_manager.add_invoke_tx_from_args(invoke_tx_args, None); + test_builder.add_invoke_tx_from_args(invoke_tx_args, None); // The faulty account's __execute__ sends a message to L1. - test_manager.messages_to_l1.push(MessageToL1 { + test_builder.messages_to_l1.push(MessageToL1 { from_address: faulty_account_address, to_address: EthAddress::default(), payload: L2ToL1Payload::default(), }); // Run the test. - let test_output = test_manager.execute_flow_test().await; + let test_output = test_builder.build_and_run().await; // Perform general validations and storage update validations. test_output.perform_default_validations(); @@ -1406,16 +1406,16 @@ async fn test_new_account_flow(#[values(true, false)] use_kzg_da: bool) { async fn test_new_syscalls_flow(#[case] use_kzg_da: bool, #[case] n_blocks_in_multi_block: usize) { let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Casm)); let test_class_hash = get_class_hash_of_feature_contract(test_contract); - let (mut test_manager, [main_contract_address, contract_address2]) = - TestManager::create_standard_with_config( + let (mut test_builder, [main_contract_address, contract_address2]) = + TestBuilder::create_standard_with_config( [ (test_contract, calldata![Felt::ZERO, Felt::ZERO]), (test_contract, calldata![Felt::ZERO, Felt::ZERO]), ], - TestManagerConfig { use_kzg_da, ..Default::default() }, + TestBuilderConfig { use_kzg_da, ..Default::default() }, ) .await; - let current_block_number = test_manager.first_block_number(); + let current_block_number = test_builder.first_block_number(); assert!( current_block_number.0 > STORED_BLOCK_HASH_BUFFER, @@ -1433,7 +1433,7 @@ async fn test_new_syscalls_flow(#[case] use_kzg_da: bool, #[case] n_blocks_in_mu "test_increment", &[felt!(5u8), felt!(6u8), felt!(7u8)], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); } update_expected_storage( &mut expected_storage_updates, @@ -1458,7 +1458,7 @@ async fn test_new_syscalls_flow(#[case] use_kzg_da: bool, #[case] n_blocks_in_mu test_call_contract_value, ], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); update_expected_storage( &mut expected_storage_updates, contract_address2, @@ -1482,7 +1482,7 @@ async fn test_new_syscalls_flow(#[case] use_kzg_da: bool, #[case] n_blocks_in_mu undeployed_address, ], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Test send-message-to-L1 syscall. let test_send_message_to_l1_to_address = Felt::ZERO; @@ -1500,8 +1500,8 @@ async fn test_new_syscalls_flow(#[case] use_kzg_da: bool, #[case] n_blocks_in_mu test_send_message_to_l1_payload[1], ], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); - test_manager.messages_to_l1.push(MessageToL1 { + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.messages_to_l1.push(MessageToL1 { from_address: contract_address2, to_address: EthAddress::try_from(test_send_message_to_l1_to_address).unwrap(), payload: L2ToL1Payload(test_send_message_to_l1_payload), @@ -1509,15 +1509,15 @@ async fn test_new_syscalls_flow(#[case] use_kzg_da: bool, #[case] n_blocks_in_mu // Call test_poseidon_hades_permutation. let calldata = create_calldata(main_contract_address, "test_poseidon_hades_permutation", &[]); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Call test_keccak. let calldata = create_calldata(main_contract_address, "test_keccak", &[]); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Call test_ec_op. let calldata = create_calldata(main_contract_address, "test_ec_op", &[]); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Points for keccak / secp tests. let x_low = Felt::from(302934307671667531413257853548643485645u128); @@ -1528,7 +1528,7 @@ async fn test_new_syscalls_flow(#[case] use_kzg_da: bool, #[case] n_blocks_in_mu // Call test_keccak. let calldata = create_calldata(main_contract_address, "test_new_point_secp256k1", &[x_low, x_high]); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Call test_getter_secp256k1. let calldata = create_calldata( @@ -1536,7 +1536,7 @@ async fn test_new_syscalls_flow(#[case] use_kzg_da: bool, #[case] n_blocks_in_mu "test_getter_secp256k1", &[x_low, x_high, y_low, y_high], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Call test_add_secp256k1. let calldata = create_calldata( @@ -1544,7 +1544,7 @@ async fn test_new_syscalls_flow(#[case] use_kzg_da: bool, #[case] n_blocks_in_mu "test_add_secp256k1", &[x_low, x_high, y_low, y_high], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Call test_mul_secp256k1. let calldata = create_calldata( @@ -1552,12 +1552,12 @@ async fn test_new_syscalls_flow(#[case] use_kzg_da: bool, #[case] n_blocks_in_mu "test_mul_secp256k1", &[Felt::from(1991), Felt::from(1996)], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Call test_signature_verification_secp256k1. let calldata = create_calldata(main_contract_address, "test_signature_verification_secp256k1", &[]); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Change points for secpR. let x_low = Felt::from_hex_unchecked("0x2D483FE223B12B91047D83258A958B0F"); @@ -1568,7 +1568,7 @@ async fn test_new_syscalls_flow(#[case] use_kzg_da: bool, #[case] n_blocks_in_mu // Call test_new_point_secp256r1. let calldata = create_calldata(main_contract_address, "test_new_point_secp256r1", &[x_low, x_high]); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Call test_add_secp256r1. let calldata = create_calldata( @@ -1576,7 +1576,7 @@ async fn test_new_syscalls_flow(#[case] use_kzg_da: bool, #[case] n_blocks_in_mu "test_add_secp256r1", &[x_low, x_high, y_low, y_high], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Call test_getter_secp256r1. let calldata = create_calldata( @@ -1584,7 +1584,7 @@ async fn test_new_syscalls_flow(#[case] use_kzg_da: bool, #[case] n_blocks_in_mu "test_getter_secp256r1", &[x_low, x_high, y_low, y_high], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Call test_mul_secp256r1. let calldata = create_calldata( @@ -1592,24 +1592,24 @@ async fn test_new_syscalls_flow(#[case] use_kzg_da: bool, #[case] n_blocks_in_mu "test_mul_secp256r1", &[Felt::from(1991), Felt::from(1996)], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Call test_signature_verification_secp256r1. let calldata = create_calldata(main_contract_address, "test_signature_verification_secp256r1", &[]); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Call test_sha256. let calldata = create_calldata(main_contract_address, "test_sha256", &[]); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Call test_circuit. let calldata = create_calldata(main_contract_address, "test_circuit", &[]); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Call test_rc96_holes. let calldata = create_calldata(main_contract_address, "test_rc96_holes", &[]); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Call test_get_block_hash. // Get the block hash at current block number minus STORED_BLOCK_HASH_BUFFER. @@ -1621,7 +1621,7 @@ async fn test_new_syscalls_flow(#[case] use_kzg_da: bool, #[case] n_blocks_in_mu "test_get_block_hash", &[Felt::from(queried_block_number.0), old_block_hash.0], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Test library call. // TODO(Yoni): test execution info on library call. @@ -1638,7 +1638,7 @@ async fn test_new_syscalls_flow(#[case] use_kzg_da: bool, #[case] n_blocks_in_mu test_library_call_value, ], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); update_expected_storage( &mut expected_storage_updates, // Library call writes to the caller storage. @@ -1650,7 +1650,7 @@ async fn test_new_syscalls_flow(#[case] use_kzg_da: bool, #[case] n_blocks_in_mu // Test segment_arena. for _ in 0..2 { let calldata = create_calldata(main_contract_address, "test_segment_arena", &[]); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); } // Run the test. @@ -1659,8 +1659,8 @@ async fn test_new_syscalls_flow(#[case] use_kzg_da: bool, #[case] n_blocks_in_mu current_block_number, n_blocks_in_multi_block, ); - test_manager.divide_transactions_into_n_blocks(n_blocks_in_multi_block); - let test_output = test_manager.execute_flow_test().await; + test_builder.divide_transactions_into_n_blocks(n_blocks_in_multi_block); + let test_output = test_builder.build_and_run().await; // Perform general validations and storage update validations. let perform_global_validations = true; @@ -1690,20 +1690,20 @@ async fn test_new_syscalls_flow(#[case] use_kzg_da: bool, #[case] n_blocks_in_mu #[rstest] #[tokio::test] async fn test_syscalls_with_alternating_inner_calls() { - let (mut test_manager, [test_contract_address]) = TestManager::create_standard_with_config( + let (mut test_builder, [test_contract_address]) = TestBuilder::create_standard_with_config( [( FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Casm)), calldata![Felt::ZERO, Felt::ZERO], )], - TestManagerConfig { use_kzg_da: true, ..Default::default() }, + TestBuilderConfig { use_kzg_da: true, ..Default::default() }, ) .await; let calldata = create_calldata(test_contract_address, "test_sha256_with_alternating_inner_calls", &[]); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); - let test_output = test_manager.execute_flow_test().await; + let test_output = test_builder.build_and_run().await; test_output.perform_default_validations(); } @@ -1714,8 +1714,8 @@ async fn test_deprecated_tx_info() { let class_hash = get_class_hash_of_feature_contract(tx_info_writer); // Initialize the test manager with the tx info writer already declared. // We can ignore the address of the deployed instance. - let (mut test_manager, _) = TestManager::create_standard([(tx_info_writer, calldata![])]).await; - let chain_id = &test_manager.chain_id(); + let (mut test_builder, _) = TestBuilder::create_standard([(tx_info_writer, calldata![])]).await; + let chain_id = &test_builder.chain_id(); // Prepare to deploy: precompute the address. let salt = Felt::ZERO; @@ -1728,7 +1728,7 @@ async fn test_deprecated_tx_info() { .unwrap(); // Fund the address. - test_manager.add_fund_address_tx_with_default_amount(tx_info_account_address); + test_builder.add_fund_address_tx_with_default_amount(tx_info_account_address); // Deploy the account. let deploy_tx_args = deploy_account_tx_args! { @@ -1737,21 +1737,21 @@ async fn test_deprecated_tx_info() { contract_address_salt: ContractAddressSalt(salt), }; let deploy_account_tx = DeployAccountTransaction::create( - deploy_account_tx(deploy_tx_args, test_manager.next_nonce(tx_info_account_address)), + deploy_account_tx(deploy_tx_args, test_builder.next_nonce(tx_info_account_address)), chain_id, ) .unwrap(); - test_manager.add_deploy_account_tx(deploy_account_tx.clone()); + test_builder.add_deploy_account_tx(deploy_account_tx.clone()); // Invoke (call write). let invoke_args = invoke_tx_args! { sender_address: tx_info_account_address, - nonce: test_manager.next_nonce(tx_info_account_address), + nonce: test_builder.next_nonce(tx_info_account_address), calldata: calldata![Felt::ZERO], resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS, }; let invoke_tx = InvokeTransaction::create(invoke_tx(invoke_args), chain_id).unwrap(); - test_manager.add_invoke_tx(invoke_tx.clone(), None); + test_builder.add_invoke_tx(invoke_tx.clone(), None); // Declare. let empty_contract = FeatureContract::Empty(CairoVersion::Cairo1(RunnableCairo1::Casm)); @@ -1764,12 +1764,12 @@ async fn test_deprecated_tx_info() { class_hash: empty_contract_class_hash, compiled_class_hash: empty_contract_compiled_class_hash, resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS, - nonce: test_manager.next_nonce(tx_info_account_address), + nonce: test_builder.next_nonce(tx_info_account_address), }; let account_declare_tx = declare_tx(declare_tx_args); let class_info = get_class_info_of_feature_contract(empty_contract); let declare_tx = DeclareTransaction::create(account_declare_tx, class_info, chain_id).unwrap(); - test_manager.add_cairo1_declare_tx(declare_tx.clone(), &empty_contract_sierra); + test_builder.add_cairo1_declare_tx(declare_tx.clone(), &empty_contract_sierra); // L1 handler (call `l1_write`). let from_address = Felt::from(85); @@ -1787,10 +1787,10 @@ async fn test_deprecated_tx_info() { Fee(1_000_000), ) .unwrap(); - test_manager.add_l1_handler_tx(l1_handler_tx.clone(), None); + test_builder.add_l1_handler_tx(l1_handler_tx.clone(), None); // Run the test. - let test_output = test_manager.execute_flow_test().await; + let test_output = test_builder.build_and_run().await; // Perform general validations and storage update validations. let mut contract_storage_updates = HashMap::new(); @@ -1845,7 +1845,7 @@ async fn test_deprecated_tx_info() { #[rstest] #[tokio::test] async fn test_deprecated_send_to_l1() { - let (mut test_manager, [test_contract_address]) = TestManager::create_standard([( + let (mut test_builder, [test_contract_address]) = TestBuilder::create_standard([( FeatureContract::TestContract(CairoVersion::Cairo0), calldata![Felt::ZERO, Felt::ZERO], )]) @@ -1853,15 +1853,15 @@ async fn test_deprecated_send_to_l1() { let to_address = Felt::from(85); let calldata = create_calldata(test_contract_address, "send_message", &[to_address]); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); - test_manager.messages_to_l1.push(MessageToL1 { + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.messages_to_l1.push(MessageToL1 { from_address: test_contract_address, to_address: to_address.try_into().unwrap(), // These numbers are hard-coded in the `send_message` entrypoint. payload: L2ToL1Payload(vec![Felt::from(12), Felt::from(34)]), }); - let test_output = test_manager.execute_flow_test().await; + let test_output = test_builder.build_and_run().await; test_output.perform_default_validations(); } @@ -1870,9 +1870,9 @@ async fn test_deprecated_send_to_l1() { async fn test_replace_class() { let empty_contract = FeatureContract::Empty(CairoVersion::Cairo1(RunnableCairo1::Casm)); let ( - mut test_manager, + mut test_builder, [test_contract_address_cairo0, test_contract_address_cairo1, _empty_contract_address], - ) = TestManager::create_standard([ + ) = TestBuilder::create_standard([ (FeatureContract::TestContract(CairoVersion::Cairo0), calldata![Felt::ZERO, Felt::ZERO]), ( FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Casm)), @@ -1885,10 +1885,10 @@ async fn test_replace_class() { for address in [test_contract_address_cairo1, test_contract_address_cairo0] { let calldata = create_calldata(address, "test_replace_class", &[empty_class_hash.0]); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); } - let test_output = test_manager.execute_flow_test().await; + let test_output = test_builder.build_and_run().await; test_output.perform_default_validations(); } @@ -1901,7 +1901,7 @@ async fn test_deploy_syscall() { let empty_class_hash = get_class_hash_of_feature_contract(empty_contract); // Initialize the test manager with the test contract and empty contract already declared. // We can ignore the addresses of the deployed instances. - let (mut test_manager, _) = TestManager::create_standard([ + let (mut test_builder, _) = TestBuilder::create_standard([ (test_contract, calldata![Felt::ZERO, Felt::ZERO]), (empty_contract, calldata![]), ]) @@ -1914,11 +1914,11 @@ async fn test_deploy_syscall() { let (deploy_tx, deployed_test_address) = get_deploy_contract_tx_and_address_with_salt( class_hash, Calldata(Arc::new(ctor_calldata.clone())), - test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS), + test_builder.next_nonce(*FUNDED_ACCOUNT_ADDRESS), *NON_TRIVIAL_RESOURCE_BOUNDS, salt, ); - test_manager.add_invoke_tx(deploy_tx, None); + test_builder.add_invoke_tx(deploy_tx, None); let expected_storage_updates = HashMap::from([( deployed_test_address, HashMap::from([( @@ -1933,10 +1933,10 @@ async fn test_deploy_syscall() { "deploy_contract", &[empty_class_hash.0, salt.0, Felt::ZERO], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Run the test and verify storage changes. - let test_output = test_manager.execute_flow_test().await; + let test_output = test_builder.build_and_run().await; let perform_global_validations = true; test_output.perform_validations( perform_global_validations, @@ -1972,8 +1972,8 @@ async fn test_deploy_syscall() { async fn test_inner_deploy_failure() { let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Casm)); let empty_contract = FeatureContract::Empty(CairoVersion::Cairo1(RunnableCairo1::Casm)); - let (mut test_manager, [test_contract_address, _empty_contract_address]) = - TestManager::create_standard([ + let (mut test_builder, [test_contract_address, _empty_contract_address]) = + TestBuilder::create_standard([ (test_contract, calldata![Felt::ZERO, Felt::ZERO]), (empty_contract, calldata![]), ]) @@ -1991,10 +1991,10 @@ async fn test_inner_deploy_failure() { "test_get_class_hash_after_failed_deploy", &[empty_class_hash.0, **test_contract_address, salt.0, **expected_deploy_address], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Run the test and verify storage changes. - let test_output = test_manager.execute_flow_test().await; + let test_output = test_builder.build_and_run().await; test_output.perform_default_validations(); } @@ -2006,11 +2006,11 @@ async fn test_block_info(#[values(true, false)] is_cairo0: bool) { let test_contract = FeatureContract::BlockInfoTestContract(cairo_version); let class_hash = get_class_hash_of_feature_contract(test_contract); let is_validate = Felt::ONE; - let (mut test_manager, _) = TestManager::create_standard([]).await; - let chain_id = &test_manager.chain_id(); + let (mut test_builder, _) = TestBuilder::create_standard([]).await; + let chain_id = &test_builder.chain_id(); // Prepare block info data. - let next_block_number = test_manager.first_block_number(); + let next_block_number = test_builder.first_block_number(); let rounded_block_number = (next_block_number.0 / 100) * 100; let next_block_timestamp = BlockInfo::create_for_testing().block_timestamp.0; let rounded_next_block_timestamp = (next_block_timestamp / 3600) * 3600; @@ -2037,7 +2037,7 @@ async fn test_block_info(#[values(true, false)] is_cairo0: bool) { }; let account_declare_tx = declare_tx(declare_args); let tx = DeclareTransaction::create(account_declare_tx, class_info, chain_id).unwrap(); - test_manager.add_cairo0_declare_tx(tx, class_hash); + test_builder.add_cairo0_declare_tx(tx, class_hash); } else { let test_contract_sierra = test_contract.get_sierra(); let test_contract_compiled_class_hash = @@ -2047,12 +2047,12 @@ async fn test_block_info(#[values(true, false)] is_cairo0: bool) { class_hash, compiled_class_hash: test_contract_compiled_class_hash, resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS, - nonce: test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS), + nonce: test_builder.next_nonce(*FUNDED_ACCOUNT_ADDRESS), }; let account_declare_tx = declare_tx(declare_tx_args); let declare_tx = DeclareTransaction::create(account_declare_tx, class_info, chain_id).unwrap(); - test_manager.add_cairo1_declare_tx(declare_tx, &test_contract_sierra); + test_builder.add_cairo1_declare_tx(declare_tx, &test_contract_sierra); } // Prepare to deploy: precompute the address. @@ -2066,7 +2066,7 @@ async fn test_block_info(#[values(true, false)] is_cairo0: bool) { .unwrap(); // Fund the address. - test_manager.add_fund_address_tx_with_default_amount(block_info_account_address); + test_builder.add_fund_address_tx_with_default_amount(block_info_account_address); // Deploy the contract using a DeployAccount transaction. let deploy_account_tx_args = deploy_account_tx_args! { @@ -2079,12 +2079,12 @@ async fn test_block_info(#[values(true, false)] is_cairo0: bool) { let deploy_account_tx = DeployAccountTransaction::create( deploy_account_tx( deploy_account_tx_args, - test_manager.next_nonce(block_info_account_address), + test_builder.next_nonce(block_info_account_address), ), chain_id, ) .unwrap(); - test_manager.add_deploy_account_tx(deploy_account_tx); + test_builder.add_deploy_account_tx(deploy_account_tx); // Test validate_declare. let empty_contract = FeatureContract::Empty(CairoVersion::Cairo1(RunnableCairo1::Casm)); @@ -2095,22 +2095,22 @@ async fn test_block_info(#[values(true, false)] is_cairo0: bool) { class_hash: empty_class_hash, compiled_class_hash: empty_compiled_class_hash, resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS, - nonce: test_manager.next_nonce(block_info_account_address), + nonce: test_builder.next_nonce(block_info_account_address), }; let account_declare_tx = declare_tx(declare_tx_args); let class_info = get_class_info_of_feature_contract(empty_contract); let declare_tx = DeclareTransaction::create(account_declare_tx, class_info, chain_id).unwrap(); - test_manager.add_cairo1_declare_tx(declare_tx, &empty_contract.get_sierra()); + test_builder.add_cairo1_declare_tx(declare_tx, &empty_contract.get_sierra()); // Test `validate` and `execute`. let invoke_args = invoke_tx_args! { sender_address: block_info_account_address, - nonce: test_manager.next_nonce(block_info_account_address), + nonce: test_builder.next_nonce(block_info_account_address), // Dummy contract address and selector, calldata length of zero. calldata: calldata![Felt::ZERO, Felt::ZERO, Felt::ZERO], resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS, }; - test_manager.add_invoke_tx_from_args(invoke_args, None); + test_builder.add_invoke_tx_from_args(invoke_args, None); // Test `constructor` in execute mode. let ctor_calldata = [Felt::ZERO]; // Not validate mode (execute mode). @@ -2120,10 +2120,10 @@ async fn test_block_info(#[values(true, false)] is_cairo0: bool) { "deploy_contract", &[class_hash.0, salt, ctor_calldata.len().into(), ctor_calldata[0]], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Run the test. - let test_output = test_manager.execute_flow_test().await; + let test_output = test_builder.build_and_run().await; test_output.perform_default_validations(); let cairo_type = if is_cairo0 { "cairo0" } else { "cairo1" }; test_output.expect_hint_coverage(&format!("test_block_info_{}", cairo_type)); @@ -2133,15 +2133,15 @@ async fn test_block_info(#[values(true, false)] is_cairo0: bool) { #[tokio::test] async fn test_initial_sierra_gas() { let account_contract = FeatureContract::Experimental; - let (mut test_manager, [account_address]) = TestManager::create_standard_with_config( + let (mut test_builder, [account_address]) = TestBuilder::create_standard_with_config( [(account_contract, calldata![])], - TestManagerConfig { use_kzg_da: true, ..Default::default() }, + TestBuilderConfig { use_kzg_da: true, ..Default::default() }, ) .await; - let chain_id = &test_manager.chain_id(); + let chain_id = &test_builder.chain_id(); // Fund the account. - test_manager.add_fund_address_tx_with_default_amount(account_address); + test_builder.add_fund_address_tx_with_default_amount(account_address); // Test invoke gas limits. let os_constants = &VersionedConstants::latest_constants().os_constants; @@ -2174,7 +2174,7 @@ async fn test_initial_sierra_gas() { // Invoke verify_gas_limits. let invoke_args = invoke_tx_args! { sender_address: account_address, - nonce: test_manager.next_nonce(account_address), + nonce: test_builder.next_nonce(account_address), calldata: create_calldata( account_address, "verify_gas_limits", @@ -2187,7 +2187,7 @@ async fn test_initial_sierra_gas() { ), resource_bounds: resource_bounds, }; - test_manager.add_invoke_tx_from_args(invoke_args, None); + test_builder.add_invoke_tx_from_args(invoke_args, None); } // L1 handler bounds test. @@ -2211,10 +2211,10 @@ async fn test_initial_sierra_gas() { Fee(1_000_000), ) .unwrap(); - test_manager.add_l1_handler_tx(l1_handler_tx.clone(), None); + test_builder.add_l1_handler_tx(l1_handler_tx.clone(), None); // Run test. - let test_output = test_manager.execute_flow_test().await; + let test_output = test_builder.build_and_run().await; test_output.perform_default_validations(); test_output.expect_hint_coverage("test_initial_sierra_gas"); @@ -2227,8 +2227,8 @@ async fn test_reverted_call() { let test_class_hash = get_class_hash_of_feature_contract(test_contract); let test_contract2 = FeatureContract::TestContract2; let empty_contract = FeatureContract::Empty(CairoVersion::Cairo0); - let (mut test_manager, [main_contract_address, test_contract2_address, empty_contract_address]) = - TestManager::create_standard_with_config( + let (mut test_builder, [main_contract_address, test_contract2_address, empty_contract_address]) = + TestBuilder::create_standard_with_config( [ // The `my_storage_var` cell is initialized as the sum of the ctor args in the // constructor. This cell is also used in revert tests, so it must be @@ -2237,7 +2237,7 @@ async fn test_reverted_call() { (test_contract2, calldata![]), (empty_contract, calldata![]), ], - TestManagerConfig { use_kzg_da: true, ..Default::default() }, + TestBuilderConfig { use_kzg_da: true, ..Default::default() }, ) .await; @@ -2261,7 +2261,7 @@ async fn test_reverted_call() { is_meta_tx.into(), ], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); } // Test call to cairo0 contracts with 0 and more then 0 entry points. @@ -2281,7 +2281,7 @@ async fn test_reverted_call() { false.into(), ], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Test 3: // - Contract A calls Contract B. @@ -2294,7 +2294,7 @@ async fn test_reverted_call() { "test_revert_with_inner_call_and_reverted_storage", &[**main_contract_address, test_class_hash.0], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); } // Test 4: @@ -2330,11 +2330,11 @@ async fn test_reverted_call() { // Call contract A. let calldata = create_calldata(main_contract_address, "test_call_contract_revert", &contract_a_calldata); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Run the test and assert only the fee token contract and the OS contracts have storage // updates. - let test_output = test_manager.execute_flow_test().await; + let test_output = test_builder.build_and_run().await; test_output.perform_default_validations(); @@ -2363,13 +2363,13 @@ async fn test_reverted_call() { #[tokio::test] async fn test_resources_type() { let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Casm)); - let (mut test_manager, [sierra_gas_contract_address]) = - TestManager::create_standard_with_config( + let (mut test_builder, [sierra_gas_contract_address]) = + TestBuilder::create_standard_with_config( [(test_contract, calldata![Felt::ZERO, Felt::ZERO])], - TestManagerConfig { use_kzg_da: true, ..Default::default() }, + TestBuilderConfig { use_kzg_da: true, ..Default::default() }, ) .await; - let chain_id = &test_manager.chain_id(); + let chain_id = &test_builder.chain_id(); // Define an updated Cairo 1.0 contract by overriding the encoded sierra version. let mut cairo_steps_contract_sierra = test_contract.get_sierra(); @@ -2394,7 +2394,7 @@ async fn test_resources_type() { class_hash: cairo_steps_class_hash, compiled_class_hash, resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS, - nonce: test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS), + nonce: test_builder.next_nonce(*FUNDED_ACCOUNT_ADDRESS), }; let account_declare_tx = declare_tx(declare_tx_args); let class_info = match test_contract.get_class() { @@ -2407,17 +2407,17 @@ async fn test_resources_type() { }, }; let tx = DeclareTransaction::create(account_declare_tx, class_info, chain_id).unwrap(); - test_manager.add_cairo1_declare_tx(tx, &cairo_steps_contract_sierra); + test_builder.add_cairo1_declare_tx(tx, &cairo_steps_contract_sierra); // Deploy it. let (deploy_tx, cairo_steps_contract_address) = get_deploy_contract_tx_and_address_with_salt( cairo_steps_class_hash, calldata![Felt::ZERO, Felt::ZERO], - test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS), + test_builder.next_nonce(*FUNDED_ACCOUNT_ADDRESS), *NON_TRIVIAL_RESOURCE_BOUNDS, ContractAddressSalt(Felt::ZERO), ); - test_manager.add_invoke_tx(deploy_tx, None); + test_builder.add_invoke_tx(deploy_tx, None); // Test recursive calling. let (key, value) = (Felt::from(123), Felt::from(45)); @@ -2443,10 +2443,10 @@ async fn test_resources_type() { "test_call_two_contracts", &[calldata_0, calldata_1].concat(), ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Run test and check storage updates. - let test_output = test_manager.execute_flow_test().await; + let test_output = test_builder.build_and_run().await; let expected_storage_updates = HashMap::from([(key, value), (key + Felt::ONE, value + Felt::ONE)]); @@ -2467,13 +2467,13 @@ async fn test_data_gas_accounts() { assert!( VersionedConstants::latest_constants().os_constants.data_gas_accounts.contains(&class_hash) ); - let (mut test_manager, _) = TestManager::create_standard([]).await; - let chain_id = &test_manager.chain_id(); + let (mut test_builder, _) = TestBuilder::create_standard([]).await; + let chain_id = &test_builder.chain_id(); // Declare the data gas account. let declare_args = declare_tx_args! { sender_address: *FUNDED_ACCOUNT_ADDRESS, - nonce: test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS), + nonce: test_builder.next_nonce(*FUNDED_ACCOUNT_ADDRESS), class_hash, compiled_class_hash, resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS, @@ -2487,33 +2487,33 @@ async fn test_data_gas_accounts() { sierra_version, }; let tx = DeclareTransaction::create(account_declare_tx, class_info, chain_id).unwrap(); - test_manager.add_cairo1_declare_tx(tx, test_contract_sierra); + test_builder.add_cairo1_declare_tx(tx, test_contract_sierra); // Deploy it (from funded account). let salt = ContractAddressSalt(Felt::ZERO); let (deploy_tx, data_gas_account_address) = get_deploy_contract_tx_and_address_with_salt( class_hash, calldata![], - test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS), + test_builder.next_nonce(*FUNDED_ACCOUNT_ADDRESS), *NON_TRIVIAL_RESOURCE_BOUNDS, salt, ); - test_manager.add_invoke_tx(deploy_tx, None); + test_builder.add_invoke_tx(deploy_tx, None); // Create and run an invoke tx. let invoke_args = invoke_tx_args! { sender_address: *FUNDED_ACCOUNT_ADDRESS, - nonce: test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS), + nonce: test_builder.next_nonce(*FUNDED_ACCOUNT_ADDRESS), calldata: create_calldata(data_gas_account_address, "test_resource_bounds", &[]), resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS, }; let tx = InvokeTransaction::create(invoke_tx(invoke_args), chain_id).unwrap(); assert_eq!(tx.version(), TransactionVersion::THREE); assert_matches!(tx.resource_bounds(), ValidResourceBounds::AllResources(_)); - test_manager.add_invoke_tx(tx, None); + test_builder.add_invoke_tx(tx, None); // Run test. - let test_output = test_manager.execute_flow_test().await; + let test_output = test_builder.build_and_run().await; test_output.perform_default_validations(); test_output.expect_hint_coverage("test_data_gas_accounts"); } @@ -2525,10 +2525,10 @@ async fn test_direct_execute_call() { let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Casm)); let dummy_account = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo1(RunnableCairo1::Casm)); - let (mut test_manager, [test_contract_address, dummy_account_address]) = - TestManager::create_standard_with_config( + let (mut test_builder, [test_contract_address, dummy_account_address]) = + TestBuilder::create_standard_with_config( [(test_contract, calldata![Felt::ZERO, Felt::ZERO]), (dummy_account, calldata![])], - TestManagerConfig { use_kzg_da: true, ..Default::default() }, + TestBuilderConfig { use_kzg_da: true, ..Default::default() }, ) .await; @@ -2545,10 +2545,10 @@ async fn test_direct_execute_call() { Felt::ONE, // Arg 2. ], ); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); // Run test. - let test_output = test_manager.execute_flow_test().await; + let test_output = test_builder.build_and_run().await; test_output.perform_default_validations(); test_output.assert_storage_diff_eq(test_contract_address, HashMap::default()); test_output.assert_storage_diff_eq(dummy_account_address, HashMap::default()); @@ -2560,13 +2560,13 @@ async fn test_direct_execute_call() { async fn test_meta_tx() { let meta_tx_contract = FeatureContract::MetaTx(RunnableCairo1::Casm); let tx_info_contract = FeatureContract::TxInfoWriter; - let (mut test_manager, [meta_tx_contract_address, tx_info_contract_address]) = - TestManager::create_standard_with_config( + let (mut test_builder, [meta_tx_contract_address, tx_info_contract_address]) = + TestBuilder::create_standard_with_config( [(meta_tx_contract, calldata![]), (tx_info_contract, calldata![])], - TestManagerConfig { use_kzg_da: true, ..Default::default() }, + TestBuilderConfig { use_kzg_da: true, ..Default::default() }, ) .await; - let chain_id = &test_manager.chain_id(); + let chain_id = &test_builder.chain_id(); let argument = Felt::from(1234); let signature = vec![Felt::from(5432), Felt::from(100)]; @@ -2574,7 +2574,7 @@ async fn test_meta_tx() { // Create and run an invoke tx. let invoke_args = invoke_tx_args! { sender_address: *FUNDED_ACCOUNT_ADDRESS, - nonce: test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS), + nonce: test_builder.next_nonce(*FUNDED_ACCOUNT_ADDRESS), calldata: create_calldata( meta_tx_contract_address, "execute_meta_tx_v0", @@ -2596,7 +2596,7 @@ async fn test_meta_tx() { let tx0_hash = tx0.tx_hash(); let tx0_nonce = tx0.nonce(); assert!(tx0_nonce != Nonce(Felt::ZERO)); - test_manager.add_invoke_tx(tx0, None); + test_builder.add_invoke_tx(tx0, None); // Compute the meta-tx hash. let meta_tx_hash0 = InvokeTransaction::create( @@ -2615,7 +2615,7 @@ async fn test_meta_tx() { let argument1 = Felt::ONE; let invoke_args = invoke_tx_args! { sender_address: *FUNDED_ACCOUNT_ADDRESS, - nonce: test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS), + nonce: test_builder.next_nonce(*FUNDED_ACCOUNT_ADDRESS), calldata: create_calldata( meta_tx_contract_address, "execute_meta_tx_v0", @@ -2637,7 +2637,7 @@ async fn test_meta_tx() { let tx1_hash = tx1.tx_hash(); let tx1_nonce = tx1.nonce(); assert!(tx1_nonce != Nonce(Felt::ZERO)); - test_manager.add_invoke_tx(tx1, None); + test_builder.add_invoke_tx(tx1, None); // Compute the meta-tx hash. let meta_tx_hash1 = InvokeTransaction::create( @@ -2655,7 +2655,7 @@ async fn test_meta_tx() { // Check that calling an entry point other than '__execute__` fails. let invoke_args = invoke_tx_args! { sender_address: *FUNDED_ACCOUNT_ADDRESS, - nonce: test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS), + nonce: test_builder.next_nonce(*FUNDED_ACCOUNT_ADDRESS), calldata: create_calldata( meta_tx_contract_address, "execute_meta_tx_v0", @@ -2676,7 +2676,7 @@ async fn test_meta_tx() { assert!(tx2.nonce() != Nonce(Felt::ZERO)); let tx2_hash = tx2.tx_hash(); let tx2_nonce = tx2.nonce(); - test_manager.add_invoke_tx(tx2, None); + test_builder.add_invoke_tx(tx2, None); // Construct the expected storage diff for each of the two contracts. // All zero-valued keys should be filtered out (as they don't appear in the state diff). @@ -2749,7 +2749,7 @@ async fn test_meta_tx() { ); // Run the test and verify the storage changes. - let test_output = test_manager.execute_flow_test().await; + let test_output = test_builder.build_and_run().await; test_output.perform_default_validations(); test_output.assert_storage_diff_eq(meta_tx_contract_address, expected_meta_tx_contract_diffs); test_output.assert_storage_diff_eq(tx_info_contract_address, expected_tx_info_writer_diffs); @@ -2763,12 +2763,12 @@ async fn test_meta_tx() { /// 2. The deployed contract's storage is properly initialized. /// 3. The class hash to compiled class hash mapping appears in the state diff. async fn test_declare_and_deploy_in_separate_blocks() { - let (mut test_manager, _) = TestManager::create_standard_with_config( + let (mut test_builder, _) = TestBuilder::create_standard_with_config( [], - TestManagerConfig { use_kzg_da: true, ..Default::default() }, + TestBuilderConfig { use_kzg_da: true, ..Default::default() }, ) .await; - let chain_id = &test_manager.chain_id(); + let chain_id = &test_builder.chain_id(); // Declare a test contract. let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Casm)); @@ -2780,16 +2780,16 @@ async fn test_declare_and_deploy_in_separate_blocks() { class_hash, compiled_class_hash, resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS, - nonce: test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS), + nonce: test_builder.next_nonce(*FUNDED_ACCOUNT_ADDRESS), }; let account_declare_tx = declare_tx(declare_tx_args); let class_info = get_class_info_of_feature_contract(test_contract); let tx = DeclareTransaction::create(account_declare_tx, class_info, chain_id).unwrap(); - test_manager.add_cairo1_declare_tx(tx, &test_contract_sierra); + test_builder.add_cairo1_declare_tx(tx, &test_contract_sierra); // Move on to the next block, with an empty block in between. - test_manager.move_to_next_block(); - test_manager.move_to_next_block(); + test_builder.move_to_next_block(); + test_builder.move_to_next_block(); // Deploy the test contract using the deploy contract syscall. let (constructor_arg1, constructor_arg2) = (Felt::from(7), Felt::from(90)); @@ -2797,14 +2797,14 @@ async fn test_declare_and_deploy_in_separate_blocks() { let (deploy_tx, address) = get_deploy_contract_tx_and_address_with_salt( class_hash, calldata![constructor_arg1, constructor_arg2], - test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS), + test_builder.next_nonce(*FUNDED_ACCOUNT_ADDRESS), *NON_TRIVIAL_RESOURCE_BOUNDS, salt, ); - test_manager.add_invoke_tx(deploy_tx, None); + test_builder.add_invoke_tx(deploy_tx, None); // Run the test and verify the storage changes. - let test_output = test_manager.execute_flow_test().await; + let test_output = test_builder.build_and_run().await; test_output.perform_default_validations(); // The test contract constructor writes the sum of the two input arguments to storage. test_output.assert_storage_diff_eq( @@ -2829,8 +2829,8 @@ async fn test_declare_and_deploy_in_separate_blocks() { #[rstest] #[tokio::test] async fn test_single_empty_block() { - let (test_manager, _) = TestManager::create_standard([]).await; - let test_output = test_manager.execute_flow_test().await; + let (test_builder, _) = TestBuilder::create_standard([]).await; + let test_output = test_builder.build_and_run().await; test_output.perform_default_validations(); } @@ -2840,18 +2840,18 @@ async fn test_single_empty_block() { #[rstest] #[tokio::test] async fn test_empty_multi_block() { - let (mut test_manager, _) = TestManager::create_standard([]).await; - let next_block_number = test_manager.first_block_number().0; + let (mut test_builder, _) = TestBuilder::create_standard([]).await; + let next_block_number = test_builder.first_block_number().0; assert!(next_block_number > STORED_BLOCK_HASH_BUFFER); // Create empty blocks. let n_blocks = STORED_BLOCK_HASH_BUFFER + 1; for _ in 0..n_blocks - 1 { - test_manager.move_to_next_block(); + test_builder.move_to_next_block(); } // Run the test and verify the storage changes. - let test_output = test_manager.execute_flow_test().await; + let test_output = test_builder.build_and_run().await; test_output.perform_default_validations(); test_output.assert_storage_diff_eq( Const::BlockHashContractAddress.fetch_from_os_program().unwrap().try_into().unwrap(), @@ -2873,29 +2873,29 @@ async fn test_empty_multi_block() { #[tokio::test] async fn test_deploy_no_ctor_contract() { let empty_contract_cairo0 = FeatureContract::Empty(CairoVersion::Cairo0); - let (mut test_manager, _) = - TestManager::create_standard([(empty_contract_cairo0, calldata![])]).await; + let (mut test_builder, _) = + TestBuilder::create_standard([(empty_contract_cairo0, calldata![])]).await; let class_hash = get_class_hash_of_feature_contract(empty_contract_cairo0); // Deploy the empty contract using the deploy syscall. let (deploy_tx, _address) = get_deploy_contract_tx_and_address_with_salt( class_hash, calldata![], - test_manager.next_nonce(*FUNDED_ACCOUNT_ADDRESS), + test_builder.next_nonce(*FUNDED_ACCOUNT_ADDRESS), *NON_TRIVIAL_RESOURCE_BOUNDS, ContractAddressSalt(Felt::ZERO), ); - test_manager.add_invoke_tx(deploy_tx, None); + test_builder.add_invoke_tx(deploy_tx, None); // Run the test. - let test_output = test_manager.execute_flow_test().await; + let test_output = test_builder.build_and_run().await; test_output.perform_default_validations(); } #[rstest] #[tokio::test] async fn test_load_bottom() { - let (mut test_manager, [test_contract_address]) = TestManager::create_standard([( + let (mut test_builder, [test_contract_address]) = TestBuilder::create_standard([( FeatureContract::TestContract(CairoVersion::Cairo0), calldata![Felt::ZERO, Felt::ZERO], )]) @@ -2908,12 +2908,12 @@ async fn test_load_bottom() { { let (key, value) = (Felt::from(key), Felt::from(value)); let calldata = create_calldata(test_contract_address, "set_value", &[key, value]); - test_manager.add_funded_account_invoke(invoke_tx_args! { calldata }); + test_builder.add_funded_account_invoke(invoke_tx_args! { calldata }); } - test_manager.divide_transactions_into_n_blocks(test_manager.total_txs()); + test_builder.divide_transactions_into_n_blocks(test_builder.total_txs()); // Run the test. - let test_output = test_manager.execute_flow_test().await; + let test_output = test_builder.build_and_run().await; test_output.perform_default_validations(); test_output.expect_hint_coverage("test_load_bottom"); }