aboutsummaryrefslogtreecommitdiff
path: root/jsonrpc/tests/impl_rpc_service.rs
blob: 52c5c3131522ae592786f563c70e81fdd243846f (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
27
28
29
30
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
        );
    });
}