Skip to content

Commit

Permalink
address comments on PR #2547
Browse files Browse the repository at this point in the history
  • Loading branch information
fselmo committed Jul 1, 2022
1 parent c5f2b8c commit 5a6d2e2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 22 deletions.
11 changes: 2 additions & 9 deletions tests/ens/test_get_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@
)
from web3 import Web3

SET_TEXT_RESOLVER_NOT_FOUND_CASES = (
("avatar", "tester.jpeg"),
("email", "[email protected]"),
("url", "http://example.com"),
("description", "a test"),
("notice", "this contract is a test contract"),
)
GET_TEXT_TEST_CASES = (
("avatar", "tester.jpeg"),
("email", "[email protected]"),
Expand All @@ -26,7 +19,7 @@
)


@pytest.mark.parametrize("key,expected", SET_TEXT_RESOLVER_NOT_FOUND_CASES)
@pytest.mark.parametrize("key,expected", GET_TEXT_TEST_CASES)
def test_set_text_resolver_not_found(ens, key, expected):
with pytest.raises(ResolverNotFound):
ens.set_text("tld", key, expected)
Expand Down Expand Up @@ -92,7 +85,7 @@ def test_get_text_for_resolver_with_unsupported_function(ens):


@pytest.mark.asyncio
@pytest.mark.parametrize("key,expected", SET_TEXT_RESOLVER_NOT_FOUND_CASES)
@pytest.mark.parametrize("key,expected", GET_TEXT_TEST_CASES)
async def test_async_set_text_resolver_not_found(async_ens, key, expected):
with pytest.raises(ResolverNotFound):
await async_ens.set_text("tld", key, expected)
Expand Down
4 changes: 2 additions & 2 deletions tests/ens/test_wildcard_resolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def test_wildcard_resolution_with_extended_resolver_for_subdomains(ens, subdomai
assert resolved_child_address == "0x000000000000000000000000000000000000dEaD"


def test_async_wildcard_resolution_with_extended_resolver_for_parent_ens_domain(ens):
def test_wildcard_resolution_with_extended_resolver_for_parent_ens_domain(ens):
# validate `extended-resolver.eth` by asserting it returns the specified hard-coded address from
# `tests/test_contracts/ExtendedResolver.sol` which requires a specific condition to be
# met for the parent domain `extended-resolver.eth`
Expand All @@ -36,7 +36,7 @@ async def test_async_wildcard_resolution_with_extended_resolver_for_subdomains(


@pytest.mark.asyncio
async def test_wildcard_resolution_with_extended_resolver_for_parent_ens_domain(
async def test_async_wildcard_resolution_with_extended_resolver_for_parent_ens_domain(
async_ens,
):
# validate `extended-resolver.eth` by asserting it returns the specified hard-coded address from
Expand Down
13 changes: 6 additions & 7 deletions web3/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@

if TYPE_CHECKING:
from web3.pm import PM # noqa: F401
from web3._utils.empty import Empty # noqa: F401


def get_default_modules() -> Dict[str, Union[Type[Module], Sequence[Any]]]:
Expand Down Expand Up @@ -249,7 +250,7 @@ def __init__(
external_modules: Optional[
Dict[str, Union[Type[Module], Sequence[Any]]]
] = None,
ens: Optional[Union[ENS, AsyncENS]] = None,
ens: Union[ENS, AsyncENS, "Empty"] = empty,
) -> None:
self.manager = self.RequestManager(self, provider, middlewares)
# this codec gets used in the module initialization,
Expand Down Expand Up @@ -350,16 +351,14 @@ def is_encodable(self, _type: TypeStr, value: Any) -> bool:
return self.codec.is_encodable(_type, value)

@property
def ens(self) -> Union[ENS, AsyncENS]:
if self._ens is cast(ENS, empty):
return ENS.fromWeb3(self)
elif self._ens is cast(AsyncENS, empty) or self.eth.is_async:
return AsyncENS.fromWeb3(self)
def ens(self) -> Union[ENS, AsyncENS, "Empty"]:
if self._ens is empty:
return AsyncENS.fromWeb3(self) if self.eth.is_async else ENS.fromWeb3(self)

return self._ens

@ens.setter
def ens(self, new_ens: Optional[Union[ENS, AsyncENS]]) -> None:
def ens(self, new_ens: Union[ENS, AsyncENS, "Empty"]) -> None:
self._ens = new_ens

@property
Expand Down
7 changes: 3 additions & 4 deletions web3/pm.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
to_tuple,
)

from ens import ENS
from ethpm import (
ASSETS_DIR,
Package,
Expand Down Expand Up @@ -62,9 +63,6 @@
from web3.module import (
Module,
)
from web3.types import (
ENS,
)

# Package Management is still in alpha, and its API is likely to change, so it
# is not automatically available on a web3 instance. To use the `PM` module,
Expand Down Expand Up @@ -383,7 +381,8 @@ def set_registry(self, address: Union[Address, ChecksumAddress, ENS]) -> None:
self.registry = SimpleRegistry(cast(ChecksumAddress, address), self.w3)
elif is_ens_name(address):
self._validate_set_ens()
addr_lookup = cast(ChecksumAddress, self.w3.ens.address(str(address)))
ens = cast(ENS, self.w3.ens)
addr_lookup = ens.address(str(address))
if not addr_lookup:
raise NameNotFound(
f"No address found after ENS lookup for name: {address!r}."
Expand Down

0 comments on commit 5a6d2e2

Please sign in to comment.