Skip to content

Commit

Permalink
Merge etotheipi#33: Update Rust tests
Browse files Browse the repository at this point in the history
af2da22 Add new tests for invalid Bech32 strings (Clark Moody)

Pull request description:

  Similar updates in the vein of etotheipi#27, etotheipi#29, etotheipi#30, etotheipi#31, etotheipi#32

  Adds invalid Bech32 string test cases.

  Please note: Rust strings are UTF-8, so that the character literal `0xff` [turns into](https://codepoints.net/U+00FF) `0xc3bf` when accessed with the `bytes` function.

Tree-SHA512: 73f85762fc22059acb9c4b382068997fb0341354f1de26ecb2d75ba3c57aee80609fd2839967541c9a9f96ccdc04137140174396f5acfe62a6511fd9f18e703e
  • Loading branch information
sipa committed Sep 13, 2017
2 parents fbba4db + af2da22 commit 2528acd
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions ref/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,38 @@ mod tests {
}
}

#[test]
fn invalid_bech32() {
let pairs: Vec<(&str, CodingError)> = vec!(
(" 1nwldj5",
CodingError::InvalidChar),
("\x7f1axkwrx",
CodingError::InvalidChar),
("an84characterslonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1569pvx",
CodingError::InvalidLength),
("pzry9x0s0muk",
CodingError::MissingSeparator),
("1pzry9x0s0muk",
CodingError::InvalidLength),
("x1b4n0q5v",
CodingError::InvalidChar),
("li1dgmt3",
CodingError::InvalidLength),
("de1lg7wt\u{ff}",
CodingError::InvalidChar),
);
for p in pairs {
let (s, expected_error) = p;
let dec_result = bech32::Bech32::from_string(s.to_string());
println!("{:?}", s.to_string());
if dec_result.is_ok() {
println!("{:?}", dec_result.unwrap());
panic!("Should be invalid: {:?}", s);
}
assert_eq!(dec_result.unwrap_err(), expected_error);
}
}

#[test]
fn valid_address() {
let pairs: Vec<(&str, Vec<u8>)> = vec![
Expand Down

0 comments on commit 2528acd

Please sign in to comment.