From ed36a980f8270db77fd8226037889328a74e1eae Mon Sep 17 00:00:00 2001 From: jamillambert Date: Tue, 3 Jun 2025 11:13:53 +0100 Subject: [PATCH] Refactor invalid derivation path tests Refactor the tests to have the invalid paths in a list, or string. --- bitcoin/src/bip32.rs | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/bitcoin/src/bip32.rs b/bitcoin/src/bip32.rs index 316419ed3..61aacbd3e 100644 --- a/bitcoin/src/bip32.rs +++ b/bitcoin/src/bip32.rs @@ -1099,28 +1099,25 @@ mod tests { #[test] fn parse_derivation_path_invalid_format() { - assert!(matches!( - "n/0'/0".parse::(), - Err(ParseChildNumberError::ParseInt(..)), - )); - assert!(matches!( - "4/m/5".parse::(), - Err(ParseChildNumberError::ParseInt(..)), - )); - assert!(matches!( - "//3/0'".parse::(), - Err(ParseChildNumberError::ParseInt(..)), - )); - assert!(matches!( - "0h/0x".parse::(), - Err(ParseChildNumberError::ParseInt(..)), - )); + let invalid_paths = [ + "n/0'/0", + "4/m/5", + "//3/0'", + "0h/0x", + ]; + for path in &invalid_paths { + assert!(matches!( + path.parse::(), + Err(ParseChildNumberError::ParseInt(..)), + )); + } } #[test] fn parse_derivation_path_out_of_range() { + let invalid_path = "2147483648"; assert_eq!( - "2147483648".parse::(), + invalid_path.parse::(), Err(ParseChildNumberError::IndexOutOfRange(IndexOutOfRangeError { index: 2147483648 })), ); }