web3 7.0.0b2__py3-none-any.whl → 7.0.0b4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. ens/_normalization.py +1 -3
  2. ens/async_ens.py +14 -11
  3. ens/contract_data.py +2 -2
  4. ens/ens.py +10 -7
  5. ens/exceptions.py +19 -27
  6. ens/specs/nf.json +1 -1
  7. ens/specs/normalization_spec.json +1 -1
  8. ens/utils.py +24 -15
  9. web3/__init__.py +2 -7
  10. web3/_utils/abi.py +30 -29
  11. web3/_utils/async_transactions.py +7 -4
  12. web3/_utils/blocks.py +6 -2
  13. web3/_utils/caching.py +7 -3
  14. web3/_utils/compat/__init__.py +0 -3
  15. web3/_utils/contract_sources/compile_contracts.py +1 -1
  16. web3/_utils/contracts.py +12 -12
  17. web3/_utils/datatypes.py +5 -1
  18. web3/_utils/decorators.py +6 -1
  19. web3/_utils/empty.py +1 -1
  20. web3/_utils/encoding.py +15 -10
  21. web3/_utils/error_formatters_utils.py +5 -3
  22. web3/_utils/events.py +35 -24
  23. web3/_utils/fee_utils.py +2 -4
  24. web3/_utils/filters.py +17 -12
  25. web3/_utils/formatters.py +2 -2
  26. web3/_utils/math.py +14 -15
  27. web3/_utils/method_formatters.py +31 -5
  28. web3/_utils/module.py +2 -1
  29. web3/_utils/module_testing/eth_module.py +129 -75
  30. web3/_utils/module_testing/go_ethereum_personal_module.py +1 -1
  31. web3/_utils/module_testing/module_testing_utils.py +1 -3
  32. web3/_utils/module_testing/utils.py +14 -7
  33. web3/_utils/normalizers.py +3 -3
  34. web3/_utils/request.py +4 -4
  35. web3/_utils/rpc_abi.py +6 -1
  36. web3/_utils/threads.py +8 -7
  37. web3/_utils/transactions.py +18 -12
  38. web3/_utils/type_conversion.py +5 -1
  39. web3/_utils/validation.py +12 -10
  40. web3/contract/async_contract.py +12 -7
  41. web3/contract/base_contract.py +51 -57
  42. web3/contract/contract.py +12 -6
  43. web3/contract/utils.py +11 -6
  44. web3/datastructures.py +22 -12
  45. web3/eth/async_eth.py +53 -30
  46. web3/eth/base_eth.py +7 -3
  47. web3/eth/eth.py +31 -14
  48. web3/exceptions.py +41 -59
  49. web3/gas_strategies/time_based.py +2 -4
  50. web3/geth.py +1 -3
  51. web3/main.py +6 -2
  52. web3/manager.py +13 -12
  53. web3/method.py +13 -5
  54. web3/middleware/base.py +4 -2
  55. web3/middleware/filter.py +27 -17
  56. web3/middleware/formatting.py +6 -3
  57. web3/middleware/names.py +4 -1
  58. web3/middleware/signing.py +6 -2
  59. web3/middleware/stalecheck.py +2 -1
  60. web3/providers/eth_tester/defaults.py +1 -1
  61. web3/providers/eth_tester/main.py +5 -4
  62. web3/providers/eth_tester/middleware.py +10 -1
  63. web3/providers/ipc.py +7 -3
  64. web3/providers/persistent/async_ipc.py +6 -7
  65. web3/providers/persistent/persistent.py +12 -2
  66. web3/providers/persistent/request_processor.py +10 -12
  67. web3/providers/persistent/websocket.py +3 -3
  68. web3/providers/rpc/async_rpc.py +23 -6
  69. web3/providers/rpc/rpc.py +27 -16
  70. web3/testing.py +4 -4
  71. web3/tools/benchmark/__init__.py +0 -0
  72. web3/tools/benchmark/main.py +189 -0
  73. web3/tools/benchmark/node.py +126 -0
  74. web3/tools/benchmark/reporting.py +39 -0
  75. web3/tools/benchmark/utils.py +69 -0
  76. web3/tracing.py +9 -5
  77. web3/types.py +23 -22
  78. web3/utils/caching.py +2 -4
  79. {web3-7.0.0b2.dist-info → web3-7.0.0b4.dist-info}/METADATA +13 -26
  80. {web3-7.0.0b2.dist-info → web3-7.0.0b4.dist-info}/RECORD +83 -78
  81. {web3-7.0.0b2.dist-info → web3-7.0.0b4.dist-info}/LICENSE +0 -0
  82. {web3-7.0.0b2.dist-info → web3-7.0.0b4.dist-info}/WHEEL +0 -0
  83. {web3-7.0.0b2.dist-info → web3-7.0.0b4.dist-info}/top_level.txt +0 -0
@@ -139,7 +139,10 @@ RPC_ACCESS_LIST = [
139
139
  if TYPE_CHECKING:
140
140
  from _pytest.monkeypatch import MonkeyPatch # noqa: F401
141
141
 
142
- from web3.contract import Contract # noqa: F401
142
+ from web3.contract import ( # noqa: F401
143
+ AsyncContract,
144
+ Contract,
145
+ )
143
146
  from web3.main import ( # noqa: F401
144
147
  AsyncWeb3,
145
148
  Web3,
@@ -147,7 +150,8 @@ if TYPE_CHECKING:
147
150
 
148
151
 
149
152
  def abi_encoded_offchain_lookup_contract_address(
150
- w3: Union["Web3", "AsyncWeb3"], offchain_lookup_contract: "Contract"
153
+ w3: Union["Web3", "AsyncWeb3"],
154
+ offchain_lookup_contract: Union["Contract", "AsyncContract"],
151
155
  ) -> HexAddress:
152
156
  return HexAddress(
153
157
  remove_0x_prefix(
@@ -834,7 +838,7 @@ class AsyncEthModuleTest:
834
838
  async def test_eth_estimate_gas_with_override_param_type_check(
835
839
  self,
836
840
  async_w3: "AsyncWeb3",
837
- async_math_contract: "Contract",
841
+ async_math_contract: "AsyncContract",
838
842
  params: StateOverrideParams,
839
843
  ) -> None:
840
844
  txn_params: TxParams = {"from": await async_w3.eth.coinbase}
@@ -977,6 +981,39 @@ class AsyncEthModuleTest:
977
981
  assert block is not None
978
982
  assert isinstance(block["number"], int)
979
983
 
984
+ @pytest.mark.asyncio
985
+ async def test_eth_getBlockReceipts_hash(
986
+ self, async_w3: "AsyncWeb3", async_empty_block: BlockData
987
+ ) -> None:
988
+ receipts = await async_w3.eth.get_block_receipts(async_empty_block["hash"])
989
+ assert isinstance(receipts, list)
990
+
991
+ @pytest.mark.asyncio
992
+ async def test_eth_getBlockReceipts_not_found(self, async_w3: "AsyncWeb3") -> None:
993
+ with pytest.raises(BlockNotFound):
994
+ await async_w3.eth.get_block_receipts(UNKNOWN_HASH)
995
+
996
+ @pytest.mark.asyncio
997
+ async def test_eth_getBlockReceipts_with_integer(
998
+ self, async_w3: "AsyncWeb3", async_empty_block: BlockData
999
+ ) -> None:
1000
+ receipts = await async_w3.eth.get_block_receipts(async_empty_block["number"])
1001
+ assert isinstance(receipts, list)
1002
+
1003
+ @pytest.mark.asyncio
1004
+ async def test_eth_getBlockReceipts_safe(
1005
+ self, async_w3: "AsyncWeb3", async_empty_block: BlockData
1006
+ ) -> None:
1007
+ receipts = await async_w3.eth.get_block_receipts("safe")
1008
+ assert isinstance(receipts, list)
1009
+
1010
+ @pytest.mark.asyncio
1011
+ async def test_eth_getBlockReceipts_finalized(
1012
+ self, async_w3: "AsyncWeb3", async_empty_block: BlockData
1013
+ ) -> None:
1014
+ receipts = await async_w3.eth.get_block_receipts("finalized")
1015
+ assert isinstance(receipts, list)
1016
+
980
1017
  @pytest.mark.asyncio
981
1018
  async def test_eth_get_block_by_number_full_transactions(
982
1019
  self, async_w3: "AsyncWeb3", async_block_with_txn: BlockData
@@ -1067,9 +1104,7 @@ class AsyncEthModuleTest:
1067
1104
  f"{unknown_identifier}"
1068
1105
  ),
1069
1106
  ):
1070
- await async_w3.eth.get_raw_transaction_by_block(
1071
- unknown_identifier, 0 # type: ignore
1072
- )
1107
+ await async_w3.eth.get_raw_transaction_by_block(unknown_identifier, 0)
1073
1108
 
1074
1109
  @pytest.mark.asyncio
1075
1110
  async def test_eth_get_balance(self, async_w3: "AsyncWeb3") -> None:
@@ -1097,7 +1132,7 @@ class AsyncEthModuleTest:
1097
1132
  async def test_eth_get_code_invalid_address(
1098
1133
  self,
1099
1134
  async_w3: "AsyncWeb3",
1100
- async_math_contract: "Contract",
1135
+ async_math_contract: "AsyncContract",
1101
1136
  ) -> None:
1102
1137
  with pytest.raises(InvalidAddress):
1103
1138
  await async_w3.eth.get_code(
@@ -1106,7 +1141,7 @@ class AsyncEthModuleTest:
1106
1141
 
1107
1142
  @pytest.mark.asyncio
1108
1143
  async def test_eth_get_code_with_block_identifier(
1109
- self, async_w3: "AsyncWeb3", async_emitter_contract: "Contract"
1144
+ self, async_w3: "AsyncWeb3", async_emitter_contract: "AsyncContract"
1110
1145
  ) -> None:
1111
1146
  block_id = await async_w3.eth.block_number
1112
1147
  code = await async_w3.eth.get_code(async_emitter_contract.address, block_id)
@@ -1118,28 +1153,15 @@ class AsyncEthModuleTest:
1118
1153
  self,
1119
1154
  async_w3: "AsyncWeb3",
1120
1155
  async_unlocked_account_dual_type: ChecksumAddress,
1121
- async_math_contract: "Contract",
1156
+ async_math_contract: "AsyncContract",
1122
1157
  ) -> None:
1123
- # Initialize transaction for gas estimation
1124
- txn_params: TxParams = {
1125
- "from": async_unlocked_account_dual_type,
1126
- "value": Wei(1),
1127
- "gas": 21000,
1128
- }
1129
- txn = async_math_contract._prepare_transaction(
1130
- fn_name="incrementCounter",
1131
- fn_args=[1],
1132
- transaction=txn_params,
1158
+ # build txn
1159
+ txn = await async_math_contract.functions.incrementCounter(1).build_transaction(
1160
+ {"from": async_unlocked_account_dual_type}
1133
1161
  )
1134
1162
 
1135
- # create access list using data from transaction
1136
- response = await async_w3.eth.create_access_list(
1137
- {
1138
- "from": async_unlocked_account_dual_type,
1139
- "to": async_math_contract.address,
1140
- "data": txn["data"],
1141
- }
1142
- )
1163
+ # create access list
1164
+ response = await async_w3.eth.create_access_list(txn)
1143
1165
 
1144
1166
  assert is_dict(response)
1145
1167
  access_list = response["accessList"]
@@ -1149,6 +1171,13 @@ class AsyncEthModuleTest:
1149
1171
  assert len(access_list[0]["storageKeys"][0]) == 32
1150
1172
  assert int(response["gasUsed"]) >= 0
1151
1173
 
1174
+ # assert the result can be used directly in a transaction dict
1175
+ txn["accessList"] = response["accessList"]
1176
+ txn["gas"] = response["gasUsed"]
1177
+
1178
+ # send txn with access list
1179
+ await async_w3.eth.send_transaction(txn)
1180
+
1152
1181
  @pytest.mark.asyncio
1153
1182
  async def test_eth_get_transaction_count(
1154
1183
  self, async_w3: "AsyncWeb3", async_unlocked_account_dual_type: ChecksumAddress
@@ -1161,7 +1190,7 @@ class AsyncEthModuleTest:
1161
1190
 
1162
1191
  @pytest.mark.asyncio
1163
1192
  async def test_eth_call(
1164
- self, async_w3: "AsyncWeb3", async_math_contract: "Contract"
1193
+ self, async_w3: "AsyncWeb3", async_math_contract: "AsyncContract"
1165
1194
  ) -> None:
1166
1195
  coinbase = await async_w3.eth.coinbase
1167
1196
  txn_params = async_math_contract._prepare_transaction(
@@ -1178,7 +1207,7 @@ class AsyncEthModuleTest:
1178
1207
  async def test_eth_call_with_override_code(
1179
1208
  self,
1180
1209
  async_w3: "AsyncWeb3",
1181
- async_revert_contract: "Contract",
1210
+ async_revert_contract: "AsyncContract",
1182
1211
  ) -> None:
1183
1212
  coinbase = await async_w3.eth.coinbase
1184
1213
  txn_params = async_revert_contract._prepare_transaction(
@@ -1234,7 +1263,7 @@ class AsyncEthModuleTest:
1234
1263
  async def test_eth_call_with_override_param_type_check(
1235
1264
  self,
1236
1265
  async_w3: "AsyncWeb3",
1237
- async_math_contract: "Contract",
1266
+ async_math_contract: "AsyncContract",
1238
1267
  params: StateOverrideParams,
1239
1268
  ) -> None:
1240
1269
  coinbase = await async_w3.eth.coinbase
@@ -1247,7 +1276,7 @@ class AsyncEthModuleTest:
1247
1276
 
1248
1277
  @pytest.mark.asyncio
1249
1278
  async def test_eth_call_with_0_result(
1250
- self, async_w3: "AsyncWeb3", async_math_contract: "Contract"
1279
+ self, async_w3: "AsyncWeb3", async_math_contract: "AsyncContract"
1251
1280
  ) -> None:
1252
1281
  coinbase = await async_w3.eth.coinbase
1253
1282
  txn_params = async_math_contract._prepare_transaction(
@@ -1264,7 +1293,7 @@ class AsyncEthModuleTest:
1264
1293
  async def test_eth_call_revert_with_msg(
1265
1294
  self,
1266
1295
  async_w3: "AsyncWeb3",
1267
- async_revert_contract: "Contract",
1296
+ async_revert_contract: "AsyncContract",
1268
1297
  async_unlocked_account: ChecksumAddress,
1269
1298
  ) -> None:
1270
1299
  txn_params = async_revert_contract._prepare_transaction(
@@ -1283,7 +1312,7 @@ class AsyncEthModuleTest:
1283
1312
  async def test_eth_call_revert_without_msg(
1284
1313
  self,
1285
1314
  async_w3: "AsyncWeb3",
1286
- async_revert_contract: "Contract",
1315
+ async_revert_contract: "AsyncContract",
1287
1316
  async_unlocked_account: ChecksumAddress,
1288
1317
  ) -> None:
1289
1318
  with pytest.raises(ContractLogicError, match="execution reverted"):
@@ -1300,10 +1329,10 @@ class AsyncEthModuleTest:
1300
1329
  async def test_eth_call_revert_custom_error_with_msg(
1301
1330
  self,
1302
1331
  async_w3: "AsyncWeb3",
1303
- async_revert_contract: "Contract",
1332
+ async_revert_contract: "AsyncContract",
1304
1333
  async_unlocked_account: ChecksumAddress,
1305
1334
  ) -> None:
1306
- data = async_revert_contract.encodeABI(
1335
+ data = async_revert_contract.encode_abi(
1307
1336
  fn_name="UnauthorizedWithMessage", args=["You are not authorized"]
1308
1337
  )
1309
1338
  txn_params = async_revert_contract._prepare_transaction(
@@ -1320,10 +1349,10 @@ class AsyncEthModuleTest:
1320
1349
  async def test_eth_call_revert_custom_error_without_msg(
1321
1350
  self,
1322
1351
  async_w3: "AsyncWeb3",
1323
- async_revert_contract: "Contract",
1352
+ async_revert_contract: "AsyncContract",
1324
1353
  async_unlocked_account: ChecksumAddress,
1325
1354
  ) -> None:
1326
- data = async_revert_contract.encodeABI(fn_name="Unauthorized")
1355
+ data = async_revert_contract.encode_abi(fn_name="Unauthorized")
1327
1356
  txn_params = async_revert_contract._prepare_transaction(
1328
1357
  fn_name="customErrorWithoutMessage",
1329
1358
  transaction={
@@ -1352,7 +1381,7 @@ class AsyncEthModuleTest:
1352
1381
  async def test_contract_panic_errors(
1353
1382
  self,
1354
1383
  async_w3: "AsyncWeb3",
1355
- async_panic_errors_contract: "Contract",
1384
+ async_panic_errors_contract: "AsyncContract",
1356
1385
  panic_error: str,
1357
1386
  params: List[Any],
1358
1387
  ) -> None:
@@ -1369,7 +1398,7 @@ class AsyncEthModuleTest:
1369
1398
  async def test_eth_call_offchain_lookup(
1370
1399
  self,
1371
1400
  async_w3: "AsyncWeb3",
1372
- async_offchain_lookup_contract: "Contract",
1401
+ async_offchain_lookup_contract: "AsyncContract",
1373
1402
  async_unlocked_account: ChecksumAddress,
1374
1403
  monkeypatch: "MonkeyPatch",
1375
1404
  ) -> None:
@@ -1395,7 +1424,7 @@ class AsyncEthModuleTest:
1395
1424
  async def test_eth_call_offchain_lookup_raises_when_ccip_read_is_disabled(
1396
1425
  self,
1397
1426
  async_w3: "AsyncWeb3",
1398
- async_offchain_lookup_contract: "Contract",
1427
+ async_offchain_lookup_contract: "AsyncContract",
1399
1428
  ) -> None:
1400
1429
  return_data = (
1401
1430
  OFFCHAIN_LOOKUP_4BYTE_DATA
@@ -1433,7 +1462,7 @@ class AsyncEthModuleTest:
1433
1462
  async def test_eth_call_offchain_lookup_call_flag_overrides_provider_flag(
1434
1463
  self,
1435
1464
  async_w3: "AsyncWeb3",
1436
- async_offchain_lookup_contract: "Contract",
1465
+ async_offchain_lookup_contract: "AsyncContract",
1437
1466
  async_unlocked_account: ChecksumAddress,
1438
1467
  monkeypatch: "MonkeyPatch",
1439
1468
  ) -> None:
@@ -1461,7 +1490,7 @@ class AsyncEthModuleTest:
1461
1490
  async def test_eth_call_offchain_lookup_raises_if_max_redirects_is_less_than_4(
1462
1491
  self,
1463
1492
  async_w3: "AsyncWeb3",
1464
- async_offchain_lookup_contract: "Contract",
1493
+ async_offchain_lookup_contract: "AsyncContract",
1465
1494
  max_redirects: int,
1466
1495
  ) -> None:
1467
1496
  default_max_redirects = async_w3.provider.ccip_read_max_redirects
@@ -1478,7 +1507,7 @@ class AsyncEthModuleTest:
1478
1507
  async def test_eth_call_offchain_lookup_raises_for_improperly_formatted_rest_request_response( # noqa: E501
1479
1508
  self,
1480
1509
  async_w3: "AsyncWeb3",
1481
- async_offchain_lookup_contract: "Contract",
1510
+ async_offchain_lookup_contract: "AsyncContract",
1482
1511
  async_unlocked_account: ChecksumAddress,
1483
1512
  monkeypatch: "MonkeyPatch",
1484
1513
  ) -> None:
@@ -1502,7 +1531,7 @@ class AsyncEthModuleTest:
1502
1531
  async def test_eth_call_offchain_lookup_tries_next_url_for_non_4xx_error_status_and_tests_POST( # noqa: E501
1503
1532
  self,
1504
1533
  async_w3: "AsyncWeb3",
1505
- async_offchain_lookup_contract: "Contract",
1534
+ async_offchain_lookup_contract: "AsyncContract",
1506
1535
  async_unlocked_account: ChecksumAddress,
1507
1536
  monkeypatch: "MonkeyPatch",
1508
1537
  status_code_non_4xx_error: int,
@@ -1540,7 +1569,7 @@ class AsyncEthModuleTest:
1540
1569
  async def test_eth_call_offchain_lookup_calls_raise_for_status_for_4xx_status_code(
1541
1570
  self,
1542
1571
  async_w3: "AsyncWeb3",
1543
- async_offchain_lookup_contract: "Contract",
1572
+ async_offchain_lookup_contract: "AsyncContract",
1544
1573
  async_unlocked_account: ChecksumAddress,
1545
1574
  monkeypatch: "MonkeyPatch",
1546
1575
  ) -> None:
@@ -1563,7 +1592,7 @@ class AsyncEthModuleTest:
1563
1592
  async def test_eth_call_offchain_lookup_raises_when_all_supplied_urls_fail(
1564
1593
  self,
1565
1594
  async_w3: "AsyncWeb3",
1566
- async_offchain_lookup_contract: "Contract",
1595
+ async_offchain_lookup_contract: "AsyncContract",
1567
1596
  ) -> None:
1568
1597
  # GET and POST requests should fail since responses are not mocked
1569
1598
  with pytest.raises(
@@ -1577,7 +1606,7 @@ class AsyncEthModuleTest:
1577
1606
  async def test_eth_call_continuous_offchain_lookup_raises_with_too_many_requests(
1578
1607
  self,
1579
1608
  async_w3: "AsyncWeb3",
1580
- async_offchain_lookup_contract: "Contract",
1609
+ async_offchain_lookup_contract: "AsyncContract",
1581
1610
  async_unlocked_account: ChecksumAddress,
1582
1611
  monkeypatch: "MonkeyPatch",
1583
1612
  ) -> None:
@@ -1652,7 +1681,7 @@ class AsyncEthModuleTest:
1652
1681
  self,
1653
1682
  async_w3: "AsyncWeb3",
1654
1683
  async_block_with_txn_with_log: BlockData,
1655
- async_emitter_contract: "Contract",
1684
+ async_emitter_contract: "AsyncContract",
1656
1685
  txn_hash_with_log: HexStr,
1657
1686
  ) -> None:
1658
1687
  receipt = await async_w3.eth.wait_for_transaction_receipt(txn_hash_with_log)
@@ -1719,7 +1748,7 @@ class AsyncEthModuleTest:
1719
1748
  self,
1720
1749
  async_w3: "AsyncWeb3",
1721
1750
  async_block_with_txn_with_log: BlockData,
1722
- async_emitter_contract: "Contract",
1751
+ async_emitter_contract: "AsyncContract",
1723
1752
  txn_hash_with_log: HexStr,
1724
1753
  ) -> None:
1725
1754
  receipt = await async_w3.eth.wait_for_transaction_receipt(txn_hash_with_log)
@@ -1744,7 +1773,7 @@ class AsyncEthModuleTest:
1744
1773
  accounts = await async_w3.eth.accounts
1745
1774
  assert is_list_like(accounts)
1746
1775
  assert len(accounts) != 0
1747
- assert all((is_checksum_address(account) for account in accounts))
1776
+ assert all(is_checksum_address(account) for account in accounts)
1748
1777
  assert await async_w3.eth.coinbase in accounts
1749
1778
 
1750
1779
  @pytest.mark.asyncio
@@ -1917,7 +1946,7 @@ class AsyncEthModuleTest:
1917
1946
 
1918
1947
  @pytest.mark.asyncio
1919
1948
  async def test_async_eth_get_storage_at(
1920
- self, async_w3: "AsyncWeb3", async_storage_contract: "Contract"
1949
+ self, async_w3: "AsyncWeb3", async_storage_contract: "AsyncContract"
1921
1950
  ) -> None:
1922
1951
  async_storage_contract_address = async_storage_contract.address
1923
1952
 
@@ -1945,7 +1974,7 @@ class AsyncEthModuleTest:
1945
1974
  @pytest.mark.asyncio
1946
1975
  @pytest.mark.xfail
1947
1976
  async def test_async_eth_get_storage_at_ens_name(
1948
- self, async_w3: "AsyncWeb3", async_storage_contract: "Contract"
1977
+ self, async_w3: "AsyncWeb3", async_storage_contract: "AsyncContract"
1949
1978
  ) -> None:
1950
1979
  with ens_addresses(async_w3, {"storage.eth": async_storage_contract.address}):
1951
1980
  storage = await async_w3.eth.get_storage_at(ENS("storage.eth"), 1)
@@ -2503,7 +2532,7 @@ class EthModuleTest:
2503
2532
  accounts = w3.eth.accounts
2504
2533
  assert is_list_like(accounts)
2505
2534
  assert len(accounts) != 0
2506
- assert all((is_checksum_address(account) for account in accounts))
2535
+ assert all(is_checksum_address(account) for account in accounts)
2507
2536
  assert w3.eth.coinbase in accounts
2508
2537
 
2509
2538
  def test_eth_block_number(self, w3: "Web3") -> None:
@@ -2702,24 +2731,14 @@ class EthModuleTest:
2702
2731
  unlocked_account_dual_type: ChecksumAddress,
2703
2732
  math_contract: "Contract",
2704
2733
  ) -> None:
2705
- # Initialize transaction for gas estimation
2706
- txn_params: TxParams = {
2707
- "from": unlocked_account_dual_type,
2708
- "value": Wei(1),
2709
- "gas": 21000,
2710
- }
2711
-
2712
- txn = math_contract.functions.incrementCounter(1).build_transaction(txn_params)
2713
-
2714
- # create access list using data from transaction
2715
- response = w3.eth.create_access_list(
2716
- {
2717
- "from": unlocked_account_dual_type,
2718
- "to": math_contract.address,
2719
- "data": txn["data"],
2720
- }
2734
+ # build txn
2735
+ txn = math_contract.functions.incrementCounter(1).build_transaction(
2736
+ {"from": unlocked_account_dual_type}
2721
2737
  )
2722
2738
 
2739
+ # create access list
2740
+ response = w3.eth.create_access_list(txn)
2741
+
2723
2742
  assert is_dict(response)
2724
2743
  access_list = response["accessList"]
2725
2744
  assert len(access_list) > 0
@@ -2728,6 +2747,13 @@ class EthModuleTest:
2728
2747
  assert len(access_list[0]["storageKeys"][0]) == 32
2729
2748
  assert int(response["gasUsed"]) >= 0
2730
2749
 
2750
+ # assert the result can be used directly in a transaction dict
2751
+ txn["accessList"] = response["accessList"]
2752
+ txn["gas"] = response["gasUsed"]
2753
+
2754
+ # send txn with access list
2755
+ w3.eth.send_transaction(txn)
2756
+
2731
2757
  def test_eth_sign(
2732
2758
  self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress
2733
2759
  ) -> None:
@@ -3755,7 +3781,7 @@ class EthModuleTest:
3755
3781
  revert_contract: "Contract",
3756
3782
  unlocked_account: ChecksumAddress,
3757
3783
  ) -> None:
3758
- data = revert_contract.encodeABI(
3784
+ data = revert_contract.encode_abi(
3759
3785
  fn_name="UnauthorizedWithMessage", args=["You are not authorized"]
3760
3786
  )
3761
3787
  txn_params = revert_contract._prepare_transaction(
@@ -3775,7 +3801,7 @@ class EthModuleTest:
3775
3801
  revert_contract: "Contract",
3776
3802
  unlocked_account: ChecksumAddress,
3777
3803
  ) -> None:
3778
- data = revert_contract.encodeABI(fn_name="Unauthorized")
3804
+ data = revert_contract.encode_abi(fn_name="Unauthorized")
3779
3805
  txn_params = revert_contract._prepare_transaction(
3780
3806
  fn_name="customErrorWithoutMessage",
3781
3807
  transaction={
@@ -4064,7 +4090,7 @@ class EthModuleTest:
4064
4090
  revert_contract: "Contract",
4065
4091
  unlocked_account: ChecksumAddress,
4066
4092
  ) -> None:
4067
- data = revert_contract.encodeABI(
4093
+ data = revert_contract.encode_abi(
4068
4094
  fn_name="UnauthorizedWithMessage", args=["You are not authorized"]
4069
4095
  )
4070
4096
  txn_params = revert_contract._prepare_transaction(
@@ -4084,7 +4110,7 @@ class EthModuleTest:
4084
4110
  revert_contract: "Contract",
4085
4111
  unlocked_account: ChecksumAddress,
4086
4112
  ) -> None:
4087
- data = revert_contract.encodeABI(fn_name="Unauthorized")
4113
+ data = revert_contract.encode_abi(fn_name="Unauthorized")
4088
4114
  txn_params = revert_contract._prepare_transaction(
4089
4115
  fn_name="customErrorWithoutMessage",
4090
4116
  transaction={
@@ -4222,7 +4248,35 @@ class EthModuleTest:
4222
4248
  ) -> None:
4223
4249
  block = w3.eth.get_block(block_with_txn["number"], True)
4224
4250
  transaction = block["transactions"][0]
4225
- assert transaction["hash"] == block_with_txn["transactions"][0] # type: ignore
4251
+ assert transaction["hash"] == block_with_txn["transactions"][0]
4252
+
4253
+ def test_eth_getBlockReceipts_hash(
4254
+ self, w3: "Web3", empty_block: BlockData
4255
+ ) -> None:
4256
+ receipts = w3.eth.get_block_receipts(empty_block["hash"])
4257
+ assert isinstance(receipts, list)
4258
+
4259
+ def test_eth_getBlockReceipts_not_found(self, w3: "Web3") -> None:
4260
+ with pytest.raises(BlockNotFound):
4261
+ w3.eth.get_block_receipts(UNKNOWN_HASH)
4262
+
4263
+ def test_eth_getBlockReceipts_with_integer(
4264
+ self, w3: "Web3", empty_block: BlockData
4265
+ ) -> None:
4266
+ receipts = w3.eth.get_block_receipts(empty_block["number"])
4267
+ assert isinstance(receipts, list)
4268
+
4269
+ def test_eth_getBlockReceipts_safe(
4270
+ self, w3: "Web3", empty_block: BlockData
4271
+ ) -> None:
4272
+ receipts = w3.eth.get_block_receipts("safe")
4273
+ assert isinstance(receipts, list)
4274
+
4275
+ def test_eth_getBlockReceipts_finalized(
4276
+ self, w3: "Web3", empty_block: BlockData
4277
+ ) -> None:
4278
+ receipts = w3.eth.get_block_receipts("finalized")
4279
+ assert isinstance(receipts, list)
4226
4280
 
4227
4281
  def test_eth_getTransactionByHash(self, w3: "Web3", mined_txn_hash: HexStr) -> None:
4228
4282
  transaction = w3.eth.get_transaction(mined_txn_hash)
@@ -4653,7 +4707,7 @@ class EthModuleTest:
4653
4707
  f"{unknown_identifier}"
4654
4708
  ),
4655
4709
  ):
4656
- w3.eth.get_raw_transaction_by_block(unknown_identifier, 0) # type: ignore
4710
+ w3.eth.get_raw_transaction_by_block(unknown_identifier, 0)
4657
4711
 
4658
4712
  def test_default_account(
4659
4713
  self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress
@@ -62,7 +62,7 @@ class GoEthereumPersonalModuleTest:
62
62
  accounts = w3.geth.personal.list_accounts()
63
63
  assert is_list_like(accounts)
64
64
  assert len(accounts) > 0
65
- assert all((is_checksum_address(item) for item in accounts))
65
+ assert all(is_checksum_address(item) for item in accounts)
66
66
 
67
67
  def test_personal_list_wallets(self, w3: "Web3") -> None:
68
68
  wallets = w3.geth.personal.list_wallets()
@@ -7,6 +7,7 @@ from typing import (
7
7
  Collection,
8
8
  Dict,
9
9
  Generator,
10
+ Literal,
10
11
  Sequence,
11
12
  Union,
12
13
  )
@@ -28,9 +29,6 @@ from hexbytes import (
28
29
  HexBytes,
29
30
  )
30
31
 
31
- from web3._utils.compat import (
32
- Literal,
33
- )
34
32
  from web3._utils.request import (
35
33
  async_cache_and_return_session,
36
34
  cache_and_return_session,
@@ -36,6 +36,7 @@ class RequestMocker:
36
36
  via a ``request_mocker`` fixture defined within the appropriate context.
37
37
 
38
38
  Example:
39
+ -------
39
40
 
40
41
  def test_my_w3(w3, request_mocker):
41
42
  assert w3.eth.block_number == 0
@@ -46,6 +47,7 @@ class RequestMocker:
46
47
  assert w3.eth.block_number == 0
47
48
 
48
49
  Example with async and a mocked response object:
50
+ -----------------------------------------------
49
51
 
50
52
  async def test_my_w3(async_w3, request_mocker):
51
53
  def _iter_responses():
@@ -77,6 +79,7 @@ class RequestMocker:
77
79
 
78
80
  If a method name is not present in any of the dicts above, the request is made as
79
81
  usual.
82
+
80
83
  """
81
84
 
82
85
  def __init__(
@@ -90,12 +93,13 @@ class RequestMocker:
90
93
  self.mock_results = mock_results or {}
91
94
  self.mock_errors = mock_errors or {}
92
95
  self.mock_responses = mock_responses or {}
93
- self._make_request: Union["AsyncMakeRequestFn", "MakeRequestFn"] = (
94
- w3.provider.make_request
95
- )
96
+ self._make_request: Union[
97
+ "AsyncMakeRequestFn", "MakeRequestFn"
98
+ ] = w3.provider.make_request
96
99
 
97
100
  def __enter__(self) -> "Self":
98
- setattr(self.w3.provider, "make_request", self._mock_request_handler)
101
+ # mypy error: Cannot assign to a method
102
+ self.w3.provider.make_request = self._mock_request_handler # type: ignore[method-assign] # noqa: E501
99
103
  # reset request func cache to re-build request_func with mocked make_request
100
104
  self.w3.provider._request_func_cache = (None, None)
101
105
 
@@ -103,7 +107,8 @@ class RequestMocker:
103
107
 
104
108
  # define __exit__ with typing information
105
109
  def __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None:
106
- setattr(self.w3.provider, "make_request", self._make_request)
110
+ # mypy error: Cannot assign to a method
111
+ self.w3.provider.make_request = self._make_request # type: ignore[method-assign] # noqa: E501
107
112
  # reset request func cache to re-build request_func with original make_request
108
113
  self.w3.provider._request_func_cache = (None, None)
109
114
 
@@ -163,13 +168,15 @@ class RequestMocker:
163
168
 
164
169
  # -- async -- #
165
170
  async def __aenter__(self) -> "Self":
166
- setattr(self.w3.provider, "make_request", self._async_mock_request_handler)
171
+ # mypy error: Cannot assign to a method
172
+ self.w3.provider.make_request = self._async_mock_request_handler # type: ignore[method-assign] # noqa: E501
167
173
  # reset request func cache to re-build request_func with mocked make_request
168
174
  self.w3.provider._request_func_cache = (None, None)
169
175
  return self
170
176
 
171
177
  async def __aexit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None:
172
- setattr(self.w3.provider, "make_request", self._make_request)
178
+ # mypy error: Cannot assign to a method
179
+ self.w3.provider.make_request = self._make_request # type: ignore[method-assign] # noqa: E501
173
180
  # reset request func cache to re-build request_func with original make_request
174
181
  self.w3.provider._request_func_cache = (None, None)
175
182
 
@@ -60,6 +60,7 @@ from web3._utils.validation import (
60
60
  from web3.exceptions import (
61
61
  InvalidAddress,
62
62
  NameNotFound,
63
+ Web3ValueError,
63
64
  )
64
65
  from web3.types import (
65
66
  ABI,
@@ -151,7 +152,7 @@ def abi_bytes_to_hex(
151
152
 
152
153
  num_bytes = abi_type.sub
153
154
  if len(bytes_data) > num_bytes:
154
- raise ValueError(
155
+ raise Web3ValueError(
155
156
  f"This value was expected to be at most {num_bytes} bytes, "
156
157
  f"but instead was {len(bytes_data)}: {data!r}"
157
158
  )
@@ -273,8 +274,7 @@ def normalize_address_no_ens(address: ChecksumAddress) -> ChecksumAddress:
273
274
  def normalize_bytecode(bytecode: bytes) -> HexBytes:
274
275
  if bytecode:
275
276
  bytecode = HexBytes(bytecode)
276
- # type ignored b/c bytecode is converted to HexBytes above
277
- return bytecode # type: ignore
277
+ return bytecode
278
278
 
279
279
 
280
280
  # --- async -- #
web3/_utils/request.py CHANGED
@@ -109,9 +109,9 @@ def get_response_from_post_request(
109
109
 
110
110
 
111
111
  def make_post_request(
112
- endpoint_uri: URI, data: Union[bytes, Dict[str, Any]], *args: Any, **kwargs: Any
112
+ endpoint_uri: URI, data: Union[bytes, Dict[str, Any]], **kwargs: Any
113
113
  ) -> bytes:
114
- response = get_response_from_post_request(endpoint_uri, data=data, *args, **kwargs)
114
+ response = get_response_from_post_request(endpoint_uri, data=data, **kwargs)
115
115
  response.raise_for_status()
116
116
  return response.content
117
117
 
@@ -236,10 +236,10 @@ async def async_get_response_from_post_request(
236
236
 
237
237
 
238
238
  async def async_make_post_request(
239
- endpoint_uri: URI, data: Union[bytes, Dict[str, Any]], *args: Any, **kwargs: Any
239
+ endpoint_uri: URI, data: Union[bytes, Dict[str, Any]], **kwargs: Any
240
240
  ) -> bytes:
241
241
  response = await async_get_response_from_post_request(
242
- endpoint_uri, data=data, *args, **kwargs
242
+ endpoint_uri, data=data, **kwargs
243
243
  )
244
244
  response.raise_for_status()
245
245
  return await response.read()
web3/_utils/rpc_abi.py CHANGED
@@ -24,6 +24,9 @@ from eth_utils.toolz import (
24
24
  from web3._utils.abi import (
25
25
  map_abi_data,
26
26
  )
27
+ from web3.exceptions import (
28
+ Web3TypeError,
29
+ )
27
30
  from web3.types import (
28
31
  RPCEndpoint,
29
32
  )
@@ -57,6 +60,7 @@ class RPC:
57
60
  eth_getBalance = RPCEndpoint("eth_getBalance")
58
61
  eth_getBlockByHash = RPCEndpoint("eth_getBlockByHash")
59
62
  eth_getBlockByNumber = RPCEndpoint("eth_getBlockByNumber")
63
+ eth_getBlockReceipts = RPCEndpoint("eth_getBlockReceipts")
60
64
  eth_getBlockTransactionCountByHash = RPCEndpoint(
61
65
  "eth_getBlockTransactionCountByHash"
62
66
  )
@@ -157,6 +161,7 @@ TRANSACTION_PARAMS_ABIS = {
157
161
  "from": "address",
158
162
  "gas": "uint",
159
163
  "gasPrice": "uint",
164
+ "maxFeePerBlobGas": "uint",
160
165
  "maxFeePerGas": "uint",
161
166
  "maxPriorityFeePerGas": "uint",
162
167
  "nonce": "uint",
@@ -245,6 +250,6 @@ def abi_request_formatters(
245
250
  single_dict_formatter = apply_abi_formatters_to_dict(normalizers, abi_types)
246
251
  yield method, apply_formatter_at_index(single_dict_formatter, 0)
247
252
  else:
248
- raise TypeError(
253
+ raise Web3TypeError(
249
254
  f"ABI definitions must be a list or dictionary, got {abi_types!r}"
250
255
  )