mirror of
https://github.com/mimblewimble/grin.git
synced 2025-02-01 08:51:08 +03:00
[1.1.0] Bring fuzz test back (#2675)
Corpus generation was updated and simplified, plus small updates
This commit is contained in:
parent
a58d671853
commit
16487a3eb7
6 changed files with 1407 additions and 68 deletions
1392
core/fuzz/Cargo.lock
generated
Normal file
1392
core/fuzz/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
|
@ -27,7 +27,7 @@ To run the tests make sure youre in folder `core` otherwise you may get
|
|||
some misleading errors, then run one of the following tests:
|
||||
|
||||
```
|
||||
cargo fuzz run tx_read
|
||||
cargo fuzz run transaction_read
|
||||
|
||||
cargo fuzz run block_read
|
||||
|
||||
|
|
|
@ -3,10 +3,10 @@ extern crate grin_core;
|
|||
#[macro_use]
|
||||
extern crate libfuzzer_sys;
|
||||
|
||||
use grin_core::core::block;
|
||||
use grin_core::core::Block;
|
||||
use grin_core::ser;
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
let mut d = data.clone();
|
||||
let _t: Result<block::Block, ser::Error> = ser::deserialize(&mut d);
|
||||
let _t: Result<Block, ser::Error> = ser::deserialize(&mut d);
|
||||
});
|
||||
|
|
|
@ -3,10 +3,10 @@ extern crate grin_core;
|
|||
#[macro_use]
|
||||
extern crate libfuzzer_sys;
|
||||
|
||||
/*use grin_core::core::block;
|
||||
use grin_core::ser;*/
|
||||
use grin_core::core::CompactBlock;
|
||||
use grin_core::ser;
|
||||
|
||||
fuzz_target!(|_data: &[u8]| {
|
||||
/*let mut d = data.clone();
|
||||
let _t: Result<block::CompactBlock, ser::Error> = ser::deserialize(&mut d);*/
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
let mut d = data.clone();
|
||||
let _t: Result<CompactBlock, ser::Error> = ser::deserialize(&mut d);
|
||||
});
|
||||
|
|
|
@ -3,10 +3,10 @@ extern crate grin_core;
|
|||
#[macro_use]
|
||||
extern crate libfuzzer_sys;
|
||||
|
||||
use grin_core::core::transaction;
|
||||
use grin_core::core::Transaction;
|
||||
use grin_core::ser;
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
let mut d = data.clone();
|
||||
let _t: Result<transaction::Transaction, ser::Error> = ser::deserialize(&mut d);
|
||||
let _t: Result<Transaction, ser::Error> = ser::deserialize(&mut d);
|
||||
});
|
||||
|
|
|
@ -1,25 +1,17 @@
|
|||
extern crate grin_core;
|
||||
extern crate grin_keychain;
|
||||
|
||||
/* These are completely out of date. Commented out until someone attends to them */
|
||||
|
||||
/*use grin_core::core::target::Difficulty;
|
||||
use grin_core::core::{Block, BlockHeader, CompactBlock, Transaction};
|
||||
use grin_core::libtx::build::{input, output, transaction, with_fee};
|
||||
use grin_core::libtx::reward;
|
||||
use grin_core::core::{Block, CompactBlock, Transaction};
|
||||
use grin_core::ser;
|
||||
use grin_keychain::keychain::ExtKeychain;
|
||||
use grin_keychain::Keychain;
|
||||
use std::fs::{self, File};
|
||||
use std::path::Path;*/
|
||||
use std::path::Path;
|
||||
|
||||
fn main() {
|
||||
/*generate("transaction_read", &tx()).unwrap();
|
||||
generate("block_read", &block()).unwrap();
|
||||
generate("compact_block_read", &compact_block()).unwrap();*/
|
||||
generate("transaction_read", Transaction::default()).unwrap();
|
||||
generate("block_read", Block::default()).unwrap();
|
||||
generate("compact_block_read", CompactBlock::from(Block::default())).unwrap();
|
||||
}
|
||||
|
||||
/*
|
||||
fn generate<W: ser::Writeable>(target: &str, obj: W) -> Result<(), ser::Error> {
|
||||
let dir_path = Path::new("corpus").join(target);
|
||||
if !dir_path.is_dir() {
|
||||
|
@ -38,48 +30,3 @@ fn generate<W: ser::Writeable>(target: &str, obj: W) -> Result<(), ser::Error> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn block() -> Block {
|
||||
let keychain = ExtKeychain::from_random_seed().unwrap();
|
||||
let key_id = keychain.derive_key_id(1).unwrap();
|
||||
|
||||
let mut txs = Vec::new();
|
||||
for _ in 1..10 {
|
||||
txs.push(tx());
|
||||
}
|
||||
|
||||
let header = BlockHeader::default();
|
||||
|
||||
let reward = reward::output(&keychain, &key_id, 0, header.height).unwrap();
|
||||
|
||||
Block::new(&header, txs, Difficulty::min(), reward).unwrap()
|
||||
}
|
||||
|
||||
fn compact_block() -> CompactBlock {
|
||||
CompactBlock {
|
||||
header: BlockHeader::default(),
|
||||
nonce: 1,
|
||||
out_full: vec![],
|
||||
kern_full: vec![],
|
||||
kern_ids: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
fn tx() -> Transaction {
|
||||
let keychain = ExtKeychain::from_random_seed().unwrap();
|
||||
let key_id1 = keychain.derive_key_id(1).unwrap();
|
||||
let key_id2 = keychain.derive_key_id(2).unwrap();
|
||||
let key_id3 = keychain.derive_key_id(3).unwrap();
|
||||
|
||||
transaction(
|
||||
vec![
|
||||
input(10, key_id1),
|
||||
input(11, key_id2),
|
||||
output(19, key_id3),
|
||||
with_fee(2),
|
||||
],
|
||||
&keychain,
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue