From 508aa507eb6e5785d59e23478839e9b78ee4dcbe Mon Sep 17 00:00:00 2001 From: antazoey Date: Wed, 7 Aug 2024 19:57:06 -0500 Subject: [PATCH] fix: issue where revert message is None (#2210) --- .pre-commit-config.yaml | 4 ++-- setup.py | 4 ++-- src/ape_ethereum/trace.py | 5 ++++- tests/conftest.py | 4 ++-- tests/functional/conftest.py | 1 + tests/functional/test_trace.py | 15 +++++++++++++++ 6 files changed, 26 insertions(+), 7 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ca5b629243..3b49eb00ae 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,13 +10,13 @@ repos: - id: isort - repo: https://github.com/psf/black - rev: 24.4.2 + rev: 24.8.0 hooks: - id: black name: black - repo: https://github.com/pycqa/flake8 - rev: 7.1.0 + rev: 7.1.1 hooks: - id: flake8 additional_dependencies: [flake8-breakpoint, flake8-print, flake8-pydantic] diff --git a/setup.py b/setup.py index 67bdef3b43..433eb31c51 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ "hypothesis-jsonschema==0.19.0", # JSON Schema fuzzer extension ], "lint": [ - "black>=24.4.2,<25", # Auto-formatter and linter + "black>=24.8.0,<25", # Auto-formatter and linter "mypy>=1.11.1,<2", # Static type analyzer "types-PyYAML", # Needed due to mypy typeshed "types-requests", # Needed due to mypy typeshed @@ -30,7 +30,7 @@ "types-toml", # Needed due to mypy typeshed "types-SQLAlchemy>=1.4.49", # Needed due to mypy typeshed "types-python-dateutil", # Needed due to mypy typeshed - "flake8>=7.1.0,<8", # Style linter + "flake8>=7.1.1,<8", # Style linter "flake8-breakpoint>=1.1.0,<2", # Detect breakpoints left in code "flake8-print>=4.0.1,<5", # Detect print statements left in code "flake8-pydantic", # For detecting issues with Pydantic models diff --git a/src/ape_ethereum/trace.py b/src/ape_ethereum/trace.py index 9472dea448..01fa157919 100644 --- a/src/ape_ethereum/trace.py +++ b/src/ape_ethereum/trace.py @@ -268,7 +268,10 @@ def try_get_revert_msg(c) -> Optional[str]: return message # Enrichment call-tree not available. Attempt looking in trace-frames. - return to_hex(self._revert_str_from_trace_frames) + if revert_str := self._revert_str_from_trace_frames: + return to_hex(revert_str) + + return None @cached_property def _last_frame(self) -> Optional[dict]: diff --git a/tests/conftest.py b/tests/conftest.py index adb999e2ab..9c02bad3cd 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -94,9 +94,9 @@ def validate_cwd(start_dir): def project(): path = "tests/functional/data/contracts/ethereum/local" with ape.project.temp_config(contracts_folder=path): - ape.project.manifest_path.unlink(missing_ok=True) + ape.project.clean() yield ape.project - ape.project.manifest_path.unlink(missing_ok=True) + ape.project.clean() @pytest.fixture(scope="session") diff --git a/tests/functional/conftest.py b/tests/functional/conftest.py index 4bfe5159de..76341e1f82 100644 --- a/tests/functional/conftest.py +++ b/tests/functional/conftest.py @@ -302,6 +302,7 @@ def project_with_dependency_config(project): } ], } + project.clean() with project.isolate_in_tempdir(**dependencies_config) as tmp_project: yield tmp_project diff --git a/tests/functional/test_trace.py b/tests/functional/test_trace.py index 2a4515f21f..e3b310ccd4 100644 --- a/tests/functional/test_trace.py +++ b/tests/functional/test_trace.py @@ -219,6 +219,21 @@ def test_revert_message_custom_error(simple_trace_cls, setup_custom_error): assert trace.revert_message == expected +def test_revert_message_empty(owner): + tx = owner.transfer(owner, 0) + trace = TransactionTrace.model_validate({"transaction_hash": tx.txn_hash}) + + # Hack in criteria to cause it to look for a revert message more. + trace._enriched_calltree = {"failed": True} + + # Only testing private member here because it was related to the bug. + assert trace._revert_str_from_trace_frames is None + + # For failed transactions with no available revert message, it should NOT crash! + # (It's None because there is no revert message). + assert trace.revert_message is None + + def test_enriched_calltree_adds_missing_gas(simple_trace_cls): compute_gas = 1234 base_gas = 21_000