Validation consistency between format & validation modules

The best place to catch share problems is immediately during parsing from
`&str`, however, because `validate_shares` takes any type that implements the
`IsShare` trait, and there's nothing about that trait that guarantees that the
share id, threshold, and secret length will be valid, I thought it best to leave
those three tests in `validate_shares` as a defensive coding practice.
This commit is contained in:
Noah Vesely
2018-03-29 01:22:54 -06:00
committed by Romain Ruetschi
parent 88743caad8
commit 3f215cdb39
3 changed files with 18 additions and 12 deletions

View File

@ -11,6 +11,13 @@ fn test_recover_no_shares() {
}
}
#[test]
#[should_panic(expected = "ShareParsingErrorEmptyShare")]
fn test_share_parsing_error_empty_share() {
let shares = vec!["2-1-".to_string()];
recover_secret(&shares, false).unwrap();
}
#[test]
#[should_panic(expected = "ShareParsingError")]
fn test_recover_2_parts_share() {
@ -34,13 +41,9 @@ fn test_recover_incorrect_share_num() {
}
#[test]
#[should_panic(expected = "ShareParsingError")]
#[should_panic(expected = "ShareParsingInvalidShareId")]
fn test_recover_0_share_num() {
let share1 = "2-0-1YAYwmOHqZ69jA".to_string();
let share2 = "2-1-YJZQDGm22Y77Gw".to_string();
let shares = vec![share1, share2];
let shares = vec!["2-0-1YAYwmOHqZ69jA".to_string()];
recover_secret(&shares, false).unwrap();
}