Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[d14n] http/grpc test consolidation #1729

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 27 additions & 5 deletions xmtp_api/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,30 @@ pub use wasm::*;
#[cfg(not(target_arch = "wasm32"))]
mod not_wasm {
use super::*;
use xmtp_proto::api_client::ApiBuilder;
use xmtp_proto::xmtp::mls::api::v1::WelcomeMessage;
#[derive(Clone)]
pub struct ApiClient;
pub struct MockApiBuilder;

impl ApiBuilder for MockApiBuilder {
type Output = ApiClient;
type Error = MockError;

fn set_libxmtp_version(&mut self, version: String) -> Result<(), Self::Error> {
Ok(())
}
fn set_app_version(&mut self, version: String) -> Result<(), Self::Error> {
Ok(())
}
fn set_host(&mut self, host: String) {
}
fn set_payer(&mut self, _host: String) {}
fn set_tls(&mut self, tls: bool) {}
async fn build(self) -> Result<Self::Output, Self::Error> {
Ok(ApiClient)
}
}

mock! {
pub ApiClient { }
Expand Down Expand Up @@ -142,10 +163,10 @@ mod not_wasm {
-> Result<VerifySmartContractWalletSignaturesResponse, MockError>;
}

#[async_trait::async_trait]
impl XmtpTestClient for ApiClient {
async fn create_local() -> Self { ApiClient }
async fn create_dev() -> Self { ApiClient }
type Builder = MockApiBuilder;
fn create_local() -> MockApiBuilder { MockApiBuilder }
fn create_dev() -> MockApiBuilder { MockApiBuilder }
}
}
}
Expand Down Expand Up @@ -207,8 +228,9 @@ mod wasm {

#[async_trait::async_trait(?Send)]
impl XmtpTestClient for ApiClient {
async fn create_local() -> Self { ApiClient }
async fn create_dev() -> Self { ApiClient }
type Builder = ();
fn create_local() -> () { () }
fn create_dev() -> () { () }
}
}
}
9 changes: 8 additions & 1 deletion xmtp_api_d14n/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ prost-types.workspace = true
xmtp_common.workspace = true
xmtp_proto = { workspace = true, features = ["convert"] }

[dev-dependencies]
xmtp_proto = { workspace = true, features = ["convert", "test-utils"] }
xmtp_common = { workspace = true, features = ["test-utils"] }
wasm-bindgen-test.workspace = true

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
xmtp_api_grpc.workspace = true
xmtp_api_grpc = { workspace = true, features = ["test-utils"] }
xmtp_api_http.workspace = true
tokio.workspace = true

Expand All @@ -24,5 +29,7 @@ xmtp_api_http.workspace = true
tokio.workspace = true

[features]
default = ["grpc-api"]
http-api = ["xmtp_proto/http-api"]
grpc-api = ["xmtp_proto/grpc-api"]
test-utils = []
40 changes: 3 additions & 37 deletions xmtp_api_d14n/src/endpoints/d14n/get_inbox_ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ impl Endpoint for GetInboxIds {
}
}

#[cfg(all(test, not(target_arch = "wasm32")))]
#[cfg(test)]
mod test {
use crate::d14n::GetInboxIds;
use xmtp_proto::traits::Query;
use xmtp_proto::prelude::*;
use xmtp_proto::xmtp::xmtpv4::message_api::GetInboxIdsResponse;

#[test]
Expand All @@ -61,43 +61,9 @@ mod test {
println!("{}", pnq);
}

#[cfg(feature = "grpc-api")]
#[tokio::test]
async fn test_get_inbox_ids() {
use crate::d14n::GetInboxIds;
use xmtp_api_grpc::grpc_client::GrpcClient;
use xmtp_api_grpc::LOCALHOST_ADDRESS;
use xmtp_proto::api_client::ApiBuilder;
use xmtp_proto::traits::Query;

let mut client = GrpcClient::builder();
client.set_app_version("0.0.0".into()).unwrap();
client.set_tls(false);
client.set_host(LOCALHOST_ADDRESS.to_string());
let client = client.build().await.unwrap();

let endpoint = GetInboxIds::builder()
.addresses(vec!["".to_string()])
.build()
.unwrap();

//todo: fix later when it was implemented
let result = endpoint.query(&client).await;
assert!(result.is_err());
}

#[cfg(feature = "http-api")]
#[tokio::test]
async fn test_get_inbox_ids_http() {
use xmtp_api_http::XmtpHttpApiClient;
use xmtp_api_http::LOCALHOST_ADDRESS;
use xmtp_proto::api_client::ApiBuilder;

let mut client = XmtpHttpApiClient::builder();
client.set_app_version("0.0.0".into()).unwrap();
client.set_libxmtp_version("0.0.0".into()).unwrap();
client.set_tls(true);
client.set_host(LOCALHOST_ADDRESS.to_string());
let client = crate::TestClient::create_local();
let client = client.build().await.unwrap();

let endpoint = GetInboxIds::builder()
Expand Down
16 changes: 5 additions & 11 deletions xmtp_api_d14n/src/endpoints/d14n/publish_client_envelopes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ impl Endpoint for PublishClientEnvelopes {
}
}

#[cfg(all(test, not(target_arch = "wasm32")))]
#[cfg(test)]
mod test {
use super::*;
use xmtp_proto::prelude::*;

#[test]
fn test_file_descriptor() {
use xmtp_proto::xmtp::xmtpv4::payer_api::{
Expand All @@ -51,20 +54,11 @@ mod test {
println!("{}", pnq);
}

#[cfg(feature = "grpc-api")]
#[tokio::test]
async fn test_get_inbox_ids() {
use crate::d14n::PublishClientEnvelopes;
use xmtp_api_grpc::grpc_client::GrpcClient;
use xmtp_api_grpc::LOCALHOST_ADDRESS;
use xmtp_proto::api_client::ApiBuilder;
use xmtp_proto::traits::Query;
use xmtp_proto::xmtp::xmtpv4::envelopes::ClientEnvelope;

let mut client = GrpcClient::builder();
client.set_app_version("0.0.0".into()).unwrap();
client.set_tls(false);
client.set_host(LOCALHOST_ADDRESS.to_string());
let client = crate::TestClient::create_local();
let client = client.build().await.unwrap();

let endpoint = PublishClientEnvelopes::builder()
Expand Down
22 changes: 8 additions & 14 deletions xmtp_api_d14n/src/endpoints/d14n/query_envelopes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,30 +81,24 @@ impl Endpoint for QueryEnvelopes {
}
}

#[cfg(all(test, not(target_arch = "wasm32")))]
#[cfg(test)]
mod test {
use xmtp_proto::prelude::*;
use super::*;
use wasm_bindgen_test::wasm_bindgen_test;

#[test]
fn test_file_descriptor() {
use xmtp_proto::xmtp::xmtpv4::message_api::{QueryEnvelopesRequest, FILE_DESCRIPTOR_SET};
let pnq = crate::path_and_query::<QueryEnvelopesRequest>(FILE_DESCRIPTOR_SET);
println!("{}", pnq);
}

#[cfg(feature = "grpc-api")]
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
#[cfg(not(target_arch = "wasm32"))]
#[wasm_bindgen_test(unsupported = tokio::test)]
async fn test_get_inbox_ids() {
use crate::d14n::QueryEnvelopes;
use xmtp_api_grpc::grpc_client::GrpcClient;
use xmtp_api_grpc::LOCALHOST_ADDRESS;
use xmtp_proto::api_client::ApiBuilder;
use xmtp_proto::traits::Query;
use xmtp_proto::xmtp::xmtpv4::message_api::EnvelopesQuery;

let mut client = GrpcClient::builder();
client.set_app_version("0.0.0".into()).unwrap();
client.set_tls(false);
client.set_host(LOCALHOST_ADDRESS.to_string());

let client = crate::TestClient::create_local();
let client = client.build().await.unwrap();

let endpoint = QueryEnvelopes::builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,20 @@ impl Endpoint for GetIdentityUpdatesV2 {
}
}

#[cfg(all(test, not(target_arch = "wasm32")))]
#[cfg(test)]
mod test {
use super::*;
use xmtp_proto::prelude::*;

#[test]
fn test_file_descriptor() {
use xmtp_proto::xmtp::identity::api::v1::{GetIdentityUpdatesRequest, FILE_DESCRIPTOR_SET};
let pnq = crate::path_and_query::<GetIdentityUpdatesRequest>(FILE_DESCRIPTOR_SET);
println!("{}", pnq);
}

#[cfg(feature = "grpc-api")]
#[tokio::test]
async fn test_get_identity_updates_v2() {
use crate::v3::GetIdentityUpdatesV2;
use xmtp_api_grpc::grpc_client::GrpcClient;
use xmtp_api_grpc::LOCALHOST_ADDRESS;
use xmtp_proto::api_client::ApiBuilder;
use xmtp_proto::traits::Query;
use xmtp_proto::xmtp::identity::api::v1::{
get_identity_updates_request::Request, GetIdentityUpdatesResponse,
};

let mut client = GrpcClient::builder();
client.set_app_version("0.0.0".into()).unwrap();
client.set_tls(false);
client.set_host(LOCALHOST_ADDRESS.to_string());
let client = crate::TestClient::create_local();
let client = client.build().await.unwrap();
let endpoint = GetIdentityUpdatesV2::builder()
.requests(vec![Request {
Expand Down
43 changes: 4 additions & 39 deletions xmtp_api_d14n/src/endpoints/v3/identity/get_inbox_ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ impl Endpoint for GetInboxIds {
}
}

#[cfg(all(test, not(target_arch = "wasm32")))]
#[cfg(test)]
mod test {
use crate::v3::GetInboxIds;
use xmtp_proto::traits::Query;
use super::*;
use xmtp_proto::prelude::*;
use xmtp_proto::xmtp::identity::api::v1::GetInboxIdsResponse;

#[test]
Expand All @@ -60,44 +60,9 @@ mod test {
println!("{}", pnq);
}

#[cfg(feature = "grpc-api")]
#[tokio::test]
#[ignore]
async fn test_get_inbox_ids() {
use crate::v3::identity::GetInboxIds;
use xmtp_api_grpc::grpc_client::GrpcClient;
use xmtp_api_grpc::LOCALHOST_ADDRESS;
use xmtp_proto::api_client::ApiBuilder;
use xmtp_proto::traits::Query;
use xmtp_proto::xmtp::identity::api::v1::GetInboxIdsResponse;

let mut client = GrpcClient::builder();
client.set_app_version("0.0.0".into()).unwrap();
client.set_tls(false);
client.set_host(LOCALHOST_ADDRESS.to_string());
let client = client.build().await.unwrap();

let endpoint = GetInboxIds::builder()
.addresses(vec!["".to_string()])
.build()
.unwrap();

let result: GetInboxIdsResponse = endpoint.query(&client).await.unwrap();
assert_eq!(result.responses.len(), 0);
}

#[cfg(feature = "http-api")]
#[tokio::test]
async fn test_get_inbox_ids_http() {
use xmtp_api_http::XmtpHttpApiClient;
use xmtp_api_http::LOCALHOST_ADDRESS;
use xmtp_proto::api_client::ApiBuilder;

let mut client = XmtpHttpApiClient::builder();
client.set_app_version("0.0.0".into()).unwrap();
client.set_libxmtp_version("0.0.0".into()).unwrap();
client.set_tls(true);
client.set_host(LOCALHOST_ADDRESS.to_string());
let client = crate::TestClient::create_local();
let client = client.build().await.unwrap();

let endpoint = GetInboxIds::builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ impl Endpoint for PublishIdentityUpdate {
}
}

#[cfg(all(test, not(target_arch = "wasm32")))]
#[cfg(test)]
mod test {
use xmtp_proto::prelude::*;
use super::*;

#[test]
fn test_file_descriptor() {
Expand All @@ -50,22 +52,12 @@ mod test {
println!("{}", pnq);
}

#[cfg(feature = "grpc-api")]
#[tokio::test]
async fn test_publish_identity_update() {
use crate::v3::PublishIdentityUpdate;
use xmtp_api_grpc::grpc_client::GrpcClient;
use xmtp_api_grpc::{GrpcError, LOCALHOST_ADDRESS};
use xmtp_common::time::now_ns;
use xmtp_proto::api_client::ApiBuilder;
use xmtp_proto::traits::Query;
use xmtp_proto::xmtp::identity::api::v1::PublishIdentityUpdateResponse;

use xmtp_proto::xmtp::identity::associations::IdentityUpdate;
let mut client = GrpcClient::builder();
client.set_app_version("0.0.0".into()).unwrap();
client.set_tls(false);
client.set_host(LOCALHOST_ADDRESS.to_string());

let client = crate::TestClient::create_local();
let client = client.build().await.unwrap();
let endpoint = PublishIdentityUpdate::builder()
.identity_update(IdentityUpdate {
Expand All @@ -76,7 +68,7 @@ mod test {
.build()
.unwrap();

let _: Result<PublishIdentityUpdateResponse, xmtp_proto::traits::ApiError<GrpcError>> =
let _: Result<PublishIdentityUpdateResponse, _> =
endpoint.query(&client).await;
}
}
Loading
Loading