Skip to content

Commit bca649d

Browse files
committed
chore: common constructor
1 parent d7a766f commit bca649d

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

crates/evm/evm/src/executors/corpus.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ enum MutationType {
5252
Abi,
5353
}
5454

55-
// TODO(dani): UUID v6 for timestamp
5655
/// Holds Corpus information.
5756
#[derive(Clone, Serialize)]
5857
struct CorpusEntry {
@@ -76,7 +75,19 @@ struct CorpusEntry {
7675
impl CorpusEntry {
7776
/// New corpus from given call sequence and corpus path to read uuid.
7877
pub fn new(tx_seq: Vec<BasicTxDetails>, path: PathBuf) -> eyre::Result<Self> {
79-
let uuid = if let Some(stem) = path.file_stem().and_then(|s| s.to_str()) {
78+
Self::_new(tx_seq, Some(path))
79+
}
80+
81+
/// New corpus with given call sequence and new uuid.
82+
pub fn from_tx_seq(tx_seq: &[BasicTxDetails]) -> Self {
83+
Self::_new(tx_seq.into(), None).expect("infallible")
84+
}
85+
86+
fn _new(tx_seq: Vec<BasicTxDetails>, path: Option<PathBuf>) -> eyre::Result<Self> {
87+
let uuid = if let Some(path) = path
88+
&& let Some(stem) = path.file_stem()
89+
&& let Some(stem) = stem.to_str()
90+
{
8091
Uuid::try_from(stem.strip_suffix(JSON_EXTENSION).unwrap_or(stem).to_string())?
8192
} else {
8293
Uuid::new_v4()
@@ -90,18 +101,6 @@ impl CorpusEntry {
90101
timestamp: SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs(),
91102
})
92103
}
93-
94-
/// New corpus with given call sequence and new uuid.
95-
pub fn from_tx_seq(tx_seq: &[BasicTxDetails]) -> Self {
96-
Self {
97-
uuid: Uuid::new_v4(),
98-
total_mutations: 0,
99-
new_finds_produced: 0,
100-
tx_seq: tx_seq.into(),
101-
is_favored: false,
102-
timestamp: SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs(),
103-
}
104-
}
105104
}
106105

107106
#[derive(Serialize, Default)]

0 commit comments

Comments
 (0)