Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add get version RPC method for all services #18366

Merged
merged 4 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions chia/_tests/core/test_full_node_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from chia_rs import AugSchemeMPL
from clvm.casts import int_to_bytes

from chia import __version__
from chia._tests.blockchain.blockchain_test_utils import _validate_and_add_block
from chia._tests.conftest import ConsensusMode
from chia._tests.connection_utils import connect_and_get_peer
Expand Down Expand Up @@ -577,6 +578,23 @@ async def test_get_network_info(one_wallet_and_one_simulator_services, self_host
}


@pytest.mark.anyio
async def test_get_version(one_wallet_and_one_simulator_services, self_hostname):
nodes, _, bt = one_wallet_and_one_simulator_services
(full_node_service_1,) = nodes
async with FullNodeRpcClient.create_as_context(
self_hostname,
full_node_service_1.rpc_server.listen_port,
full_node_service_1.root_path,
full_node_service_1.config,
) as client:
version = await client.fetch("get_version", {})
assert version == {
"success": True,
"version": __version__,
}


@pytest.mark.anyio
async def test_get_blockchain_state(one_wallet_and_one_simulator_services, self_hostname):
num_blocks = 5
Expand Down
1 change: 1 addition & 0 deletions chia/_tests/util/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ async def validate_get_routes(client: RpcClient, api: RpcApiProtocol) -> None:
"/close_connection",
"/stop_node",
"/get_routes",
"/get_version",
"/healthz",
]
assert len(routes_api) > 0
Expand Down
7 changes: 7 additions & 0 deletions chia/rpc/rpc_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from aiohttp import ClientConnectorError, ClientSession, ClientWebSocketResponse, WSMsgType, web
from typing_extensions import Protocol, final

from chia import __version__
from chia.rpc.util import wrap_http_handler
from chia.server.outbound_message import NodeType
from chia.server.server import ChiaServer, ssl_context_for_client, ssl_context_for_server
Expand Down Expand Up @@ -241,6 +242,7 @@ def _get_routes(self) -> Dict[str, Endpoint]:
"/close_connection": self.close_connection,
"/stop_node": self.stop_node,
"/get_routes": self.get_routes,
"/get_version": self.get_version,
"/healthz": self.healthz,
}

Expand Down Expand Up @@ -301,6 +303,11 @@ async def healthz(self, request: Dict[str, Any]) -> EndpointResult:
"success": True,
}

async def get_version(self, request: Dict[str, Any]) -> EndpointResult:
return {
"version": __version__,
}

async def ws_api(self, message: WsRpcMessage) -> Optional[Dict[str, object]]:
"""
This function gets called when new message is received via websocket.
Expand Down
Loading