-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathparse_human.rs
More file actions
39 lines (31 loc) · 910 Bytes
/
parse_human.rs
File metadata and controls
39 lines (31 loc) · 910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// SPDX-License-Identifier: CC0-1.0
#![cfg_attr(fuzzing, no_main)]
#[cfg(any(fuzzing, test))]
fn do_test(data: &[u8]) {
use simplicity::human_encoding::Forest;
use simplicity::jet::ElementsTxEnv;
let s = match std::str::from_utf8(data) {
Ok(s) => s,
Err(_) => return,
};
if let Ok(program) = Forest::parse::<ElementsTxEnv>(s) {
let reserialize = program.string_serialize();
let round_trip = Forest::parse::<ElementsTxEnv>(&reserialize).unwrap();
assert_eq!(program, round_trip);
}
}
#[cfg(fuzzing)]
libfuzzer_sys::fuzz_target!(|data| do_test(data));
#[cfg(not(fuzzing))]
fn main() {}
#[cfg(test)]
mod tests {
use base64::Engine;
#[test]
fn duplicate_crash() {
let data = base64::prelude::BASE64_STANDARD
.decode("Cg==")
.expect("base64 should be valid");
super::do_test(&data);
}
}