mirror of
https://github.com/mimblewimble/grin.git
synced 2025-02-01 17:01:09 +03:00
Update fuzz in core crate
Fix compilation error in fuzz code after the wallet refactoring
This commit is contained in:
parent
328d832bd6
commit
32662a0a16
3 changed files with 34 additions and 18 deletions
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "grin_core-fuzz"
|
name = "grin_core-fuzz"
|
||||||
version = "0.0.1"
|
version = "0.0.3"
|
||||||
authors = ["Grin Developers <mimblewimble@lists.launchpad.net>"]
|
authors = ["Grin Developers <mimblewimble@lists.launchpad.net>"]
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
|
@ -10,7 +10,9 @@ cargo-fuzz = true
|
||||||
[dependencies]
|
[dependencies]
|
||||||
grin_core = { path = ".."}
|
grin_core = { path = ".."}
|
||||||
grin_keychain = { path = "../../keychain"}
|
grin_keychain = { path = "../../keychain"}
|
||||||
libfuzzer-sys = { git = "https://github.com/rust-fuzz/libfuzzer-sys.git" }
|
grin_wallet = { path = "../../wallet"}
|
||||||
|
[dependencies.libfuzzer-sys]
|
||||||
|
git = "https://github.com/rust-fuzz/libfuzzer-sys.git"
|
||||||
|
|
||||||
# Prevent this from interfering with workspaces
|
# Prevent this from interfering with workspaces
|
||||||
[workspace]
|
[workspace]
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# Fuzz testing
|
# Fuzz testing
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
You have to use Rust nightly at the moment.
|
||||||
Cargo-fuzz (https://github.com/rust-fuzz/cargo-fuzz) has been used.
|
Cargo-fuzz (https://github.com/rust-fuzz/cargo-fuzz) has been used.
|
||||||
To install it:
|
To install it:
|
||||||
|
|
||||||
|
@ -24,6 +25,7 @@ Fuzz test is basically infinite test, run it for some period of time then
|
||||||
stop if no failures are found.
|
stop if no failures are found.
|
||||||
To run the tests make sure youre in folder `core` otherwise you may get
|
To run the tests make sure youre in folder `core` otherwise you may get
|
||||||
some misleading errors, then run one of the following tests:
|
some misleading errors, then run one of the following tests:
|
||||||
|
|
||||||
```
|
```
|
||||||
cargo fuzz run tx_read
|
cargo fuzz run tx_read
|
||||||
|
|
||||||
|
@ -32,4 +34,9 @@ cargo fuzz run block_read
|
||||||
cargo fuzz run compact_block_read
|
cargo fuzz run compact_block_read
|
||||||
|
|
||||||
```
|
```
|
||||||
Check `fuzz/Cargo.toml` for the full list of targets.
|
|
||||||
|
Run
|
||||||
|
```
|
||||||
|
cargo fuzz list
|
||||||
|
```
|
||||||
|
or check `fuzz/Cargo.toml` for the full list of targets.
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
extern crate grin_core;
|
extern crate grin_core;
|
||||||
extern crate grin_keychain;
|
extern crate grin_keychain;
|
||||||
|
extern crate grin_wallet;
|
||||||
|
|
||||||
use grin_core::core::build::{input, output, transaction_with_offset, with_fee};
|
|
||||||
use grin_core::core::target::Difficulty;
|
use grin_core::core::target::Difficulty;
|
||||||
use grin_core::core::{Block, BlockHeader, CompactBlock, Transaction};
|
use grin_core::core::{Block, BlockHeader, CompactBlock, Transaction};
|
||||||
use grin_core::ser;
|
use grin_core::ser;
|
||||||
use grin_keychain::keychain::Keychain;
|
use grin_keychain::keychain::ExtKeychain;
|
||||||
|
use grin_keychain::Keychain;
|
||||||
|
use grin_wallet::libtx::build::{input, output, transaction_with_offset, with_fee};
|
||||||
|
use grin_wallet::libtx::reward;
|
||||||
use std::fs::{self, File};
|
use std::fs::{self, File};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
|
@ -18,12 +21,16 @@ fn main() {
|
||||||
fn generate<W: ser::Writeable>(target: &str, obj: W) -> Result<(), ser::Error> {
|
fn generate<W: ser::Writeable>(target: &str, obj: W) -> Result<(), ser::Error> {
|
||||||
let dir_path = Path::new("corpus").join(target);
|
let dir_path = Path::new("corpus").join(target);
|
||||||
if !dir_path.is_dir() {
|
if !dir_path.is_dir() {
|
||||||
fs::create_dir(&dir_path).map_err(|e| ser::Error::IOErr(e))?;
|
fs::create_dir_all(&dir_path).map_err(|e| {
|
||||||
|
println!("fail: {}", e);
|
||||||
|
ser::Error::IOErr("can't create corpus directory".to_owned(), e.kind())
|
||||||
|
})?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let pattern_path = dir_path.join("pattern");
|
let pattern_path = dir_path.join("pattern");
|
||||||
if !pattern_path.exists() {
|
if !pattern_path.exists() {
|
||||||
let mut file = File::create(&pattern_path).map_err(|e| ser::Error::IOErr(e))?;
|
let mut file = File::create(&pattern_path)
|
||||||
|
.map_err(|e| ser::Error::IOErr("can't create a pattern file".to_owned(), e.kind()))?;
|
||||||
ser::serialize(&mut file, &obj)
|
ser::serialize(&mut file, &obj)
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -31,19 +38,19 @@ fn generate<W: ser::Writeable>(target: &str, obj: W) -> Result<(), ser::Error> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn block() -> Block {
|
fn block() -> Block {
|
||||||
let keychain = Keychain::from_random_seed().unwrap();
|
let keychain = ExtKeychain::from_random_seed().unwrap();
|
||||||
let key_id = keychain.derive_key_id(1).unwrap();
|
let key_id = keychain.derive_key_id(1).unwrap();
|
||||||
|
|
||||||
let mut tx1 = tx();
|
let mut txs = Vec::new();
|
||||||
let mut tx2 = tx();
|
for _ in 1..10 {
|
||||||
|
txs.push(tx());
|
||||||
|
}
|
||||||
|
|
||||||
Block::new(
|
let header = BlockHeader::default();
|
||||||
&BlockHeader::default(),
|
|
||||||
vec![&mut tx1, &mut tx2],
|
let reward = reward::output(&keychain, &key_id, 0, header.height).unwrap();
|
||||||
&keychain,
|
|
||||||
&key_id,
|
Block::new(&header, txs, Difficulty::one(), reward).unwrap()
|
||||||
Difficulty::one(),
|
|
||||||
).unwrap()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compact_block() -> CompactBlock {
|
fn compact_block() -> CompactBlock {
|
||||||
|
@ -57,7 +64,7 @@ fn compact_block() -> CompactBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tx() -> Transaction {
|
fn tx() -> Transaction {
|
||||||
let keychain = Keychain::from_random_seed().unwrap();
|
let keychain = ExtKeychain::from_random_seed().unwrap();
|
||||||
let key_id1 = keychain.derive_key_id(1).unwrap();
|
let key_id1 = keychain.derive_key_id(1).unwrap();
|
||||||
let key_id2 = keychain.derive_key_id(2).unwrap();
|
let key_id2 = keychain.derive_key_id(2).unwrap();
|
||||||
let key_id3 = keychain.derive_key_id(3).unwrap();
|
let key_id3 = keychain.derive_key_id(3).unwrap();
|
||||||
|
|
Loading…
Reference in a new issue