use crate::helpers; use jsonrpsee_http_client::*; use jsonrpsee_ws_client::*; jsonrpsee_proc_macros::rpc_client_api! { Test { fn say_hello() -> T; } } jsonrpsee_proc_macros::rpc_client_api! { pub(crate) Test2 { #[rpc(method = "say_hello")] fn foo(b: B) -> T; } } jsonrpsee_proc_macros::rpc_client_api! { Author { #[rpc(method = "author_submitExtrinsic", positional_params)] fn submit_extrinsic(extrinsic: String) -> u128; } Chain { #[rpc(method = "chain_getFinalizedHead")] fn current_block_hash() -> u128; #[rpc(method = "chain_getHeader", positional_params)] fn header(hash: u128) -> Option; #[rpc(method = "chain_getBlockHash", positional_params)] fn block_hash(hash: Option) -> Option; } State { #[rpc(method = "state_getRuntimeVersion")] fn runtime_version() -> u128; } } // https://github.com/paritytech/jsonrpsee/issues/104 jsonrpsee_proc_macros::rpc_client_api! { Registrar { #[rpc(method = "say_hello")] fn register_para(foo: i32, bar: String); } } jsonrpsee_proc_macros::rpc_client_api! { ManyReturnTypes { #[rpc(method = "say_hello")] fn a() -> A; fn b() -> B; fn c() -> C; fn d() -> D; fn e() -> E; } } #[tokio::test] async fn proc_macros_generic_ws_client_api() { let server_addr = helpers::websocket_server().await; let server_url = format!("ws://{}", server_addr); let client = WsClient::new(WsConfig::with_url(&server_url)).await.unwrap(); assert_eq!(Test::::say_hello(&client).await.unwrap(), "hello".to_string()); assert_eq!(Test2::::foo(&client, 99_u16).await.unwrap(), "hello".to_string()); assert!(Registrar::register_para(&client, 99, "para").await.is_ok()); } #[tokio::test] async fn proc_macros_generic_http_client_api() { let server_addr = helpers::http_server().await; let server_url = format!("http://{}", server_addr); let client = HttpClient::new(&server_url, HttpConfig::default()).unwrap(); assert_eq!(Test::::say_hello(&client).await.unwrap(), "hello".to_string()); assert_eq!(Test2::::foo(&client, 99_u16).await.unwrap(), "hello".to_string()); // TODO: https://github.com/paritytech/jsonrpsee/issues/212 //assert!(Registrar::register_para(&client, 99, "para").await.is_ok()); }