Skip to content

Commit

Permalink
✨ Code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
lukacan committed Jan 2, 2025
1 parent a523393 commit 28c7123
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 58 deletions.
2 changes: 1 addition & 1 deletion crates/config/src/fuzz.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::utils::resolve_path;
use base64::{prelude::BASE64_STANDARD, Engine};
use serde::{Deserialize, Serialize};
use solana_sdk::{
account::{AccountSharedData, WritableAccount},
pubkey::Pubkey,
};
use std::{fs, str::FromStr};
use crate::utils::resolve_path;

#[derive(Debug, Deserialize, Clone, Default)]
pub struct Fuzz {
Expand Down
24 changes: 12 additions & 12 deletions crates/config/src/honggfuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ mod tests {
honggfuzz.timeout = Some(timeout);

let arg = honggfuzz.get_collect_fuzz_args();
assert_eq!(arg, vec!["-t 10"]);
assert_eq!(arg, vec!["-t", "10"]);
}
#[test]
fn test_iterations() {
Expand All @@ -278,7 +278,7 @@ mod tests {
honggfuzz.iterations = Some(iterations);

let arg = honggfuzz.get_collect_fuzz_args();
assert_eq!(arg, vec!["-N 1000"]);
assert_eq!(arg, vec!["-N", "1000"]);
}
#[test]
fn test_threads() {
Expand All @@ -289,7 +289,7 @@ mod tests {
honggfuzz.threads = Some(threads);

let arg = honggfuzz.get_collect_fuzz_args();
assert_eq!(arg, vec!["-n 15"]);
assert_eq!(arg, vec!["-n", "15"]);
}
#[test]
fn test_keep_output() {
Expand All @@ -299,7 +299,7 @@ mod tests {
honggfuzz.keep_output = Some(true);

let arg = honggfuzz.get_collect_fuzz_args();
assert_eq!(arg, vec!["-Q"]);
assert_eq!(arg, vec!["-Q", ""]);
}
#[test]
fn test_verbose() {
Expand All @@ -309,7 +309,7 @@ mod tests {
honggfuzz.verbose = Some(true);

let arg = honggfuzz.get_collect_fuzz_args();
assert_eq!(arg, vec!["-v"]);
assert_eq!(arg, vec!["-v", ""]);
}
#[test]
fn test_exit_upon_crash() {
Expand All @@ -319,7 +319,7 @@ mod tests {
honggfuzz.exit_upon_crash = Some(true);

let arg = honggfuzz.get_collect_fuzz_args();
assert_eq!(arg, vec!["--exit_upon_crash"]);
assert_eq!(arg, vec!["--exit_upon_crash", ""]);
}
#[test]
fn test_mutations_per_run() {
Expand All @@ -330,7 +330,7 @@ mod tests {
honggfuzz.mutations_per_run = Some(mutations_per_run);

let arg = honggfuzz.get_collect_fuzz_args();
assert_eq!(arg, vec!["-r 33"]);
assert_eq!(arg, vec!["-r", "33"]);
}
#[test]
fn test_crashdir() {
Expand All @@ -340,7 +340,7 @@ mod tests {
honggfuzz.crashdir = Some(crash_dir.to_string());

let arg = honggfuzz.get_collect_fuzz_args();
assert_eq!(arg, vec!["--crashdir crashdir1"]);
assert_eq!(arg, vec!["--crashdir", "crashdir1"]);
}
#[test]
fn test_extension() {
Expand All @@ -351,7 +351,7 @@ mod tests {
honggfuzz.extension = Some(extension.to_string());

let arg = honggfuzz.get_collect_fuzz_args();
assert_eq!(arg, vec!["-e sol"]);
assert_eq!(arg, vec!["-e", "sol"]);
}
#[test]
fn test_run_time() {
Expand All @@ -362,7 +362,7 @@ mod tests {
honggfuzz.run_time = Some(run_time);

let arg = honggfuzz.get_collect_fuzz_args();
assert_eq!(arg, vec!["--run_time 13"]);
assert_eq!(arg, vec!["--run_time", "13"]);
}
#[test]
fn test_max_file_size() {
Expand All @@ -373,7 +373,7 @@ mod tests {
honggfuzz.max_file_size = Some(max_file_size);

let arg = honggfuzz.get_collect_fuzz_args();
assert_eq!(arg, vec!["-F 500"]);
assert_eq!(arg, vec!["-F", "500"]);
}
#[test]
fn test_save_all() {
Expand All @@ -383,7 +383,7 @@ mod tests {
honggfuzz.save_all = Some(true);

let arg = honggfuzz.get_collect_fuzz_args();
assert_eq!(arg, vec!["-u"]);
assert_eq!(arg, vec!["-u", ""]);
}
#[test]
fn test_cargo_target_dir() {
Expand Down
84 changes: 40 additions & 44 deletions crates/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,65 +115,61 @@ impl Config {
full_path.to_str().unwrap().to_string()
}
pub fn get_afl_build_args(&self) -> Vec<String> {
if let Some(afl) = &self.afl {
afl.get_collect_build_args()
} else {
Vec::default()
}
self.afl
.as_ref()
.map(|afl| afl.get_collect_build_args())
.unwrap_or_default()
}
pub fn get_afl_fuzz_args(&self) -> Vec<String> {
if let Some(afl) = &self.afl {
afl.get_collect_fuzz_args()
} else {
Vec::default()
}
self.afl
.as_ref()
.map(|afl| afl.get_collect_fuzz_args())
.unwrap_or_default()
}

pub fn get_initial_seed(&self) -> Vec<AflSeed> {
if let Some(afl) = &self.afl {
afl.get_seeds()
} else {
// if nothing is provided, use the default seed
vec![AflSeed::default()]
}
self.afl
.as_ref()
.map(|afl| afl.get_seeds())
.unwrap_or_else(|| vec![AflSeed::default()])
}
// -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
// fuzz
pub fn get_fuzzing_with_stats(&self) -> bool {
if let Some(fuzz) = &self.fuzz {
fuzz.get_fuzzing_with_stats()
} else {
false
}
self.fuzz
.as_ref()
.map(|fuzz| fuzz.get_fuzzing_with_stats())
.unwrap_or_default()
}
pub fn get_allow_duplicate_txs(&self) -> bool {
if let Some(fuzz) = &self.fuzz {
fuzz.get_allow_duplicate_txs()
} else {
false
}
self.fuzz
.as_ref()
.map(|fuzz| fuzz.get_allow_duplicate_txs())
.unwrap_or_default()
}

pub fn programs(&self) -> Vec<FuzzProgram> {
if let Some(fuzz) = &self.fuzz {
if let Some(programs) = &fuzz.programs {
programs.iter().map(FuzzProgram::from).collect()
} else {
Vec::default()
}
} else {
Vec::default()
}
self.fuzz
.as_ref()
.map(|fuzz| {
if let Some(programs) = &fuzz.programs {
programs.iter().map(FuzzProgram::from).collect()
} else {
Vec::default()
}
})
.unwrap_or_default()
}
pub fn accounts(&self) -> Vec<FuzzAccount> {
if let Some(fuzz) = &self.fuzz {
if let Some(accounts) = &fuzz.accounts {
accounts.iter().map(FuzzAccount::from).collect()
} else {
Vec::default()
}
} else {
Vec::default()
}
self.fuzz
.as_ref()
.map(|fuzz| {
if let Some(accounts) = &fuzz.accounts {
accounts.iter().map(FuzzAccount::from).collect()
} else {
Vec::default()
}
})
.unwrap_or_default()
}
}
2 changes: 1 addition & 1 deletion crates/fuzz/src/fuzz_client.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#![allow(dead_code)]

use trident_config::Config;
use crate::error::*;
use solana_sdk::account::AccountSharedData;
use solana_sdk::hash::Hash;
use solana_sdk::instruction::Instruction;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::Keypair;
use solana_sdk::sysvar::Sysvar;
use trident_config::Config;
use trident_svm::utils::ProgramEntrypoint;

/// A trait providing methods to read and write (manipulate) accounts
Expand Down

0 comments on commit 28c7123

Please sign in to comment.