|
1 | 1 | use std::time::Duration;
|
2 | 2 |
|
3 | 3 | use mempool_test_utils::starknet_api_test_utils::MultiAccountTransactionGenerator;
|
| 4 | +use metrics_exporter_prometheus::{PrometheusBuilder, PrometheusRecorder}; |
4 | 5 | use pretty_assertions::assert_eq;
|
5 | 6 | use rstest::{fixture, rstest};
|
6 | 7 | use starknet_api::execution_resources::GasAmount;
|
@@ -42,22 +43,27 @@ fn tx_generator() -> MultiAccountTransactionGenerator {
|
42 | 43 | #[case::end_to_end_flow(
|
43 | 44 | TestIdentifier::EndToEndFlowTest,
|
44 | 45 | create_test_scenarios(),
|
45 |
| - GasAmount(29000000) |
| 46 | + GasAmount(29000000), |
| 47 | + false |
46 | 48 | )]
|
47 | 49 | // TODO(yair): Add check that a block closed due to being full instead of deadline.
|
48 | 50 | #[case::many_txs_scenario(
|
49 | 51 | TestIdentifier::EndToEndFlowTestManyTxs,
|
50 | 52 | create_many_txs_scenario(),
|
51 |
| - GasAmount(17500000) |
| 53 | + GasAmount(17500000), |
| 54 | + true |
52 | 55 | )]
|
53 | 56 | #[tokio::test]
|
54 | 57 | async fn end_to_end_flow(
|
55 | 58 | mut tx_generator: MultiAccountTransactionGenerator,
|
56 | 59 | #[case] test_identifier: TestIdentifier,
|
57 | 60 | #[case] test_blocks_scenarios: Vec<TestScenario>,
|
58 | 61 | #[case] block_max_capacity_sierra_gas: GasAmount,
|
| 62 | + #[case] expecting_full_blocks: bool, |
59 | 63 | ) {
|
60 | 64 | configure_tracing().await;
|
| 65 | + let recorder = PrometheusBuilder::new().build_recorder(); |
| 66 | + let _recorder_guard = metrics::set_default_local_recorder(&recorder); |
61 | 67 |
|
62 | 68 | const TEST_SCENARIO_TIMOUT: std::time::Duration = std::time::Duration::from_secs(50);
|
63 | 69 | // Setup.
|
@@ -129,14 +135,33 @@ async fn end_to_end_flow(
|
129 | 135 | });
|
130 | 136 | }
|
131 | 137 |
|
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 | +) { |
133 | 149 | total_expected_txs.sort();
|
134 |
| - let mut batched_txs = |
135 |
| - mock_running_system.accumulated_txs.lock().await.accumulated_tx_hashes.clone(); |
136 | 150 | batched_txs.sort();
|
137 | 151 | assert_eq!(total_expected_txs, batched_txs);
|
138 | 152 | }
|
139 | 153 |
|
| 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 | + |
140 | 165 | fn create_test_scenarios() -> Vec<TestScenario> {
|
141 | 166 | vec![
|
142 | 167 | // This block should be the first to be tested, as the addition of L1 handler transaction
|
|
0 commit comments