mirror of https://github.com/crytic/slither
parent
f60e4d4915
commit
3e68ffc8a2
@ -0,0 +1,48 @@ |
||||
pragma solidity ^0.4.24; |
||||
|
||||
contract A { |
||||
|
||||
/* constant state variable naming - bad */ |
||||
/* unused state variable - bad */ |
||||
/* Overlapping detectors - so neither will be applied for now */ |
||||
uint max_tx = 100; |
||||
|
||||
/* state variable declaration naming convention - bad */ |
||||
uint SV_count = 0; |
||||
|
||||
modifier mod (uint c) { |
||||
require (c > 100); |
||||
_; |
||||
} |
||||
|
||||
/* parameter declaration naming convention - bad */ |
||||
function foo(uint Count) { |
||||
/* parameter use naming convention- bad */ |
||||
/* state variable use naming convention - bad */ |
||||
SV_count = Count; |
||||
} |
||||
|
||||
/* implicitly public, can be made external - bad */ |
||||
/* parameter declarations naming convention - bad */ |
||||
function foobar(uint Count, uint Number) returns (uint) { |
||||
/* parameter use naming convention - bad */ |
||||
foo (Number); |
||||
/* parameter use naming convention - bad */ |
||||
return (Count+Number); |
||||
} |
||||
|
||||
/* explicitly public, can be made external - bad */ |
||||
/* view but modifies state - bad */ |
||||
/* parameter declarations naming convention - bad */ |
||||
/* parameter use passed to modifier naming convention - bad */ |
||||
function bar(uint Count) public view mod (Count) returns(uint) { |
||||
/* Use of state variable naming convention - bad */ |
||||
/* Use of parameter naming convention - bad */ |
||||
SV_count += Count; |
||||
/* Use of state variable naming convention - bad */ |
||||
return (SV_count); |
||||
} |
||||
|
||||
} |
||||
|
||||
|
@ -0,0 +1,40 @@ |
||||
import unittest |
||||
import subprocess, os, sys |
||||
|
||||
class TestDetectorCombinations(unittest.TestCase): |
||||
testDataDir = "./slither_format/tests/test_data/" |
||||
testDataFile1 = "detector_combinations.sol" |
||||
testFilePath1 = testDataDir+testDataFile1 |
||||
|
||||
def setUp(self): |
||||
outFD1 = open(self.testFilePath1+".out","w") |
||||
errFD1 = open(self.testFilePath1+".err","w") |
||||
p1 = subprocess.Popen(['python3', '-m', 'slither_format','--verbose-test',self.testFilePath1], stdout=outFD1,stderr=errFD1) |
||||
p1.wait() |
||||
outFD1.close() |
||||
errFD1.close() |
||||
|
||||
def tearDown(self): |
||||
p1 = subprocess.Popen(['rm','-f',self.testFilePath1+'.out',self.testFilePath1+'.err',self.testFilePath1+'.format']) |
||||
p1.wait() |
||||
|
||||
def test_detector_combinations(self): |
||||
outFD1 = open(self.testFilePath1+".out","r") |
||||
outFD1_lines = outFD1.readlines() |
||||
outFD1.close() |
||||
for i in range(len(outFD1_lines)): |
||||
outFD1_lines[i] = outFD1_lines[i].strip() |
||||
self.assertTrue(os.path.isfile(self.testFilePath1+".format"),"Patched .format file is not created?!") |
||||
self.assertEqual(outFD1_lines.count("Number of Slither results: 11"), 1) |
||||
self.assertEqual(outFD1_lines.count("Number of patches: 18"), 1) |
||||
self.assertEqual(outFD1_lines.count("Overlapping patch won't be applied!"), 2) |
||||
self.assertEqual(outFD1_lines.count("xDetector: unused-state"), 1) |
||||
self.assertEqual(outFD1_lines.count("xDetector: constable-states"), 1) |
||||
self.assertEqual(outFD1_lines.count("Detector: naming-convention (state variable declaration)"), 2) |
||||
self.assertEqual(outFD1_lines.count("Detector: naming-convention (state variable uses)"), 3) |
||||
self.assertEqual(outFD1_lines.count("Detector: naming-convention (parameter declaration)"), 4) |
||||
self.assertEqual(outFD1_lines.count("Detector: naming-convention (parameter uses)"), 6) |
||||
self.assertEqual(outFD1_lines.count("Detector: external-function"), 2) |
||||
self.assertEqual(outFD1_lines.count("Detector: constant-function"), 1) |
||||
if __name__ == '__main__': |
||||
unittest.main() |
Loading…
Reference in new issue