Skip to content

Commit

Permalink
Merge pull request #36 from iamdefinitelyahuman/v0.7.1
Browse files Browse the repository at this point in the history
v0.7.1
  • Loading branch information
iamdefinitelyahuman committed Jan 14, 2020
2 parents 28b7110 + d7d4688 commit 32dfb7b
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 25 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
0.7.1
-----

- Bugfix: compiling with limited output values

0.7.0
-----

Expand Down
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
include LICENSE
include README.md
include requirements.txt

recursive-exclude * __pycache__
recursive-exclude * *.py[co]
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ To run the test suite:
pytest tests/
```

By default, the test suite installs all available solc versions for your OS. If you only wish to test against already installed versions, include the `--no-install` flag.

## License

This project is licensed under the [MIT license](LICENSE).
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name='py-solc-x',
version='0.7.0',
version='0.7.1',
description="""Python wrapper around the solc binary with 0.5.x and 0.6.x support""",
long_description_markdown_filename='README.md',
author='Ben Hauser (forked from py-solc by Piper Merriam)',
Expand Down
18 changes: 9 additions & 9 deletions solcx/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ def solc_supports_standard_json_interface(**kwargs):
def _parse_compiler_output(stdoutdata):
output = json.loads(stdoutdata)

if "contracts" not in output:
return {}

contracts = output['contracts']
sources = output['sources']

for source, data in contracts.items():
data['abi'] = json.loads(data['abi'])
data['ast'] = sources[source.rsplit(':', maxsplit=1)[0]]['AST']
contracts = output.get('contracts', {})
sources = output.get('sources', {})

for path_str, data in contracts.items():
if 'abi' in data:
data['abi'] = json.loads(data['abi'])
key = path_str.rsplit(':', maxsplit=1)[0]
if 'AST' in sources.get(key, {}):
data['ast'] = sources[key]['AST']

return contracts

Expand Down
28 changes: 23 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,32 @@

import pytest
import shutil
import sys

from requests import ConnectionError

import solcx

if sys.platform == "darwin":
VERSIONS = solcx.get_installed_solc_versions()
else:
VERSIONS = solcx.get_available_solc_versions()

def pytest_addoption(parser):
parser.addoption(
"--no-install",
action="store_true",
help="Only run solcx tests against already installed solc versions"
)


def pytest_configure(config):
global VERSIONS
if config.getoption('--no-install'):
VERSIONS = solcx.get_installed_solc_versions()
return
try:
VERSIONS = solcx.get_available_solc_versions()
except ConnectionError:
raise pytest.UsageError(
"ConnectionError while attempting to get solc versions.\n"
"Use the --no-install flag to only run tests against already installed versions."
)


# auto-parametrize the all_versions fixture with all target solc versions
Expand Down
58 changes: 50 additions & 8 deletions tests/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,85 @@
import pytest

import solcx
from solcx.main import ALL_OUTPUT_VALUES
from solcx.exceptions import ContractsNotFound

# interfaces and compact-format do not return anything
combined_json_values = (
'abi',
'asm',
'ast',
'bin',
'bin-runtime',
'devdoc',
'hashes',
'metadata',
'opcodes',
'srcmap',
'srcmap-runtime',
'userdoc',
)


@pytest.fixture(autouse=True)
def setup(all_versions):
pass


def test_compile_source(foo_source):
output = solcx.compile_source(foo_source)
_compile_assertions(output, "<stdin>:Foo")
output = solcx.compile_source(foo_source, optimize=True)
_compile_assertions(output, "<stdin>:Foo")


def test_compile_source_empty():
with pytest.raises(ContractsNotFound):
solcx.compile_source(" ")
solcx.compile_source(" ", allow_empty=True)


@pytest.mark.parametrize('key', combined_json_values)
def test_compile_source_output_types(foo_source, key):
if key == "hashes" and str(solcx.get_solc_version().truncate()) == "0.4.11":
return
output = solcx.compile_source(foo_source, output_values=[key])
assert key in output["<stdin>:Foo"]


def test_compile_files(foo_path):
output = solcx.compile_files([foo_path])
_compile_assertions(output, f"{foo_path}:Foo")
output = solcx.compile_files([foo_path], optimize=True)
_compile_assertions(output, f"{foo_path}:Foo")


def test_import_remapping(foo_path, bar_path):
def test_compile_files_empty():
with pytest.raises(ContractsNotFound):
solcx.compile_files([])
solcx.compile_files([], allow_empty=True)


@pytest.mark.parametrize('key', combined_json_values)
def test_compile_files_output_types(foo_path, key):
if key == "hashes" and str(solcx.get_solc_version().truncate()) == "0.4.11":
return
output = solcx.compile_files([foo_path], output_values=[key])
assert key in output[f"{foo_path}:Foo"]


def test_compile_files_import_remapping(foo_path, bar_path):
path = Path(bar_path).parent.as_posix()
output = solcx.compile_files([bar_path], import_remappings=[f"contracts={path}"])
assert output
assert f'{bar_path}:Bar' in output


def test_compile_files_empty():
with pytest.raises(ContractsNotFound):
solcx.compile_files([])


def _compile_assertions(output, key):
assert output
assert key in output
assert 'bin' in output[key]
assert 'bin-runtime' in output[key]
for value in ALL_OUTPUT_VALUES:
if value == "clone-bin" and solcx.get_solc_version().minor >= 5:
assert value not in output[key]
else:
assert value in output[key]
2 changes: 1 addition & 1 deletion tests/test_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def popen(monkeypatch):


@pytest.fixture(autouse=True)
def all_(all_versions):
def setup(all_versions):
pass


Expand Down

0 comments on commit 32dfb7b

Please sign in to comment.