Skip to content

Commit af0c821

Browse files
committed
apollo_integration_tests: simplify scenario arg in end to end flow
1 parent ce7d79e commit af0c821

11 files changed

+81
-85
lines changed

crates/apollo_integration_tests/tests/bootstrap_declare.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ use crate::common::{end_to_end_flow, test_single_tx, EndToEndFlowArgs, TestScena
66

77
mod common;
88

9-
fn create_bootstrap_declare_scenario() -> Vec<TestScenario> {
10-
vec![TestScenario {
9+
fn create_bootstrap_declare_scenario() -> TestScenario {
10+
TestScenario {
1111
create_rpc_txs_fn: |_| vec![generate_bootstrap_declare()],
1212
create_l1_to_l2_messages_args_fn: |_| vec![],
1313
test_tx_hashes_fn: test_single_tx,
14-
}]
14+
}
1515
}
1616

1717
/// Bootstrap declare txs are unique: they are sent from a special address and do not increment its

crates/apollo_integration_tests/tests/common/mod.rs

Lines changed: 51 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use tracing::info;
2828

2929
pub struct EndToEndFlowArgs {
3030
pub test_identifier: TestIdentifier,
31-
pub test_blocks_scenarios: Vec<TestScenario>,
31+
pub test_scenario: TestScenario,
3232
pub block_max_capacity_gas: GasAmount, // Used to max both sierra and proving gas.
3333
pub expecting_full_blocks: bool,
3434
pub expecting_reverted_transactions: bool,
@@ -38,12 +38,12 @@ pub struct EndToEndFlowArgs {
3838
impl EndToEndFlowArgs {
3939
pub fn new(
4040
test_identifier: TestIdentifier,
41-
test_blocks_scenarios: Vec<TestScenario>,
41+
test_scenario: TestScenario,
4242
block_max_capacity_gas: GasAmount,
4343
) -> Self {
4444
Self {
4545
test_identifier,
46-
test_blocks_scenarios,
46+
test_scenario,
4747
block_max_capacity_gas,
4848
expecting_full_blocks: false,
4949
expecting_reverted_transactions: false,
@@ -70,7 +70,7 @@ impl EndToEndFlowArgs {
7070
pub async fn end_to_end_flow(args: EndToEndFlowArgs) {
7171
let EndToEndFlowArgs {
7272
test_identifier,
73-
test_blocks_scenarios,
73+
test_scenario,
7474
block_max_capacity_gas,
7575
expecting_full_blocks,
7676
expecting_reverted_transactions,
@@ -113,58 +113,54 @@ pub async fn end_to_end_flow(args: EndToEndFlowArgs) {
113113
let mut total_expected_batched_txs_count = 0;
114114

115115
// Build multiple heights to ensure heights are committed.
116-
for (
117-
i,
118-
TestScenario { create_rpc_txs_fn, create_l1_to_l2_messages_args_fn, test_tx_hashes_fn },
119-
) in test_blocks_scenarios.into_iter().enumerate()
120-
{
121-
info!("Starting scenario {i}.");
122-
// Create and send transactions.
123-
// TODO(Arni): move send messages to l2 into [run_test_scenario].
124-
let l1_handlers = create_l1_to_l2_messages_args_fn(&mut tx_generator);
125-
mock_running_system.send_messages_to_l2(&l1_handlers).await;
126-
127-
// Run the test scenario and get the expected batched tx hashes of the current scenario.
128-
let expected_batched_tx_hashes = run_test_scenario(
129-
&mut tx_generator,
130-
create_rpc_txs_fn,
131-
l1_handlers,
132-
&mut send_rpc_tx_fn,
133-
test_tx_hashes_fn,
134-
&chain_id,
135-
)
136-
.await;
137-
138-
// Each sequencer increases the same BATCHED_TRANSACTIONS metric because they are running
139-
// in the same process in this test.
140-
total_expected_batched_txs_count += NUM_OF_SEQUENCERS * expected_batched_tx_hashes.len();
141-
let mut current_batched_txs_count = 0;
142-
143-
tokio::time::timeout(TEST_SCENARIO_TIMEOUT, async {
144-
loop {
145-
info!(
146-
"Waiting for more txs to be batched in a block. Expected batched txs: \
147-
{total_expected_batched_txs_count}, Currently batched txs: \
148-
{current_batched_txs_count}"
149-
);
150-
151-
current_batched_txs_count = get_total_batched_txs_count(&global_recorder_handle);
152-
if current_batched_txs_count == total_expected_batched_txs_count {
153-
break;
154-
}
155-
156-
tokio::time::sleep(Duration::from_millis(2000)).await;
116+
let TestScenario { create_rpc_txs_fn, create_l1_to_l2_messages_args_fn, test_tx_hashes_fn } =
117+
test_scenario;
118+
119+
// Create and send transactions.
120+
// TODO(Arni): move send messages to l2 into [run_test_scenario].
121+
let l1_handlers = create_l1_to_l2_messages_args_fn(&mut tx_generator);
122+
mock_running_system.send_messages_to_l2(&l1_handlers).await;
123+
124+
// Run the test scenario and get the expected batched tx hashes of the current scenario.
125+
let expected_batched_tx_hashes = run_test_scenario(
126+
&mut tx_generator,
127+
create_rpc_txs_fn,
128+
l1_handlers,
129+
&mut send_rpc_tx_fn,
130+
test_tx_hashes_fn,
131+
&chain_id,
132+
)
133+
.await;
134+
135+
// Each sequencer increases the same BATCHED_TRANSACTIONS metric because they are running
136+
// in the same process in this test.
137+
total_expected_batched_txs_count += NUM_OF_SEQUENCERS * expected_batched_tx_hashes.len();
138+
let mut current_batched_txs_count = 0;
139+
140+
tokio::time::timeout(TEST_SCENARIO_TIMEOUT, async {
141+
loop {
142+
info!(
143+
"Waiting for more txs to be batched in a block. Expected batched txs: \
144+
{total_expected_batched_txs_count}, Currently batched txs: \
145+
{current_batched_txs_count}"
146+
);
147+
148+
current_batched_txs_count = get_total_batched_txs_count(&global_recorder_handle);
149+
if current_batched_txs_count == total_expected_batched_txs_count {
150+
break;
157151
}
158-
})
159-
.await
160-
.unwrap_or_else(|_| {
161-
panic!(
162-
"Scenario {i}: Expected transactions should be included in a block by now, \
163-
Expected amount of batched txs: {total_expected_batched_txs_count}, Currently \
164-
amount of batched txs: {current_batched_txs_count}"
165-
)
166-
});
167-
}
152+
153+
tokio::time::sleep(Duration::from_millis(2000)).await;
154+
}
155+
})
156+
.await
157+
.unwrap_or_else(|_| {
158+
panic!(
159+
"Expected transactions should be included in a block by now, Expected amount of \
160+
batched txs: {total_expected_batched_txs_count}, Currently amount of batched txs: \
161+
{current_batched_txs_count}"
162+
)
163+
});
168164

169165
assert_full_blocks_flow(&global_recorder_handle, expecting_full_blocks);
170166
assert_on_number_of_reverted_transactions_flow(

crates/apollo_integration_tests/tests/declare_tx_flow_test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ async fn test_declare_tx_flow() {
1919
.await
2020
}
2121

22-
fn create_test_scenarios() -> Vec<TestScenario> {
23-
vec![TestScenario {
22+
fn create_test_scenarios() -> TestScenario {
23+
TestScenario {
2424
create_rpc_txs_fn: create_declare_tx,
2525
create_l1_to_l2_messages_args_fn: |_| vec![],
2626
test_tx_hashes_fn: test_single_tx,
27-
}]
27+
}
2828
}
2929

3030
fn create_declare_tx(tx_generator: &mut MultiAccountTransactionGenerator) -> Vec<RpcTransaction> {

crates/apollo_integration_tests/tests/deploy_account_and_invoke_flow_test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ async fn test_deploy_account_and_invoke_flow() {
2222
.await
2323
}
2424

25-
fn create_test_scenarios() -> Vec<TestScenario> {
26-
vec![TestScenario {
25+
fn create_test_scenarios() -> TestScenario {
26+
TestScenario {
2727
create_rpc_txs_fn: deploy_account_and_invoke,
2828
create_l1_to_l2_messages_args_fn: |_| vec![],
2929
test_tx_hashes_fn: |tx_hashes| validate_tx_count(tx_hashes, 2),
30-
}]
30+
}
3131
}
3232

3333
/// Generates a deploy account transaction followed by an invoke transaction from the same deployed

crates/apollo_integration_tests/tests/funding_txs_flow_test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ async fn test_funding_txs_flow() {
1919
.await
2020
}
2121

22-
fn create_test_scenarios() -> Vec<TestScenario> {
23-
vec![TestScenario {
22+
fn create_test_scenarios() -> TestScenario {
23+
TestScenario {
2424
create_rpc_txs_fn: create_funding_txs,
2525
create_l1_to_l2_messages_args_fn: |_| vec![],
2626
test_tx_hashes_fn: test_single_tx,
27-
}]
27+
}
2828
}
2929

3030
fn create_funding_txs(tx_generator: &mut MultiAccountTransactionGenerator) -> Vec<RpcTransaction> {

crates/apollo_integration_tests/tests/l1_to_l2_message_flow_test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ async fn test_l1_to_l2_message_flow() {
1919
.await
2020
}
2121

22-
fn create_test_scenarios() -> Vec<TestScenario> {
23-
vec![TestScenario {
22+
fn create_test_scenarios() -> TestScenario {
23+
TestScenario {
2424
create_rpc_txs_fn: |_| vec![],
2525
create_l1_to_l2_messages_args_fn: create_l1_to_l2_message_args,
2626
test_tx_hashes_fn: test_single_tx,
27-
}]
27+
}
2828
}
2929

3030
fn create_l1_to_l2_message_args(

crates/apollo_integration_tests/tests/multiple_account_txs_flow_test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ async fn test_multiple_account_txs_flow() {
2020
.await
2121
}
2222

23-
fn create_test_scenarios() -> Vec<TestScenario> {
24-
vec![TestScenario {
23+
fn create_test_scenarios() -> TestScenario {
24+
TestScenario {
2525
create_rpc_txs_fn: create_multiple_account_txs,
2626
create_l1_to_l2_messages_args_fn: |_| vec![],
2727
test_tx_hashes_fn: test_multiple_account_txs,
28-
}]
28+
}
2929
}
3030

3131
fn create_multiple_account_txs(

crates/apollo_integration_tests/tests/reverted_l1_handler_tx_flow_test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ async fn reverted_l1_handler_tx_flow() {
2222
.await
2323
}
2424

25-
fn create_test_scenarios() -> Vec<TestScenario> {
26-
vec![TestScenario {
25+
fn create_test_scenarios() -> TestScenario {
26+
TestScenario {
2727
create_rpc_txs_fn: |_| vec![],
2828
create_l1_to_l2_messages_args_fn: create_l1_to_l2_reverted_message_args,
2929
test_tx_hashes_fn: test_single_tx,
30-
}]
30+
}
3131
}
3232

3333
fn create_l1_to_l2_reverted_message_args(

crates/apollo_integration_tests/tests/test_custom_cairo0_txs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ async fn custom_cairo0_txs() {
3131
.await
3232
}
3333

34-
fn create_custom_cairo0_txs_scenario() -> Vec<TestScenario> {
35-
vec![TestScenario {
34+
fn create_custom_cairo0_txs_scenario() -> TestScenario {
35+
TestScenario {
3636
create_rpc_txs_fn: create_custom_cairo0_test_txs,
3737
create_l1_to_l2_messages_args_fn: |_| vec![],
3838
test_tx_hashes_fn: |tx_hashes| validate_tx_count(tx_hashes, CUSTOM_CAIRO_0_INVOKE_TX_COUNT),
39-
}]
39+
}
4040
}
4141

4242
/// Creates a set of transactions that test the Cairo 0 functionality.

crates/apollo_integration_tests/tests/test_custom_cairo1_txs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ async fn custom_cairo1_txs() {
3737
.await
3838
}
3939

40-
fn create_custom_cairo1_txs_scenario() -> Vec<TestScenario> {
41-
vec![TestScenario {
40+
fn create_custom_cairo1_txs_scenario() -> TestScenario {
41+
TestScenario {
4242
create_rpc_txs_fn: create_custom_cairo1_test_txs,
4343
create_l1_to_l2_messages_args_fn: |_| vec![],
4444
test_tx_hashes_fn: |tx_hashes| validate_tx_count(tx_hashes, CUSTOM_INVOKE_TX_COUNT),
45-
}]
45+
}
4646
}
4747

4848
/// Creates a set of transactions that test the Cairo 1.0 syscall functionality.

0 commit comments

Comments
 (0)