From 307838108fbddff7c1cfb0a541d141cf8053d356 Mon Sep 17 00:00:00 2001 From: Jinsuk Park Date: Tue, 1 Oct 2024 00:41:48 +0900 Subject: [PATCH] remove name() method from FunctionCallDefinition --- src/generator/types.rs | 86 ------------------------------------------ 1 file changed, 86 deletions(-) diff --git a/src/generator/types.rs b/src/generator/types.rs index 9ae5e9a..33f7071 100644 --- a/src/generator/types.rs +++ b/src/generator/types.rs @@ -7,7 +7,6 @@ use alloy::{ use serde::{Deserialize, Serialize}; use std::collections::HashMap; use tokio::task::JoinHandle; -use regex::Regex; pub type RpcProvider = RootProvider>; @@ -71,88 +70,3 @@ pub enum PlanType CallbackResult> { Setup(F), Spam(usize, F), } - -impl FunctionCallDefinition { - /// Constructs a function name string combining signature and arguments. - pub fn name(&self) -> String { - // Use regex to parse the function signature - let signature = &self.signature; - let re = Regex::new(r"(?P\w+)\s*\((?P[^\)]*)\)(\s*returns\s*\((?P[^\)]*)\))?").unwrap(); - - // If the signature matches the expected pattern - if let Some(caps) = re.captures(signature) { - let func_name = caps.name("func_name").unwrap().as_str(); - let params_str = caps.name("params").unwrap().as_str(); - - // Split the parameters into a vector - let params: Vec<&str> = params_str.split(',').map(|s| s.trim()).collect(); - - // Prepare a vector to hold the reconstructed parameters - let mut reconstructed_params = Vec::new(); - - let values = self.args.as_deref().unwrap_or(&[]); - - // Iterate over parameters and associate them with args[i] - for (i, param) in params.iter().enumerate() { - // Split each parameter into type and name - let parts: Vec<&str> = param.split_whitespace().collect(); - let param_value = values.get(i).map(String::as_str).unwrap_or(""); - if parts.len() == 2 { - let param_type = parts[0]; - let param_name = parts[1]; - reconstructed_params.push(format!("{} {}=[{}]", param_type, param_name, param_value)); - } - } - - // Reconstruct the function signature - let reconstructed_signature = format!("{}({})", func_name, reconstructed_params.join(", ")); - - return reconstructed_signature; - } - - // If the signature doesn't match, return it as is - signature.clone() - } -} - -#[cfg(test)] -pub mod tests { - use super::FunctionCallDefinition; - - #[test] - fn constructs_name_from_signature() { - let fn_def_with_args = FunctionCallDefinition { - to: "0x1234".to_string(), - from: "0x5678".to_string(), - signature: "transfer(address to, uint256 amount)".to_string(), - args: Some(vec!["0x8765".to_string(), "100".to_string()]), - value: Some("100".to_string()), - fuzz: None, - kind: None, - }; - assert_eq!(fn_def_with_args.name(), "transfer(address to=[0x8765], uint256 amount=[100])"); - - let fn_def_no_args = FunctionCallDefinition { - to: "0x1234".to_string(), - from: "0x5678".to_string(), - signature: "transfer()".to_string(), - args: None, - value: Some("100".to_string()), - fuzz: None, - kind: None, - }; - assert_eq!(fn_def_no_args.name(), "transfer()"); - - // checks if it does not fail against invalid signature. - let fn_def_invalid_sig = FunctionCallDefinition { - to: "0x1234".to_string(), - from: "0x5678".to_string(), - signature: "transfer(address, uint256 amount)".to_string(), - args: Some(vec!["0x8765".to_string(), "100".to_string()]), - value: Some("100".to_string()), - fuzz: None, - kind: None, - }; - assert_eq!(fn_def_invalid_sig.name(), "transfer(uint256 amount=[100])"); - } -}