diff --git a/.gitignore b/.gitignore index b2da5de..87cbe24 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,4 @@ version.py *.swo tests/node_modules +.benchmarks/ diff --git a/README.md b/README.md index 4dfa726..3e389e8 100644 --- a/README.md +++ b/README.md @@ -97,8 +97,8 @@ Use the `add_library()` method from the `ape-solidity` compiler class to add the A typical flow is: 1. Deploy the library. -1. Call `add_library()` using the Solidity compiler plugin, which will also re-compile contracts that need the library. -1. Deploy and use contracts that require the library. +2. Call `add_library()` using the Solidity compiler plugin, which will also re-compile contracts that need the library. +3. Deploy and use contracts that require the library. For example: diff --git a/ape_solidity/compiler.py b/ape_solidity/compiler.py index ba62a95..df50f45 100644 --- a/ape_solidity/compiler.py +++ b/ape_solidity/compiler.py @@ -11,8 +11,7 @@ from ape.utils import cached_property, get_relative_path from eth_pydantic_types import HexBytes from eth_utils import add_0x_prefix, is_0x_prefixed -from ethpm_types import ASTNode, PackageManifest -from ethpm_types.ast import ASTClassification +from ethpm_types import PackageManifest from ethpm_types.source import Compiler, Content from packaging.specifiers import SpecifierSet from packaging.version import Version @@ -455,7 +454,6 @@ def get_standard_input_json( if not list(files_by_solc_version[solc_version]): continue - logger.debug(f"Compiling using Solidity compiler '{solc_version}'") cleaned_version = Version(solc_version.base_version) solc_binary = get_executable(version=cleaned_version) arguments = {"solc_binary": solc_binary, "solc_version": cleaned_version} @@ -521,17 +519,8 @@ def compile( if source_id in str(input_file_path): input_contract_names.append(name) - def classify_ast(_node: ASTNode): - if _node.ast_type in ("FunctionDefinition", "FunctionDefinitionNode"): - _node.classification = ASTClassification.FUNCTION - - for child in _node.children: - classify_ast(child) - for source_id, contracts_out in contracts.items(): - ast_data = output["sources"][source_id]["ast"] - ast = ASTNode.model_validate(ast_data) - classify_ast(ast) + # ast_data = output["sources"][source_id]["ast"] for contract_name, ct_data in contracts_out.items(): contract_path = base_path / source_id @@ -579,7 +568,6 @@ def classify_ast(_node: ASTNode): ct_data["userdoc"] = load_dict(ct_data["userdoc"]) ct_data["devdoc"] = load_dict(ct_data["devdoc"]) ct_data["sourcemap"] = evm_data["bytecode"]["sourceMap"] - ct_data["ast"] = ast contract_type = ContractType.model_validate(ct_data) contract_types.append(contract_type) contract_versions[contract_name] = solc_version diff --git a/setup.py b/setup.py index b4506b6..db349d6 100644 --- a/setup.py +++ b/setup.py @@ -9,6 +9,7 @@ "pytest-cov", # Coverage analyzer plugin "pytest-mock", # For creating and using mocks "hypothesis>=6.2.0,<7.0", # Strategy-based fuzzer + "pytest-benchmark", # For performance tests ], "lint": [ "black>=23.12.0,<24", # Auto-formatter and linter @@ -21,6 +22,7 @@ "mdformat>=0.7.17", # Auto-formatter for markdown "mdformat-gfm>=0.3.5", # Needed for formatting GitHub-flavored markdown "mdformat-frontmatter>=0.4.1", # Needed for frontmatters-style headers in issue templates + "mdformat-pyproject>=0.0.1", # Allows configuring in pyproject.toml ], "doc": [ "Sphinx>=6.1.3,<7", # Documentation generator diff --git a/tests/test_compiler.py b/tests/test_compiler.py index 8af011e..f57c5ff 100644 --- a/tests/test_compiler.py +++ b/tests/test_compiler.py @@ -8,7 +8,6 @@ from ape import reverts from ape.contracts import ContractContainer from ape.exceptions import CompilerError -from ethpm_types.ast import ASTClassification from packaging.version import Version from pkg_resources import get_distribution from requests.exceptions import ConnectionError @@ -50,6 +49,15 @@ def test_compile(project, contract): assert contract.source_id == f"{contract.name}.sol" +def test_compile_performance(benchmark, compiler, project): + """ + See https://pytest-benchmark.readthedocs.io/en/latest/ + """ + source_path = project.contracts_folder / "MultipleDefinitions.sol" + result = benchmark.pedantic(compiler.compile, args=([source_path],), rounds=1) + assert len(result) > 0 + + def test_compile_solc_not_installed(project, fake_no_installs): assert len(project.load_contracts(use_cache=False)) > 0 @@ -477,12 +485,13 @@ def test_enrich_error_when_builtin(project, owner, connection): contract.checkIndexOutOfBounds(sender=owner) -def test_ast(project, compiler): - source_path = project.contracts_folder / "MultipleDefinitions.sol" - actual = compiler.compile([source_path])[-1].ast - fn_node = actual.children[1].children[0] - assert actual.ast_type == "SourceUnit" - assert fn_node.classification == ASTClassification.FUNCTION +# TODO: Not yet used and super slow. +# def test_ast(project, compiler): +# source_path = project.contracts_folder / "MultipleDefinitions.sol" +# actual = compiler.compile([source_path])[-1].ast +# fn_node = actual.children[1].children[0] +# assert actual.ast_type == "SourceUnit" +# assert fn_node.classification == ASTClassification.FUNCTION def test_via_ir(project, compiler):