diff --git a/.gitignore b/.gitignore index 2d57dbb..abbc1af 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ # Binaries bin +solcx/temp # C extensions *.so @@ -58,3 +59,6 @@ docs/_build # npm node_modules + +# other +.vscode diff --git a/.travis.yml b/.travis.yml index 36e93cd..6281ccd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,189 +1,40 @@ -language: python -python: - - "3.5" -os: - - linux -dist: trusty -sudo: required -env: - global: - - SOLC_BASE_INSTALL_PATH=$TRAVIS_BUILD_DIR +# Based on https://github.com/cclauss/Travis-CI-Python-on-three-OSes matrix: include: - # lint - - python: "3.5" - env: TOX_POSARGS="-e flake8" - # installation - - python: "3.4" - env: TOX_POSARGS="-e py34-installation" - - python: "3.5" - env: TOX_POSARGS="-e py35-installation" - - python: "3.6" - env: TOX_POSARGS="-e py36-installation" - # solc 0.4.1 - - python: "3.4" - env: TOX_POSARGS="-e py34" SOLC_VERSION=v0.4.1 - - python: "3.5" - env: TOX_POSARGS="-e py35" SOLC_VERSION=v0.4.1 - - python: "3.6" - env: TOX_POSARGS="-e py36" SOLC_VERSION=v0.4.1 - # solc 0.4.2 - - python: "3.4" - env: TOX_POSARGS="-e py34" SOLC_VERSION=v0.4.2 - - python: "3.5" - env: TOX_POSARGS="-e py35" SOLC_VERSION=v0.4.2 - - python: "3.6" - env: TOX_POSARGS="-e py36" SOLC_VERSION=v0.4.2 - # solc 0.4.6 - - python: "3.4" - env: TOX_POSARGS="-e py34" SOLC_VERSION=v0.4.6 - - python: "3.5" - env: TOX_POSARGS="-e py35" SOLC_VERSION=v0.4.6 - - python: "3.6" - env: TOX_POSARGS="-e py36" SOLC_VERSION=v0.4.6 - # solc 0.4.7 - - python: "3.4" - env: TOX_POSARGS="-e py34" SOLC_VERSION=v0.4.7 - - python: "3.5" - env: TOX_POSARGS="-e py35" SOLC_VERSION=v0.4.7 - - python: "3.6" - env: TOX_POSARGS="-e py36" SOLC_VERSION=v0.4.7 - # solc 0.4.8 - - python: "3.4" - env: TOX_POSARGS="-e py34" SOLC_VERSION=v0.4.8 - - python: "3.5" - env: TOX_POSARGS="-e py35" SOLC_VERSION=v0.4.8 - - python: "3.6" - env: TOX_POSARGS="-e py36" SOLC_VERSION=v0.4.8 - # solc 0.4.9 - - python: "3.4" - env: TOX_POSARGS="-e py34" SOLC_VERSION=v0.4.9 - - python: "3.5" - env: TOX_POSARGS="-e py35" SOLC_VERSION=v0.4.9 - - python: "3.6" - env: TOX_POSARGS="-e py36" SOLC_VERSION=v0.4.9 - # solc 0.4.11 - - python: "3.4" - env: TOX_POSARGS="-e py34" SOLC_VERSION=v0.4.11 - - python: "3.5" - env: TOX_POSARGS="-e py35" SOLC_VERSION=v0.4.11 - - python: "3.6" - env: TOX_POSARGS="-e py36" SOLC_VERSION=v0.4.11 - # solc 0.4.12 - - python: "3.4" - env: TOX_POSARGS="-e py34" SOLC_VERSION=v0.4.12 - - python: "3.5" - env: TOX_POSARGS="-e py35" SOLC_VERSION=v0.4.12 - - python: "3.6" - env: TOX_POSARGS="-e py36" SOLC_VERSION=v0.4.12 - # solc 0.4.13 - - python: "3.4" - env: TOX_POSARGS="-e py34" SOLC_VERSION=v0.4.13 - - python: "3.5" - env: TOX_POSARGS="-e py35" SOLC_VERSION=v0.4.13 - - python: "3.6" - env: TOX_POSARGS="-e py36" SOLC_VERSION=v0.4.13 - # solc 0.4.14 - - python: "3.4" - env: TOX_POSARGS="-e py34" SOLC_VERSION=v0.4.14 - - python: "3.5" - env: TOX_POSARGS="-e py35" SOLC_VERSION=v0.4.14 - - python: "3.6" - env: TOX_POSARGS="-e py36" SOLC_VERSION=v0.4.14 - # solc 0.4.15 - - python: "3.4" - env: TOX_POSARGS="-e py34" SOLC_VERSION=v0.4.15 - - python: "3.5" - env: TOX_POSARGS="-e py35" SOLC_VERSION=v0.4.15 - - python: "3.6" - env: TOX_POSARGS="-e py36" SOLC_VERSION=v0.4.15 - # solc 0.4.16 - - python: "3.4" - env: TOX_POSARGS="-e py34" SOLC_VERSION=v0.4.16 - - python: "3.5" - env: TOX_POSARGS="-e py35" SOLC_VERSION=v0.4.16 - - python: "3.6" - env: TOX_POSARGS="-e py36" SOLC_VERSION=v0.4.16 - # solc 0.4.17 - - python: "3.4" - env: TOX_POSARGS="-e py34" SOLC_VERSION=v0.4.17 - - python: "3.5" - env: TOX_POSARGS="-e py35" SOLC_VERSION=v0.4.17 - - python: "3.6" - env: TOX_POSARGS="-e py36" SOLC_VERSION=v0.4.17 - # solc 0.4.18 - - python: "3.4" - env: TOX_POSARGS="-e py34" SOLC_VERSION=v0.4.18 - - python: "3.5" - env: TOX_POSARGS="-e py35" SOLC_VERSION=v0.4.18 - - python: "3.6" - env: TOX_POSARGS="-e py36" SOLC_VERSION=v0.4.18 - # solc 0.4.19 - - python: "3.4" - env: TOX_POSARGS="-e py34" SOLC_VERSION=v0.4.19 - - python: "3.5" - env: TOX_POSARGS="-e py35" SOLC_VERSION=v0.4.19 - - python: "3.6" - env: TOX_POSARGS="-e py36" SOLC_VERSION=v0.4.19 - # solc 0.4.20 - - python: "3.4" - env: TOX_POSARGS="-e py34" SOLC_VERSION=v0.4.20 - - python: "3.5" - env: TOX_POSARGS="-e py35" SOLC_VERSION=v0.4.20 - - python: "3.6" - env: TOX_POSARGS="-e py36" SOLC_VERSION=v0.4.20 - # solc 0.4.21 - - python: "3.4" - env: TOX_POSARGS="-e py34" SOLC_VERSION=v0.4.21 - - python: "3.5" - env: TOX_POSARGS="-e py35" SOLC_VERSION=v0.4.21 - - python: "3.6" - env: TOX_POSARGS="-e py36" SOLC_VERSION=v0.4.21 - # solc 0.4.22 - - python: "3.4" - env: TOX_POSARGS="-e py34" SOLC_VERSION=v0.4.22 - - python: "3.5" - env: TOX_POSARGS="-e py35" SOLC_VERSION=v0.4.22 - - python: "3.6" - env: TOX_POSARGS="-e py36" SOLC_VERSION=v0.4.22 - # solc 0.4.23 - - python: "3.4" - env: TOX_POSARGS="-e py34" SOLC_VERSION=v0.4.23 - - python: "3.5" - env: TOX_POSARGS="-e py35" SOLC_VERSION=v0.4.23 - - python: "3.6" - env: TOX_POSARGS="-e py36" SOLC_VERSION=v0.4.23 - # solc 0.4.24 - - python: "3.4" - env: TOX_POSARGS="-e py34" SOLC_VERSION=v0.4.24 - - python: "3.5" - env: TOX_POSARGS="-e py35" SOLC_VERSION=v0.4.24 - - python: "3.6" - env: TOX_POSARGS="-e py36" SOLC_VERSION=v0.4.24 - # solc 0.4.25 - - python: "3.4" - env: TOX_POSARGS="-e py34" SOLC_VERSION=v0.4.25 - - python: "3.5" - env: TOX_POSARGS="-e py35" SOLC_VERSION=v0.4.25 - - python: "3.6" - env: TOX_POSARGS="-e py36" SOLC_VERSION=v0.4.25 + - name: "Python 3.7.1 on Xenial Linux" + language: python + python: 3.7 # this works for Linux but is ignored on macOS or Windows + dist: xenial # required for Python >= 3.7 + sudo: true + install: + - sudo add-apt-repository -y ppa:ethereum/ethereum + - sudo apt-get update + - sudo apt-get install -y solc + - pip install -r requirements-dev.txt + - pip install flake8 + script: flake8 solcx/ tests/ --max-line-length=100 + - name: "Python 3.6.8 on Xenial Linux" + language: python + python: 3.6 + dist: xenial + sudo: true + install: + - sudo add-apt-repository -y ppa:ethereum/ethereum + - sudo apt-get update + - sudo apt-get install -y solc + - pip install -r requirements-dev.txt + script: python -m pytest tests/ --cov=solcx/ + - name: "Python 3.7.3 on Windows" + os: windows # Windows 10.0.17134 N/A Build 17134 + language: shell # 'language: python' is an error on Travis CI Windows + # python: 3.7 # 'python:' is ignored on Travis CI Windows + install: + - choco install python # this install takes at least 1 min 30 sec + - python -m pip install --upgrade pip + - pip3 install -r requirements-dev.txt + env: PATH=/c/Python37:/c/Python37/Scripts:$PATH -cache: - - pip: true -before_install: -install: - - travis_retry pip install setuptools --upgrade - - travis_retry pip install tox - - pip --version - - pip install -e . # install py-solc globally in order to use the solc installation scripts. -before_script: - - python --version - - if [ -n "$SOLC_VERSION" ]; then python -m solc.install $SOLC_VERSION; fi - - if [ -n "$SOLC_VERSION" ]; then export SOLC_BINARY="$SOLC_BASE_INSTALL_PATH/solc-$SOLC_VERSION/bin/solc"; fi - - if [ -n "$SOLC_VERSION" ]; then export LD_LIBRARY_PATH="$SOLC_BASE_INSTALL_PATH/solc-$SOLC_VERSION/bin"; fi - - env - - if [ -n "$SOLC_BINARY" ]; then $SOLC_BINARY --version; fi -script: - - tox $TOX_POSARGS -after_script: - - cat .tox/$TOX_POSARGS/log/*.log +script: python -m pytest tests --cov=solcx/ +after_success: coveralls +notifications: + email: false diff --git a/requirements-dev.txt b/requirements-dev.txt index 7c536b3..bdfaad9 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,5 +1,6 @@ -pytest>=2.9.2 -tox>=2.3.1 +coveralls==1.7.0 +pytest>=5.0.0 +pytest-cov>=2.7.1 semantic_version>=2.6.0 -bumpversion==0.5.3 -twine==1.12.1 +twine==1.13.0 +requests>=2.19.0 \ No newline at end of file diff --git a/solcx/install.py b/solcx/install.py index 1272180..1f59a7d 100644 --- a/solcx/install.py +++ b/solcx/install.py @@ -142,10 +142,10 @@ def set_solc_version_pragma(version, silent=False): print("Using solc version {}".format(solc_version)) -def get_available_solc_versions(): +def get_available_solc_versions(headers={}): versions = [] pattern = VERSION_REGEX[_get_platform()] - for release in requests.get(ALL_RELEASES).json(): + for release in requests.get(ALL_RELEASES, headers=headers).json(): asset = next((i for i in release['assets'] if re.match(pattern, i['name'])), False) if asset: versions.append(release['tag_name']) diff --git a/solcx/temp/solc-binary b/solcx/temp/solc-binary deleted file mode 100644 index 836a508..0000000 Binary files a/solcx/temp/solc-binary and /dev/null differ diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..b9464d3 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,52 @@ +from base64 import b64encode +import os +import pytest +import sys + +import solcx + +TEST_CONTRACT = '''pragma solidity >=0.4.11 <0.6.0; + +contract Foo { + function return13() public returns (uint) { + return 13; + } +} +''' + +if sys.platform == "darwin": + VERSIONS = solcx.get_installed_solc_versions() +else: + auth = b64encode(os.environ['GITAUTH'].encode()).decode('ascii') + headers = {'Authorization': f"Basic {auth}"} + VERSIONS = solcx.get_available_solc_versions(headers=headers) + + +def pytest_generate_tests(metafunc): + if 'all_versions' in metafunc.fixturenames: + metafunc.parametrize('all_versions', VERSIONS, indirect=True) + + +_installed = {} +@pytest.fixture() +def all_versions(request): + version = request.param + if version not in _installed: + try: + solcx.install_solc(version) + _installed[version] = True + except Exception: + _installed[version] = False + pytest.fail(f"Unable to install solc {version}") + if _installed[version]: + solcx.set_solc_version(version) + else: + request.applymarker('skip') + + +@pytest.fixture() +def contract_source(tmp_path): + source = tmp_path.joinpath('test.sol') + with source.open('w') as fp: + fp.write(TEST_CONTRACT) + return str(source) diff --git a/tests/test_compile.py b/tests/test_compile.py new file mode 100644 index 0000000..4ff7f04 --- /dev/null +++ b/tests/test_compile.py @@ -0,0 +1,12 @@ +import pytest + +import solcx + + +@pytest.fixture(autouse=True) +def setup(all_versions): + pass + + +def test_compile_files(contract_source): + solcx.compile_files([contract_source]) diff --git a/tox.ini b/tox.ini deleted file mode 100644 index f758cae..0000000 --- a/tox.ini +++ /dev/null @@ -1,30 +0,0 @@ -[tox] -envlist= - py{34,35,36}-{core,installation} - flake8 - -[flake8] -max-line-length= 100 -exclude= tests/* - -[testenv] -commands= - core: py.test {posargs:tests/core} - installation: py.test {posargs:-s tests/installation} -passenv = - SOLC_BINARY - TRAVIS_BUILD_DIR - SOLC_RUN_INSTALL_TESTS -setenv = - py{34,35,36}-installation: SOLC_RUN_INSTALL_TESTS=enabled -deps = - -r{toxinidir}/requirements-dev.txt -basepython = - py34: python3.4 - py35: python3.5 - py36: python3.6 - -[testenv:flake8] -basepython=python -deps=flake8 -commands=flake8 {toxinidir}/solc