File tree 1 file changed +30
-0
lines changed
1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -1450,6 +1450,36 @@ mod tests {
1450
1450
assert_eq ! ( raw_tx, & buf[ ..size] ) ;
1451
1451
}
1452
1452
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
+
1453
1483
#[ test]
1454
1484
fn test_outpoint ( ) {
1455
1485
assert_eq ! ( OutPoint :: from_str( "i don't care" ) , Err ( ParseOutPointError :: Format ) ) ;
You can’t perform that action at this time.
0 commit comments