Skip to content

Commit 1f1bd7f

Browse files
committed
Address comments on PR #3012
1 parent 90fcf86 commit 1f1bd7f

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

tests/core/middleware/test_name_to_address_middleware.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
Web3,
88
)
99
from web3.exceptions import (
10+
InvalidAddress,
1011
NameNotFound,
1112
)
1213
from web3.middleware import (
@@ -96,7 +97,7 @@ def test_pass_name_resolver_send_transaction_dict_args(
9697

9798

9899
def test_fail_name_resolver(w3):
99-
with pytest.raises(NameNotFound, match=r".*ethereum\.eth.*"):
100+
with pytest.raises(InvalidAddress, match=r".*ethereum\.eth.*"):
100101
w3.eth.get_balance("ethereum.eth")
101102

102103

web3/_utils/normalizers.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
)
5959
from web3.exceptions import (
6060
InvalidAddress,
61+
NameNotFound,
6162
)
6263
from web3.types import (
6364
ABI,
@@ -220,10 +221,16 @@ def abi_ens_resolver(
220221
_ens = cast(ENS, w3.ens)
221222
if _ens is None:
222223
raise InvalidAddress(
223-
f"Could not look up name {val!r} because ENS is" " set to None"
224+
f"Could not look up name {val!r} because ENS is set to None"
224225
)
225226
else:
226-
return type_str, validate_name_has_address(_ens, val)
227+
try:
228+
return type_str, validate_name_has_address(_ens, val)
229+
except NameNotFound as e:
230+
# TODO: This try/except is to keep backwards compatibility when we
231+
# removed the mainnet requirement. Remove this in web3.py v7 and allow
232+
# NameNotFound to raise.
233+
raise InvalidAddress(f"{e}")
227234
else:
228235
return type_str, val
229236

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

0 commit comments

Comments
 (0)