]> Untitled Git - bdk/commitdiff
test(wallet): add check for a tx locktime cltv with timestamp
authorf3r10 <frledesma@outlook.com>
Sat, 21 Dec 2024 21:00:34 +0000 (16:00 -0500)
committerf3r10 <frledesma@outlook.com>
Tue, 21 Jan 2025 21:37:56 +0000 (16:37 -0500)
crates/wallet/src/test_utils.rs
crates/wallet/tests/wallet.rs

index 7ad93e0c376f2649e084a5551f18c16212a881b7..7e1778fab256eefd03bb3fadcd169bc1419a29db 100644 (file)
@@ -160,6 +160,13 @@ pub fn get_test_single_sig_cltv() -> &'static str {
     "wsh(and_v(v:pk(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW),after(100000)))"
 }
 
+/// `wsh` descriptor with policy `and(pk(A),after(1_734_230_218))`
+// the parameter passed to miniscript fragment `after` has to equal or greater than 500_000_000
+// in order to use a lock based on unix time
+pub fn get_test_single_sig_cltv_timestamp() -> &'static str {
+    "wsh(and_v(v:pk(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW),after(1734230218)))"
+}
+
 /// taproot single key descriptor
 pub fn get_test_tr_single_sig() -> &'static str {
     "tr(cNJmN3fH9DDbDt131fQNkVakkpzawJBSeybCUNmP1BovpmGQ45xG)"
index 4fa744ad7923e78fd7de89db7c33bad52e036791..174a628d2508755cbabf394c37e569c53c370974 100644 (file)
@@ -609,6 +609,21 @@ fn test_create_tx_default_locktime_cltv() {
     assert_eq!(psbt.unsigned_tx.lock_time.to_consensus_u32(), 100_000);
 }
 
+#[test]
+fn test_create_tx_locktime_cltv_timestamp() {
+    let (mut wallet, _) = get_funded_wallet_single(get_test_single_sig_cltv_timestamp());
+    let addr = wallet.next_unused_address(KeychainKind::External);
+    let mut builder = wallet.build_tx();
+    builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000));
+    let mut psbt = builder.finish().unwrap();
+
+    assert_eq!(psbt.unsigned_tx.lock_time.to_consensus_u32(), 1_734_230_218);
+
+    let finalized = wallet.sign(&mut psbt, SignOptions::default()).unwrap();
+
+    assert!(finalized);
+}
+
 #[test]
 fn test_create_tx_custom_locktime() {
     let (mut wallet, _) = get_funded_wallet_wpkh();