import unittest
import subprocess , os , sys
class TestNamingConvention ( unittest . TestCase ) :
testDataDir = " ./slither_format/tests/test_data/ "
testDataFile1 = " naming_convention_contract.sol "
testDataFile2 = " naming_convention_modifier.sol "
testDataFile3 = " naming_convention_structure.sol "
testDataFile4 = " naming_convention_enum.sol "
testDataFile5 = " naming_convention_event.sol "
testDataFile6 = " naming_convention_function.sol "
testDataFile7 = " naming_convention_parameter.sol "
testDataFile8 = " naming_convention_state_variable.sol "
testFilePath1 = testDataDir + testDataFile1
testFilePath2 = testDataDir + testDataFile2
testFilePath3 = testDataDir + testDataFile3
testFilePath4 = testDataDir + testDataFile4
testFilePath5 = testDataDir + testDataFile5
testFilePath6 = testDataDir + testDataFile6
testFilePath7 = testDataDir + testDataFile7
testFilePath8 = testDataDir + testDataFile8
def setUp ( self ) :
outFD1 = open ( self . testFilePath1 + " .out " , " w " )
errFD1 = open ( self . testFilePath1 + " .err " , " w " )
p1 = subprocess . Popen ( [ ' python3 ' , ' -m ' , ' slither_format ' , ' --verbose-test ' , ' --detect ' , ' naming-convention ' , self . testFilePath1 ] , stdout = outFD1 , stderr = errFD1 )
p1 . wait ( )
outFD1 . close ( )
errFD1 . close ( )
outFD2 = open ( self . testFilePath2 + " .out " , " w " )
errFD2 = open ( self . testFilePath2 + " .err " , " w " )
p2 = subprocess . Popen ( [ ' python3 ' , ' -m ' , ' slither_format ' , ' --verbose-test ' , ' --detect ' , ' naming-convention ' , self . testFilePath2 ] , stdout = outFD2 , stderr = errFD2 )
p2 . wait ( )
outFD2 . close ( )
errFD2 . close ( )
outFD3 = open ( self . testFilePath3 + " .out " , " w " )
errFD3 = open ( self . testFilePath3 + " .err " , " w " )
p3 = subprocess . Popen ( [ ' python3 ' , ' -m ' , ' slither_format ' , ' --verbose-test ' , ' --detect ' , ' naming-convention ' , self . testFilePath3 ] , stdout = outFD3 , stderr = errFD3 )
p3 . wait ( )
outFD3 . close ( )
errFD3 . close ( )
outFD4 = open ( self . testFilePath4 + " .out " , " w " )
errFD4 = open ( self . testFilePath4 + " .err " , " w " )
p4 = subprocess . Popen ( [ ' python3 ' , ' -m ' , ' slither_format ' , ' --verbose-test ' , ' --detect ' , ' naming-convention ' , self . testFilePath4 ] , stdout = outFD4 , stderr = errFD4 )
p4 . wait ( )
outFD4 . close ( )
errFD4 . close ( )
outFD5 = open ( self . testFilePath5 + " .out " , " w " )
errFD5 = open ( self . testFilePath5 + " .err " , " w " )
p5 = subprocess . Popen ( [ ' python3 ' , ' -m ' , ' slither_format ' , ' --verbose-test ' , ' --detect ' , ' naming-convention ' , self . testFilePath5 ] , stdout = outFD5 , stderr = errFD5 )
p5 . wait ( )
outFD5 . close ( )
errFD5 . close ( )
outFD6 = open ( self . testFilePath6 + " .out " , " w " )
errFD6 = open ( self . testFilePath6 + " .err " , " w " )
p6 = subprocess . Popen ( [ ' python3 ' , ' -m ' , ' slither_format ' , ' --verbose-test ' , ' --detect ' , ' naming-convention ' , self . testFilePath6 ] , stdout = outFD6 , stderr = errFD6 )
p6 . wait ( )
outFD6 . close ( )
errFD6 . close ( )
outFD7 = open ( self . testFilePath7 + " .out " , " w " )
errFD7 = open ( self . testFilePath7 + " .err " , " w " )
p7 = subprocess . Popen ( [ ' python3 ' , ' -m ' , ' slither_format ' , ' --verbose-test ' , ' --detect ' , ' naming-convention ' , self . testFilePath7 ] , stdout = outFD7 , stderr = errFD7 )
p7 . wait ( )
outFD7 . close ( )
errFD7 . close ( )
outFD8 = open ( self . testFilePath8 + " .out " , " w " )
errFD8 = open ( self . testFilePath8 + " .err " , " w " )
p8 = subprocess . Popen ( [ ' python3 ' , ' -m ' , ' slither_format ' , ' --verbose-test ' , ' --detect ' , ' naming-convention ' , self . testFilePath8 ] , stdout = outFD8 , stderr = errFD8 )
p8 . wait ( )
outFD8 . close ( )
errFD8 . close ( )
def tearDown ( self ) :
p1 = subprocess . Popen ( [ ' rm ' , ' -f ' , self . testFilePath1 + ' .out ' , self . testFilePath1 + ' .err ' , self . testFilePath1 + ' .format ' ] )
p1 . wait ( )
p2 = subprocess . Popen ( [ ' rm ' , ' -f ' , self . testFilePath2 + ' .out ' , self . testFilePath2 + ' .err ' , self . testFilePath2 + ' .format ' ] )
p2 . wait ( )
p3 = subprocess . Popen ( [ ' rm ' , ' -f ' , self . testFilePath3 + ' .out ' , self . testFilePath3 + ' .err ' , self . testFilePath3 + ' .format ' ] )
p3 . wait ( )
p4 = subprocess . Popen ( [ ' rm ' , ' -f ' , self . testFilePath4 + ' .out ' , self . testFilePath4 + ' .err ' , self . testFilePath4 + ' .format ' ] )
p4 . wait ( )
p5 = subprocess . Popen ( [ ' rm ' , ' -f ' , self . testFilePath5 + ' .out ' , self . testFilePath5 + ' .err ' , self . testFilePath5 + ' .format ' ] )
p5 . wait ( )
p6 = subprocess . Popen ( [ ' rm ' , ' -f ' , self . testFilePath6 + ' .out ' , self . testFilePath6 + ' .err ' , self . testFilePath6 + ' .format ' ] )
p6 . wait ( )
p7 = subprocess . Popen ( [ ' rm ' , ' -f ' , self . testFilePath7 + ' .out ' , self . testFilePath7 + ' .err ' , self . testFilePath7 + ' .format ' ] )
p7 . wait ( )
p8 = subprocess . Popen ( [ ' rm ' , ' -f ' , self . testFilePath8 + ' .out ' , self . testFilePath8 + ' .err ' , self . testFilePath8 + ' .format ' ] )
p8 . wait ( )
def test_naming_convention_contract ( self ) :
errFD1 = open ( self . testFilePath1 + " .err " , " r " )
errFD1_lines = errFD1 . readlines ( )
errFD1 . close ( )
for i in range ( len ( errFD1_lines ) ) :
errFD1_lines [ i ] = errFD1_lines [ i ] . strip ( )
self . assertTrue ( os . path . isfile ( self . testFilePath1 + " .format " ) , " Patched .format file is not created?! " )
self . assertEqual ( errFD1_lines [ 0 ] , " INFO:Slither.Format:Number of Slither results: 2 " )
self . assertEqual ( errFD1_lines [ 1 ] , " INFO:Slither.Format:Number of patches: 10 " )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:Detector: naming-convention (contract definition) " ) , 2 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:Detector: naming-convention (contract state variable) " ) , 2 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:Detector: naming-convention (contract function variable) " ) , 5 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:Detector: naming-convention (contract new object) " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:Old string: contract one " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:New string: contract One " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:Location start: 53 " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:Location end: 65 " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:Old string: three k " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:New string: Three k " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:Location start: 117 " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:Location end: 124 " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:Old string: three l " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:New string: Three l " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:Location start: 206 " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:Location end: 213 " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:Old string: one m " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:New string: One m " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:Location start: 343 " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:Location end: 348 " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:Old string: one n " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:New string: One n " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:Location start: 423 " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:Location end: 428 " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:Old string: contract three " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:New string: contract Three " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:Location start: 498 " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:Location end: 512 " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:Old string: one " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:New string: One " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:Location start: 646 " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:Location end: 649 " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:Old string: one r = new one() " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:New string: One r = new one() " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:Location start: 773 " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:Location end: 790 " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:Old string: one q " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:New string: One q " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:Location start: 871 " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:Location end: 876 " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:Old string: new one() " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:New string: new One() " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:Location start: 781 " ) , 1 )
self . assertEqual ( errFD1_lines . count ( " INFO:Slither.Format:Location end: 788 " ) , 1 )
def test_naming_convention_modifier ( self ) :
errFD2 = open ( self . testFilePath2 + " .err " , " r " )
errFD2_lines = errFD2 . readlines ( )
errFD2 . close ( )
for i in range ( len ( errFD2_lines ) ) :
errFD2_lines [ i ] = errFD2_lines [ i ] . strip ( )
self . assertTrue ( os . path . isfile ( self . testFilePath2 + " .format " ) , " Patched .format file is not created?! " )
self . assertEqual ( errFD2_lines [ 0 ] , " INFO:Slither.Format:Number of Slither results: 2 " )
self . assertEqual ( errFD2_lines [ 1 ] , " INFO:Slither.Format:Number of patches: 5 " )
self . assertEqual ( errFD2_lines . count ( " INFO:Slither.Format:Detector: naming-convention (modifier definition) " ) , 2 )
self . assertEqual ( errFD2_lines . count ( " INFO:Slither.Format:Detector: naming-convention (modifier uses) " ) , 3 )
self . assertEqual ( errFD2_lines . count ( " INFO:Slither.Format:Old string: modifier One " ) , 1 )
self . assertEqual ( errFD2_lines . count ( " INFO:Slither.Format:New string: modifier one " ) , 1 )
self . assertEqual ( errFD2_lines . count ( " INFO:Slither.Format:Location start: 215 " ) , 1 )
self . assertEqual ( errFD2_lines . count ( " INFO:Slither.Format:Location end: 227 " ) , 1 )
self . assertEqual ( errFD2_lines . count ( " INFO:Slither.Format:Old string: () One " ) , 1 )
self . assertEqual ( errFD2_lines . count ( " INFO:Slither.Format:New string: () one " ) , 1 )
self . assertEqual ( errFD2_lines . count ( " INFO:Slither.Format:Location start: 288 " ) , 1 )
self . assertEqual ( errFD2_lines . count ( " INFO:Slither.Format:Location end: 295 " ) , 1 )
self . assertEqual ( errFD2_lines . count ( " INFO:Slither.Format:Old string: modifier Two " ) , 1 )
self . assertEqual ( errFD2_lines . count ( " INFO:Slither.Format:New string: modifier two " ) , 1 )
self . assertEqual ( errFD2_lines . count ( " INFO:Slither.Format:Location start: 423 " ) , 1 )
self . assertEqual ( errFD2_lines . count ( " INFO:Slither.Format:Location end: 435 " ) , 1 )
self . assertEqual ( errFD2_lines . count ( " INFO:Slither.Format:Old string: () one Two returns " ) , 2 )
self . assertEqual ( errFD2_lines . count ( " INFO:Slither.Format:New string: () one two returns " ) , 2 )
self . assertEqual ( errFD2_lines . count ( " INFO:Slither.Format:Location start: 503 " ) , 1 )
self . assertEqual ( errFD2_lines . count ( " INFO:Slither.Format:Location end: 522 " ) , 1 )
self . assertEqual ( errFD2_lines . count ( " INFO:Slither.Format:Location start: 718 " ) , 1 )
self . assertEqual ( errFD2_lines . count ( " INFO:Slither.Format:Location end: 737 " ) , 1 )
def test_naming_convention_structure ( self ) :
errFD3 = open ( self . testFilePath3 + " .err " , " r " )
errFD3_lines = errFD3 . readlines ( )
errFD3 . close ( )
for i in range ( len ( errFD3_lines ) ) :
errFD3_lines [ i ] = errFD3_lines [ i ] . strip ( )
self . assertTrue ( os . path . isfile ( self . testFilePath3 + " .format " ) , " Patched .format file is not created?! " )
self . assertEqual ( errFD3_lines [ 0 ] , " INFO:Slither.Format:Number of Slither results: 2 " )
self . assertEqual ( errFD3_lines [ 1 ] , " INFO:Slither.Format:Number of patches: 8 " )
self . assertEqual ( errFD3_lines . count ( " INFO:Slither.Format:Detector: naming-convention (struct definition) " ) , 2 )
self . assertEqual ( errFD3_lines . count ( " INFO:Slither.Format:Detector: naming-convention (struct use) " ) , 6 )
self . assertEqual ( errFD3_lines . count ( " INFO:Slither.Format:Old string: struct s { uint i; } " ) , 2 )
self . assertEqual ( errFD3_lines . count ( " INFO:Slither.Format:New string: struct S { uint i; } " ) , 2 )
self . assertEqual ( errFD3_lines . count ( " INFO:Slither.Format:Location start: 108 " ) , 1 )
self . assertEqual ( errFD3_lines . count ( " INFO:Slither.Format:Location end: 134 " ) , 1 )
self . assertEqual ( errFD3_lines . count ( " INFO:Slither.Format:Location start: 434 " ) , 1 )
self . assertEqual ( errFD3_lines . count ( " INFO:Slither.Format:Location end: 460 " ) , 1 )
self . assertEqual ( errFD3_lines . count ( " INFO:Slither.Format:Old string: s s1 " ) , 2 )
self . assertEqual ( errFD3_lines . count ( " INFO:Slither.Format:New string: S s1 " ) , 2 )
self . assertEqual ( errFD3_lines . count ( " INFO:Slither.Format:Location start: 171 " ) , 1 )
self . assertEqual ( errFD3_lines . count ( " INFO:Slither.Format:Location end: 175 " ) , 1 )
self . assertEqual ( errFD3_lines . count ( " INFO:Slither.Format:Location start: 497 " ) , 1 )
self . assertEqual ( errFD3_lines . count ( " INFO:Slither.Format:Location end: 501 " ) , 1 )
self . assertEqual ( errFD3_lines . count ( " INFO:Slither.Format:Old string: s sA " ) , 2 )
self . assertEqual ( errFD3_lines . count ( " INFO:Slither.Format:New string: S sA " ) , 2 )
self . assertEqual ( errFD3_lines . count ( " INFO:Slither.Format:Location start: 570 " ) , 1 )
self . assertEqual ( errFD3_lines . count ( " INFO:Slither.Format:Location end: 574 " ) , 1 )
self . assertEqual ( errFD3_lines . count ( " INFO:Slither.Format:Location start: 715 " ) , 1 )
self . assertEqual ( errFD3_lines . count ( " INFO:Slither.Format:Location end: 719 " ) , 1 )
self . assertEqual ( errFD3_lines . count ( " INFO:Slither.Format:Old string: s " ) , 2 )
self . assertEqual ( errFD3_lines . count ( " INFO:Slither.Format:New string: S " ) , 2 )
self . assertEqual ( errFD3_lines . count ( " INFO:Slither.Format:Location start: 585 " ) , 1 )
self . assertEqual ( errFD3_lines . count ( " INFO:Slither.Format:Location end: 586 " ) , 1 )
self . assertEqual ( errFD3_lines . count ( " INFO:Slither.Format:Location start: 730 " ) , 1 )
self . assertEqual ( errFD3_lines . count ( " INFO:Slither.Format:Location end: 731 " ) , 1 )
def test_naming_convention_enum ( self ) :
errFD4 = open ( self . testFilePath4 + " .err " , " r " )
errFD4_lines = errFD4 . readlines ( )
errFD4 . close ( )
for i in range ( len ( errFD4_lines ) ) :
errFD4_lines [ i ] = errFD4_lines [ i ] . strip ( )
self . assertTrue ( os . path . isfile ( self . testFilePath4 + " .format " ) , " Patched .format file is not created?! " )
self . assertEqual ( errFD4_lines [ 0 ] , " INFO:Slither.Format:Number of Slither results: 2 " )
self . assertEqual ( errFD4_lines [ 1 ] , " INFO:Slither.Format:Number of patches: 11 " )
self . assertEqual ( errFD4_lines . count ( " INFO:Slither.Format:Detector: naming-convention (enum definition) " ) , 2 )
self . assertEqual ( errFD4_lines . count ( " INFO:Slither.Format:Detector: naming-convention (enum use) " ) , 9 )
self . assertEqual ( errFD4_lines . count ( " INFO:Slither.Format:Old string: enum e { ONE, TWO} " ) , 2 )
self . assertEqual ( errFD4_lines . count ( " INFO:Slither.Format:New string: enum E { ONE, TWO} " ) , 2 )
self . assertEqual ( errFD4_lines . count ( " INFO:Slither.Format:Location start: 73 " ) , 1 )
self . assertEqual ( errFD4_lines . count ( " INFO:Slither.Format:Location end: 90 " ) , 1 )
self . assertEqual ( errFD4_lines . count ( " INFO:Slither.Format:Location start: 426 " ) , 1 )
self . assertEqual ( errFD4_lines . count ( " INFO:Slither.Format:Location end: 443 " ) , 1 )
self . assertEqual ( errFD4_lines . count ( " INFO:Slither.Format:Old string: e e1 " ) , 2 )
self . assertEqual ( errFD4_lines . count ( " INFO:Slither.Format:New string: E e1 " ) , 2 )
self . assertEqual ( errFD4_lines . count ( " INFO:Slither.Format:Location start: 125 " ) , 1 )
self . assertEqual ( errFD4_lines . count ( " INFO:Slither.Format:Location end: 129 " ) , 1 )
self . assertEqual ( errFD4_lines . count ( " INFO:Slither.Format:Location start: 478 " ) , 1 )
self . assertEqual ( errFD4_lines . count ( " INFO:Slither.Format:Location end: 482 " ) , 1 )
self . assertEqual ( errFD4_lines . count ( " INFO:Slither.Format:Old string: e eA " ) , 2 )
self . assertEqual ( errFD4_lines . count ( " INFO:Slither.Format:New string: E eA " ) , 2 )
self . assertEqual ( errFD4_lines . count ( " INFO:Slither.Format:Location start: 549 " ) , 1 )
self . assertEqual ( errFD4_lines . count ( " INFO:Slither.Format:Location end: 553 " ) , 1 )
self . assertEqual ( errFD4_lines . count ( " INFO:Slither.Format:Location start: 690 " ) , 1 )
self . assertEqual ( errFD4_lines . count ( " INFO:Slither.Format:Location end: 694 " ) , 1 )
self . assertEqual ( errFD4_lines . count ( " INFO:Slither.Format:Old string: e e2 = eA " ) , 2 )
self . assertEqual ( errFD4_lines . count ( " INFO:Slither.Format:New string: E e2 = eA " ) , 2 )
self . assertEqual ( errFD4_lines . count ( " INFO:Slither.Format:Location start: 573 " ) , 1 )
self . assertEqual ( errFD4_lines . count ( " INFO:Slither.Format:Location end: 582 " ) , 1 )
self . assertEqual ( errFD4_lines . count ( " INFO:Slither.Format:Location start: 714 " ) , 1 )
self . assertEqual ( errFD4_lines . count ( " INFO:Slither.Format:Location end: 723 " ) , 1 )
self . assertEqual ( errFD4_lines . count ( " INFO:Slither.Format:Old string: e.ONE " ) , 1 )
self . assertEqual ( errFD4_lines . count ( " INFO:Slither.Format:New string: E.ONE " ) , 1 )
self . assertEqual ( errFD4_lines . count ( " INFO:Slither.Format:Location start: 186 " ) , 1 )
self . assertEqual ( errFD4_lines . count ( " INFO:Slither.Format:Location end: 192 " ) , 1 )
self . assertEqual ( errFD4_lines . count ( " INFO:Slither.Format:Old string: e " ) , 2 )
self . assertEqual ( errFD4_lines . count ( " INFO:Slither.Format:New string: E " ) , 2 )
self . assertEqual ( errFD4_lines . count ( " INFO:Slither.Format:Location start: 564 " ) , 1 )
self . assertEqual ( errFD4_lines . count ( " INFO:Slither.Format:Location end: 565 " ) , 1 )
self . assertEqual ( errFD4_lines . count ( " INFO:Slither.Format:Location start: 705 " ) , 1 )
self . assertEqual ( errFD4_lines . count ( " INFO:Slither.Format:Location end: 706 " ) , 1 )
def test_naming_convention_event ( self ) :
errFD5 = open ( self . testFilePath5 + " .err " , " r " )
errFD5_lines = errFD5 . readlines ( )
errFD5 . close ( )
for i in range ( len ( errFD5_lines ) ) :
errFD5_lines [ i ] = errFD5_lines [ i ] . strip ( )
self . assertTrue ( os . path . isfile ( self . testFilePath5 + " .format " ) , " Patched .format file is not created?! " )
self . assertEqual ( errFD5_lines [ 0 ] , " INFO:Slither.Format:Number of Slither results: 2 " )
self . assertEqual ( errFD5_lines [ 1 ] , " INFO:Slither.Format:Number of patches: 5 " )
self . assertEqual ( errFD5_lines . count ( " INFO:Slither.Format:Detector: naming-convention (event definition) " ) , 2 )
self . assertEqual ( errFD5_lines . count ( " INFO:Slither.Format:Detector: naming-convention (event calls) " ) , 3 )
self . assertEqual ( errFD5_lines . count ( " INFO:Slither.Format:Old string: event e(uint); " ) , 2 )
self . assertEqual ( errFD5_lines . count ( " INFO:Slither.Format:New string: event E(uint); " ) , 2 )
self . assertEqual ( errFD5_lines . count ( " INFO:Slither.Format:Location start: 75 " ) , 1 )
self . assertEqual ( errFD5_lines . count ( " INFO:Slither.Format:Location end: 89 " ) , 1 )
self . assertEqual ( errFD5_lines . count ( " INFO:Slither.Format:Location start: 148 " ) , 1 )
self . assertEqual ( errFD5_lines . count ( " INFO:Slither.Format:Location end: 152 " ) , 1 )
self . assertEqual ( errFD5_lines . count ( " INFO:Slither.Format:Old string: e(i) " ) , 3 )
self . assertEqual ( errFD5_lines . count ( " INFO:Slither.Format:New string: E(i) " ) , 3 )
self . assertEqual ( errFD5_lines . count ( " INFO:Slither.Format:Location start: 148 " ) , 1 )
self . assertEqual ( errFD5_lines . count ( " INFO:Slither.Format:Location end: 152 " ) , 1 )
self . assertEqual ( errFD5_lines . count ( " INFO:Slither.Format:Location start: 438 " ) , 1 )
self . assertEqual ( errFD5_lines . count ( " INFO:Slither.Format:Location end: 442 " ) , 1 )
self . assertEqual ( errFD5_lines . count ( " INFO:Slither.Format:Location start: 550 " ) , 1 )
self . assertEqual ( errFD5_lines . count ( " INFO:Slither.Format:Location end: 554 " ) , 1 )
def test_naming_convention_function ( self ) :
errFD6 = open ( self . testFilePath6 + " .err " , " r " )
errFD6_lines = errFD6 . readlines ( )
errFD6 . close ( )
for i in range ( len ( errFD6_lines ) ) :
errFD6_lines [ i ] = errFD6_lines [ i ] . strip ( )
self . assertTrue ( os . path . isfile ( self . testFilePath6 + " .format " ) , " Patched .format file is not created?! " )
self . assertEqual ( errFD6_lines [ 0 ] , " INFO:Slither.Format:Number of Slither results: 2 " )
self . assertEqual ( errFD6_lines [ 1 ] , " INFO:Slither.Format:Number of patches: 4 " )
self . assertEqual ( errFD6_lines . count ( " INFO:Slither.Format:Detector: naming-convention (function definition) " ) , 2 )
self . assertEqual ( errFD6_lines . count ( " INFO:Slither.Format:Detector: naming-convention (function calls) " ) , 2 )
self . assertEqual ( errFD6_lines . count ( " INFO:Slither.Format:Old string: function Foo " ) , 1 )
self . assertEqual ( errFD6_lines . count ( " INFO:Slither.Format:New string: function foo " ) , 1 )
self . assertEqual ( errFD6_lines . count ( " INFO:Slither.Format:Location start: 76 " ) , 1 )
self . assertEqual ( errFD6_lines . count ( " INFO:Slither.Format:Location end: 88 " ) , 1 )
self . assertEqual ( errFD6_lines . count ( " INFO:Slither.Format:Old string: function Foobar " ) , 1 )
self . assertEqual ( errFD6_lines . count ( " INFO:Slither.Format:New string: function foobar " ) , 1 )
self . assertEqual ( errFD6_lines . count ( " INFO:Slither.Format:Location start: 189 " ) , 1 )
self . assertEqual ( errFD6_lines . count ( " INFO:Slither.Format:Location end: 204 " ) , 1 )
self . assertEqual ( errFD6_lines . count ( " INFO:Slither.Format:Old string: Foobar(10) " ) , 1 )
self . assertEqual ( errFD6_lines . count ( " INFO:Slither.Format:New string: foobar(10) " ) , 1 )
self . assertEqual ( errFD6_lines . count ( " INFO:Slither.Format:Location start: 136 " ) , 1 )
self . assertEqual ( errFD6_lines . count ( " INFO:Slither.Format:Location end: 146 " ) , 1 )
self . assertEqual ( errFD6_lines . count ( " INFO:Slither.Format:Old string: a.Foobar(10) " ) , 1 )
self . assertEqual ( errFD6_lines . count ( " INFO:Slither.Format:New string: a.foobar(10) " ) , 1 )
self . assertEqual ( errFD6_lines . count ( " INFO:Slither.Format:Location start: 516 " ) , 1 )
self . assertEqual ( errFD6_lines . count ( " INFO:Slither.Format:Location end: 528 " ) , 1 )
def test_naming_convention_parameter ( self ) :
errFD7 = open ( self . testFilePath7 + " .err " , " r " )
errFD7_lines = errFD7 . readlines ( )
errFD7 . close ( )
for i in range ( len ( errFD7_lines ) ) :
errFD7_lines [ i ] = errFD7_lines [ i ] . strip ( )
self . assertTrue ( os . path . isfile ( self . testFilePath7 + " .format " ) , " Patched .format file is not created?! " )
self . assertEqual ( errFD7_lines [ 0 ] , " INFO:Slither.Format:Number of Slither results: 6 " )
self . assertEqual ( errFD7_lines [ 1 ] , " INFO:Slither.Format:Number of patches: 12 " )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:Detector: naming-convention (parameter declaration) " ) , 6 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:Detector: naming-convention (parameter uses) " ) , 6 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:Old string: uint Count " ) , 3 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:New string: uint _Count " ) , 3 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:Location start: 91 " ) , 1 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:Location end: 101 " ) , 1 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:Location start: 215 " ) , 1 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:Location end: 225 " ) , 1 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:Old string: Count " ) , 3 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:New string: _Count " ) , 3 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:Location start: 148 " ) , 1 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:Location end: 153 " ) , 1 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:Location start: 308 " ) , 1 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:Location end: 313 " ) , 1 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:Location start: 489 " ) , 1 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:Location end: 499 " ) , 1 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:Location start: 580 " ) , 1 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:Location end: 585 " ) , 1 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:Old string: Count) " ) , 1 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:New string: _Count) " ) , 1 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:Location start: 506 " ) , 1 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:Location end: 512 " ) , 1 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:Old string: uint Number " ) , 1 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:New string: uint _Number " ) , 1 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:Location start: 227 " ) , 1 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:Location end: 238 " ) , 1 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:Old string: Number " ) , 1 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:New string: _Number " ) , 1 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:Location start: 314 " ) , 1 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:Location end: 320 " ) , 1 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:Old string: address _to " ) , 1 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:New string: address _To " ) , 1 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:Location start: 708 " ) , 1 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:Location end: 719 " ) , 1 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:Old string: address _from " ) , 1 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:New string: address _From " ) , 1 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:Location start: 721 " ) , 1 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:Location end: 734 " ) , 1 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:Old string: _to " ) , 1 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:New string: _To " ) , 1 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:Location start: 811 " ) , 1 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:Location end: 814 " ) , 1 )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:Old string: _from " ) , 1 , " Index variables of writes are not captured by node._expression_vars_read of Slither " )
self . assertEqual ( errFD7_lines . count ( " INFO:Slither.Format:New string: _From " ) , 1 )
def test_naming_convention_state_variable ( self ) :
errFD8 = open ( self . testFilePath8 + " .err " , " r " )
errFD8_lines = errFD8 . readlines ( )
errFD8 . close ( )
for i in range ( len ( errFD8_lines ) ) :
errFD8_lines [ i ] = errFD8_lines [ i ] . strip ( )
self . assertTrue ( os . path . isfile ( self . testFilePath8 + " .format " ) , " Patched .format file is not created?! " )
self . assertEqual ( errFD8_lines [ 0 ] , " INFO:Slither.Format:Number of Slither results: 3 " )
self . assertEqual ( errFD8_lines [ 1 ] , " INFO:Slither.Format:Number of patches: 9 " )
self . assertEqual ( errFD8_lines . count ( " INFO:Slither.Format:Detector: naming-convention (state variable declaration) " ) , 3 )
self . assertEqual ( errFD8_lines . count ( " INFO:Slither.Format:Detector: naming-convention (state variable uses) " ) , 6 )
self . assertEqual ( errFD8_lines . count ( " INFO:Slither.Format:Old string: number " ) , 3 )
self . assertEqual ( errFD8_lines . count ( " INFO:Slither.Format:New string: NUMBER " ) , 3 )
self . assertEqual ( errFD8_lines . count ( " INFO:Slither.Format:Location start: 469 " ) , 1 )
self . assertEqual ( errFD8_lines . count ( " INFO:Slither.Format:Location end: 475 " ) , 1 )
self . assertEqual ( errFD8_lines . count ( " INFO:Slither.Format:Location start: 716 " ) , 1 )
self . assertEqual ( errFD8_lines . count ( " INFO:Slither.Format:Location end: 722 " ) , 1 )
self . assertEqual ( errFD8_lines . count ( " INFO:Slither.Format:Location start: 850 " ) , 1 )
self . assertEqual ( errFD8_lines . count ( " INFO:Slither.Format:Location end: 856 " ) , 1 )
self . assertEqual ( errFD8_lines . count ( " INFO:Slither.Format:Old string: Count " ) , 3 )
self . assertEqual ( errFD8_lines . count ( " INFO:Slither.Format:New string: count " ) , 3 )
self . assertEqual ( errFD8_lines . count ( " INFO:Slither.Format:Location start: 547 " ) , 1 )
self . assertEqual ( errFD8_lines . count ( " INFO:Slither.Format:Location end: 552 " ) , 1 )
self . assertEqual ( errFD8_lines . count ( " INFO:Slither.Format:Location start: 725 " ) , 1 )
self . assertEqual ( errFD8_lines . count ( " INFO:Slither.Format:Location end: 730 " ) , 1 )
self . assertEqual ( errFD8_lines . count ( " INFO:Slither.Format:Location start: 745 " ) , 1 )
self . assertEqual ( errFD8_lines . count ( " INFO:Slither.Format:Location end: 750 " ) , 1 )
self . assertEqual ( errFD8_lines . count ( " INFO:Slither.Format:Old string: Maxnum " ) , 3 )
self . assertEqual ( errFD8_lines . count ( " INFO:Slither.Format:New string: maxnum " ) , 3 )
self . assertEqual ( errFD8_lines . count ( " INFO:Slither.Format:Location start: 634 " ) , 1 )
self . assertEqual ( errFD8_lines . count ( " INFO:Slither.Format:Location end: 640 " ) , 1 )
self . assertEqual ( errFD8_lines . count ( " INFO:Slither.Format:Location start: 733 " ) , 1 )
self . assertEqual ( errFD8_lines . count ( " INFO:Slither.Format:Location end: 739 " ) , 1 )
self . assertEqual ( errFD8_lines . count ( " INFO:Slither.Format:Location start: 859 " ) , 1 )
self . assertEqual ( errFD8_lines . count ( " INFO:Slither.Format:Location end: 865 " ) , 1 )
if __name__ == ' __main__ ' :
unittest . main ( )