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 {
182
182
183
183
use mithril_common:: cardano_block_scanner:: { DumbBlockScanner , ScannedBlock } ;
184
184
use mithril_common:: crypto_helper:: MKTree ;
185
- use mithril_common:: entities:: BlockNumber ;
185
+ use mithril_common:: entities:: { BlockNumber , BlockRangesSequence } ;
186
186
187
187
use crate :: database:: repository:: CardanoTransactionRepository ;
188
188
use crate :: database:: test_helper:: cardano_tx_db_connection;
@@ -534,8 +534,8 @@ mod tests {
534
534
// Upper bound should be the block number of the highest transaction in a db that can be
535
535
// included in a block range
536
536
. 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)
539
539
} )
540
540
. returning ( transactions_for_block) ;
541
541
store_mock
Original file line number Diff line number Diff line change @@ -179,6 +179,11 @@ impl BlockRangesSequence {
179
179
self . end
180
180
}
181
181
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
+
182
187
/// Returns `true` if the block ranges sequence contains no elements.
183
188
pub fn is_empty ( & self ) -> bool {
184
189
self . len ( ) == 0
@@ -338,6 +343,20 @@ mod tests {
338
343
) ;
339
344
}
340
345
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
+
341
360
#[ test]
342
361
fn test_block_range_from_number ( ) {
343
362
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 {
182
182
183
183
use mithril_common:: cardano_block_scanner:: { DumbBlockScanner , ScannedBlock } ;
184
184
use mithril_common:: crypto_helper:: MKTree ;
185
- use mithril_common:: entities:: BlockNumber ;
185
+ use mithril_common:: entities:: { BlockNumber , BlockRangesSequence } ;
186
186
187
187
use crate :: database:: repository:: CardanoTransactionRepository ;
188
188
use crate :: database:: test_utils:: cardano_tx_db_connection;
@@ -534,8 +534,8 @@ mod tests {
534
534
// Upper bound should be the block number of the highest transaction in a db that can be
535
535
// included in a block range
536
536
. 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)
539
539
} )
540
540
. returning ( transactions_for_block) ;
541
541
store_mock
You can’t perform that action at this time.
0 commit comments