Skip to content

Commit 366170d

Browse files
authored
Allow async ens tests to run (#3675)
* Allow async ens tests to run * Add newsfragment for #3675
1 parent 7bec6f7 commit 366170d

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

newsfragments/3675.internal.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
AsyncENS tests were xfailing for the wrong reason.

web3/_utils/ens.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,21 @@ def address(self, name: str) -> ChecksumAddress:
6565
return self.registry.get(name, None)
6666

6767

68+
class AsyncStaticENS:
69+
def __init__(self, name_addr_pairs: Dict[str, ChecksumAddress]) -> None:
70+
self.registry = dict(name_addr_pairs)
71+
72+
async def address(self, name: str) -> ChecksumAddress:
73+
return self.registry.get(name, None)
74+
75+
6876
@contextmanager
6977
def ens_addresses(
7078
w3: Union["Web3", "AsyncWeb3"], name_addr_pairs: Dict[str, ChecksumAddress]
7179
) -> Iterator[None]:
7280
original_ens = w3.ens
7381
if w3.provider.is_async:
74-
w3.ens = cast(AsyncENS, StaticENS(name_addr_pairs))
82+
w3.ens = cast(AsyncENS, AsyncStaticENS(name_addr_pairs))
7583
else:
7684
w3.ens = cast(ENS, StaticENS(name_addr_pairs))
7785
yield

web3/_utils/module_testing/eth_module.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,6 @@ async def test_async_eth_sign_transaction_hex_fees(
454454
assert result["tx"]["nonce"] == txn_params["nonce"]
455455

456456
@pytest.mark.asyncio
457-
@pytest.mark.xfail(
458-
reason="async name_to_address_middleware has not been implemented yet"
459-
)
460457
async def test_async_eth_sign_transaction_ens_names(
461458
self, async_w3: "AsyncWeb3", async_keyfile_account_address: ChecksumAddress
462459
) -> None:
@@ -2086,7 +2083,6 @@ async def test_async_eth_get_storage_at(
20862083
assert bytes(slot_4[:4]) == b"four"
20872084

20882085
@pytest.mark.asyncio
2089-
@pytest.mark.xfail
20902086
async def test_async_eth_get_storage_at_ens_name(
20912087
self, async_w3: "AsyncWeb3", async_storage_contract: "AsyncContract"
20922088
) -> None:
@@ -2238,9 +2234,6 @@ async def test_async_eth_sign(
22382234
assert new_signature != signature
22392235

22402236
@pytest.mark.asyncio
2241-
@pytest.mark.xfail(
2242-
reason="Async middleware to convert ENS names to addresses is missing"
2243-
)
22442237
async def test_async_eth_sign_ens_names(
22452238
self,
22462239
async_w3: "AsyncWeb3",

0 commit comments

Comments
 (0)