diff --git a/crates/apollo_integration_tests/tests/bootstrap_declare.rs b/crates/apollo_integration_tests/tests/bootstrap_declare.rs index a65ce104c7f..79c4288dd2e 100644 --- a/crates/apollo_integration_tests/tests/bootstrap_declare.rs +++ b/crates/apollo_integration_tests/tests/bootstrap_declare.rs @@ -6,12 +6,12 @@ use crate::common::{end_to_end_flow, test_single_tx, EndToEndFlowArgs, TestScena mod common; -fn create_bootstrap_declare_scenario() -> Vec { - vec![TestScenario { +fn create_bootstrap_declare_scenario() -> TestScenario { + TestScenario { create_rpc_txs_fn: |_| vec![generate_bootstrap_declare()], create_l1_to_l2_messages_args_fn: |_| vec![], test_tx_hashes_fn: test_single_tx, - }] + } } /// Bootstrap declare txs are unique: they are sent from a special address and do not increment its diff --git a/crates/apollo_integration_tests/tests/common/mod.rs b/crates/apollo_integration_tests/tests/common/mod.rs index 215e31e85e4..d643e68a94a 100644 --- a/crates/apollo_integration_tests/tests/common/mod.rs +++ b/crates/apollo_integration_tests/tests/common/mod.rs @@ -29,7 +29,7 @@ use tracing::info; pub struct EndToEndFlowArgs { pub test_identifier: TestIdentifier, - pub test_blocks_scenarios: Vec, + pub test_scenario: TestScenario, pub block_max_capacity_gas: GasAmount, // Used to max both sierra and proving gas. pub expecting_full_blocks: bool, pub expecting_reverted_transactions: bool, @@ -39,12 +39,12 @@ pub struct EndToEndFlowArgs { impl EndToEndFlowArgs { pub fn new( test_identifier: TestIdentifier, - test_blocks_scenarios: Vec, + test_scenario: TestScenario, block_max_capacity_gas: GasAmount, ) -> Self { Self { test_identifier, - test_blocks_scenarios, + test_scenario, block_max_capacity_gas, expecting_full_blocks: false, expecting_reverted_transactions: false, @@ -71,7 +71,7 @@ impl EndToEndFlowArgs { pub async fn end_to_end_flow(args: EndToEndFlowArgs) { let EndToEndFlowArgs { test_identifier, - test_blocks_scenarios, + test_scenario, block_max_capacity_gas, expecting_full_blocks, expecting_reverted_transactions, @@ -114,58 +114,54 @@ pub async fn end_to_end_flow(args: EndToEndFlowArgs) { let mut total_expected_batched_txs_count = 0; // Build multiple heights to ensure heights are committed. - for ( - i, - TestScenario { create_rpc_txs_fn, create_l1_to_l2_messages_args_fn, test_tx_hashes_fn }, - ) in test_blocks_scenarios.into_iter().enumerate() - { - info!("Starting scenario {i}."); - // Create and send transactions. - // TODO(Arni): move send messages to l2 into [run_test_scenario]. - let l1_handlers = create_l1_to_l2_messages_args_fn(&mut tx_generator); - mock_running_system.send_messages_to_l2(&l1_handlers).await; - - // Run the test scenario and get the expected batched tx hashes of the current scenario. - let expected_batched_tx_hashes = run_test_scenario( - &mut tx_generator, - create_rpc_txs_fn, - l1_handlers, - &mut send_rpc_tx_fn, - test_tx_hashes_fn, - &chain_id, - ) - .await; - - // Each sequencer increases the same BATCHED_TRANSACTIONS metric because they are running - // in the same process in this test. - total_expected_batched_txs_count += NUM_OF_SEQUENCERS * expected_batched_tx_hashes.len(); - let mut current_batched_txs_count = 0; - - tokio::time::timeout(TEST_SCENARIO_TIMEOUT, async { - loop { - info!( - "Waiting for more txs to be batched in a block. Expected batched txs: \ - {total_expected_batched_txs_count}, Currently batched txs: \ - {current_batched_txs_count}" - ); - - current_batched_txs_count = get_total_batched_txs_count(&global_recorder_handle); - if current_batched_txs_count == total_expected_batched_txs_count { - break; - } - - tokio::time::sleep(Duration::from_millis(2000)).await; + let TestScenario { create_rpc_txs_fn, create_l1_to_l2_messages_args_fn, test_tx_hashes_fn } = + test_scenario; + + // Create and send transactions. + // TODO(Arni): move send messages to l2 into [run_test_scenario]. + let l1_handlers = create_l1_to_l2_messages_args_fn(&mut tx_generator); + mock_running_system.send_messages_to_l2(&l1_handlers).await; + + // Run the test scenario and get the expected batched tx hashes of the current scenario. + let expected_batched_tx_hashes = run_test_scenario( + &mut tx_generator, + create_rpc_txs_fn, + l1_handlers, + &mut send_rpc_tx_fn, + test_tx_hashes_fn, + &chain_id, + ) + .await; + + // Each sequencer increases the same BATCHED_TRANSACTIONS metric because they are running + // in the same process in this test. + total_expected_batched_txs_count += NUM_OF_SEQUENCERS * expected_batched_tx_hashes.len(); + let mut current_batched_txs_count = 0; + + tokio::time::timeout(TEST_SCENARIO_TIMEOUT, async { + loop { + info!( + "Waiting for more txs to be batched in a block. Expected batched txs: \ + {total_expected_batched_txs_count}, Currently batched txs: \ + {current_batched_txs_count}" + ); + + current_batched_txs_count = get_total_batched_txs_count(&global_recorder_handle); + if current_batched_txs_count == total_expected_batched_txs_count { + break; } - }) - .await - .unwrap_or_else(|_| { - panic!( - "Scenario {i}: Expected transactions should be included in a block by now, \ - Expected amount of batched txs: {total_expected_batched_txs_count}, Currently \ - amount of batched txs: {current_batched_txs_count}" - ) - }); - } + + tokio::time::sleep(Duration::from_millis(2000)).await; + } + }) + .await + .unwrap_or_else(|_| { + panic!( + "Expected transactions should be included in a block by now, Expected amount of \ + batched txs: {total_expected_batched_txs_count}, Currently amount of batched txs: \ + {current_batched_txs_count}" + ) + }); assert_full_blocks_flow(&global_recorder_handle, expecting_full_blocks); assert_on_number_of_reverted_transactions_flow( diff --git a/crates/apollo_integration_tests/tests/declare_tx_flow_test.rs b/crates/apollo_integration_tests/tests/declare_tx_flow_test.rs index f15fb286033..1eb7db7b1ac 100644 --- a/crates/apollo_integration_tests/tests/declare_tx_flow_test.rs +++ b/crates/apollo_integration_tests/tests/declare_tx_flow_test.rs @@ -20,12 +20,12 @@ async fn declare_tx_flow() { .await } -fn create_test_scenarios() -> Vec { - vec![TestScenario { +fn create_test_scenarios() -> TestScenario { + TestScenario { create_rpc_txs_fn: create_declare_tx, create_l1_to_l2_messages_args_fn: |_| vec![], test_tx_hashes_fn: test_single_tx, - }] + } } fn create_declare_tx(tx_generator: &mut MultiAccountTransactionGenerator) -> Vec { diff --git a/crates/apollo_integration_tests/tests/deploy_account_and_invoke_flow_test.rs b/crates/apollo_integration_tests/tests/deploy_account_and_invoke_flow_test.rs index 80c9b00012e..e20081bf939 100644 --- a/crates/apollo_integration_tests/tests/deploy_account_and_invoke_flow_test.rs +++ b/crates/apollo_integration_tests/tests/deploy_account_and_invoke_flow_test.rs @@ -23,12 +23,12 @@ async fn deploy_account_and_invoke_flow() { .await } -fn create_test_scenarios() -> Vec { - vec![TestScenario { +fn create_test_scenarios() -> TestScenario { + TestScenario { create_rpc_txs_fn: deploy_account_and_invoke, create_l1_to_l2_messages_args_fn: |_| vec![], test_tx_hashes_fn: |tx_hashes| validate_tx_count(tx_hashes, 2), - }] + } } /// Generates a deploy account transaction followed by an invoke transaction from the same deployed diff --git a/crates/apollo_integration_tests/tests/funding_txs_flow_test.rs b/crates/apollo_integration_tests/tests/funding_txs_flow_test.rs index 8d5c10e5ff3..e9e9394b66e 100644 --- a/crates/apollo_integration_tests/tests/funding_txs_flow_test.rs +++ b/crates/apollo_integration_tests/tests/funding_txs_flow_test.rs @@ -20,12 +20,12 @@ async fn funding_txs_flow() { .await } -fn create_test_scenarios() -> Vec { - vec![TestScenario { +fn create_test_scenarios() -> TestScenario { + TestScenario { create_rpc_txs_fn: create_funding_txs, create_l1_to_l2_messages_args_fn: |_| vec![], test_tx_hashes_fn: test_single_tx, - }] + } } fn create_funding_txs(tx_generator: &mut MultiAccountTransactionGenerator) -> Vec { diff --git a/crates/apollo_integration_tests/tests/l1_to_l2_message_flow_test.rs b/crates/apollo_integration_tests/tests/l1_to_l2_message_flow_test.rs index 5adb0fa83d4..ffb549e592a 100644 --- a/crates/apollo_integration_tests/tests/l1_to_l2_message_flow_test.rs +++ b/crates/apollo_integration_tests/tests/l1_to_l2_message_flow_test.rs @@ -20,12 +20,12 @@ async fn l1_to_l2_message_flow() { .await } -fn create_test_scenarios() -> Vec { - vec![TestScenario { +fn create_test_scenarios() -> TestScenario { + TestScenario { create_rpc_txs_fn: |_| vec![], create_l1_to_l2_messages_args_fn: |tx_generator| { create_l1_to_l2_messages_args(tx_generator, 1, false) }, test_tx_hashes_fn: test_single_tx, - }] + } } diff --git a/crates/apollo_integration_tests/tests/multiple_account_txs_flow_test.rs b/crates/apollo_integration_tests/tests/multiple_account_txs_flow_test.rs index 3426d8cec95..25a82856a65 100644 --- a/crates/apollo_integration_tests/tests/multiple_account_txs_flow_test.rs +++ b/crates/apollo_integration_tests/tests/multiple_account_txs_flow_test.rs @@ -21,12 +21,12 @@ async fn multiple_account_txs_flow() { .await } -fn create_test_scenarios() -> Vec { - vec![TestScenario { +fn create_test_scenarios() -> TestScenario { + TestScenario { create_rpc_txs_fn: create_multiple_account_txs, create_l1_to_l2_messages_args_fn: |_| vec![], test_tx_hashes_fn: test_multiple_account_txs, - }] + } } fn create_multiple_account_txs( diff --git a/crates/apollo_integration_tests/tests/reverted_l1_handler_tx_flow_test.rs b/crates/apollo_integration_tests/tests/reverted_l1_handler_tx_flow_test.rs index c0251d2a70d..06bc906bb65 100644 --- a/crates/apollo_integration_tests/tests/reverted_l1_handler_tx_flow_test.rs +++ b/crates/apollo_integration_tests/tests/reverted_l1_handler_tx_flow_test.rs @@ -22,12 +22,12 @@ async fn reverted_l1_handler_tx_flow() { .await } -fn create_test_scenarios() -> Vec { - vec![TestScenario { +fn create_test_scenarios() -> TestScenario { + TestScenario { create_rpc_txs_fn: |_| vec![], create_l1_to_l2_messages_args_fn: create_l1_to_l2_reverted_message_args, test_tx_hashes_fn: test_single_tx, - }] + } } fn create_l1_to_l2_reverted_message_args( diff --git a/crates/apollo_integration_tests/tests/test_custom_cairo0_txs.rs b/crates/apollo_integration_tests/tests/test_custom_cairo0_txs.rs index 08afd2a3144..f5f174d58e8 100644 --- a/crates/apollo_integration_tests/tests/test_custom_cairo0_txs.rs +++ b/crates/apollo_integration_tests/tests/test_custom_cairo0_txs.rs @@ -31,12 +31,12 @@ async fn custom_cairo0_txs() { .await } -fn create_custom_cairo0_txs_scenario() -> Vec { - vec![TestScenario { +fn create_custom_cairo0_txs_scenario() -> TestScenario { + TestScenario { create_rpc_txs_fn: create_custom_cairo0_test_txs, create_l1_to_l2_messages_args_fn: |_| vec![], test_tx_hashes_fn: |tx_hashes| validate_tx_count(tx_hashes, CUSTOM_CAIRO_0_INVOKE_TX_COUNT), - }] + } } /// Creates a set of transactions that test the Cairo 0 functionality. diff --git a/crates/apollo_integration_tests/tests/test_custom_cairo1_txs.rs b/crates/apollo_integration_tests/tests/test_custom_cairo1_txs.rs index eb624245745..13884affddd 100644 --- a/crates/apollo_integration_tests/tests/test_custom_cairo1_txs.rs +++ b/crates/apollo_integration_tests/tests/test_custom_cairo1_txs.rs @@ -37,12 +37,12 @@ async fn custom_cairo1_txs() { .await } -fn create_custom_cairo1_txs_scenario() -> Vec { - vec![TestScenario { +fn create_custom_cairo1_txs_scenario() -> TestScenario { + TestScenario { create_rpc_txs_fn: create_custom_cairo1_test_txs, create_l1_to_l2_messages_args_fn: |_| vec![], test_tx_hashes_fn: |tx_hashes| validate_tx_count(tx_hashes, CUSTOM_INVOKE_TX_COUNT), - }] + } } /// Creates a set of transactions that test the Cairo 1.0 syscall functionality. diff --git a/crates/apollo_integration_tests/tests/test_many.rs b/crates/apollo_integration_tests/tests/test_many.rs index 59a73814295..7bd7f5fea09 100644 --- a/crates/apollo_integration_tests/tests/test_many.rs +++ b/crates/apollo_integration_tests/tests/test_many.rs @@ -26,12 +26,12 @@ async fn many_txs_fill_at_least_one_block() { .await } -fn create_many_txs_scenario() -> Vec { - vec![TestScenario { +fn create_many_txs_scenario() -> TestScenario { + TestScenario { create_rpc_txs_fn: create_many_invoke_txs, create_l1_to_l2_messages_args_fn: |_| vec![], test_tx_hashes_fn: |tx_hashes| validate_tx_count(tx_hashes, N_TXS), - }] + } } /// Creates and sends more transactions than can fit in a block.