@@ -286,6 +286,60 @@ async def test_get_metadata_with_http_url(self, mock_client_class):
286286 "https://rofl.example.com/rofl/v1/metadata" , timeout = 60.0
287287 )
288288
289+ @patch ("oasis_rofl_client.rofl_client.httpx.AsyncClient" )
290+ async def test_query (self , mock_client_class ):
291+ """Test query method."""
292+ # Setup mock
293+ mock_response = MagicMock ()
294+ mock_response .json .return_value = {"data" : "48656c6c6f" } # "Hello" in hex
295+ mock_response .raise_for_status = MagicMock ()
296+
297+ mock_client = AsyncMock ()
298+ mock_client .post .return_value = mock_response
299+ mock_client_class .return_value .__aenter__ .return_value = mock_client
300+
301+ # Test query
302+ client = RoflClient ()
303+ args = b"\xa1 \x64 test\x65 value" # CBOR-encoded test data
304+ result = await client .query ("test.Method" , args )
305+
306+ # Verify the result
307+ self .assertEqual (result , b"Hello" )
308+
309+ # Verify the API call
310+ mock_client .post .assert_called_once_with (
311+ "http://localhost/rofl/v1/query" ,
312+ json = {"method" : "test.Method" , "args" : args .hex ()},
313+ timeout = 60.0 ,
314+ )
315+
316+ @patch ("oasis_rofl_client.rofl_client.httpx.AsyncClient" )
317+ async def test_query_with_http_url (self , mock_client_class ):
318+ """Test query method with HTTP URL."""
319+ # Setup mock
320+ mock_response = MagicMock ()
321+ mock_response .json .return_value = {"data" : "deadbeef" }
322+ mock_response .raise_for_status = MagicMock ()
323+
324+ mock_client = AsyncMock ()
325+ mock_client .post .return_value = mock_response
326+ mock_client_class .return_value .__aenter__ .return_value = mock_client
327+
328+ # Test with HTTP URL
329+ client = RoflClient (url = "https://rofl.example.com" )
330+ args = b"\x00 \x01 \x02 "
331+ result = await client .query ("state.Query" , args )
332+
333+ # Verify the result
334+ self .assertEqual (result , bytes .fromhex ("deadbeef" ))
335+
336+ # Verify the API call uses the custom URL
337+ mock_client .post .assert_called_once_with (
338+ "https://rofl.example.com/rofl/v1/query" ,
339+ json = {"method" : "state.Query" , "args" : "000102" },
340+ timeout = 60.0 ,
341+ )
342+
289343
290344if __name__ == "__main__" :
291345 unittest .main ()
0 commit comments