diff --git a/core/node/node_sync/src/fetcher.rs b/core/node/node_sync/src/fetcher.rs index 9ce12c4fe3e..3f8558ed0ac 100644 --- a/core/node/node_sync/src/fetcher.rs +++ b/core/node/node_sync/src/fetcher.rs @@ -201,3 +201,35 @@ impl IoCursorExt for IoCursor { new_actions } } + +#[cfg(test)] +mod tests { + use zksync_dal::{ConnectionPool, Core, CoreDal}; + use zksync_node_genesis::{insert_genesis_batch, GenesisParams}; + use zksync_state_keeper::io::IoCursor; + use zksync_types::{block::UnsealedL1BatchHeader, L1BatchNumber}; + + use crate::fetcher::IoCursorExt; + + #[tokio::test] + async fn io_cursor_recognizes_empty_unsealed_batch() -> anyhow::Result<()> { + let pool = ConnectionPool::::test_pool().await; + let mut conn = pool.connection().await.unwrap(); + insert_genesis_batch(&mut conn, &GenesisParams::mock()) + .await + .unwrap(); + conn.blocks_dal() + .insert_l1_batch(UnsealedL1BatchHeader { + number: L1BatchNumber(1), + timestamp: 1, + protocol_version: None, + fee_address: Default::default(), + fee_input: Default::default(), + }) + .await?; + + let io_cursor = IoCursor::for_fetcher(&mut conn).await?; + assert_eq!(io_cursor.l1_batch, L1BatchNumber(1)); + Ok(()) + } +}