Skip to content

Commit d4da472

Browse files
author
Gilad Chase
committed
refactor(starknet_l1_provider): use consts
Makes it easier to debug (tooltips show the value)
1 parent 3522af7 commit d4da472

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

crates/starknet_l1_provider/src/l1_scraper_tests.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ async fn bootstrap_e2e() {
149149
// Setup.
150150

151151
let l1_provider_client = Arc::new(FakeL1ProviderClient::default());
152-
let startup_height = BlockNumber(2);
153-
let catch_up_height = BlockNumber(5);
152+
const STARTUP_HEIGHT: BlockNumber = BlockNumber(2);
153+
const CATCH_UP_HEIGHT: BlockNumber = BlockNumber(5);
154154

155155
// Make the mocked sync client try removing from a hashmap as a response to get block.
156156
let mut sync_client = MockStateSyncClient::default();
@@ -159,15 +159,15 @@ async fn bootstrap_e2e() {
159159
sync_client.expect_get_block().returning(move |input| Ok(sync_response_clone.remove(&input)));
160160

161161
let config = L1ProviderConfig {
162-
bootstrap_catch_up_height_override: Some(catch_up_height),
162+
bootstrap_catch_up_height_override: Some(CATCH_UP_HEIGHT),
163163
startup_sync_sleep_retry_interval: Duration::from_millis(10),
164164
..Default::default()
165165
};
166166
let mut l1_provider = create_l1_provider(
167167
config,
168168
l1_provider_client.clone(),
169169
Arc::new(sync_client),
170-
startup_height,
170+
STARTUP_HEIGHT,
171171
);
172172

173173
// Test.
@@ -182,25 +182,25 @@ async fn bootstrap_e2e() {
182182

183183
// Load first **Sync** response: the initializer task will pick it up within the specified
184184
// interval.
185-
sync_response.lock().unwrap().insert(startup_height, SyncBlock::default());
185+
sync_response.lock().unwrap().insert(STARTUP_HEIGHT, SyncBlock::default());
186186
tokio::time::sleep(config.startup_sync_sleep_retry_interval).await;
187187

188188
// **Commit** 2 blocks past catchup height, should be received after the previous sync.
189189
let no_txs_committed = vec![]; // Not testing txs in this test.
190190
l1_provider_client
191-
.commit_block(no_txs_committed.clone(), catch_up_height.unchecked_next())
191+
.commit_block(no_txs_committed.clone(), CATCH_UP_HEIGHT.unchecked_next())
192192
.await
193193
.unwrap();
194194
tokio::time::sleep(config.startup_sync_sleep_retry_interval).await;
195195
l1_provider_client
196-
.commit_block(no_txs_committed, catch_up_height.unchecked_next().unchecked_next())
196+
.commit_block(no_txs_committed, CATCH_UP_HEIGHT.unchecked_next().unchecked_next())
197197
.await
198198
.unwrap();
199199
tokio::time::sleep(config.startup_sync_sleep_retry_interval).await;
200200

201201
// Feed sync task the remaining blocks, will be received after the commits above.
202-
sync_response.lock().unwrap().insert(BlockNumber(startup_height.0 + 1), SyncBlock::default());
203-
sync_response.lock().unwrap().insert(BlockNumber(startup_height.0 + 2), SyncBlock::default());
202+
sync_response.lock().unwrap().insert(BlockNumber(STARTUP_HEIGHT.0 + 1), SyncBlock::default());
203+
sync_response.lock().unwrap().insert(BlockNumber(STARTUP_HEIGHT.0 + 2), SyncBlock::default());
204204
tokio::time::sleep(2 * config.startup_sync_sleep_retry_interval).await;
205205

206206
// Assert that initializer task has received the stubbed responses from the sync client and sent
@@ -265,7 +265,7 @@ async fn bootstrap_delayed_sync_state_with_trivial_catch_up() {
265265
// Setup.
266266

267267
let l1_provider_client = Arc::new(FakeL1ProviderClient::default());
268-
let startup_height = BlockNumber(2);
268+
const STARTUP_HEIGHT: BlockNumber = BlockNumber(2);
269269

270270
let mut sync_client = MockStateSyncClient::default();
271271
// Mock sync response for an arbitrary number of calls to get_latest_block_number.
@@ -284,7 +284,7 @@ async fn bootstrap_delayed_sync_state_with_trivial_catch_up() {
284284
config,
285285
l1_provider_client.clone(),
286286
Arc::new(sync_client),
287-
startup_height,
287+
STARTUP_HEIGHT,
288288
);
289289

290290
// Test.
@@ -297,9 +297,9 @@ async fn bootstrap_delayed_sync_state_with_trivial_catch_up() {
297297
// is a trivial catchup scenario (nothing to catch up).
298298
// This checks that the trivial catch_up_height doesn't mess up this flow.
299299
let no_txs_committed = []; // Not testing txs in this test.
300-
l1_provider_client.commit_block(no_txs_committed.to_vec(), startup_height).await.unwrap();
300+
l1_provider_client.commit_block(no_txs_committed.to_vec(), STARTUP_HEIGHT).await.unwrap();
301301
l1_provider_client
302-
.commit_block(no_txs_committed.to_vec(), startup_height.unchecked_next())
302+
.commit_block(no_txs_committed.to_vec(), STARTUP_HEIGHT.unchecked_next())
303303
.await
304304
.unwrap();
305305

@@ -311,7 +311,7 @@ async fn bootstrap_delayed_sync_state_with_trivial_catch_up() {
311311
}
312312

313313
// Commit blocks should have been applied.
314-
let start_height_plus_2 = startup_height.unchecked_next().unchecked_next();
314+
let start_height_plus_2 = STARTUP_HEIGHT.unchecked_next().unchecked_next();
315315
assert_eq!(l1_provider.current_height, start_height_plus_2);
316316
// Should still be bootstrapping, since catchup height isn't determined yet.
317317
// Technically we could end bootstrapping at this point, but its simpler to let it

0 commit comments

Comments
 (0)