Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
insipx committed Nov 15, 2023
1 parent 2768918 commit d3201eb
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 15 deletions.
2 changes: 1 addition & 1 deletion xmtp_mls/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ where
}
Ok(identity)
}
None => Ok(Identity::new(store, provider, &owner)?),
None => Ok(Identity::new(provider, &owner)?),
},
#[cfg(test)]
IdentityStrategy::ExternalIdentity(identity) => Ok(identity),
Expand Down
9 changes: 3 additions & 6 deletions xmtp_mls/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ where
let groups: Vec<MlsGroup<ApiClient>> = envelopes
.into_iter()
.filter_map(|envelope| {
// TODO: We can handle errors in the transaction() function to make error handling
// cleaner. Retryable errors can possibly be part of their own enum
XmtpOpenMlsProvider::transaction(&mut conn, |provider| {
let welcome = match extract_welcome(&envelope.message) {
Ok(welcome) => welcome,
Expand All @@ -221,12 +223,7 @@ where

// TODO: Update last_message_timestamp_ns on success or non-retryable error
// TODO: Abort if error is retryable
match MlsGroup::create_from_welcome(
self,
*provider.conn().borrow_mut(),
&provider,
welcome,
) {
match MlsGroup::create_from_welcome(self, &provider, welcome) {
Ok(mls_group) => Ok(Some(mls_group)),
Err(err) => {
log::error!("failed to create group from welcome: {}", err);
Expand Down
3 changes: 1 addition & 2 deletions xmtp_mls/src/groups/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ where

pub fn create_from_welcome(
client: &'c Client<ApiClient>,
conn: &mut DbConnection,
provider: &XmtpOpenMlsProvider,
welcome: MlsWelcome,
) -> Result<Self, GroupError> {
Expand All @@ -155,7 +154,7 @@ where
let group_id = mls_group.group_id().to_vec();
let stored_group =
StoredGroup::new(group_id.clone(), now_ns(), GroupMembershipState::Pending);
stored_group.store(conn)?;
stored_group.store(*provider.conn().borrow_mut())?;

Ok(Self::new(client, group_id, stored_group.created_at_ns))
}
Expand Down
10 changes: 4 additions & 6 deletions xmtp_mls/src/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ pub struct Identity {
pub(crate) credential: Credential,
}

impl<'a> Identity {
impl Identity {
pub(crate) fn new(
store: &EncryptedMessageStore,
provider: &XmtpOpenMlsProvider,
owner: &impl InboxOwner,
) -> Result<Self, IdentityError> {
Expand All @@ -63,8 +62,7 @@ impl<'a> Identity {
};

identity.new_key_package(provider)?;
StoredIdentity::from(&identity).store(&mut store.conn()?)?;
// StoredIdentity::from(&identity).store(*provider.conn().borrow_mut())?;
StoredIdentity::from(&identity).store(*provider.conn().borrow_mut())?;

// TODO: upload credential_with_key and last_resort_key_package

Expand Down Expand Up @@ -154,15 +152,15 @@ mod tests {
let store = EncryptedMessageStore::new_test();
let mut conn = store.conn().unwrap();
let provider = XmtpOpenMlsProvider::new(&mut conn);
Identity::new(&store, &provider, &generate_local_wallet()).unwrap();
Identity::new(&provider, &generate_local_wallet()).unwrap();
}

#[test]
fn test_key_package_extensions() {
let store = EncryptedMessageStore::new_test();
let mut conn = store.conn().unwrap();
let provider = XmtpOpenMlsProvider::new(&mut conn);
let identity = Identity::new(&store, &provider, &generate_local_wallet()).unwrap();
let identity = Identity::new(&provider, &generate_local_wallet()).unwrap();

let new_key_package = identity.new_key_package(&provider).unwrap();
assert!(new_key_package
Expand Down

0 comments on commit d3201eb

Please sign in to comment.