Skip to content

Commit a53f68a

Browse files
test(starknet_integration_tests): assert the full blocks flow
1 parent 8708926 commit a53f68a

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/starknet_integration_tests/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ url.workspace = true
5555

5656
[dev-dependencies]
5757
futures.workspace = true
58+
metrics.workspace = true
59+
metrics-exporter-prometheus.workspace = true
5860
pretty_assertions.workspace = true
5961
rstest.workspace = true
6062
starknet_sequencer_infra.workspace = true

crates/starknet_integration_tests/tests/end_to_end_flow_test.rs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::time::Duration;
22

33
use mempool_test_utils::starknet_api_test_utils::MultiAccountTransactionGenerator;
4+
use metrics_exporter_prometheus::{PrometheusBuilder, PrometheusRecorder};
45
use pretty_assertions::assert_eq;
56
use rstest::{fixture, rstest};
67
use starknet_api::execution_resources::GasAmount;
@@ -42,22 +43,27 @@ fn tx_generator() -> MultiAccountTransactionGenerator {
4243
#[case::end_to_end_flow(
4344
TestIdentifier::EndToEndFlowTest,
4445
create_test_scenarios(),
45-
GasAmount(29000000)
46+
GasAmount(29000000),
47+
false
4648
)]
4749
// TODO(yair): Add check that a block closed due to being full instead of deadline.
4850
#[case::many_txs_scenario(
4951
TestIdentifier::EndToEndFlowTestManyTxs,
5052
create_many_txs_scenario(),
51-
GasAmount(17500000)
53+
GasAmount(17500000),
54+
true
5255
)]
5356
#[tokio::test]
5457
async fn end_to_end_flow(
5558
mut tx_generator: MultiAccountTransactionGenerator,
5659
#[case] test_identifier: TestIdentifier,
5760
#[case] test_blocks_scenarios: Vec<TestScenario>,
5861
#[case] block_max_capacity_sierra_gas: GasAmount,
62+
#[case] expecting_full_blocks: bool,
5963
) {
6064
configure_tracing().await;
65+
let recorder = PrometheusBuilder::new().build_recorder();
66+
let _recorder_guard = metrics::set_default_local_recorder(&recorder);
6167

6268
const TEST_SCENARIO_TIMOUT: std::time::Duration = std::time::Duration::from_secs(50);
6369
// Setup.
@@ -129,14 +135,33 @@ async fn end_to_end_flow(
129135
});
130136
}
131137

132-
// Check that only the expected txs were included in the blocks.
138+
assert_only_expected_txs(
139+
total_expected_txs,
140+
mock_running_system.accumulated_txs.lock().await.accumulated_tx_hashes.clone(),
141+
);
142+
assert_full_blocks_flow(&recorder, expecting_full_blocks);
143+
}
144+
145+
fn assert_only_expected_txs(
146+
mut total_expected_txs: Vec<TransactionHash>,
147+
mut batched_txs: Vec<TransactionHash>,
148+
) {
133149
total_expected_txs.sort();
134-
let mut batched_txs =
135-
mock_running_system.accumulated_txs.lock().await.accumulated_tx_hashes.clone();
136150
batched_txs.sort();
137151
assert_eq!(total_expected_txs, batched_txs);
138152
}
139153

154+
fn assert_full_blocks_flow(recorder: &PrometheusRecorder, expecting_full_blocks: bool) {
155+
let metrics = recorder.handle().render();
156+
let full_blocks_metric =
157+
starknet_batcher::metrics::FULL_BLOCKS.parse_numeric_metric::<u64>(&metrics).unwrap();
158+
if expecting_full_blocks {
159+
assert!(full_blocks_metric > 0);
160+
} else {
161+
assert_eq!(full_blocks_metric, 0);
162+
}
163+
}
164+
140165
fn create_test_scenarios() -> Vec<TestScenario> {
141166
vec![
142167
// This block should be the first to be tested, as the addition of L1 handler transaction

0 commit comments

Comments
 (0)