From 01f3846763e24cea6a6e912536f843af16de362c Mon Sep 17 00:00:00 2001 From: Daniyar Itegulov Date: Mon, 14 Oct 2024 22:20:17 +1100 Subject: [PATCH] add test --- core/node/node_sync/src/fetcher.rs | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) 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(()) + } +}