From f8a07a90e181f174434016c8afe715acf9b2bb2f Mon Sep 17 00:00:00 2001 From: rajeevgopalakrishna Date: Thu, 16 May 2019 17:37:11 +0530 Subject: [PATCH] Moves the inheritance testing to existing test. --- utils/slither_format/.gitignore | 3 + .../naming_convention_state_variable.sol | 7 +++ ..._convention_state_variable_inheritance.sol | 37 ----------- .../tests/test_naming_convention.py | 63 +++---------------- 4 files changed, 20 insertions(+), 90 deletions(-) delete mode 100644 utils/slither_format/tests/test_data/naming_convention_state_variable_inheritance.sol diff --git a/utils/slither_format/.gitignore b/utils/slither_format/.gitignore index f5478e79f..d356da7f4 100644 --- a/utils/slither_format/.gitignore +++ b/utils/slither_format/.gitignore @@ -3,6 +3,9 @@ # Temporary files (Emacs backup files ending in tilde and others) *~ +*.err +*.out + diff --git a/utils/slither_format/tests/test_data/naming_convention_state_variable.sol b/utils/slither_format/tests/test_data/naming_convention_state_variable.sol index 449fcb2db..2e7239f71 100644 --- a/utils/slither_format/tests/test_data/naming_convention_state_variable.sol +++ b/utils/slither_format/tests/test_data/naming_convention_state_variable.sol @@ -28,3 +28,10 @@ contract B { } } +contract C is B { + function foo() { + /* State variable uses - bad */ + uint i = number + Maxnum; + } +} + diff --git a/utils/slither_format/tests/test_data/naming_convention_state_variable_inheritance.sol b/utils/slither_format/tests/test_data/naming_convention_state_variable_inheritance.sol deleted file mode 100644 index 2e7239f71..000000000 --- a/utils/slither_format/tests/test_data/naming_convention_state_variable_inheritance.sol +++ /dev/null @@ -1,37 +0,0 @@ -pragma solidity ^0.4.24; - -contract A { - /* State variable declaration constant - good */ - uint constant NUMBER = 100; - /* State variable declaration private - good */ - uint private count = 100; - /* State variable declaration non-constant non-private - good */ - uint maxnum = 999; - - function foo() { - /* State variable uses - good */ - uint i = NUMBER + count + maxnum; - } -} - -contract B { - /* State variable declaration constant - bad */ - uint constant number = 100; - /* State variable declaration private - bad */ - uint private Count = 100; - /* State variable declaration non-constant non-private - good */ - uint Maxnum = 999; - function foo() { - /* State variable uses - bad */ - uint i = number + Count + Maxnum; - Count += i; - } -} - -contract C is B { - function foo() { - /* State variable uses - bad */ - uint i = number + Maxnum; - } -} - diff --git a/utils/slither_format/tests/test_naming_convention.py b/utils/slither_format/tests/test_naming_convention.py index 358282f66..67900b9b9 100644 --- a/utils/slither_format/tests/test_naming_convention.py +++ b/utils/slither_format/tests/test_naming_convention.py @@ -11,7 +11,6 @@ class TestNamingConvention(unittest.TestCase): testDataFile6 = "naming_convention_function.sol" testDataFile7 = "naming_convention_parameter.sol" testDataFile8 = "naming_convention_state_variable.sol" - testDataFile9 = "naming_convention_state_variable_inheritance.sol" testFilePath1 = testDataDir+testDataFile1 testFilePath2 = testDataDir+testDataFile2 testFilePath3 = testDataDir+testDataFile3 @@ -20,7 +19,6 @@ class TestNamingConvention(unittest.TestCase): testFilePath6 = testDataDir+testDataFile6 testFilePath7 = testDataDir+testDataFile7 testFilePath8 = testDataDir+testDataFile8 - testFilePath9 = testDataDir+testDataFile9 def setUp(self): outFD1 = open(self.testFilePath1+".out","w") @@ -79,13 +77,6 @@ class TestNamingConvention(unittest.TestCase): outFD8.close() errFD8.close() - outFD9 = open(self.testFilePath9+".out","w") - errFD9 = open(self.testFilePath9+".err","w") - p8 = subprocess.Popen(['python3', '-m', 'slither_format','--verbose-test','--detect','naming-convention',self.testFilePath9], stdout=outFD9,stderr=errFD9) - p8.wait() - outFD9.close() - errFD9.close() - def tearDown(self): p1 = subprocess.Popen(['rm','-f',self.testFilePath1+'.out',self.testFilePath1+'.err',self.testFilePath1+'.format']) p1.wait() @@ -103,44 +94,6 @@ class TestNamingConvention(unittest.TestCase): p7.wait() p8 = subprocess.Popen(['rm','-f',self.testFilePath8+'.out',self.testFilePath8+'.err',self.testFilePath8+'.format']) p8.wait() - p9 = subprocess.Popen(['rm','-f',self.testFilePath9+'.out',self.testFilePath9+'.err',self.testFilePath9+'.format']) - p9.wait() - - def test_naming_convention_state_variable_inheritance(self): - outFD9 = open(self.testFilePath9+".out","r") - outFD9_lines = outFD9.readlines() - outFD9.close() - for i in range(len(outFD9_lines)): - outFD9_lines[i] = outFD9_lines[i].strip() - self.assertTrue(os.path.isfile(self.testFilePath9+".format"),"Patched .format file is not created?!") - self.assertEqual(outFD9_lines[0],"Number of Slither results: 3") - self.assertEqual(outFD9_lines[1],"Number of patches: 9") - self.assertEqual(outFD9_lines.count("Detector: naming-convention (state variable declaration)"), 3) - self.assertEqual(outFD9_lines.count("Detector: naming-convention (state variable uses)"), 6) - self.assertEqual(outFD9_lines.count("Old string: number"), 3) - self.assertEqual(outFD9_lines.count("New string: NUMBER"), 3) - self.assertEqual(outFD9_lines.count("Location start: 469"), 1) - self.assertEqual(outFD9_lines.count("Location end: 475"), 1) - self.assertEqual(outFD9_lines.count("Location start: 716"), 1) - self.assertEqual(outFD9_lines.count("Location end: 722"), 1) - self.assertEqual(outFD9_lines.count("Location start: 850"), 1) - self.assertEqual(outFD9_lines.count("Location end: 856"), 1) - self.assertEqual(outFD9_lines.count("Old string: Count"), 3) - self.assertEqual(outFD9_lines.count("New string: count"), 3) - self.assertEqual(outFD9_lines.count("Location start: 547"), 1) - self.assertEqual(outFD9_lines.count("Location end: 552"), 1) - self.assertEqual(outFD9_lines.count("Location start: 725"), 1) - self.assertEqual(outFD9_lines.count("Location end: 730"), 1) - self.assertEqual(outFD9_lines.count("Location start: 745"), 1) - self.assertEqual(outFD9_lines.count("Location end: 750"), 1) - self.assertEqual(outFD9_lines.count("Old string: Maxnum"), 3) - self.assertEqual(outFD9_lines.count("New string: maxnum"), 3) - self.assertEqual(outFD9_lines.count("Location start: 634"), 1) - self.assertEqual(outFD9_lines.count("Location end: 640"), 1) - self.assertEqual(outFD9_lines.count("Location start: 733"), 1) - self.assertEqual(outFD9_lines.count("Location end: 739"), 1) - self.assertEqual(outFD9_lines.count("Location start: 859"), 1) - self.assertEqual(outFD9_lines.count("Location end: 865"), 1) def test_naming_convention_contract(self): outFD1 = open(self.testFilePath1+".out","r") @@ -406,15 +359,17 @@ class TestNamingConvention(unittest.TestCase): outFD8_lines[i] = outFD8_lines[i].strip() self.assertTrue(os.path.isfile(self.testFilePath8+".format"),"Patched .format file is not created?!") self.assertEqual(outFD8_lines[0],"Number of Slither results: 3") - self.assertEqual(outFD8_lines[1],"Number of patches: 7") + self.assertEqual(outFD8_lines[1],"Number of patches: 9") self.assertEqual(outFD8_lines.count("Detector: naming-convention (state variable declaration)"), 3) - self.assertEqual(outFD8_lines.count("Detector: naming-convention (state variable uses)"), 4) - self.assertEqual(outFD8_lines.count("Old string: number"), 2) - self.assertEqual(outFD8_lines.count("New string: NUMBER"), 2) + self.assertEqual(outFD8_lines.count("Detector: naming-convention (state variable uses)"), 6) + self.assertEqual(outFD8_lines.count("Old string: number"), 3) + self.assertEqual(outFD8_lines.count("New string: NUMBER"), 3) self.assertEqual(outFD8_lines.count("Location start: 469"), 1) self.assertEqual(outFD8_lines.count("Location end: 475"), 1) self.assertEqual(outFD8_lines.count("Location start: 716"), 1) self.assertEqual(outFD8_lines.count("Location end: 722"), 1) + self.assertEqual(outFD8_lines.count("Location start: 850"), 1) + self.assertEqual(outFD8_lines.count("Location end: 856"), 1) self.assertEqual(outFD8_lines.count("Old string: Count"), 3) self.assertEqual(outFD8_lines.count("New string: count"), 3) self.assertEqual(outFD8_lines.count("Location start: 547"), 1) @@ -423,12 +378,14 @@ class TestNamingConvention(unittest.TestCase): self.assertEqual(outFD8_lines.count("Location end: 730"), 1) self.assertEqual(outFD8_lines.count("Location start: 745"), 1) self.assertEqual(outFD8_lines.count("Location end: 750"), 1) - self.assertEqual(outFD8_lines.count("Old string: Maxnum"), 2) - self.assertEqual(outFD8_lines.count("New string: maxnum"), 2) + self.assertEqual(outFD8_lines.count("Old string: Maxnum"), 3) + self.assertEqual(outFD8_lines.count("New string: maxnum"), 3) self.assertEqual(outFD8_lines.count("Location start: 634"), 1) self.assertEqual(outFD8_lines.count("Location end: 640"), 1) self.assertEqual(outFD8_lines.count("Location start: 733"), 1) self.assertEqual(outFD8_lines.count("Location end: 739"), 1) + self.assertEqual(outFD8_lines.count("Location start: 859"), 1) + self.assertEqual(outFD8_lines.count("Location end: 865"), 1) if __name__ == '__main__': unittest.main()