import pytest from populus.solidity import ( solc, version_regex, is_solc_available, ) skip_if_no_sol_compiler = pytest.mark.skipif( not is_solc_available(), reason="'solc' compiler not available", ) contract_source = "contract Example { function Example() {}}" contract_compiled_raw = '{"contracts":{"Example":{"abi":"[{\\"inputs\\":[],\\"type\\":\\"constructor\\"}]\\n","bin":"60606040525b5b600a8060126000396000f360606040526008565b00","devdoc":"{\\n \\"methods\\" : {}\\n}\\n","userdoc":"{\\n \\"methods\\" : {}\\n}\\n"}},"version":"0.1.3-1736fe80/RelWithDebInfo-Darwin/unknown/JIT linked to libethereum-0.9.92-dcf2fd11/RelWithDebInfo-Darwin/unknown/JIT"}\n\n' # NOQA contract_compiled_json = [('Example', {'bin': '60606040525b5b600a8060126000396000f360606040526008565b00', 'abi': [{'inputs': [], 'type': 'constructor'}], 'userdoc': {'methods': {}}, 'devdoc': {'methods': {}}})] # NOQA contract_compiled_json_rich = {'Example': {'natspec-user': {'methods': {}}, 'binary': '60606040525b5b600a8060136000396000f30060606040526008565b00', 'json-abi': [{'inputs': [], 'type': 'constructor'}], 'sol-abi': 'contract Example{function Example();}', 'natspec-dev': {'methods': {}}}} def test_source_and_input_files_mutually_exclusive(): with pytest.raises(ValueError): solc(source=contract_source, input_files=['someContract.sol']) def test_one_of_source_or_input_files_required(): with pytest.raises(ValueError): solc()
import pytest import os from populus.compilation import ( compile_and_write_contracts, ) from populus.solidity import ( is_solc_available, ) skip_if_no_sol_compiler = pytest.mark.skipif( not is_solc_available(), reason="'solc' compiler not available", ) BASE_DIR = os.path.abspath(os.path.dirname(__file__)) project_dir = os.path.join(BASE_DIR, 'projects', 'test-01') @pytest.fixture(autouse=True) def _project_dir(monkeypatch): monkeypatch.chdir(project_dir) return project_dir @skip_if_no_sol_compiler def test_compilation(): compile_and_write_contracts(project_dir)
import pytest from populus.compilation import get_compiler_for_file from populus.solidity import ( solc, is_solc_available, ) @pytest.mark.parametrize('filename', ['unknown.txt', 'unknown.bak', 'swap.sol.swp']) def test_unknown_contract_extensions(filename): with pytest.raises(ValueError): get_compiler_for_file(filename) @pytest.mark.skipif(is_solc_available() is None, reason="'solc' compiler not available") def test_solidity_compiler(): compiler = get_compiler_for_file('Example.sol') assert compiler == solc @pytest.mark.skipif(is_solc_available() is not None, reason="'solc' compiler available") def test_solidity_compiler_not_available(): with pytest.raises(ValueError): get_compiler_for_file('Example.sol')