From 6afc3aa033f4c422e945eb0b08dc3d9d087c32c4 Mon Sep 17 00:00:00 2001 From: TilakMaddy Date: Wed, 31 Jul 2024 14:31:39 +0530 Subject: [PATCH] change --- .../src/context/investigator/callgraph_tests.rs | 14 +++++++------- .../high/delegate_call_no_address_check.rs | 2 +- .../src/detect/high/send_ether_no_checks.rs | 2 +- .../src/detect/test_utils/load_source_unit.rs | 16 +--------------- aderyn_core/src/detect/test_utils/mod.rs | 1 - 5 files changed, 10 insertions(+), 25 deletions(-) diff --git a/aderyn_core/src/context/investigator/callgraph_tests.rs b/aderyn_core/src/context/investigator/callgraph_tests.rs index faa0a1ccc..501f13667 100644 --- a/aderyn_core/src/context/investigator/callgraph_tests.rs +++ b/aderyn_core/src/context/investigator/callgraph_tests.rs @@ -36,7 +36,7 @@ mod callgraph_tests { #[test] fn test_callgraph_is_not_none() { - let context = crate::detect::test_utils::load_solidity_source_unit_with_callgraphs( + let context = crate::detect::test_utils::load_solidity_source_unit( "../tests/contract-playground/src/CallGraphTests.sol", ); assert!(context.forward_callgraph.is_some()); @@ -45,7 +45,7 @@ mod callgraph_tests { #[test] fn test_tower1_modifier_has_no_downstream() { - let context = crate::detect::test_utils::load_solidity_source_unit_with_callgraphs( + let context = crate::detect::test_utils::load_solidity_source_unit( "../tests/contract-playground/src/CallGraphTests.sol", ); @@ -63,7 +63,7 @@ mod callgraph_tests { #[test] fn test_tower1_modifier_has_upstream() { - let context = crate::detect::test_utils::load_solidity_source_unit_with_callgraphs( + let context = crate::detect::test_utils::load_solidity_source_unit( "../tests/contract-playground/src/CallGraphTests.sol", ); @@ -81,7 +81,7 @@ mod callgraph_tests { #[test] fn test_tower2_modifier_has_both_upstream_and_downstream() { - let context = crate::detect::test_utils::load_solidity_source_unit_with_callgraphs( + let context = crate::detect::test_utils::load_solidity_source_unit( "../tests/contract-playground/src/CallGraphTests.sol", ); @@ -100,7 +100,7 @@ mod callgraph_tests { #[test] fn test_tower3_modifier_has_both_upstream_and_downstream() { - let context = crate::detect::test_utils::load_solidity_source_unit_with_callgraphs( + let context = crate::detect::test_utils::load_solidity_source_unit( "../tests/contract-playground/src/CallGraphTests.sol", ); @@ -121,7 +121,7 @@ mod callgraph_tests { #[test] fn test_tower3_functions_has_upstream() { - let context = crate::detect::test_utils::load_solidity_source_unit_with_callgraphs( + let context = crate::detect::test_utils::load_solidity_source_unit( "../tests/contract-playground/src/CallGraphTests.sol", ); @@ -138,7 +138,7 @@ mod callgraph_tests { #[test] fn test_tower4_functions_has_upstream_and_downstream() { - let context = crate::detect::test_utils::load_solidity_source_unit_with_callgraphs( + let context = crate::detect::test_utils::load_solidity_source_unit( "../tests/contract-playground/src/CallGraphTests.sol", ); diff --git a/aderyn_core/src/detect/high/delegate_call_no_address_check.rs b/aderyn_core/src/detect/high/delegate_call_no_address_check.rs index 19ec1e134..19a698cc0 100644 --- a/aderyn_core/src/detect/high/delegate_call_no_address_check.rs +++ b/aderyn_core/src/detect/high/delegate_call_no_address_check.rs @@ -100,7 +100,7 @@ mod delegate_call_no_address_check_tests { #[test] #[serial] fn test_delegate_call_without_checks() { - let context = crate::detect::test_utils::load_solidity_source_unit_with_callgraphs( + let context = crate::detect::test_utils::load_solidity_source_unit( "../tests/contract-playground/src/DelegateCallWithoutAddressCheck.sol", ); diff --git a/aderyn_core/src/detect/high/send_ether_no_checks.rs b/aderyn_core/src/detect/high/send_ether_no_checks.rs index a20f35667..964c694a8 100644 --- a/aderyn_core/src/detect/high/send_ether_no_checks.rs +++ b/aderyn_core/src/detect/high/send_ether_no_checks.rs @@ -74,7 +74,7 @@ mod send_ether_no_checks_detector_tests { #[test] #[serial] fn test_send_ether_no_checks() { - let context = crate::detect::test_utils::load_solidity_source_unit_with_callgraphs( + let context = crate::detect::test_utils::load_solidity_source_unit( "../tests/contract-playground/src/SendEtherNoChecks.sol", ); diff --git a/aderyn_core/src/detect/test_utils/load_source_unit.rs b/aderyn_core/src/detect/test_utils/load_source_unit.rs index 31844c086..c52a15f29 100644 --- a/aderyn_core/src/detect/test_utils/load_source_unit.rs +++ b/aderyn_core/src/detect/test_utils/load_source_unit.rs @@ -13,19 +13,8 @@ use crate::{context::graph::WorkspaceCallGraph, visitor::ast_visitor::Node}; use super::ensure_valid_solidity_file; -#[cfg(test)] -pub fn load_solidity_source_unit_with_callgraphs(filepath: &str) -> WorkspaceContext { - _load_solidity_source_unit(filepath, true) -} - #[cfg(test)] pub fn load_solidity_source_unit(filepath: &str) -> WorkspaceContext { - println!("WARNING: Callgraph won't be loaded. Please use `load_solidity_source_unit_with_callgraphs` if callgraph is required!"); - _load_solidity_source_unit(filepath, false) -} - -#[cfg(test)] -fn _load_solidity_source_unit(filepath: &str, should_load_callgraphs: bool) -> WorkspaceContext { let solidity_file = &ensure_valid_solidity_file(filepath); let solidity_content = std::fs::read_to_string(solidity_file).unwrap(); @@ -95,10 +84,6 @@ fn _load_solidity_source_unit(filepath: &str, should_load_callgraphs: bool) -> W absorb_ast_content_into_context(&ast_content, solidity_content.clone(), &mut context); } - if should_load_callgraphs { - load_callgraphs(&mut context); - } - context } else { eprintln!("Error running solc command"); @@ -128,6 +113,7 @@ fn absorb_ast_content_into_context( eprintln!("{:?}", err); std::process::exit(1); }); + load_callgraphs(context); } fn is_demarcation_line(line: &str, file_args: Vec<&str>) -> (bool, Option) { diff --git a/aderyn_core/src/detect/test_utils/mod.rs b/aderyn_core/src/detect/test_utils/mod.rs index b10ddc7df..10a76c7fd 100644 --- a/aderyn_core/src/detect/test_utils/mod.rs +++ b/aderyn_core/src/detect/test_utils/mod.rs @@ -7,7 +7,6 @@ use std::path::PathBuf; // Using `solc` to read AST given a source unit (i.e Solidity file) pub use load_source_unit::load_multiple_solidity_source_units_into_single_context; pub use load_source_unit::load_solidity_source_unit; -pub use load_source_unit::load_solidity_source_unit_with_callgraphs; pub(crate) fn take_loader_lock() -> impl Drop { static LOCK: Lazy> = Lazy::new(|| std::sync::Mutex::new(()));