aboutsummaryrefslogtreecommitdiff
path: root/jsonrpc/tests
diff options
context:
space:
mode:
Diffstat (limited to 'jsonrpc/tests')
-rw-r--r--jsonrpc/tests/impl_rpc_service.rs27
-rw-r--r--jsonrpc/tests/rpc_impl.rs26
2 files changed, 53 insertions, 0 deletions
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<Value, Error> {
+ 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);
+ });
+}
diff --git a/jsonrpc/tests/rpc_impl.rs b/jsonrpc/tests/rpc_impl.rs
new file mode 100644
index 0000000..5b14b59
--- /dev/null
+++ b/jsonrpc/tests/rpc_impl.rs
@@ -0,0 +1,26 @@
+use karyon_jsonrpc::{rpc_impl, Error, RPCService};
+use serde_json::Value;
+
+#[test]
+fn rpc_impl_service() {
+ struct Foo {}
+
+ #[rpc_impl]
+ impl Foo {
+ async fn foo(&self, params: Value) -> Result<Value, Error> {
+ Ok(params)
+ }
+ }
+
+ 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);
+ });
+}