From fec700a665a08da65bcdb5ddf76d528d5c9366a7 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Thu, 5 Oct 2023 07:56:04 +1100 Subject: [PATCH] Add bip 380 checksum test vectors Add test vectors from BIP-380 that cover the checksum and character set, both valid and invalid. --- src/descriptor/checksum.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/descriptor/checksum.rs b/src/descriptor/checksum.rs index 33602b99e..adb423d00 100644 --- a/src/descriptor/checksum.rs +++ b/src/descriptor/checksum.rs @@ -221,4 +221,34 @@ mod test { format!("Invalid descriptor: Invalid character in checksum: '{}'", sparkle_heart) ); } + + #[test] + fn bip_380_test_vectors_checksum_and_character_set_valid() { + let tcs = vec![ + "raw(deadbeef)#89f8spxm", // Valid checksum. + "raw(deadbeef)", // No checksum. + ]; + for tc in tcs { + if verify_checksum(tc).is_err() { + panic!("false negative: {}", tc) + } + } + } + + #[test] + fn bip_380_test_vectors_checksum_and_character_set_invalid() { + let tcs = vec![ + "raw(deadbeef)#", // Missing checksum. + "raw(deadbeef)#89f8spxmx", // Too long checksum. + "raw(deadbeef)#89f8spx", // Too short checksum. + "raw(dedbeef)#89f8spxm", // Error in payload. + "raw(deadbeef)##9f8spxm", // Error in checksum. + "raw(Ü)#00000000", // Invalid characters in payload. + ]; + for tc in tcs { + if verify_checksum(tc).is_ok() { + panic!("false positive: {}", tc) + } + } + } }