Skip to content

Commit

Permalink
Address comments on PR ethereum#3012
Browse files Browse the repository at this point in the history
  • Loading branch information
fselmo committed Jul 7, 2023
1 parent 90fcf86 commit 1f1bd7f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
3 changes: 2 additions & 1 deletion tests/core/middleware/test_name_to_address_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Web3,
)
from web3.exceptions import (
InvalidAddress,
NameNotFound,
)
from web3.middleware import (
Expand Down Expand Up @@ -96,7 +97,7 @@ def test_pass_name_resolver_send_transaction_dict_args(


def test_fail_name_resolver(w3):
with pytest.raises(NameNotFound, match=r".*ethereum\.eth.*"):
with pytest.raises(InvalidAddress, match=r".*ethereum\.eth.*"):
w3.eth.get_balance("ethereum.eth")


Expand Down
13 changes: 10 additions & 3 deletions web3/_utils/normalizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
)
from web3.exceptions import (
InvalidAddress,
NameNotFound,
)
from web3.types import (
ABI,
Expand Down Expand Up @@ -220,10 +221,16 @@ def abi_ens_resolver(
_ens = cast(ENS, w3.ens)
if _ens is None:
raise InvalidAddress(
f"Could not look up name {val!r} because ENS is" " set to None"
f"Could not look up name {val!r} because ENS is set to None"
)
else:
return type_str, validate_name_has_address(_ens, val)
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 v7 and allow
# NameNotFound to raise.
raise InvalidAddress(f"{e}")
else:
return type_str, val

Expand Down Expand Up @@ -285,7 +292,7 @@ async def async_abi_ens_resolver(
_async_ens = cast(AsyncENS, async_w3.ens)
if _async_ens is None:
raise InvalidAddress(
f"Could not look up name {val!r} because ENS is" " set to None"
f"Could not look up name {val!r} because ENS is set to None"
)
else:
address = await async_validate_name_has_address(_async_ens, val)
Expand Down

0 comments on commit 1f1bd7f

Please sign in to comment.