Skip to content

Commit 0af8d45

Browse files
committed
Merge rust-bitcoin#1797: Add predict_weight test for witness address types
8f6317f 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 8f6317f apoelstra: ACK 8f6317f Tree-SHA512: 954908f068d6b0e8f7cc6bc6bffd110d490d7165cf2544ff0f936264761cb1f8e4da1e37fd5a6a34fd8b05f8d72817a3b340bbf968b29c9f538f10853347fdf0
2 parents 3795f60 + 8f6317f commit 0af8d45

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

bitcoin/src/blockdata/transaction.rs

+30
Original file line numberDiff line numberDiff line change
@@ -1450,6 +1450,36 @@ mod tests {
14501450
assert_eq!(raw_tx, &buf[..size]);
14511451
}
14521452

1453+
#[test]
1454+
fn predict_weight_all_witness_size() {
1455+
// 109
1456+
let p2wpkh = InputWeightPrediction::P2WPKH_MAX;
1457+
1458+
// 66
1459+
let p2tr_default = InputWeightPrediction::P2TR_KEY_DEFAULT_SIGHASH;
1460+
1461+
// 67
1462+
let p2tr_non_default = InputWeightPrediction::P2TR_KEY_NON_DEFAULT_SIGHASH;
1463+
1464+
// 109 + 66 + 67 = 242
1465+
let p = vec![p2wpkh, p2tr_default, p2tr_non_default];
1466+
let output_script_lens = vec![1];
1467+
let w = predict_weight(p, output_script_lens);
1468+
1469+
// input_weight = partial_input_weight + input_count * 4 * (32 + 4 + 4)
1470+
// input_weight = 242 + 3 * 4 * (32 + 4 + 4)
1471+
// input_weight = 722
1472+
1473+
// output_size = 8 * output_count + output_scripts_size
1474+
// output_size = 8 * 1 + 2
1475+
// output_size = 10
1476+
1477+
// weight = non_input_size * 4 + input_weight + input_count - inputs_with_witnesses + 2
1478+
// weight = 20 * 4 + 722 + 3 - 3 + 2
1479+
// weight = 804
1480+
assert_eq!(w, Weight::from_wu(804));
1481+
}
1482+
14531483
#[test]
14541484
fn test_outpoint() {
14551485
assert_eq!(OutPoint::from_str("i don't care"), Err(ParseOutPointError::Format));

0 commit comments

Comments
 (0)