Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add kwargs to compile functions by source and file #159

Merged
merged 2 commits into from
Nov 9, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add kwargs to compile functions by source and file
rfreis committed Jul 18, 2023
commit 4aeba6dd4bebdb4acb196f391319186f4de298d5
4 changes: 4 additions & 0 deletions solcx/main.py
Original file line number Diff line number Diff line change
@@ -47,6 +47,7 @@ def compile_source(
solc_binary: Union[str, Path] = None,
solc_version: Version = None,
allow_empty: bool = False,
**kwargs: Any,
) -> Dict:
"""
Compile a Solidity contract.
@@ -128,6 +129,7 @@ def compile_source(
no_optimize_yul=no_optimize_yul,
yul_optimizations=yul_optimizations,
allow_empty=allow_empty,
**kwargs,
)


@@ -151,6 +153,7 @@ def compile_files(
solc_binary: Union[str, Path] = None,
solc_version: Version = None,
allow_empty: bool = False,
**kwargs: Any,
) -> Dict:
"""
Compile one or more Solidity source files.
@@ -232,6 +235,7 @@ def compile_files(
no_optimize_yul=no_optimize_yul,
yul_optimizations=yul_optimizations,
allow_empty=allow_empty,
**kwargs,
)


21 changes: 21 additions & 0 deletions tests/main/conftest.py
Original file line number Diff line number Diff line change
@@ -20,3 +20,24 @@ def wrapper_mock(monkeypatch):
mock = WrapperMock()
monkeypatch.setattr("solcx.wrapper.solc_wrapper", mock)
yield mock


class CompileCombinedJsonMock:
"""
Simple mock for solcx.main._compile_combined_json
"""

def __call__(self, **kwargs):
for key, value in self.kwargs.items():
assert kwargs[key] == value
return {}

def expect(self, **kwargs):
self.kwargs = kwargs


@pytest.fixture
def compile_combined_json_mock(monkeypatch):
mock = CompileCombinedJsonMock()
monkeypatch.setattr("solcx.main._compile_combined_json", mock)
yield mock
5 changes: 5 additions & 0 deletions tests/main/test_compile_files.py
Original file line number Diff line number Diff line change
@@ -122,3 +122,8 @@ def test_solc_version(wrapper_mock, all_versions, foo_path):
solc_binary = solcx.install.get_executable(all_versions)
wrapper_mock.expect(solc_binary=solc_binary)
solcx.compile_files([foo_path], ["abi"], solc_version=all_versions, allow_empty=True)


def test_value_kwargs(compile_combined_json_mock, foo_path):
compile_combined_json_mock.expect(random_kwarg="random-value")
solcx.compile_files(foo_path, output_values=["abi"], random_kwarg="random-value")
5 changes: 5 additions & 0 deletions tests/main/test_compile_source.py
Original file line number Diff line number Diff line change
@@ -104,3 +104,8 @@ def test_solc_version(wrapper_mock, all_versions, foo_source):
solc_binary = solcx.install.get_executable(all_versions)
wrapper_mock.expect(solc_binary=solc_binary)
solcx.compile_source(foo_source, ["abi"], solc_version=all_versions, allow_empty=True)


def test_value_kwargs(compile_combined_json_mock, foo_source):
compile_combined_json_mock.expect(random_kwarg="random-value")
solcx.compile_files(foo_source, output_values=["abi"], random_kwarg="random-value")