@@ -1305,7 +1305,7 @@ mod test {
13051305
13061306 // 1 privkey and 1 pubkey descriptor, 1 private key is required.
13071307 #[ test]
1308- #[ ignore] // see https://github.com/bitcoindevkit/ bdk/issues/225
1308+ #[ ignore = "Policy will be replaced by rust-miniscript in the future, see bdk#255 for context" ]
13091309 fn test_extract_policy_for_sh_multi_complete_1of2 ( ) {
13101310 let secp = Secp256k1 :: new ( ) ;
13111311
@@ -1398,7 +1398,7 @@ mod test {
13981398
13991399 // Single key, 1 privkey and 1 pubkey descriptor, 1 privkey is required.
14001400 #[ test]
1401- #[ ignore] // see https://github.com/bitcoindevkit/ bdk/issues/225
1401+ #[ ignore = "Policy will be replaced by rust-miniscript in the future, see bdk#255 for context" ]
14021402 fn test_extract_policy_for_single_wsh_multi_complete_1of2 ( ) {
14031403 let secp = Secp256k1 :: new ( ) ;
14041404
@@ -1427,9 +1427,8 @@ mod test {
14271427 }
14281428
14291429 // Test ExtractPolicy trait with descriptors containing timelocks in a `thresh()`.
1430-
14311430 #[ test]
1432- #[ ignore] // see https://github.com/bitcoindevkit/ bdk/issues/225
1431+ #[ ignore = "Policy will be replaced by rust-miniscript in the future, see bdk#255 for context" ]
14331432 fn test_extract_policy_for_wsh_multi_timelock ( ) {
14341433 let secp = Secp256k1 :: new ( ) ;
14351434
@@ -1465,10 +1464,8 @@ mod test {
14651464 ) ;
14661465 }
14671466
1468- // Mixed timelocks should fail.
1469-
1467+ // Merging mixed timelocks should fail.
14701468 #[ test]
1471- #[ ignore]
14721469 fn test_extract_policy_for_wsh_mixed_timelocks ( ) {
14731470 let secp = Secp256k1 :: new ( ) ;
14741471 let ( prvkey0, _pubkey0, _fingerprint0) = setup_keys ( TPRV0_STR , PATH , & secp) ;
@@ -1484,57 +1481,69 @@ mod test {
14841481 . into_wallet_descriptor ( & secp, NetworkKind :: Test )
14851482 . unwrap ( ) ;
14861483 let signers_container = Arc :: new ( SignersContainer :: build ( keymap, & wallet_desc, & secp) ) ;
1487- let _policy = wallet_desc
1484+ let policy = wallet_desc
14881485 . extract_policy ( & signers_container, BuildSatisfaction :: None , & secp)
14891486 . unwrap ( )
14901487 . unwrap ( ) ;
1491- // println!("desc policy = {:?}", policy); // TODO remove
1492- // TODO how should this fail with mixed timelocks?
1488+ let policy_condition = policy. get_condition ( & BTreeMap :: new ( ) ) ;
1489+
1490+ assert_eq ! ( policy_condition, Err ( PolicyError :: MixedTimelockUnits ) ) ;
14931491 }
14941492
14951493 // Multiple timelocks of the same type should be correctly merged together.
14961494 #[ test]
1497- #[ ignore]
14981495 fn test_extract_policy_for_multiple_same_timelocks ( ) {
14991496 let secp = Secp256k1 :: new ( ) ;
1497+
1498+ // Merge block-based timelocks: `after(100)` and `after(200)` should yield `after(200)`
15001499 let ( prvkey0, _pubkey0, _fingerprint0) = setup_keys ( TPRV0_STR , PATH , & secp) ;
1501- let locktime_blocks0 = 100 ;
1502- let locktime_blocks1 = 200 ;
1500+ let locktime_blocks_100 = 100 ;
1501+ let locktime_blocks_200 = 200 ;
15031502 let desc = descriptor ! ( sh( and_v(
15041503 v: pk( prvkey0) ,
1505- and_v( v: after( locktime_blocks0 ) , after( locktime_blocks1 ) )
1504+ and_v( v: after( locktime_blocks_100 ) , after( locktime_blocks_200 ) )
15061505 ) ) )
15071506 . unwrap ( ) ;
15081507 let ( wallet_desc, keymap) = desc
15091508 . into_wallet_descriptor ( & secp, NetworkKind :: Test )
15101509 . unwrap ( ) ;
15111510 let signers_container = Arc :: new ( SignersContainer :: build ( keymap, & wallet_desc, & secp) ) ;
1512- let _policy = wallet_desc
1511+ let policy = wallet_desc
15131512 . extract_policy ( & signers_container, BuildSatisfaction :: None , & secp)
15141513 . unwrap ( )
15151514 . unwrap ( ) ;
1516- // println!("desc policy = {:?}", policy); // TODO remove
1517- // TODO how should this merge timelocks?
1518- let ( prvkey1, _pubkey1, _fingerprint1) = setup_keys ( TPRV0_STR , PATH , & secp) ;
1519- let locktime_seconds0 = 500000100 ;
1520- let locktime_seconds1 = 500000200 ;
1515+ let condition = policy. get_condition ( & BTreeMap :: new ( ) ) . unwrap ( ) ;
1516+ assert_eq ! (
1517+ condition. timelock,
1518+ Some ( absolute:: LockTime :: from_height( locktime_blocks_200) . unwrap( ) )
1519+ ) ;
1520+ assert_eq ! ( condition. csv, None ) ;
1521+
1522+ // Merge time-based timelocks: merging
1523+ // `after(500000100)` and `after(500000200)` should yield `after(500000200)`.
1524+ let ( prvkey1, _pubkey1, _fingerprint1) = setup_keys ( TPRV1_STR , PATH , & secp) ;
1525+ let locktime_seconds_offset = 500000000 ;
1526+ let locktime_seconds_100 = locktime_seconds_offset + 100 ;
1527+ let locktime_seconds_200 = locktime_seconds_offset + 200 ;
15211528 let desc = descriptor ! ( sh( and_v(
15221529 v: pk( prvkey1) ,
1523- and_v( v: after( locktime_seconds0 ) , after( locktime_seconds1 ) )
1530+ and_v( v: after( locktime_seconds_100 ) , after( locktime_seconds_200 ) )
15241531 ) ) )
15251532 . unwrap ( ) ;
15261533 let ( wallet_desc, keymap) = desc
15271534 . into_wallet_descriptor ( & secp, NetworkKind :: Test )
15281535 . unwrap ( ) ;
15291536 let signers_container = Arc :: new ( SignersContainer :: build ( keymap, & wallet_desc, & secp) ) ;
1530- let _policy = wallet_desc
1537+ let policy = wallet_desc
15311538 . extract_policy ( & signers_container, BuildSatisfaction :: None , & secp)
15321539 . unwrap ( )
15331540 . unwrap ( ) ;
1534-
1535- // println!("desc policy = {:?}", policy); // TODO remove
1536-
1537- // TODO how should this merge timelocks?
1541+ let condition = policy. get_condition ( & BTreeMap :: new ( ) ) . unwrap ( ) ;
1542+ assert_eq ! (
1543+ condition. timelock,
1544+ Some ( absolute:: LockTime :: from_time( locktime_seconds_200) . unwrap( ) )
1545+ ) ;
1546+ assert_eq ! ( condition. csv, None ) ;
15381547 }
15391548
15401549 #[ test]
0 commit comments