fuzz: run 'cargo fmt' on all the fuzz targets

This commit is contained in:
Andrew Poelstra 2023-03-22 14:33:50 +00:00
parent 9cfc0fcd81
commit 6e2ee5be66
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
18 changed files with 48 additions and 67 deletions

View File

@ -1,8 +1,8 @@
use honggfuzz::fuzz; use honggfuzz::fuzz;
fn do_test(data: &[u8]) { fn do_test(data: &[u8]) {
let _: Result<bitcoin::network::message::RawNetworkMessage, _> = bitcoin::consensus::encode::deserialize(data); let _: Result<bitcoin::network::message::RawNetworkMessage, _> =
bitcoin::consensus::encode::deserialize(data);
} }
fn main() { fn main() {

View File

@ -1,6 +1,6 @@
use std::str::FromStr;
use honggfuzz::fuzz; use honggfuzz::fuzz;
use std::str::FromStr;
fn do_test(data: &[u8]) { fn do_test(data: &[u8]) {
let data_str = String::from_utf8_lossy(data); let data_str = String::from_utf8_lossy(data);

View File

@ -1,6 +1,6 @@
use std::str::FromStr;
use honggfuzz::fuzz; use honggfuzz::fuzz;
use std::str::FromStr;
fn do_test(data: &[u8]) { fn do_test(data: &[u8]) {
let data_str = String::from_utf8_lossy(data); let data_str = String::from_utf8_lossy(data);

View File

@ -1,8 +1,8 @@
use honggfuzz::fuzz; use honggfuzz::fuzz;
fn do_test(data: &[u8]) { fn do_test(data: &[u8]) {
let _: Result<bitcoin::blockdata::block::Block, _>= bitcoin::consensus::encode::deserialize(data); let _: Result<bitcoin::blockdata::block::Block, _> =
bitcoin::consensus::encode::deserialize(data);
} }
fn main() { fn main() {

View File

@ -1,12 +1,12 @@
use honggfuzz::fuzz; use honggfuzz::fuzz;
fn do_test(data: &[u8]) { fn do_test(data: &[u8]) {
// We already fuzz Transactions in `./deserialize_transaction.rs`. // We already fuzz Transactions in `./deserialize_transaction.rs`.
let tx_result: Result<bitcoin::bip152::PrefilledTransaction, _> = bitcoin::consensus::encode::deserialize(data); let tx_result: Result<bitcoin::bip152::PrefilledTransaction, _> =
bitcoin::consensus::encode::deserialize(data);
match tx_result { match tx_result {
Err(_) => {}, Err(_) => {}
Ok(tx) => { Ok(tx) => {
let ser = bitcoin::consensus::encode::serialize(&tx); let ser = bitcoin::consensus::encode::serialize(&tx);
assert_eq!(&ser[..], data); assert_eq!(&ser[..], data);

View File

@ -1,10 +1,10 @@
use honggfuzz::fuzz; use honggfuzz::fuzz;
fn do_test(data: &[u8]) { fn do_test(data: &[u8]) {
let psbt: Result<bitcoin::psbt::PartiallySignedTransaction, _> = bitcoin::psbt::Psbt::deserialize(data); let psbt: Result<bitcoin::psbt::PartiallySignedTransaction, _> =
bitcoin::psbt::Psbt::deserialize(data);
match psbt { match psbt {
Err(_) => {}, Err(_) => {}
Ok(psbt) => { Ok(psbt) => {
let ser = bitcoin::psbt::Psbt::serialize(&psbt); let ser = bitcoin::psbt::Psbt::serialize(&psbt);
let deser = bitcoin::psbt::Psbt::deserialize(&ser).unwrap(); let deser = bitcoin::psbt::Psbt::deserialize(&ser).unwrap();

View File

@ -1,10 +1,8 @@
use honggfuzz::fuzz;
use bitcoin::address::Address; use bitcoin::address::Address;
use bitcoin::network::constants::Network;
use bitcoin::blockdata::script; use bitcoin::blockdata::script;
use bitcoin::consensus::encode; use bitcoin::consensus::encode;
use bitcoin::network::constants::Network;
use honggfuzz::fuzz;
fn do_test(data: &[u8]) { fn do_test(data: &[u8]) {
let s: Result<script::ScriptBuf, _> = encode::deserialize(data); let s: Result<script::ScriptBuf, _> = encode::deserialize(data);
@ -17,7 +15,9 @@ fn do_test(data: &[u8]) {
return; return;
} }
match ins.ok().unwrap() { match ins.ok().unwrap() {
script::Instruction::Op(op) => { b = b.push_opcode(op); } script::Instruction::Op(op) => {
b = b.push_opcode(op);
}
script::Instruction::PushBytes(bytes) => { script::Instruction::PushBytes(bytes) => {
// Any one-byte pushes, except -0, which can be interpreted as numbers, should be // Any one-byte pushes, except -0, which can be interpreted as numbers, should be
// reserialized as numbers. (For -1 through 16, this will use special ops; for // reserialized as numbers. (For -1 through 16, this will use special ops; for

View File

@ -1,10 +1,10 @@
use honggfuzz::fuzz; use honggfuzz::fuzz;
fn do_test(data: &[u8]) { fn do_test(data: &[u8]) {
let tx_result: Result<bitcoin::blockdata::transaction::Transaction, _> = bitcoin::consensus::encode::deserialize(data); let tx_result: Result<bitcoin::blockdata::transaction::Transaction, _> =
bitcoin::consensus::encode::deserialize(data);
match tx_result { match tx_result {
Err(_) => {}, Err(_) => {}
Ok(mut tx) => { Ok(mut tx) => {
let ser = bitcoin::consensus::encode::serialize(&tx); let ser = bitcoin::consensus::encode::serialize(&tx);
assert_eq!(&ser[..], data); assert_eq!(&ser[..], data);
@ -22,7 +22,7 @@ fn do_test(data: &[u8]) {
} else { } else {
assert_eq!(no_witness_len * 3 + len, calculated_weight); assert_eq!(no_witness_len * 3 + len, calculated_weight);
} }
}, }
} }
} }

View File

@ -1,8 +1,6 @@
use honggfuzz::fuzz;
use bitcoin::consensus::{serialize, deserialize};
use bitcoin::blockdata::witness::Witness; use bitcoin::blockdata::witness::Witness;
use bitcoin::consensus::{deserialize, serialize};
use honggfuzz::fuzz;
fn do_test(data: &[u8]) { fn do_test(data: &[u8]) {
let w: Result<Witness, _> = deserialize(data); let w: Result<Witness, _> = deserialize(data);

View File

@ -1,21 +1,22 @@
use std::str::FromStr;
use honggfuzz::fuzz;
use bitcoin::blockdata::transaction::OutPoint; use bitcoin::blockdata::transaction::OutPoint;
use bitcoin::consensus::encode; use bitcoin::consensus::encode;
use honggfuzz::fuzz;
use std::str::FromStr;
fn do_test(data: &[u8]) { fn do_test(data: &[u8]) {
let lowercase: Vec<u8> = data.iter().map(|c| match *c { let lowercase: Vec<u8> = data
.iter()
.map(|c| match *c {
b'A' => b'a', b'A' => b'a',
b'B' => b'b', b'B' => b'b',
b'C' => b'c', b'C' => b'c',
b'D' => b'd', b'D' => b'd',
b'E' => b'e', b'E' => b'e',
b'F' => b'f', b'F' => b'f',
x => x x => x,
}).collect(); })
.collect();
let data_str = match String::from_utf8(lowercase) { let data_str = match String::from_utf8(lowercase) {
Err(_) => return, Err(_) => return,
Ok(s) => s, Ok(s) => s,
@ -33,7 +34,7 @@ fn do_test(data: &[u8]) {
let string = deser.to_string(); let string = deser.to_string();
match OutPoint::from_str(&string) { match OutPoint::from_str(&string) {
Ok(destring) => assert_eq!(destring, deser), Ok(destring) => assert_eq!(destring, deser),
Err(_) => panic!() Err(_) => panic!(),
} }
} }
} }

View File

@ -1,18 +1,14 @@
use std::fmt;
use honggfuzz::fuzz; use honggfuzz::fuzz;
use std::fmt;
// faster than String, we don't need to actually produce the value, just check absence of panics // faster than String, we don't need to actually produce the value, just check absence of panics
struct NullWriter; struct NullWriter;
impl fmt::Write for NullWriter { impl fmt::Write for NullWriter {
fn write_str(&mut self, _s: &str) -> fmt::Result { fn write_str(&mut self, _s: &str) -> fmt::Result { Ok(()) }
Ok(())
}
fn write_char(&mut self, _c: char) -> fmt::Result { fn write_char(&mut self, _c: char) -> fmt::Result { Ok(()) }
Ok(())
}
} }
fn do_test(data: &[u8]) { fn do_test(data: &[u8]) {

View File

@ -1,6 +1,4 @@
use bitcoin::hashes::{ripemd160, sha1, sha256d, sha512, Hmac};
use bitcoin::hashes::Hmac;
use bitcoin::hashes::{sha1, sha512, ripemd160, sha256d};
use honggfuzz::fuzz; use honggfuzz::fuzz;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View File

@ -1,6 +1,4 @@
use bitcoin::hashes::{ripemd160, sha1, sha256d, sha512, Hmac};
use bitcoin::hashes::Hmac;
use bitcoin::hashes::{sha1, sha512, ripemd160, sha256d};
use honggfuzz::fuzz; use honggfuzz::fuzz;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View File

@ -1,6 +1,4 @@
use bitcoin::hashes::{ripemd160, Hash};
use bitcoin::hashes::Hash;
use bitcoin::hashes::ripemd160;
use crypto::digest::Digest; use crypto::digest::Digest;
use crypto::ripemd160::Ripemd160; use crypto::ripemd160::Ripemd160;
use honggfuzz::fuzz; use honggfuzz::fuzz;

View File

@ -1,6 +1,4 @@
use bitcoin::hashes::{sha1, Hash};
use bitcoin::hashes::Hash;
use bitcoin::hashes::sha1;
use crypto::digest::Digest; use crypto::digest::Digest;
use crypto::sha1::Sha1; use crypto::sha1::Sha1;
use honggfuzz::fuzz; use honggfuzz::fuzz;

View File

@ -1,6 +1,4 @@
use bitcoin::hashes::{sha256, Hash};
use bitcoin::hashes::Hash;
use bitcoin::hashes::sha256;
use crypto::digest::Digest; use crypto::digest::Digest;
use crypto::sha2::Sha256; use crypto::sha2::Sha256;
use honggfuzz::fuzz; use honggfuzz::fuzz;

View File

@ -1,6 +1,4 @@
use bitcoin::hashes::{sha512, Hash};
use bitcoin::hashes::Hash;
use bitcoin::hashes::sha512;
use crypto::digest::Digest; use crypto::digest::Digest;
use crypto::sha2::Sha512; use crypto::sha2::Sha512;
use honggfuzz::fuzz; use honggfuzz::fuzz;

View File

@ -1,6 +1,4 @@
use bitcoin::hashes::{sha512_256, Hash};
use bitcoin::hashes::Hash;
use bitcoin::hashes::sha512_256;
use crypto::digest::Digest; use crypto::digest::Digest;
use crypto::sha2::Sha512Trunc256; use crypto::sha2::Sha512Trunc256;
use honggfuzz::fuzz; use honggfuzz::fuzz;