aboutsummaryrefslogtreecommitdiff
path: root/jsonrpc/tests/rpc_impl.rs
blob: 5b14b599baa3de240762594461a8e4d449428420 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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);
    });
}