Skip to content

Commit 01f6832

Browse files
committed
fix(test): push P2WPKH's signature and pubkey separately into witness
1 parent a1d58c3 commit 01f6832

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

@@ -488,7 +489,8 @@ macro_rules! assert_fee_rate {
488489
$(
489490
$( $add_signature )*
490491
for txin in &mut tx.input {
491-
txin.witness.push([0x00; P2WPKH_FAKE_WITNESS_SIZE]); // fake signature
492+
txin.witness.push([0x00; P2WPKH_FAKE_SIG_SIZE]); // sig (72)
493+
txin.witness.push([0x00; P2WPKH_FAKE_PK_SIZE]); // pk (33)
492494
}
493495
)*
494496

@@ -2777,7 +2779,8 @@ fn test_bump_fee_add_input_change_dust() {
27772779

27782780
let mut tx = psbt.extract_tx().expect("failed to extract tx");
27792781
for txin in &mut tx.input {
2780-
txin.witness.push([0x00; P2WPKH_FAKE_WITNESS_SIZE]); // to get realistic weight
2782+
txin.witness.push([0x00; P2WPKH_FAKE_SIG_SIZE]); // sig (72)
2783+
txin.witness.push([0x00; P2WPKH_FAKE_PK_SIZE]); // pk (33)
27812784
}
27822785
let original_tx_weight = tx.weight();
27832786
assert_eq!(tx.input.len(), 1);
@@ -2848,7 +2851,8 @@ fn test_bump_fee_force_add_input() {
28482851
let original_sent_received = wallet.sent_and_received(&tx);
28492852
let txid = tx.compute_txid();
28502853
for txin in &mut tx.input {
2851-
txin.witness.push([0x00; P2WPKH_FAKE_WITNESS_SIZE]); // fake signature
2854+
txin.witness.push([0x00; P2WPKH_FAKE_SIG_SIZE]); // sig (72)
2855+
txin.witness.push([0x00; P2WPKH_FAKE_PK_SIZE]); // pk (33)
28522856
}
28532857
insert_tx(&mut wallet, tx.clone());
28542858
// the new fee_rate is low enough that just reducing the change would be fine, but we force
@@ -2911,7 +2915,8 @@ fn test_bump_fee_absolute_force_add_input() {
29112915
let txid = tx.compute_txid();
29122916
// skip saving the new utxos, we know they can't be used anyways
29132917
for txin in &mut tx.input {
2914-
txin.witness.push([0x00; P2WPKH_FAKE_WITNESS_SIZE]); // fake signature
2918+
txin.witness.push([0x00; P2WPKH_FAKE_SIG_SIZE]); // sig (72)
2919+
txin.witness.push([0x00; P2WPKH_FAKE_PK_SIZE]); // pk (33)
29152920
}
29162921
insert_tx(&mut wallet, tx.clone());
29172922

@@ -2981,7 +2986,8 @@ fn test_bump_fee_unconfirmed_inputs_only() {
29812986
let mut tx = psbt.extract_tx().expect("failed to extract tx");
29822987
let txid = tx.compute_txid();
29832988
for txin in &mut tx.input {
2984-
txin.witness.push([0x00; P2WPKH_FAKE_WITNESS_SIZE]); // fake signature
2989+
txin.witness.push([0x00; P2WPKH_FAKE_SIG_SIZE]); // sig (72)
2990+
txin.witness.push([0x00; P2WPKH_FAKE_PK_SIZE]); // pk (33)
29852991
}
29862992
insert_tx(&mut wallet, tx);
29872993
let mut builder = wallet.build_fee_bump(txid).unwrap();
@@ -3009,7 +3015,8 @@ fn test_bump_fee_unconfirmed_input() {
30093015
let mut tx = psbt.extract_tx().expect("failed to extract tx");
30103016
let txid = tx.compute_txid();
30113017
for txin in &mut tx.input {
3012-
txin.witness.push([0x00; P2WPKH_FAKE_WITNESS_SIZE]); // fake signature
3018+
txin.witness.push([0x00; P2WPKH_FAKE_SIG_SIZE]); // sig (72)
3019+
txin.witness.push([0x00; P2WPKH_FAKE_PK_SIZE]); // pk (33)
30133020
}
30143021
insert_tx(&mut wallet, tx);
30153022

0 commit comments

Comments
 (0)