diff --git a/docs/providers.rst b/docs/providers.rst index b1501eeaa8..d89069ea6b 100644 --- a/docs/providers.rst +++ b/docs/providers.rst @@ -451,9 +451,9 @@ Geth - :meth:`web3.geth.admin.datadir() ` - :meth:`web3.geth.admin.node_info() ` - :meth:`web3.geth.admin.peers() ` -- :meth:`web3.geth.admin.start_rpc() ` +- :meth:`web3.geth.admin.start_http() ` - :meth:`web3.geth.admin.start_ws() ` -- :meth:`web3.geth.admin.stop_rpc() ` +- :meth:`web3.geth.admin.stop_http() ` - :meth:`web3.geth.admin.stop_ws() ` - :meth:`web3.geth.personal.ec_recover()` - :meth:`web3.geth.personal.import_raw_key() ` diff --git a/docs/web3.geth.rst b/docs/web3.geth.rst index c17cc500be..e9ce1bafb0 100644 --- a/docs/web3.geth.rst +++ b/docs/web3.geth.rst @@ -112,9 +112,9 @@ The ``web3.geth.admin`` object exposes methods to interact with the RPC APIs und True -.. py:method:: start_rpc(host='localhost', port=8545, cors="", apis="eth,net,web3") +.. py:method:: start_http(host='localhost', port=8545, cors="", apis="eth,net,web3") - * Delegates to ``admin_startRPC`` RPC Method + * Delegates to ``admin_startHTTP`` RPC Method Starts the HTTP based JSON RPC API webserver on the specified ``host`` and ``port``, with the ``rpccorsdomain`` set to the provided ``cors`` value and @@ -123,8 +123,14 @@ The ``web3.geth.admin`` object exposes methods to interact with the RPC APIs und .. code-block:: python - >>> web3.geth.admin.start_rpc() + >>> web3.geth.admin.start_http() True + + +.. py:method:: start_rpc() + + .. warning:: Deprecated: This method is deprecated in favor of + :meth:`~web3.geth.admin.start_http()` .. py:method:: start_ws(host='localhost', port=8546, cors="", apis="eth,net,web3") @@ -142,18 +148,24 @@ The ``web3.geth.admin`` object exposes methods to interact with the RPC APIs und True -.. py:method:: stop_rpc() +.. py:method:: stop_http() - * Delegates to ``admin_stopRPC`` RPC Method + * Delegates to ``admin_stopHTTP`` RPC Method Stops the HTTP based JSON RPC server. .. code-block:: python - >>> web3.geth.admin.stop_rpc() + >>> web3.geth.admin.stop_http() True +.. py:method:: stop_rpc() + + .. warning:: Deprecated: This method is deprecated in favor of + :meth:`~web3.geth.admin.stop_http()` + + .. py:method:: stop_ws() * Delegates to ``admin_stopWS`` RPC Method diff --git a/newsfragments/2507.feature.rst b/newsfragments/2507.feature.rst new file mode 100644 index 0000000000..3741af4ee0 --- /dev/null +++ b/newsfragments/2507.feature.rst @@ -0,0 +1 @@ +Deprecate Geth Admin StartRPC and StopRPC for StartHTTP and StopHTTP diff --git a/tests/integration/go_ethereum/test_goethereum_http.py b/tests/integration/go_ethereum/test_goethereum_http.py index c4c9ed5dbc..8489804133 100644 --- a/tests/integration/go_ethereum/test_goethereum_http.py +++ b/tests/integration/go_ethereum/test_goethereum_http.py @@ -104,16 +104,21 @@ class TestGoEthereumAdminModuleTest(GoEthereumAdminModuleTest): def test_admin_peers(self, w3: "Web3") -> None: super().test_admin_peers(w3) - def test_admin_start_stop_rpc(self, w3: "Web3") -> None: + def test_admin_start_stop_http(self, w3: "Web3") -> None: # This test causes all tests after it to fail on CI if it's allowed to run - pytest.xfail(reason='Only one RPC endpoint is allowed to be active at any time') - super().test_admin_start_stop_rpc(w3) + pytest.xfail(reason='Only one HTTP endpoint is allowed to be active at any time') + super().test_admin_start_stop_http(w3) def test_admin_start_stop_ws(self, w3: "Web3") -> None: # This test causes all tests after it to fail on CI if it's allowed to run pytest.xfail(reason='Only one WS endpoint is allowed to be active at any time') super().test_admin_start_stop_ws(w3) + def test_admin_start_stop_rpc(self, w3: "Web3") -> None: + # This test causes all tests after it to fail on CI if it's allowed to run + pytest.xfail(reason='Only one RPC endpoint is allowed to be active at any time') + super().test_admin_start_stop_rpc(w3) + class TestGoEthereumEthModuleTest(GoEthereumEthModuleTest): pass @@ -162,10 +167,10 @@ async def test_admin_peers(self, w3: "Web3") -> None: await super().test_admin_peers(w3) @pytest.mark.asyncio - async def test_admin_start_stop_rpc(self, w3: "Web3") -> None: + async def test_admin_start_stop_http(self, w3: "Web3") -> None: # This test causes all tests after it to fail on CI if it's allowed to run - pytest.xfail(reason='Only one RPC endpoint is allowed to be active at any time') - await super().test_admin_start_stop_rpc(w3) + pytest.xfail(reason='Only one HTTP endpoint is allowed to be active at any time') + await super().test_admin_start_stop_http(w3) @pytest.mark.asyncio async def test_admin_start_stop_ws(self, w3: "Web3") -> None: @@ -173,6 +178,12 @@ async def test_admin_start_stop_ws(self, w3: "Web3") -> None: pytest.xfail(reason='Only one WS endpoint is allowed to be active at any time') await super().test_admin_start_stop_ws(w3) + @pytest.mark.asyncio + async def test_admin_start_stop_rpc(self, w3: "Web3") -> None: + # This test causes all tests after it to fail on CI if it's allowed to run + pytest.xfail(reason='Only one RPC endpoint is allowed to be active at any time') + await super().test_admin_start_stop_rpc(w3) + class TestGoEthereumAsyncNetModuleTest(GoEthereumAsyncNetModuleTest): pass diff --git a/tests/integration/go_ethereum/test_goethereum_ipc.py b/tests/integration/go_ethereum/test_goethereum_ipc.py index e636b5a08e..eb56719792 100644 --- a/tests/integration/go_ethereum/test_goethereum_ipc.py +++ b/tests/integration/go_ethereum/test_goethereum_ipc.py @@ -66,10 +66,21 @@ class TestGoEthereumAdminModuleTest(GoEthereumAdminModuleTest): def test_admin_peers(w3): super().test_admin_peers(w3) - @pytest.mark.xfail(reason="websockets aren't enabled with our IPC flags") - def test_admin_start_stop_ws(w3): + def test_admin_start_stop_http(self, w3: "Web3") -> None: + # This test causes all tests after it to fail on CI if it's allowed to run + pytest.xfail(reason='Only one HTTP endpoint is allowed to be active at any time') + super().test_admin_start_stop_http(w3) + + def test_admin_start_stop_ws(self, w3: "Web3") -> None: + # This test causes all tests after it to fail on CI if it's allowed to run + pytest.xfail(reason='Only one WS endpoint is allowed to be active at any time') super().test_admin_start_stop_ws(w3) + def test_admin_start_stop_rpc(self, w3: "Web3") -> None: + # This test causes all tests after it to fail on CI if it's allowed to run + pytest.xfail(reason='Only one RPC endpoint is allowed to be active at any time') + super().test_admin_start_stop_rpc(w3) + class TestGoEthereumEthModuleTest(GoEthereumEthModuleTest): pass diff --git a/tests/integration/go_ethereum/test_goethereum_ws.py b/tests/integration/go_ethereum/test_goethereum_ws.py index 1460e8799a..0baafd073a 100644 --- a/tests/integration/go_ethereum/test_goethereum_ws.py +++ b/tests/integration/go_ethereum/test_goethereum_ws.py @@ -79,6 +79,11 @@ class TestGoEthereumAdminModuleTest(GoEthereumAdminModuleTest): def test_admin_peers(self, w3: "Web3") -> None: super().test_admin_peers(w3) + def test_admin_start_stop_http(self, w3: "Web3") -> None: + # This test causes all tests after it to fail on CI if it's allowed to run + pytest.xfail(reason='Only one HTTP endpoint is allowed to be active at any time') + super().test_admin_start_stop_http(w3) + def test_admin_start_stop_ws(self, w3: "Web3") -> None: # This test inconsistently causes all tests after it to fail on CI if it's allowed to run pytest.xfail(reason='Only one WebSocket endpoint is allowed to be active at any time') @@ -86,7 +91,7 @@ def test_admin_start_stop_ws(self, w3: "Web3") -> None: def test_admin_start_stop_rpc(self, w3: "Web3") -> None: pytest.xfail(reason="This test inconsistently causes all tests after it on CI to fail if it's allowed to run") # noqa: E501 - super().test_admin_start_stop_ws(w3) + super().test_admin_start_stop_rpc(w3) class TestGoEthereumEthModuleTest(GoEthereumEthModuleTest): diff --git a/web3/_utils/admin.py b/web3/_utils/admin.py index a19ad98dfe..dbe841c913 100644 --- a/web3/_utils/admin.py +++ b/web3/_utils/admin.py @@ -11,6 +11,7 @@ RPC, ) from web3.method import ( + DeprecatedMethod, Method, default_root_munger, ) @@ -62,8 +63,8 @@ def __call__( pass -start_rpc: Method[ServerConnection] = Method( - RPC.admin_startRPC, +start_http: Method[ServerConnection] = Method( + RPC.admin_startHTTP, mungers=[admin_start_params_munger], ) @@ -74,8 +75,8 @@ def __call__( ) -stop_rpc: Method[Callable[[], bool]] = Method( - RPC.admin_stopRPC, +stop_http: Method[Callable[[], bool]] = Method( + RPC.admin_stopHTTP, is_property=True, ) @@ -84,3 +85,9 @@ def __call__( RPC.admin_stopWS, is_property=True, ) + +# +# Deprecated Methods +# +start_rpc = DeprecatedMethod(start_http, 'start_rpc', 'start_http') +stop_rpc = DeprecatedMethod(stop_http, 'stop_rpc', 'stop_http') diff --git a/web3/_utils/module_testing/go_ethereum_admin_module.py b/web3/_utils/module_testing/go_ethereum_admin_module.py index aa568fe919..0100d76436 100644 --- a/web3/_utils/module_testing/go_ethereum_admin_module.py +++ b/web3/_utils/module_testing/go_ethereum_admin_module.py @@ -45,13 +45,22 @@ def test_admin_peers(self, w3: "Web3") -> None: result = w3.geth.admin.peers() assert len(result) == 1 - def test_admin_start_stop_rpc(self, w3: "Web3") -> None: - stop = w3.geth.admin.stop_rpc() + def test_admin_start_stop_http(self, w3: "Web3") -> None: + stop = w3.geth.admin.stop_http() assert stop is True - start = w3.geth.admin.start_rpc() + start = w3.geth.admin.start_http() assert start is True + def test_admin_start_stop_rpc(self, w3: "Web3") -> None: + with pytest.warns(DeprecationWarning, match='deprecated in favor of stop_http'): + stop = w3.geth.admin.stop_rpc() + assert stop is True + + with pytest.warns(DeprecationWarning, match='deprecated in favor of start_http'): + start = w3.geth.admin.start_rpc() + assert start is True + def test_admin_start_stop_ws(self, w3: "Web3") -> None: stop = w3.geth.admin.stop_ws() assert stop is True @@ -85,13 +94,23 @@ async def test_admin_peers(self, w3: "Web3") -> None: assert len(result) == 1 @pytest.mark.asyncio - async def test_admin_start_stop_rpc(self, w3: "Web3") -> None: - stop = await w3.geth.admin.stop_rpc() # type: ignore + async def test_admin_start_stop_http(self, w3: "Web3") -> None: + stop = await w3.geth.admin.stop_http() # type: ignore assert stop is True - start = await w3.geth.admin.start_rpc() # type: ignore + start = await w3.geth.admin.start_http() # type: ignore assert start is True + @pytest.mark.asyncio + async def test_admin_start_stop_rpc(self, w3: "Web3") -> None: + with pytest.warns(DeprecationWarning, match='deprecated in favor of stop_http'): + stop = await w3.geth.admin.stop_rpc() + assert stop is True + + with pytest.warns(DeprecationWarning, match='deprecated in favor of start_http'): + start = await w3.geth.admin.start_rpc() + assert start is True + @pytest.mark.asyncio async def test_admin_start_stop_ws(self, w3: "Web3") -> None: stop = await w3.geth.admin.stop_ws() # type: ignore diff --git a/web3/_utils/rpc_abi.py b/web3/_utils/rpc_abi.py index bb55e89c9a..44dcac809e 100644 --- a/web3/_utils/rpc_abi.py +++ b/web3/_utils/rpc_abi.py @@ -34,10 +34,13 @@ class RPC: admin_datadir = RPCEndpoint("admin_datadir") admin_nodeInfo = RPCEndpoint("admin_nodeInfo") admin_peers = RPCEndpoint("admin_peers") - admin_startRPC = RPCEndpoint("admin_startRPC") + admin_startHTTP = RPCEndpoint("admin_startHTTP") admin_startWS = RPCEndpoint("admin_startWS") - admin_stopRPC = RPCEndpoint("admin_stopRPC") + admin_stopHTTP = RPCEndpoint("admin_stopHTTP") admin_stopWS = RPCEndpoint("admin_stopWS") + # deprecated + admin_startRPC = RPCEndpoint("admin_startRPC") + admin_stopRPC = RPCEndpoint("admin_stopRPC") # eth eth_accounts = RPCEndpoint("eth_accounts") diff --git a/web3/geth.py b/web3/geth.py index 315f52676c..fb2a24cdfb 100644 --- a/web3/geth.py +++ b/web3/geth.py @@ -21,11 +21,16 @@ datadir, node_info, peers, + start_http, start_rpc, start_ws, + stop_http, stop_rpc, stop_ws, ) +from web3._utils.decorators import ( + deprecated_for, +) from web3._utils.miner import ( make_dag, set_etherbase, @@ -210,9 +215,12 @@ class BaseGethAdmin(Module): _datadir = datadir _node_info = node_info _peers = peers - _start_rpc = start_rpc + _start_http = start_http _start_ws = start_ws + _stop_http = stop_http _stop_ws = stop_ws + # deprecated + _start_rpc = start_rpc _stop_rpc = stop_rpc @@ -231,26 +239,44 @@ def node_info(self) -> NodeInfo: def peers(self) -> List[Peer]: return self._peers() - def start_rpc(self, - host: str = "localhost", - port: int = 8546, - cors: str = "", - apis: str = "eth,net,web3") -> bool: - return self._start_rpc(host, port, cors, apis) - - def start_ws(self, - host: str = "localhost", - port: int = 8546, - cors: str = "", - apis: str = "eth,net,web3") -> bool: + def start_http( + self, + host: str = "localhost", + port: int = 8546, + cors: str = "", + apis: str = "eth,net,web3" + ) -> bool: + return self._start_http(host, port, cors, apis) + + def start_ws( + self, + host: str = "localhost", + port: int = 8546, + cors: str = "", + apis: str = "eth,net,web3" + ) -> bool: return self._start_ws(host, port, cors, apis) - def stop_rpc(self) -> bool: + def stop_http(self) -> bool: return self._stop_rpc() def stop_ws(self) -> bool: return self._stop_ws() + @deprecated_for("start_http") + def start_rpc( + self, + host: str = "localhost", + port: int = 8546, + cors: str = "", + apis: str = "eth,net,web3" + ) -> bool: + return self._start_rpc(host, port, cors, apis) + + @deprecated_for("stop_http") + def stop_rpc(self) -> bool: + return self._stop_rpc() + class AsyncGethAdmin(BaseGethAdmin): is_async = True @@ -267,26 +293,44 @@ async def node_info(self) -> Awaitable[NodeInfo]: async def peers(self) -> Awaitable[List[Peer]]: return await self._peers() # type: ignore - async def start_rpc(self, - host: str = "localhost", - port: int = 8546, - cors: str = "", - apis: str = "eth,net,web3") -> Awaitable[bool]: - return await self._start_rpc(host, port, cors, apis) # type: ignore - - async def start_ws(self, - host: str = "localhost", - port: int = 8546, - cors: str = "", - apis: str = "eth,net,web3") -> Awaitable[bool]: + async def start_http( + self, + host: str = "localhost", + port: int = 8546, + cors: str = "", + apis: str = "eth,net,web3" + ) -> Awaitable[bool]: + return await self._start_http(host, port, cors, apis) # type: ignore + + async def start_ws( + self, + host: str = "localhost", + port: int = 8546, + cors: str = "", + apis: str = "eth,net,web3" + ) -> Awaitable[bool]: return await self._start_ws(host, port, cors, apis) # type: ignore - async def stop_rpc(self) -> Awaitable[bool]: - return await self._stop_rpc() # type: ignore + async def stop_http(self) -> Awaitable[bool]: + return await self._stop_http() # type: ignore async def stop_ws(self) -> Awaitable[bool]: return await self._stop_ws() # type: ignore + @deprecated_for("start_http") + async def start_rpc( + self, + host: str = "localhost", + port: int = 8546, + cors: str = "", + apis: str = "eth,net,web3" + ) -> Awaitable[bool]: + return await self._start_rpc(host, port, cors, apis) + + @deprecated_for("stop_http") + async def stop_rpc(self) -> Awaitable[bool]: + return await self._stop_rpc() + class GethMiner(Module): """ diff --git a/web3/providers/eth_tester/defaults.py b/web3/providers/eth_tester/defaults.py index f9090a3769..efd6d06afb 100644 --- a/web3/providers/eth_tester/defaults.py +++ b/web3/providers/eth_tester/defaults.py @@ -320,20 +320,16 @@ def personal_send_transaction(eth_tester: "EthereumTester", params: Any) -> HexS }, 'admin': { 'add_peer': not_implemented, + 'datadir': not_implemented, 'node_info': not_implemented, - 'start_rpc': not_implemented, + 'peers': not_implemented, + 'start_http': not_implemented, 'start_ws': not_implemented, - 'stop_rpc': not_implemented, + 'stop_http': not_implemented, 'stop_ws': not_implemented, # deprecated - 'addPeer': not_implemented, - 'datadir': not_implemented, - 'nodeInfo': not_implemented, - 'peers': not_implemented, - 'startRPC': not_implemented, - 'startWS': not_implemented, - 'stopRPC': not_implemented, - 'stopWS': not_implemented, + 'start_rpc': not_implemented, + 'stop_rpc': not_implemented, }, 'debug': { 'backtraceAt': not_implemented,