Merge rust-bitcoin/rust-bitcoin#4495: test: Add constructor test

3fbd6fb6b3 test: Add constructor test (yancy)

Pull request description:

  The constructor currently has no test coverage.

ACKs for top commit:
  apoelstra:
    ACK 3fbd6fb6b3c6dc1f1d5c14b3f3486140a781d0f0; successfully ran local tests
  tcharding:
    ACK 3fbd6fb6b3

Tree-SHA512: 9819bd058b84a7b633279d12da48c9af7af765fd8dca5d297787872badc431769c026e57b03bf6d907c89a7b7a5c116cda1be98cb6261dd2a6c331276e627cc3
This commit is contained in:
merge-script 2025-05-13 16:40:00 +00:00
commit 525e1a4d1f
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 56 additions and 0 deletions

View File

@ -1941,6 +1941,62 @@ mod tests {
assert_eq!(weight, Weight::from_wu(2493));
}
#[test]
// needless_borrows_for_generic_args incorrecctly identifies &[] as a needless borrow
#[allow(clippy::needless_borrows_for_generic_args)]
fn weight_prediction_new() {
let p2wpkh_max = InputWeightPrediction::new(0, [72,33]);
assert_eq!(p2wpkh_max.script_size, 1);
assert_eq!(p2wpkh_max.witness_size, 108);
assert_eq!(p2wpkh_max.total_weight(), Weight::from_wu(272));
assert_eq!(p2wpkh_max.total_weight(), InputWeightPrediction::P2WPKH_MAX.total_weight());
let nested_p2wpkh_max = InputWeightPrediction::new(23, [72, 33]);
assert_eq!(nested_p2wpkh_max.script_size, 24);
assert_eq!(nested_p2wpkh_max.witness_size, 108);
assert_eq!(nested_p2wpkh_max.total_weight(), Weight::from_wu(364));
assert_eq!(
nested_p2wpkh_max.total_weight(),
InputWeightPrediction::NESTED_P2WPKH_MAX.total_weight()
);
let p2pkh_compressed_max = InputWeightPrediction::new(107, &[]);
assert_eq!(p2pkh_compressed_max.script_size, 108);
assert_eq!(p2pkh_compressed_max.witness_size, 0);
assert_eq!(p2pkh_compressed_max.total_weight(), Weight::from_wu(592));
assert_eq!(
p2pkh_compressed_max.total_weight(),
InputWeightPrediction::P2PKH_COMPRESSED_MAX.total_weight()
);
let p2pkh_uncompressed_max = InputWeightPrediction::new(139, &[]);
assert_eq!(p2pkh_uncompressed_max.script_size, 140);
assert_eq!(p2pkh_uncompressed_max.witness_size, 0);
assert_eq!(p2pkh_uncompressed_max.total_weight(), Weight::from_wu(720));
assert_eq!(
p2pkh_uncompressed_max.total_weight(),
InputWeightPrediction::P2PKH_UNCOMPRESSED_MAX.total_weight()
);
let p2tr_key_default_sighash = InputWeightPrediction::new(0, [64]);
assert_eq!(p2tr_key_default_sighash.script_size, 1);
assert_eq!(p2tr_key_default_sighash.witness_size, 66);
assert_eq!(p2tr_key_default_sighash.total_weight(), Weight::from_wu(230));
assert_eq!(
p2tr_key_default_sighash.total_weight(),
InputWeightPrediction::P2TR_KEY_DEFAULT_SIGHASH.total_weight()
);
let p2tr_key_non_default_sighash = InputWeightPrediction::new(0, [65]);
assert_eq!(p2tr_key_non_default_sighash.script_size, 1);
assert_eq!(p2tr_key_non_default_sighash.witness_size, 67);
assert_eq!(p2tr_key_non_default_sighash.total_weight(), Weight::from_wu(231));
assert_eq!(
p2tr_key_non_default_sighash.total_weight(),
InputWeightPrediction::P2TR_KEY_NON_DEFAULT_SIGHASH.total_weight()
);
}
#[test]
fn sequence_debug_output() {
let seq = Sequence::from_seconds_floor(1000);