From 0992071a7f1a36424bcfaf1fbc84541ea041df1a Mon Sep 17 00:00:00 2001 From: hozan23 Date: Thu, 11 Apr 2024 10:19:20 +0200 Subject: add support for tokio & improve net crate api --- jsonrpc/tests/impl_rpc_service.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 jsonrpc/tests/impl_rpc_service.rs (limited to 'jsonrpc/tests/impl_rpc_service.rs') diff --git a/jsonrpc/tests/impl_rpc_service.rs b/jsonrpc/tests/impl_rpc_service.rs new file mode 100644 index 0000000..e590ae1 --- /dev/null +++ b/jsonrpc/tests/impl_rpc_service.rs @@ -0,0 +1,27 @@ +use karyon_jsonrpc::{impl_rpc_service, Error, RPCService}; +use serde_json::Value; + +#[test] +fn service() { + struct Foo {} + + impl Foo { + async fn foo(&self, params: Value) -> Result { + Ok(params) + } + } + + impl_rpc_service!(Foo, foo); + + let f = Foo {}; + + assert!(f.get_method("foo").is_some()); + assert!(f.get_method("bar").is_none()); + + let params = serde_json::json!("params"); + + smol::block_on(async { + let foo_method = f.get_method("foo").unwrap(); + assert_eq!(foo_method(params.clone()).await.unwrap(), params); + }); +} -- cgit v1.2.3