-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #532 from Chia-Network/node_from_stream_backrefs_o…
…ptimisation Node from stream backrefs optimisation
- Loading branch information
Showing
7 changed files
with
356 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,29 @@ | ||
#![no_main] | ||
|
||
mod node_eq; | ||
|
||
use clvmr::allocator::Allocator; | ||
use clvmr::serde::node_from_bytes_backrefs; | ||
use clvmr::serde::node_to_bytes_backrefs; | ||
use clvmr::serde::node_from_bytes_backrefs_old; | ||
use libfuzzer_sys::fuzz_target; | ||
|
||
fuzz_target!(|data: &[u8]| { | ||
let mut allocator = Allocator::new(); | ||
let program = match node_from_bytes_backrefs(&mut allocator, data) { | ||
Err(_) => { | ||
let res1 = node_from_bytes_backrefs(&mut allocator, data); | ||
let node_count = allocator.pair_count(); | ||
let res2 = node_from_bytes_backrefs_old(&mut allocator, data); | ||
// check that the new implementation creates the same number of pair nodes as the old one | ||
assert_eq!(node_count * 2, allocator.pair_count()); | ||
match (res1, res2) { | ||
(Err(_e1), Err(_e2)) => { | ||
// both failed, that's fine | ||
return; | ||
} | ||
Ok(r) => r, | ||
}; | ||
|
||
let b1 = node_to_bytes_backrefs(&allocator, program).unwrap(); | ||
|
||
let mut allocator = Allocator::new(); | ||
let program = node_from_bytes_backrefs(&mut allocator, &b1).unwrap(); | ||
|
||
let b2 = node_to_bytes_backrefs(&allocator, program).unwrap(); | ||
assert_eq!(b1, b2); | ||
(Ok(n1), Ok(n2)) => { | ||
assert!(node_eq::node_eq(&allocator, n1, n2)); | ||
} | ||
_ => { | ||
panic!("mismatching results"); | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.