From 6f45466d7c99a423108a49a6200093d7c7a4bde8 Mon Sep 17 00:00:00 2001 From: Andrew Plaza Date: Tue, 26 Nov 2024 12:13:49 -0500 Subject: [PATCH] fix IdentityStrategy and lints --- bindings_ffi/src/mls.rs | 2 +- bindings_node/test/helpers.ts | 2 +- bindings_wasm/src/client.rs | 2 +- examples/cli/cli-client.rs | 2 +- xmtp_debug/src/app/clients.rs | 2 +- xmtp_mls/src/builder.rs | 36 +++++++++---------- xmtp_mls/src/identity.rs | 4 +-- xmtp_mls/src/storage/encrypted_store/group.rs | 6 ++-- xmtp_mls/src/utils/test/mod.rs | 4 +-- 9 files changed, 29 insertions(+), 31 deletions(-) diff --git a/bindings_ffi/src/mls.rs b/bindings_ffi/src/mls.rs index 1261d2ef9..1dc95f2a7 100644 --- a/bindings_ffi/src/mls.rs +++ b/bindings_ffi/src/mls.rs @@ -112,7 +112,7 @@ pub async fn create_client( None => EncryptedMessageStore::new_unencrypted(storage_option).await?, }; log::info!("Creating XMTP client"); - let identity_strategy = IdentityStrategy::CreateIfNotFound( + let identity_strategy = IdentityStrategy::new( inbox_id.clone(), account_address.clone(), nonce, diff --git a/bindings_node/test/helpers.ts b/bindings_node/test/helpers.ts index 90f61189a..fc44c2229 100644 --- a/bindings_node/test/helpers.ts +++ b/bindings_node/test/helpers.ts @@ -44,7 +44,7 @@ export const createClient = async (user: User) => { user.account.address, undefined, undefined, - { level: 'trace', structured: true } + { level: 'info' } ) } diff --git a/bindings_wasm/src/client.rs b/bindings_wasm/src/client.rs index be29aea38..1db20bf67 100644 --- a/bindings_wasm/src/client.rs +++ b/bindings_wasm/src/client.rs @@ -153,7 +153,7 @@ pub async fn create_client( .map_err(|_| JsError::new("Error creating unencrypted message store"))?, }; - let identity_strategy = IdentityStrategy::CreateIfNotFound( + let identity_strategy = IdentityStrategy::new( inbox_id.clone(), account_address.clone().to_lowercase(), // this is a temporary solution diff --git a/examples/cli/cli-client.rs b/examples/cli/cli-client.rs index 0448e03b4..9e28e9cc8 100755 --- a/examples/cli/cli-client.rs +++ b/examples/cli/cli-client.rs @@ -535,7 +535,7 @@ where let inbox_id = generate_inbox_id(&w.get_address(), &nonce)?; let client = create_client( cli, - IdentityStrategy::CreateIfNotFound(inbox_id, w.get_address(), nonce, None), + IdentityStrategy::new(inbox_id, w.get_address(), nonce, None), client, ) .await?; diff --git a/xmtp_debug/src/app/clients.rs b/xmtp_debug/src/app/clients.rs index 6ed848eeb..fe07c5a9c 100644 --- a/xmtp_debug/src/app/clients.rs +++ b/xmtp_debug/src/app/clients.rs @@ -72,7 +72,7 @@ async fn new_client_inner( dir.join(db_name) }; - let client = crate::DbgClient::builder(IdentityStrategy::CreateIfNotFound( + let client = crate::DbgClient::builder(IdentityStrategy::new( inbox_id, wallet.get_address(), nonce, diff --git a/xmtp_mls/src/builder.rs b/xmtp_mls/src/builder.rs index ac779cb01..e8303e1ec 100644 --- a/xmtp_mls/src/builder.rs +++ b/xmtp_mls/src/builder.rs @@ -344,7 +344,7 @@ pub(crate) mod tests { IdentityStrategyTestCase { strategy: { let (legacy_key, legacy_account_address) = generate_random_legacy_key().await; - IdentityStrategy::CreateIfNotFound( + IdentityStrategy::new( generate_inbox_id(&legacy_account_address, &1).unwrap(), legacy_account_address.clone(), 1, @@ -356,7 +356,7 @@ pub(crate) mod tests { IdentityStrategyTestCase { strategy: { let (legacy_key, legacy_account_address) = generate_random_legacy_key().await; - IdentityStrategy::CreateIfNotFound( + IdentityStrategy::new( generate_inbox_id(&legacy_account_address, &1).unwrap(), legacy_account_address.clone(), 0, @@ -368,7 +368,7 @@ pub(crate) mod tests { IdentityStrategyTestCase { strategy: { let (legacy_key, legacy_account_address) = generate_random_legacy_key().await; - IdentityStrategy::CreateIfNotFound( + IdentityStrategy::new( generate_inbox_id(&legacy_account_address, &0).unwrap(), legacy_account_address.clone(), 0, @@ -381,7 +381,7 @@ pub(crate) mod tests { IdentityStrategyTestCase { strategy: { let account_address = generate_local_wallet().get_address(); - IdentityStrategy::CreateIfNotFound( + IdentityStrategy::new( generate_inbox_id(&account_address, &1).unwrap(), account_address.clone(), 0, @@ -394,7 +394,7 @@ pub(crate) mod tests { strategy: { let nonce = 1; let account_address = generate_local_wallet().get_address(); - IdentityStrategy::CreateIfNotFound( + IdentityStrategy::new( generate_inbox_id(&account_address, &nonce).unwrap(), account_address.clone(), nonce, @@ -407,7 +407,7 @@ pub(crate) mod tests { strategy: { let nonce = 0; let account_address = generate_local_wallet().get_address(); - IdentityStrategy::CreateIfNotFound( + IdentityStrategy::new( generate_inbox_id(&account_address, &nonce).unwrap(), account_address.clone(), nonce, @@ -450,7 +450,7 @@ pub(crate) mod tests { let id = generate_inbox_id(&legacy_account_address, &0).unwrap(); println!("{}", id.len()); - let identity_strategy = IdentityStrategy::CreateIfNotFound( + let identity_strategy = IdentityStrategy::new( generate_inbox_id(&legacy_account_address, &0).unwrap(), legacy_account_address.clone(), 0, @@ -483,7 +483,7 @@ pub(crate) mod tests { assert!(client1.inbox_id() == client2.inbox_id()); assert!(client1.installation_public_key() == client2.installation_public_key()); - let client3 = ClientBuilder::new(IdentityStrategy::CreateIfNotFound( + let client3 = ClientBuilder::new(IdentityStrategy::new( generate_inbox_id(&legacy_account_address, &0).unwrap(), legacy_account_address.to_string(), 0, @@ -499,7 +499,7 @@ pub(crate) mod tests { assert!(client1.inbox_id() == client3.inbox_id()); assert!(client1.installation_public_key() == client3.installation_public_key()); - let client4 = ClientBuilder::new(IdentityStrategy::CreateIfNotFound( + let client4 = ClientBuilder::new(IdentityStrategy::new( generate_inbox_id(&legacy_account_address, &0).unwrap(), legacy_account_address.to_string(), 0, @@ -548,8 +548,7 @@ pub(crate) mod tests { let wrapper = ApiClientWrapper::new(mock_api.into(), Retry::default()); - let identity = - IdentityStrategy::CreateIfNotFound("other_inbox_id".to_string(), address, nonce, None); + let identity = IdentityStrategy::new("other_inbox_id".to_string(), address, nonce, None); assert!(matches!( identity .initialize_identity(&wrapper, &store, &scw_verifier) @@ -590,7 +589,7 @@ pub(crate) mod tests { let wrapper = ApiClientWrapper::new(mock_api.into(), Retry::default()); - let identity = IdentityStrategy::CreateIfNotFound(inbox_id.clone(), address, nonce, None); + let identity = IdentityStrategy::new(inbox_id.clone(), address, nonce, None); assert!(dbg!( identity .initialize_identity(&wrapper, &store, &scw_verifier) @@ -629,7 +628,7 @@ pub(crate) mod tests { stored.store(&store.conn().unwrap()).unwrap(); let wrapper = ApiClientWrapper::new(mock_api.into(), Retry::default()); - let identity = IdentityStrategy::CreateIfNotFound(inbox_id.clone(), address, nonce, None); + let identity = IdentityStrategy::new(inbox_id.clone(), address, nonce, None); assert!(identity .initialize_identity(&wrapper, &store, &scw_verifier) .await @@ -669,8 +668,7 @@ pub(crate) mod tests { let wrapper = ApiClientWrapper::new(mock_api.into(), Retry::default()); let inbox_id = "inbox_id".to_string(); - let identity = - IdentityStrategy::CreateIfNotFound(inbox_id.clone(), address.clone(), nonce, None); + let identity = IdentityStrategy::new(inbox_id.clone(), address.clone(), nonce, None); let err = identity .initialize_identity(&wrapper, &store, &scw_verifier) .await @@ -695,7 +693,7 @@ pub(crate) mod tests { let nonce = 1; let inbox_id = generate_inbox_id(&wallet.get_address(), &nonce).unwrap(); - let client_a = Client::builder(IdentityStrategy::CreateIfNotFound( + let client_a = Client::builder(IdentityStrategy::new( inbox_id.clone(), wallet.get_address(), nonce, @@ -719,7 +717,7 @@ pub(crate) mod tests { .await .unwrap(); - let client_b = Client::builder(IdentityStrategy::CreateIfNotFound( + let client_b = Client::builder(IdentityStrategy::new( inbox_id, wallet.get_address(), nonce, @@ -743,7 +741,7 @@ pub(crate) mod tests { // EncryptedMessageStore::new_unencrypted(StorageOption::Persistent(tmpdb.clone())) // .unwrap(); - // ClientBuilder::new(IdentityStrategy::CreateIfNotFound( + // ClientBuilder::new(IdentityStrategy::new( // generate_local_wallet().get_address(), // None, // )) @@ -805,7 +803,7 @@ pub(crate) mod tests { let account_address = format!("{scw_addr:?}"); let account_id = AccountId::new_evm(anvil_meta.chain_id, account_address.clone()); - let identity_strategy = IdentityStrategy::CreateIfNotFound( + let identity_strategy = IdentityStrategy::new( generate_inbox_id(&account_address, &0).unwrap(), account_address, 0, diff --git a/xmtp_mls/src/identity.rs b/xmtp_mls/src/identity.rs index b253d889f..0b73a784d 100644 --- a/xmtp_mls/src/identity.rs +++ b/xmtp_mls/src/identity.rs @@ -74,7 +74,7 @@ pub enum IdentityStrategy { } impl IdentityStrategy { - pub fn inbox_id<'a>(&'a self) -> Option> { + pub fn inbox_id(&self) -> Option> { use IdentityStrategy::*; match self { CreateIfNotFound { ref inbox_id, .. } => Some(inbox_id), @@ -82,7 +82,7 @@ impl IdentityStrategy { } } - /// Create a new Identity Strategy. + /// Create a new Identity Strategy, with [`IdentityStrategy::CreateIfNotFound`]. /// If an Identity is not found in the local store, creates a new one. pub fn new( inbox_id: InboxId, diff --git a/xmtp_mls/src/storage/encrypted_store/group.rs b/xmtp_mls/src/storage/encrypted_store/group.rs index 6b9bc0221..1bd426db7 100644 --- a/xmtp_mls/src/storage/encrypted_store/group.rs +++ b/xmtp_mls/src/storage/encrypted_store/group.rs @@ -521,9 +521,9 @@ impl std::fmt::Display for ConversationType { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { use ConversationType::*; match self { - Group => write!(f, "{}", "group"), - Dm => write!(f, "{}", "dm"), - Sync => write!(f, "{}", "sync"), + Group => write!(f, "group"), + Dm => write!(f, "dm"), + Sync => write!(f, "sync"), } } } diff --git a/xmtp_mls/src/utils/test/mod.rs b/xmtp_mls/src/utils/test/mod.rs index 1616556ea..952b31988 100755 --- a/xmtp_mls/src/utils/test/mod.rs +++ b/xmtp_mls/src/utils/test/mod.rs @@ -175,7 +175,7 @@ where let nonce = 1; let inbox_id = generate_inbox_id(&owner.get_address(), &nonce).unwrap(); - let client = Client::::builder(IdentityStrategy::CreateIfNotFound( + let client = Client::::builder(IdentityStrategy::new( inbox_id, owner.get_address(), nonce, @@ -208,7 +208,7 @@ where let nonce = 1; let inbox_id = generate_inbox_id(&owner.get_address(), &nonce).unwrap(); - let mut builder = Client::::builder(IdentityStrategy::CreateIfNotFound( + let mut builder = Client::::builder(IdentityStrategy::new( inbox_id, owner.get_address(), nonce,