aboutsummaryrefslogtreecommitdiff
path: root/jsonrpc/tests
diff options
context:
space:
mode:
Diffstat (limited to 'jsonrpc/tests')
-rw-r--r--jsonrpc/tests/impl_rpc_service.rs30
-rw-r--r--jsonrpc/tests/rpc_pubsub_impl.rs30
2 files changed, 30 insertions, 30 deletions
diff --git a/jsonrpc/tests/impl_rpc_service.rs b/jsonrpc/tests/impl_rpc_service.rs
deleted file mode 100644
index 52c5c31..0000000
--- a/jsonrpc/tests/impl_rpc_service.rs
+++ /dev/null
@@ -1,30 +0,0 @@
-use karyon_jsonrpc::{impl_rpc_service, RPCError, RPCService};
-use serde_json::Value;
-
-#[test]
-fn service() {
- struct Foo {}
-
- impl Foo {
- async fn foo(&self, params: Value) -> Result<Value, RPCError> {
- 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").expect("Get method foo");
- assert_eq!(
- foo_method(params.clone()).await.expect("Call foo method"),
- params
- );
- });
-}
diff --git a/jsonrpc/tests/rpc_pubsub_impl.rs b/jsonrpc/tests/rpc_pubsub_impl.rs
new file mode 100644
index 0000000..9d2eb57
--- /dev/null
+++ b/jsonrpc/tests/rpc_pubsub_impl.rs
@@ -0,0 +1,30 @@
+use std::sync::Arc;
+
+use karyon_jsonrpc::{rpc_pubsub_impl, Channel, PubSubRPCService, RPCError};
+use serde_json::Value;
+
+#[test]
+fn rpc_pubsub_impl_service() {
+ struct Foo {}
+
+ #[rpc_pubsub_impl]
+ impl Foo {
+ async fn foo(
+ &self,
+ _channel: Arc<Channel>,
+ _method: String,
+ params: Value,
+ ) -> Result<Value, RPCError> {
+ Ok(params)
+ }
+ }
+
+ let f = Arc::new(Foo {});
+
+ assert!(f.get_pubsub_method("foo").is_some());
+ assert!(f.get_pubsub_method("bar").is_none());
+
+ let _params = serde_json::json!("params");
+
+ // TODO add more tests here
+}