Merge rust-bitcoin/rust-bitcoin#2828: fuzz: add more coverage for `deserialize_block`

ee30eaa81b fuzz: add more coverage for `deserialize_block` (Bruno Garcia)

Pull request description:

  This PR adds more coverage for the `deserialize_block` target. First, it serializes the block and compares with the data provided and then call some block functions to ensure they run without any issue.

ACKs for top commit:
  apoelstra:
    ACK ee30eaa81b Thanks!

Tree-SHA512: db6c7befa7b429267e9b28fb7910d2b9e8d462e22c791b544b1aa528c7ba4f8e1cd32e1276c67d3da1f97ce484e7ed19ec20b10d2030f2977fd8f855cf510ffe
This commit is contained in:
Andrew Poelstra 2024-06-03 13:15:36 +00:00
commit 741589c5ad
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 15 additions and 1 deletions

View File

@ -1,8 +1,22 @@
use honggfuzz::fuzz; use honggfuzz::fuzz;
fn do_test(data: &[u8]) { fn do_test(data: &[u8]) {
let _: Result<bitcoin::blockdata::block::Block, _> = let block_result: Result<bitcoin::blockdata::block::Block, _> =
bitcoin::consensus::encode::deserialize(data); bitcoin::consensus::encode::deserialize(data);
match block_result {
Err(_) => {}
Ok(block) => {
let ser = bitcoin::consensus::encode::serialize(&block);
assert_eq!(&ser[..], data);
let _ = block.bip34_block_height();
block.block_hash();
block.check_merkle_root();
block.check_witness_commitment();
block.weight();
block.witness_root();
}
}
} }
fn main() { fn main() {