Skip to content

Commit 6fe4bce

Browse files
committed
Merge #366: Actually return the error
4d0e8fb Add unit test SortedMultiVec constructor (Tobin C. Harding) fb932f6 Actually return the error (Tobin C. Harding) Pull request description: 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. ACKs for top commit: apoelstra: ACK 4d0e8fb Tree-SHA512: 7a79b678fb77e092415b78857a5b0bfd2b4cf58382858729f2e6c2d57d8c6b50fabcbe498fd12fee05d9886574a545ad568310df76609fe2eb123af861c4ad14
2 parents 148112c + 4d0e8fb commit 6fe4bce

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

src/descriptor/sortedmulti.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> SortedMultiVec<Pk, Ctx> {
4646
pub fn new(k: usize, pks: Vec<Pk>) -> Result<Self, Error> {
4747
// A sortedmulti() is only defined for <= 20 keys (it maps to CHECKMULTISIG)
4848
if pks.len() > MAX_PUBKEYS_PER_MULTISIG {
49-
Error::BadDescriptor("Too many public keys".to_string());
49+
return Err(Error::BadDescriptor("Too many public keys".to_string()));
5050
}
5151

5252
// Check the limits before creating a new SortedMultiVec
@@ -237,3 +237,34 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> fmt::Display for SortedMultiVec<Pk,
237237
f.write_str(")")
238238
}
239239
}
240+
241+
#[cfg(test)]
242+
mod tests {
243+
use super::*;
244+
use bitcoin::secp256k1::PublicKey;
245+
use miniscript::context::Legacy;
246+
247+
#[test]
248+
fn too_many_pubkeys() {
249+
// Arbitrary pubic key.
250+
let pk = PublicKey::from_str(
251+
"02e6642fd69bd211f93f7f1f36ca51a26a5290eb2dd1b0d8279a87bb0d480c8443",
252+
)
253+
.unwrap();
254+
255+
let over = 1 + MAX_PUBKEYS_PER_MULTISIG;
256+
257+
let mut pks = Vec::new();
258+
for _ in 0..over {
259+
pks.push(pk.clone());
260+
}
261+
262+
let res: Result<SortedMultiVec<PublicKey, Legacy>, Error> = SortedMultiVec::new(0, pks);
263+
let error = res.err().expect("constructor should err");
264+
265+
match error {
266+
Error::BadDescriptor(_) => {} // ok
267+
other => panic!("unexpected error: {:?}", other),
268+
}
269+
}
270+
}

0 commit comments

Comments
 (0)