Skip to content

Commit

Permalink
Fix some async typing in eth_module tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fselmo committed Apr 3, 2024
1 parent 68fd07e commit cfb931d
Showing 1 changed file with 32 additions and 28 deletions.
60 changes: 32 additions & 28 deletions web3/_utils/module_testing/eth_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,19 @@
if TYPE_CHECKING:
from _pytest.monkeypatch import MonkeyPatch # noqa: F401

from web3.contract import Contract # noqa: F401
from web3.contract import ( # noqa: F401
AsyncContract,
Contract,
)
from web3.main import ( # noqa: F401
AsyncWeb3,
Web3,
)


def abi_encoded_offchain_lookup_contract_address(
w3: Union["Web3", "AsyncWeb3"], offchain_lookup_contract: "Contract"
w3: Union["Web3", "AsyncWeb3"],
offchain_lookup_contract: Union["Contract", "AsyncContract"],
) -> HexAddress:
return HexAddress(
remove_0x_prefix(
Expand Down Expand Up @@ -836,7 +840,7 @@ async def test_eth_estimate_gas(
async def test_eth_estimate_gas_with_override_param_type_check(
self,
async_w3: "AsyncWeb3",
async_math_contract: "Contract",
async_math_contract: "AsyncContract",
params: CallOverrideParams,
) -> None:
txn_params: TxParams = {"from": await async_w3.eth.coinbase}
Expand Down Expand Up @@ -1134,7 +1138,7 @@ async def test_eth_get_code(
async def test_eth_get_code_invalid_address(
self,
async_w3: "AsyncWeb3",
async_math_contract: "Contract",
async_math_contract: "AsyncContract",
) -> None:
with pytest.raises(InvalidAddress):
await async_w3.eth.get_code(
Expand All @@ -1143,7 +1147,7 @@ async def test_eth_get_code_invalid_address(

@pytest.mark.asyncio
async def test_eth_get_code_with_block_identifier(
self, async_w3: "AsyncWeb3", async_emitter_contract: "Contract"
self, async_w3: "AsyncWeb3", async_emitter_contract: "AsyncContract"
) -> None:
block_id = await async_w3.eth.block_number
code = await async_w3.eth.get_code(async_emitter_contract.address, block_id)
Expand All @@ -1155,7 +1159,7 @@ async def test_eth_create_access_list(
self,
async_w3: "AsyncWeb3",
async_unlocked_account_dual_type: ChecksumAddress,
async_math_contract: "Contract",
async_math_contract: "AsyncContract",
) -> None:
# build txn
txn = await async_math_contract.functions.incrementCounter(1).build_transaction(
Expand Down Expand Up @@ -1192,7 +1196,7 @@ async def test_eth_get_transaction_count(

@pytest.mark.asyncio
async def test_eth_call(
self, async_w3: "AsyncWeb3", async_math_contract: "Contract"
self, async_w3: "AsyncWeb3", async_math_contract: "AsyncContract"
) -> None:
coinbase = await async_w3.eth.coinbase
txn_params = async_math_contract._prepare_transaction(
Expand All @@ -1209,7 +1213,7 @@ async def test_eth_call(
async def test_eth_call_with_override_code(
self,
async_w3: "AsyncWeb3",
async_revert_contract: "Contract",
async_revert_contract: "AsyncContract",
) -> None:
coinbase = await async_w3.eth.coinbase
txn_params = async_revert_contract._prepare_transaction(
Expand Down Expand Up @@ -1265,7 +1269,7 @@ async def test_eth_call_with_override_code(
async def test_eth_call_with_override_param_type_check(
self,
async_w3: "AsyncWeb3",
async_math_contract: "Contract",
async_math_contract: "AsyncContract",
params: CallOverrideParams,
) -> None:
coinbase = await async_w3.eth.coinbase
Expand All @@ -1278,7 +1282,7 @@ async def test_eth_call_with_override_param_type_check(

@pytest.mark.asyncio
async def test_eth_call_with_0_result(
self, async_w3: "AsyncWeb3", async_math_contract: "Contract"
self, async_w3: "AsyncWeb3", async_math_contract: "AsyncContract"
) -> None:
coinbase = await async_w3.eth.coinbase
txn_params = async_math_contract._prepare_transaction(
Expand All @@ -1295,7 +1299,7 @@ async def test_eth_call_with_0_result(
async def test_eth_call_revert_with_msg(
self,
async_w3: "AsyncWeb3",
async_revert_contract: "Contract",
async_revert_contract: "AsyncContract",
async_unlocked_account: ChecksumAddress,
) -> None:
txn_params = async_revert_contract._prepare_transaction(
Expand All @@ -1314,7 +1318,7 @@ async def test_eth_call_revert_with_msg(
async def test_eth_call_revert_without_msg(
self,
async_w3: "AsyncWeb3",
async_revert_contract: "Contract",
async_revert_contract: "AsyncContract",
async_unlocked_account: ChecksumAddress,
) -> None:
with pytest.raises(ContractLogicError, match="execution reverted"):
Expand All @@ -1331,7 +1335,7 @@ async def test_eth_call_revert_without_msg(
async def test_eth_call_revert_custom_error_with_msg(
self,
async_w3: "AsyncWeb3",
async_revert_contract: "Contract",
async_revert_contract: "AsyncContract",
async_unlocked_account: ChecksumAddress,
) -> None:
data = async_revert_contract.encode_abi(
Expand All @@ -1351,7 +1355,7 @@ async def test_eth_call_revert_custom_error_with_msg(
async def test_eth_call_revert_custom_error_without_msg(
self,
async_w3: "AsyncWeb3",
async_revert_contract: "Contract",
async_revert_contract: "AsyncContract",
async_unlocked_account: ChecksumAddress,
) -> None:
data = async_revert_contract.encode_abi(fn_name="Unauthorized")
Expand Down Expand Up @@ -1383,7 +1387,7 @@ async def test_eth_call_revert_custom_error_without_msg(
async def test_contract_panic_errors(
self,
async_w3: "AsyncWeb3",
async_panic_errors_contract: "Contract",
async_panic_errors_contract: "AsyncContract",
panic_error: str,
params: List[Any],
) -> None:
Expand All @@ -1400,7 +1404,7 @@ async def test_contract_panic_errors(
async def test_eth_call_offchain_lookup(
self,
async_w3: "AsyncWeb3",
async_offchain_lookup_contract: "Contract",
async_offchain_lookup_contract: "AsyncContract",
async_unlocked_account: ChecksumAddress,
monkeypatch: "MonkeyPatch",
) -> None:
Expand All @@ -1426,7 +1430,7 @@ async def test_eth_call_offchain_lookup(
async def test_eth_call_offchain_lookup_raises_when_ccip_read_is_disabled(
self,
async_w3: "AsyncWeb3",
async_offchain_lookup_contract: "Contract",
async_offchain_lookup_contract: "AsyncContract",
) -> None:
return_data = (
OFFCHAIN_LOOKUP_4BYTE_DATA
Expand Down Expand Up @@ -1464,7 +1468,7 @@ async def test_eth_call_offchain_lookup_raises_when_ccip_read_is_disabled(
async def test_eth_call_offchain_lookup_call_flag_overrides_provider_flag(
self,
async_w3: "AsyncWeb3",
async_offchain_lookup_contract: "Contract",
async_offchain_lookup_contract: "AsyncContract",
async_unlocked_account: ChecksumAddress,
monkeypatch: "MonkeyPatch",
) -> None:
Expand Down Expand Up @@ -1492,7 +1496,7 @@ async def test_eth_call_offchain_lookup_call_flag_overrides_provider_flag(
async def test_eth_call_offchain_lookup_raises_if_max_redirects_is_less_than_4(
self,
async_w3: "AsyncWeb3",
async_offchain_lookup_contract: "Contract",
async_offchain_lookup_contract: "AsyncContract",
max_redirects: int,
) -> None:
default_max_redirects = async_w3.provider.ccip_read_max_redirects
Expand All @@ -1509,7 +1513,7 @@ async def test_eth_call_offchain_lookup_raises_if_max_redirects_is_less_than_4(
async def test_eth_call_offchain_lookup_raises_for_improperly_formatted_rest_request_response( # noqa: E501
self,
async_w3: "AsyncWeb3",
async_offchain_lookup_contract: "Contract",
async_offchain_lookup_contract: "AsyncContract",
async_unlocked_account: ChecksumAddress,
monkeypatch: "MonkeyPatch",
) -> None:
Expand All @@ -1533,7 +1537,7 @@ async def test_eth_call_offchain_lookup_raises_for_improperly_formatted_rest_req
async def test_eth_call_offchain_lookup_tries_next_url_for_non_4xx_error_status_and_tests_POST( # noqa: E501
self,
async_w3: "AsyncWeb3",
async_offchain_lookup_contract: "Contract",
async_offchain_lookup_contract: "AsyncContract",
async_unlocked_account: ChecksumAddress,
monkeypatch: "MonkeyPatch",
status_code_non_4xx_error: int,
Expand Down Expand Up @@ -1571,7 +1575,7 @@ async def test_eth_call_offchain_lookup_tries_next_url_for_non_4xx_error_status_
async def test_eth_call_offchain_lookup_calls_raise_for_status_for_4xx_status_code(
self,
async_w3: "AsyncWeb3",
async_offchain_lookup_contract: "Contract",
async_offchain_lookup_contract: "AsyncContract",
async_unlocked_account: ChecksumAddress,
monkeypatch: "MonkeyPatch",
) -> None:
Expand All @@ -1594,7 +1598,7 @@ async def test_eth_call_offchain_lookup_calls_raise_for_status_for_4xx_status_co
async def test_eth_call_offchain_lookup_raises_when_all_supplied_urls_fail(
self,
async_w3: "AsyncWeb3",
async_offchain_lookup_contract: "Contract",
async_offchain_lookup_contract: "AsyncContract",
) -> None:
# GET and POST requests should fail since responses are not mocked
with pytest.raises(
Expand All @@ -1608,7 +1612,7 @@ async def test_eth_call_offchain_lookup_raises_when_all_supplied_urls_fail(
async def test_eth_call_continuous_offchain_lookup_raises_with_too_many_requests(
self,
async_w3: "AsyncWeb3",
async_offchain_lookup_contract: "Contract",
async_offchain_lookup_contract: "AsyncContract",
async_unlocked_account: ChecksumAddress,
monkeypatch: "MonkeyPatch",
) -> None:
Expand Down Expand Up @@ -1683,7 +1687,7 @@ async def test_async_eth_get_transaction_receipt_with_log_entry(
self,
async_w3: "AsyncWeb3",
async_block_with_txn_with_log: BlockData,
async_emitter_contract: "Contract",
async_emitter_contract: "AsyncContract",
txn_hash_with_log: HexStr,
) -> None:
receipt = await async_w3.eth.wait_for_transaction_receipt(txn_hash_with_log)
Expand Down Expand Up @@ -1750,7 +1754,7 @@ async def test_async_eth_wait_for_transaction_receipt_with_log_entry(
self,
async_w3: "AsyncWeb3",
async_block_with_txn_with_log: BlockData,
async_emitter_contract: "Contract",
async_emitter_contract: "AsyncContract",
txn_hash_with_log: HexStr,
) -> None:
receipt = await async_w3.eth.wait_for_transaction_receipt(txn_hash_with_log)
Expand Down Expand Up @@ -1948,7 +1952,7 @@ async def test_async_eth_syncing(self, async_w3: "AsyncWeb3") -> None:

@pytest.mark.asyncio
async def test_async_eth_get_storage_at(
self, async_w3: "AsyncWeb3", async_storage_contract: "Contract"
self, async_w3: "AsyncWeb3", async_storage_contract: "AsyncContract"
) -> None:
async_storage_contract_address = async_storage_contract.address

Expand Down Expand Up @@ -1976,7 +1980,7 @@ async def test_async_eth_get_storage_at(
@pytest.mark.asyncio
@pytest.mark.xfail
async def test_async_eth_get_storage_at_ens_name(
self, async_w3: "AsyncWeb3", async_storage_contract: "Contract"
self, async_w3: "AsyncWeb3", async_storage_contract: "AsyncContract"
) -> None:
with ens_addresses(async_w3, {"storage.eth": async_storage_contract.address}):
storage = await async_w3.eth.get_storage_at(ENS("storage.eth"), 1)
Expand Down

0 comments on commit cfb931d

Please sign in to comment.