Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit a9f27d3

Browse files
authored
Merge pull request #431 from gsalgado/compile_code_error_when_solc_missing
compile_code: raise exception when solc missing
2 parents 64e9f63 + 0bee834 commit a9f27d3

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

ethereum/_solidity.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ class CompileError(Exception):
1717
pass
1818

1919

20+
class SolcMissing(Exception):
21+
pass
22+
23+
2024
def get_compiler_path():
2125
""" Return the path to the solc compiler.
2226
@@ -323,7 +327,10 @@ def compile_last_contract(filepath, libraries=None, combined='bin,abi', optimize
323327

324328
def compile_code(sourcecode, libraries=None, combined='bin,abi', optimize=True, extra_args=None):
325329
args = solc_arguments(libraries=libraries, combined=combined, optimize=optimize, extra_args=extra_args)
326-
args.insert(0, get_compiler_path())
330+
compiler = get_compiler_path()
331+
if compiler is None:
332+
raise SolcMissing("solc not found")
333+
args.insert(0, compiler)
327334

328335
process = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
329336
stdoutdata, stderrdata = process.communicate(input=utils.to_string(sourcecode))

ethereum/tests/test_solidity.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,10 @@ def test_extra_args():
271271
extra_args=["--optimize-runs", "100"]
272272
)
273273
assert bytecode_is_generated(contract_info, 'foo')
274+
275+
def test_missing_solc(monkeypatch):
276+
monkeypatch.setattr(_solidity, 'get_compiler_path', lambda: None)
277+
assert _solidity.get_compiler_path() is None
278+
sample_sol_code = "contract SampleContract {}"
279+
with pytest.raises(_solidity.SolcMissing):
280+
_solidity.compile_code(sample_sol_code)

0 commit comments

Comments
 (0)