simplify using reviewer suggestions

pull/1808/head
alpharush 2 years ago
parent 0d3115fda0
commit 07fcb5c149
  1. 9
      Makefile
  2. 31
      tests/conftest.py
  3. 9
      tests/e2e/compilation/test_resolution.py
  4. 4
      tests/tools/read-storage/test_read_storage.py
  5. 5
      tests/unit/core/test_arithmetic.py
  6. 18
      tests/unit/core/test_code_comments.py
  7. 20
      tests/unit/core/test_constant_folding.py
  8. 21
      tests/unit/core/test_contract_declaration.py
  9. 17
      tests/unit/core/test_function_declaration.py
  10. 12
      tests/unit/core/test_source_mapping.py
  11. 5
      tests/unit/core/test_storage_layout.py
  12. 43
      tests/unit/core/test_using_for.py
  13. 5
      tests/unit/slithir/test_operation_reads.py
  14. 5
      tests/unit/slithir/test_ssa_generation.py
  15. 4
      tests/unit/slithir/test_ternary_expressions.py
  16. 5
      tests/unit/utils/test_code_generation.py
  17. 5
      tests/unit/utils/test_functions_ids.py
  18. 5
      tests/unit/utils/test_type_helpers.py

@ -1,6 +1,7 @@
SHELL := /bin/bash SHELL := /bin/bash
PY_MODULE := slither PY_MODULE := slither
TEST_MODULE := tests
ALL_PY_SRCS := $(shell find $(PY_MODULE) -name '*.py') \ ALL_PY_SRCS := $(shell find $(PY_MODULE) -name '*.py') \
$(shell find test -name '*.py') $(shell find test -name '*.py')
@ -33,7 +34,7 @@ ifneq ($(TESTS),)
COV_ARGS := COV_ARGS :=
else else
TEST_ARGS := -n auto TEST_ARGS := -n auto
COV_ARGS := --cov-append # --fail-under 100 COV_ARGS := # --fail-under 100
endif endif
.PHONY: all .PHONY: all
@ -56,15 +57,15 @@ $(VENV)/pyvenv.cfg: pyproject.toml
.PHONY: lint .PHONY: lint
lint: $(VENV)/pyvenv.cfg lint: $(VENV)/pyvenv.cfg
. $(VENV_BIN)/activate && \ . $(VENV_BIN)/activate && \
black --check $(ALL_PY_SRCS) && \ black --check . && \
pylint $(ALL_PY_SRCS) pylint $(PY_MODULE) $(TEST_MODULE)
# ruff $(ALL_PY_SRCS) && \ # ruff $(ALL_PY_SRCS) && \
# mypy $(PY_MODULE) && # mypy $(PY_MODULE) &&
.PHONY: reformat .PHONY: reformat
reformat: reformat:
. $(VENV_BIN)/activate && \ . $(VENV_BIN)/activate && \
black $(PY_MODULE) black .
.PHONY: test tests .PHONY: test tests
test tests: $(VENV)/pyvenv.cfg test tests: $(VENV)/pyvenv.cfg

@ -2,26 +2,15 @@ import pytest
from filelock import FileLock from filelock import FileLock
from solc_select import solc_select from solc_select import solc_select
@pytest.fixture(scope="session")
def solc_versions_installed():
"""List of solc versions available in the test environment."""
return []
@pytest.fixture(scope="session", autouse=True)
def register_solc_versions_installed(solc_versions_installed):
solc_versions_installed.extend(solc_select.installed_versions())
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
def use_solc_version(request, solc_versions_installed): def solc_binary_path():
def _use_solc_version(version): def inner(version):
print(version) lock = FileLock(f"{version}.lock", timeout=60)
if version not in solc_versions_installed: with lock:
print("Installing solc version", version) if not solc_select.artifact_path(version).exists():
solc_select.install_artifacts([version]) print("Installing solc version", version)
artifact_path = solc_select.artifact_path(version) solc_select.install_artifacts([version])
lock = FileLock(artifact_path) return solc_select.artifact_path(version)
try:
yield artifact_path return inner
finally:
lock.release()
return _use_solc_version

@ -3,7 +3,6 @@ import pytest
from crytic_compile import CryticCompile from crytic_compile import CryticCompile
from crytic_compile.platform.solc_standard_json import SolcStandardJson from crytic_compile.platform.solc_standard_json import SolcStandardJson
from solc_select import solc_select
from slither import Slither from slither import Slither
@ -24,8 +23,8 @@ def test_node_modules() -> None:
_run_all_detectors(slither) _run_all_detectors(slither)
def test_contract_name_collision(use_solc_version) -> None: def test_contract_name_collision(solc_binary_path) -> None:
solc_path = next(use_solc_version("0.8.0")) solc_path = solc_binary_path("0.8.0")
standard_json = SolcStandardJson() standard_json = SolcStandardJson()
standard_json.add_source_file( standard_json.add_source_file(
Path(TEST_DATA_DIR, "test_contract_name_collisions", "a.sol").as_posix() Path(TEST_DATA_DIR, "test_contract_name_collisions", "a.sol").as_posix()
@ -40,7 +39,7 @@ def test_contract_name_collision(use_solc_version) -> None:
_run_all_detectors(slither) _run_all_detectors(slither)
def test_cycle(use_solc_version) -> None: def test_cycle(solc_binary_path) -> None:
solc_path = next(use_solc_version("0.8.0")) solc_path = solc_binary_path("0.8.0")
slither = Slither(Path(TEST_DATA_DIR, "test_cyclic_import", "a.sol").as_posix(), solc=solc_path) slither = Slither(Path(TEST_DATA_DIR, "test_cyclic_import", "a.sol").as_posix(), solc=solc_path)
_run_all_detectors(slither) _run_all_detectors(slither)

@ -90,8 +90,8 @@ def deploy_contract(w3, ganache, contract_bin, contract_abi) -> Contract:
# pylint: disable=too-many-locals # pylint: disable=too-many-locals
@pytest.mark.usefixtures("web3", "ganache") @pytest.mark.usefixtures("web3", "ganache")
def test_read_storage(web3, ganache, use_solc_version) -> None: def test_read_storage(web3, ganache, solc_binary_path) -> None:
solc_path = next(use_solc_version(version="0.8.10")) solc_path = solc_binary_path(version="0.8.10")
assert web3.is_connected() assert web3.is_connected()
bin_path = Path(TEST_DATA_DIR, "StorageLayout.bin").as_posix() bin_path = Path(TEST_DATA_DIR, "StorageLayout.bin").as_posix()

@ -1,5 +1,4 @@
from pathlib import Path from pathlib import Path
from solc_select import solc_select
from slither import Slither from slither import Slither
from slither.utils.arithmetic import unchecked_arithemtic_usage from slither.utils.arithmetic import unchecked_arithemtic_usage
@ -8,8 +7,8 @@ from slither.utils.arithmetic import unchecked_arithemtic_usage
TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data" / "arithmetic_usage" TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data" / "arithmetic_usage"
def test_arithmetic_usage(use_solc_version) -> None: def test_arithmetic_usage(solc_binary_path) -> None:
solc_path = next(use_solc_version("0.8.15")) solc_path = solc_binary_path("0.8.15")
slither = Slither(Path(TEST_DATA_DIR, "test.sol").as_posix(), solc=solc_path) slither = Slither(Path(TEST_DATA_DIR, "test.sol").as_posix(), solc=solc_path)
assert { assert {

@ -8,8 +8,8 @@ TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data"
CUSTOM_COMMENTS_TEST_DATA_DIR = Path(TEST_DATA_DIR, "custom_comments") CUSTOM_COMMENTS_TEST_DATA_DIR = Path(TEST_DATA_DIR, "custom_comments")
def test_upgradeable_comments(use_solc_version) -> None: def test_upgradeable_comments(solc_binary_path) -> None:
solc_path = next(use_solc_version("0.8.10")) solc_path = solc_binary_path("0.8.10")
slither = Slither(Path(CUSTOM_COMMENTS_TEST_DATA_DIR, "upgrade.sol").as_posix(), solc=solc_path) slither = Slither(Path(CUSTOM_COMMENTS_TEST_DATA_DIR, "upgrade.sol").as_posix(), solc=solc_path)
compilation_unit = slither.compilation_units[0] compilation_unit = slither.compilation_units[0]
proxy = compilation_unit.get_contract_from_name("Proxy")[0] proxy = compilation_unit.get_contract_from_name("Proxy")[0]
@ -27,11 +27,13 @@ def test_upgradeable_comments(use_solc_version) -> None:
assert v1.upgradeable_version == "version_1" assert v1.upgradeable_version == "version_1"
def test_contract_comments(use_solc_version) -> None: def test_contract_comments(solc_binary_path) -> None:
comments = " @title Test Contract\n @dev Test comment" comments = " @title Test Contract\n @dev Test comment"
solc_path = next(use_solc_version("0.8.10")) solc_path = solc_binary_path("0.8.10")
slither = Slither(Path(CUSTOM_COMMENTS_TEST_DATA_DIR, "contract_comment.sol").as_posix(), solc=solc_path) slither = Slither(
Path(CUSTOM_COMMENTS_TEST_DATA_DIR, "contract_comment.sol").as_posix(), solc=solc_path
)
compilation_unit = slither.compilation_units[0] compilation_unit = slither.compilation_units[0]
contract = compilation_unit.get_contract_from_name("A")[0] contract = compilation_unit.get_contract_from_name("A")[0]
@ -40,8 +42,10 @@ def test_contract_comments(use_solc_version) -> None:
# Old solc versions have a different parsing of comments # Old solc versions have a different parsing of comments
# the initial space (after *) is also not kept on every line # the initial space (after *) is also not kept on every line
comments = "@title Test Contract\n@dev Test comment" comments = "@title Test Contract\n@dev Test comment"
solc_path = next(use_solc_version("0.5.16")) solc_path = solc_binary_path("0.5.16")
slither = Slither(Path(CUSTOM_COMMENTS_TEST_DATA_DIR, "contract_comment.sol").as_posix(), solc=solc_path) slither = Slither(
Path(CUSTOM_COMMENTS_TEST_DATA_DIR, "contract_comment.sol").as_posix(), solc=solc_path
)
compilation_unit = slither.compilation_units[0] compilation_unit = slither.compilation_units[0]
contract = compilation_unit.get_contract_from_name("A")[0] contract = compilation_unit.get_contract_from_name("A")[0]

@ -6,15 +6,17 @@ TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data"
CONSTANT_FOLDING_TEST_ROOT = Path(TEST_DATA_DIR, "constant_folding") CONSTANT_FOLDING_TEST_ROOT = Path(TEST_DATA_DIR, "constant_folding")
def test_constant_folding_unary(use_solc_version): def test_constant_folding_unary(solc_binary_path):
solc_path = next(use_solc_version("0.8.0")) solc_path = solc_binary_path("0.8.0")
file = Path(CONSTANT_FOLDING_TEST_ROOT, "constant_folding_unary.sol").as_posix() file = Path(CONSTANT_FOLDING_TEST_ROOT, "constant_folding_unary.sol").as_posix()
Slither(file, solc=solc_path) Slither(file, solc=solc_path)
def test_constant_folding_rational(use_solc_version): def test_constant_folding_rational(solc_binary_path):
solc_path = next(use_solc_version("0.8.0")) solc_path = solc_binary_path("0.8.0")
s = Slither(Path(CONSTANT_FOLDING_TEST_ROOT, "constant_folding_rational.sol").as_posix(), solc=solc_path) s = Slither(
Path(CONSTANT_FOLDING_TEST_ROOT, "constant_folding_rational.sol").as_posix(), solc=solc_path
)
contract = s.get_contract_from_name("C")[0] contract = s.get_contract_from_name("C")[0]
variable_a = contract.get_state_variable_from_name("a") variable_a = contract.get_state_variable_from_name("a")
@ -52,9 +54,11 @@ def test_constant_folding_rational(use_solc_version):
assert str(ConstantFolding(variable_g.expression, "int64").result()) == "-7" assert str(ConstantFolding(variable_g.expression, "int64").result()) == "-7"
def test_constant_folding_binary_expressions(use_solc_version): def test_constant_folding_binary_expressions(solc_binary_path):
solc_path = next(use_solc_version("0.8.0")) solc_path = solc_binary_path("0.8.0")
sl = Slither(Path(CONSTANT_FOLDING_TEST_ROOT, "constant_folding_binop.sol").as_posix(), solc=solc_path) sl = Slither(
Path(CONSTANT_FOLDING_TEST_ROOT, "constant_folding_binop.sol").as_posix(), solc=solc_path
)
contract = sl.get_contract_from_name("BinOp")[0] contract = sl.get_contract_from_name("BinOp")[0]
variable_a = contract.get_state_variable_from_name("a") variable_a = contract.get_state_variable_from_name("a")

@ -1,6 +1,5 @@
from pathlib import Path from pathlib import Path
from solc_select import solc_select
from slither import Slither from slither import Slither
from slither.core.variables.state_variable import StateVariable from slither.core.variables.state_variable import StateVariable
@ -9,26 +8,30 @@ TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data"
CONTRACT_DECL_TEST_ROOT = Path(TEST_DATA_DIR, "contract_declaration") CONTRACT_DECL_TEST_ROOT = Path(TEST_DATA_DIR, "contract_declaration")
def test_abstract_contract(use_solc_version) -> None: def test_abstract_contract(solc_binary_path) -> None:
solc_path = next(use_solc_version("0.8.0")) solc_path = solc_binary_path("0.8.0")
slither = Slither(Path(CONTRACT_DECL_TEST_ROOT, "abstract.sol").as_posix(), solc=solc_path) slither = Slither(Path(CONTRACT_DECL_TEST_ROOT, "abstract.sol").as_posix(), solc=solc_path)
assert not slither.contracts[0].is_fully_implemented assert not slither.contracts[0].is_fully_implemented
solc_path = next(use_solc_version("0.5.0")) solc_path = solc_binary_path("0.5.0")
slither = Slither(Path(CONTRACT_DECL_TEST_ROOT, "implicit_abstract.sol").as_posix(), solc=solc_path) slither = Slither(
Path(CONTRACT_DECL_TEST_ROOT, "implicit_abstract.sol").as_posix(), solc=solc_path
)
assert not slither.contracts[0].is_fully_implemented assert not slither.contracts[0].is_fully_implemented
slither = Slither( slither = Slither(
Path(CONTRACT_DECL_TEST_ROOT, "implicit_abstract.sol").as_posix(), Path(CONTRACT_DECL_TEST_ROOT, "implicit_abstract.sol").as_posix(),
solc_force_legacy_json=True, solc_force_legacy_json=True,
solc=solc_path solc=solc_path,
) )
assert not slither.contracts[0].is_fully_implemented assert not slither.contracts[0].is_fully_implemented
def test_private_variable(use_solc_version) -> None: def test_private_variable(solc_binary_path) -> None:
solc_path = next(use_solc_version("0.8.15")) solc_path = solc_binary_path("0.8.15")
slither = Slither(Path(CONTRACT_DECL_TEST_ROOT, "private_variable.sol").as_posix(), solc=solc_path) slither = Slither(
Path(CONTRACT_DECL_TEST_ROOT, "private_variable.sol").as_posix(), solc=solc_path
)
contract_c = slither.get_contract_from_name("C")[0] contract_c = slither.get_contract_from_name("C")[0]
f = contract_c.functions[0] f = contract_c.functions[0]
var_read = f.variables_read[0] var_read = f.variables_read[0]

@ -5,7 +5,6 @@ tests that `tests/test_function.sol` gets translated into correct
and that these objects behave correctly. and that these objects behave correctly.
""" """
from pathlib import Path from pathlib import Path
from solc_select import solc_select
from slither import Slither from slither import Slither
from slither.core.declarations.function import FunctionType from slither.core.declarations.function import FunctionType
@ -15,9 +14,9 @@ TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data"
FUNC_DELC_TEST_ROOT = Path(TEST_DATA_DIR, "function_declaration") FUNC_DELC_TEST_ROOT = Path(TEST_DATA_DIR, "function_declaration")
def test_functions(use_solc_version): def test_functions(solc_binary_path):
# pylint: disable=too-many-statements # pylint: disable=too-many-statements
solc_path = next(use_solc_version("0.6.12")) solc_path = solc_binary_path("0.6.12")
file = Path(FUNC_DELC_TEST_ROOT, "test_function.sol").as_posix() file = Path(FUNC_DELC_TEST_ROOT, "test_function.sol").as_posix()
slither = Slither(file, solc=solc_path) slither = Slither(file, solc=solc_path)
functions = slither.get_contract_from_name("TestFunction")[0].available_functions_as_dict() functions = slither.get_contract_from_name("TestFunction")[0].available_functions_as_dict()
@ -248,8 +247,8 @@ def test_functions(use_solc_version):
assert f.return_type[0] == ElementaryType("bool") assert f.return_type[0] == ElementaryType("bool")
def test_function_can_send_eth(use_solc_version): def test_function_can_send_eth(solc_binary_path):
solc_path = next(use_solc_version("0.6.12")) solc_path = solc_binary_path("0.6.12")
file = Path(FUNC_DELC_TEST_ROOT, "test_function.sol").as_posix() file = Path(FUNC_DELC_TEST_ROOT, "test_function.sol").as_posix()
slither = Slither(file, solc=solc_path) slither = Slither(file, solc=solc_path)
compilation_unit = slither.compilation_units[0] compilation_unit = slither.compilation_units[0]
@ -273,8 +272,8 @@ def test_function_can_send_eth(use_solc_version):
assert functions["highlevel_call_via_external()"].can_send_eth() is False assert functions["highlevel_call_via_external()"].can_send_eth() is False
def test_reentrant(use_solc_version): def test_reentrant(solc_binary_path):
solc_path = next(use_solc_version("0.8.10")) solc_path = solc_binary_path("0.8.10")
file = Path(FUNC_DELC_TEST_ROOT, "test_function_reentrant.sol").as_posix() file = Path(FUNC_DELC_TEST_ROOT, "test_function_reentrant.sol").as_posix()
slither = Slither(file, solc=solc_path) slither = Slither(file, solc=solc_path)
compilation_unit = slither.compilation_units[0] compilation_unit = slither.compilation_units[0]
@ -290,8 +289,8 @@ def test_reentrant(use_solc_version):
assert functions["internal_and_reentrant()"].is_reentrant assert functions["internal_and_reentrant()"].is_reentrant
def test_public_variable(use_solc_version) -> None: def test_public_variable(solc_binary_path) -> None:
solc_path = next(use_solc_version("0.6.12")) solc_path = solc_binary_path("0.6.12")
file = Path(FUNC_DELC_TEST_ROOT, "test_function.sol").as_posix() file = Path(FUNC_DELC_TEST_ROOT, "test_function.sol").as_posix()
slither = Slither(file, solc=solc_path) slither = Slither(file, solc=solc_path)
contracts = slither.get_contract_from_name("TestFunction") contracts = slither.get_contract_from_name("TestFunction")

@ -8,8 +8,8 @@ TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data"
SRC_MAPPING_TEST_ROOT = Path(TEST_DATA_DIR, "src_mapping") SRC_MAPPING_TEST_ROOT = Path(TEST_DATA_DIR, "src_mapping")
def test_source_mapping(use_solc_version): def test_source_mapping(solc_binary_path):
solc_path = next(use_solc_version("0.6.12")) solc_path = solc_binary_path("0.6.12")
file = Path(SRC_MAPPING_TEST_ROOT, "inheritance.sol").as_posix() file = Path(SRC_MAPPING_TEST_ROOT, "inheritance.sol").as_posix()
slither = Slither(file, solc=solc_path) slither = Slither(file, solc=solc_path)
@ -78,11 +78,11 @@ def _sort_references_lines(refs: list) -> list:
return sorted([ref.lines[0] for ref in refs]) return sorted([ref.lines[0] for ref in refs])
def test_references_user_defined_aliases(use_solc_version): def test_references_user_defined_aliases(solc_binary_path):
""" """
Tests if references are filled correctly for user defined aliases (declared using "type [...] is [...]" statement). Tests if references are filled correctly for user defined aliases (declared using "type [...] is [...]" statement).
""" """
solc_path = next(use_solc_version("0.8.16")) solc_path = solc_binary_path("0.8.16")
file = Path(SRC_MAPPING_TEST_ROOT, "ReferencesUserDefinedAliases.sol").as_posix() file = Path(SRC_MAPPING_TEST_ROOT, "ReferencesUserDefinedAliases.sol").as_posix()
slither = Slither(file, solc=solc_path) slither = Slither(file, solc=solc_path)
@ -101,11 +101,11 @@ def test_references_user_defined_aliases(use_solc_version):
assert lines == [13, 16] assert lines == [13, 16]
def test_references_user_defined_types_when_casting(use_solc_version): def test_references_user_defined_types_when_casting(solc_binary_path):
""" """
Tests if references are filled correctly for user defined types in case of casting. Tests if references are filled correctly for user defined types in case of casting.
""" """
solc_path = next(use_solc_version("0.8.16")) solc_path = solc_binary_path("0.8.16")
file = Path(SRC_MAPPING_TEST_ROOT, "ReferencesUserDefinedTypesCasting.sol").as_posix() file = Path(SRC_MAPPING_TEST_ROOT, "ReferencesUserDefinedTypesCasting.sol").as_posix()
slither = Slither(file, solc=solc_path) slither = Slither(file, solc=solc_path)

@ -1,16 +1,15 @@
import json import json
from pathlib import Path from pathlib import Path
from subprocess import PIPE, Popen from subprocess import PIPE, Popen
from solc_select import solc_select
from slither import Slither from slither import Slither
TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data" TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data"
STORAGE_TEST_ROOT = Path(TEST_DATA_DIR, "storage_layout") STORAGE_TEST_ROOT = Path(TEST_DATA_DIR, "storage_layout")
def test_storage_layout(use_solc_version): def test_storage_layout(solc_binary_path):
# the storage layout has not yet changed between solidity versions so we will test with one version of the compiler # the storage layout has not yet changed between solidity versions so we will test with one version of the compiler
solc_path = next(use_solc_version("0.8.10")) solc_path = solc_binary_path("0.8.10")
test_item = Path(STORAGE_TEST_ROOT, "storage_layout-0.8.10.sol").as_posix() test_item = Path(STORAGE_TEST_ROOT, "storage_layout-0.8.10.sol").as_posix()
sl = Slither(test_item, disallow_partial=True, solc=solc_path) sl = Slither(test_item, disallow_partial=True, solc=solc_path)

@ -1,7 +1,6 @@
from pathlib import Path from pathlib import Path
from crytic_compile import CryticCompile from crytic_compile import CryticCompile
from crytic_compile.platform.solc_standard_json import SolcStandardJson from crytic_compile.platform.solc_standard_json import SolcStandardJson
from solc_select import solc_select
from slither import Slither from slither import Slither
from slither.slithir.operations import InternalCall, LibraryCall from slither.slithir.operations import InternalCall, LibraryCall
@ -12,8 +11,8 @@ TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data"
USING_FOR_TEST_DATA_DIR = Path(TEST_DATA_DIR, "using_for") USING_FOR_TEST_DATA_DIR = Path(TEST_DATA_DIR, "using_for")
def test_using_for_global_collision(use_solc_version) -> None: def test_using_for_global_collision(solc_binary_path) -> None:
solc_path = next(use_solc_version("0.8.15")) solc_path = solc_binary_path("0.8.15")
standard_json = SolcStandardJson() standard_json = SolcStandardJson()
for source_file in Path(USING_FOR_TEST_DATA_DIR, "using_for_global_collision").rglob("*.sol"): for source_file in Path(USING_FOR_TEST_DATA_DIR, "using_for_global_collision").rglob("*.sol"):
standard_json.add_source_file(Path(source_file).as_posix()) standard_json.add_source_file(Path(source_file).as_posix())
@ -22,9 +21,11 @@ def test_using_for_global_collision(use_solc_version) -> None:
_run_all_detectors(sl) _run_all_detectors(sl)
def test_using_for_top_level_same_name(use_solc_version) -> None: def test_using_for_top_level_same_name(solc_binary_path) -> None:
solc_path = next(use_solc_version("0.8.15")) solc_path = solc_binary_path("0.8.15")
slither = Slither(Path(USING_FOR_TEST_DATA_DIR, "using-for-3-0.8.0.sol").as_posix(), solc=solc_path) slither = Slither(
Path(USING_FOR_TEST_DATA_DIR, "using-for-3-0.8.0.sol").as_posix(), solc=solc_path
)
contract_c = slither.get_contract_from_name("C")[0] contract_c = slither.get_contract_from_name("C")[0]
libCall = contract_c.get_function_from_full_name("libCall(uint256)") libCall = contract_c.get_function_from_full_name("libCall(uint256)")
for ir in libCall.all_slithir_operations(): for ir in libCall.all_slithir_operations():
@ -33,9 +34,11 @@ def test_using_for_top_level_same_name(use_solc_version) -> None:
assert False assert False
def test_using_for_top_level_implicit_conversion(use_solc_version) -> None: def test_using_for_top_level_implicit_conversion(solc_binary_path) -> None:
solc_path = next(use_solc_version("0.8.15")) solc_path = solc_binary_path("0.8.15")
slither = Slither(Path(USING_FOR_TEST_DATA_DIR, "using-for-4-0.8.0.sol").as_posix(), solc=solc_path) slither = Slither(
Path(USING_FOR_TEST_DATA_DIR, "using-for-4-0.8.0.sol").as_posix(), solc=solc_path
)
contract_c = slither.get_contract_from_name("C")[0] contract_c = slither.get_contract_from_name("C")[0]
libCall = contract_c.get_function_from_full_name("libCall(uint16)") libCall = contract_c.get_function_from_full_name("libCall(uint16)")
for ir in libCall.all_slithir_operations(): for ir in libCall.all_slithir_operations():
@ -44,10 +47,11 @@ def test_using_for_top_level_implicit_conversion(use_solc_version) -> None:
assert False assert False
def test_using_for_alias_top_level(use_solc_version) -> None: def test_using_for_alias_top_level(solc_binary_path) -> None:
solc_path = next(use_solc_version("0.8.15")) solc_path = solc_binary_path("0.8.15")
slither = Slither( slither = Slither(
Path(USING_FOR_TEST_DATA_DIR, "using-for-alias-top-level-0.8.0.sol").as_posix(), solc=solc_path Path(USING_FOR_TEST_DATA_DIR, "using-for-alias-top-level-0.8.0.sol").as_posix(),
solc=solc_path,
) )
contract_c = slither.get_contract_from_name("C")[0] contract_c = slither.get_contract_from_name("C")[0]
libCall = contract_c.get_function_from_full_name("libCall(uint256)") libCall = contract_c.get_function_from_full_name("libCall(uint256)")
@ -64,10 +68,11 @@ def test_using_for_alias_top_level(use_solc_version) -> None:
assert False assert False
def test_using_for_alias_contract(use_solc_version) -> None: def test_using_for_alias_contract(solc_binary_path) -> None:
solc_path = next(use_solc_version("0.8.15")) solc_path = solc_binary_path("0.8.15")
slither = Slither( slither = Slither(
Path(USING_FOR_TEST_DATA_DIR, "using-for-alias-contract-0.8.0.sol").as_posix(), solc=solc_path Path(USING_FOR_TEST_DATA_DIR, "using-for-alias-contract-0.8.0.sol").as_posix(),
solc=solc_path,
) )
contract_c = slither.get_contract_from_name("C")[0] contract_c = slither.get_contract_from_name("C")[0]
libCall = contract_c.get_function_from_full_name("libCall(uint256)") libCall = contract_c.get_function_from_full_name("libCall(uint256)")
@ -84,9 +89,11 @@ def test_using_for_alias_contract(use_solc_version) -> None:
assert False assert False
def test_using_for_in_library(use_solc_version) -> None: def test_using_for_in_library(solc_binary_path) -> None:
solc_path = next(use_solc_version("0.8.15")) solc_path = solc_binary_path("0.8.15")
slither = Slither(Path(USING_FOR_TEST_DATA_DIR, "using-for-in-library-0.8.0.sol").as_posix(), solc=solc_path) slither = Slither(
Path(USING_FOR_TEST_DATA_DIR, "using-for-in-library-0.8.0.sol").as_posix(), solc=solc_path
)
contract_c = slither.get_contract_from_name("A")[0] contract_c = slither.get_contract_from_name("A")[0]
libCall = contract_c.get_function_from_full_name("a(uint256)") libCall = contract_c.get_function_from_full_name("a(uint256)")
for ir in libCall.all_slithir_operations(): for ir in libCall.all_slithir_operations():

@ -1,6 +1,5 @@
from pathlib import Path from pathlib import Path
from collections import namedtuple from collections import namedtuple
from solc_select import solc_select
from slither import Slither from slither import Slither
from slither.slithir.operations import Operation, NewContract from slither.slithir.operations import Operation, NewContract
@ -28,11 +27,11 @@ OperationTest = namedtuple("OperationTest", "contract_name slithir_op")
OPERATION_TEST = [OperationTest("NewContract", NewContract)] OPERATION_TEST = [OperationTest("NewContract", NewContract)]
def test_operation_reads(use_solc_version) -> None: def test_operation_reads(solc_binary_path) -> None:
""" """
Every slithir operation has its own contract and reads all local and state variables in readAllLocalVariables and readAllStateVariables, respectively. Every slithir operation has its own contract and reads all local and state variables in readAllLocalVariables and readAllStateVariables, respectively.
""" """
solc_path = next(use_solc_version("0.8.15")) solc_path = solc_binary_path("0.8.15")
slither = Slither(Path(TEST_DATA_DIR, "operation_reads.sol").as_posix(), solc=solc_path) slither = Slither(Path(TEST_DATA_DIR, "operation_reads.sol").as_posix(), solc=solc_path)
for op_test in OPERATION_TEST: for op_test in OPERATION_TEST:

@ -230,9 +230,8 @@
# assert have_phi_for_var(df, ssa_lvalue) # assert have_phi_for_var(df, ssa_lvalue)
# @contextmanager # @contextmanager
# def slither_from_source(source_code: str, use_solc_version, solc_version: str = "latest"): # def slither_from_source(source_code: str, solc_binary_path, solc_version: str = "latest"):
# """Yields a Slither instance using source_code string and solc_version # """Yields a Slither instance using source_code string and solc_version
# Creates a temporary file and changes the solc-version temporary to solc_version. # Creates a temporary file and changes the solc-version temporary to solc_version.
@ -243,7 +242,7 @@
# with NamedTemporaryFile(dir=SCRIPT_DIR, mode="w", suffix=".sol", delete=False) as f: # with NamedTemporaryFile(dir=SCRIPT_DIR, mode="w", suffix=".sol", delete=False) as f:
# fname = f.name # fname = f.name
# f.write(source_code) # f.write(source_code)
# solc_path = use_solc_version(solc_version) # solc_path = solc_binary_path(solc_version)
# yield Slither(fname, solc=solc_path) # yield Slither(fname, solc=solc_path)
# finally: # finally:
# pathlib.Path(fname).unlink() # pathlib.Path(fname).unlink()

@ -8,9 +8,9 @@ from slither.core.expressions import AssignmentOperation, TupleExpression
TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data" TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data"
# pylint: disable=too-many-nested-blocks # pylint: disable=too-many-nested-blocks
def test_ternary_conversions(use_solc_version) -> None: def test_ternary_conversions(solc_binary_path) -> None:
"""This tests that true and false sons define the same number of variables that the father node declares""" """This tests that true and false sons define the same number of variables that the father node declares"""
solc_path = next(use_solc_version("0.8.0")) solc_path = solc_binary_path("0.8.0")
slither = Slither(Path(TEST_DATA_DIR, "ternary_expressions.sol").as_posix(), solc=solc_path) slither = Slither(Path(TEST_DATA_DIR, "ternary_expressions.sol").as_posix(), solc=solc_path)
for contract in slither.contracts: for contract in slither.contracts:
for function in contract.functions: for function in contract.functions:

@ -1,5 +1,4 @@
from pathlib import Path from pathlib import Path
from solc_select import solc_select
from slither import Slither from slither import Slither
from slither.utils.code_generation import ( from slither.utils.code_generation import (
@ -9,8 +8,8 @@ from slither.utils.code_generation import (
TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data" / "code_generation" TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data" / "code_generation"
def test_interface_generation(use_solc_version) -> None: def test_interface_generation(solc_binary_path) -> None:
solc_path = next(use_solc_version("0.8.4")) solc_path = solc_binary_path("0.8.4")
sl = Slither(Path(TEST_DATA_DIR, "CodeGeneration.sol").as_posix(), solc=solc_path) sl = Slither(Path(TEST_DATA_DIR, "CodeGeneration.sol").as_posix(), solc=solc_path)

@ -1,5 +1,4 @@
from pathlib import Path from pathlib import Path
from solc_select import solc_select
from slither import Slither from slither import Slither
# % solc functions_ids.sol --hashes # % solc functions_ids.sol --hashes
@ -41,8 +40,8 @@ signatures = {
TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data" TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data"
def test_functions_ids(use_solc_version) -> None: def test_functions_ids(solc_binary_path) -> None:
solc_path = next(use_solc_version("0.7.0")) solc_path = solc_binary_path("0.7.0")
file = Path(TEST_DATA_DIR, "functions_ids.sol").as_posix() file = Path(TEST_DATA_DIR, "functions_ids.sol").as_posix()
sl = Slither(file, solc=solc_path) sl = Slither(file, solc=solc_path)
contracts_c = sl.get_contract_from_name("C") contracts_c = sl.get_contract_from_name("C")

@ -1,12 +1,11 @@
from pathlib import Path from pathlib import Path
from solc_select import solc_select
from slither import Slither from slither import Slither
TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data" TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data"
def test_function_id_rec_structure(use_solc_version) -> None: def test_function_id_rec_structure(solc_binary_path) -> None:
solc_path = next(use_solc_version("0.8.0")) solc_path = solc_binary_path("0.8.0")
slither = Slither(Path(TEST_DATA_DIR, "type_helpers.sol").as_posix(), solc=solc_path) slither = Slither(Path(TEST_DATA_DIR, "type_helpers.sol").as_posix(), solc=solc_path)
for compilation_unit in slither.compilation_units: for compilation_unit in slither.compilation_units:
for function in compilation_unit.functions: for function in compilation_unit.functions:

Loading…
Cancel
Save