@@ -36,12 +36,13 @@ fn parse_descriptor(s: &str) -> (Descriptor<DescriptorPublicKey>, KeyMap) {
3636 . expect ( "failed to parse descriptor" )
3737}
3838
39- // The satisfaction size of a P2WPKH is 108 WU =
40- // 1 (elements in witness) + 1 (OP_PUSH) + 33 (pubkey) + 1 (OP_PUSH) + 72 (signature + sighash).
41- // TODO: tests won't pass with 108 but will with 106.
42- const P2WPKH_FAKE_WITNESS_SIZE : usize = 106 ;
39+ /// The satisfaction size of P2WPKH is 108 WU =
40+ /// 1 (elements in witness) + 1 (size)
41+ /// + 72 (signature + sighash) + 1 (size) + 33 (pubkey).
42+ const P2WPKH_FAKE_PK_SIZE : usize = 72 ;
43+ const P2WPKH_FAKE_SIG_SIZE : usize = 33 ;
4344
44- /// The satisfaction size of a P2PKH is 107 WU =
45+ /// The satisfaction size of P2PKH is 107 =
4546/// 1 (OP_PUSH) + 72 (signature + sighash) + 1 (OP_PUSH) + 33 (pubkey).
4647const P2PKH_FAKE_SCRIPT_SIG_SIZE : usize = 107 ;
4748
@@ -484,7 +485,8 @@ macro_rules! assert_fee_rate {
484485 $(
485486 $( $add_signature ) *
486487 for txin in & mut tx. input {
487- txin. witness. push( [ 0x00 ; P2WPKH_FAKE_WITNESS_SIZE ] ) ; // fake signature
488+ txin. witness. push( [ 0x00 ; P2WPKH_FAKE_SIG_SIZE ] ) ; // sig (72)
489+ txin. witness. push( [ 0x00 ; P2WPKH_FAKE_PK_SIZE ] ) ; // pk (33)
488490 }
489491 ) *
490492
@@ -2776,7 +2778,8 @@ fn test_bump_fee_add_input_change_dust() {
27762778
27772779 let mut tx = psbt. extract_tx ( ) . expect ( "failed to extract tx" ) ;
27782780 for txin in & mut tx. input {
2779- txin. witness . push ( [ 0x00 ; P2WPKH_FAKE_WITNESS_SIZE ] ) ; // to get realistic weight
2781+ txin. witness . push ( [ 0x00 ; P2WPKH_FAKE_SIG_SIZE ] ) ; // sig (72)
2782+ txin. witness . push ( [ 0x00 ; P2WPKH_FAKE_PK_SIZE ] ) ; // pk (33)
27802783 }
27812784 let original_tx_weight = tx. weight ( ) ;
27822785 assert_eq ! ( tx. input. len( ) , 1 ) ;
@@ -2847,7 +2850,8 @@ fn test_bump_fee_force_add_input() {
28472850 let original_sent_received = wallet. sent_and_received ( & tx) ;
28482851 let txid = tx. compute_txid ( ) ;
28492852 for txin in & mut tx. input {
2850- txin. witness . push ( [ 0x00 ; P2WPKH_FAKE_WITNESS_SIZE ] ) ; // fake signature
2853+ txin. witness . push ( [ 0x00 ; P2WPKH_FAKE_SIG_SIZE ] ) ; // sig (72)
2854+ txin. witness . push ( [ 0x00 ; P2WPKH_FAKE_PK_SIZE ] ) ; // pk (33)
28512855 }
28522856 insert_tx ( & mut wallet, tx. clone ( ) ) ;
28532857 // the new fee_rate is low enough that just reducing the change would be fine, but we force
@@ -2910,7 +2914,8 @@ fn test_bump_fee_absolute_force_add_input() {
29102914 let txid = tx. compute_txid ( ) ;
29112915 // skip saving the new utxos, we know they can't be used anyways
29122916 for txin in & mut tx. input {
2913- txin. witness . push ( [ 0x00 ; P2WPKH_FAKE_WITNESS_SIZE ] ) ; // fake signature
2917+ txin. witness . push ( [ 0x00 ; P2WPKH_FAKE_SIG_SIZE ] ) ; // sig (72)
2918+ txin. witness . push ( [ 0x00 ; P2WPKH_FAKE_PK_SIZE ] ) ; // pk (33)
29142919 }
29152920 insert_tx ( & mut wallet, tx. clone ( ) ) ;
29162921
@@ -2980,7 +2985,8 @@ fn test_bump_fee_unconfirmed_inputs_only() {
29802985 let mut tx = psbt. extract_tx ( ) . expect ( "failed to extract tx" ) ;
29812986 let txid = tx. compute_txid ( ) ;
29822987 for txin in & mut tx. input {
2983- txin. witness . push ( [ 0x00 ; P2WPKH_FAKE_WITNESS_SIZE ] ) ; // fake signature
2988+ txin. witness . push ( [ 0x00 ; P2WPKH_FAKE_SIG_SIZE ] ) ; // sig (72)
2989+ txin. witness . push ( [ 0x00 ; P2WPKH_FAKE_PK_SIZE ] ) ; // pk (33)
29842990 }
29852991 insert_tx ( & mut wallet, tx) ;
29862992 let mut builder = wallet. build_fee_bump ( txid) . unwrap ( ) ;
@@ -3008,7 +3014,8 @@ fn test_bump_fee_unconfirmed_input() {
30083014 let mut tx = psbt. extract_tx ( ) . expect ( "failed to extract tx" ) ;
30093015 let txid = tx. compute_txid ( ) ;
30103016 for txin in & mut tx. input {
3011- txin. witness . push ( [ 0x00 ; P2WPKH_FAKE_WITNESS_SIZE ] ) ; // fake signature
3017+ txin. witness . push ( [ 0x00 ; P2WPKH_FAKE_SIG_SIZE ] ) ; // sig (72)
3018+ txin. witness . push ( [ 0x00 ; P2WPKH_FAKE_PK_SIZE ] ) ; // pk (33)
30123019 }
30133020 insert_tx ( & mut wallet, tx) ;
30143021
0 commit comments