Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/apollo_integration_tests/tests/bootstrap_declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use crate::common::{end_to_end_flow, test_single_tx, EndToEndFlowArgs, TestScena

mod common;

fn create_bootstrap_declare_scenario() -> Vec<TestScenario> {
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
Expand Down
106 changes: 51 additions & 55 deletions crates/apollo_integration_tests/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use tracing::info;

pub struct EndToEndFlowArgs {
pub test_identifier: TestIdentifier,
pub test_blocks_scenarios: Vec<TestScenario>,
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,
Expand All @@ -39,12 +39,12 @@ pub struct EndToEndFlowArgs {
impl EndToEndFlowArgs {
pub fn new(
test_identifier: TestIdentifier,
test_blocks_scenarios: Vec<TestScenario>,
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,
Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions crates/apollo_integration_tests/tests/declare_tx_flow_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ async fn declare_tx_flow() {
.await
}

fn create_test_scenarios() -> Vec<TestScenario> {
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<RpcTransaction> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ async fn deploy_account_and_invoke_flow() {
.await
}

fn create_test_scenarios() -> Vec<TestScenario> {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ async fn funding_txs_flow() {
.await
}

fn create_test_scenarios() -> Vec<TestScenario> {
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<RpcTransaction> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ async fn l1_to_l2_message_flow() {
.await
}

fn create_test_scenarios() -> Vec<TestScenario> {
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,
}]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ async fn multiple_account_txs_flow() {
.await
}

fn create_test_scenarios() -> Vec<TestScenario> {
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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ async fn reverted_l1_handler_tx_flow() {
.await
}

fn create_test_scenarios() -> Vec<TestScenario> {
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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ async fn custom_cairo0_txs() {
.await
}

fn create_custom_cairo0_txs_scenario() -> Vec<TestScenario> {
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ async fn custom_cairo1_txs() {
.await
}

fn create_custom_cairo1_txs_scenario() -> Vec<TestScenario> {
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.
Expand Down
6 changes: 3 additions & 3 deletions crates/apollo_integration_tests/tests/test_many.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ async fn many_txs_fill_at_least_one_block() {
.await
}

fn create_many_txs_scenario() -> Vec<TestScenario> {
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.
Expand Down
Loading