Refactor invalid derivation path tests

Refactor the tests to have the invalid paths in a list, or string.
This commit is contained in:
jamillambert 2025-06-03 11:13:53 +01:00
parent 015fb1be3b
commit ed36a980f8
No known key found for this signature in database
GPG Key ID: 6152B1CE57C49017
1 changed files with 14 additions and 17 deletions

View File

@ -1099,28 +1099,25 @@ mod tests {
#[test]
fn parse_derivation_path_invalid_format() {
let invalid_paths = [
"n/0'/0",
"4/m/5",
"//3/0'",
"0h/0x",
];
for path in &invalid_paths {
assert!(matches!(
"n/0'/0".parse::<DerivationPath>(),
Err(ParseChildNumberError::ParseInt(..)),
));
assert!(matches!(
"4/m/5".parse::<DerivationPath>(),
Err(ParseChildNumberError::ParseInt(..)),
));
assert!(matches!(
"//3/0'".parse::<DerivationPath>(),
Err(ParseChildNumberError::ParseInt(..)),
));
assert!(matches!(
"0h/0x".parse::<DerivationPath>(),
path.parse::<DerivationPath>(),
Err(ParseChildNumberError::ParseInt(..)),
));
}
}
#[test]
fn parse_derivation_path_out_of_range() {
let invalid_path = "2147483648";
assert_eq!(
"2147483648".parse::<DerivationPath>(),
invalid_path.parse::<DerivationPath>(),
Err(ParseChildNumberError::IndexOutOfRange(IndexOutOfRangeError { index: 2147483648 })),
);
}