@@ -7,6 +7,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
7
7
import org.junit.Assert
8
8
import org.junit.Assert.assertEquals
9
9
import org.junit.Assert.assertThrows
10
+ import org.junit.Assert.assertTrue
10
11
import org.junit.Before
11
12
import org.junit.Ignore
12
13
import org.junit.Test
@@ -180,13 +181,11 @@ class ConversationTest {
180
181
@Test
181
182
fun testCanLoadV2Messages () {
182
183
val bobConversation = bobClient.conversations.newConversation(
183
- aliceWallet.address,
184
- InvitationV1ContextBuilder .buildFromConversation(" hi" )
184
+ aliceWallet.address, InvitationV1ContextBuilder .buildFromConversation(" hi" )
185
185
)
186
186
187
187
val aliceConversation = aliceClient.conversations.newConversation(
188
- bobWallet.address,
189
- InvitationV1ContextBuilder .buildFromConversation(" hi" )
188
+ bobWallet.address, InvitationV1ContextBuilder .buildFromConversation(" hi" )
190
189
)
191
190
bobConversation.send(content = " hey alice" )
192
191
val messages = aliceConversation.messages()
@@ -214,31 +213,23 @@ class ConversationTest {
214
213
val preKey = aliceClient.keys?.preKeysList?.get(0 )
215
214
val signature = preKey?.sign(digest)
216
215
val bundle = aliceClient.privateKeyBundleV1?.toV2()?.getPublicKeyBundle()
217
- val signedContent =
218
- SignedContentBuilder .builderFromPayload(
219
- payload = originalPayload,
220
- sender = bundle,
221
- signature = signature
222
- )
216
+ val signedContent = SignedContentBuilder .builderFromPayload(
217
+ payload = originalPayload, sender = bundle, signature = signature
218
+ )
223
219
val signedBytes = signedContent.toByteArray()
224
- val ciphertext =
225
- Crypto .encrypt(
226
- aliceConversation.keyMaterial!! ,
227
- signedBytes,
228
- additionalData = headerBytes
229
- )
220
+ val ciphertext = Crypto .encrypt(
221
+ aliceConversation.keyMaterial!! , signedBytes, additionalData = headerBytes
222
+ )
230
223
val tamperedMessage =
231
224
MessageV2Builder .buildFromCipherText(headerBytes = headerBytes, ciphertext = ciphertext)
232
- val tamperedEnvelope =
233
- EnvelopeBuilder .buildFromString(
234
- topic = aliceConversation.topic,
235
- timestamp = Date (),
236
- message = MessageBuilder .buildFromMessageV2(v2 = tamperedMessage).toByteArray()
237
- )
225
+ val tamperedEnvelope = EnvelopeBuilder .buildFromString(
226
+ topic = aliceConversation.topic,
227
+ timestamp = Date (),
228
+ message = MessageBuilder .buildFromMessageV2(v2 = tamperedMessage).toByteArray()
229
+ )
238
230
aliceClient.publish(envelopes = listOf (tamperedEnvelope))
239
231
val bobConversation = bobClient.conversations.newConversation(
240
- aliceWallet.address,
241
- InvitationV1ContextBuilder .buildFromConversation(" hi" )
232
+ aliceWallet.address, InvitationV1ContextBuilder .buildFromConversation(" hi" )
242
233
)
243
234
assertThrows(" Invalid signature" , XMTPException ::class .java) {
244
235
bobConversation.decode(tamperedEnvelope)
@@ -330,11 +321,11 @@ class ConversationTest {
330
321
val invitationContext = Invitation .InvitationV1 .Context .newBuilder().also {
331
322
it.conversationId = " https://example.com/1"
332
323
}.build()
333
- val invitationv1 =
334
- InvitationV1 .newBuilder().build().createDeterministic(
335
- sender = client .keys,
336
- recipient = fakeContactClient.keys.getPublicKeyBundle(), context = invitationContext
337
- )
324
+ val invitationv1 = InvitationV1 .newBuilder().build().createDeterministic(
325
+ sender = client.keys,
326
+ recipient = fakeContactClient .keys.getPublicKeyBundle() ,
327
+ context = invitationContext
328
+ )
338
329
val senderBundle = client.privateKeyBundleV1?.toV2()
339
330
assertEquals(
340
331
senderBundle?.identityKey?.publicKey?.recoverWalletSignerPublicKey()?.walletAddress,
@@ -397,13 +388,11 @@ class ConversationTest {
397
388
@Test
398
389
fun testCanPaginateV2Messages () {
399
390
val bobConversation = bobClient.conversations.newConversation(
400
- alice.walletAddress,
401
- context = InvitationV1ContextBuilder .buildFromConversation(" hi" )
391
+ alice.walletAddress, context = InvitationV1ContextBuilder .buildFromConversation(" hi" )
402
392
)
403
393
404
394
val aliceConversation = aliceClient.conversations.newConversation(
405
- bob.walletAddress,
406
- context = InvitationV1ContextBuilder .buildFromConversation(" hi" )
395
+ bob.walletAddress, context = InvitationV1ContextBuilder .buildFromConversation(" hi" )
407
396
)
408
397
val date = Date ()
409
398
date.time = date.time - 1000000
@@ -421,18 +410,24 @@ class ConversationTest {
421
410
@Test
422
411
fun testListBatchMessages () {
423
412
val bobConversation = aliceClient.conversations.newConversation(bob.walletAddress)
424
- val steveConversation = aliceClient.conversations.newConversation(fixtures.steve.walletAddress)
413
+ val steveConversation =
414
+ aliceClient.conversations.newConversation(fixtures.steve.walletAddress)
425
415
426
416
bobConversation.send(text = " hey alice 1" )
427
417
bobConversation.send(text = " hey alice 2" )
428
418
steveConversation.send(text = " hey alice 3" )
429
419
val messages = aliceClient.conversations.listBatchMessages(
430
420
listOf (
431
- Pair (steveConversation.topic, null ),
432
- Pair (bobConversation.topic, null )
421
+ Pair (steveConversation.topic, null ), Pair (bobConversation.topic, null )
433
422
)
434
423
)
424
+ val isSteveOrBobConversation = { topic: String ->
425
+ (topic.equals(steveConversation.topic) || topic.equals(bobConversation.topic))
426
+ }
435
427
assertEquals(3 , messages.size)
428
+ assertTrue(isSteveOrBobConversation(messages[0 ].topic))
429
+ assertTrue(isSteveOrBobConversation(messages[1 ].topic))
430
+ assertTrue(isSteveOrBobConversation(messages[2 ].topic))
436
431
}
437
432
438
433
@Test
@@ -586,9 +581,7 @@ class ConversationTest {
586
581
header = Invitation .SealedInvitationHeaderV1 .newBuilder().build()
587
582
)
588
583
val envelope = EnvelopeBuilder .buildFromString(
589
- topic = topic,
590
- timestamp = Date (),
591
- message = envelopeMessage
584
+ topic = topic, timestamp = Date (), message = envelopeMessage
592
585
)
593
586
assertThrows(" pre-key not signed by identity key" , XMTPException ::class .java) {
594
587
conversation.decodeEnvelope(envelope)
@@ -627,8 +620,38 @@ class ConversationTest {
627
620
fun testFetchConversation () {
628
621
// Generated from JS script
629
622
val ints = arrayOf(
630
- 31 , 116 , 198 , 193 , 189 , 122 , 19 , 254 , 191 , 189 , 211 , 215 , 255 , 131 ,
631
- 171 , 239 , 243 , 33 , 4 , 62 , 143 , 86 , 18 , 195 , 251 , 61 , 128 , 90 , 34 , 126 , 219 , 236
623
+ 31 ,
624
+ 116 ,
625
+ 198 ,
626
+ 193 ,
627
+ 189 ,
628
+ 122 ,
629
+ 19 ,
630
+ 254 ,
631
+ 191 ,
632
+ 189 ,
633
+ 211 ,
634
+ 215 ,
635
+ 255 ,
636
+ 131 ,
637
+ 171 ,
638
+ 239 ,
639
+ 243 ,
640
+ 33 ,
641
+ 4 ,
642
+ 62 ,
643
+ 143 ,
644
+ 86 ,
645
+ 18 ,
646
+ 195 ,
647
+ 251 ,
648
+ 61 ,
649
+ 128 ,
650
+ 90 ,
651
+ 34 ,
652
+ 126 ,
653
+ 219 ,
654
+ 236
632
655
)
633
656
val bytes =
634
657
ints.foldIndexed(ByteArray (ints.size)) { i, a, v -> a.apply { set(i, v.toByte()) } }
0 commit comments