Skip to content

Commit 1a2b6f3

Browse files
committed
apollo_integration_tests: simplify scenario arg in end to end flow
1 parent b9a7b96 commit 1a2b6f3

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
@@ -29,7 +29,7 @@ use tracing::info;
2929

3030
pub struct EndToEndFlowArgs {
3131
pub test_identifier: TestIdentifier,
32-
pub test_blocks_scenarios: Vec<TestScenario>,
32+
pub test_scenario: TestScenario,
3333
pub block_max_capacity_gas: GasAmount, // Used to max both sierra and proving gas.
3434
pub expecting_full_blocks: bool,
3535
pub expecting_reverted_transactions: bool,
@@ -39,12 +39,12 @@ pub struct EndToEndFlowArgs {
3939
impl EndToEndFlowArgs {
4040
pub fn new(
4141
test_identifier: TestIdentifier,
42-
test_blocks_scenarios: Vec<TestScenario>,
42+
test_scenario: TestScenario,
4343
block_max_capacity_gas: GasAmount,
4444
) -> Self {
4545
Self {
4646
test_identifier,
47-
test_blocks_scenarios,
47+
test_scenario,
4848
block_max_capacity_gas,
4949
expecting_full_blocks: false,
5050
expecting_reverted_transactions: false,
@@ -71,7 +71,7 @@ impl EndToEndFlowArgs {
7171
pub async fn end_to_end_flow(args: EndToEndFlowArgs) {
7272
let EndToEndFlowArgs {
7373
test_identifier,
74-
test_blocks_scenarios,
74+
test_scenario,
7575
block_max_capacity_gas,
7676
expecting_full_blocks,
7777
expecting_reverted_transactions,
@@ -114,58 +114,54 @@ pub async fn end_to_end_flow(args: EndToEndFlowArgs) {
114114
let mut total_expected_batched_txs_count = 0;
115115

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

170166
assert_full_blocks_flow(&global_recorder_handle, expecting_full_blocks);
171167
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
@@ -20,12 +20,12 @@ async fn declare_tx_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_declare_tx,
2626
create_l1_to_l2_messages_args_fn: |_| vec![],
2727
test_tx_hashes_fn: test_single_tx,
28-
}]
28+
}
2929
}
3030

3131
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
@@ -23,12 +23,12 @@ async fn deploy_account_and_invoke_flow() {
2323
.await
2424
}
2525

26-
fn create_test_scenarios() -> Vec<TestScenario> {
27-
vec![TestScenario {
26+
fn create_test_scenarios() -> TestScenario {
27+
TestScenario {
2828
create_rpc_txs_fn: deploy_account_and_invoke,
2929
create_l1_to_l2_messages_args_fn: |_| vec![],
3030
test_tx_hashes_fn: |tx_hashes| validate_tx_count(tx_hashes, 2),
31-
}]
31+
}
3232
}
3333

3434
/// 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
@@ -20,12 +20,12 @@ async fn funding_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_funding_txs,
2626
create_l1_to_l2_messages_args_fn: |_| vec![],
2727
test_tx_hashes_fn: test_single_tx,
28-
}]
28+
}
2929
}
3030

3131
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
@@ -20,12 +20,12 @@ async fn l1_to_l2_message_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: |_| vec![],
2626
create_l1_to_l2_messages_args_fn: |tx_generator| {
2727
create_l1_to_l2_messages_args(tx_generator, 1, false)
2828
},
2929
test_tx_hashes_fn: test_single_tx,
30-
}]
30+
}
3131
}

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
@@ -21,12 +21,12 @@ async fn multiple_account_txs_flow() {
2121
.await
2222
}
2323

24-
fn create_test_scenarios() -> Vec<TestScenario> {
25-
vec![TestScenario {
24+
fn create_test_scenarios() -> TestScenario {
25+
TestScenario {
2626
create_rpc_txs_fn: create_multiple_account_txs,
2727
create_l1_to_l2_messages_args_fn: |_| vec![],
2828
test_tx_hashes_fn: test_multiple_account_txs,
29-
}]
29+
}
3030
}
3131

3232
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)