web3 7.0.0b2__py3-none-any.whl → 7.7.0__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
- ens/_normalization.py +4 -4
- ens/async_ens.py +27 -15
- ens/base_ens.py +3 -1
- ens/contract_data.py +2 -2
- ens/ens.py +10 -7
- ens/exceptions.py +16 -29
- ens/specs/nf.json +1 -1
- ens/specs/normalization_spec.json +1 -1
- ens/utils.py +24 -32
- web3/__init__.py +23 -12
- web3/_utils/abi.py +157 -263
- web3/_utils/async_transactions.py +34 -20
- web3/_utils/batching.py +217 -0
- web3/_utils/blocks.py +6 -2
- web3/_utils/caching/__init__.py +12 -0
- web3/_utils/caching/caching_utils.py +433 -0
- web3/_utils/caching/request_caching_validation.py +287 -0
- web3/_utils/compat/__init__.py +2 -3
- web3/_utils/contract_sources/compile_contracts.py +1 -1
- web3/_utils/contract_sources/contract_data/ambiguous_function_contract.py +42 -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 +50 -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/contracts.py +172 -220
- web3/_utils/datatypes.py +5 -1
- web3/_utils/decorators.py +6 -1
- web3/_utils/empty.py +1 -1
- web3/_utils/encoding.py +16 -12
- web3/_utils/error_formatters_utils.py +5 -3
- web3/_utils/events.py +78 -72
- web3/_utils/fee_utils.py +1 -3
- web3/_utils/filters.py +24 -22
- web3/_utils/formatters.py +2 -2
- web3/_utils/http.py +8 -2
- web3/_utils/http_session_manager.py +314 -0
- web3/_utils/math.py +14 -15
- web3/_utils/method_formatters.py +161 -34
- web3/_utils/module.py +2 -1
- web3/_utils/module_testing/__init__.py +3 -2
- web3/_utils/module_testing/eth_module.py +736 -583
- web3/_utils/module_testing/go_ethereum_debug_module.py +128 -0
- web3/_utils/module_testing/module_testing_utils.py +81 -24
- web3/_utils/module_testing/persistent_connection_provider.py +702 -220
- web3/_utils/module_testing/utils.py +114 -33
- web3/_utils/module_testing/web3_module.py +438 -17
- web3/_utils/normalizers.py +13 -11
- web3/_utils/rpc_abi.py +10 -22
- web3/_utils/threads.py +8 -7
- web3/_utils/transactions.py +32 -25
- web3/_utils/type_conversion.py +5 -1
- web3/_utils/validation.py +20 -17
- web3/beacon/__init__.py +5 -0
- web3/beacon/api_endpoints.py +3 -0
- web3/beacon/async_beacon.py +29 -6
- web3/beacon/beacon.py +24 -6
- web3/contract/__init__.py +7 -0
- web3/contract/async_contract.py +285 -82
- web3/contract/base_contract.py +556 -258
- web3/contract/contract.py +295 -84
- web3/contract/utils.py +251 -55
- web3/datastructures.py +49 -34
- web3/eth/__init__.py +7 -0
- web3/eth/async_eth.py +89 -69
- web3/eth/base_eth.py +7 -3
- web3/eth/eth.py +43 -66
- web3/exceptions.py +158 -83
- web3/gas_strategies/time_based.py +8 -6
- web3/geth.py +53 -184
- web3/main.py +77 -17
- web3/manager.py +362 -95
- web3/method.py +43 -15
- web3/middleware/__init__.py +17 -0
- web3/middleware/attrdict.py +12 -22
- web3/middleware/base.py +55 -2
- web3/middleware/filter.py +45 -23
- web3/middleware/formatting.py +6 -3
- web3/middleware/names.py +4 -1
- web3/middleware/signing.py +15 -6
- web3/middleware/stalecheck.py +2 -1
- web3/module.py +61 -25
- web3/providers/__init__.py +21 -0
- web3/providers/async_base.py +87 -32
- web3/providers/base.py +77 -32
- web3/providers/eth_tester/__init__.py +5 -0
- web3/providers/eth_tester/defaults.py +2 -55
- web3/providers/eth_tester/main.py +41 -15
- web3/providers/eth_tester/middleware.py +16 -17
- web3/providers/ipc.py +41 -17
- web3/providers/legacy_websocket.py +26 -1
- web3/providers/persistent/__init__.py +7 -0
- web3/providers/persistent/async_ipc.py +61 -121
- web3/providers/persistent/persistent.py +323 -16
- web3/providers/persistent/persistent_connection.py +54 -5
- web3/providers/persistent/request_processor.py +136 -56
- web3/providers/persistent/subscription_container.py +56 -0
- web3/providers/persistent/subscription_manager.py +233 -0
- web3/providers/persistent/websocket.py +29 -92
- web3/providers/rpc/__init__.py +5 -0
- web3/providers/rpc/async_rpc.py +73 -18
- web3/providers/rpc/rpc.py +73 -30
- web3/providers/rpc/utils.py +1 -13
- web3/scripts/install_pre_releases.py +33 -0
- web3/scripts/parse_pygeth_version.py +16 -0
- web3/testing.py +4 -4
- web3/tracing.py +9 -5
- web3/types.py +141 -74
- web3/utils/__init__.py +64 -5
- web3/utils/abi.py +790 -10
- web3/utils/address.py +8 -0
- web3/utils/async_exception_handling.py +20 -11
- web3/utils/caching.py +34 -4
- web3/utils/exception_handling.py +9 -12
- web3/utils/subscriptions.py +285 -0
- {web3-7.0.0b2.dist-info → web3-7.7.0.dist-info}/LICENSE +1 -1
- web3-7.7.0.dist-info/METADATA +130 -0
- web3-7.7.0.dist-info/RECORD +171 -0
- {web3-7.0.0b2.dist-info → web3-7.7.0.dist-info}/WHEEL +1 -1
- web3/_utils/caching.py +0 -155
- web3/_utils/contract_sources/contract_data/address_reflector.py +0 -29
- web3/_utils/module_testing/go_ethereum_personal_module.py +0 -300
- web3/_utils/request.py +0 -265
- web3-7.0.0b2.dist-info/METADATA +0 -106
- web3-7.0.0b2.dist-info/RECORD +0 -163
- /web3/_utils/{function_identifiers.py → abi_element_identifiers.py} +0 -0
- {web3-7.0.0b2.dist-info → web3-7.7.0.dist-info}/top_level.txt +0 -0
|
@@ -10,10 +10,14 @@ from typing import (
|
|
|
10
10
|
cast,
|
|
11
11
|
)
|
|
12
12
|
|
|
13
|
-
from toolz import (
|
|
13
|
+
from eth_utils.toolz import (
|
|
14
14
|
merge,
|
|
15
15
|
)
|
|
16
16
|
|
|
17
|
+
from web3.providers.persistent import (
|
|
18
|
+
PersistentConnectionProvider,
|
|
19
|
+
)
|
|
20
|
+
|
|
17
21
|
if TYPE_CHECKING:
|
|
18
22
|
from web3 import ( # noqa: F401
|
|
19
23
|
AsyncWeb3,
|
|
@@ -26,6 +30,7 @@ if TYPE_CHECKING:
|
|
|
26
30
|
AsyncMakeRequestFn,
|
|
27
31
|
MakeRequestFn,
|
|
28
32
|
RPCEndpoint,
|
|
33
|
+
RPCRequest,
|
|
29
34
|
RPCResponse,
|
|
30
35
|
)
|
|
31
36
|
|
|
@@ -35,7 +40,16 @@ class RequestMocker:
|
|
|
35
40
|
Context manager to mock requests made by a web3 instance. This is meant to be used
|
|
36
41
|
via a ``request_mocker`` fixture defined within the appropriate context.
|
|
37
42
|
|
|
43
|
+
************************************************************************************
|
|
44
|
+
Important: When mocking results, it's important to keep in mind the types that
|
|
45
|
+
clients return. For example, what we commonly translate to integers are returned
|
|
46
|
+
as hex strings in the RPC response and should be mocked as such for more
|
|
47
|
+
accurate testing.
|
|
48
|
+
************************************************************************************
|
|
49
|
+
|
|
50
|
+
|
|
38
51
|
Example:
|
|
52
|
+
-------
|
|
39
53
|
|
|
40
54
|
def test_my_w3(w3, request_mocker):
|
|
41
55
|
assert w3.eth.block_number == 0
|
|
@@ -46,6 +60,7 @@ class RequestMocker:
|
|
|
46
60
|
assert w3.eth.block_number == 0
|
|
47
61
|
|
|
48
62
|
Example with async and a mocked response object:
|
|
63
|
+
-----------------------------------------------
|
|
49
64
|
|
|
50
65
|
async def test_my_w3(async_w3, request_mocker):
|
|
51
66
|
def _iter_responses():
|
|
@@ -77,6 +92,7 @@ class RequestMocker:
|
|
|
77
92
|
|
|
78
93
|
If a method name is not present in any of the dicts above, the request is made as
|
|
79
94
|
usual.
|
|
95
|
+
|
|
80
96
|
"""
|
|
81
97
|
|
|
82
98
|
def __init__(
|
|
@@ -90,20 +106,33 @@ class RequestMocker:
|
|
|
90
106
|
self.mock_results = mock_results or {}
|
|
91
107
|
self.mock_errors = mock_errors or {}
|
|
92
108
|
self.mock_responses = mock_responses or {}
|
|
93
|
-
|
|
94
|
-
w3.provider.
|
|
109
|
+
if isinstance(w3.provider, PersistentConnectionProvider):
|
|
110
|
+
self._send_request = w3.provider.send_request
|
|
111
|
+
self._recv_for_request = w3.provider.recv_for_request
|
|
112
|
+
else:
|
|
113
|
+
self._make_request: Union[
|
|
114
|
+
"AsyncMakeRequestFn", "MakeRequestFn"
|
|
115
|
+
] = w3.provider.make_request
|
|
116
|
+
|
|
117
|
+
def _build_request_id(self) -> int:
|
|
118
|
+
request_id = (
|
|
119
|
+
next(copy.deepcopy(self.w3.provider.request_counter))
|
|
120
|
+
if hasattr(self.w3.provider, "request_counter")
|
|
121
|
+
else 1
|
|
95
122
|
)
|
|
123
|
+
return request_id
|
|
96
124
|
|
|
97
125
|
def __enter__(self) -> "Self":
|
|
98
|
-
|
|
126
|
+
# mypy error: Cannot assign to a method
|
|
127
|
+
self.w3.provider.make_request = self._mock_request_handler # type: ignore[method-assign] # noqa: E501
|
|
99
128
|
# reset request func cache to re-build request_func with mocked make_request
|
|
100
129
|
self.w3.provider._request_func_cache = (None, None)
|
|
101
130
|
|
|
102
131
|
return self
|
|
103
132
|
|
|
104
|
-
# define __exit__ with typing information
|
|
105
133
|
def __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None:
|
|
106
|
-
|
|
134
|
+
# mypy error: Cannot assign to a method
|
|
135
|
+
self.w3.provider.make_request = self._make_request # type: ignore[assignment]
|
|
107
136
|
# reset request func cache to re-build request_func with original make_request
|
|
108
137
|
self.w3.provider._request_func_cache = (None, None)
|
|
109
138
|
|
|
@@ -119,11 +148,7 @@ class RequestMocker:
|
|
|
119
148
|
):
|
|
120
149
|
return self._make_request(method, params)
|
|
121
150
|
|
|
122
|
-
request_id = (
|
|
123
|
-
next(copy.deepcopy(self.w3.provider.request_counter))
|
|
124
|
-
if hasattr(self.w3.provider, "request_counter")
|
|
125
|
-
else 1
|
|
126
|
-
)
|
|
151
|
+
request_id = self._build_request_id()
|
|
127
152
|
response_dict = {"jsonrpc": "2.0", "id": request_id}
|
|
128
153
|
|
|
129
154
|
if method in self.mock_responses:
|
|
@@ -162,34 +187,36 @@ class RequestMocker:
|
|
|
162
187
|
return mocked_response
|
|
163
188
|
|
|
164
189
|
# -- async -- #
|
|
190
|
+
|
|
165
191
|
async def __aenter__(self) -> "Self":
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
192
|
+
if not isinstance(self.w3.provider, PersistentConnectionProvider):
|
|
193
|
+
# mypy error: Cannot assign to a method
|
|
194
|
+
self.w3.provider.make_request = self._async_mock_request_handler # type: ignore[method-assign] # noqa: E501
|
|
195
|
+
# reset request func cache to re-build request_func w/ mocked make_request
|
|
196
|
+
self.w3.provider._request_func_cache = (None, None)
|
|
197
|
+
else:
|
|
198
|
+
self.w3.provider.send_request = self._async_mock_send_handler # type: ignore[method-assign] # noqa: E501
|
|
199
|
+
self.w3.provider.recv_for_request = self._async_mock_recv_handler # type: ignore[method-assign] # noqa: E501
|
|
200
|
+
self.w3.provider._send_func_cache = (None, None)
|
|
201
|
+
self.w3.provider._recv_func_cache = (None, None)
|
|
169
202
|
return self
|
|
170
203
|
|
|
171
204
|
async def __aexit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None:
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
205
|
+
if not isinstance(self.w3.provider, PersistentConnectionProvider):
|
|
206
|
+
# mypy error: Cannot assign to a method
|
|
207
|
+
self.w3.provider.make_request = self._make_request # type: ignore[assignment] # noqa: E501
|
|
208
|
+
# reset request func cache to re-build request_func w/ original make_request
|
|
209
|
+
self.w3.provider._request_func_cache = (None, None)
|
|
210
|
+
else:
|
|
211
|
+
self.w3.provider.send_request = self._send_request # type: ignore[method-assign] # noqa: E501
|
|
212
|
+
self.w3.provider.recv_for_request = self._recv_for_request # type: ignore[method-assign] # noqa: E501
|
|
213
|
+
self.w3.provider._send_func_cache = (None, None)
|
|
214
|
+
self.w3.provider._recv_func_cache = (None, None)
|
|
175
215
|
|
|
176
|
-
async def
|
|
177
|
-
self, method: "RPCEndpoint", params: Any
|
|
216
|
+
async def _async_build_mock_result(
|
|
217
|
+
self, method: "RPCEndpoint", params: Any, request_id: int = None
|
|
178
218
|
) -> "RPCResponse":
|
|
179
|
-
|
|
180
|
-
self._make_request = cast("AsyncMakeRequestFn", self._make_request)
|
|
181
|
-
|
|
182
|
-
if all(
|
|
183
|
-
method not in mock_dict
|
|
184
|
-
for mock_dict in (self.mock_errors, self.mock_results, self.mock_responses)
|
|
185
|
-
):
|
|
186
|
-
return await self._make_request(method, params)
|
|
187
|
-
|
|
188
|
-
request_id = (
|
|
189
|
-
next(copy.deepcopy(self.w3.provider.request_counter))
|
|
190
|
-
if hasattr(self.w3.provider, "request_counter")
|
|
191
|
-
else 1
|
|
192
|
-
)
|
|
219
|
+
request_id = request_id if request_id else self._build_request_id()
|
|
193
220
|
response_dict = {"jsonrpc": "2.0", "id": request_id}
|
|
194
221
|
|
|
195
222
|
if method in self.mock_responses:
|
|
@@ -229,6 +256,19 @@ class RequestMocker:
|
|
|
229
256
|
else:
|
|
230
257
|
raise Exception("Invariant: unreachable code path")
|
|
231
258
|
|
|
259
|
+
return mocked_result
|
|
260
|
+
|
|
261
|
+
async def _async_mock_request_handler(
|
|
262
|
+
self, method: "RPCEndpoint", params: Any
|
|
263
|
+
) -> "RPCResponse":
|
|
264
|
+
self.w3 = cast("AsyncWeb3", self.w3)
|
|
265
|
+
self._make_request = cast("AsyncMakeRequestFn", self._make_request)
|
|
266
|
+
if all(
|
|
267
|
+
method not in mock_dict
|
|
268
|
+
for mock_dict in (self.mock_errors, self.mock_results, self.mock_responses)
|
|
269
|
+
):
|
|
270
|
+
return await self._make_request(method, params)
|
|
271
|
+
mocked_result = await self._async_build_mock_result(method, params)
|
|
232
272
|
decorator = getattr(self._make_request, "_decorator", None)
|
|
233
273
|
if decorator is not None:
|
|
234
274
|
# If the original make_request was decorated, we need to re-apply
|
|
@@ -244,6 +284,47 @@ class RequestMocker:
|
|
|
244
284
|
else:
|
|
245
285
|
return mocked_result
|
|
246
286
|
|
|
287
|
+
async def _async_mock_send_handler(
|
|
288
|
+
self, method: "RPCEndpoint", params: Any
|
|
289
|
+
) -> "RPCRequest":
|
|
290
|
+
if all(
|
|
291
|
+
method not in mock_dict
|
|
292
|
+
for mock_dict in (self.mock_errors, self.mock_results, self.mock_responses)
|
|
293
|
+
):
|
|
294
|
+
return await self._send_request(method, params)
|
|
295
|
+
else:
|
|
296
|
+
request_id = self._build_request_id()
|
|
297
|
+
return {"id": request_id, "method": method, "params": params}
|
|
298
|
+
|
|
299
|
+
async def _async_mock_recv_handler(
|
|
300
|
+
self, rpc_request: "RPCRequest"
|
|
301
|
+
) -> "RPCResponse":
|
|
302
|
+
self.w3 = cast("AsyncWeb3", self.w3)
|
|
303
|
+
method = rpc_request["method"]
|
|
304
|
+
request_id = rpc_request["id"]
|
|
305
|
+
if all(
|
|
306
|
+
method not in mock_dict
|
|
307
|
+
for mock_dict in (self.mock_errors, self.mock_results, self.mock_responses)
|
|
308
|
+
):
|
|
309
|
+
return await self._recv_for_request(request_id)
|
|
310
|
+
mocked_result = await self._async_build_mock_result(
|
|
311
|
+
method, rpc_request["params"], request_id=int(request_id)
|
|
312
|
+
)
|
|
313
|
+
decorator = getattr(self._recv_for_request, "_decorator", None)
|
|
314
|
+
if decorator is not None:
|
|
315
|
+
# If the original recv_for_request was decorated, we need to re-apply
|
|
316
|
+
# the decorator to the mocked recv_for_request. This is necessary for
|
|
317
|
+
# the request caching decorator to work properly.
|
|
318
|
+
|
|
319
|
+
async def _coro(
|
|
320
|
+
_provider: Any, _rpc_request: "RPCRequest"
|
|
321
|
+
) -> "RPCResponse":
|
|
322
|
+
return mocked_result
|
|
323
|
+
|
|
324
|
+
return await decorator(_coro)(self.w3.provider, rpc_request)
|
|
325
|
+
else:
|
|
326
|
+
return mocked_result
|
|
327
|
+
|
|
247
328
|
@staticmethod
|
|
248
329
|
def _create_error_object(error: Dict[str, Any]) -> Dict[str, Any]:
|
|
249
330
|
code = error.get("code", -32000)
|