Merge rust-bitcoin/rust-bitcoin#1797: Add predict_weight test for witness address types

8f6317fbab Add predict_weight test for witness address types (yancy)

Pull request description:

  Add a predict_weight test for address types with witness data

ACKs for top commit:
  Kixunil:
    ACK 8f6317fbab
  apoelstra:
    ACK 8f6317fbab

Tree-SHA512: 954908f068d6b0e8f7cc6bc6bffd110d490d7165cf2544ff0f936264761cb1f8e4da1e37fd5a6a34fd8b05f8d72817a3b340bbf968b29c9f538f10853347fdf0
This commit is contained in:
Andrew Poelstra 2023-04-14 14:48:35 +00:00
commit 0af8d45e21
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 30 additions and 0 deletions

View File

@ -1450,6 +1450,36 @@ mod tests {
assert_eq!(raw_tx, &buf[..size]);
}
#[test]
fn predict_weight_all_witness_size() {
// 109
let p2wpkh = InputWeightPrediction::P2WPKH_MAX;
// 66
let p2tr_default = InputWeightPrediction::P2TR_KEY_DEFAULT_SIGHASH;
// 67
let p2tr_non_default = InputWeightPrediction::P2TR_KEY_NON_DEFAULT_SIGHASH;
// 109 + 66 + 67 = 242
let p = vec![p2wpkh, p2tr_default, p2tr_non_default];
let output_script_lens = vec![1];
let w = predict_weight(p, output_script_lens);
// input_weight = partial_input_weight + input_count * 4 * (32 + 4 + 4)
// input_weight = 242 + 3 * 4 * (32 + 4 + 4)
// input_weight = 722
// output_size = 8 * output_count + output_scripts_size
// output_size = 8 * 1 + 2
// output_size = 10
// weight = non_input_size * 4 + input_weight + input_count - inputs_with_witnesses + 2
// weight = 20 * 4 + 722 + 3 - 3 + 2
// weight = 804
assert_eq!(w, Weight::from_wu(804));
}
#[test]
fn test_outpoint() {
assert_eq!(OutPoint::from_str("i don't care"), Err(ParseOutPointError::Format));