diff --git a/library/src/androidTest/java/org/xmtp/android/library/AttachmentTest.kt b/library/src/androidTest/java/org/xmtp/android/library/AttachmentTest.kt index 69db1001..a30f8d6e 100644 --- a/library/src/androidTest/java/org/xmtp/android/library/AttachmentTest.kt +++ b/library/src/androidTest/java/org/xmtp/android/library/AttachmentTest.kt @@ -25,8 +25,9 @@ class AttachmentTest { val fixtures = fixtures() val aliceClient = fixtures.aliceClient - val aliceConversation = + val aliceConversation = runBlocking { aliceClient.conversations.newConversation(fixtures.bob.walletAddress) + } runBlocking { aliceConversation.send( diff --git a/library/src/androidTest/java/org/xmtp/android/library/ClientTest.kt b/library/src/androidTest/java/org/xmtp/android/library/ClientTest.kt index 1f0086f8..ac5b9a65 100644 --- a/library/src/androidTest/java/org/xmtp/android/library/ClientTest.kt +++ b/library/src/androidTest/java/org/xmtp/android/library/ClientTest.kt @@ -26,8 +26,8 @@ class ClientTest { fun testHasPrivateKeyBundleV1() { val fakeWallet = PrivateKeyBuilder() val client = Client().create(account = fakeWallet) - assertEquals(1, client.privateKeyBundleV1?.preKeysList?.size) - val preKey = client.privateKeyBundleV1?.preKeysList?.get(0) + assertEquals(1, client.privateKeyBundleV1.preKeysList?.size) + val preKey = client.privateKeyBundleV1.preKeysList?.get(0) assert(preKey?.publicKey?.hasSignature() ?: false) } @@ -50,15 +50,15 @@ class ClientTest { val fakeWallet = PrivateKeyBuilder() val client = Client().create(account = fakeWallet) val bundle = client.privateKeyBundle - val clientFromV1Bundle = Client().buildFromBundle(bundle!!) + val clientFromV1Bundle = Client().buildFromBundle(bundle) assertEquals(client.address, clientFromV1Bundle.address) assertEquals( - client.privateKeyBundleV1?.identityKey, - clientFromV1Bundle.privateKeyBundleV1?.identityKey, + client.privateKeyBundleV1.identityKey, + clientFromV1Bundle.privateKeyBundleV1.identityKey, ) assertEquals( - client.privateKeyBundleV1?.preKeysList, - clientFromV1Bundle.privateKeyBundleV1?.preKeysList, + client.privateKeyBundleV1.preKeysList, + clientFromV1Bundle.privateKeyBundleV1.preKeysList, ) } @@ -67,15 +67,15 @@ class ClientTest { val fakeWallet = PrivateKeyBuilder() val client = Client().create(account = fakeWallet) val bundleV1 = client.v1keys - val clientFromV1Bundle = Client().buildFromV1Bundle(bundleV1!!) + val clientFromV1Bundle = Client().buildFromV1Bundle(bundleV1) assertEquals(client.address, clientFromV1Bundle.address) assertEquals( - client.privateKeyBundleV1?.identityKey, - clientFromV1Bundle.privateKeyBundleV1?.identityKey, + client.privateKeyBundleV1.identityKey, + clientFromV1Bundle.privateKeyBundleV1.identityKey, ) assertEquals( - client.privateKeyBundleV1?.preKeysList, - clientFromV1Bundle.privateKeyBundleV1?.preKeysList, + client.privateKeyBundleV1.preKeysList, + clientFromV1Bundle.privateKeyBundleV1.preKeysList, ) } @@ -93,7 +93,8 @@ class ClientTest { assert(client.canMessageV3(listOf(client.address))) val bundle = client.privateKeyBundle - val clientFromV1Bundle = Client().buildFromBundle(bundle, account = fakeWallet, options = options) + val clientFromV1Bundle = + Client().buildFromBundle(bundle, account = fakeWallet, options = options) assertEquals(client.address, clientFromV1Bundle.address) assertEquals( client.privateKeyBundleV1.identityKey, @@ -147,8 +148,10 @@ class ClientTest { appContext = context ) ) - client.conversations.newGroup(listOf(client2.address,)) - runBlocking { client.conversations.syncGroups() } + runBlocking { + client.conversations.newGroup(listOf(client2.address)) + client.conversations.syncGroups() + } assertEquals(client.conversations.listGroups().size, 1) client.deleteLocalDatabase() diff --git a/library/src/androidTest/java/org/xmtp/android/library/CodecTest.kt b/library/src/androidTest/java/org/xmtp/android/library/CodecTest.kt index a02dbbb1..5b1201a3 100644 --- a/library/src/androidTest/java/org/xmtp/android/library/CodecTest.kt +++ b/library/src/androidTest/java/org/xmtp/android/library/CodecTest.kt @@ -59,8 +59,9 @@ class CodecTest { Client.register(codec = NumberCodec()) val fixtures = fixtures() val aliceClient = fixtures.aliceClient - val aliceConversation = + val aliceConversation = runBlocking { aliceClient.conversations.newConversation(fixtures.bob.walletAddress) + } runBlocking { aliceConversation.send( content = 3.14, @@ -81,8 +82,9 @@ class CodecTest { Client.register(codec = CompositeCodec()) val fixtures = fixtures() val aliceClient = fixtures.aliceClient - val aliceConversation = + val aliceConversation = runBlocking { aliceClient.conversations.newConversation(fixtures.bob.walletAddress) + } val textContent = TextCodec().encode(content = "hiya") val source = DecodedComposite(encodedContent = textContent) runBlocking { @@ -102,8 +104,9 @@ class CodecTest { Client.register(codec = NumberCodec()) val fixtures = fixtures() val aliceClient = fixtures.aliceClient!! - val aliceConversation = + val aliceConversation = runBlocking { aliceClient.conversations.newConversation(fixtures.bob.walletAddress) + } val textContent = TextCodec().encode(content = "sup") val numberContent = NumberCodec().encode(content = 3.14) val source = DecodedComposite( @@ -131,9 +134,10 @@ class CodecTest { val codec = NumberCodec() Client.register(codec = codec) val fixtures = fixtures() - val aliceClient = fixtures.aliceClient!! - val aliceConversation = + val aliceClient = fixtures.aliceClient + val aliceConversation = runBlocking { aliceClient.conversations.newConversation(fixtures.bob.walletAddress) + } runBlocking { aliceConversation.send( content = 3.14, @@ -165,12 +169,14 @@ class CodecTest { repeat(5) { val account = PrivateKeyBuilder() val client = Client().create(account, clientOptions) - conversations.add( - alixClient.conversations.newConversation( - client.address, - context = InvitationV1ContextBuilder.buildFromConversation(conversationId = "hi") + runBlocking { + conversations.add( + alixClient.conversations.newConversation( + client.address, + context = InvitationV1ContextBuilder.buildFromConversation(conversationId = "hi") + ) ) - ) + } } val thirtyDayPeriodsSinceEpoch = Instant.now().epochSecond / 60 / 60 / 24 / 30 diff --git a/library/src/androidTest/java/org/xmtp/android/library/ContactsTest.kt b/library/src/androidTest/java/org/xmtp/android/library/ContactsTest.kt index 6cccc9b9..bb559583 100644 --- a/library/src/androidTest/java/org/xmtp/android/library/ContactsTest.kt +++ b/library/src/androidTest/java/org/xmtp/android/library/ContactsTest.kt @@ -5,6 +5,7 @@ import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith import org.xmtp.android.library.messages.walletAddress + @RunWith(AndroidJUnit4::class) class ContactsTest { diff --git a/library/src/androidTest/java/org/xmtp/android/library/ConversationTest.kt b/library/src/androidTest/java/org/xmtp/android/library/ConversationTest.kt index ce047784..daa7549f 100644 --- a/library/src/androidTest/java/org/xmtp/android/library/ConversationTest.kt +++ b/library/src/androidTest/java/org/xmtp/android/library/ConversationTest.kt @@ -4,7 +4,6 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import app.cash.turbine.test import com.google.protobuf.kotlin.toByteString import com.google.protobuf.kotlin.toByteStringUtf8 -import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.runBlocking import org.junit.Assert import org.junit.Assert.assertEquals @@ -46,7 +45,6 @@ import org.xmtp.proto.message.contents.Invitation.InvitationV1.Context import java.nio.charset.StandardCharsets import java.util.Date -@OptIn(ExperimentalCoroutinesApi::class) @RunWith(AndroidJUnit4::class) class ConversationTest { lateinit var fakeApiClient: FakeApiClient @@ -74,26 +72,10 @@ class ConversationTest { fun testDoesNotAllowConversationWithSelf() { val client = Client().create(account = aliceWallet) assertThrows("Recipient is sender", XMTPException::class.java) { - client.conversations.newConversation(alice.walletAddress) + runBlocking { client.conversations.newConversation(alice.walletAddress) } } } - @Test - fun testCanInitiateV2Conversation() { - val existingConversations = aliceClient.conversations.conversationsByTopic - assert(existingConversations.isEmpty()) - val conversation = bobClient.conversations.newConversation(alice.walletAddress) - val aliceInviteMessage = - fakeApiClient.findPublishedEnvelope(Topic.userInvite(alice.walletAddress)) - val bobInviteMessage = - fakeApiClient.findPublishedEnvelope(Topic.userInvite(bob.walletAddress)) - assert(aliceInviteMessage != null) - assert(bobInviteMessage != null) - assertEquals(conversation.peerAddress, alice.walletAddress) - val newConversations = aliceClient.conversations.list() - assertEquals("already had conversations somehow", 1, newConversations.size) - } - @Test fun testCanFindExistingV1Conversation() { val encoder = TextCodec() @@ -133,11 +115,12 @@ class ConversationTest { ), ) } - var conversation = aliceClient.conversations.newConversation(bob.walletAddress) + var conversation = + runBlocking { aliceClient.conversations.newConversation(bob.walletAddress) } assertEquals(conversation.peerAddress, bob.walletAddress) assertEquals(conversation.createdAt, someTimeAgo) val existingMessages = fakeApiClient.published.size - conversation = bobClient.conversations.newConversation(alice.walletAddress) + conversation = runBlocking { bobClient.conversations.newConversation(alice.walletAddress) } assertEquals( "published more messages when we shouldn't have", @@ -150,17 +133,21 @@ class ConversationTest { @Test fun testCanFindExistingV2Conversation() { - val existingConversation = bobClient.conversations.newConversation( - alice.walletAddress, - context = InvitationV1ContextBuilder.buildFromConversation("http://example.com/2"), - ) - var conversation: Conversation? = null - fakeApiClient.assertNoPublish { - conversation = bobClient.conversations.newConversation( + val existingConversation = runBlocking { + bobClient.conversations.newConversation( alice.walletAddress, context = InvitationV1ContextBuilder.buildFromConversation("http://example.com/2"), ) } + var conversation: Conversation? = null + fakeApiClient.assertNoPublish { + runBlocking { + conversation = bobClient.conversations.newConversation( + alice.walletAddress, + context = InvitationV1ContextBuilder.buildFromConversation("http://example.com/2"), + ) + } + } assertEquals( "made new conversation instead of using existing one", conversation!!.topic, @@ -173,8 +160,10 @@ class ConversationTest { // Overwrite contact as legacy so we can get v1 fixtures.publishLegacyContact(client = bobClient) fixtures.publishLegacyContact(client = aliceClient) - val bobConversation = bobClient.conversations.newConversation(aliceWallet.address) - val aliceConversation = aliceClient.conversations.newConversation(bobWallet.address) + val bobConversation = + runBlocking { bobClient.conversations.newConversation(aliceWallet.address) } + val aliceConversation = + runBlocking { aliceClient.conversations.newConversation(bobWallet.address) } runBlocking { bobConversation.send(content = "hey alice") } runBlocking { bobConversation.send(content = "hey alice again") } @@ -186,15 +175,19 @@ class ConversationTest { @Test fun testCanLoadV2Messages() { - val bobConversation = bobClient.conversations.newConversation( - aliceWallet.address, - InvitationV1ContextBuilder.buildFromConversation("hi"), - ) + val bobConversation = runBlocking { + bobClient.conversations.newConversation( + aliceWallet.address, + InvitationV1ContextBuilder.buildFromConversation("hi"), + ) + } - val aliceConversation = aliceClient.conversations.newConversation( - bobWallet.address, - InvitationV1ContextBuilder.buildFromConversation("hi"), - ) + val aliceConversation = runBlocking { + aliceClient.conversations.newConversation( + bobWallet.address, + InvitationV1ContextBuilder.buildFromConversation("hi"), + ) + } runBlocking { bobConversation.send(content = "hey alice") } val messages = aliceConversation.messages() assertEquals(1, messages.size) @@ -204,10 +197,12 @@ class ConversationTest { @Test fun testVerifiesV2MessageSignature() { - val aliceConversation = aliceClient.conversations.newConversation( - bobWallet.address, - context = InvitationV1ContextBuilder.buildFromConversation(conversationId = "hi"), - ) + val aliceConversation = runBlocking { + aliceClient.conversations.newConversation( + bobWallet.address, + context = InvitationV1ContextBuilder.buildFromConversation(conversationId = "hi"), + ) + } val codec = TextCodec() val originalContent = codec.encode(content = "hello") @@ -255,10 +250,12 @@ class ConversationTest { .toByteArray(), ) runBlocking { aliceClient.publish(envelopes = listOf(tamperedEnvelope)) } - val bobConversation = bobClient.conversations.newConversation( - aliceWallet.address, - InvitationV1ContextBuilder.buildFromConversation("hi"), - ) + val bobConversation = runBlocking { + bobClient.conversations.newConversation( + aliceWallet.address, + InvitationV1ContextBuilder.buildFromConversation("hi"), + ) + } assertThrows("Invalid signature", XMTPException::class.java) { bobConversation.decode(tamperedEnvelope) } @@ -270,8 +267,10 @@ class ConversationTest { fun testCanSendGzipCompressedV1Messages() { fixtures.publishLegacyContact(client = bobClient) fixtures.publishLegacyContact(client = aliceClient) - val bobConversation = bobClient.conversations.newConversation(aliceWallet.address) - val aliceConversation = aliceClient.conversations.newConversation(bobWallet.address) + val bobConversation = + runBlocking { bobClient.conversations.newConversation(aliceWallet.address) } + val aliceConversation = + runBlocking { aliceClient.conversations.newConversation(bobWallet.address) } runBlocking { bobConversation.send( text = MutableList(1000) { "A" }.toString(), @@ -287,8 +286,10 @@ class ConversationTest { fun testCanSendDeflateCompressedV1Messages() { fixtures.publishLegacyContact(client = bobClient) fixtures.publishLegacyContact(client = aliceClient) - val bobConversation = bobClient.conversations.newConversation(aliceWallet.address) - val aliceConversation = aliceClient.conversations.newConversation(bobWallet.address) + val bobConversation = + runBlocking { bobClient.conversations.newConversation(aliceWallet.address) } + val aliceConversation = + runBlocking { aliceClient.conversations.newConversation(bobWallet.address) } runBlocking { bobConversation.send( content = MutableList(1000) { "A" }.toString(), @@ -302,14 +303,18 @@ class ConversationTest { @Test fun testCanSendGzipCompressedV2Messages() { - val bobConversation = bobClient.conversations.newConversation( - aliceWallet.address, - InvitationV1ContextBuilder.buildFromConversation(conversationId = "hi"), - ) - val aliceConversation = aliceClient.conversations.newConversation( - bobWallet.address, - InvitationV1ContextBuilder.buildFromConversation(conversationId = "hi"), - ) + val bobConversation = runBlocking { + bobClient.conversations.newConversation( + aliceWallet.address, + InvitationV1ContextBuilder.buildFromConversation(conversationId = "hi"), + ) + } + val aliceConversation = runBlocking { + aliceClient.conversations.newConversation( + bobWallet.address, + InvitationV1ContextBuilder.buildFromConversation(conversationId = "hi"), + ) + } runBlocking { bobConversation.send( text = MutableList(1000) { "A" }.toString(), @@ -324,14 +329,18 @@ class ConversationTest { @Test fun testCanSendDeflateCompressedV2Messages() { - val bobConversation = bobClient.conversations.newConversation( - aliceWallet.address, - InvitationV1ContextBuilder.buildFromConversation(conversationId = "hi"), - ) - val aliceConversation = aliceClient.conversations.newConversation( - bobWallet.address, - InvitationV1ContextBuilder.buildFromConversation(conversationId = "hi"), - ) + val bobConversation = runBlocking { + bobClient.conversations.newConversation( + aliceWallet.address, + InvitationV1ContextBuilder.buildFromConversation(conversationId = "hi"), + ) + } + val aliceConversation = runBlocking { + aliceClient.conversations.newConversation( + bobWallet.address, + InvitationV1ContextBuilder.buildFromConversation(conversationId = "hi"), + ) + } runBlocking { bobConversation.send( content = MutableList(1000) { "A" }.toString(), @@ -395,10 +404,10 @@ class ConversationTest { @Test fun testCanUseCachedConversation() { - bobClient.conversations.newConversation(alice.walletAddress) + runBlocking { bobClient.conversations.newConversation(alice.walletAddress) } fakeApiClient.assertNoQuery { - bobClient.conversations.newConversation(alice.walletAddress) + runBlocking { bobClient.conversations.newConversation(alice.walletAddress) } } } @@ -408,8 +417,10 @@ class ConversationTest { // Overwrite contact as legacy so we can get v1 fixtures.publishLegacyContact(client = bobClient) fixtures.publishLegacyContact(client = aliceClient) - val bobConversation = bobClient.conversations.newConversation(alice.walletAddress) - val aliceConversation = aliceClient.conversations.newConversation(bob.walletAddress) + val bobConversation = + runBlocking { bobClient.conversations.newConversation(alice.walletAddress) } + val aliceConversation = + runBlocking { aliceClient.conversations.newConversation(bob.walletAddress) } val date = Date() date.time = date.time - 1000000 @@ -423,15 +434,18 @@ class ConversationTest { @Test fun testCanPaginateV2Messages() { - val bobConversation = bobClient.conversations.newConversation( - alice.walletAddress, - context = InvitationV1ContextBuilder.buildFromConversation("hi"), - ) - - val aliceConversation = aliceClient.conversations.newConversation( - bob.walletAddress, - context = InvitationV1ContextBuilder.buildFromConversation("hi"), - ) + val bobConversation = runBlocking { + bobClient.conversations.newConversation( + alice.walletAddress, + context = InvitationV1ContextBuilder.buildFromConversation("hi"), + ) + } + val aliceConversation = runBlocking { + aliceClient.conversations.newConversation( + bob.walletAddress, + context = InvitationV1ContextBuilder.buildFromConversation("hi"), + ) + } val date = Date() date.time = date.time - 1000000 runBlocking { bobConversation.send(text = "hey alice 1", sentAt = date) } @@ -442,7 +456,7 @@ class ConversationTest { assertEquals("hey alice 3", messages[0].body) val messages2 = aliceConversation.messages(limit = 1, after = date) assertEquals(1, messages2.size) - assertEquals("hey alice 1", messages2[0].body) + assertEquals("hey alice 3", messages2[0].body) val messagesAsc = aliceConversation.messages(direction = MessageApiOuterClass.SortDirection.SORT_DIRECTION_ASCENDING) assertEquals("hey alice 1", messagesAsc[0].body) @@ -453,9 +467,11 @@ class ConversationTest { @Test fun testListBatchMessages() { - val bobConversation = aliceClient.conversations.newConversation(bob.walletAddress) - val steveConversation = + val bobConversation = + runBlocking { aliceClient.conversations.newConversation(bob.walletAddress) } + val steveConversation = runBlocking { aliceClient.conversations.newConversation(fixtures.caro.walletAddress) + } runBlocking { bobConversation.send(text = "hey alice 1") } runBlocking { bobConversation.send(text = "hey alice 2") } @@ -477,13 +493,17 @@ class ConversationTest { @Test fun testListBatchDecryptedMessages() { - val bobConversation = aliceClient.conversations.newConversation(bob.walletAddress) - val steveConversation = + val bobConversation = + runBlocking { aliceClient.conversations.newConversation(bob.walletAddress) } + val steveConversation = runBlocking { aliceClient.conversations.newConversation(fixtures.caro.walletAddress) + } - runBlocking { bobConversation.send(text = "hey alice 1") } - runBlocking { bobConversation.send(text = "hey alice 2") } - runBlocking { steveConversation.send(text = "hey alice 3") } + runBlocking { + bobConversation.send(text = "hey alice 1") + bobConversation.send(text = "hey alice 2") + steveConversation.send(text = "hey alice 3") + } val messages = aliceClient.conversations.listBatchDecryptedMessages( listOf( Pair(steveConversation.topic, null), @@ -491,7 +511,7 @@ class ConversationTest { ), ) val isSteveOrBobConversation = { topic: String -> - (topic.equals(steveConversation.topic) || topic.equals(bobConversation.topic)) + (topic.lowercase() == steveConversation.topic.lowercase() || topic.lowercase() == bobConversation.topic.lowercase()) } assertEquals(3, messages.size) assertTrue(isSteveOrBobConversation(messages[0].topic)) @@ -501,20 +521,25 @@ class ConversationTest { @Test fun testListBatchMessagesWithPagination() { - val bobConversation = aliceClient.conversations.newConversation(bob.walletAddress) + val bobConversation = + runBlocking { aliceClient.conversations.newConversation(bob.walletAddress) } val steveConversation = - aliceClient.conversations.newConversation(fixtures.caro.walletAddress) + runBlocking { aliceClient.conversations.newConversation(fixtures.caro.walletAddress) } - runBlocking { bobConversation.send(text = "hey alice 1 bob") } - runBlocking { steveConversation.send(text = "hey alice 1 steve") } + runBlocking { + bobConversation.send(text = "hey alice 1 bob") + steveConversation.send(text = "hey alice 1 steve") + } Thread.sleep(100) val date = Date() - runBlocking { bobConversation.send(text = "hey alice 2 bob") } - runBlocking { bobConversation.send(text = "hey alice 3 bob") } - runBlocking { steveConversation.send(text = "hey alice 2 steve") } - runBlocking { steveConversation.send(text = "hey alice 3 steve") } + runBlocking { + bobConversation.send(text = "hey alice 2 bob") + bobConversation.send(text = "hey alice 3 bob") + steveConversation.send(text = "hey alice 2 steve") + steveConversation.send(text = "hey alice 3 steve") + } val messages = aliceClient.conversations.listBatchMessages( listOf( @@ -562,7 +587,6 @@ class ConversationTest { val conversation = bobClient.conversations.newConversation(alice.walletAddress) conversation.send(content = "hi") assertEquals("hi", awaitItem().messages(limit = 1).first().body) - awaitComplete() } } @@ -573,25 +597,8 @@ class ConversationTest { fixtures.publishLegacyContact(client = aliceClient) val conversation = aliceClient.conversations.newConversation(bob.walletAddress) conversation.streamMessages().test { - val encoder = TextCodec() - val encodedContent = encoder.encode(content = "hi alice") - // Stream a message - fakeApiClient.send( - envelope = EnvelopeBuilder.buildFromString( - topic = conversation.topic, - timestamp = Date(), - message = MessageBuilder.buildFromMessageV1( - v1 = MessageV1Builder.buildEncode( - sender = bobClient.privateKeyBundleV1!!, - recipient = aliceClient.privateKeyBundleV1!!.toPublicKeyBundle(), - message = encodedContent.toByteArray(), - timestamp = Date(), - ), - ).toByteArray(), - ), - ) + conversation.send("hi alice") assertEquals("hi alice", awaitItem().encodedContent.content.toStringUtf8()) - awaitComplete() } } @@ -599,26 +606,8 @@ class ConversationTest { fun testStreamingMessagesFromV2Conversations() = kotlinx.coroutines.test.runTest { val conversation = aliceClient.conversations.newConversation(bob.walletAddress) conversation.streamMessages().test { - val encoder = TextCodec() - val encodedContent = encoder.encode(content = "hi alice") - // Stream a message - fakeApiClient.send( - envelope = EnvelopeBuilder.buildFromString( - topic = conversation.topic, - timestamp = Date(), - message = MessageBuilder.buildFromMessageV2( - v2 = MessageV2Builder.buildEncode( - client = bobClient, - encodedContent, - topic = conversation.topic, - keyMaterial = conversation.keyMaterial!!, - codec = encoder, - ).messageV2, - ).toByteArray(), - ), - ) + conversation.send("hi alice") assertEquals("hi alice", awaitItem().encodedContent.content.toStringUtf8()) - awaitComplete() } } @@ -653,7 +642,8 @@ class ConversationTest { // Publish legacy contacts so we can get v1 conversations fixtures.publishLegacyContact(client = bobClient) fixtures.publishLegacyContact(client = aliceClient) - val conversation = aliceClient.conversations.newConversation(bob.walletAddress) + val conversation = + runBlocking { aliceClient.conversations.newConversation(bob.walletAddress) } assertEquals(conversation.version, Conversation.Version.V1) val preparedMessage = conversation.prepareMessage(content = "hi") val messageID = preparedMessage.messageId @@ -666,7 +656,8 @@ class ConversationTest { @Test fun testCanPrepareV2Message() { - val conversation = aliceClient.conversations.newConversation(bob.walletAddress) + val conversation = + runBlocking { aliceClient.conversations.newConversation(bob.walletAddress) } val preparedMessage = conversation.prepareMessage(content = "hi") val messageID = preparedMessage.messageId runBlocking { conversation.send(prepared = preparedMessage) } @@ -678,7 +669,8 @@ class ConversationTest { @Test fun testCanSendPreparedMessageWithoutConversation() { - val conversation = aliceClient.conversations.newConversation(bob.walletAddress) + val conversation = + runBlocking { aliceClient.conversations.newConversation(bob.walletAddress) } val preparedMessage = conversation.prepareMessage(content = "hi") val messageID = preparedMessage.messageId @@ -762,8 +754,10 @@ class ConversationTest { fun testCanSendEncodedContentV1Message() { fixtures.publishLegacyContact(client = bobClient) fixtures.publishLegacyContact(client = aliceClient) - val bobConversation = bobClient.conversations.newConversation(aliceWallet.address) - val aliceConversation = aliceClient.conversations.newConversation(bobWallet.address) + val bobConversation = + runBlocking { bobClient.conversations.newConversation(aliceWallet.address) } + val aliceConversation = + runBlocking { aliceClient.conversations.newConversation(bobWallet.address) } val encodedContent = TextCodec().encode(content = "hi") runBlocking { bobConversation.send(encodedContent = encodedContent) } val messages = aliceConversation.messages() @@ -773,7 +767,8 @@ class ConversationTest { @Test fun testCanSendEncodedContentV2Message() { - val bobConversation = bobClient.conversations.newConversation(aliceWallet.address) + val bobConversation = + runBlocking { bobClient.conversations.newConversation(aliceWallet.address) } val encodedContent = TextCodec().encode(content = "hi") runBlocking { bobConversation.send(encodedContent = encodedContent) } val messages = bobConversation.messages() @@ -783,7 +778,8 @@ class ConversationTest { @Test fun testCanHaveConsentState() { - val bobConversation = bobClient.conversations.newConversation(alice.walletAddress, null) + val bobConversation = + runBlocking { bobClient.conversations.newConversation(alice.walletAddress, null) } val isAllowed = bobConversation.consentState() == ConsentState.ALLOWED // Conversations you start should start as allowed @@ -808,7 +804,7 @@ class ConversationTest { val isBobAllowed = aliceConversation.consentState() == ConsentState.ALLOWED assertTrue(isBobAllowed) - val aliceClient2 = Client().create(aliceWallet, fakeApiClient) + val aliceClient2 = Client().create(aliceWallet) val aliceConversation2 = aliceClient2.conversations.list()[0] aliceClient2.contacts.refreshConsentList() @@ -821,7 +817,8 @@ class ConversationTest { @Test fun testCanHaveImplicitConsentOnMessageSend() { - val bobConversation = bobClient.conversations.newConversation(alice.walletAddress, null) + val bobConversation = + runBlocking { bobClient.conversations.newConversation(alice.walletAddress, null) } val isAllowed = bobConversation.consentState() == ConsentState.ALLOWED // Conversations you start should start as allowed diff --git a/library/src/androidTest/java/org/xmtp/android/library/ConversationsTest.kt b/library/src/androidTest/java/org/xmtp/android/library/ConversationsTest.kt index 9fbe4200..15e92d40 100644 --- a/library/src/androidTest/java/org/xmtp/android/library/ConversationsTest.kt +++ b/library/src/androidTest/java/org/xmtp/android/library/ConversationsTest.kt @@ -33,7 +33,7 @@ class ConversationsTest { val client = fixtures.aliceClient val created = Date() val newWallet = PrivateKeyBuilder() - val newClient = Client().create(account = newWallet, apiClient = fixtures.fakeApiClient) + val newClient = Client().create(account = newWallet) val message = MessageV1Builder.buildEncode( sender = newClient.privateKeyBundleV1, recipient = fixtures.aliceClient.v1keys.toPublicKeyBundle(), @@ -56,7 +56,7 @@ class ConversationsTest { val client = fixtures.aliceClient val created = Date() val newWallet = PrivateKeyBuilder() - val newClient = Client().create(account = newWallet, apiClient = fixtures.fakeApiClient) + val newClient = Client().create(account = newWallet) val invitation = InvitationV1.newBuilder().build().createDeterministic( sender = newClient.keys, recipient = client.keys.getPublicKeyBundle() @@ -87,7 +87,7 @@ class ConversationsTest { ClientOptions(api = ClientOptions.Api(env = XMTPEnvironment.LOCAL, isSecure = false)) val boClient = Client().create(bo, clientOptions) val alixClient = Client().create(alix, clientOptions) - val boConversation = boClient.conversations.newConversation(alixClient.address) + val boConversation = runBlocking { boClient.conversations.newConversation(alixClient.address) } // Record message stream across all conversations val allMessages = mutableListOf() @@ -109,7 +109,7 @@ class ConversationsTest { val caro = PrivateKeyBuilder() val caroClient = Client().create(caro, clientOptions) - val caroConversation = caroClient.conversations.newConversation(alixClient.address) + val caroConversation = runBlocking { caroClient.conversations.newConversation(alixClient.address) } sleep(2500) for (i in 0 until 5) { diff --git a/library/src/androidTest/java/org/xmtp/android/library/GroupMembershipChangeTest.kt b/library/src/androidTest/java/org/xmtp/android/library/GroupMembershipChangeTest.kt index 8cb1e9de..2d7048d2 100644 --- a/library/src/androidTest/java/org/xmtp/android/library/GroupMembershipChangeTest.kt +++ b/library/src/androidTest/java/org/xmtp/android/library/GroupMembershipChangeTest.kt @@ -3,6 +3,7 @@ package org.xmtp.android.library import android.content.Context import androidx.test.core.app.ApplicationProvider import androidx.test.ext.junit.runners.AndroidJUnit4 +import kotlinx.coroutines.runBlocking import org.junit.Assert.assertEquals import org.junit.Before import org.junit.Test @@ -15,7 +16,6 @@ import uniffi.xmtpv3.org.xmtp.android.library.codecs.GroupMembershipChanges @RunWith(AndroidJUnit4::class) class GroupMembershipChangeTest { - lateinit var fakeApiClient: FakeApiClient lateinit var alixWallet: PrivateKeyBuilder lateinit var boWallet: PrivateKeyBuilder lateinit var alix: PrivateKey @@ -44,7 +44,6 @@ class GroupMembershipChangeTest { caroWallet = fixtures.caroAccount caro = fixtures.caro - fakeApiClient = fixtures.fakeApiClient alixClient = fixtures.aliceClient boClient = fixtures.bobClient caroClient = fixtures.caroClient @@ -54,12 +53,14 @@ class GroupMembershipChangeTest { fun testCanAddMembers() { Client.register(codec = GroupMembershipChangeCodec()) - val group = alixClient.conversations.newGroup( - listOf( - bo.walletAddress, - caro.walletAddress + val group = runBlocking { + alixClient.conversations.newGroup( + listOf( + bo.walletAddress, + caro.walletAddress + ) ) - ) + } val messages = group.messages() assertEquals(messages.size, 1) val content: GroupMembershipChanges? = messages.first().content() @@ -74,16 +75,18 @@ class GroupMembershipChangeTest { fun testCanRemoveMembers() { Client.register(codec = GroupMembershipChangeCodec()) - val group = alixClient.conversations.newGroup( - listOf( - bo.walletAddress, - caro.walletAddress + val group = runBlocking { + alixClient.conversations.newGroup( + listOf( + bo.walletAddress, + caro.walletAddress + ) ) - ) + } val messages = group.messages() assertEquals(messages.size, 1) assertEquals(group.memberAddresses().size, 3) - group.removeMembers(listOf(caro.walletAddress)) + runBlocking { group.removeMembers(listOf(caro.walletAddress)) } val updatedMessages = group.messages() assertEquals(updatedMessages.size, 2) assertEquals(group.memberAddresses().size, 2) @@ -98,12 +101,14 @@ class GroupMembershipChangeTest { @Test fun testIfNotRegisteredReturnsFallback() { - val group = alixClient.conversations.newGroup( - listOf( - bo.walletAddress, - caro.walletAddress + val group = runBlocking { + alixClient.conversations.newGroup( + listOf( + bo.walletAddress, + caro.walletAddress + ) ) - ) + } val messages = group.messages() assertEquals(messages.size, 1) assert(messages.first().fallbackContent.isBlank()) diff --git a/library/src/androidTest/java/org/xmtp/android/library/GroupTest.kt b/library/src/androidTest/java/org/xmtp/android/library/GroupTest.kt index 670c064c..5e8cf0f9 100644 --- a/library/src/androidTest/java/org/xmtp/android/library/GroupTest.kt +++ b/library/src/androidTest/java/org/xmtp/android/library/GroupTest.kt @@ -24,7 +24,6 @@ import uniffi.xmtpv3.GroupPermissions @RunWith(AndroidJUnit4::class) class GroupTest { - private lateinit var fakeApiClient: FakeApiClient private lateinit var alixWallet: PrivateKeyBuilder private lateinit var boWallet: PrivateKeyBuilder private lateinit var alix: PrivateKey @@ -54,7 +53,6 @@ class GroupTest { caroWallet = fixtures.caroAccount caro = fixtures.caro - fakeApiClient = fixtures.fakeApiClient alixClient = fixtures.aliceClient boClient = fixtures.bobClient caroClient = fixtures.caroClient @@ -62,24 +60,30 @@ class GroupTest { @Test fun testCanCreateAGroupWithDefaultPermissions() { - val boGroup = boClient.conversations.newGroup(listOf(alix.walletAddress)) + val boGroup = runBlocking { boClient.conversations.newGroup(listOf(alix.walletAddress)) } runBlocking { alixClient.conversations.syncGroups() } val alixGroup = alixClient.conversations.listGroups().first() assert(boGroup.id.isNotEmpty()) assert(alixGroup.id.isNotEmpty()) - alixGroup.addMembers(listOf(caro.walletAddress)) - runBlocking { boGroup.sync() } + runBlocking { + alixGroup.addMembers(listOf(caro.walletAddress)) + boGroup.sync() + } assertEquals(alixGroup.memberAddresses().size, 3) assertEquals(boGroup.memberAddresses().size, 3) - alixGroup.removeMembers(listOf(caro.walletAddress)) - runBlocking { boGroup.sync() } + runBlocking { + alixGroup.removeMembers(listOf(caro.walletAddress)) + boGroup.sync() + } assertEquals(alixGroup.memberAddresses().size, 2) assertEquals(boGroup.memberAddresses().size, 2) - boGroup.addMembers(listOf(caro.walletAddress)) - runBlocking { alixGroup.sync() } + runBlocking { + boGroup.addMembers(listOf(caro.walletAddress)) + alixGroup.sync() + } assertEquals(alixGroup.memberAddresses().size, 3) assertEquals(boGroup.memberAddresses().size, 3) @@ -93,10 +97,12 @@ class GroupTest { @Test fun testCanCreateAGroupWithAdminPermissions() { - val boGroup = boClient.conversations.newGroup( - listOf(alix.walletAddress), - permissions = GroupPermissions.GROUP_CREATOR_IS_ADMIN - ) + val boGroup = runBlocking { + boClient.conversations.newGroup( + listOf(alix.walletAddress), + permissions = GroupPermissions.GROUP_CREATOR_IS_ADMIN + ) + } runBlocking { alixClient.conversations.syncGroups() } val alixGroup = alixClient.conversations.listGroups().first() assert(boGroup.id.isNotEmpty()) @@ -105,25 +111,28 @@ class GroupTest { assertEquals(boClient.contacts.consentList.groupState(boGroup.id), ConsentState.ALLOWED) assertEquals(alixClient.contacts.consentList.groupState(alixGroup.id), ConsentState.UNKNOWN) - boGroup.addMembers(listOf(caro.walletAddress)) - runBlocking { alixGroup.sync() } + runBlocking { + boGroup.addMembers(listOf(caro.walletAddress)) + alixGroup.sync() + } assertEquals(alixGroup.memberAddresses().size, 3) assertEquals(boGroup.memberAddresses().size, 3) assertThrows(XMTPException::class.java) { - alixGroup.removeMembers(listOf(caro.walletAddress)) + runBlocking { alixGroup.removeMembers(listOf(caro.walletAddress)) } } runBlocking { boGroup.sync() } assertEquals(alixGroup.memberAddresses().size, 3) assertEquals(boGroup.memberAddresses().size, 3) - - boGroup.removeMembers(listOf(caro.walletAddress)) - runBlocking { alixGroup.sync() } + runBlocking { + boGroup.removeMembers(listOf(caro.walletAddress)) + alixGroup.sync() + } assertEquals(alixGroup.memberAddresses().size, 2) assertEquals(boGroup.memberAddresses().size, 2) assertThrows(XMTPException::class.java) { - alixGroup.addMembers(listOf(caro.walletAddress)) + runBlocking { alixGroup.addMembers(listOf(caro.walletAddress)) } } runBlocking { boGroup.sync() } assertEquals(alixGroup.memberAddresses().size, 2) @@ -139,12 +148,14 @@ class GroupTest { @Test fun testCanListGroupMembers() { - val group = boClient.conversations.newGroup( - listOf( - alix.walletAddress, - caro.walletAddress + val group = runBlocking { + boClient.conversations.newGroup( + listOf( + alix.walletAddress, + caro.walletAddress + ) ) - ) + } assertEquals( group.memberAddresses().sorted(), listOf( @@ -165,8 +176,8 @@ class GroupTest { @Test fun testCanAddGroupMembers() { - val group = boClient.conversations.newGroup(listOf(alix.walletAddress)) - group.addMembers(listOf(caro.walletAddress)) + val group = runBlocking { boClient.conversations.newGroup(listOf(alix.walletAddress)) } + runBlocking { group.addMembers(listOf(caro.walletAddress)) } assertEquals( group.memberAddresses().sorted(), listOf( @@ -179,13 +190,15 @@ class GroupTest { @Test fun testCanRemoveGroupMembers() { - val group = boClient.conversations.newGroup( - listOf( - alix.walletAddress, - caro.walletAddress + val group = runBlocking { + boClient.conversations.newGroup( + listOf( + alix.walletAddress, + caro.walletAddress + ) ) - ) - group.removeMembers(listOf(caro.walletAddress)) + } + runBlocking { group.removeMembers(listOf(caro.walletAddress)) } assertEquals( group.memberAddresses().sorted(), listOf( @@ -197,15 +210,17 @@ class GroupTest { @Test fun testCanRemoveGroupMembersWhenNotCreator() { - boClient.conversations.newGroup( - listOf( - alix.walletAddress, - caro.walletAddress + runBlocking { + boClient.conversations.newGroup( + listOf( + alix.walletAddress, + caro.walletAddress + ) ) - ) + } runBlocking { alixClient.conversations.syncGroups() } val group = alixClient.conversations.listGroups().first() - group.removeMembers(listOf(caro.walletAddress)) + runBlocking { group.removeMembers(listOf(caro.walletAddress)) } assertEquals( group.memberAddresses().sorted(), listOf( @@ -217,69 +232,76 @@ class GroupTest { @Test fun testIsActiveReturnsCorrectly() { - val group = boClient.conversations.newGroup( - listOf( - alix.walletAddress, - caro.walletAddress + val group = runBlocking { + boClient.conversations.newGroup( + listOf( + alix.walletAddress, + caro.walletAddress + ) ) - ) + } runBlocking { caroClient.conversations.syncGroups() } val caroGroup = caroClient.conversations.listGroups().first() runBlocking { caroGroup.sync() } assert(caroGroup.isActive()) assert(group.isActive()) - group.removeMembers(listOf(caro.walletAddress)) - runBlocking { caroGroup.sync() } + runBlocking { + group.removeMembers(listOf(caro.walletAddress)) + caroGroup.sync() + } assert(group.isActive()) assert(!caroGroup.isActive()) } @Test fun testCanListGroups() { - boClient.conversations.newGroup(listOf(alix.walletAddress)) - boClient.conversations.newGroup(listOf(caro.walletAddress)) + runBlocking { + boClient.conversations.newGroup(listOf(alix.walletAddress)) + boClient.conversations.newGroup(listOf(caro.walletAddress)) + } val groups = boClient.conversations.listGroups() assertEquals(groups.size, 2) } @Test fun testCanListGroupsAndConversations() { - boClient.conversations.newGroup(listOf(alix.walletAddress)) - boClient.conversations.newGroup(listOf(caro.walletAddress)) - boClient.conversations.newConversation(alix.walletAddress) + runBlocking { + boClient.conversations.newGroup(listOf(alix.walletAddress)) + boClient.conversations.newGroup(listOf(caro.walletAddress)) + boClient.conversations.newConversation(alix.walletAddress) + } val convos = boClient.conversations.list(includeGroups = true) assertEquals(convos.size, 3) } @Test fun testCannotSendMessageToGroupMemberNotOnV3() { - val fakeApiClient = FakeApiClient() val chuxAccount = PrivateKeyBuilder() val chux: PrivateKey = chuxAccount.getPrivateKey() - val chuxClient: Client = Client().create(account = chuxAccount, apiClient = fakeApiClient) + Client().create(account = chuxAccount) assertThrows("Recipient not on network", XMTPException::class.java) { - boClient.conversations.newGroup(listOf(chux.walletAddress)) + runBlocking { boClient.conversations.newGroup(listOf(chux.walletAddress)) } } } @Test fun testCannotStartGroupWithSelf() { assertThrows("Recipient is sender", XMTPException::class.java) { - boClient.conversations.newGroup(listOf(bo.walletAddress)) + runBlocking { boClient.conversations.newGroup(listOf(bo.walletAddress)) } } } @Test fun testCannotStartEmptyGroupChat() { assertThrows("Cannot start an empty group chat.", XMTPException::class.java) { - boClient.conversations.newGroup(listOf()) + runBlocking { boClient.conversations.newGroup(listOf()) } } } @Test fun testGroupStartsWithAllowedState() { - val group = boClient.conversations.newGroup(listOf(alix.walletAddress)) + val group = runBlocking { boClient.conversations.newGroup(listOf(alix.walletAddress)) } runBlocking { group.send("howdy") } runBlocking { group.send("gm") } runBlocking { group.sync() } @@ -289,7 +311,7 @@ class GroupTest { @Test fun testCanSendMessageToGroup() { - val group = boClient.conversations.newGroup(listOf(alix.walletAddress)) + val group = runBlocking { boClient.conversations.newGroup(listOf(alix.walletAddress)) } runBlocking { group.send("howdy") } runBlocking { group.send("gm") } runBlocking { group.sync() } @@ -307,7 +329,7 @@ class GroupTest { fun testCanSendContentTypesToGroup() { Client.register(codec = ReactionCodec()) - val group = boClient.conversations.newGroup(listOf(alix.walletAddress)) + val group = runBlocking { boClient.conversations.newGroup(listOf(alix.walletAddress)) } runBlocking { group.send("gm") } runBlocking { group.sync() } val messageToReact = group.messages()[0] @@ -390,7 +412,6 @@ class GroupTest { } group.send("hi 1") - Thread.sleep(2000) conversation.send("hi 2") job.join() @@ -451,7 +472,6 @@ class GroupTest { } group.send("hi 1") - Thread.sleep(2000) conversation.send("hi 2") job.join() @@ -476,19 +496,21 @@ class GroupTest { caroClient.conversations.newGroup(listOf(bo.walletAddress)) assertEquals(group.id.toHex(), awaitItem().topic) val conversation = - boClient.conversations.newConversation(alix.walletAddress) + alixClient.conversations.newConversation(bo.walletAddress) assertEquals(conversation.topic, awaitItem().topic) } } @Test fun testCanAllowGroup() { - val group = boClient.conversations.newGroup( - listOf( - alix.walletAddress, - caro.walletAddress + val group = runBlocking { + boClient.conversations.newGroup( + listOf( + alix.walletAddress, + caro.walletAddress + ) ) - ) + } var result = boClient.contacts.isGroupAllowed(group.id) assert(result) @@ -501,12 +523,14 @@ class GroupTest { @Test fun testCanDenyGroup() { - val group = boClient.conversations.newGroup( - listOf( - alix.walletAddress, - caro.walletAddress + val group = runBlocking { + boClient.conversations.newGroup( + listOf( + alix.walletAddress, + caro.walletAddress + ) ) - ) + } var result = boClient.contacts.isGroupAllowed(group.id) assert(result) diff --git a/library/src/androidTest/java/org/xmtp/android/library/LocalInstrumentedTest.kt b/library/src/androidTest/java/org/xmtp/android/library/LocalInstrumentedTest.kt index 7fbb054a..3f17e93a 100644 --- a/library/src/androidTest/java/org/xmtp/android/library/LocalInstrumentedTest.kt +++ b/library/src/androidTest/java/org/xmtp/android/library/LocalInstrumentedTest.kt @@ -63,7 +63,10 @@ class LocalInstrumentedTest { val identity = PrivateKey.newBuilder().build().generate() val authorized = alice.createIdentity(identity) val authToken = authorized.createAuthToken() - val api = GRPCApiClient(environment = XMTPEnvironment.LOCAL, secure = false) + val api = GRPCApiClient( + environment = XMTPEnvironment.LOCAL, + secure = false, + ) api.setAuthToken(authToken) val encryptedBundle = authorized.toBundle.encrypted(alice) val envelope = Envelope.newBuilder().also { @@ -90,7 +93,10 @@ class LocalInstrumentedTest { val identity = PrivateKeyBuilder().getPrivateKey() val authorized = aliceWallet.createIdentity(identity) val authToken = authorized.createAuthToken() - val api = GRPCApiClient(environment = XMTPEnvironment.LOCAL, secure = false) + val api = GRPCApiClient( + environment = XMTPEnvironment.LOCAL, + secure = false, + ) api.setAuthToken(authToken) val encryptedBundle = PrivateKeyBundleBuilder.buildFromV1Key(v1 = alice).encrypted(aliceWallet) @@ -126,10 +132,12 @@ class LocalInstrumentedTest { val bobClient = Client().create(bob, clientOptions) // Publish alice's contact Client().create(account = alice, clientOptions) - val convo = bobClient.conversations.newConversation( - alice.address, - context = InvitationV1ContextBuilder.buildFromConversation("hi") - ) + val convo = runBlocking { + bobClient.conversations.newConversation( + alice.address, + context = InvitationV1ContextBuilder.buildFromConversation("hi") + ) + } // Say this message is sent in the past val date = Date() date.time = date.time - 5000 @@ -169,13 +177,15 @@ class LocalInstrumentedTest { ) // First Bob starts a conversation with Alice - val c1 = bob.conversations.newConversation( - alice.address, - context = context { - conversationId = "example.com/alice-bob-1" - metadata["title"] = "First Chat" - } - ) + val c1 = runBlocking { + bob.conversations.newConversation( + alice.address, + context = context { + conversationId = "example.com/alice-bob-1" + metadata["title"] = "First Chat" + } + ) + } runBlocking { c1.send("hello Alice!") } delayToPropagate() @@ -185,13 +195,15 @@ class LocalInstrumentedTest { assertEquals("example.com/alice-bob-1", aliceConvoList[0].conversationId) // And later when Bob starts a second conversation with Alice - val c2 = bob.conversations.newConversation( - alice.address, - context = context { - conversationId = "example.com/alice-bob-2" - metadata["title"] = "Second Chat" - } - ) + val c2 = runBlocking { + bob.conversations.newConversation( + alice.address, + context = context { + conversationId = "example.com/alice-bob-2" + metadata["title"] = "Second Chat" + } + ) + } runBlocking { c2.send("hello again Alice!") } delayToPropagate() @@ -209,13 +221,15 @@ class LocalInstrumentedTest { val bob = Client().create(PrivateKeyBuilder(), options) // Alice starts a conversation with Bob - val aliceConvo = alice.conversations.newConversation( - bob.address, - context = context { - conversationId = "example.com/alice-bob-1" - metadata["title"] = "Chatting Using Saved Credentials" - } - ) + val aliceConvo = runBlocking { + alice.conversations.newConversation( + bob.address, + context = context { + conversationId = "example.com/alice-bob-1" + metadata["title"] = "Chatting Using Saved Credentials" + } + ) + } runBlocking { aliceConvo.send("Hello Bob") } delayToPropagate() @@ -279,7 +293,8 @@ class LocalInstrumentedTest { aliceClient.conversations.streamAllMessages().mapLatest { assertEquals("hi", it.encodedContent.content.toStringUtf8()) } - val bobConversation = bobClient.conversations.newConversation(aliceClient.address) + val bobConversation = + runBlocking { bobClient.conversations.newConversation(aliceClient.address) } runBlocking { bobConversation.send(text = "hi") } } @@ -300,7 +315,8 @@ class LocalInstrumentedTest { aliceClient.conversations.streamAllMessages().mapLatest { assertEquals("hi", it.encodedContent.content.toStringUtf8()) } - val bobConversation = bobClient.conversations.newConversation(aliceClient.address) + val bobConversation = + runBlocking { bobClient.conversations.newConversation(aliceClient.address) } assertEquals(bobConversation.version, Conversation.Version.V1) runBlocking { bobConversation.send(text = "hi") } } @@ -737,7 +753,10 @@ class LocalInstrumentedTest { val identity = PrivateKey.newBuilder().build().generate() val authorized = alice.createIdentity(identity) val authToken = authorized.createAuthToken() - val api = GRPCApiClient(environment = XMTPEnvironment.LOCAL, secure = false) + val api = GRPCApiClient( + environment = XMTPEnvironment.LOCAL, + secure = false, + ) api.setAuthToken(authToken) val encryptedBundle = authorized.toBundle.encrypted(alice) val envelope = Envelope.newBuilder().also { @@ -790,14 +809,18 @@ class LocalInstrumentedTest { ClientOptions(api = ClientOptions.Api(env = XMTPEnvironment.LOCAL, isSecure = false)) val bobClient = Client().create(bob, clientOptions) val aliceClient = Client().create(account = alice, options = clientOptions) - val aliceConversation = aliceClient.conversations.newConversation( - bob.address, - context = InvitationV1ContextBuilder.buildFromConversation("https://example.com/3") - ) - val bobConversation = bobClient.conversations.newConversation( - alice.address, - context = InvitationV1ContextBuilder.buildFromConversation("https://example.com/3") - ) + val aliceConversation = runBlocking { + aliceClient.conversations.newConversation( + bob.address, + context = InvitationV1ContextBuilder.buildFromConversation("https://example.com/3") + ) + } + val bobConversation = runBlocking { + bobClient.conversations.newConversation( + alice.address, + context = InvitationV1ContextBuilder.buildFromConversation("https://example.com/3") + ) + } bobConversation.streamEphemeral().mapLatest { assertEquals("hi", it.message.toStringUtf8()) diff --git a/library/src/androidTest/java/org/xmtp/android/library/MessageTest.kt b/library/src/androidTest/java/org/xmtp/android/library/MessageTest.kt index f7154086..a164d6ce 100644 --- a/library/src/androidTest/java/org/xmtp/android/library/MessageTest.kt +++ b/library/src/androidTest/java/org/xmtp/android/library/MessageTest.kt @@ -9,7 +9,6 @@ import org.junit.Assert.assertEquals import org.junit.Ignore import org.junit.Test import org.junit.runner.RunWith -import org.web3j.crypto.Hash import org.web3j.utils.Numeric import org.xmtp.android.library.codecs.TextCodec import org.xmtp.android.library.messages.InvitationV1 @@ -256,10 +255,12 @@ class MessageTest { fun canReceiveV2MessagesFromJS() { val wallet = PrivateKeyBuilder() val client = Client().create(account = wallet) - val convo = client.conversations.newConversation( - "0xf4BF19Ed562651837bc11ff975472ABd239D35B5", - InvitationV1ContextBuilder.buildFromConversation("https://example.com/4"), - ) + val convo = runBlocking { + client.conversations.newConversation( + "0xf4BF19Ed562651837bc11ff975472ABd239D35B5", + InvitationV1ContextBuilder.buildFromConversation("https://example.com/4"), + ) + } runBlocking { convo.send(content = "hello from kotlin") } val messages = convo.messages() @@ -268,17 +269,6 @@ class MessageTest { assertEquals(convo.topic, messages[0].topic) } - @Test - fun testGetsV1ID() { - val fixtures = fixtures() - val conversation = - fixtures.aliceClient.conversations.newConversation(fixtures.bob.walletAddress) - runBlocking { conversation.send(text = "hi") } - val envelope = fixtures.fakeApiClient.published.lastOrNull()!! - val decodedMessage = conversation.decode(envelope) - assertEquals(Hash.sha256(envelope.message.toByteArray()).toHex(), decodedMessage.id) - } - @Test fun testGetsV2ID() { val envelopeMessageData = diff --git a/library/src/androidTest/java/org/xmtp/android/library/ReactionTest.kt b/library/src/androidTest/java/org/xmtp/android/library/ReactionTest.kt index 70427b5b..b27cdf0c 100644 --- a/library/src/androidTest/java/org/xmtp/android/library/ReactionTest.kt +++ b/library/src/androidTest/java/org/xmtp/android/library/ReactionTest.kt @@ -68,8 +68,9 @@ class ReactionTest { val fixtures = fixtures() val aliceClient = fixtures.aliceClient - val aliceConversation = + val aliceConversation = runBlocking { aliceClient.conversations.newConversation(fixtures.bob.walletAddress) + } runBlocking { aliceConversation.send(text = "hey alice 2 bob") } @@ -105,8 +106,9 @@ class ReactionTest { val fixtures = fixtures() val aliceClient = fixtures.aliceClient - val aliceConversation = + val aliceConversation = runBlocking { aliceClient.conversations.newConversation(fixtures.bob.walletAddress) + } runBlocking { aliceConversation.send(text = "hey alice 2 bob") } diff --git a/library/src/androidTest/java/org/xmtp/android/library/ReadReceiptTest.kt b/library/src/androidTest/java/org/xmtp/android/library/ReadReceiptTest.kt index 32cbb713..2793a8c4 100644 --- a/library/src/androidTest/java/org/xmtp/android/library/ReadReceiptTest.kt +++ b/library/src/androidTest/java/org/xmtp/android/library/ReadReceiptTest.kt @@ -19,8 +19,9 @@ class ReadReceiptTest { val fixtures = fixtures() val aliceClient = fixtures.aliceClient - val aliceConversation = + val aliceConversation = runBlocking { aliceClient.conversations.newConversation(fixtures.bob.walletAddress) + } runBlocking { aliceConversation.send(text = "hey alice 2 bob") } diff --git a/library/src/androidTest/java/org/xmtp/android/library/ReplyTest.kt b/library/src/androidTest/java/org/xmtp/android/library/ReplyTest.kt index a0e6ed78..6e0c0cfd 100644 --- a/library/src/androidTest/java/org/xmtp/android/library/ReplyTest.kt +++ b/library/src/androidTest/java/org/xmtp/android/library/ReplyTest.kt @@ -20,8 +20,9 @@ class ReplyTest { val fixtures = fixtures() val aliceClient = fixtures.aliceClient - val aliceConversation = + val aliceConversation = runBlocking { aliceClient.conversations.newConversation(fixtures.bob.walletAddress) + } runBlocking { aliceConversation.send(text = "hey alice 2 bob") } diff --git a/library/src/androidTest/java/org/xmtp/android/library/TestHelpers.kt b/library/src/androidTest/java/org/xmtp/android/library/TestHelpers.kt index db06a554..3d250ac8 100644 --- a/library/src/androidTest/java/org/xmtp/android/library/TestHelpers.kt +++ b/library/src/androidTest/java/org/xmtp/android/library/TestHelpers.kt @@ -191,17 +191,7 @@ class FakeApiClient : ApiClient { published.addAll(envelopes) return PublishResponse.newBuilder().build() } - - override suspend fun subscribe(topics: List): Flow { - val env = stream.counts().first() - - if (topics.contains(env.contentTopic)) { - return flowOf(env) - } - return flowOf() - } - - override suspend fun subscribe2(request: Flow): Flow { + override suspend fun subscribe(request: Flow): Flow { val env = stream.counts().first() if (request.first().contentTopicsList.contains(env.contentTopic)) { @@ -219,11 +209,11 @@ data class Fixtures( ) { var fakeApiClient: FakeApiClient = FakeApiClient() var alice: PrivateKey = aliceAccount.getPrivateKey() - var aliceClient: Client = Client().create(account = aliceAccount, apiClient = fakeApiClient, options = clientOptions) + var aliceClient: Client = Client().create(account = aliceAccount, options = clientOptions) var bob: PrivateKey = bobAccount.getPrivateKey() - var bobClient: Client = Client().create(account = bobAccount, apiClient = fakeApiClient, options = clientOptions) + var bobClient: Client = Client().create(account = bobAccount, options = clientOptions) var caro: PrivateKey = caroAccount.getPrivateKey() - var caroClient: Client = Client().create(account = caroAccount, apiClient = fakeApiClient, options = clientOptions) + var caroClient: Client = Client().create(account = caroAccount, options = clientOptions) constructor(clientOptions: ClientOptions?) : this( aliceAccount = PrivateKeyBuilder(), bobAccount = PrivateKeyBuilder(), diff --git a/library/src/main/java/org/xmtp/android/library/ApiClient.kt b/library/src/main/java/org/xmtp/android/library/ApiClient.kt index 19beca89..9766c574 100644 --- a/library/src/main/java/org/xmtp/android/library/ApiClient.kt +++ b/library/src/main/java/org/xmtp/android/library/ApiClient.kt @@ -34,8 +34,7 @@ interface ApiClient { suspend fun batchQuery(requests: List): BatchQueryResponse suspend fun envelopes(topic: String, pagination: Pagination? = null): List suspend fun publish(envelopes: List): PublishResponse - suspend fun subscribe(topics: List): Flow - suspend fun subscribe2(request: Flow): Flow + suspend fun subscribe(request: Flow): Flow } data class GRPCApiClient( @@ -183,19 +182,7 @@ data class GRPCApiClient( return client.publish(request, headers) } - override suspend fun subscribe(topics: List): Flow { - val request = makeSubscribeRequest(topics) - val headers = Metadata() - - headers.put(CLIENT_VERSION_HEADER_KEY, Constants.VERSION) - if (appVersion != null) { - headers.put(APP_VERSION_HEADER_KEY, appVersion) - } - - return client.subscribe(request, headers) - } - - override suspend fun subscribe2(request: Flow): Flow { + override suspend fun subscribe(request: Flow): Flow { val headers = Metadata() headers.put(CLIENT_VERSION_HEADER_KEY, Constants.VERSION) diff --git a/library/src/main/java/org/xmtp/android/library/Client.kt b/library/src/main/java/org/xmtp/android/library/Client.kt index a739f430..c9f23e43 100644 --- a/library/src/main/java/org/xmtp/android/library/Client.kt +++ b/library/src/main/java/org/xmtp/android/library/Client.kt @@ -9,10 +9,12 @@ import com.google.crypto.tink.subtle.Base64 import com.google.gson.GsonBuilder import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withContext import org.web3j.crypto.Keys import org.web3j.crypto.Keys.toChecksumAddress +import org.xmtp.android.library.GRPCApiClient.Companion.makeSubscribeRequest import org.xmtp.android.library.codecs.ContentCodec import org.xmtp.android.library.codecs.TextCodec import org.xmtp.android.library.libxmtp.XMTPLogger @@ -41,6 +43,7 @@ import org.xmtp.android.library.messages.walletAddress import org.xmtp.proto.message.api.v1.MessageApiOuterClass import org.xmtp.proto.message.api.v1.MessageApiOuterClass.BatchQueryResponse import org.xmtp.proto.message.api.v1.MessageApiOuterClass.QueryRequest +import uniffi.xmtpv3.FfiV2ApiClient import uniffi.xmtpv3.FfiXmtpClient import uniffi.xmtpv3.LegacyIdentitySource import uniffi.xmtpv3.createClient @@ -86,6 +89,7 @@ class Client() { val libXMTPVersion: String = getVersionInfo() private var libXMTPClient: FfiXmtpClient? = null private var dbPath: String = "" + private lateinit var v2RustClient: FfiV2ApiClient companion object { private const val TAG = "Client" @@ -181,7 +185,10 @@ class Client() { val address = bundle.identityKey.publicKey.recoverWalletSignerPublicKey().walletAddress val clientOptions = options ?: ClientOptions() val apiClient = - GRPCApiClient(environment = clientOptions.api.env, secure = clientOptions.api.isSecure) + GRPCApiClient( + environment = clientOptions.api.env, + secure = clientOptions.api.isSecure, + ) val (v3Client, dbPath) = if (isAlphaMlsEnabled(options)) { runBlocking { ffiXmtpClient( @@ -210,7 +217,10 @@ class Client() { ): Client { val clientOptions = options ?: ClientOptions() val apiClient = - GRPCApiClient(environment = clientOptions.api.env, secure = clientOptions.api.isSecure) + GRPCApiClient( + environment = clientOptions.api.env, + secure = clientOptions.api.isSecure, + ) return create( account = account, apiClient = apiClient, @@ -223,24 +233,32 @@ class Client() { apiClient: ApiClient, options: ClientOptions? = null, ): Client { + val clientOptions = options ?: ClientOptions() return runBlocking { try { val (privateKeyBundleV1, legacyIdentityKey) = loadOrCreateKeys( account, apiClient, - options + clientOptions ) val (libXMTPClient, dbPath) = ffiXmtpClient( options, account, - options?.appContext, + clientOptions.appContext, privateKeyBundleV1, legacyIdentityKey, account.address ) + val client = - Client(account.address, privateKeyBundleV1, apiClient, libXMTPClient, dbPath) + Client( + account.address, + privateKeyBundleV1, + apiClient, + libXMTPClient, + dbPath + ) client.ensureUserContactPublished() client } catch (e: java.lang.Exception) { @@ -264,7 +282,10 @@ class Client() { val address = v1Bundle.identityKey.publicKey.recoverWalletSignerPublicKey().walletAddress val newOptions = options ?: ClientOptions() val apiClient = - GRPCApiClient(environment = newOptions.api.env, secure = newOptions.api.isSecure) + GRPCApiClient( + environment = newOptions.api.env, + secure = newOptions.api.isSecure, + ) val (v3Client, dbPath) = if (isAlphaMlsEnabled(options)) { runBlocking { ffiXmtpClient( @@ -346,7 +367,7 @@ class Client() { createClient( logger = logger, - host = if (options.api.env == XMTPEnvironment.LOCAL) "http://${options.api.env.getValue()}:5556" else "https://${options.api.env.getValue()}:443", + host = options.api.env.getUrl(), isSecure = options.api.isSecure, db = dbPath, encryptionKey = encryptionKey, @@ -479,15 +500,10 @@ class Client() { } suspend fun subscribe(topics: List): Flow { - return apiClient.subscribe(topics = topics) + return subscribe2(flowOf(makeSubscribeRequest(topics))) } - suspend fun subscribe2(request: Flow): Flow { - return apiClient.subscribe2(request = request) - } - - suspend fun subscribeTopic(topics: List): Flow { - return subscribe(topics.map { it.description }) + return apiClient.subscribe(request = request) } fun fetchConversation(topic: String?, includeGroups: Boolean = false): Conversation? { diff --git a/library/src/main/java/org/xmtp/android/library/ConversationV1.kt b/library/src/main/java/org/xmtp/android/library/ConversationV1.kt index 99bc9403..2c680f22 100644 --- a/library/src/main/java/org/xmtp/android/library/ConversationV1.kt +++ b/library/src/main/java/org/xmtp/android/library/ConversationV1.kt @@ -8,6 +8,7 @@ import org.web3j.crypto.Hash import org.xmtp.android.library.codecs.ContentCodec import org.xmtp.android.library.codecs.EncodedContent import org.xmtp.android.library.codecs.compress +import org.xmtp.android.library.messages.DecryptedMessage import org.xmtp.android.library.messages.Envelope import org.xmtp.android.library.messages.EnvelopeBuilder import org.xmtp.android.library.messages.Message @@ -22,7 +23,6 @@ import org.xmtp.android.library.messages.sentAt import org.xmtp.android.library.messages.toPublicKeyBundle import org.xmtp.android.library.messages.walletAddress import org.xmtp.proto.message.api.v1.MessageApiOuterClass -import org.xmtp.android.library.messages.DecryptedMessage import java.util.Date data class ConversationV1( @@ -272,7 +272,7 @@ data class ConversationV1( get() = topic.description.replace("/xmtp/0/dm-", "/xmtp/0/dmE-") fun streamEphemeral(): Flow = flow { - client.subscribe(topics = listOf(ephemeralTopic)).collect { + client.subscribe(listOf(ephemeralTopic)).collect { emit(it) } } diff --git a/library/src/main/java/org/xmtp/android/library/ConversationV2.kt b/library/src/main/java/org/xmtp/android/library/ConversationV2.kt index 13a9e033..945e2cf5 100644 --- a/library/src/main/java/org/xmtp/android/library/ConversationV2.kt +++ b/library/src/main/java/org/xmtp/android/library/ConversationV2.kt @@ -9,6 +9,7 @@ import org.web3j.crypto.Hash import org.xmtp.android.library.codecs.ContentCodec import org.xmtp.android.library.codecs.EncodedContent import org.xmtp.android.library.codecs.compress +import org.xmtp.android.library.messages.DecryptedMessage import org.xmtp.android.library.messages.Envelope import org.xmtp.android.library.messages.EnvelopeBuilder import org.xmtp.android.library.messages.Message @@ -21,7 +22,6 @@ import org.xmtp.android.library.messages.getPublicKeyBundle import org.xmtp.android.library.messages.walletAddress import org.xmtp.proto.message.api.v1.MessageApiOuterClass import org.xmtp.proto.message.contents.Invitation -import org.xmtp.android.library.messages.DecryptedMessage import java.util.Date data class ConversationV2( @@ -269,7 +269,7 @@ data class ConversationV2( get() = topic.replace("/xmtp/0/m", "/xmtp/0/mE") fun streamEphemeral(): Flow = flow { - client.subscribe(topics = listOf(ephemeralTopic)).collect { + client.subscribe(listOf(ephemeralTopic)).collect { emit(it) } } diff --git a/library/src/main/java/org/xmtp/android/library/Conversations.kt b/library/src/main/java/org/xmtp/android/library/Conversations.kt index 6d1b773b..f7504966 100644 --- a/library/src/main/java/org/xmtp/android/library/Conversations.kt +++ b/library/src/main/java/org/xmtp/android/library/Conversations.kt @@ -99,7 +99,7 @@ data class Conversations( ) } - fun newGroup( + suspend fun newGroup( accountAddresses: List, permissions: GroupPermissions = GroupPermissions.EVERYONE_IS_ADMIN, ): Group { @@ -115,10 +115,9 @@ data class Conversations( throw XMTPException("Recipient not on network") } - val group = runBlocking { + val group = libXMTPConversations?.createGroup(accountAddresses, permissions = permissions) ?: throw XMTPException("Client does not support Groups") - } client.contacts.allowGroup(groupIds = listOf(group.id())) return Group(client, group) @@ -149,7 +148,7 @@ data class Conversations( * @return New [Conversation] using the address and according to that address is able to find * the topics if exists for that new conversation. */ - fun newConversation( + suspend fun newConversation( peerAddress: String, context: Invitation.InvitationV1.Context? = null, ): Conversation { @@ -484,7 +483,7 @@ data class Conversations( * @param created Specified date creation for this invitation. * @return [SealedInvitation] with the specified information. */ - fun sendInvitation( + suspend fun sendInvitation( recipient: SignedPublicKeyBundle, invitation: InvitationV1, created: Date, @@ -498,26 +497,24 @@ data class Conversations( ) val peerAddress = recipient.walletAddress - runBlocking { - client.publish( - envelopes = listOf( - EnvelopeBuilder.buildFromTopic( - topic = Topic.userInvite( - client.address, - ), - timestamp = created, - message = sealed.toByteArray(), + client.publish( + envelopes = listOf( + EnvelopeBuilder.buildFromTopic( + topic = Topic.userInvite( + client.address, ), - EnvelopeBuilder.buildFromTopic( - topic = Topic.userInvite( - peerAddress, - ), - timestamp = created, - message = sealed.toByteArray(), + timestamp = created, + message = sealed.toByteArray(), + ), + EnvelopeBuilder.buildFromTopic( + topic = Topic.userInvite( + peerAddress, ), + timestamp = created, + message = sealed.toByteArray(), ), - ) - } + ), + ) return sealed } } @@ -529,8 +526,11 @@ data class Conversations( */ fun stream(): Flow = flow { val streamedConversationTopics: MutableSet = mutableSetOf() - client.subscribeTopic( - listOf(Topic.userIntro(client.address), Topic.userInvite(client.address)), + client.subscribe( + listOf( + Topic.userIntro(client.address).description, + Topic.userInvite(client.address).description + ) ).collect { envelope -> if (envelope.contentTopic == Topic.userIntro(client.address).description) { val conversationV1 = fromIntro(envelope = envelope) diff --git a/library/src/main/java/org/xmtp/android/library/Group.kt b/library/src/main/java/org/xmtp/android/library/Group.kt index 5b1c4513..330073c9 100644 --- a/library/src/main/java/org/xmtp/android/library/Group.kt +++ b/library/src/main/java/org/xmtp/android/library/Group.kt @@ -140,17 +140,17 @@ class Group(val client: Client, private val libXMTPGroup: FfiGroup) { return metadata.creatorAccountAddress() } - fun addMembers(addresses: List) { + suspend fun addMembers(addresses: List) { try { - runBlocking { libXMTPGroup.addMembers(addresses) } + libXMTPGroup.addMembers(addresses) } catch (e: Exception) { throw XMTPException("User does not have permissions", e) } } - fun removeMembers(addresses: List) { + suspend fun removeMembers(addresses: List) { try { - runBlocking { libXMTPGroup.removeMembers(addresses) } + libXMTPGroup.removeMembers(addresses) } catch (e: Exception) { throw XMTPException("User does not have permissions", e) } diff --git a/library/src/main/java/org/xmtp/android/library/XMTPEnvironment.kt b/library/src/main/java/org/xmtp/android/library/XMTPEnvironment.kt index f5bd4da9..9a1e0855 100644 --- a/library/src/main/java/org/xmtp/android/library/XMTPEnvironment.kt +++ b/library/src/main/java/org/xmtp/android/library/XMTPEnvironment.kt @@ -26,4 +26,12 @@ enum class XMTPEnvironment(val rawValue: String) { fun getValue(): String { return if (this == LOCAL && customValue.isNotEmpty()) customValue else rawValue } + + fun getUrl(): String { + return when (this) { + DEV -> "https://${getValue()}:443" + PRODUCTION -> "https://${getValue()}:443" + LOCAL -> "http://${getValue()}:5556" + } + } } diff --git a/library/src/main/jniLibs/arm64-v8a/libuniffi_xmtpv3.so b/library/src/main/jniLibs/arm64-v8a/libuniffi_xmtpv3.so index 6b56ebc5..f4ad741b 100755 Binary files a/library/src/main/jniLibs/arm64-v8a/libuniffi_xmtpv3.so and b/library/src/main/jniLibs/arm64-v8a/libuniffi_xmtpv3.so differ diff --git a/library/src/main/jniLibs/armeabi-v7a/libuniffi_xmtpv3.so b/library/src/main/jniLibs/armeabi-v7a/libuniffi_xmtpv3.so index a5e027b8..4be31d1d 100755 Binary files a/library/src/main/jniLibs/armeabi-v7a/libuniffi_xmtpv3.so and b/library/src/main/jniLibs/armeabi-v7a/libuniffi_xmtpv3.so differ diff --git a/library/src/main/jniLibs/x86/libuniffi_xmtpv3.so b/library/src/main/jniLibs/x86/libuniffi_xmtpv3.so index ade9f141..f989d376 100755 Binary files a/library/src/main/jniLibs/x86/libuniffi_xmtpv3.so and b/library/src/main/jniLibs/x86/libuniffi_xmtpv3.so differ diff --git a/library/src/main/jniLibs/x86_64/libuniffi_xmtpv3.so b/library/src/main/jniLibs/x86_64/libuniffi_xmtpv3.so index 1b693be9..afbce8ff 100755 Binary files a/library/src/main/jniLibs/x86_64/libuniffi_xmtpv3.so and b/library/src/main/jniLibs/x86_64/libuniffi_xmtpv3.so differ diff --git a/library/src/test/java/org/xmtp/android/library/RemoteAttachmentTest.kt b/library/src/test/java/org/xmtp/android/library/RemoteAttachmentTest.kt index b038963d..303851df 100644 --- a/library/src/test/java/org/xmtp/android/library/RemoteAttachmentTest.kt +++ b/library/src/test/java/org/xmtp/android/library/RemoteAttachmentTest.kt @@ -68,8 +68,9 @@ class RemoteAttachmentTest { val fixtures = fixtures() val aliceClient = fixtures.aliceClient - val aliceConversation = + val aliceConversation = runBlocking { aliceClient.conversations.newConversation(fixtures.bob.walletAddress) + } runBlocking { aliceConversation.send( @@ -149,8 +150,9 @@ class RemoteAttachmentTest { val fixtures = fixtures() val aliceClient = fixtures.aliceClient - val aliceConversation = + val aliceConversation = runBlocking { aliceClient.conversations.newConversation(fixtures.bob.walletAddress) + } runBlocking { aliceConversation.send( diff --git a/library/src/test/java/org/xmtp/android/library/TestHelpers.kt b/library/src/test/java/org/xmtp/android/library/TestHelpers.kt index 930b14fc..329a80f6 100644 --- a/library/src/test/java/org/xmtp/android/library/TestHelpers.kt +++ b/library/src/test/java/org/xmtp/android/library/TestHelpers.kt @@ -187,16 +187,7 @@ class FakeApiClient : ApiClient { return PublishResponse.newBuilder().build() } - override suspend fun subscribe(topics: List): Flow { - val env = stream.counts().first() - - if (topics.contains(env.contentTopic)) { - return flowOf(env) - } - return flowOf() - } - - override suspend fun subscribe2(request: Flow): Flow { + override suspend fun subscribe(request: Flow): Flow { val env = stream.counts().first() if (request.first().contentTopicsList.contains(env.contentTopic)) {