Skip to content

Commit 4d0e8fb

Browse files
committed
Add unit test SortedMultiVec constructor
The `SortedMultiVec` constructor appears to have a bug in it, add a unit test to trigger the bug.
1 parent fb932f6 commit 4d0e8fb

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/descriptor/sortedmulti.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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)