@@ -5,6 +5,7 @@ import app.cash.turbine.test
5
5
import com.google.protobuf.kotlin.toByteString
6
6
import com.google.protobuf.kotlin.toByteStringUtf8
7
7
import kotlinx.coroutines.ExperimentalCoroutinesApi
8
+ import kotlinx.coroutines.runBlocking
8
9
import org.junit.Assert
9
10
import org.junit.Assert.assertEquals
10
11
import org.junit.Assert.assertFalse
@@ -108,28 +109,30 @@ class ConversationTest {
108
109
// Overwrite contact as legacy
109
110
bobClient.publishUserContact(legacy = true )
110
111
aliceClient.publishUserContact(legacy = true )
111
- bobClient.publish(
112
- envelopes = listOf (
113
- EnvelopeBuilder .buildFromTopic(
114
- topic = Topic .userIntro(bob.walletAddress),
115
- timestamp = someTimeAgo,
116
- message = MessageBuilder .buildFromMessageV1(v1 = messageV1).toByteArray(),
117
- ),
118
- EnvelopeBuilder .buildFromTopic(
119
- topic = Topic .userIntro(alice.walletAddress),
120
- timestamp = someTimeAgo,
121
- message = MessageBuilder .buildFromMessageV1(v1 = messageV1).toByteArray(),
122
- ),
123
- EnvelopeBuilder .buildFromTopic(
124
- topic = Topic .directMessageV1(
125
- bob.walletAddress,
126
- alice.walletAddress,
112
+ runBlocking {
113
+ bobClient.publish(
114
+ envelopes = listOf (
115
+ EnvelopeBuilder .buildFromTopic(
116
+ topic = Topic .userIntro(bob.walletAddress),
117
+ timestamp = someTimeAgo,
118
+ message = MessageBuilder .buildFromMessageV1(v1 = messageV1).toByteArray(),
119
+ ),
120
+ EnvelopeBuilder .buildFromTopic(
121
+ topic = Topic .userIntro(alice.walletAddress),
122
+ timestamp = someTimeAgo,
123
+ message = MessageBuilder .buildFromMessageV1(v1 = messageV1).toByteArray(),
124
+ ),
125
+ EnvelopeBuilder .buildFromTopic(
126
+ topic = Topic .directMessageV1(
127
+ bob.walletAddress,
128
+ alice.walletAddress,
129
+ ),
130
+ timestamp = someTimeAgo,
131
+ message = MessageBuilder .buildFromMessageV1(v1 = messageV1).toByteArray(),
127
132
),
128
- timestamp = someTimeAgo,
129
- message = MessageBuilder .buildFromMessageV1(v1 = messageV1).toByteArray(),
130
133
),
131
- ),
132
- )
134
+ )
135
+ }
133
136
var conversation = aliceClient.conversations.newConversation(bob.walletAddress)
134
137
assertEquals(conversation.peerAddress, bob.walletAddress)
135
138
assertEquals(conversation.createdAt, someTimeAgo)
@@ -173,8 +176,8 @@ class ConversationTest {
173
176
val bobConversation = bobClient.conversations.newConversation(aliceWallet.address)
174
177
val aliceConversation = aliceClient.conversations.newConversation(bobWallet.address)
175
178
176
- bobConversation.send(content = " hey alice" )
177
- bobConversation.send(content = " hey alice again" )
179
+ runBlocking { bobConversation.send(content = " hey alice" ) }
180
+ runBlocking { bobConversation.send(content = " hey alice again" ) }
178
181
val messages = aliceConversation.messages()
179
182
assertEquals(2 , messages.size)
180
183
assertEquals(" hey alice" , messages[1 ].body)
@@ -192,7 +195,7 @@ class ConversationTest {
192
195
bobWallet.address,
193
196
InvitationV1ContextBuilder .buildFromConversation(" hi" ),
194
197
)
195
- bobConversation.send(content = " hey alice" )
198
+ runBlocking { bobConversation.send(content = " hey alice" ) }
196
199
val messages = aliceConversation.messages()
197
200
assertEquals(1 , messages.size)
198
201
assertEquals(" hey alice" , messages[0 ].body)
@@ -248,9 +251,10 @@ class ConversationTest {
248
251
val tamperedEnvelope = EnvelopeBuilder .buildFromString(
249
252
topic = aliceConversation.topic,
250
253
timestamp = Date (),
251
- message = MessageBuilder .buildFromMessageV2(v2 = tamperedMessage.messageV2).toByteArray(),
254
+ message = MessageBuilder .buildFromMessageV2(v2 = tamperedMessage.messageV2)
255
+ .toByteArray(),
252
256
)
253
- aliceClient.publish(envelopes = listOf (tamperedEnvelope))
257
+ runBlocking { aliceClient.publish(envelopes = listOf (tamperedEnvelope)) }
254
258
val bobConversation = bobClient.conversations.newConversation(
255
259
aliceWallet.address,
256
260
InvitationV1ContextBuilder .buildFromConversation(" hi" ),
@@ -268,10 +272,12 @@ class ConversationTest {
268
272
fixtures.publishLegacyContact(client = aliceClient)
269
273
val bobConversation = bobClient.conversations.newConversation(aliceWallet.address)
270
274
val aliceConversation = aliceClient.conversations.newConversation(bobWallet.address)
271
- bobConversation.send(
272
- text = MutableList (1000 ) { " A" }.toString(),
273
- sendOptions = SendOptions (compression = EncodedContentCompression .GZIP ),
274
- )
275
+ runBlocking {
276
+ bobConversation.send(
277
+ text = MutableList (1000 ) { " A" }.toString(),
278
+ sendOptions = SendOptions (compression = EncodedContentCompression .GZIP ),
279
+ )
280
+ }
275
281
val messages = aliceConversation.messages()
276
282
assertEquals(1 , messages.size)
277
283
assertEquals(MutableList (1000 ) { " A" }.toString(), messages[0 ].content())
@@ -283,10 +289,12 @@ class ConversationTest {
283
289
fixtures.publishLegacyContact(client = aliceClient)
284
290
val bobConversation = bobClient.conversations.newConversation(aliceWallet.address)
285
291
val aliceConversation = aliceClient.conversations.newConversation(bobWallet.address)
286
- bobConversation.send(
287
- content = MutableList (1000 ) { " A" }.toString(),
288
- options = SendOptions (compression = EncodedContentCompression .DEFLATE ),
289
- )
292
+ runBlocking {
293
+ bobConversation.send(
294
+ content = MutableList (1000 ) { " A" }.toString(),
295
+ options = SendOptions (compression = EncodedContentCompression .DEFLATE ),
296
+ )
297
+ }
290
298
val messages = aliceConversation.messages()
291
299
assertEquals(1 , messages.size)
292
300
assertEquals(MutableList (1000 ) { " A" }.toString(), messages[0 ].content())
@@ -302,10 +310,12 @@ class ConversationTest {
302
310
bobWallet.address,
303
311
InvitationV1ContextBuilder .buildFromConversation(conversationId = " hi" ),
304
312
)
305
- bobConversation.send(
306
- text = MutableList (1000 ) { " A" }.toString(),
307
- sendOptions = SendOptions (compression = EncodedContentCompression .GZIP ),
308
- )
313
+ runBlocking {
314
+ bobConversation.send(
315
+ text = MutableList (1000 ) { " A" }.toString(),
316
+ sendOptions = SendOptions (compression = EncodedContentCompression .GZIP ),
317
+ )
318
+ }
309
319
val messages = aliceConversation.messages()
310
320
assertEquals(1 , messages.size)
311
321
assertEquals(MutableList (1000 ) { " A" }.toString(), messages[0 ].body)
@@ -322,10 +332,12 @@ class ConversationTest {
322
332
bobWallet.address,
323
333
InvitationV1ContextBuilder .buildFromConversation(conversationId = " hi" ),
324
334
)
325
- bobConversation.send(
326
- content = MutableList (1000 ) { " A" }.toString(),
327
- options = SendOptions (compression = EncodedContentCompression .DEFLATE ),
328
- )
335
+ runBlocking {
336
+ bobConversation.send(
337
+ content = MutableList (1000 ) { " A" }.toString(),
338
+ options = SendOptions (compression = EncodedContentCompression .DEFLATE ),
339
+ )
340
+ }
329
341
val messages = aliceConversation.messages()
330
342
assertEquals(1 , messages.size)
331
343
assertEquals(MutableList (1000 ) { " A" }.toString(), messages[0 ].body)
@@ -369,7 +381,7 @@ class ConversationTest {
369
381
ConversationV2 .create(client = client, invitation = invitationv1, header = header)
370
382
assertEquals(fakeContactWallet.address, conversation.peerAddress)
371
383
372
- conversation.send(content = " hello world" )
384
+ runBlocking { conversation.send(content = " hello world" ) }
373
385
374
386
val conversationList = client.conversations.list()
375
387
val recipientConversation = conversationList.lastOrNull()
@@ -401,9 +413,9 @@ class ConversationTest {
401
413
402
414
val date = Date ()
403
415
date.time = date.time - 1000000
404
- bobConversation.send(text = " hey alice 1" , sentAt = date)
405
- bobConversation.send(text = " hey alice 2" )
406
- bobConversation.send(text = " hey alice 3" )
416
+ runBlocking { bobConversation.send(text = " hey alice 1" , sentAt = date) }
417
+ runBlocking { bobConversation.send(text = " hey alice 2" ) }
418
+ runBlocking { bobConversation.send(text = " hey alice 3" ) }
407
419
val messages = aliceConversation.messages(limit = 1 )
408
420
assertEquals(1 , messages.size)
409
421
assertEquals(" hey alice 3" , messages[0 ].body)
@@ -422,9 +434,9 @@ class ConversationTest {
422
434
)
423
435
val date = Date ()
424
436
date.time = date.time - 1000000
425
- bobConversation.send(text = " hey alice 1" , sentAt = date)
426
- bobConversation.send(text = " hey alice 2" )
427
- bobConversation.send(text = " hey alice 3" )
437
+ runBlocking { bobConversation.send(text = " hey alice 1" , sentAt = date) }
438
+ runBlocking { bobConversation.send(text = " hey alice 2" ) }
439
+ runBlocking { bobConversation.send(text = " hey alice 3" ) }
428
440
val messages = aliceConversation.messages(limit = 1 )
429
441
assertEquals(1 , messages.size)
430
442
assertEquals(" hey alice 3" , messages[0 ].body)
@@ -445,9 +457,9 @@ class ConversationTest {
445
457
val steveConversation =
446
458
aliceClient.conversations.newConversation(fixtures.caro.walletAddress)
447
459
448
- bobConversation.send(text = " hey alice 1" )
449
- bobConversation.send(text = " hey alice 2" )
450
- steveConversation.send(text = " hey alice 3" )
460
+ runBlocking { bobConversation.send(text = " hey alice 1" ) }
461
+ runBlocking { bobConversation.send(text = " hey alice 2" ) }
462
+ runBlocking { steveConversation.send(text = " hey alice 3" ) }
451
463
val messages = aliceClient.conversations.listBatchMessages(
452
464
listOf (
453
465
Pair (steveConversation.topic, null ),
@@ -469,9 +481,9 @@ class ConversationTest {
469
481
val steveConversation =
470
482
aliceClient.conversations.newConversation(fixtures.caro.walletAddress)
471
483
472
- bobConversation.send(text = " hey alice 1" )
473
- bobConversation.send(text = " hey alice 2" )
474
- steveConversation.send(text = " hey alice 3" )
484
+ runBlocking { bobConversation.send(text = " hey alice 1" ) }
485
+ runBlocking { bobConversation.send(text = " hey alice 2" ) }
486
+ runBlocking { steveConversation.send(text = " hey alice 3" ) }
475
487
val messages = aliceClient.conversations.listBatchDecryptedMessages(
476
488
listOf (
477
489
Pair (steveConversation.topic, null ),
@@ -493,16 +505,16 @@ class ConversationTest {
493
505
val steveConversation =
494
506
aliceClient.conversations.newConversation(fixtures.caro.walletAddress)
495
507
496
- bobConversation.send(text = " hey alice 1 bob" )
497
- steveConversation.send(text = " hey alice 1 steve" )
508
+ runBlocking { bobConversation.send(text = " hey alice 1 bob" ) }
509
+ runBlocking { steveConversation.send(text = " hey alice 1 steve" ) }
498
510
499
511
Thread .sleep(100 )
500
512
val date = Date ()
501
513
502
- bobConversation.send(text = " hey alice 2 bob" )
503
- bobConversation.send(text = " hey alice 3 bob" )
504
- steveConversation.send(text = " hey alice 2 steve" )
505
- steveConversation.send(text = " hey alice 3 steve" )
514
+ runBlocking { bobConversation.send(text = " hey alice 2 bob" ) }
515
+ runBlocking { bobConversation.send(text = " hey alice 3 bob" ) }
516
+ runBlocking { steveConversation.send(text = " hey alice 2 steve" ) }
517
+ runBlocking { steveConversation.send(text = " hey alice 3 steve" ) }
506
518
507
519
val messages = aliceClient.conversations.listBatchMessages(
508
520
listOf (
@@ -645,7 +657,7 @@ class ConversationTest {
645
657
assertEquals(conversation.version, Conversation .Version .V1 )
646
658
val preparedMessage = conversation.prepareMessage(content = " hi" )
647
659
val messageID = preparedMessage.messageId
648
- conversation.send(prepared = preparedMessage)
660
+ runBlocking { conversation.send(prepared = preparedMessage) }
649
661
val messages = conversation.messages()
650
662
val message = messages[0 ]
651
663
assertEquals(" hi" , message.body)
@@ -657,7 +669,7 @@ class ConversationTest {
657
669
val conversation = aliceClient.conversations.newConversation(bob.walletAddress)
658
670
val preparedMessage = conversation.prepareMessage(content = " hi" )
659
671
val messageID = preparedMessage.messageId
660
- conversation.send(prepared = preparedMessage)
672
+ runBlocking { conversation.send(prepared = preparedMessage) }
661
673
val messages = conversation.messages()
662
674
val message = messages[0 ]
663
675
assertEquals(" hi" , message.body)
@@ -672,7 +684,7 @@ class ConversationTest {
672
684
673
685
// This does not need the `conversation` to `.publish` the message.
674
686
// This simulates a background task publishing all pending messages upon connection.
675
- aliceClient.publish(envelopes = preparedMessage.envelopes)
687
+ runBlocking { aliceClient.publish(envelopes = preparedMessage.envelopes) }
676
688
677
689
val messages = conversation.messages()
678
690
val message = messages[0 ]
@@ -753,7 +765,7 @@ class ConversationTest {
753
765
val bobConversation = bobClient.conversations.newConversation(aliceWallet.address)
754
766
val aliceConversation = aliceClient.conversations.newConversation(bobWallet.address)
755
767
val encodedContent = TextCodec ().encode(content = " hi" )
756
- bobConversation.send(encodedContent = encodedContent)
768
+ runBlocking { bobConversation.send(encodedContent = encodedContent) }
757
769
val messages = aliceConversation.messages()
758
770
assertEquals(1 , messages.size)
759
771
assertEquals(" hi" , messages[0 ].content())
@@ -763,7 +775,7 @@ class ConversationTest {
763
775
fun testCanSendEncodedContentV2Message () {
764
776
val bobConversation = bobClient.conversations.newConversation(aliceWallet.address)
765
777
val encodedContent = TextCodec ().encode(content = " hi" )
766
- bobConversation.send(encodedContent = encodedContent)
778
+ runBlocking { bobConversation.send(encodedContent = encodedContent) }
767
779
val messages = bobConversation.messages()
768
780
assertEquals(1 , messages.size)
769
781
assertEquals(" hi" , messages[0 ].content())
@@ -821,7 +833,7 @@ class ConversationTest {
821
833
// Conversations you receive should start as unknown
822
834
assertTrue(isUnknown)
823
835
824
- aliceConversation.send(content = " hey bob" )
836
+ runBlocking { aliceConversation.send(content = " hey bob" ) }
825
837
aliceClient.contacts.refreshConsentList()
826
838
val isNowAllowed = aliceConversation.consentState() == ConsentState .ALLOWED
827
839
0 commit comments