Adds support for inheritance in naming-convention of enums.

pull/238/head
rajeevgopalakrishna 6 years ago
parent 54f3f26e8a
commit be84d6618a
  1. 5
      utils/slither_format/format_naming_convention.py
  2. 7
      utils/slither_format/tests/test_data/naming_convention_enum.sol
  3. 22
      utils/slither_format/tests/test_naming_convention.py

@ -456,7 +456,10 @@ class FormatNamingConvention:
@staticmethod @staticmethod
def create_patch_enum_uses(slither, patches, name, contract_name, in_file): def create_patch_enum_uses(slither, patches, name, contract_name, in_file):
for contract in slither.contracts: 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] in_file_str = slither.source_code[in_file]
# Check state variable declarations of enum type # Check state variable declarations of enum type
# To-do: Deep-check aggregate types (struct and mapping) # To-do: Deep-check aggregate types (struct and mapping)

@ -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);
}
}

@ -221,9 +221,9 @@ class TestNamingConvention(unittest.TestCase):
outFD4_lines[i] = outFD4_lines[i].strip() outFD4_lines[i] = outFD4_lines[i].strip()
self.assertTrue(os.path.isfile(self.testFilePath4+".format"),"Patched .format file is not created?!") 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[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 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("Old string: enum e {ONE, TWO}"), 2)
self.assertEqual(outFD4_lines.count("New 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) 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 end: 129"), 1)
self.assertEqual(outFD4_lines.count("Location start: 478"), 1) self.assertEqual(outFD4_lines.count("Location start: 478"), 1)
self.assertEqual(outFD4_lines.count("Location end: 482"), 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("Old string: e eA"), 2)
self.assertEqual(outFD4_lines.count("New string: E eA"), 1) 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 start: 549"), 1)
self.assertEqual(outFD4_lines.count("Location end: 553"), 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("Location start: 690"), 1)
self.assertEqual(outFD4_lines.count("New string: E e2 = eA"), 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 start: 573"), 1)
self.assertEqual(outFD4_lines.count("Location end: 582"), 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("Old string: e.ONE"), 1)
self.assertEqual(outFD4_lines.count("New 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 start: 186"), 1)
self.assertEqual(outFD4_lines.count("Location end: 192"), 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): def test_naming_convention_event(self):
outFD5 = open(self.testFilePath5+".out","r") outFD5 = open(self.testFilePath5+".out","r")

Loading…
Cancel
Save