Merge pull request #1073 from BradSwain/brad/auto-install-solc

Install missing solc versions in tests
pull/1082/head
Feist Josselin 3 years ago committed by GitHub
commit cf8be9df87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 31
      tests/test_ast_parsing.py
  2. 19
      tests/test_detectors.py

@ -12,6 +12,9 @@ import pytest
from crytic_compile import CryticCompile, save_to_zip
from crytic_compile.utils.zip import load_from_zip
from solc_select.solc_select import install_artifacts as install_solc_versions
from solc_select.solc_select import installed_versions as get_installed_solc_versions
from slither import Slither
from slither.printers.guidance.echidna import Echidna
@ -70,25 +73,9 @@ XFAIL = (
)
def get_solc_versions() -> List[str]:
"""
get a list of all the supported versions of solidity, sorted from earliest to latest
:return: ascending list of versions, for example ["0.4.0", "0.4.1", ...]
"""
result = subprocess.run(["solc-select", "versions"], stdout=subprocess.PIPE, check=True)
solc_versions = result.stdout.decode("utf-8").split("\n")
# there's an extra newline so just remove all empty strings
solc_versions = [version.split(" ")[0] for version in solc_versions if version != ""]
solc_versions = sorted(solc_versions, key=lambda x: list(map(int, x.split("."))))
return solc_versions
def get_tests(solc_versions) -> Dict[str, List[str]]:
def get_tests() -> Dict[str, List[str]]:
"""
parse the list of testcases on disk
:param solc_versions: the list of valid solidity versions
:return: a dictionary of test id to list of base solidity versions supported
"""
slither_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@ -112,6 +99,8 @@ def get_tests(solc_versions) -> Dict[str, List[str]]:
tests[key] = sorted(test, key=StrictVersion)
# validate tests
solc_versions = get_installed_solc_versions()
missing_solc_versions = set()
for test, vers in tests.items():
if len(vers) == 1:
if vers[0] != "all":
@ -119,7 +108,9 @@ def get_tests(solc_versions) -> Dict[str, List[str]]:
else:
for ver in vers:
if ver not in solc_versions:
raise Exception("base version not found", test, ver)
missing_solc_versions.add(ver)
if missing_solc_versions:
install_solc_versions(missing_solc_versions)
return tests
@ -140,8 +131,8 @@ def get_all_test() -> List[Item]:
generate a list of testcases by testing each test id with every solidity version for both legacy and compact ast
:return: the testcases
"""
solc_versions = get_solc_versions()
tests = get_tests(solc_versions)
tests = get_tests()
solc_versions = get_installed_solc_versions()
ret = []

@ -8,6 +8,9 @@ from typing import Type, Optional, List
import pytest
from deepdiff import DeepDiff # pip install deepdiff
from solc_select.solc_select import install_artifacts as install_solc_versions
from solc_select.solc_select import installed_versions as get_installed_solc_versions
from slither import Slither
from slither.detectors.abstract_detector import AbstractDetector
from slither.detectors import all_detectors
@ -52,7 +55,7 @@ def id_test(test_item: Test):
return f"{test_item.detector}: {test_item.solc_ver}/{test_item.test_file}"
ALL_TESTS = [
ALL_TEST_OBJECTS = [
Test(
all_detectors.UninitializedFunctionPtrsConstructor,
"uninitialized_function_ptr_constructor.sol",
@ -1200,6 +1203,20 @@ ALL_TESTS = [
"0.8.0",
),
]
def get_all_tests() -> List[Test]:
installed_solcs = set(get_installed_solc_versions())
required_solcs = {test.solc_ver for test in ALL_TEST_OBJECTS}
missing_solcs = list(required_solcs - installed_solcs)
if missing_solcs:
install_solc_versions(missing_solcs)
return ALL_TEST_OBJECTS
ALL_TESTS = get_all_tests()
GENERIC_PATH = "/GENERIC_PATH"

Loading…
Cancel
Save