File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -607,4 +607,34 @@ mod tests {
607607 timestamps. reverse ( ) ;
608608 assert_eq ! ( MedianTimePast :: new( timestamps) . unwrap( ) . to_u32( ) , 500_000_005 ) ;
609609 }
610+
611+ #[ test]
612+ fn height_is_satisfied_by ( ) {
613+ let chain_tip = Height :: from_u32 ( 100 ) . unwrap ( ) ;
614+
615+ // lock is satisfied if transaction can go in the next block (height <= chain_tip + 1).
616+ let locktime = Height :: from_u32 ( 100 ) . unwrap ( ) ;
617+ assert ! ( locktime. is_satisfied_by( chain_tip) ) ;
618+ let locktime = Height :: from_u32 ( 101 ) . unwrap ( ) ;
619+ assert ! ( locktime. is_satisfied_by( chain_tip) ) ;
620+
621+ // It is not satisfied if the lock height is after the next block.
622+ let locktime = Height :: from_u32 ( 102 ) . unwrap ( ) ;
623+ assert ! ( !locktime. is_satisfied_by( chain_tip) ) ;
624+ }
625+
626+ #[ test]
627+ fn median_time_past_is_satisfied_by ( ) {
628+ let mtp = MedianTimePast :: from_u32 ( 500_000_001 ) . unwrap ( ) ;
629+
630+ // lock is satisfied if transaction can go in the next block (locktime <= mtp).
631+ let locktime = MedianTimePast :: from_u32 ( 500_000_000 ) . unwrap ( ) ;
632+ assert ! ( locktime. is_satisfied_by( mtp) ) ;
633+ let locktime = MedianTimePast :: from_u32 ( 500_000_001 ) . unwrap ( ) ;
634+ assert ! ( locktime. is_satisfied_by( mtp) ) ;
635+
636+ // It is not satisfied if the lock time is after the median time past.
637+ let locktime = MedianTimePast :: from_u32 ( 500_000_002 ) . unwrap ( ) ;
638+ assert ! ( !locktime. is_satisfied_by( mtp) ) ;
639+ }
610640}
You can’t perform that action at this time.
0 commit comments