@@ -144,6 +144,72 @@ fn test_create_psbt_cltv() {
144144 }
145145}
146146
147+ #[ test]
148+ fn test_create_psbt_csv ( ) {
149+ use bitcoin:: relative;
150+ use bitcoin:: Sequence ;
151+
152+ let desc = get_test_single_sig_csv ( ) ;
153+ let mut wallet = Wallet :: create_single ( desc)
154+ . network ( Network :: Regtest )
155+ . create_wallet_no_persist ( )
156+ . unwrap ( ) ;
157+
158+ // Receive coins
159+ let anchor = ConfirmationBlockTime {
160+ block_id : BlockId {
161+ height : 10_000 ,
162+ hash : Hash :: hash ( b"abc" ) ,
163+ } ,
164+ confirmation_time : 1234567000 ,
165+ } ;
166+ insert_checkpoint ( & mut wallet, anchor. block_id ) ;
167+ let op = receive_output ( & mut wallet, Amount :: ONE_BTC , ReceiveTo :: Block ( anchor) ) ;
168+
169+ let addr = wallet. reveal_next_address ( KeychainKind :: External ) ;
170+
171+ // No assets fail
172+ {
173+ let mut params = PsbtParams :: default ( ) ;
174+ params
175+ . add_utxos ( & [ op] )
176+ . add_recipients ( [ ( addr. script_pubkey ( ) , Amount :: from_btc ( 0.42 ) . unwrap ( ) ) ] ) ;
177+ let res = wallet. create_psbt ( params) ;
178+ assert ! (
179+ matches!( res, Err ( CreatePsbtError :: Plan ( err) ) if err == op) ,
180+ "UTXO requires CSV but the assets are insufficient" ,
181+ ) ;
182+ }
183+
184+ // Add assets ok
185+ {
186+ let mut params = PsbtParams :: default ( ) ;
187+ let rel_locktime = relative:: LockTime :: from_consensus ( 6 ) . unwrap ( ) ;
188+ params
189+ . add_utxos ( & [ op] )
190+ . add_assets ( Assets :: new ( ) . older ( rel_locktime) )
191+ . add_recipients ( [ ( addr. script_pubkey ( ) , Amount :: from_btc ( 0.42 ) . unwrap ( ) ) ] ) ;
192+ let ( psbt, _) = wallet. create_psbt ( params) . unwrap ( ) ;
193+ assert_eq ! ( psbt. unsigned_tx. input[ 0 ] . sequence, Sequence ( 6 ) ) ;
194+ }
195+
196+ // Add 6 confirmations (no assets)
197+ {
198+ let anchor = ConfirmationBlockTime {
199+ block_id : BlockId {
200+ height : 10_005 ,
201+ hash : Hash :: hash ( b"xyz" ) ,
202+ } ,
203+ confirmation_time : 1234567000 ,
204+ } ;
205+ insert_checkpoint ( & mut wallet, anchor. block_id ) ;
206+ let mut params = PsbtParams :: default ( ) ;
207+ params. add_recipients ( [ ( addr. script_pubkey ( ) , Amount :: from_btc ( 0.42 ) . unwrap ( ) ) ] ) ;
208+ let ( psbt, _) = wallet. create_psbt ( params) . unwrap ( ) ;
209+ assert_eq ! ( psbt. unsigned_tx. input[ 0 ] . sequence, Sequence ( 6 ) ) ;
210+ }
211+ }
212+
147213// Test that replacing two unconfirmed txs A, B results in a transaction
148214// that spends the inputs of both A and B.
149215#[ test]
0 commit comments