Skip to content

Commit 0375fd1

Browse files
committed
apollo_integration_tests: simplify scenario arg in end to end flow
1 parent bc3025e commit 0375fd1

11 files changed

+76
-80
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: 46 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use tracing::info;
3030
pub struct EndToEndFlowArgs {
3131
pub test_identifier: TestIdentifier,
3232
pub instance_index: u16,
33-
pub test_blocks_scenarios: Vec<TestScenario>,
33+
pub test_scenario: TestScenario,
3434
pub block_max_capacity_gas: GasAmount, // Used to max both sierra and proving gas.
3535
pub expecting_full_blocks: bool,
3636
pub expecting_reverted_transactions: bool,
@@ -40,13 +40,13 @@ pub struct EndToEndFlowArgs {
4040
impl EndToEndFlowArgs {
4141
pub fn new(
4242
test_identifier: TestIdentifier,
43-
test_blocks_scenarios: Vec<TestScenario>,
43+
test_scenario: TestScenario,
4444
block_max_capacity_gas: GasAmount,
4545
) -> Self {
4646
Self {
4747
test_identifier,
4848
instance_index: 0,
49-
test_blocks_scenarios,
49+
test_scenario,
5050
block_max_capacity_gas,
5151
expecting_full_blocks: false,
5252
expecting_reverted_transactions: false,
@@ -78,7 +78,7 @@ pub async fn end_to_end_flow(args: EndToEndFlowArgs) {
7878
let EndToEndFlowArgs {
7979
test_identifier,
8080
instance_index,
81-
test_blocks_scenarios,
81+
test_scenario,
8282
block_max_capacity_gas,
8383
expecting_full_blocks,
8484
expecting_reverted_transactions,
@@ -122,58 +122,54 @@ pub async fn end_to_end_flow(args: EndToEndFlowArgs) {
122122
let mut total_expected_batched_txs_count = 0;
123123

124124
// Build multiple heights to ensure heights are committed.
125-
for (
126-
i,
127-
TestScenario { create_rpc_txs_fn, create_l1_to_l2_messages_args_fn, test_tx_hashes_fn },
128-
) in test_blocks_scenarios.into_iter().enumerate()
129-
{
130-
info!("Starting scenario {i}.");
131-
// Create and send transactions.
132-
// TODO(Arni): move send messages to l2 into [run_test_scenario].
133-
let l1_handlers = create_l1_to_l2_messages_args_fn(&mut tx_generator);
134-
mock_running_system.send_messages_to_l2(&l1_handlers).await;
125+
let TestScenario { create_rpc_txs_fn, create_l1_to_l2_messages_args_fn, test_tx_hashes_fn } =
126+
test_scenario;
135127

136-
// Run the test scenario and get the expected batched tx hashes of the current scenario.
137-
let expected_batched_tx_hashes = run_test_scenario(
138-
&mut tx_generator,
139-
create_rpc_txs_fn,
140-
l1_handlers,
141-
&mut send_rpc_tx_fn,
142-
test_tx_hashes_fn,
143-
&chain_id,
144-
)
145-
.await;
128+
// Create and send transactions.
129+
// TODO(Arni): move send messages to l2 into [run_test_scenario].
130+
let l1_handlers = create_l1_to_l2_messages_args_fn(&mut tx_generator);
131+
mock_running_system.send_messages_to_l2(&l1_handlers).await;
146132

147-
// Each sequencer increases the same BATCHED_TRANSACTIONS metric because they are running
148-
// in the same process in this test.
149-
total_expected_batched_txs_count += NUM_OF_SEQUENCERS * expected_batched_tx_hashes.len();
150-
let mut current_batched_txs_count = 0;
133+
// Run the test scenario and get the expected batched tx hashes of the current scenario.
134+
let expected_batched_tx_hashes = run_test_scenario(
135+
&mut tx_generator,
136+
create_rpc_txs_fn,
137+
l1_handlers,
138+
&mut send_rpc_tx_fn,
139+
test_tx_hashes_fn,
140+
&chain_id,
141+
)
142+
.await;
151143

152-
tokio::time::timeout(TEST_SCENARIO_TIMEOUT, async {
153-
loop {
154-
info!(
155-
"Waiting for more txs to be batched in a block. Expected batched txs: \
156-
{total_expected_batched_txs_count}, Currently batched txs: \
157-
{current_batched_txs_count}"
158-
);
144+
// Each sequencer increases the same BATCHED_TRANSACTIONS metric because they are running
145+
// in the same process in this test.
146+
total_expected_batched_txs_count += NUM_OF_SEQUENCERS * expected_batched_tx_hashes.len();
147+
let mut current_batched_txs_count = 0;
159148

160-
current_batched_txs_count = get_total_batched_txs_count(&global_recorder_handle);
161-
if current_batched_txs_count == total_expected_batched_txs_count {
162-
break;
163-
}
149+
tokio::time::timeout(TEST_SCENARIO_TIMEOUT, async {
150+
loop {
151+
info!(
152+
"Waiting for more txs to be batched in a block. Expected batched txs: \
153+
{total_expected_batched_txs_count}, Currently batched txs: \
154+
{current_batched_txs_count}"
155+
);
164156

165-
tokio::time::sleep(Duration::from_millis(2000)).await;
157+
current_batched_txs_count = get_total_batched_txs_count(&global_recorder_handle);
158+
if current_batched_txs_count == total_expected_batched_txs_count {
159+
break;
166160
}
167-
})
168-
.await
169-
.unwrap_or_else(|_| {
170-
panic!(
171-
"Scenario {i}: Expected transactions should be included in a block by now, \
172-
Expected amount of batched txs: {total_expected_batched_txs_count}, Currently \
173-
amount of batched txs: {current_batched_txs_count}"
174-
)
175-
});
176-
}
161+
162+
tokio::time::sleep(Duration::from_millis(2000)).await;
163+
}
164+
})
165+
.await
166+
.unwrap_or_else(|_| {
167+
panic!(
168+
"Expected transactions should be included in a block by now, Expected amount of \
169+
batched txs: {total_expected_batched_txs_count}, Currently amount of batched txs: \
170+
{current_batched_txs_count}"
171+
)
172+
});
177173

178174
assert_full_blocks_flow(&global_recorder_handle, expecting_full_blocks);
179175
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
@@ -23,12 +23,12 @@ async fn declare_tx_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: create_declare_tx,
2929
create_l1_to_l2_messages_args_fn: |_| vec![],
3030
test_tx_hashes_fn: test_single_tx,
31-
}]
31+
}
3232
}
3333

3434
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
@@ -27,12 +27,12 @@ async fn deploy_account_and_invoke_flow() {
2727
.await
2828
}
2929

30-
fn create_test_scenarios() -> Vec<TestScenario> {
31-
vec![TestScenario {
30+
fn create_test_scenarios() -> TestScenario {
31+
TestScenario {
3232
create_rpc_txs_fn: deploy_account_and_invoke,
3333
create_l1_to_l2_messages_args_fn: |_| vec![],
3434
test_tx_hashes_fn: |tx_hashes| validate_tx_count(tx_hashes, 2),
35-
}]
35+
}
3636
}
3737

3838
/// 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
@@ -23,12 +23,12 @@ async fn funding_txs_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: create_funding_txs,
2929
create_l1_to_l2_messages_args_fn: |_| vec![],
3030
test_tx_hashes_fn: test_single_tx,
31-
}]
31+
}
3232
}
3333

3434
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
@@ -21,12 +21,12 @@ async fn l1_to_l2_message_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: |_| vec![],
2727
create_l1_to_l2_messages_args_fn: |tx_generator| {
2828
create_l1_to_l2_messages_args(tx_generator, 1, false)
2929
},
3030
test_tx_hashes_fn: test_single_tx,
31-
}]
31+
}
3232
}

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
@@ -24,12 +24,12 @@ async fn multiple_account_txs_flow() {
2424
.await
2525
}
2626

27-
fn create_test_scenarios() -> Vec<TestScenario> {
28-
vec![TestScenario {
27+
fn create_test_scenarios() -> TestScenario {
28+
TestScenario {
2929
create_rpc_txs_fn: create_multiple_account_txs,
3030
create_l1_to_l2_messages_args_fn: |_| vec![],
3131
test_tx_hashes_fn: test_multiple_account_txs,
32-
}]
32+
}
3333
}
3434

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