@@ -789,7 +789,33 @@ async def test_client_get_signed_base_and_extended_cards(
789789
790790
791791@pytest .mark .asyncio
792- async def test_jsonrpc_malformed_payload (jsonrpc_setup : TransportSetup ) -> None :
792+ @pytest .mark .parametrize (
793+ 'request_kwargs, expected_error_code' ,
794+ [
795+ pytest .param (
796+ {'content' : 'not a json' },
797+ - 32700 , # Parse error
798+ id = 'invalid-json' ,
799+ ),
800+ pytest .param (
801+ {
802+ 'json' : {
803+ 'jsonrpc' : '2.0' ,
804+ 'method' : 'SendMessage' ,
805+ 'params' : {'message' : 'should be an object' },
806+ 'id' : 1 ,
807+ }
808+ },
809+ - 32602 , # Invalid params
810+ id = 'wrong-params-type' ,
811+ ),
812+ ],
813+ )
814+ async def test_jsonrpc_malformed_payload (
815+ jsonrpc_setup : TransportSetup ,
816+ request_kwargs : dict [str , Any ],
817+ expected_error_code : int ,
818+ ) -> None :
793819 """Integration test to verify that JSON-RPC malformed payloads don't return 500."""
794820 client_obj = jsonrpc_setup .client
795821 assert isinstance (client_obj , BaseClient )
@@ -798,23 +824,9 @@ async def test_jsonrpc_malformed_payload(jsonrpc_setup: TransportSetup) -> None:
798824 client = transport .httpx_client
799825 url = transport .url
800826
801- # 1. Invalid JSON
802- response = await client .post (url , content = 'not a json' )
803- assert response .status_code == 200
804- assert response .json ()['error' ]['code' ] == - 32700 # Parse error
805-
806- # 2. Wrong types in params
807- response = await client .post (
808- url ,
809- json = {
810- 'jsonrpc' : '2.0' ,
811- 'method' : 'SendMessage' ,
812- 'params' : {'message' : 'should be an object' },
813- 'id' : 1 ,
814- },
815- )
827+ response = await client .post (url , ** request_kwargs )
816828 assert response .status_code == 200
817- assert response .json ()['error' ]['code' ] == - 32602 # Invalid params
829+ assert response .json ()['error' ]['code' ] == expected_error_code
818830
819831 await transport .close ()
820832
0 commit comments