11from asyncio import (
22 iscoroutinefunction ,
33)
4- import copy
54from 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