diff --git a/utils/slither_format/format_naming_convention.py b/utils/slither_format/format_naming_convention.py index 4fcb65027..089933553 100644 --- a/utils/slither_format/format_naming_convention.py +++ b/utils/slither_format/format_naming_convention.py @@ -456,7 +456,10 @@ class FormatNamingConvention: @staticmethod def create_patch_enum_uses(slither, patches, name, contract_name, in_file): for contract in slither.contracts: - if contract.name == contract_name: + if (contract.name == contract_name): + target_contract = contract + for contract in slither.contracts: + if (contract == target_contract or (contract in target_contract.derived_contracts)): in_file_str = slither.source_code[in_file] # Check state variable declarations of enum type # To-do: Deep-check aggregate types (struct and mapping) diff --git a/utils/slither_format/tests/test_data/naming_convention_enum.sol b/utils/slither_format/tests/test_data/naming_convention_enum.sol index 386be0c3d..2f4f37904 100644 --- a/utils/slither_format/tests/test_data/naming_convention_enum.sol +++ b/utils/slither_format/tests/test_data/naming_convention_enum.sol @@ -44,3 +44,10 @@ contract C { } } +contract D is C { + /* enum as parameter and return value - bad */ + function foo(e eA) returns (e) { + e e2 = eA; + return (e2); + } +} diff --git a/utils/slither_format/tests/test_naming_convention.py b/utils/slither_format/tests/test_naming_convention.py index 4e3ab50d6..ee6639e1e 100644 --- a/utils/slither_format/tests/test_naming_convention.py +++ b/utils/slither_format/tests/test_naming_convention.py @@ -221,9 +221,9 @@ class TestNamingConvention(unittest.TestCase): outFD4_lines[i] = outFD4_lines[i].strip() self.assertTrue(os.path.isfile(self.testFilePath4+".format"),"Patched .format file is not created?!") self.assertEqual(outFD4_lines[0],"Number of Slither results: 2") - self.assertEqual(outFD4_lines[1],"Number of patches: 8") + self.assertEqual(outFD4_lines[1],"Number of patches: 11") self.assertEqual(outFD4_lines.count("Detector: naming-convention (enum definition)"), 2) - self.assertEqual(outFD4_lines.count("Detector: naming-convention (enum use)"), 6) + self.assertEqual(outFD4_lines.count("Detector: naming-convention (enum use)"), 9) self.assertEqual(outFD4_lines.count("Old string: enum e {ONE, TWO}"), 2) self.assertEqual(outFD4_lines.count("New string: enum E {ONE, TWO}"), 2) self.assertEqual(outFD4_lines.count("Location start: 73"), 1) @@ -236,18 +236,28 @@ class TestNamingConvention(unittest.TestCase): self.assertEqual(outFD4_lines.count("Location end: 129"), 1) self.assertEqual(outFD4_lines.count("Location start: 478"), 1) self.assertEqual(outFD4_lines.count("Location end: 482"), 1) - self.assertEqual(outFD4_lines.count("Old string: e eA"), 1) - self.assertEqual(outFD4_lines.count("New string: E eA"), 1) + self.assertEqual(outFD4_lines.count("Old string: e eA"), 2) + self.assertEqual(outFD4_lines.count("New string: E eA"), 2) self.assertEqual(outFD4_lines.count("Location start: 549"), 1) self.assertEqual(outFD4_lines.count("Location end: 553"), 1) - self.assertEqual(outFD4_lines.count("Old string: e e2 = eA"), 1) - self.assertEqual(outFD4_lines.count("New string: E e2 = eA"), 1) + self.assertEqual(outFD4_lines.count("Location start: 690"), 1) + self.assertEqual(outFD4_lines.count("Location end: 694"), 1) + self.assertEqual(outFD4_lines.count("Old string: e e2 = eA"), 2) + self.assertEqual(outFD4_lines.count("New string: E e2 = eA"), 2) self.assertEqual(outFD4_lines.count("Location start: 573"), 1) self.assertEqual(outFD4_lines.count("Location end: 582"), 1) + self.assertEqual(outFD4_lines.count("Location start: 714"), 1) + self.assertEqual(outFD4_lines.count("Location end: 723"), 1) self.assertEqual(outFD4_lines.count("Old string: e.ONE"), 1) self.assertEqual(outFD4_lines.count("New string: E.ONE"), 1) self.assertEqual(outFD4_lines.count("Location start: 186"), 1) self.assertEqual(outFD4_lines.count("Location end: 192"), 1) + self.assertEqual(outFD4_lines.count("Old string: e"), 2) + self.assertEqual(outFD4_lines.count("New string: E"), 2) + self.assertEqual(outFD4_lines.count("Location start: 564"), 1) + self.assertEqual(outFD4_lines.count("Location end: 565"), 1) + self.assertEqual(outFD4_lines.count("Location start: 705"), 1) + self.assertEqual(outFD4_lines.count("Location end: 706"), 1) def test_naming_convention_event(self): outFD5 = open(self.testFilePath5+".out","r")