Skip to content

Commit

Permalink
change
Browse files Browse the repository at this point in the history
  • Loading branch information
TilakMaddy committed Jul 31, 2024
1 parent ee2f464 commit 6afc3aa
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 25 deletions.
14 changes: 7 additions & 7 deletions aderyn_core/src/context/investigator/callgraph_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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",
);

Expand All @@ -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",
);

Expand All @@ -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",
);

Expand All @@ -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",
);

Expand All @@ -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",
);

Expand All @@ -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",
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
);

Expand Down
2 changes: 1 addition & 1 deletion aderyn_core/src/detect/high/send_ether_no_checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
);

Expand Down
16 changes: 1 addition & 15 deletions aderyn_core/src/detect/test_utils/load_source_unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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<String>) {
Expand Down
1 change: 0 additions & 1 deletion aderyn_core/src/detect/test_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::sync::Mutex<()>> = Lazy::new(|| std::sync::Mutex::new(()));
Expand Down

0 comments on commit 6afc3aa

Please sign in to comment.