From 8e2422f92bcc8f7b8264d262c166826afe8a93ca Mon Sep 17 00:00:00 2001 From: Tobin Harding Date: Fri, 25 Feb 2022 10:07:49 +0000 Subject: [PATCH] Add unit test for deserialize non-standard sighash It is possible, although not immediately obvious, that it is possible to create a `PsbtSigHashType` with a non-standard value. Add a unit test to show this and also catch any regressions if we accidental change this logic. --- src/util/psbt/serialize.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/util/psbt/serialize.rs b/src/util/psbt/serialize.rs index 8492e8af..bb1443a5 100644 --- a/src/util/psbt/serialize.rs +++ b/src/util/psbt/serialize.rs @@ -367,3 +367,15 @@ impl Deserialize for TapTree { fn key_source_len(key_source: &KeySource) -> usize { 4 + 4 * (key_source.1).as_ref().len() } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn can_deserialize_non_standard_psbt_sig_hash_type() { + let non_standard_sighash = [222u8, 0u8, 0u8, 0u8]; // 32 byte value. + let sighash = PsbtSigHashType::deserialize(&non_standard_sighash); + assert!(sighash.is_ok()) + } +}