Skip to content

Commit fec700a

Browse files
committed
Add bip 380 checksum test vectors
Add test vectors from BIP-380 that cover the checksum and character set, both valid and invalid.
1 parent 73f4892 commit fec700a

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/descriptor/checksum.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,4 +221,34 @@ mod test {
221221
format!("Invalid descriptor: Invalid character in checksum: '{}'", sparkle_heart)
222222
);
223223
}
224+
225+
#[test]
226+
fn bip_380_test_vectors_checksum_and_character_set_valid() {
227+
let tcs = vec![
228+
"raw(deadbeef)#89f8spxm", // Valid checksum.
229+
"raw(deadbeef)", // No checksum.
230+
];
231+
for tc in tcs {
232+
if verify_checksum(tc).is_err() {
233+
panic!("false negative: {}", tc)
234+
}
235+
}
236+
}
237+
238+
#[test]
239+
fn bip_380_test_vectors_checksum_and_character_set_invalid() {
240+
let tcs = vec![
241+
"raw(deadbeef)#", // Missing checksum.
242+
"raw(deadbeef)#89f8spxmx", // Too long checksum.
243+
"raw(deadbeef)#89f8spx", // Too short checksum.
244+
"raw(dedbeef)#89f8spxm", // Error in payload.
245+
"raw(deadbeef)##9f8spxm", // Error in checksum.
246+
"raw(Ü)#00000000", // Invalid characters in payload.
247+
];
248+
for tc in tcs {
249+
if verify_checksum(tc).is_ok() {
250+
panic!("false positive: {}", tc)
251+
}
252+
}
253+
}
224254
}

0 commit comments

Comments
 (0)