File tree Expand file tree Collapse file tree 5 files changed +21
-30
lines changed Expand file tree Collapse file tree 5 files changed +21
-30
lines changed Original file line number Diff line number Diff line change 1+ A bugfix, pre-release, to update the ``Beacon `` APIs (sync and async) to properly use the new ``HTTPSessionManager ``.
Original file line number Diff line number Diff line change 33 randint ,
44)
55
6+ from aiohttp .client_exceptions import (
7+ InvalidURL ,
8+ )
69import pytest_asyncio
710
8- from web3 ._utils .request import (
9- _async_session_cache ,
10- )
1111from web3 .beacon import (
1212 AsyncBeacon ,
1313)
14- from web3 .exceptions import (
15- Web3ValueError ,
16- )
1714
1815# tested against lighthouse which uses port 5052 by default
1916BASE_URL = "http://localhost:5052"
@@ -27,20 +24,22 @@ def _assert_valid_response(response):
2724
2825@pytest .fixture
2926def async_beacon ():
30- return AsyncBeacon (base_url = BASE_URL )
27+ return AsyncBeacon (base_url = BASE_URL , request_timeout = 30.0 )
3128
3229
3330@pytest_asyncio .fixture (autouse = True )
34- async def _cleanup ():
31+ async def _cleanup (async_beacon ):
3532 yield
36- [await session .close () for _ , session in _async_session_cache .items ()]
37- _async_session_cache .clear ()
33+ [
34+ await session .close ()
35+ for _ , session in async_beacon ._request_session_manager .session_cache .items ()
36+ ]
3837
3938
4039# sanity check to make sure the positive test cases are valid
4140@pytest .mark .asyncio
4241async def test_async_cl_beacon_raises_exception_on_invalid_url (async_beacon ):
43- with pytest .raises (Web3ValueError ):
42+ with pytest .raises (InvalidURL ):
4443 await async_beacon ._async_make_get_request (
4544 BASE_URL + "/eth/v1/beacon/nonexistent"
4645 )
Original file line number Diff line number Diff line change 66from requests import (
77 Timeout ,
88)
9-
10- from web3 ._utils .request import (
11- _session_cache ,
9+ from requests .exceptions import (
10+ InvalidURL ,
1211)
12+
1313from web3 .beacon import (
1414 Beacon ,
1515)
16- from web3 .exceptions import (
17- Web3ValueError ,
18- )
1916
2017# tested against lighthouse which uses port 5052 by default
2118BASE_URL = "http://localhost:5052"
@@ -32,15 +29,9 @@ def beacon():
3229 return Beacon (base_url = BASE_URL )
3330
3431
35- @pytest .fixture (autouse = True )
36- def _cleanup ():
37- yield
38- _session_cache .clear ()
39-
40-
4132# sanity check to make sure the positive test cases are valid
4233def test_cl_beacon_raises_exception_on_invalid_url (beacon ):
43- with pytest .raises (Web3ValueError ):
34+ with pytest .raises (InvalidURL ):
4435 beacon ._make_get_request (BASE_URL + "/eth/v1/beacon/nonexistent" )
4536
4637
Original file line number Diff line number Diff line change 88 HexStr ,
99)
1010
11+ from web3 ._utils .http_session_manager import (
12+ HTTPSessionManager ,
13+ )
1114from web3 .beacon .api_endpoints import (
1215 GET_ATTESTATIONS ,
1316 GET_ATTESTER_SLASHINGS ,
4750 GET_VERSION ,
4851 GET_VOLUNTARY_EXITS ,
4952)
50- from web3 .session_manager import (
51- HTTPSessionManager ,
52- )
5353
5454
5555class AsyncBeacon :
Original file line number Diff line number Diff line change 88 HexStr ,
99)
1010
11+ from web3 ._utils .http_session_manager import (
12+ HTTPSessionManager ,
13+ )
1114from web3 .beacon .api_endpoints import (
1215 GET_ATTESTATIONS ,
1316 GET_ATTESTER_SLASHINGS ,
4750 GET_VERSION ,
4851 GET_VOLUNTARY_EXITS ,
4952)
50- from web3 .session_manager import (
51- HTTPSessionManager ,
52- )
5353
5454
5555class Beacon :
You can’t perform that action at this time.
0 commit comments