web3 7.0.0b5__py3-none-any.whl → 7.0.0b7__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.
- ens/__init__.py +13 -2
- web3/__init__.py +21 -5
- web3/_utils/batching.py +217 -0
- web3/_utils/caching.py +26 -2
- web3/_utils/compat/__init__.py +1 -0
- web3/_utils/contract_sources/contract_data/arrays_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/bytes_contracts.py +5 -5
- web3/_utils/contract_sources/contract_data/constructor_contracts.py +7 -7
- web3/_utils/contract_sources/contract_data/contract_caller_tester.py +3 -3
- web3/_utils/contract_sources/contract_data/emitter_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/event_contracts.py +5 -5
- web3/_utils/contract_sources/contract_data/extended_resolver.py +3 -3
- web3/_utils/contract_sources/contract_data/fallback_function_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/function_name_tester_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/math_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/offchain_lookup.py +3 -3
- web3/_utils/contract_sources/contract_data/offchain_resolver.py +3 -3
- web3/_utils/contract_sources/contract_data/panic_errors_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/payable_tester.py +3 -3
- web3/_utils/contract_sources/contract_data/receive_function_contracts.py +5 -5
- web3/_utils/contract_sources/contract_data/reflector_contracts.py +3 -3
- web3/_utils/contract_sources/contract_data/revert_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/simple_resolver.py +3 -3
- web3/_utils/contract_sources/contract_data/storage_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/string_contract.py +3 -3
- web3/_utils/contract_sources/contract_data/tuple_contracts.py +5 -5
- web3/_utils/events.py +2 -2
- web3/_utils/http.py +3 -0
- web3/_utils/http_session_manager.py +280 -0
- web3/_utils/method_formatters.py +0 -2
- web3/_utils/module_testing/eth_module.py +92 -119
- web3/_utils/module_testing/module_testing_utils.py +27 -9
- web3/_utils/module_testing/persistent_connection_provider.py +1 -0
- web3/_utils/module_testing/web3_module.py +438 -17
- web3/_utils/rpc_abi.py +0 -3
- web3/beacon/__init__.py +5 -0
- web3/beacon/async_beacon.py +9 -5
- web3/beacon/beacon.py +7 -5
- web3/contract/__init__.py +7 -0
- web3/contract/base_contract.py +10 -1
- web3/contract/utils.py +112 -4
- web3/eth/__init__.py +7 -0
- web3/eth/async_eth.py +5 -37
- web3/eth/eth.py +7 -57
- web3/exceptions.py +20 -0
- web3/gas_strategies/time_based.py +2 -2
- web3/main.py +21 -9
- web3/manager.py +113 -8
- web3/method.py +29 -9
- web3/middleware/__init__.py +17 -0
- web3/middleware/base.py +43 -0
- web3/module.py +47 -7
- web3/providers/__init__.py +21 -0
- web3/providers/async_base.py +55 -23
- web3/providers/base.py +59 -26
- web3/providers/eth_tester/__init__.py +5 -0
- web3/providers/eth_tester/defaults.py +0 -6
- web3/providers/eth_tester/middleware.py +3 -8
- web3/providers/ipc.py +23 -8
- web3/providers/legacy_websocket.py +26 -1
- web3/providers/persistent/__init__.py +7 -0
- web3/providers/persistent/async_ipc.py +60 -76
- web3/providers/persistent/persistent.py +134 -10
- web3/providers/persistent/request_processor.py +98 -14
- web3/providers/persistent/websocket.py +43 -66
- web3/providers/rpc/__init__.py +5 -0
- web3/providers/rpc/async_rpc.py +34 -12
- web3/providers/rpc/rpc.py +34 -12
- web3/providers/rpc/utils.py +0 -3
- web3/tools/benchmark/main.py +7 -6
- web3/tools/benchmark/node.py +1 -1
- web3/types.py +7 -1
- web3/utils/__init__.py +14 -5
- web3/utils/async_exception_handling.py +19 -7
- web3/utils/exception_handling.py +7 -5
- {web3-7.0.0b5.dist-info → web3-7.0.0b7.dist-info}/LICENSE +1 -1
- {web3-7.0.0b5.dist-info → web3-7.0.0b7.dist-info}/METADATA +33 -20
- {web3-7.0.0b5.dist-info → web3-7.0.0b7.dist-info}/RECORD +80 -80
- {web3-7.0.0b5.dist-info → web3-7.0.0b7.dist-info}/WHEEL +1 -1
- web3/_utils/contract_sources/contract_data/address_reflector.py +0 -29
- web3/_utils/request.py +0 -265
- {web3-7.0.0b5.dist-info → web3-7.0.0b7.dist-info}/top_level.txt +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import asyncio
|
|
1
2
|
import json
|
|
2
3
|
import math
|
|
3
4
|
import pytest
|
|
@@ -5,7 +6,6 @@ from random import (
|
|
|
5
6
|
randint,
|
|
6
7
|
)
|
|
7
8
|
import re
|
|
8
|
-
import time
|
|
9
9
|
from typing import (
|
|
10
10
|
TYPE_CHECKING,
|
|
11
11
|
Any,
|
|
@@ -42,9 +42,6 @@ from hexbytes import (
|
|
|
42
42
|
HexBytes,
|
|
43
43
|
)
|
|
44
44
|
|
|
45
|
-
from web3._utils.empty import (
|
|
46
|
-
empty,
|
|
47
|
-
)
|
|
48
45
|
from web3._utils.ens import (
|
|
49
46
|
ens_addresses,
|
|
50
47
|
)
|
|
@@ -220,7 +217,7 @@ class AsyncEthModuleTest:
|
|
|
220
217
|
txn_hash = await async_w3.eth.send_transaction(txn_params)
|
|
221
218
|
|
|
222
219
|
modified_txn_hash = await async_w3.eth.modify_transaction(
|
|
223
|
-
txn_hash, gasPrice=(cast(
|
|
220
|
+
txn_hash, gasPrice=(cast(Wei, txn_params["gasPrice"] * 2)), value=Wei(2)
|
|
224
221
|
)
|
|
225
222
|
modified_txn = await async_w3.eth.get_transaction(modified_txn_hash)
|
|
226
223
|
|
|
@@ -252,9 +249,9 @@ class AsyncEthModuleTest:
|
|
|
252
249
|
|
|
253
250
|
modified_txn_hash = await async_w3.eth.modify_transaction(
|
|
254
251
|
txn_hash,
|
|
255
|
-
value=2,
|
|
256
|
-
maxPriorityFeePerGas=(cast(Wei, txn_params["maxPriorityFeePerGas"]
|
|
257
|
-
maxFeePerGas=(cast(Wei, txn_params["maxFeePerGas"]
|
|
252
|
+
value=Wei(2),
|
|
253
|
+
maxPriorityFeePerGas=(cast(Wei, txn_params["maxPriorityFeePerGas"] * 2)),
|
|
254
|
+
maxFeePerGas=(cast(Wei, txn_params["maxFeePerGas"] * 2)),
|
|
258
255
|
)
|
|
259
256
|
modified_txn = await async_w3.eth.get_transaction(modified_txn_hash)
|
|
260
257
|
|
|
@@ -721,7 +718,7 @@ class AsyncEthModuleTest:
|
|
|
721
718
|
"gasPrice": 10**9,
|
|
722
719
|
}
|
|
723
720
|
signed = keyfile_account.sign_transaction(txn)
|
|
724
|
-
txn_hash = await async_w3.eth.send_raw_transaction(signed.
|
|
721
|
+
txn_hash = await async_w3.eth.send_raw_transaction(signed.raw_transaction)
|
|
725
722
|
assert txn_hash == HexBytes(signed.hash)
|
|
726
723
|
|
|
727
724
|
@pytest.mark.asyncio
|
|
@@ -882,7 +879,8 @@ class AsyncEthModuleTest:
|
|
|
882
879
|
async_math_contract: "AsyncContract",
|
|
883
880
|
params: StateOverrideParams,
|
|
884
881
|
) -> None:
|
|
885
|
-
|
|
882
|
+
accounts = await async_w3.eth.accounts
|
|
883
|
+
txn_params: TxParams = {"from": accounts[0]}
|
|
886
884
|
|
|
887
885
|
# assert does not raise
|
|
888
886
|
await async_w3.eth.estimate_gas(
|
|
@@ -978,9 +976,8 @@ class AsyncEthModuleTest:
|
|
|
978
976
|
async def test_eth_getBlockByNumber_latest(
|
|
979
977
|
self, async_w3: "AsyncWeb3", async_empty_block: BlockData
|
|
980
978
|
) -> None:
|
|
981
|
-
current_block_number = await async_w3.eth.block_number
|
|
982
979
|
block = await async_w3.eth.get_block("latest")
|
|
983
|
-
assert block["
|
|
980
|
+
assert block["hash"] is not None
|
|
984
981
|
|
|
985
982
|
@pytest.mark.asyncio
|
|
986
983
|
async def test_eth_getBlockByNumber_not_found(
|
|
@@ -993,9 +990,8 @@ class AsyncEthModuleTest:
|
|
|
993
990
|
async def test_eth_getBlockByNumber_pending(
|
|
994
991
|
self, async_w3: "AsyncWeb3", async_empty_block: BlockData
|
|
995
992
|
) -> None:
|
|
996
|
-
current_block_number = await async_w3.eth.block_number
|
|
997
993
|
block = await async_w3.eth.get_block("pending")
|
|
998
|
-
assert block["
|
|
994
|
+
assert block["hash"] is None
|
|
999
995
|
|
|
1000
996
|
@pytest.mark.asyncio
|
|
1001
997
|
async def test_eth_getBlockByNumber_earliest(
|
|
@@ -1087,7 +1083,6 @@ class AsyncEthModuleTest:
|
|
|
1087
1083
|
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
1088
1084
|
) -> None:
|
|
1089
1085
|
# eth_getRawTransactionByBlockNumberAndIndex: block identifier
|
|
1090
|
-
# send a txn to make sure pending block has at least one txn
|
|
1091
1086
|
await async_w3.eth.send_transaction(
|
|
1092
1087
|
{
|
|
1093
1088
|
"from": async_keyfile_account_address_dual_type,
|
|
@@ -1095,11 +1090,16 @@ class AsyncEthModuleTest:
|
|
|
1095
1090
|
"value": Wei(1),
|
|
1096
1091
|
}
|
|
1097
1092
|
)
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1093
|
+
|
|
1094
|
+
async def wait_for_block_with_txn() -> HexBytes:
|
|
1095
|
+
while True:
|
|
1096
|
+
try:
|
|
1097
|
+
return await async_w3.eth.get_raw_transaction_by_block("latest", 0)
|
|
1098
|
+
except TransactionNotFound:
|
|
1099
|
+
await asyncio.sleep(0.1)
|
|
1100
|
+
continue
|
|
1101
|
+
|
|
1102
|
+
raw_txn = await asyncio.wait_for(wait_for_block_with_txn(), timeout=5)
|
|
1103
1103
|
assert is_bytes(raw_txn)
|
|
1104
1104
|
|
|
1105
1105
|
# eth_getRawTransactionByBlockNumberAndIndex: block number
|
|
@@ -1149,14 +1149,15 @@ class AsyncEthModuleTest:
|
|
|
1149
1149
|
|
|
1150
1150
|
@pytest.mark.asyncio
|
|
1151
1151
|
async def test_eth_get_balance(self, async_w3: "AsyncWeb3") -> None:
|
|
1152
|
-
|
|
1152
|
+
accounts = await async_w3.eth.accounts
|
|
1153
|
+
account = accounts[0]
|
|
1153
1154
|
|
|
1154
1155
|
with pytest.raises(InvalidAddress):
|
|
1155
1156
|
await async_w3.eth.get_balance(
|
|
1156
|
-
ChecksumAddress(HexAddress(HexStr(
|
|
1157
|
+
ChecksumAddress(HexAddress(HexStr(account.lower())))
|
|
1157
1158
|
)
|
|
1158
1159
|
|
|
1159
|
-
balance = await async_w3.eth.get_balance(
|
|
1160
|
+
balance = await async_w3.eth.get_balance(account)
|
|
1160
1161
|
|
|
1161
1162
|
assert is_integer(balance)
|
|
1162
1163
|
assert balance >= 0
|
|
@@ -1235,11 +1236,13 @@ class AsyncEthModuleTest:
|
|
|
1235
1236
|
async def test_eth_call(
|
|
1236
1237
|
self, async_w3: "AsyncWeb3", async_math_contract: "AsyncContract"
|
|
1237
1238
|
) -> None:
|
|
1238
|
-
|
|
1239
|
+
accounts = await async_w3.eth.accounts
|
|
1240
|
+
account = accounts[0]
|
|
1241
|
+
|
|
1239
1242
|
txn_params = async_math_contract._prepare_transaction(
|
|
1240
1243
|
fn_name="add",
|
|
1241
1244
|
fn_args=(7, 11),
|
|
1242
|
-
transaction={"from":
|
|
1245
|
+
transaction={"from": account, "to": async_math_contract.address},
|
|
1243
1246
|
)
|
|
1244
1247
|
call_result = await async_w3.eth.call(txn_params)
|
|
1245
1248
|
assert is_string(call_result)
|
|
@@ -1252,10 +1255,11 @@ class AsyncEthModuleTest:
|
|
|
1252
1255
|
async_w3: "AsyncWeb3",
|
|
1253
1256
|
async_revert_contract: "AsyncContract",
|
|
1254
1257
|
) -> None:
|
|
1255
|
-
|
|
1258
|
+
accounts = await async_w3.eth.accounts
|
|
1259
|
+
account = accounts[0]
|
|
1256
1260
|
txn_params = async_revert_contract._prepare_transaction(
|
|
1257
1261
|
fn_name="normalFunction",
|
|
1258
|
-
transaction={"from":
|
|
1262
|
+
transaction={"from": account, "to": async_revert_contract.address},
|
|
1259
1263
|
)
|
|
1260
1264
|
call_result = await async_w3.eth.call(txn_params)
|
|
1261
1265
|
(result,) = async_w3.codec.decode(["bool"], call_result)
|
|
@@ -1309,8 +1313,8 @@ class AsyncEthModuleTest:
|
|
|
1309
1313
|
async_math_contract: "AsyncContract",
|
|
1310
1314
|
params: StateOverrideParams,
|
|
1311
1315
|
) -> None:
|
|
1312
|
-
|
|
1313
|
-
txn_params: TxParams = {"from":
|
|
1316
|
+
accounts = await async_w3.eth.accounts
|
|
1317
|
+
txn_params: TxParams = {"from": accounts[0]}
|
|
1314
1318
|
|
|
1315
1319
|
# assert does not raise
|
|
1316
1320
|
await async_w3.eth.call(
|
|
@@ -1321,11 +1325,11 @@ class AsyncEthModuleTest:
|
|
|
1321
1325
|
async def test_eth_call_with_0_result(
|
|
1322
1326
|
self, async_w3: "AsyncWeb3", async_math_contract: "AsyncContract"
|
|
1323
1327
|
) -> None:
|
|
1324
|
-
|
|
1328
|
+
accounts = await async_w3.eth.accounts
|
|
1325
1329
|
txn_params = async_math_contract._prepare_transaction(
|
|
1326
1330
|
fn_name="add",
|
|
1327
1331
|
fn_args=(0, 0),
|
|
1328
|
-
transaction={"from":
|
|
1332
|
+
transaction={"from": accounts[0], "to": async_math_contract.address},
|
|
1329
1333
|
)
|
|
1330
1334
|
call_result = await async_w3.eth.call(txn_params)
|
|
1331
1335
|
assert is_string(call_result)
|
|
@@ -1661,23 +1665,12 @@ class AsyncEthModuleTest:
|
|
|
1661
1665
|
with pytest.raises(TooManyRequests, match="Too many CCIP read redirects"):
|
|
1662
1666
|
await async_offchain_lookup_contract.caller().continuousOffchainLookup() # noqa: E501 type: ignore
|
|
1663
1667
|
|
|
1664
|
-
@pytest.mark.asyncio
|
|
1665
|
-
async def test_async_eth_hashrate(self, async_w3: "AsyncWeb3") -> None:
|
|
1666
|
-
hashrate = await async_w3.eth.hashrate
|
|
1667
|
-
assert is_integer(hashrate)
|
|
1668
|
-
assert hashrate >= 0
|
|
1669
|
-
|
|
1670
1668
|
@pytest.mark.asyncio
|
|
1671
1669
|
async def test_async_eth_chain_id(self, async_w3: "AsyncWeb3") -> None:
|
|
1672
1670
|
chain_id = await async_w3.eth.chain_id
|
|
1673
1671
|
# chain id value from geth fixture genesis file
|
|
1674
1672
|
assert chain_id == 131277322940537
|
|
1675
1673
|
|
|
1676
|
-
@pytest.mark.asyncio
|
|
1677
|
-
async def test_async_eth_mining(self, async_w3: "AsyncWeb3") -> None:
|
|
1678
|
-
mining = await async_w3.eth.mining
|
|
1679
|
-
assert is_boolean(mining)
|
|
1680
|
-
|
|
1681
1674
|
@pytest.mark.asyncio
|
|
1682
1675
|
async def test_async_eth_get_transaction_receipt_mined(
|
|
1683
1676
|
self,
|
|
@@ -1818,7 +1811,6 @@ class AsyncEthModuleTest:
|
|
|
1818
1811
|
assert is_list_like(accounts)
|
|
1819
1812
|
assert len(accounts) != 0
|
|
1820
1813
|
assert all(is_checksum_address(account) for account in accounts)
|
|
1821
|
-
assert await async_w3.eth.coinbase in accounts
|
|
1822
1814
|
|
|
1823
1815
|
@pytest.mark.asyncio
|
|
1824
1816
|
async def test_async_eth_get_logs_without_logs(
|
|
@@ -2028,10 +2020,10 @@ class AsyncEthModuleTest:
|
|
|
2028
2020
|
async def test_async_eth_get_storage_at_invalid_address(
|
|
2029
2021
|
self, async_w3: "AsyncWeb3"
|
|
2030
2022
|
) -> None:
|
|
2031
|
-
|
|
2023
|
+
accounts = await async_w3.eth.accounts
|
|
2032
2024
|
with pytest.raises(InvalidAddress):
|
|
2033
2025
|
await async_w3.eth.get_storage_at(
|
|
2034
|
-
ChecksumAddress(HexAddress(HexStr(
|
|
2026
|
+
ChecksumAddress(HexAddress(HexStr(accounts[0].lower()))), 0
|
|
2035
2027
|
)
|
|
2036
2028
|
|
|
2037
2029
|
def test_async_provider_default_account(
|
|
@@ -2039,9 +2031,7 @@ class AsyncEthModuleTest:
|
|
|
2039
2031
|
async_w3: "AsyncWeb3",
|
|
2040
2032
|
async_keyfile_account_address_dual_type: ChecksumAddress,
|
|
2041
2033
|
) -> None:
|
|
2042
|
-
|
|
2043
|
-
default_account = async_w3.eth.default_account
|
|
2044
|
-
assert default_account is empty
|
|
2034
|
+
current_default_account = async_w3.eth.default_account
|
|
2045
2035
|
|
|
2046
2036
|
# check setter
|
|
2047
2037
|
async_w3.eth.default_account = async_keyfile_account_address_dual_type
|
|
@@ -2049,7 +2039,7 @@ class AsyncEthModuleTest:
|
|
|
2049
2039
|
assert default_account == async_keyfile_account_address_dual_type
|
|
2050
2040
|
|
|
2051
2041
|
# reset to default
|
|
2052
|
-
async_w3.eth.default_account =
|
|
2042
|
+
async_w3.eth.default_account = current_default_account
|
|
2053
2043
|
|
|
2054
2044
|
def test_async_provider_default_block(
|
|
2055
2045
|
self,
|
|
@@ -2517,19 +2507,6 @@ class EthModuleTest:
|
|
|
2517
2507
|
assert is_integer(sync_dict["currentBlock"])
|
|
2518
2508
|
assert is_integer(sync_dict["highestBlock"])
|
|
2519
2509
|
|
|
2520
|
-
def test_eth_coinbase(self, w3: "Web3") -> None:
|
|
2521
|
-
coinbase = w3.eth.coinbase
|
|
2522
|
-
assert is_checksum_address(coinbase)
|
|
2523
|
-
|
|
2524
|
-
def test_eth_mining(self, w3: "Web3") -> None:
|
|
2525
|
-
mining = w3.eth.mining
|
|
2526
|
-
assert is_boolean(mining)
|
|
2527
|
-
|
|
2528
|
-
def test_eth_hashrate(self, w3: "Web3") -> None:
|
|
2529
|
-
hashrate = w3.eth.hashrate
|
|
2530
|
-
assert is_integer(hashrate)
|
|
2531
|
-
assert hashrate >= 0
|
|
2532
|
-
|
|
2533
2510
|
def test_eth_chain_id(self, w3: "Web3") -> None:
|
|
2534
2511
|
chain_id = w3.eth.chain_id
|
|
2535
2512
|
# chain id value from geth fixture genesis file
|
|
@@ -2597,7 +2574,6 @@ class EthModuleTest:
|
|
|
2597
2574
|
assert is_list_like(accounts)
|
|
2598
2575
|
assert len(accounts) != 0
|
|
2599
2576
|
assert all(is_checksum_address(account) for account in accounts)
|
|
2600
|
-
assert w3.eth.coinbase in accounts
|
|
2601
2577
|
|
|
2602
2578
|
def test_eth_block_number(self, w3: "Web3") -> None:
|
|
2603
2579
|
block_number = w3.eth.block_number
|
|
@@ -2610,12 +2586,12 @@ class EthModuleTest:
|
|
|
2610
2586
|
assert block_number >= 0
|
|
2611
2587
|
|
|
2612
2588
|
def test_eth_get_balance(self, w3: "Web3") -> None:
|
|
2613
|
-
|
|
2589
|
+
account = w3.eth.accounts[0]
|
|
2614
2590
|
|
|
2615
2591
|
with pytest.raises(InvalidAddress):
|
|
2616
|
-
w3.eth.get_balance(ChecksumAddress(HexAddress(HexStr(
|
|
2592
|
+
w3.eth.get_balance(ChecksumAddress(HexAddress(HexStr(account.lower()))))
|
|
2617
2593
|
|
|
2618
|
-
balance = w3.eth.get_balance(
|
|
2594
|
+
balance = w3.eth.get_balance(account)
|
|
2619
2595
|
|
|
2620
2596
|
assert is_integer(balance)
|
|
2621
2597
|
assert balance >= 0
|
|
@@ -2677,10 +2653,10 @@ class EthModuleTest:
|
|
|
2677
2653
|
assert storage == HexBytes(f"0x{'00' * 31}01")
|
|
2678
2654
|
|
|
2679
2655
|
def test_eth_get_storage_at_invalid_address(self, w3: "Web3") -> None:
|
|
2680
|
-
|
|
2656
|
+
account = w3.eth.accounts[0]
|
|
2681
2657
|
with pytest.raises(InvalidAddress):
|
|
2682
2658
|
w3.eth.get_storage_at(
|
|
2683
|
-
ChecksumAddress(HexAddress(HexStr(
|
|
2659
|
+
ChecksumAddress(HexAddress(HexStr(account.lower()))), 0
|
|
2684
2660
|
)
|
|
2685
2661
|
|
|
2686
2662
|
def test_eth_get_transaction_count(
|
|
@@ -2705,10 +2681,10 @@ class EthModuleTest:
|
|
|
2705
2681
|
assert transaction_count >= 0
|
|
2706
2682
|
|
|
2707
2683
|
def test_eth_get_transaction_count_invalid_address(self, w3: "Web3") -> None:
|
|
2708
|
-
|
|
2684
|
+
account = w3.eth.accounts[0]
|
|
2709
2685
|
with pytest.raises(InvalidAddress):
|
|
2710
2686
|
w3.eth.get_transaction_count(
|
|
2711
|
-
ChecksumAddress(HexAddress(HexStr(
|
|
2687
|
+
ChecksumAddress(HexAddress(HexStr(account.lower())))
|
|
2712
2688
|
)
|
|
2713
2689
|
|
|
2714
2690
|
def test_eth_getBlockTransactionCountByHash_empty_block(
|
|
@@ -3657,7 +3633,7 @@ class EthModuleTest:
|
|
|
3657
3633
|
txn_hash = w3.eth.send_transaction(txn_params)
|
|
3658
3634
|
|
|
3659
3635
|
modified_txn_hash = w3.eth.modify_transaction(
|
|
3660
|
-
txn_hash, gasPrice=(cast(
|
|
3636
|
+
txn_hash, gasPrice=(cast(Wei, txn_params["gasPrice"] * 2)), value=Wei(2)
|
|
3661
3637
|
)
|
|
3662
3638
|
modified_txn = w3.eth.get_transaction(modified_txn_hash)
|
|
3663
3639
|
|
|
@@ -3686,9 +3662,9 @@ class EthModuleTest:
|
|
|
3686
3662
|
|
|
3687
3663
|
modified_txn_hash = w3.eth.modify_transaction(
|
|
3688
3664
|
txn_hash,
|
|
3689
|
-
value=2,
|
|
3690
|
-
maxPriorityFeePerGas=(cast(Wei, txn_params["maxPriorityFeePerGas"]
|
|
3691
|
-
maxFeePerGas=(cast(Wei, txn_params["maxFeePerGas"]
|
|
3665
|
+
value=Wei(2),
|
|
3666
|
+
maxPriorityFeePerGas=(cast(Wei, txn_params["maxPriorityFeePerGas"] * 2)),
|
|
3667
|
+
maxFeePerGas=(cast(Wei, txn_params["maxFeePerGas"] * 2)),
|
|
3692
3668
|
)
|
|
3693
3669
|
modified_txn = w3.eth.get_transaction(modified_txn_hash)
|
|
3694
3670
|
|
|
@@ -3720,15 +3696,14 @@ class EthModuleTest:
|
|
|
3720
3696
|
"gasPrice": 10**9,
|
|
3721
3697
|
}
|
|
3722
3698
|
signed = keyfile_account.sign_transaction(txn)
|
|
3723
|
-
txn_hash = w3.eth.send_raw_transaction(signed.
|
|
3699
|
+
txn_hash = w3.eth.send_raw_transaction(signed.raw_transaction)
|
|
3724
3700
|
assert txn_hash == HexBytes(signed.hash)
|
|
3725
3701
|
|
|
3726
3702
|
def test_eth_call(self, w3: "Web3", math_contract: "Contract") -> None:
|
|
3727
|
-
coinbase = w3.eth.coinbase
|
|
3728
3703
|
txn_params = math_contract._prepare_transaction(
|
|
3729
3704
|
fn_name="add",
|
|
3730
3705
|
fn_args=(7, 11),
|
|
3731
|
-
transaction={"from":
|
|
3706
|
+
transaction={"from": w3.eth.accounts[0], "to": math_contract.address},
|
|
3732
3707
|
)
|
|
3733
3708
|
call_result = w3.eth.call(txn_params)
|
|
3734
3709
|
assert is_string(call_result)
|
|
@@ -3738,10 +3713,9 @@ class EthModuleTest:
|
|
|
3738
3713
|
def test_eth_call_with_override_code(
|
|
3739
3714
|
self, w3: "Web3", revert_contract: "Contract"
|
|
3740
3715
|
) -> None:
|
|
3741
|
-
coinbase = w3.eth.coinbase
|
|
3742
3716
|
txn_params = revert_contract._prepare_transaction(
|
|
3743
3717
|
fn_name="normalFunction",
|
|
3744
|
-
transaction={"from":
|
|
3718
|
+
transaction={"from": w3.eth.accounts[0], "to": revert_contract.address},
|
|
3745
3719
|
)
|
|
3746
3720
|
call_result = w3.eth.call(txn_params)
|
|
3747
3721
|
(result,) = w3.codec.decode(["bool"], call_result)
|
|
@@ -3792,7 +3766,7 @@ class EthModuleTest:
|
|
|
3792
3766
|
math_contract: "Contract",
|
|
3793
3767
|
params: StateOverrideParams,
|
|
3794
3768
|
) -> None:
|
|
3795
|
-
txn_params: TxParams = {"from": w3.eth.
|
|
3769
|
+
txn_params: TxParams = {"from": w3.eth.accounts[0]}
|
|
3796
3770
|
|
|
3797
3771
|
# assert does not raise
|
|
3798
3772
|
w3.eth.call(txn_params, "latest", {math_contract.address: params})
|
|
@@ -3800,11 +3774,10 @@ class EthModuleTest:
|
|
|
3800
3774
|
def test_eth_call_with_0_result(
|
|
3801
3775
|
self, w3: "Web3", math_contract: "Contract"
|
|
3802
3776
|
) -> None:
|
|
3803
|
-
coinbase = w3.eth.coinbase
|
|
3804
3777
|
txn_params = math_contract._prepare_transaction(
|
|
3805
3778
|
fn_name="add",
|
|
3806
3779
|
fn_args=(0, 0),
|
|
3807
|
-
transaction={"from":
|
|
3780
|
+
transaction={"from": w3.eth.accounts[0], "to": math_contract.address},
|
|
3808
3781
|
)
|
|
3809
3782
|
call_result = w3.eth.call(txn_params)
|
|
3810
3783
|
assert is_string(call_result)
|
|
@@ -4243,7 +4216,7 @@ class EthModuleTest:
|
|
|
4243
4216
|
math_contract: "Contract",
|
|
4244
4217
|
params: StateOverrideParams,
|
|
4245
4218
|
) -> None:
|
|
4246
|
-
txn_params: TxParams = {"from": w3.eth.
|
|
4219
|
+
txn_params: TxParams = {"from": w3.eth.accounts[0]}
|
|
4247
4220
|
|
|
4248
4221
|
# assert does not raise
|
|
4249
4222
|
w3.eth.estimate_gas(txn_params, None, {math_contract.address: params})
|
|
@@ -4270,12 +4243,9 @@ class EthModuleTest:
|
|
|
4270
4243
|
block = w3.eth.get_block(empty_block["number"])
|
|
4271
4244
|
assert block["number"] == empty_block["number"]
|
|
4272
4245
|
|
|
4273
|
-
def test_eth_getBlockByNumber_latest(
|
|
4274
|
-
self, w3: "Web3", empty_block: BlockData
|
|
4275
|
-
) -> None:
|
|
4276
|
-
current_block_number = w3.eth.block_number
|
|
4246
|
+
def test_eth_getBlockByNumber_latest(self, w3: "Web3") -> None:
|
|
4277
4247
|
block = w3.eth.get_block("latest")
|
|
4278
|
-
assert block["
|
|
4248
|
+
assert block["hash"] is not None
|
|
4279
4249
|
|
|
4280
4250
|
def test_eth_getBlockByNumber_not_found(
|
|
4281
4251
|
self, w3: "Web3", empty_block: BlockData
|
|
@@ -4665,39 +4635,42 @@ class EthModuleTest:
|
|
|
4665
4635
|
math_contract: "Contract",
|
|
4666
4636
|
keyfile_account_address: ChecksumAddress,
|
|
4667
4637
|
) -> None:
|
|
4668
|
-
|
|
4669
|
-
block_num =
|
|
4670
|
-
block_hash =
|
|
4638
|
+
current_block = w3.eth.get_block("latest")
|
|
4639
|
+
block_num = current_block["number"]
|
|
4640
|
+
block_hash = current_block["hash"]
|
|
4671
4641
|
|
|
4642
|
+
default_call_result = math_contract.functions.counter().call()
|
|
4672
4643
|
latest_call_result = math_contract.functions.counter().call(
|
|
4673
4644
|
block_identifier="latest"
|
|
4674
4645
|
)
|
|
4646
|
+
|
|
4647
|
+
# increment counter and get tx receipt
|
|
4648
|
+
tx_hash = math_contract.functions.incrementCounter().transact(
|
|
4649
|
+
{"from": keyfile_account_address}
|
|
4650
|
+
)
|
|
4651
|
+
tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
|
|
4652
|
+
|
|
4653
|
+
# get new state value
|
|
4654
|
+
post_state_block_num_call_result = math_contract.functions.counter().call(
|
|
4655
|
+
block_identifier=tx_receipt["blockNumber"]
|
|
4656
|
+
)
|
|
4657
|
+
|
|
4658
|
+
# call old state values with different block identifiers
|
|
4675
4659
|
block_hash_call_result = math_contract.functions.counter().call(
|
|
4676
4660
|
block_identifier=block_hash
|
|
4677
4661
|
)
|
|
4678
|
-
|
|
4662
|
+
pre_state_block_num_call_result = math_contract.functions.counter().call(
|
|
4679
4663
|
block_identifier=block_num
|
|
4680
4664
|
)
|
|
4681
|
-
default_call_result = math_contract.functions.counter().call()
|
|
4682
|
-
|
|
4683
|
-
# send and wait 1 second to mine
|
|
4684
|
-
math_contract.functions.incrementCounter().transact(
|
|
4685
|
-
{"from": keyfile_account_address}
|
|
4686
|
-
)
|
|
4687
|
-
time.sleep(1)
|
|
4688
4665
|
|
|
4689
|
-
|
|
4690
|
-
|
|
4666
|
+
# assert old state values before incrementing counter
|
|
4667
|
+
assert pre_state_block_num_call_result == post_state_block_num_call_result - 1
|
|
4668
|
+
assert (
|
|
4669
|
+
pre_state_block_num_call_result
|
|
4670
|
+
== block_hash_call_result
|
|
4671
|
+
== default_call_result
|
|
4672
|
+
== latest_call_result
|
|
4691
4673
|
)
|
|
4692
|
-
assert block_hash_call_result == 0
|
|
4693
|
-
assert block_num_call_result == 0
|
|
4694
|
-
assert latest_call_result == 0
|
|
4695
|
-
assert default_call_result == 0
|
|
4696
|
-
|
|
4697
|
-
if pending_call_result != 1:
|
|
4698
|
-
raise AssertionError(
|
|
4699
|
-
f"pending call result was {pending_call_result} instead of 1"
|
|
4700
|
-
)
|
|
4701
4674
|
|
|
4702
4675
|
def test_eth_uninstall_filter(self, w3: "Web3") -> None:
|
|
4703
4676
|
filter = w3.eth.filter({})
|
|
@@ -4726,7 +4699,6 @@ class EthModuleTest:
|
|
|
4726
4699
|
block_with_txn: BlockData,
|
|
4727
4700
|
) -> None:
|
|
4728
4701
|
# eth_getRawTransactionByBlockNumberAndIndex: block identifier
|
|
4729
|
-
# send a txn to make sure pending block has at least one txn
|
|
4730
4702
|
w3.eth.send_transaction(
|
|
4731
4703
|
{
|
|
4732
4704
|
"from": keyfile_account_address_dual_type,
|
|
@@ -4734,10 +4706,13 @@ class EthModuleTest:
|
|
|
4734
4706
|
"value": Wei(1),
|
|
4735
4707
|
}
|
|
4736
4708
|
)
|
|
4737
|
-
|
|
4738
|
-
|
|
4739
|
-
|
|
4740
|
-
|
|
4709
|
+
raw_transaction = None
|
|
4710
|
+
while not raw_transaction:
|
|
4711
|
+
try:
|
|
4712
|
+
raw_transaction = w3.eth.get_raw_transaction_by_block("latest", 0)
|
|
4713
|
+
except TransactionNotFound:
|
|
4714
|
+
continue
|
|
4715
|
+
|
|
4741
4716
|
assert is_bytes(raw_transaction)
|
|
4742
4717
|
|
|
4743
4718
|
# eth_getRawTransactionByBlockNumberAndIndex: block number
|
|
@@ -4781,9 +4756,7 @@ class EthModuleTest:
|
|
|
4781
4756
|
def test_default_account(
|
|
4782
4757
|
self, w3: "Web3", keyfile_account_address_dual_type: ChecksumAddress
|
|
4783
4758
|
) -> None:
|
|
4784
|
-
|
|
4785
|
-
default_account = w3.eth.default_account
|
|
4786
|
-
assert default_account is empty
|
|
4759
|
+
current_default = w3.eth.default_account
|
|
4787
4760
|
|
|
4788
4761
|
# check setter
|
|
4789
4762
|
w3.eth.default_account = keyfile_account_address_dual_type
|
|
@@ -4791,7 +4764,7 @@ class EthModuleTest:
|
|
|
4791
4764
|
assert default_account == keyfile_account_address_dual_type
|
|
4792
4765
|
|
|
4793
4766
|
# reset to default
|
|
4794
|
-
w3.eth.default_account =
|
|
4767
|
+
w3.eth.default_account = current_default
|
|
4795
4768
|
|
|
4796
4769
|
def test_default_block(
|
|
4797
4770
|
self,
|
|
@@ -13,6 +13,7 @@ from typing import (
|
|
|
13
13
|
)
|
|
14
14
|
|
|
15
15
|
from aiohttp import (
|
|
16
|
+
ClientSession,
|
|
16
17
|
ClientTimeout,
|
|
17
18
|
)
|
|
18
19
|
from eth_typing import (
|
|
@@ -28,10 +29,10 @@ from flaky import (
|
|
|
28
29
|
from hexbytes import (
|
|
29
30
|
HexBytes,
|
|
30
31
|
)
|
|
32
|
+
import requests
|
|
31
33
|
|
|
32
|
-
from web3._utils.
|
|
33
|
-
|
|
34
|
-
cache_and_return_session,
|
|
34
|
+
from web3._utils.http import (
|
|
35
|
+
DEFAULT_HTTP_TIMEOUT,
|
|
35
36
|
)
|
|
36
37
|
from web3.types import (
|
|
37
38
|
BlockData,
|
|
@@ -40,7 +41,9 @@ from web3.types import (
|
|
|
40
41
|
|
|
41
42
|
if TYPE_CHECKING:
|
|
42
43
|
from _pytest.monkeypatch import MonkeyPatch # noqa: F401
|
|
43
|
-
from aiohttp import
|
|
44
|
+
from aiohttp import ( # noqa: F401
|
|
45
|
+
ClientResponse,
|
|
46
|
+
)
|
|
44
47
|
from requests import Response # noqa: F401
|
|
45
48
|
|
|
46
49
|
from web3 import Web3 # noqa: F401
|
|
@@ -102,13 +105,13 @@ def mock_offchain_lookup_request_response(
|
|
|
102
105
|
|
|
103
106
|
# mock response only to specified url while validating appropriate fields
|
|
104
107
|
if url_from_args == mocked_request_url:
|
|
105
|
-
assert kwargs["timeout"] ==
|
|
108
|
+
assert kwargs["timeout"] == DEFAULT_HTTP_TIMEOUT
|
|
106
109
|
if http_method.upper() == "POST":
|
|
107
110
|
assert kwargs["data"] == {"data": calldata, "sender": sender}
|
|
108
111
|
return MockedResponse()
|
|
109
112
|
|
|
110
113
|
# else, make a normal request (no mocking)
|
|
111
|
-
session =
|
|
114
|
+
session = requests.Session()
|
|
112
115
|
return session.request(method=http_method.upper(), url=url_from_args, **kwargs)
|
|
113
116
|
|
|
114
117
|
monkeypatch.setattr(
|
|
@@ -152,16 +155,18 @@ def async_mock_offchain_lookup_request_response(
|
|
|
152
155
|
|
|
153
156
|
# mock response only to specified url while validating appropriate fields
|
|
154
157
|
if url_from_args == mocked_request_url:
|
|
155
|
-
assert kwargs["timeout"] == ClientTimeout(
|
|
158
|
+
assert kwargs["timeout"] == ClientTimeout(DEFAULT_HTTP_TIMEOUT)
|
|
156
159
|
if http_method.upper() == "post":
|
|
157
160
|
assert kwargs["data"] == {"data": calldata, "sender": sender}
|
|
158
161
|
return AsyncMockedResponse()
|
|
159
162
|
|
|
160
163
|
# else, make a normal request (no mocking)
|
|
161
|
-
session =
|
|
162
|
-
|
|
164
|
+
session = ClientSession()
|
|
165
|
+
response = await session.request(
|
|
163
166
|
method=http_method.upper(), url=url_from_args, **kwargs
|
|
164
167
|
)
|
|
168
|
+
await session.close()
|
|
169
|
+
return response
|
|
165
170
|
|
|
166
171
|
monkeypatch.setattr(
|
|
167
172
|
f"aiohttp.ClientSession.{http_method.lower()}", _mock_specific_request
|
|
@@ -177,6 +182,12 @@ class WebSocketMessageStreamMock:
|
|
|
177
182
|
self.messages = deque(messages) if messages else deque()
|
|
178
183
|
self.raise_exception = raise_exception
|
|
179
184
|
|
|
185
|
+
def __await__(self) -> Generator[Any, Any, "Self"]:
|
|
186
|
+
async def __async_init__() -> "Self":
|
|
187
|
+
return self
|
|
188
|
+
|
|
189
|
+
return __async_init__().__await__()
|
|
190
|
+
|
|
180
191
|
def __aiter__(self) -> "Self":
|
|
181
192
|
return self
|
|
182
193
|
|
|
@@ -189,6 +200,13 @@ class WebSocketMessageStreamMock:
|
|
|
189
200
|
|
|
190
201
|
return self.messages.popleft()
|
|
191
202
|
|
|
203
|
+
@staticmethod
|
|
204
|
+
async def pong() -> Literal[False]:
|
|
205
|
+
return False
|
|
206
|
+
|
|
207
|
+
async def connect(self) -> None:
|
|
208
|
+
pass
|
|
209
|
+
|
|
192
210
|
async def send(self, data: bytes) -> None:
|
|
193
211
|
pass
|
|
194
212
|
|