forked from crytic/slither
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_features.py
71 lines (47 loc) · 2.22 KB
/
test_features.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import inspect
from crytic_compile import CryticCompile
from crytic_compile.platform.solc_standard_json import SolcStandardJson
from solc_select import solc_select
from slither import Slither
from slither.detectors import all_detectors
from slither.detectors.abstract_detector import AbstractDetector
def _run_all_detectors(slither: Slither) -> None:
detectors = [getattr(all_detectors, name) for name in dir(all_detectors)]
detectors = [d for d in detectors if inspect.isclass(d) and issubclass(d, AbstractDetector)]
for detector in detectors:
slither.register_detector(detector)
slither.run_detectors()
def test_node() -> None:
# hardhat must have been installed in tests/test_node_modules
# For the CI its done through the github action config
slither = Slither("./tests/test_node_modules")
_run_all_detectors(slither)
def test_collision() -> None:
standard_json = SolcStandardJson()
standard_json.add_source_file("./tests/collisions/a.sol")
standard_json.add_source_file("./tests/collisions/b.sol")
compilation = CryticCompile(standard_json)
slither = Slither(compilation)
_run_all_detectors(slither)
def test_cycle() -> None:
slither = Slither("./tests/test_cyclic_import/a.sol")
_run_all_detectors(slither)
def test_funcion_id_rec_structure() -> None:
solc_select.switch_global_version("0.8.0", always_install=True)
slither = Slither("./tests/function_ids/rec_struct-0.8.sol")
for compilation_unit in slither.compilation_units:
for function in compilation_unit.functions:
assert function.solidity_signature
def test_upgradeable_comments() -> None:
solc_select.switch_global_version("0.8.10", always_install=True)
slither = Slither("./tests/custom_comments/upgrade.sol")
compilation_unit = slither.compilation_units[0]
proxy = compilation_unit.get_contract_from_name("Proxy")[0]
assert proxy.is_upgradeable_proxy
v0 = compilation_unit.get_contract_from_name("V0")[0]
assert v0.is_upgradeable
print(v0.upgradeable_version)
assert v0.upgradeable_version == "version-0"
v1 = compilation_unit.get_contract_from_name("V1")[0]
assert v0.is_upgradeable
assert v1.upgradeable_version == "version_1"