@@ -448,10 +448,9 @@ impl<'a> UtxosView for UtxosCache<'a> {
448
448
impl < ' a > FlushableUtxoView for UtxosCache < ' a > {
449
449
fn batch_write ( & mut self , utxo_entries : ConsumedUtxoCache ) -> Result < ( ) , Error > {
450
450
for ( key, entry) in utxo_entries. container {
451
- let parent_entry = self . utxos . get ( & key) ;
452
-
453
451
// Ignore non-dirty entries (optimization).
454
452
if entry. is_dirty {
453
+ let parent_entry = self . utxos . get ( & key) ;
455
454
match parent_entry {
456
455
None => {
457
456
// The parent cache does not have an entry, while the child cache does.
@@ -516,35 +515,44 @@ mod simulation;
516
515
#[ cfg( test) ]
517
516
mod unit_test {
518
517
use common:: primitives:: H256 ;
518
+ use rstest:: rstest;
519
+ use test_utils:: random:: { make_seedable_rng, Seed } ;
519
520
520
521
use crate :: test_helper:: { insert_single_entry, Presence , DIRTY , FRESH } ;
521
522
use crate :: UtxosCache ;
522
523
523
- #[ test]
524
- fn test_uncache ( ) {
524
+ #[ rstest]
525
+ #[ trace]
526
+ #[ case( Seed :: from_entropy( ) ) ]
527
+ fn test_uncache ( #[ case] seed : Seed ) {
528
+ let mut rng = make_seedable_rng ( seed) ;
525
529
let mut cache = UtxosCache :: new_for_test ( H256 :: random ( ) . into ( ) ) ;
526
530
527
531
// when the entry is not dirty and not fresh
528
- let ( utxo, outp) = insert_single_entry ( & mut cache, & Presence :: Present , Some ( 0 ) , None ) ;
532
+ let ( utxo, outp) =
533
+ insert_single_entry ( & mut rng, & mut cache, & Presence :: Present , Some ( 0 ) , None ) ;
529
534
let res = cache. uncache ( & outp) . expect ( "should return an entry" ) ;
530
535
assert_eq ! ( res. utxo( ) , Some ( utxo) ) ;
531
536
assert ! ( !cache. has_utxo_in_cache( & outp) ) ;
532
537
533
538
// when the outpoint does not exist.
534
- let ( _, outp) = insert_single_entry ( & mut cache, & Presence :: Absent , None , None ) ;
539
+ let ( _, outp) = insert_single_entry ( & mut rng , & mut cache, & Presence :: Absent , None , None ) ;
535
540
assert_eq ! ( cache. uncache( & outp) , None ) ;
536
541
assert ! ( !cache. has_utxo_in_cache( & outp) ) ;
537
542
538
543
// when the entry is fresh, entry cannot be removed.
539
- let ( _, outp) = insert_single_entry ( & mut cache, & Presence :: Present , Some ( FRESH ) , None ) ;
544
+ let ( _, outp) =
545
+ insert_single_entry ( & mut rng, & mut cache, & Presence :: Present , Some ( FRESH ) , None ) ;
540
546
assert_eq ! ( cache. uncache( & outp) , None ) ;
541
547
542
548
// when the entry is dirty, entry cannot be removed.
543
- let ( _, outp) = insert_single_entry ( & mut cache, & Presence :: Present , Some ( DIRTY ) , None ) ;
549
+ let ( _, outp) =
550
+ insert_single_entry ( & mut rng, & mut cache, & Presence :: Present , Some ( DIRTY ) , None ) ;
544
551
assert_eq ! ( cache. uncache( & outp) , None ) ;
545
552
546
553
// when the entry is both fresh and dirty, entry cannot be removed.
547
- let ( _, outp) = insert_single_entry ( & mut cache, & Presence :: Present , Some ( FRESH ) , None ) ;
554
+ let ( _, outp) =
555
+ insert_single_entry ( & mut rng, & mut cache, & Presence :: Present , Some ( FRESH ) , None ) ;
548
556
assert_eq ! ( cache. uncache( & outp) , None ) ;
549
557
}
550
558
}
0 commit comments