Skip to content

Commit

Permalink
feat: add kwargs to compile methods
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Nov 9, 2023
2 parents b6c2ef9 + 161e6bb commit d270c2a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions solcx/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -128,6 +129,7 @@ def compile_source(
no_optimize_yul=no_optimize_yul,
yul_optimizations=yul_optimizations,
allow_empty=allow_empty,
**kwargs,
)


Expand All @@ -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.
Expand Down Expand Up @@ -232,6 +235,7 @@ def compile_files(
no_optimize_yul=no_optimize_yul,
yul_optimizations=yul_optimizations,
allow_empty=allow_empty,
**kwargs,
)


Expand Down
21 changes: 21 additions & 0 deletions tests/main/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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
Expand Up @@ -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_source(foo_source, output_values=["abi"], random_kwarg="random-value")

0 comments on commit d270c2a

Please sign in to comment.