From fb932f666be3b0dceab7258f5e63ed7aa9951a52 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Fri, 22 Apr 2022 13:08:01 +1000 Subject: [PATCH 1/2] Actually return the error We have what appears to be an error return but do not actually return the error. This line needs an explicit `return` statement otherwise it is a noop. --- src/descriptor/sortedmulti.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/descriptor/sortedmulti.rs b/src/descriptor/sortedmulti.rs index b63b8edcc..2725ecd28 100644 --- a/src/descriptor/sortedmulti.rs +++ b/src/descriptor/sortedmulti.rs @@ -46,7 +46,7 @@ impl SortedMultiVec { pub fn new(k: usize, pks: Vec) -> Result { // A sortedmulti() is only defined for <= 20 keys (it maps to CHECKMULTISIG) if pks.len() > MAX_PUBKEYS_PER_MULTISIG { - Error::BadDescriptor("Too many public keys".to_string()); + return Err(Error::BadDescriptor("Too many public keys".to_string())); } // Check the limits before creating a new SortedMultiVec From 4d0e8fb7692a49dd140fa34711ef53a9f31b357a Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Mon, 25 Apr 2022 16:52:27 +1000 Subject: [PATCH 2/2] Add unit test SortedMultiVec constructor The `SortedMultiVec` constructor appears to have a bug in it, add a unit test to trigger the bug. --- src/descriptor/sortedmulti.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/descriptor/sortedmulti.rs b/src/descriptor/sortedmulti.rs index 2725ecd28..3e21091be 100644 --- a/src/descriptor/sortedmulti.rs +++ b/src/descriptor/sortedmulti.rs @@ -237,3 +237,34 @@ impl fmt::Display for SortedMultiVec, Error> = SortedMultiVec::new(0, pks); + let error = res.err().expect("constructor should err"); + + match error { + Error::BadDescriptor(_) => {} // ok + other => panic!("unexpected error: {:?}", other), + } + } +}