File tree Expand file tree Collapse file tree 3 files changed +25
-6
lines changed
mithril-aggregator/src/services
mithril-common/src/entities Expand file tree Collapse file tree 3 files changed +25
-6
lines changed Original file line number Diff line number Diff line change @@ -182,7 +182,7 @@ mod tests {
182182
183183 use mithril_common:: cardano_block_scanner:: { DumbBlockScanner , ScannedBlock } ;
184184 use mithril_common:: crypto_helper:: MKTree ;
185- use mithril_common:: entities:: BlockNumber ;
185+ use mithril_common:: entities:: { BlockNumber , BlockRangesSequence } ;
186186
187187 use crate :: database:: repository:: CardanoTransactionRepository ;
188188 use crate :: database:: test_helper:: cardano_tx_db_connection;
@@ -534,8 +534,8 @@ mod tests {
534534 // Upper bound should be the block number of the highest transaction in a db that can be
535535 // included in a block range
536536 . withf ( |range| {
537- let expected_range = BlockRange :: LENGTH ..= ( BlockRange :: LENGTH * 5 ) ;
538- expected_range . contains ( & range . start ) && expected_range . contains ( & range. end )
537+ BlockRangesSequence :: new ( BlockRange :: LENGTH ..( BlockRange :: LENGTH * 5 ) )
538+ . contains ( range)
539539 } )
540540 . returning ( transactions_for_block) ;
541541 store_mock
Original file line number Diff line number Diff line change @@ -179,6 +179,11 @@ impl BlockRangesSequence {
179179 self . end
180180 }
181181
182+ /// Returns `true` if range is contained in the sequence.
183+ pub fn contains ( & self , range : & Range < BlockNumber > ) -> bool {
184+ self . start <= range. start && range. end <= self . end
185+ }
186+
182187 /// Returns `true` if the block ranges sequence contains no elements.
183188 pub fn is_empty ( & self ) -> bool {
184189 self . len ( ) == 0
@@ -338,6 +343,20 @@ mod tests {
338343 ) ;
339344 }
340345
346+ #[ test]
347+ fn test_block_ranges_sequence_contains ( ) {
348+ let block_range = BlockRange :: new ( 15 , 30 ) ;
349+ assert ! ( BlockRange :: all_block_ranges_in( 0 ..15 )
350+ . contains( & block_range)
351+ . not( ) ) ;
352+ assert ! ( BlockRange :: all_block_ranges_in( 30 ..60 )
353+ . contains( & block_range)
354+ . not( ) ) ;
355+ assert ! ( BlockRange :: all_block_ranges_in( 0 ..30 ) . contains( & block_range) ) ;
356+ assert ! ( BlockRange :: all_block_ranges_in( 15 ..30 ) . contains( & block_range) ) ;
357+ assert ! ( BlockRange :: all_block_ranges_in( 15 ..45 ) . contains( & block_range) ) ;
358+ }
359+
341360 #[ test]
342361 fn test_block_range_from_number ( ) {
343362 assert_eq ! ( BlockRange :: from_block_number( 0 ) , BlockRange :: new( 0 , 15 ) ) ;
Original file line number Diff line number Diff line change @@ -182,7 +182,7 @@ mod tests {
182182
183183 use mithril_common:: cardano_block_scanner:: { DumbBlockScanner , ScannedBlock } ;
184184 use mithril_common:: crypto_helper:: MKTree ;
185- use mithril_common:: entities:: BlockNumber ;
185+ use mithril_common:: entities:: { BlockNumber , BlockRangesSequence } ;
186186
187187 use crate :: database:: repository:: CardanoTransactionRepository ;
188188 use crate :: database:: test_utils:: cardano_tx_db_connection;
@@ -534,8 +534,8 @@ mod tests {
534534 // Upper bound should be the block number of the highest transaction in a db that can be
535535 // included in a block range
536536 . withf ( |range| {
537- let expected_range = BlockRange :: LENGTH ..= ( BlockRange :: LENGTH * 5 ) ;
538- expected_range . contains ( & range . start ) && expected_range . contains ( & range. end )
537+ BlockRangesSequence :: new ( BlockRange :: LENGTH ..( BlockRange :: LENGTH * 5 ) )
538+ . contains ( range)
539539 } )
540540 . returning ( transactions_for_block) ;
541541 store_mock
You can’t perform that action at this time.
0 commit comments