Skip to content

Commit 2b64f1e

Browse files
committed
test branch for testing pausing of groups bc of min verison in ffi bindings
1 parent 9a62523 commit 2b64f1e

File tree

4 files changed

+175
-3
lines changed

4 files changed

+175
-3
lines changed

bindings_ffi/src/mls.rs

+150
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ pub async fn create_client(
118118
nonce: u64,
119119
legacy_signed_private_key_proto: Option<Vec<u8>>,
120120
history_sync_url: Option<String>,
121+
version_info: Option<String>,
121122
) -> Result<Arc<FfiXmtpClient>, GenericError> {
122123
let ident = account_identifier.clone();
123124
init_logger();
@@ -160,6 +161,10 @@ pub async fn create_client(
160161
builder = builder.history_sync_url(url);
161162
}
162163

164+
if let Some(version) = &version_info {
165+
builder = builder.version_info(version);
166+
}
167+
163168
let xmtp_client = builder.build().await?;
164169

165170
log::info!(
@@ -384,6 +389,10 @@ impl FfiXmtpClient {
384389
Ok(state.into())
385390
}
386391

392+
pub async fn version_info(&self) -> Result<String, GenericError> {
393+
Ok(self.inner_client.version_info().pkg_version.to_string())
394+
}
395+
387396
/**
388397
* Get the inbox state for each `inbox_id`.
389398
*
@@ -2107,6 +2116,11 @@ impl FfiConversation {
21072116
self.inner.paused_for_version(&provider).map_err(Into::into)
21082117
}
21092118

2119+
pub async fn update_group_min_version_to_match_self(&self) -> Result<(), GenericError> {
2120+
self.inner.update_group_min_version_to_match_self().await?;
2121+
Ok(())
2122+
}
2123+
21102124
pub fn consent_state(&self) -> Result<FfiConsentState, GenericError> {
21112125
self.inner
21122126
.consent_state()
@@ -2703,6 +2717,7 @@ mod tests {
27032717
FfiMessageWithReactions, FfiMetadataField, FfiMultiRemoteAttachment, FfiPasskeySignature,
27042718
FfiPermissionPolicy, FfiPermissionPolicySet, FfiPermissionUpdateType, FfiReaction,
27052719
FfiReactionAction, FfiReactionSchema, FfiRemoteAttachmentInfo, FfiSubscribeError,
2720+
GenericError,
27062721
};
27072722
use ethers::utils::hex;
27082723
use prost::Message;
@@ -2941,6 +2956,39 @@ mod tests {
29412956
nonce,
29422957
None,
29432958
history_sync_url,
2959+
None,
2960+
)
2961+
.await
2962+
.unwrap();
2963+
2964+
let conn = client.inner_client.context().store().conn().unwrap();
2965+
conn.register_triggers();
2966+
2967+
register_client(&ffi_inbox_owner, &client).await;
2968+
client
2969+
}
2970+
2971+
async fn new_test_client_with_wallet_and_version_info(
2972+
wallet: xmtp_cryptography::utils::LocalWallet,
2973+
version_info: Option<String>,
2974+
) -> Arc<FfiXmtpClient> {
2975+
let ffi_inbox_owner = LocalWalletInboxOwner::with_wallet(wallet);
2976+
let ident = ffi_inbox_owner.identifier();
2977+
let nonce = 1;
2978+
let inbox_id = ident.inbox_id(nonce).unwrap();
2979+
2980+
let client = create_client(
2981+
connect_to_backend(xmtp_api_grpc::LOCALHOST_ADDRESS.to_string(), false)
2982+
.await
2983+
.unwrap(),
2984+
Some(tmp_path()),
2985+
Some(xmtp_mls::storage::EncryptedMessageStore::generate_enc_key().into()),
2986+
&inbox_id,
2987+
ident,
2988+
nonce,
2989+
None,
2990+
None,
2991+
version_info,
29442992
)
29452993
.await
29462994
.unwrap();
@@ -2963,6 +3011,12 @@ mod tests {
29633011
.await
29643012
}
29653013

3014+
async fn new_test_client_with_version_info() -> Arc<FfiXmtpClient> {
3015+
let wallet = xmtp_cryptography::utils::LocalWallet::new(&mut rng());
3016+
new_test_client_with_wallet_and_history_sync_url(wallet, Some(HISTORY_SYNC_URL.to_string()))
3017+
.await
3018+
}
3019+
29663020
impl FfiConversation {
29673021
#[cfg(test)]
29683022
async fn update_installations(&self) -> Result<(), GroupError> {
@@ -3012,6 +3066,7 @@ mod tests {
30123066
nonce,
30133067
Some(legacy_keys),
30143068
None,
3069+
None,
30153070
)
30163071
.await
30173072
.unwrap();
@@ -3039,6 +3094,7 @@ mod tests {
30393094
nonce,
30403095
None,
30413096
None,
3097+
None,
30423098
)
30433099
.await
30443100
.unwrap();
@@ -3058,6 +3114,7 @@ mod tests {
30583114
nonce,
30593115
None,
30603116
None,
3117+
None,
30613118
)
30623119
.await
30633120
.unwrap();
@@ -3093,6 +3150,7 @@ mod tests {
30933150
nonce,
30943151
None,
30953152
None,
3153+
None,
30963154
)
30973155
.await
30983156
.unwrap();
@@ -3113,6 +3171,7 @@ mod tests {
31133171
nonce,
31143172
None,
31153173
None,
3174+
None,
31163175
)
31173176
.await
31183177
.is_err();
@@ -3167,6 +3226,7 @@ mod tests {
31673226
nonce,
31683227
None,
31693228
None,
3229+
None,
31703230
)
31713231
.await
31723232
.unwrap();
@@ -3349,6 +3409,7 @@ mod tests {
33493409
nonce,
33503410
None,
33513411
None,
3412+
None,
33523413
)
33533414
.await
33543415
.unwrap();
@@ -3438,6 +3499,7 @@ mod tests {
34383499
nonce,
34393500
None, // v2_signed_private_key_proto
34403501
None,
3502+
None,
34413503
)
34423504
.await
34433505
.unwrap();
@@ -3469,6 +3531,7 @@ mod tests {
34693531
nonce,
34703532
None,
34713533
None,
3534+
None,
34723535
)
34733536
.await
34743537
.unwrap();
@@ -3496,6 +3559,7 @@ mod tests {
34963559
nonce,
34973560
None,
34983561
None,
3562+
None,
34993563
)
35003564
.await
35013565
.unwrap();
@@ -6635,6 +6699,7 @@ mod tests {
66356699
1,
66366700
None,
66376701
Some(HISTORY_SYNC_URL.to_string()),
6702+
None,
66386703
)
66396704
.await
66406705
.unwrap();
@@ -6674,6 +6739,7 @@ mod tests {
66746739
nonce,
66756740
None,
66766741
Some(HISTORY_SYNC_URL.to_string()),
6742+
None,
66776743
)
66786744
.await
66796745
.unwrap();
@@ -6738,6 +6804,7 @@ mod tests {
67386804
nonce,
67396805
None,
67406806
Some(HISTORY_SYNC_URL.to_string()),
6807+
None,
67416808
)
67426809
.await;
67436810

@@ -6773,6 +6840,7 @@ mod tests {
67736840
1,
67746841
None,
67756842
Some(HISTORY_SYNC_URL.to_string()),
6843+
None,
67766844
)
67776845
.await
67786846
.unwrap();
@@ -6795,6 +6863,7 @@ mod tests {
67956863
1,
67966864
None,
67976865
Some(HISTORY_SYNC_URL.to_string()),
6866+
None,
67986867
)
67996868
.await
68006869
.unwrap();
@@ -6814,6 +6883,7 @@ mod tests {
68146883
1,
68156884
None,
68166885
Some(HISTORY_SYNC_URL.to_string()),
6886+
None,
68176887
)
68186888
.await
68196889
.unwrap();
@@ -6844,6 +6914,7 @@ mod tests {
68446914
1,
68456915
None,
68466916
Some(HISTORY_SYNC_URL.to_string()),
6917+
None,
68476918
)
68486919
.await;
68496920

@@ -7345,4 +7416,83 @@ mod tests {
73457416
assert_eq!(decoded.url, original.url);
73467417
}
73477418
}
7419+
7420+
#[tokio::test]
7421+
async fn test_version_info() {
7422+
let amal_client = new_test_client_with_wallet_and_version_info(
7423+
generate_local_wallet(),
7424+
Some("2.0.0".to_string()),
7425+
)
7426+
.await;
7427+
assert_eq!(amal_client.version_info().await.unwrap(), "2.0.0");
7428+
let bola_client = new_test_client().await;
7429+
assert_eq!(bola_client.version_info().await.unwrap(), "1.0.0-rc1");
7430+
7431+
let amal_group = amal_client
7432+
.conversations()
7433+
.create_group(
7434+
vec![bola_client.account_identifier.clone()],
7435+
FfiCreateGroupOptions::default(),
7436+
)
7437+
.await
7438+
.unwrap();
7439+
let mut buf = Vec::new();
7440+
TextCodec::encode("hello".to_string())
7441+
.unwrap()
7442+
.encode(&mut buf)
7443+
.unwrap();
7444+
amal_group.send(buf).await.unwrap();
7445+
amal_group.sync().await.unwrap();
7446+
7447+
bola_client
7448+
.conversations()
7449+
.sync_all_conversations(None)
7450+
.await
7451+
.unwrap();
7452+
let bola_groups = bola_client
7453+
.conversations()
7454+
.list_groups(FfiListConversationsOptions::default())
7455+
.unwrap();
7456+
assert_eq!(bola_groups.len(), 1);
7457+
let bola_group = bola_groups[0].conversation.clone();
7458+
let messages = bola_group
7459+
.find_messages(FfiListMessagesOptions::default())
7460+
.await
7461+
.unwrap();
7462+
assert_eq!(messages.len(), 1);
7463+
let message = messages[0].clone();
7464+
let decoded_content = EncodedContent::decode(message.content.as_slice()).unwrap();
7465+
assert_eq!(TextCodec::decode(decoded_content).unwrap(), "hello");
7466+
7467+
let paused_for_version = bola_group.paused_for_version().unwrap();
7468+
assert_eq!(paused_for_version, None);
7469+
7470+
// Update group min version
7471+
amal_group
7472+
.update_group_min_version_to_match_self()
7473+
.await
7474+
.unwrap();
7475+
amal_group.sync().await.unwrap();
7476+
bola_group.sync().await.unwrap();
7477+
7478+
let paused_for_version = bola_group.paused_for_version().unwrap();
7479+
assert_eq!(paused_for_version, Some("2.0.0".to_string()));
7480+
7481+
// Bola tries to send a message
7482+
let result = bola_group.send(vec![]).await;
7483+
// This should fail with a GroupPausedUntilUpdate error
7484+
assert!(result.is_err());
7485+
7486+
// Check the specific error type and message
7487+
let error = result.unwrap_err();
7488+
match error {
7489+
GenericError::GroupError(group_error) => {
7490+
assert_eq!(
7491+
group_error.to_string(),
7492+
"Group is paused until version 2.0.0 is available"
7493+
);
7494+
}
7495+
_ => panic!("Expected GroupError but got: {:?}", error),
7496+
}
7497+
}
73487498
}

0 commit comments

Comments
 (0)