Skip to content

Commit

Permalink
Add bip 380 checksum test vectors
Browse files Browse the repository at this point in the history
Add test vectors from BIP-380 that cover the checksum and character set,
both valid and invalid.
  • Loading branch information
tcharding committed Oct 4, 2023
1 parent 73f4892 commit fec700a
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/descriptor/checksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}

0 comments on commit fec700a

Please sign in to comment.