Do ext checks after translation.#556
Open
sanket1729 wants to merge 1 commit intorust-bitcoin:masterfrom
Open
Conversation
Also adds some basic tests
Member
|
I think the CI failure is something real, though maybe it means that we need to update the test. |
Member
|
The bug is in the test I believe, just change the match statement in match (ms, valid) {
(Ok(ms), true) => {
assert_eq!(format!("{:x}", ms.encode()), expected_hex);
assert_eq!(ms.ty.mall.non_malleable, non_mal);
assert_eq!(ms.ty.mall.safe, need_sig);
assert_eq!(ms.ext.ops.op_count().unwrap(), ops);
}
(Err(_), false) => {}
(Ok(_), false) => panic!("false positive"),
(Err(_), true) => panic!("false negative"),
} |
Member
|
Here is a refactor of the new unit test I did while debugging if you want it: // Sanity test for `translate_fails_for_duplicate_key`.
#[test]
fn can_translate_different_keys() {
let ms = Miniscript::<String, Segwitv0>::from_str("and_b(pk(A),a:pk(B))").unwrap();
let mut t = StrKeyTranslator::new();
let key0 = bitcoin::PublicKey::from_str(
"0238e6a8035e67d46f2a350f748a9c2dd45ba467f12432e5f9371ca91fb9831086",
).unwrap();
// insecure complement of key0
let key1 = bitcoin::PublicKey::from_str(
"03a8e6a8035e67d46f2a350f748a9c2dd45ba467f12432e5f9371ca91fb9831086",
).unwrap();
t.pk_map.insert(String::from("A"), key0);
t.pk_map.insert(String::from("B"), key1);
ms.translate_pk(&mut t).expect("translation failed");
}
#[test]
fn translate_fails_for_duplicate_key() {
let ms = Miniscript::<String, Segwitv0>::from_str("and_b(pk(A),a:pk(B))").unwrap();
let mut t = StrKeyTranslator::new();
let key = bitcoin::PublicKey::from_str(
"0238e6a8035e67d46f2a350f748a9c2dd45ba467f12432e5f9371ca91fb9831086",
).unwrap();
t.pk_map.insert(String::from("A"), key);
t.pk_map.insert(String::from("B"), key);
match ms.translate_pk(&mut t) {
Err(TranslateErr::OuterError(Error::AnalysisError(AnalysisError::RepeatedPubkeys))) => {},
Err(_) => panic!("Unexpected error"),
Ok(_) => panic!("False positive"),
}
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #238
Also adds some basic tests