Skip to content

Commit

Permalink
Rename ConstantsInsteadOfLiterals detector to better suit `//aderyn…
Browse files Browse the repository at this point in the history
…-ignore-(..)` (#737)
  • Loading branch information
TilakMaddy authored Oct 4, 2024
1 parent 69a4d5a commit c270c08
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
10 changes: 5 additions & 5 deletions aderyn_core/src/detect/detector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub fn get_all_issue_detectors() -> Vec<Box<dyn IssueDetector>> {
Box::<UnspecificSolidityPragmaDetector>::default(),
Box::<ZeroAddressCheckDetector>::default(),
Box::<UselessPublicFunctionDetector>::default(),
Box::<ConstantsInsteadOfLiteralsDetector>::default(),
Box::<LiteralsInsteadOfConstantsDetector>::default(),
Box::<UnindexedEventsDetector>::default(),
Box::<RequireWithStringDetector>::default(),
Box::<NonReentrantBeforeOthersDetector>::default(),
Expand Down Expand Up @@ -139,8 +139,8 @@ pub(crate) enum IssueDetectorNamePool {
UnspecificSolidityPragma,
ZeroAddressCheck,
UselessPublicFunction,
ConstantsInsteadOfLiterals,
UnindexedEvents,
LiteralInsteadOfConstant,
RequireWithString,
NonReentrantBeforeOthers,
BlockTimestampDeadline,
Expand Down Expand Up @@ -226,6 +226,9 @@ pub fn request_issue_detector_by_name(detector_name: &str) -> Option<Box<dyn Iss
IssueDetectorNamePool::StateVariableCouldBeDeclaredConstant => {
Some(Box::<StateVariableCouldBeConstantDetector>::default())
}
IssueDetectorNamePool::LiteralInsteadOfConstant => {
Some(Box::<LiteralsInsteadOfConstantsDetector>::default())
}
IssueDetectorNamePool::FunctionPointerInConstructor => {
Some(Box::<FucntionPointerInConstructorDetector>::default())
}
Expand Down Expand Up @@ -291,9 +294,6 @@ pub fn request_issue_detector_by_name(detector_name: &str) -> Option<Box<dyn Iss
IssueDetectorNamePool::UselessPublicFunction => {
Some(Box::<UselessPublicFunctionDetector>::default())
}
IssueDetectorNamePool::ConstantsInsteadOfLiterals => {
Some(Box::<ConstantsInsteadOfLiteralsDetector>::default())
}
IssueDetectorNamePool::UnindexedEvents => Some(Box::<UnindexedEventsDetector>::default()),
IssueDetectorNamePool::RequireWithString => {
Some(Box::<RequireWithStringDetector>::default())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ use crate::{
use eyre::Result;

#[derive(Default)]
pub struct ConstantsInsteadOfLiteralsDetector {
pub struct LiteralsInsteadOfConstantsDetector {
// Keys are: [0] source file name, [1] line number, [2] character location of node.
// Do not add items manually, use `capture!` to add nodes to this BTreeMap.
found_instances: BTreeMap<(String, usize, String), NodeID>,
}

impl IssueDetector for ConstantsInsteadOfLiteralsDetector {
impl IssueDetector for LiteralsInsteadOfConstantsDetector {
fn detect(&mut self, context: &WorkspaceContext) -> Result<bool, Box<dyn Error>> {
// Get all contracts
// For each contract
Expand Down Expand Up @@ -128,26 +128,25 @@ impl IssueDetector for ConstantsInsteadOfLiteralsDetector {
}

fn name(&self) -> String {
format!("{}", IssueDetectorNamePool::ConstantsInsteadOfLiterals)
format!("{}", IssueDetectorNamePool::LiteralInsteadOfConstant)
}
}

#[cfg(test)]
mod constants_instead_of_literals_tests {
use serial_test::serial;

use super::LiteralsInsteadOfConstantsDetector;
use crate::detect::detector::IssueDetector;

use super::ConstantsInsteadOfLiteralsDetector;

#[test]
#[serial]
fn test_constants_instead_of_literals_by_loading_contract_directly() {
let context = crate::detect::test_utils::load_solidity_source_unit(
"../tests/contract-playground/src/ConstantsLiterals.sol",
);

let mut detector = ConstantsInsteadOfLiteralsDetector::default();
let mut detector = LiteralsInsteadOfConstantsDetector::default();
// assert that the detector finds the public Function
let found = detector.detect(&context).unwrap();
assert!(found);
Expand Down
4 changes: 2 additions & 2 deletions aderyn_core/src/detect/low/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pub(crate) mod builtin_symbol_shadowing;
pub(crate) mod cache_array_length;
pub(crate) mod centralization_risk;
pub(crate) mod constant_funcs_assembly;
pub(crate) mod constants_instead_of_literals;
pub(crate) mod contracts_with_todos;
pub(crate) mod costly_operations_inside_loops;
pub(crate) mod dead_code;
Expand All @@ -16,6 +15,7 @@ pub(crate) mod function_init_state_vars;
pub(crate) mod function_pointer_in_constructor;
pub(crate) mod inconsistent_type_names;
pub(crate) mod large_literal_value;
pub(crate) mod literals_instead_of_constants;
pub(crate) mod local_variable_shadowing;
pub(crate) mod missing_inheritance;
pub(crate) mod multiple_placeholders;
Expand Down Expand Up @@ -49,7 +49,6 @@ pub use builtin_symbol_shadowing::BuiltinSymbolShadowDetector;
pub use cache_array_length::CacheArrayLengthDetector;
pub use centralization_risk::CentralizationRiskDetector;
pub use constant_funcs_assembly::ConstantFunctionContainsAssemblyDetector;
pub use constants_instead_of_literals::ConstantsInsteadOfLiteralsDetector;
pub use contracts_with_todos::ContractsWithTodosDetector;
pub use costly_operations_inside_loops::CostlyOperationsInsideLoopsDetector;
pub use dead_code::DeadCodeDetector;
Expand All @@ -61,6 +60,7 @@ pub use function_init_state_vars::FunctionInitializingStateDetector;
pub use function_pointer_in_constructor::FucntionPointerInConstructorDetector;
pub use inconsistent_type_names::InconsistentTypeNamesDetector;
pub use large_literal_value::LargeLiteralValueDetector;
pub use literals_instead_of_constants::LiteralsInsteadOfConstantsDetector;
pub use local_variable_shadowing::LocalVariableShadowingDetector;
pub use missing_inheritance::MissingInheritanceDetector;
pub use multiple_placeholders::MultiplePlaceholdersDetector;
Expand Down
4 changes: 2 additions & 2 deletions reports/report.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion reports/report.sarif

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c270c08

Please sign in to comment.