Skip to main content

xmtp_api_backend/endpoints/backend/
mod.rs

1mod publish;
2pub use publish::Publish;
3mod create_upload;
4pub use create_upload::{CREATE_UPLOAD_PATH, CreateUpload};
5mod query;
6pub use query::Query;
7mod query_newest;
8pub use query_newest::QueryNewest;
9mod get_inbox_ids;
10pub use get_inbox_ids::GetInboxIds;
11mod get_configuration;
12pub use get_configuration::{GET_CONFIGURATION_PATH, GetConfiguration};
13mod verify_smart_contract_wallet_signatures;
14pub use verify_smart_contract_wallet_signatures::VerifySmartContractWalletSignatures;
15mod subscribe_static;
16pub use subscribe_static::SubscribeStatic;
17mod register;
18pub use register::Register;
19mod unregister;
20pub use unregister::Unregister;
21mod update_subscriptions;
22pub use update_subscriptions::UpdateSubscriptions;
23
24#[cfg(test)]
25mod tests {
26    use super::*;
27    use prost::Message;
28    use std::collections::HashSet;
29    use xmtp_proto::api::Endpoint;
30
31    #[xmtp_common::test(unwrap_try = true)]
32    fn endpoint_paths_match_backend_services() {
33        let paths = [
34            (
35                Publish(Default::default()).grpc_endpoint(),
36                "/xmtp.backend.v1.PublishService/Publish",
37            ),
38            (
39                CreateUpload(Default::default()).grpc_endpoint(),
40                CREATE_UPLOAD_PATH,
41            ),
42            (
43                Query(Default::default()).grpc_endpoint(),
44                "/xmtp.backend.v1.QueryService/Query",
45            ),
46            (
47                QueryNewest(Default::default()).grpc_endpoint(),
48                "/xmtp.backend.v1.QueryService/QueryNewest",
49            ),
50            (
51                GetInboxIds(Default::default()).grpc_endpoint(),
52                "/xmtp.backend.v1.IdentityService/GetInboxIds",
53            ),
54            (
55                GetConfiguration(Default::default()).grpc_endpoint(),
56                "/xmtp.backend.v1.ConfigurationService/GetConfiguration",
57            ),
58            (
59                VerifySmartContractWalletSignatures(Default::default()).grpc_endpoint(),
60                "/xmtp.backend.v1.IdentityService/VerifySmartContractWalletSignatures",
61            ),
62            (
63                SubscribeStatic(Default::default()).grpc_endpoint(),
64                "/xmtp.backend.v1.SubscriptionService/SubscribeStatic",
65            ),
66            (
67                Register(Default::default()).grpc_endpoint(),
68                "/xmtp.backend.v1.NotificationService/Register",
69            ),
70            (
71                Unregister(Default::default()).grpc_endpoint(),
72                "/xmtp.backend.v1.NotificationService/Unregister",
73            ),
74            (
75                UpdateSubscriptions(Default::default()).grpc_endpoint(),
76                "/xmtp.backend.v1.NotificationService/UpdateSubscriptions",
77            ),
78        ];
79        let descriptors = prost_types::FileDescriptorSet::decode(xmtp_proto::FILE_DESCRIPTOR_SET)?;
80        let service_paths = descriptors
81            .file
82            .iter()
83            .flat_map(|file| {
84                let package = file.package.as_deref().unwrap_or_default();
85                file.service.iter().flat_map(move |service| {
86                    let service_name = service.name.as_deref().unwrap_or_default();
87                    service.method.iter().map(move |method| {
88                        format!(
89                            "/{package}.{service_name}/{}",
90                            method.name.as_deref().unwrap_or_default()
91                        )
92                    })
93                })
94            })
95            .collect::<HashSet<_>>();
96        for (actual, expected) in paths {
97            assert_eq!(actual, expected);
98            assert!(
99                service_paths.contains(expected),
100                "missing proto service path: {expected}"
101            );
102        }
103    }
104}