diff --git a/newsfragments/3421.bugfix.rst b/newsfragments/3421.bugfix.rst new file mode 100644 index 0000000000..2c8a6fb88d --- /dev/null +++ b/newsfragments/3421.bugfix.rst @@ -0,0 +1 @@ +A bugfix, pre-release, to update the ``Beacon`` APIs (sync and async) to properly use the new ``HTTPSessionManager``. diff --git a/tests/beacon/test_async_beacon.py b/tests/beacon/test_async_beacon.py index a9a8f03665..ca0efa9509 100644 --- a/tests/beacon/test_async_beacon.py +++ b/tests/beacon/test_async_beacon.py @@ -3,17 +3,14 @@ randint, ) +from aiohttp.client_exceptions import ( + InvalidURL, +) import pytest_asyncio -from web3._utils.request import ( - _async_session_cache, -) from web3.beacon import ( AsyncBeacon, ) -from web3.exceptions import ( - Web3ValueError, -) # tested against lighthouse which uses port 5052 by default BASE_URL = "http://localhost:5052" @@ -27,20 +24,22 @@ def _assert_valid_response(response): @pytest.fixture def async_beacon(): - return AsyncBeacon(base_url=BASE_URL) + return AsyncBeacon(base_url=BASE_URL, request_timeout=30.0) @pytest_asyncio.fixture(autouse=True) -async def _cleanup(): +async def _cleanup(async_beacon): yield - [await session.close() for _, session in _async_session_cache.items()] - _async_session_cache.clear() + [ + await session.close() + for _, session in async_beacon._request_session_manager.session_cache.items() + ] # sanity check to make sure the positive test cases are valid @pytest.mark.asyncio async def test_async_cl_beacon_raises_exception_on_invalid_url(async_beacon): - with pytest.raises(Web3ValueError): + with pytest.raises(InvalidURL): await async_beacon._async_make_get_request( BASE_URL + "/eth/v1/beacon/nonexistent" ) diff --git a/tests/beacon/test_beacon.py b/tests/beacon/test_beacon.py index 5bdaf06bd9..112c2276f2 100644 --- a/tests/beacon/test_beacon.py +++ b/tests/beacon/test_beacon.py @@ -6,16 +6,13 @@ from requests import ( Timeout, ) - -from web3._utils.request import ( - _session_cache, +from requests.exceptions import ( + InvalidURL, ) + from web3.beacon import ( Beacon, ) -from web3.exceptions import ( - Web3ValueError, -) # tested against lighthouse which uses port 5052 by default BASE_URL = "http://localhost:5052" @@ -32,15 +29,9 @@ def beacon(): return Beacon(base_url=BASE_URL) -@pytest.fixture(autouse=True) -def _cleanup(): - yield - _session_cache.clear() - - # sanity check to make sure the positive test cases are valid def test_cl_beacon_raises_exception_on_invalid_url(beacon): - with pytest.raises(Web3ValueError): + with pytest.raises(InvalidURL): beacon._make_get_request(BASE_URL + "/eth/v1/beacon/nonexistent") diff --git a/web3/beacon/async_beacon.py b/web3/beacon/async_beacon.py index f1643776f0..5368caffc3 100644 --- a/web3/beacon/async_beacon.py +++ b/web3/beacon/async_beacon.py @@ -8,6 +8,9 @@ HexStr, ) +from web3._utils.http_session_manager import ( + HTTPSessionManager, +) from web3.beacon.api_endpoints import ( GET_ATTESTATIONS, GET_ATTESTER_SLASHINGS, @@ -47,9 +50,6 @@ GET_VERSION, GET_VOLUNTARY_EXITS, ) -from web3.session_manager import ( - HTTPSessionManager, -) class AsyncBeacon: diff --git a/web3/beacon/beacon.py b/web3/beacon/beacon.py index f2f7270f87..2a77585159 100644 --- a/web3/beacon/beacon.py +++ b/web3/beacon/beacon.py @@ -8,6 +8,9 @@ HexStr, ) +from web3._utils.http_session_manager import ( + HTTPSessionManager, +) from web3.beacon.api_endpoints import ( GET_ATTESTATIONS, GET_ATTESTER_SLASHINGS, @@ -47,9 +50,6 @@ GET_VERSION, GET_VOLUNTARY_EXITS, ) -from web3.session_manager import ( - HTTPSessionManager, -) class Beacon: