@@ -219,10 +219,8 @@ mod tests {
219219 // If we have a bogus input amount or outputs valued more than inputs, we should fail
220220 let version = Version :: TWO ;
221221 let lock_time = LockTime :: ZERO ;
222- let input = Vec :: new ( ) ;
223222 let tx_out = TxOut { script_pubkey : ScriptBuf :: new ( ) , value : Amount :: from_sat ( 1000 ) } ;
224- let output = vec ! [ tx_out] ;
225- let mut tx = Transaction { version, lock_time, input, output } ;
223+ let mut tx = Transaction { version, lock_time, input : Vec :: new ( ) , output : vec ! [ tx_out] } ;
226224 let amount = Amount :: from_sat ( 21_000_000_0000_0001 ) ;
227225 assert ! ( maybe_add_change_output( & mut tx, amount, 0 , 253 , ScriptBuf :: new( ) ) . is_err( ) ) ;
228226 let amount = Amount :: from_sat ( 400 ) ;
@@ -294,36 +292,32 @@ mod tests {
294292 let tx_in = TxIn { previous_output, script_sig, witness, sequence } ;
295293 let version = Version :: TWO ;
296294 let lock_time = LockTime :: ZERO ;
297- let input = vec ! [ tx_in] ;
298- let output = vec ! [ tx_out] ;
299- let mut tx = Transaction { version, lock_time, input, output } ;
295+ let mut tx = Transaction { version, lock_time, input : vec ! [ tx_in] , output : vec ! [ tx_out] } ;
300296 let orig_wtxid = tx. compute_wtxid ( ) ;
301297 let orig_weight = tx. weight ( ) . to_wu ( ) ;
302298 assert_eq ! ( orig_weight / 4 , 61 ) ;
303299
304300 assert_eq ! ( Builder :: new( ) . push_int( 2 ) . into_script( ) . minimal_non_dust( ) . to_sat( ) , 474 ) ;
305301
302+ let script = Builder :: new ( ) . push_int ( 2 ) . into_script ( ) ;
303+
306304 // Input value of the output value + fee - 1 should fail:
307305 let amount = Amount :: from_sat ( 1000 + 61 + 100 - 1 ) ;
308- let script = Builder :: new ( ) . push_int ( 2 ) . into_script ( ) ;
309- assert ! ( maybe_add_change_output( & mut tx, amount, 400 , 250 , script) . is_err( ) ) ;
306+ assert ! ( maybe_add_change_output( & mut tx, amount, 400 , 250 , script. clone( ) ) . is_err( ) ) ;
310307 // Failure doesn't change the transaction
311308 assert_eq ! ( tx. compute_wtxid( ) , orig_wtxid) ;
312309 // but one more input sat should succeed, without changing the transaction
313310 let amount = Amount :: from_sat ( 1000 + 61 + 100 ) ;
314- let script = Builder :: new ( ) . push_int ( 2 ) . into_script ( ) ;
315- assert ! ( maybe_add_change_output( & mut tx, amount, 400 , 250 , script) . is_ok( ) ) ;
311+ assert ! ( maybe_add_change_output( & mut tx, amount, 400 , 250 , script. clone( ) ) . is_ok( ) ) ;
316312 // If we don't add an output, we don't change the transaction
317313 assert_eq ! ( tx. compute_wtxid( ) , orig_wtxid) ;
318314 // In order to get a change output, we need to add 474 plus the output's weight / 4 (10)...
319315 let amount = Amount :: from_sat ( 1000 + 61 + 100 + 474 + 9 ) ;
320- let script = Builder :: new ( ) . push_int ( 2 ) . into_script ( ) ;
321- assert ! ( maybe_add_change_output( & mut tx, amount, 400 , 250 , script) . is_ok( ) ) ;
316+ assert ! ( maybe_add_change_output( & mut tx, amount, 400 , 250 , script. clone( ) ) . is_ok( ) ) ;
322317 // If we don't add an output, we don't change the transaction
323318 assert_eq ! ( tx. compute_wtxid( ) , orig_wtxid) ;
324319
325320 let amount = Amount :: from_sat ( 1000 + 61 + 100 + 474 + 10 ) ;
326- let script = Builder :: new ( ) . push_int ( 2 ) . into_script ( ) ;
327321 assert ! ( maybe_add_change_output( & mut tx, amount, 400 , 250 , script) . is_ok( ) ) ;
328322 assert_eq ! ( tx. output. len( ) , 2 ) ;
329323 assert_eq ! ( tx. output[ 1 ] . value. to_sat( ) , 474 ) ;
0 commit comments