@@ -719,29 +719,6 @@ mod test {
719719 Ok ( ( ) )
720720 }
721721
722- #[ test]
723- fn test_output_substitution ( ) -> Result < ( ) , BoxError > {
724- let mut ctx = create_psbt_context ( ) ?;
725- let mut proposal = PARSED_PAYJOIN_PROPOSAL . clone ( ) ;
726-
727- ctx. output_substitution = OutputSubstitution :: Disabled ;
728- assert ! ( ctx. clone( ) . process_proposal( proposal. clone( ) ) . is_ok( ) , ) ;
729-
730- std:: mem:: swap (
731- & mut ctx. original_psbt . unsigned_tx . output [ 0 ] . value ,
732- & mut proposal. unsigned_tx . output [ 0 ] . value ,
733- ) ;
734-
735- ctx. original_psbt . unsigned_tx . output [ 0 ] . script_pubkey = ctx. payee . clone ( ) ;
736-
737- assert ! ( matches!(
738- ctx. clone( ) . process_proposal( proposal. clone( ) ) . unwrap_err( ) ,
739- InternalProposalError :: DisallowedOutputSubstitution
740- ) ) ;
741-
742- Ok ( ( ) )
743- }
744-
745722 #[ test]
746723 fn test_payee_output_value_decreased ( ) -> Result < ( ) , BoxError > {
747724 let mut ctx = create_psbt_context ( ) ?;
@@ -1118,12 +1095,23 @@ mod test {
11181095 fn test_process_proposal_when_payee_output_has_disallowed_output_substitution (
11191096 ) -> Result < ( ) , BoxError > {
11201097 let mut ctx = create_psbt_context ( ) ?;
1121- let proposal = PARSED_PAYJOIN_PROPOSAL . clone ( ) ;
1098+ let mut proposal = PARSED_PAYJOIN_PROPOSAL . clone ( ) ;
1099+ ctx. output_substitution = OutputSubstitution :: Disabled ;
1100+
1101+ // When output substitution is disabled ensure that the output value did not decrease
1102+ assert ! ( ctx. clone( ) . process_proposal( proposal. clone( ) ) . is_ok( ) ) ;
1103+
1104+ // When output substitution is disabled still allow increasing the output value
1105+ proposal. unsigned_tx . output [ 0 ] . value += Amount :: from_sat ( 182 ) ;
1106+ assert ! ( ctx. clone( ) . process_proposal( proposal. clone( ) ) . is_ok( ) ) ;
11221107
1108+ proposal. unsigned_tx . output [ 0 ] . value -= Amount :: from_sat ( 182 ) ;
11231109 ctx. original_psbt . unsigned_tx . output . get_mut ( 0 ) . unwrap ( ) . script_pubkey =
11241110 ctx. payee . clone ( ) ;
1125- ctx. output_substitution = OutputSubstitution :: Disabled ;
1126-
1111+ std:: mem:: swap (
1112+ & mut ctx. original_psbt . unsigned_tx . output [ 0 ] . value ,
1113+ & mut proposal. unsigned_tx . output [ 0 ] . value ,
1114+ ) ;
11271115 assert_eq ! (
11281116 ctx. process_proposal( proposal) . unwrap_err( ) . to_string( ) ,
11291117 InternalProposalError :: DisallowedOutputSubstitution . to_string( )
@@ -1132,6 +1120,27 @@ mod test {
11321120 Ok ( ( ) )
11331121 }
11341122
1123+ #[ test]
1124+ fn test_process_proposal_when_payee_output_has_allowed_output_substitution (
1125+ ) -> Result < ( ) , BoxError > {
1126+ let mut ctx = create_psbt_context ( ) ?;
1127+ let mut proposal = PARSED_PAYJOIN_PROPOSAL . clone ( ) ;
1128+
1129+ // Do not make any checks when output substitution is enabled
1130+ ctx. output_substitution = OutputSubstitution :: Enabled ;
1131+ ctx. original_psbt . unsigned_tx . output . get_mut ( 0 ) . unwrap ( ) . script_pubkey =
1132+ ctx. payee . clone ( ) ;
1133+ assert ! ( ctx. clone( ) . process_proposal( proposal. clone( ) ) . is_ok( ) ) ;
1134+
1135+ proposal. unsigned_tx . output [ 0 ] . value += Amount :: from_sat ( 182 ) ;
1136+ assert ! ( ctx. clone( ) . process_proposal( proposal. clone( ) ) . is_ok( ) ) ;
1137+
1138+ proposal. unsigned_tx . output [ 0 ] . value -= Amount :: from_sat ( 364 ) ;
1139+ assert ! ( ctx. process_proposal( proposal) . is_ok( ) ) ;
1140+
1141+ Ok ( ( ) )
1142+ }
1143+
11351144 #[ test]
11361145 fn test_process_proposal_when_output_value_decreased ( ) -> Result < ( ) , BoxError > {
11371146 let mut ctx = create_psbt_context ( ) ?;
0 commit comments