Skip to content

Commit 8af1b1b

Browse files
committed
fix(test): push P2WPKH's signature and pubkey separately into witness
1 parent c968796 commit 8af1b1b

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

wallet/tests/wallet.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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).
4647
const 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

@@ -2773,7 +2775,8 @@ fn test_bump_fee_add_input_change_dust() {
27732775

27742776
let mut tx = psbt.extract_tx().expect("failed to extract tx");
27752777
for txin in &mut tx.input {
2776-
txin.witness.push([0x00; P2WPKH_FAKE_WITNESS_SIZE]); // to get realistic weight
2778+
txin.witness.push([0x00; P2WPKH_FAKE_SIG_SIZE]); // sig (72)
2779+
txin.witness.push([0x00; P2WPKH_FAKE_PK_SIZE]); // pk (33)
27772780
}
27782781
let original_tx_weight = tx.weight();
27792782
assert_eq!(tx.input.len(), 1);
@@ -2844,7 +2847,8 @@ fn test_bump_fee_force_add_input() {
28442847
let original_sent_received = wallet.sent_and_received(&tx);
28452848
let txid = tx.compute_txid();
28462849
for txin in &mut tx.input {
2847-
txin.witness.push([0x00; P2WPKH_FAKE_WITNESS_SIZE]); // fake signature
2850+
txin.witness.push([0x00; P2WPKH_FAKE_SIG_SIZE]); // sig (72)
2851+
txin.witness.push([0x00; P2WPKH_FAKE_PK_SIZE]); // pk (33)
28482852
}
28492853
insert_tx(&mut wallet, tx.clone());
28502854
// the new fee_rate is low enough that just reducing the change would be fine, but we force
@@ -2907,7 +2911,8 @@ fn test_bump_fee_absolute_force_add_input() {
29072911
let txid = tx.compute_txid();
29082912
// skip saving the new utxos, we know they can't be used anyways
29092913
for txin in &mut tx.input {
2910-
txin.witness.push([0x00; P2WPKH_FAKE_WITNESS_SIZE]); // fake signature
2914+
txin.witness.push([0x00; P2WPKH_FAKE_SIG_SIZE]); // sig (72)
2915+
txin.witness.push([0x00; P2WPKH_FAKE_PK_SIZE]); // pk (33)
29112916
}
29122917
insert_tx(&mut wallet, tx.clone());
29132918

@@ -2977,7 +2982,8 @@ fn test_bump_fee_unconfirmed_inputs_only() {
29772982
let mut tx = psbt.extract_tx().expect("failed to extract tx");
29782983
let txid = tx.compute_txid();
29792984
for txin in &mut tx.input {
2980-
txin.witness.push([0x00; P2WPKH_FAKE_WITNESS_SIZE]); // fake signature
2985+
txin.witness.push([0x00; P2WPKH_FAKE_SIG_SIZE]); // sig (72)
2986+
txin.witness.push([0x00; P2WPKH_FAKE_PK_SIZE]); // pk (33)
29812987
}
29822988
insert_tx(&mut wallet, tx);
29832989
let mut builder = wallet.build_fee_bump(txid).unwrap();
@@ -3005,7 +3011,8 @@ fn test_bump_fee_unconfirmed_input() {
30053011
let mut tx = psbt.extract_tx().expect("failed to extract tx");
30063012
let txid = tx.compute_txid();
30073013
for txin in &mut tx.input {
3008-
txin.witness.push([0x00; P2WPKH_FAKE_WITNESS_SIZE]); // fake signature
3014+
txin.witness.push([0x00; P2WPKH_FAKE_SIG_SIZE]); // sig (72)
3015+
txin.witness.push([0x00; P2WPKH_FAKE_PK_SIZE]); // pk (33)
30093016
}
30103017
insert_tx(&mut wallet, tx);
30113018

0 commit comments

Comments
 (0)