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

Commit 0bee834

Browse files
committed
compile_code: raise exception when solc missing
When solc is not installed, compile_code() would end up using None as the first element in the args list passed to subprocess.Popen(), causing it to crash with an AttributeError. This fixes that
1 parent 22e96d2 commit 0bee834

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
@@ -296,7 +300,10 @@ def compile_last_contract(filepath, libraries=None, combined='bin,abi', optimize
296300

297301
def compile_code(sourcecode, libraries=None, combined='bin,abi', optimize=True, extra_args=None):
298302
args = solc_arguments(libraries=libraries, combined=combined, optimize=optimize, extra_args=extra_args)
299-
args.insert(0, get_compiler_path())
303+
compiler = get_compiler_path()
304+
if compiler is None:
305+
raise SolcMissing("solc not found")
306+
args.insert(0, compiler)
300307

301308
process = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
302309
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
@@ -269,3 +269,10 @@ def test_extra_args():
269269
extra_args=["--optimize-runs", "100"]
270270
)
271271
assert bytecode_is_generated(contract_info, 'foo')
272+
273+
def test_missing_solc(monkeypatch):
274+
monkeypatch.setattr(_solidity, 'get_compiler_path', lambda: None)
275+
assert _solidity.get_compiler_path() is None
276+
sample_sol_code = "contract SampleContract {}"
277+
with pytest.raises(_solidity.SolcMissing):
278+
_solidity.compile_code(sample_sol_code)

0 commit comments

Comments
 (0)