Skip to content

Commit 0aa206c

Browse files
committed
Remove deepcopy in request_id for mocked responses
1 parent 169a8f1 commit 0aa206c

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
"requests>=2.23.0",
7979
"typing-extensions>=4.0.1",
8080
"types-requests>=2.0.0",
81-
"websockets>=10.0.0,<16.0.0",
81+
"websockets>=14.0.0",
8282
"pyunormalize>=15.0.0",
8383
],
8484
python_requires=">=3.10, <4",
@@ -99,5 +99,6 @@
9999
"Programming Language :: Python :: 3.11",
100100
"Programming Language :: Python :: 3.12",
101101
"Programming Language :: Python :: 3.13",
102+
"Programming Language :: Python :: 3.14",
102103
],
103104
)

web3/_utils/module_testing/utils.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from asyncio import (
22
iscoroutinefunction,
33
)
4-
import copy
54
from typing import (
65
TYPE_CHECKING,
76
Any,
@@ -113,12 +112,11 @@ def __init__(
113112
"AsyncMakeRequestFn", "MakeRequestFn"
114113
] = w3.provider.make_request
115114

115+
self._mock_request_counter = 0
116+
116117
def _build_request_id(self) -> int:
117-
request_id = (
118-
next(copy.deepcopy(self.w3.provider.request_counter))
119-
if hasattr(self.w3.provider, "request_counter")
120-
else 1
121-
)
118+
request_id = self._mock_request_counter
119+
self._mock_request_counter += 1
122120
return request_id
123121

124122
def __enter__(self) -> "Self":
@@ -144,7 +142,11 @@ def _mock_request_handler(
144142

145143
if all(
146144
method not in mock_dict
147-
for mock_dict in (self.mock_errors, self.mock_results, self.mock_responses)
145+
for mock_dict in (
146+
self.mock_errors,
147+
self.mock_results,
148+
self.mock_responses,
149+
)
148150
):
149151
return self._make_request(method, params)
150152

@@ -265,7 +267,11 @@ async def _async_mock_request_handler(
265267
self._make_request = cast("AsyncMakeRequestFn", self._make_request)
266268
if all(
267269
method not in mock_dict
268-
for mock_dict in (self.mock_errors, self.mock_results, self.mock_responses)
270+
for mock_dict in (
271+
self.mock_errors,
272+
self.mock_results,
273+
self.mock_responses,
274+
)
269275
):
270276
return await self._make_request(method, params)
271277
mocked_result = await self._async_build_mock_result(method, params)
@@ -289,7 +295,11 @@ async def _async_mock_send_handler(
289295
) -> "RPCRequest":
290296
if all(
291297
method not in mock_dict
292-
for mock_dict in (self.mock_errors, self.mock_results, self.mock_responses)
298+
for mock_dict in (
299+
self.mock_errors,
300+
self.mock_results,
301+
self.mock_responses,
302+
)
293303
):
294304
return await self._send_request(method, params)
295305
else:
@@ -304,7 +314,11 @@ async def _async_mock_recv_handler(
304314
request_id = rpc_request["id"]
305315
if all(
306316
method not in mock_dict
307-
for mock_dict in (self.mock_errors, self.mock_results, self.mock_responses)
317+
for mock_dict in (
318+
self.mock_errors,
319+
self.mock_results,
320+
self.mock_responses,
321+
)
308322
):
309323
return await self._recv_for_request(request_id)
310324
mocked_result = await self._async_build_mock_result(

0 commit comments

Comments
 (0)