Skip to content

Commit

Permalink
update tests, bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdefinitelyahuman committed Jul 27, 2019
1 parent a558875 commit 4dc177f
Show file tree
Hide file tree
Showing 11 changed files with 211 additions and 258 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ matrix:
- sudo apt-get update
- sudo apt-get install -y solc
- pip install -r requirements-dev.txt
script: python -m pytest tests --cov=solcx
after_success: python -m coveralls
- 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
Expand All @@ -32,8 +34,8 @@ matrix:
- python -m pip install --upgrade pip
- pip3 install -r requirements-dev.txt
env: PATH=/c/Python37:/c/Python37/Scripts:$PATH
script: python -m pytest tests --cov=solcx
after_success: python -m coveralls

script: python -m pytest tests --cov=solcx
after_success: python -m coveralls
notifications:
email: false
4 changes: 2 additions & 2 deletions solcx/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ def solc_wrapper(solc_binary=None,
command.extend(('--evm-version', evm_version))

if (
standard_json is None and
source_files is None and
not standard_json and
not source_files and
"v0.5" in command[0]
):
command.append('-')
Expand Down
23 changes: 0 additions & 23 deletions tests-old/core/compilation/test_compile_empty.py

This file was deleted.

21 changes: 0 additions & 21 deletions tests-old/core/compilation/test_compile_from_source_code.py

This file was deleted.

97 changes: 0 additions & 97 deletions tests-old/core/compilation/test_compile_standard.py

This file was deleted.

32 changes: 0 additions & 32 deletions tests-old/core/compilation/test_compiler_from_source_file.py

This file was deleted.

30 changes: 0 additions & 30 deletions tests-old/core/compilation/test_compiler_remappings.py

This file was deleted.

58 changes: 43 additions & 15 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
#!/usr/bin/python3

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:
Expand Down Expand Up @@ -49,13 +42,48 @@ def all_versions(request):


@pytest.fixture()
def contract_path(tmp_path):
source = tmp_path.joinpath('test.sol')
def foo_source():
yield """pragma solidity >=0.4.11;
contract Foo {
function return13() public returns (uint) {
return 13;
}
}
"""


@pytest.fixture()
def bar_source():
yield """
pragma solidity >=0.4.11;
import "contracts/Foo.sol";
contract Bar is Foo {
function getFunky() public returns (bytes4) {
return 0x420Faded;
}
}"""


@pytest.fixture()
def invalid_source():
yield """pragma solidity >=0.4.11;
contract Foo {"""


@pytest.fixture()
def foo_path(tmp_path, foo_source):
source = tmp_path.joinpath('Foo.sol')
with source.open('w') as fp:
fp.write(TEST_CONTRACT)
return str(source)
fp.write(foo_source)
return source


@pytest.fixture()
def contract_source():
yield TEST_CONTRACT
def bar_path(tmp_path, bar_source):
source = tmp_path.joinpath('Bar.sol')
with source.open('w') as fp:
fp.write(bar_source)
return source
43 changes: 39 additions & 4 deletions tests/test_compile.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,51 @@
#!/usr/bin/python3

import pytest

import solcx
from solcx.exceptions import ContractsNotFound


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


def test_compile_files(contract_path):
solcx.compile_files([contract_path])
def test_compile_source(foo_source):
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(" ")


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


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


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


def test_compile_files_wrong_type(foo_path):
with pytest.raises(TypeError):
solcx.compile_files(foo_path)
with pytest.raises(TypeError):
solcx.compile_files({foo_path: "foo"})


def test_compile_source(contract_source):
solcx.compile_source(contract_source)
def _compile_assertions(output, key):
assert output
assert key in output
assert 'bin' in output[key]
assert 'bin-runtime' in output[key]
Loading

0 comments on commit 4dc177f

Please sign in to comment.