Skip to content

Commit

Permalink
Fix fuzztests
Browse files Browse the repository at this point in the history
  • Loading branch information
sgeisler committed Jul 17, 2019
1 parent 0d87e9d commit a58acbb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions fuzz/fuzz_targets/decode_rnd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use std::str::FromStr;

fn do_test(data: &[u8]) {
let data_str = String::from_utf8_lossy(data);
let decoded = data_str.parse::<bech32::Bech32>();
let decoded = bech32::decode(&data_str);
let b32 = match decoded {
Ok(b32) => b32,
Err(_) => return,
};

assert_eq!(b32.to_string(), data_str);
assert_eq!(bech32::encode(&b32.0, b32.1).unwrap(), data_str);
}

#[cfg(feature = "afl")]
Expand Down
8 changes: 4 additions & 4 deletions fuzz/fuzz_targets/encode_decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ fn do_test(data: &[u8]) {
return;
}

let hrp = String::from_utf8_lossy(&data[1..hrp_end]).to_string();
let hrp = String::from_utf8_lossy(&data[1..hrp_end]).to_lowercase().to_string();

let dp = data[hrp_end..]
.iter()
.map(|b| bech32::u5::try_from_u8(b % 32).unwrap())
.collect::<Vec<_>>();

if let Ok(data_str) = bech32::Bech32::new(hrp, dp).map(|b32| b32.to_string()) {
let decoded = data_str.parse::<bech32::Bech32>();
if let Ok(data_str) = bech32::encode(&hrp, &dp).map(|b32| b32.to_string()) {
let decoded = bech32::decode(&data_str);
let b32 = decoded.expect("should be able to decode own encoding");

assert_eq!(b32.to_string(), data_str);
assert_eq!(bech32::encode(&b32.0, &b32.1).unwrap(), data_str);
}
}

Expand Down

0 comments on commit a58acbb

Please sign in to comment.