From 07fcb5c1497a985b328beaf2d5a199fe8da92d0a Mon Sep 17 00:00:00 2001 From: alpharush <0xalpharush@protonmail.com> Date: Tue, 28 Mar 2023 14:18:26 -0500 Subject: [PATCH] simplify using reviewer suggestions --- Makefile | 9 ++-- tests/conftest.py | 31 +++++-------- tests/e2e/compilation/test_resolution.py | 9 ++-- tests/tools/read-storage/test_read_storage.py | 4 +- tests/unit/core/test_arithmetic.py | 5 +-- tests/unit/core/test_code_comments.py | 18 +++++--- tests/unit/core/test_constant_folding.py | 20 +++++---- tests/unit/core/test_contract_declaration.py | 21 +++++---- tests/unit/core/test_function_declaration.py | 17 ++++---- tests/unit/core/test_source_mapping.py | 12 +++--- tests/unit/core/test_storage_layout.py | 7 ++- tests/unit/core/test_using_for.py | 43 +++++++++++-------- tests/unit/slithir/test_operation_reads.py | 5 +-- tests/unit/slithir/test_ssa_generation.py | 5 +-- .../unit/slithir/test_ternary_expressions.py | 4 +- tests/unit/utils/test_code_generation.py | 5 +-- tests/unit/utils/test_functions_ids.py | 5 +-- tests/unit/utils/test_type_helpers.py | 5 +-- 18 files changed, 112 insertions(+), 113 deletions(-) diff --git a/Makefile b/Makefile index cc102c9586..a94c3eeb87 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ SHELL := /bin/bash PY_MODULE := slither +TEST_MODULE := tests ALL_PY_SRCS := $(shell find $(PY_MODULE) -name '*.py') \ $(shell find test -name '*.py') @@ -33,7 +34,7 @@ ifneq ($(TESTS),) COV_ARGS := else TEST_ARGS := -n auto - COV_ARGS := --cov-append # --fail-under 100 + COV_ARGS := # --fail-under 100 endif .PHONY: all @@ -56,15 +57,15 @@ $(VENV)/pyvenv.cfg: pyproject.toml .PHONY: lint lint: $(VENV)/pyvenv.cfg . $(VENV_BIN)/activate && \ - black --check $(ALL_PY_SRCS) && \ - pylint $(ALL_PY_SRCS) + black --check . && \ + pylint $(PY_MODULE) $(TEST_MODULE) # ruff $(ALL_PY_SRCS) && \ # mypy $(PY_MODULE) && .PHONY: reformat reformat: . $(VENV_BIN)/activate && \ - black $(PY_MODULE) + black . .PHONY: test tests test tests: $(VENV)/pyvenv.cfg diff --git a/tests/conftest.py b/tests/conftest.py index bf15b27d11..63f40b672d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,26 +2,15 @@ from filelock import FileLock 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") -def use_solc_version(request, solc_versions_installed): - def _use_solc_version(version): - print(version) - if version not in solc_versions_installed: - print("Installing solc version", version) - solc_select.install_artifacts([version]) - artifact_path = solc_select.artifact_path(version) - lock = FileLock(artifact_path) - try: - yield artifact_path - finally: - lock.release() - return _use_solc_version +def solc_binary_path(): + def inner(version): + lock = FileLock(f"{version}.lock", timeout=60) + with lock: + if not solc_select.artifact_path(version).exists(): + print("Installing solc version", version) + solc_select.install_artifacts([version]) + return solc_select.artifact_path(version) + + return inner diff --git a/tests/e2e/compilation/test_resolution.py b/tests/e2e/compilation/test_resolution.py index 3444af2e90..71edaa143f 100644 --- a/tests/e2e/compilation/test_resolution.py +++ b/tests/e2e/compilation/test_resolution.py @@ -3,7 +3,6 @@ from crytic_compile import CryticCompile from crytic_compile.platform.solc_standard_json import SolcStandardJson -from solc_select import solc_select from slither import Slither @@ -24,8 +23,8 @@ def test_node_modules() -> None: _run_all_detectors(slither) -def test_contract_name_collision(use_solc_version) -> None: - solc_path = next(use_solc_version("0.8.0")) +def test_contract_name_collision(solc_binary_path) -> None: + solc_path = solc_binary_path("0.8.0") standard_json = SolcStandardJson() standard_json.add_source_file( 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) -def test_cycle(use_solc_version) -> None: - solc_path = next(use_solc_version("0.8.0")) +def test_cycle(solc_binary_path) -> None: + solc_path = solc_binary_path("0.8.0") slither = Slither(Path(TEST_DATA_DIR, "test_cyclic_import", "a.sol").as_posix(), solc=solc_path) _run_all_detectors(slither) diff --git a/tests/tools/read-storage/test_read_storage.py b/tests/tools/read-storage/test_read_storage.py index 3b83df8558..6d2ab007dd 100644 --- a/tests/tools/read-storage/test_read_storage.py +++ b/tests/tools/read-storage/test_read_storage.py @@ -90,8 +90,8 @@ def deploy_contract(w3, ganache, contract_bin, contract_abi) -> Contract: # pylint: disable=too-many-locals @pytest.mark.usefixtures("web3", "ganache") -def test_read_storage(web3, ganache, use_solc_version) -> None: - solc_path = next(use_solc_version(version="0.8.10")) +def test_read_storage(web3, ganache, solc_binary_path) -> None: + solc_path = solc_binary_path(version="0.8.10") assert web3.is_connected() bin_path = Path(TEST_DATA_DIR, "StorageLayout.bin").as_posix() diff --git a/tests/unit/core/test_arithmetic.py b/tests/unit/core/test_arithmetic.py index 6e7843ea0d..6de63d7674 100644 --- a/tests/unit/core/test_arithmetic.py +++ b/tests/unit/core/test_arithmetic.py @@ -1,5 +1,4 @@ from pathlib import Path -from solc_select import solc_select from slither import Slither from slither.utils.arithmetic import unchecked_arithemtic_usage @@ -8,8 +7,8 @@ TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data" / "arithmetic_usage" -def test_arithmetic_usage(use_solc_version) -> None: - solc_path = next(use_solc_version("0.8.15")) +def test_arithmetic_usage(solc_binary_path) -> None: + solc_path = solc_binary_path("0.8.15") slither = Slither(Path(TEST_DATA_DIR, "test.sol").as_posix(), solc=solc_path) assert { diff --git a/tests/unit/core/test_code_comments.py b/tests/unit/core/test_code_comments.py index 4fbbae658b..2dd07caf0c 100644 --- a/tests/unit/core/test_code_comments.py +++ b/tests/unit/core/test_code_comments.py @@ -8,8 +8,8 @@ CUSTOM_COMMENTS_TEST_DATA_DIR = Path(TEST_DATA_DIR, "custom_comments") -def test_upgradeable_comments(use_solc_version) -> None: - solc_path = next(use_solc_version("0.8.10")) +def test_upgradeable_comments(solc_binary_path) -> None: + solc_path = solc_binary_path("0.8.10") slither = Slither(Path(CUSTOM_COMMENTS_TEST_DATA_DIR, "upgrade.sol").as_posix(), solc=solc_path) compilation_unit = slither.compilation_units[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" -def test_contract_comments(use_solc_version) -> None: +def test_contract_comments(solc_binary_path) -> None: comments = " @title Test Contract\n @dev Test comment" - solc_path = next(use_solc_version("0.8.10")) - slither = Slither(Path(CUSTOM_COMMENTS_TEST_DATA_DIR, "contract_comment.sol").as_posix(), solc=solc_path) + solc_path = solc_binary_path("0.8.10") + slither = Slither( + Path(CUSTOM_COMMENTS_TEST_DATA_DIR, "contract_comment.sol").as_posix(), solc=solc_path + ) compilation_unit = slither.compilation_units[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 # the initial space (after *) is also not kept on every line comments = "@title Test Contract\n@dev Test comment" - solc_path = next(use_solc_version("0.5.16")) - slither = Slither(Path(CUSTOM_COMMENTS_TEST_DATA_DIR, "contract_comment.sol").as_posix(), solc=solc_path) + solc_path = solc_binary_path("0.5.16") + slither = Slither( + Path(CUSTOM_COMMENTS_TEST_DATA_DIR, "contract_comment.sol").as_posix(), solc=solc_path + ) compilation_unit = slither.compilation_units[0] contract = compilation_unit.get_contract_from_name("A")[0] diff --git a/tests/unit/core/test_constant_folding.py b/tests/unit/core/test_constant_folding.py index d01b35dc0e..a572987a4b 100644 --- a/tests/unit/core/test_constant_folding.py +++ b/tests/unit/core/test_constant_folding.py @@ -6,15 +6,17 @@ CONSTANT_FOLDING_TEST_ROOT = Path(TEST_DATA_DIR, "constant_folding") -def test_constant_folding_unary(use_solc_version): - solc_path = next(use_solc_version("0.8.0")) +def test_constant_folding_unary(solc_binary_path): + solc_path = solc_binary_path("0.8.0") file = Path(CONSTANT_FOLDING_TEST_ROOT, "constant_folding_unary.sol").as_posix() Slither(file, solc=solc_path) -def test_constant_folding_rational(use_solc_version): - solc_path = next(use_solc_version("0.8.0")) - s = Slither(Path(CONSTANT_FOLDING_TEST_ROOT, "constant_folding_rational.sol").as_posix(), solc=solc_path) +def test_constant_folding_rational(solc_binary_path): + solc_path = solc_binary_path("0.8.0") + s = Slither( + Path(CONSTANT_FOLDING_TEST_ROOT, "constant_folding_rational.sol").as_posix(), solc=solc_path + ) contract = s.get_contract_from_name("C")[0] 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" -def test_constant_folding_binary_expressions(use_solc_version): - solc_path = next(use_solc_version("0.8.0")) - sl = Slither(Path(CONSTANT_FOLDING_TEST_ROOT, "constant_folding_binop.sol").as_posix(), solc=solc_path) +def test_constant_folding_binary_expressions(solc_binary_path): + solc_path = solc_binary_path("0.8.0") + sl = Slither( + Path(CONSTANT_FOLDING_TEST_ROOT, "constant_folding_binop.sol").as_posix(), solc=solc_path + ) contract = sl.get_contract_from_name("BinOp")[0] variable_a = contract.get_state_variable_from_name("a") diff --git a/tests/unit/core/test_contract_declaration.py b/tests/unit/core/test_contract_declaration.py index 3c1e7175e0..7760829351 100644 --- a/tests/unit/core/test_contract_declaration.py +++ b/tests/unit/core/test_contract_declaration.py @@ -1,6 +1,5 @@ from pathlib import Path -from solc_select import solc_select from slither import Slither from slither.core.variables.state_variable import StateVariable @@ -9,26 +8,30 @@ CONTRACT_DECL_TEST_ROOT = Path(TEST_DATA_DIR, "contract_declaration") -def test_abstract_contract(use_solc_version) -> None: - solc_path = next(use_solc_version("0.8.0")) +def test_abstract_contract(solc_binary_path) -> None: + solc_path = solc_binary_path("0.8.0") slither = Slither(Path(CONTRACT_DECL_TEST_ROOT, "abstract.sol").as_posix(), solc=solc_path) assert not slither.contracts[0].is_fully_implemented - solc_path = next(use_solc_version("0.5.0")) - slither = Slither(Path(CONTRACT_DECL_TEST_ROOT, "implicit_abstract.sol").as_posix(), solc=solc_path) + solc_path = solc_binary_path("0.5.0") + slither = Slither( + Path(CONTRACT_DECL_TEST_ROOT, "implicit_abstract.sol").as_posix(), solc=solc_path + ) assert not slither.contracts[0].is_fully_implemented slither = Slither( Path(CONTRACT_DECL_TEST_ROOT, "implicit_abstract.sol").as_posix(), solc_force_legacy_json=True, - solc=solc_path + solc=solc_path, ) assert not slither.contracts[0].is_fully_implemented -def test_private_variable(use_solc_version) -> None: - solc_path = next(use_solc_version("0.8.15")) - slither = Slither(Path(CONTRACT_DECL_TEST_ROOT, "private_variable.sol").as_posix(), solc=solc_path) +def test_private_variable(solc_binary_path) -> None: + solc_path = solc_binary_path("0.8.15") + slither = Slither( + Path(CONTRACT_DECL_TEST_ROOT, "private_variable.sol").as_posix(), solc=solc_path + ) contract_c = slither.get_contract_from_name("C")[0] f = contract_c.functions[0] var_read = f.variables_read[0] diff --git a/tests/unit/core/test_function_declaration.py b/tests/unit/core/test_function_declaration.py index 4faa9d919c..651f449de5 100644 --- a/tests/unit/core/test_function_declaration.py +++ b/tests/unit/core/test_function_declaration.py @@ -5,7 +5,6 @@ and that these objects behave correctly. """ from pathlib import Path -from solc_select import solc_select from slither import Slither from slither.core.declarations.function import FunctionType @@ -15,9 +14,9 @@ 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 - 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() slither = Slither(file, solc=solc_path) 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") -def test_function_can_send_eth(use_solc_version): - solc_path = next(use_solc_version("0.6.12")) +def test_function_can_send_eth(solc_binary_path): + solc_path = solc_binary_path("0.6.12") file = Path(FUNC_DELC_TEST_ROOT, "test_function.sol").as_posix() slither = Slither(file, solc=solc_path) 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 -def test_reentrant(use_solc_version): - solc_path = next(use_solc_version("0.8.10")) +def test_reentrant(solc_binary_path): + solc_path = solc_binary_path("0.8.10") file = Path(FUNC_DELC_TEST_ROOT, "test_function_reentrant.sol").as_posix() slither = Slither(file, solc=solc_path) compilation_unit = slither.compilation_units[0] @@ -290,8 +289,8 @@ def test_reentrant(use_solc_version): assert functions["internal_and_reentrant()"].is_reentrant -def test_public_variable(use_solc_version) -> None: - solc_path = next(use_solc_version("0.6.12")) +def test_public_variable(solc_binary_path) -> None: + solc_path = solc_binary_path("0.6.12") file = Path(FUNC_DELC_TEST_ROOT, "test_function.sol").as_posix() slither = Slither(file, solc=solc_path) contracts = slither.get_contract_from_name("TestFunction") diff --git a/tests/unit/core/test_source_mapping.py b/tests/unit/core/test_source_mapping.py index 2dd8c24359..1eec9d32a8 100644 --- a/tests/unit/core/test_source_mapping.py +++ b/tests/unit/core/test_source_mapping.py @@ -8,8 +8,8 @@ SRC_MAPPING_TEST_ROOT = Path(TEST_DATA_DIR, "src_mapping") -def test_source_mapping(use_solc_version): - solc_path = next(use_solc_version("0.6.12")) +def test_source_mapping(solc_binary_path): + solc_path = solc_binary_path("0.6.12") file = Path(SRC_MAPPING_TEST_ROOT, "inheritance.sol").as_posix() 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]) -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). """ - 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() slither = Slither(file, solc=solc_path) @@ -101,11 +101,11 @@ def test_references_user_defined_aliases(use_solc_version): 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. """ - 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() slither = Slither(file, solc=solc_path) diff --git a/tests/unit/core/test_storage_layout.py b/tests/unit/core/test_storage_layout.py index fd21ce009c..3337eb0f74 100644 --- a/tests/unit/core/test_storage_layout.py +++ b/tests/unit/core/test_storage_layout.py @@ -1,16 +1,15 @@ import json from pathlib import Path from subprocess import PIPE, Popen -from solc_select import solc_select from slither import Slither TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data" 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 - 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() sl = Slither(test_item, disallow_partial=True, solc=solc_path) @@ -35,4 +34,4 @@ def test_storage_layout(use_solc_version): except KeyError as e: print(f"not found {e} ") process.communicate() - assert process.returncode == 0 \ No newline at end of file + assert process.returncode == 0 diff --git a/tests/unit/core/test_using_for.py b/tests/unit/core/test_using_for.py index 7b0e2d1d66..ebba72eeff 100644 --- a/tests/unit/core/test_using_for.py +++ b/tests/unit/core/test_using_for.py @@ -1,7 +1,6 @@ from pathlib import Path 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.slithir.operations import InternalCall, LibraryCall @@ -12,8 +11,8 @@ USING_FOR_TEST_DATA_DIR = Path(TEST_DATA_DIR, "using_for") -def test_using_for_global_collision(use_solc_version) -> None: - solc_path = next(use_solc_version("0.8.15")) +def test_using_for_global_collision(solc_binary_path) -> None: + solc_path = solc_binary_path("0.8.15") standard_json = SolcStandardJson() 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()) @@ -22,9 +21,11 @@ def test_using_for_global_collision(use_solc_version) -> None: _run_all_detectors(sl) -def test_using_for_top_level_same_name(use_solc_version) -> None: - solc_path = next(use_solc_version("0.8.15")) - slither = Slither(Path(USING_FOR_TEST_DATA_DIR, "using-for-3-0.8.0.sol").as_posix(), solc=solc_path) +def test_using_for_top_level_same_name(solc_binary_path) -> None: + 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 + ) contract_c = slither.get_contract_from_name("C")[0] libCall = contract_c.get_function_from_full_name("libCall(uint256)") 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 -def test_using_for_top_level_implicit_conversion(use_solc_version) -> None: - solc_path = next(use_solc_version("0.8.15")) - slither = Slither(Path(USING_FOR_TEST_DATA_DIR, "using-for-4-0.8.0.sol").as_posix(), solc=solc_path) +def test_using_for_top_level_implicit_conversion(solc_binary_path) -> None: + 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 + ) contract_c = slither.get_contract_from_name("C")[0] libCall = contract_c.get_function_from_full_name("libCall(uint16)") 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 -def test_using_for_alias_top_level(use_solc_version) -> None: - solc_path = next(use_solc_version("0.8.15")) +def test_using_for_alias_top_level(solc_binary_path) -> None: + solc_path = solc_binary_path("0.8.15") 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] 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 -def test_using_for_alias_contract(use_solc_version) -> None: - solc_path = next(use_solc_version("0.8.15")) +def test_using_for_alias_contract(solc_binary_path) -> None: + solc_path = solc_binary_path("0.8.15") 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] 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 -def test_using_for_in_library(use_solc_version) -> None: - solc_path = next(use_solc_version("0.8.15")) - slither = Slither(Path(USING_FOR_TEST_DATA_DIR, "using-for-in-library-0.8.0.sol").as_posix(), solc=solc_path) +def test_using_for_in_library(solc_binary_path) -> None: + 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 + ) contract_c = slither.get_contract_from_name("A")[0] libCall = contract_c.get_function_from_full_name("a(uint256)") for ir in libCall.all_slithir_operations(): diff --git a/tests/unit/slithir/test_operation_reads.py b/tests/unit/slithir/test_operation_reads.py index 10ae474043..fc3018cc80 100644 --- a/tests/unit/slithir/test_operation_reads.py +++ b/tests/unit/slithir/test_operation_reads.py @@ -1,6 +1,5 @@ from pathlib import Path from collections import namedtuple -from solc_select import solc_select from slither import Slither from slither.slithir.operations import Operation, NewContract @@ -28,11 +27,11 @@ def check_num_states_vars_read(function, slithir_op: Operation, num_reads_expect 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. """ - 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) for op_test in OPERATION_TEST: diff --git a/tests/unit/slithir/test_ssa_generation.py b/tests/unit/slithir/test_ssa_generation.py index 34ad5e4fe2..865e3263d0 100644 --- a/tests/unit/slithir/test_ssa_generation.py +++ b/tests/unit/slithir/test_ssa_generation.py @@ -230,9 +230,8 @@ # assert have_phi_for_var(df, ssa_lvalue) - # @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 # 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: # fname = f.name # f.write(source_code) -# solc_path = use_solc_version(solc_version) +# solc_path = solc_binary_path(solc_version) # yield Slither(fname, solc=solc_path) # finally: # pathlib.Path(fname).unlink() diff --git a/tests/unit/slithir/test_ternary_expressions.py b/tests/unit/slithir/test_ternary_expressions.py index 3fb5159f75..68a6089ccf 100644 --- a/tests/unit/slithir/test_ternary_expressions.py +++ b/tests/unit/slithir/test_ternary_expressions.py @@ -8,9 +8,9 @@ TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data" # 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""" - 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) for contract in slither.contracts: for function in contract.functions: diff --git a/tests/unit/utils/test_code_generation.py b/tests/unit/utils/test_code_generation.py index d4c40f42f1..35f6cea0ed 100644 --- a/tests/unit/utils/test_code_generation.py +++ b/tests/unit/utils/test_code_generation.py @@ -1,5 +1,4 @@ from pathlib import Path -from solc_select import solc_select from slither import Slither from slither.utils.code_generation import ( @@ -9,8 +8,8 @@ TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data" / "code_generation" -def test_interface_generation(use_solc_version) -> None: - solc_path = next(use_solc_version("0.8.4")) +def test_interface_generation(solc_binary_path) -> None: + solc_path = solc_binary_path("0.8.4") sl = Slither(Path(TEST_DATA_DIR, "CodeGeneration.sol").as_posix(), solc=solc_path) diff --git a/tests/unit/utils/test_functions_ids.py b/tests/unit/utils/test_functions_ids.py index e6ca9f539b..23888774b1 100644 --- a/tests/unit/utils/test_functions_ids.py +++ b/tests/unit/utils/test_functions_ids.py @@ -1,5 +1,4 @@ from pathlib import Path -from solc_select import solc_select from slither import Slither # % solc functions_ids.sol --hashes @@ -41,8 +40,8 @@ TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data" -def test_functions_ids(use_solc_version) -> None: - solc_path = next(use_solc_version("0.7.0")) +def test_functions_ids(solc_binary_path) -> None: + solc_path = solc_binary_path("0.7.0") file = Path(TEST_DATA_DIR, "functions_ids.sol").as_posix() sl = Slither(file, solc=solc_path) contracts_c = sl.get_contract_from_name("C") diff --git a/tests/unit/utils/test_type_helpers.py b/tests/unit/utils/test_type_helpers.py index 6a71a0a19a..420329ab2f 100644 --- a/tests/unit/utils/test_type_helpers.py +++ b/tests/unit/utils/test_type_helpers.py @@ -1,12 +1,11 @@ from pathlib import Path -from solc_select import solc_select from slither import Slither TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data" -def test_function_id_rec_structure(use_solc_version) -> None: - solc_path = next(use_solc_version("0.8.0")) +def test_function_id_rec_structure(solc_binary_path) -> None: + solc_path = solc_binary_path("0.8.0") slither = Slither(Path(TEST_DATA_DIR, "type_helpers.sol").as_posix(), solc=solc_path) for compilation_unit in slither.compilation_units: for function in compilation_unit.functions: