@@ -287,7 +287,7 @@ fn insert_tx_displaces_txouts() {
287287}
288288
289289#[ test]
290- fn insert_signed_tx_displaces_unsigned ( ) {
290+ fn insert_tx_witness_precedence ( ) {
291291 let previous_output = OutPoint :: new ( hash ! ( "prev" ) , 2 ) ;
292292 let unsigned_tx = Transaction {
293293 version : transaction:: Version :: ONE ,
@@ -352,6 +352,67 @@ fn insert_signed_tx_displaces_unsigned() {
352352 ) ;
353353 assert ! ( changeset_insert_unsigned. is_empty( ) ) ;
354354 }
355+
356+ // Smaller witness displaces larger witness and witnesses must not get cleared.
357+ {
358+ let previous_output_2 = OutPoint :: new ( hash ! ( "prev" ) , 3 ) ;
359+ let small_wit = Witness :: from_slice ( & [ vec ! [ 0u8 ; 10 ] ] ) ;
360+ let large_wit = Witness :: from_slice ( & [ vec ! [ 0u8 ; 20 ] ] ) ;
361+ let other_wit = Witness :: from_slice ( & [ vec ! [ 0u8 ; 21 ] ] ) ;
362+ let tx_small = Transaction {
363+ input : vec ! [
364+ TxIn {
365+ previous_output,
366+ sequence: transaction:: Sequence :: ENABLE_RBF_NO_LOCKTIME ,
367+ witness: small_wit. clone( ) ,
368+ ..Default :: default ( )
369+ } ,
370+ TxIn {
371+ previous_output: previous_output_2,
372+ sequence: transaction:: Sequence :: ENABLE_RBF_NO_LOCKTIME ,
373+ witness: other_wit,
374+ ..Default :: default ( )
375+ } ,
376+ ] ,
377+ ..unsigned_tx. clone ( )
378+ } ;
379+ let tx_large = Transaction {
380+ input : vec ! [
381+ // This input has a larger witness than the previous, so we expect that the witness
382+ // for this input does not get replaced.
383+ TxIn {
384+ previous_output,
385+ sequence: transaction:: Sequence :: ENABLE_RBF_NO_LOCKTIME ,
386+ witness: large_wit. clone( ) ,
387+ ..Default :: default ( )
388+ } ,
389+ // This input has no witness, so we expect that the witness for this input does not
390+ // get replaced either.
391+ TxIn {
392+ previous_output: previous_output_2,
393+ sequence: transaction:: Sequence :: ENABLE_RBF_NO_LOCKTIME ,
394+ ..Default :: default ( )
395+ } ,
396+ ] ,
397+ ..unsigned_tx. clone ( )
398+ } ;
399+
400+ let mut tx_graph = TxGraph :: < ConfirmationBlockTime > :: default ( ) ;
401+ let changeset_small = tx_graph. insert_tx ( tx_small. clone ( ) ) ;
402+ let changeset_large = tx_graph. insert_tx ( tx_large) ;
403+ assert_eq ! (
404+ changeset_small,
405+ ChangeSet {
406+ txs: [ Arc :: new( tx_small. clone( ) ) ] . into( ) ,
407+ ..Default :: default ( )
408+ }
409+ ) ;
410+ assert ! ( changeset_large. is_empty( ) ) ;
411+ let tx = tx_graph
412+ . get_tx ( tx_small. compute_txid ( ) )
413+ . expect ( "tx must exist" ) ;
414+ assert_eq ! ( tx. as_ref( ) . clone( ) , tx_small, "tx must not have changed" ) ;
415+ }
355416}
356417
357418#[ test]
0 commit comments