Skip to content

fix(ens): remove abi_ens_resolver v8 backwards-compat NameNotFound catch#3844

Open
genisis0x wants to merge 1 commit into
ApeWorX:mainfrom
genisis0x:fix/3580-ens-v7-todo-removal
Open

fix(ens): remove abi_ens_resolver v8 backwards-compat NameNotFound catch#3844
genisis0x wants to merge 1 commit into
ApeWorX:mainfrom
genisis0x:fix/3580-ens-v7-todo-removal

Conversation

@genisis0x
Copy link
Copy Markdown

What

Closes #3580.

web3/_utils/normalizers.py:227 had a TODO flagging the try/except NameNotFound block for removal in v8:

try:
    return type_str, validate_name_has_address(_ens, val)
except NameNotFound as e:
    # TODO: This try/except is to keep backwards compatibility when we
    #  removed the mainnet requirement. Remove this in web3.py v8 and allow
    #  NameNotFound to raise.
    if not isinstance(_ens, StaticENS):
        raise InvalidAddress(f"{e}")
    raise e

v8 has shipped (8.0.0-beta.3), so the backward-compat wrap can go.

Changes

  • web3/_utils/normalizers.py: drop the try/except and let NameNotFound propagate from validate_name_has_address directly. The sync resolver now matches async_abi_ens_resolver (line 282-304), which already has no such guard — closing a sync/async inconsistency the TODO already implied.
  • web3/_utils/normalizers.py: remove the now-unused StaticENS and NameNotFound imports.
  • tests/core/middleware/test_name_to_address_middleware.py::test_fail_name_resolver: switch the expectation from InvalidAddress to NameNotFound. The async counterpart at line 179 (test_async_fail_name_resolver) already expects NameNotFound, so this aligns the two paths.
  • newsfragments/3580.breaking.rst: user-facing breaking-change note.

Compat surface

The only callers exposed to the change are those that previously caught InvalidAddress on ENS lookup failures specifically. Two filtered grep sweeps to confirm no internal callers in the repo depend on the old shape:

  • All other pytest.raises(InvalidAddress) sites in tests/core/contracts/test_contract_call_interface.py and tests/core/utilities/test_validation.py pass non-checksum hex addresses through validate_address, not ENS names through abi_ens_resolver, so they keep raising InvalidAddress as before.
  • Async-side tests that exercise the same surface already expect NameNotFound.

Tests

$ python -m pytest tests/core/middleware/test_name_to_address_middleware.py tests/core/contracts/test_contract_call_interface.py -q
423 passed, 7 xfailed in 22.60s

$ python -m pytest tests/core/ -q
13088 passed, 7 skipped, 9 xfailed in 237s
(one pre-existing macOS-only failure in tests/core/providers/test_auto_provider.py::test_get_dev_ipc_path
 unrelated to this change — Python's tempfile.gettempdir() resolves /tmp to /var/folders/... on macOS;
 Linux CI will not see this)

pre-commit run --files web3/_utils/normalizers.py tests/core/middleware/test_name_to_address_middleware.py — all hooks green (black, flake8, isort, pydocstyle, mypy, autoflake, pyupgrade, blocklint).

…tch (ApeWorX#3580)

The TODO at web3/_utils/normalizers.py:227 flagged the try/except NameNotFound
block for removal in web3.py v8. v8 has shipped (beta.3 / 8.0.0-beta.3), so the
backward-compat wrap of NameNotFound into InvalidAddress can go.

After the change the sync abi_ens_resolver lets NameNotFound propagate from
validate_name_has_address regardless of whether the configured resolver is a
StaticENS — matching async_abi_ens_resolver which already had no such guard.

Updated tests/core/middleware/test_name_to_address_middleware.py::test_fail_name_resolver
to expect NameNotFound (the async counterpart at line 179 already does), and
dropped the now-unused StaticENS / NameNotFound imports from normalizers.py.

Closes ApeWorX#3580
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove ENS backward compatibility code in abi_ens_resolver (v7 TODO)

1 participant