File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
crates/consensus-logic/src Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -400,3 +400,42 @@ fn poll_status_loop<E: ExecEngineCtl>(
400400
401401 Ok ( None )
402402}
403+
404+ #[ cfg( test) ]
405+ mod tests {
406+ use alpen_test_utils:: l2:: gen_l2_chain;
407+ use alpen_vertex_db:: traits:: { Database , L2DataStore } ;
408+ use alpen_vertex_state:: header:: L2Header ;
409+
410+ use super :: get_finalized_blocks;
411+
412+ #[ test]
413+ fn test_get_finalized_blocks ( ) {
414+ let db = alpen_test_utils:: get_common_db ( ) ;
415+ let chain = gen_l2_chain ( None , 5 ) ;
416+
417+ for block in chain. clone ( ) {
418+ db. as_ref ( )
419+ . l2_store ( )
420+ . as_ref ( )
421+ . put_block_data ( block)
422+ . unwrap ( ) ;
423+ }
424+
425+ let block_ids: Vec < _ > = chain. iter ( ) . map ( |b| b. header ( ) . get_blockid ( ) ) . collect ( ) ;
426+
427+ let mut last_finalized_block = Some ( block_ids[ 0 ] ) ;
428+ let new_finalized = Some ( block_ids[ 4 ] ) ;
429+ let finalized_blocks = get_finalized_blocks (
430+ new_finalized,
431+ db. l2_provider ( ) . as_ref ( ) ,
432+ & mut last_finalized_block,
433+ )
434+ . unwrap ( ) ;
435+
436+ let expected_finalized_blocks: Vec < _ > = block_ids[ 1 ..=4 ] . iter ( ) . rev ( ) . cloned ( ) . collect ( ) ;
437+
438+ assert_eq ! ( finalized_blocks, expected_finalized_blocks) ;
439+ assert_eq ! ( last_finalized_block, new_finalized) ;
440+ }
441+ }
You can’t perform that action at this time.
0 commit comments