def test_providing_standard_json_input(FOO_SOURCE, BAR_SOURCE): stdin = json.dumps({ "language": "Solidity", "sources": { "Foo.sol": { "content": FOO_SOURCE }, "Bar.sol": { "content": BAR_SOURCE } }, "settings": { "outputSelection": { "*": { "*": [ "abi", "evm.bytecode.link_references", "evm.bytecode.object", "devdoc", "metadata", "userdoc" ] } } } }) output, err, _, _ = solc_wrapper(stdin=stdin, standard_json=True) output = json.loads(output) assert output assert 'Foo.sol' in output['contracts'] assert 'Bar.sol' in output['contracts'] assert is_benign(err)
def compile_solfiles(files, proj_dir, solc_version=None, output_values=OUTPUT_VALUES): remappings = [] node_modules_dir = find_node_modules_dir(proj_dir) if node_modules_dir is not None: zeppelin_path = os.path.abspath(os.path.join( node_modules_dir, 'zeppelin-solidity')) open_zeppelin_path = os.path.abspath( os.path.join(node_modules_dir, 'openzeppelin-solidity')) if os.path.isdir(zeppelin_path): remappings.append(f'zeppelin-solidity={zeppelin_path}') if os.path.isdir(open_zeppelin_path): remappings.append(f'openzeppelin-solidity={open_zeppelin_path}') if solc_version is None: solc_version = min(map(parse_version, files), key=_version_to_tuple) binary = os.path.join(Path.home(), f'.py-solc/solc-v{solc_version}/bin/solc') combined_json = ','.join(output_values) compiler_kwargs = {'import_remappings': remappings, 'allow_paths': proj_dir, 'source_files': files, 'solc_binary': binary, 'combined_json': combined_json} try: stdoutdata, _, _, _ = solc_wrapper(**compiler_kwargs) return _parse_compiler_output(stdoutdata) except SolcError as e: raise SolidityCompilationException(e, files)
def _compile_solfiles(self, files, solc_version=None, output_values=utils.OUTPUT_VALUES): """Compiles the files using the solc compiler.""" node_modules_dir = utils.find_node_modules_dir(self.project_root) remappings = [] if node_modules_dir is not None: zeppelin_path = os.path.abspath(os.path.join( node_modules_dir, 'zeppelin-solidity')) open_zeppelin_path = os.path.abspath( os.path.join(node_modules_dir, 'openzeppelin-solidity')) if os.path.isdir(zeppelin_path): remappings.append(f'zeppelin-solidity={zeppelin_path}') if os.path.isdir(open_zeppelin_path): remappings.append(f'openzeppelin-solidity={open_zeppelin_path}') if solc_version is None: solc_version = min(map(utils.parse_sol_version, files), key=utils.version_to_tuple) binary = _get_binary(solc_version) combined_json = ','.join(output_values) compiler_kwargs = {'import_remappings': remappings, 'allow_paths': self.project_root, 'source_files': files, 'solc_binary': binary, 'combined_json': combined_json} try: stdoutdata, _, _, _ = solc_wrapper(**compiler_kwargs) return _parse_compiler_output(stdoutdata) except SolcError as e: raise utils.SolidityCompilationException(e, files)
def test_providing_single_source_file(contracts_dir, FOO_SOURCE): source_file_path = os.path.join(contracts_dir, 'Foo.sol') with open(source_file_path, 'w') as source_file: source_file.write(FOO_SOURCE) output, err, _, _ = solc_wrapper(source_files=[source_file_path], bin=True) assert output assert 'Foo' in output assert is_benign(err)
def test_providing_single_source_file(contracts_dir): source_file_path = os.path.join(contracts_dir, 'Foo.sol') with open(source_file_path, 'w') as source_file: source_file.write("contract Foo { function Foo() {} }") output, err = solc_wrapper(source_files=[source_file_path], bin=True) assert output assert 'Foo' in output assert not err
def test_providing_multiple_source_files(contracts_dir, FOO_SOURCE, BAR_SOURCE): source_file_a_path = os.path.join(contracts_dir, 'Foo.sol') source_file_b_path = os.path.join(contracts_dir, 'Bar.sol') with open(source_file_a_path, 'wb') as source_file: source_file.write(FOO_SOURCE) with open(source_file_b_path, 'wb') as source_file: source_file.write(BAR_SOURCE) output, err, _, _ = solc_wrapper(source_files=[source_file_a_path, source_file_b_path], bin=True) assert output assert 'Foo' in output assert 'Bar' in output assert not err
def test_providing_stdin(): stdin_bytes = b"contract Foo { function Foo() {} }" output, err = solc_wrapper(stdin_bytes=stdin_bytes, bin=True) assert output assert 'Foo' in output assert not err
def test_providing_stdin(FOO_SOURCE): output, err, _, _ = solc_wrapper(stdin=FOO_SOURCE, bin=True) assert output assert 'Foo' in output assert is_benign(err)
def test_version(): output, err, _, _ = solc_wrapper(version=True) assert output assert 'Version' in output assert is_benign(err)
def test_help(): output, err, _, _ = solc_wrapper(help=True, success_return_code=1) assert output assert 'Solidity' in output assert is_benign(err)
def test_version(): output, err = solc_wrapper(version=True) assert output assert 'Version' in output assert not err
def test_help(): output, err = solc_wrapper(help=True, success_return_code=1) assert output assert 'Solidity' in output assert not err
def test_providing_stdin(FOO_SOURCE): output, err, _, _ = solc_wrapper(stdin_bytes=FOO_SOURCE, bin=True) assert output assert 'Foo' in output assert not err