Skip to content

Commit 2c11d46

Browse files
committed
test(wallet): add check for a tx locktime cltv with timestamp
1 parent 7664574 commit 2c11d46

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

crates/wallet/src/test_utils.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@ pub fn get_test_single_sig_cltv() -> &'static str {
160160
"wsh(and_v(v:pk(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW),after(100000)))"
161161
}
162162

163+
/// `wsh` descriptor with policy `and(pk(A),after(1_734_230_218))`
164+
// the parameter passed to miniscript fragment `after` has to equal or greater than 500_000_000
165+
// in order to use a lock based on unix time
166+
pub fn get_test_single_sig_cltv_timestamp() -> &'static str {
167+
"wsh(and_v(v:pk(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW),after(1734230218)))"
168+
}
169+
163170
/// taproot single key descriptor
164171
pub fn get_test_tr_single_sig() -> &'static str {
165172
"tr(cNJmN3fH9DDbDt131fQNkVakkpzawJBSeybCUNmP1BovpmGQ45xG)"

crates/wallet/tests/wallet.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,21 @@ fn test_create_tx_default_locktime_cltv() {
609609
assert_eq!(psbt.unsigned_tx.lock_time.to_consensus_u32(), 100_000);
610610
}
611611

612+
#[test]
613+
fn test_create_tx_locktime_cltv_timestamp() {
614+
let (mut wallet, _) = get_funded_wallet_single(get_test_single_sig_cltv_timestamp());
615+
let addr = wallet.next_unused_address(KeychainKind::External);
616+
let mut builder = wallet.build_tx();
617+
builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000));
618+
let mut psbt = builder.finish().unwrap();
619+
620+
assert_eq!(psbt.unsigned_tx.lock_time.to_consensus_u32(), 1_734_230_218);
621+
622+
let finalized = wallet.sign(&mut psbt, SignOptions::default()).unwrap();
623+
624+
assert!(finalized);
625+
}
626+
612627
#[test]
613628
fn test_create_tx_custom_locktime() {
614629
let (mut wallet, _) = get_funded_wallet_wpkh();

0 commit comments

Comments
 (0)