Skip to content

Commit

Permalink
Sanitize address before inbox ID lookup (#863)
Browse files Browse the repository at this point in the history
* Sanitize address before inbox ID lookup

* Add test
  • Loading branch information
rygine authored Jun 24, 2024
1 parent 1e09690 commit b815d53
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions xmtp_mls/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,15 @@ where
&self,
address: String,
) -> Result<Option<String>, ClientError> {
let mut results = self.api_client.get_inbox_ids(vec![address.clone()]).await?;
Ok(results.remove(&address))
if let Some(sanitized_address) = sanitize_evm_addresses(vec![address])?.pop() {
let mut results = self
.api_client
.get_inbox_ids(vec![sanitized_address.clone()])
.await?;
Ok(results.remove(&sanitized_address))
} else {
Ok(None)
}
}

/// Get sequence id, may not be consistent with the backend
Expand Down Expand Up @@ -630,6 +637,7 @@ pub fn deserialize_welcome(welcome_bytes: &Vec<u8>) -> Result<Welcome, ClientErr
#[cfg(test)]
mod tests {
use xmtp_cryptography::utils::generate_local_wallet;
use xmtp_id::InboxOwner;

use crate::{
builder::ClientBuilder,
Expand Down Expand Up @@ -706,6 +714,19 @@ mod tests {
assert_eq!(groups[1].group_id, group_2.group_id);
}

#[tokio::test]
async fn test_find_inbox_id() {
let wallet = generate_local_wallet();
let client = ClientBuilder::new_test_client(&wallet).await;
assert_eq!(
client
.find_inbox_id_from_address(wallet.get_address())
.await
.unwrap(),
Some(client.inbox_id())
);
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_sync_welcomes() {
let alice = ClientBuilder::new_test_client(&generate_local_wallet()).await;
Expand Down

0 comments on commit b815d53

Please sign in to comment.