Skip to content

Commit 5f74e94

Browse files
committed
feat: fix up the tests
1 parent 6a011a8 commit 5f74e94

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

library/src/androidTest/java/org/xmtp/android/library/ClientTest.kt

+9-12
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,7 @@ class ClientTest {
9191
)
9292
val client =
9393
Client().create(account = fakeWallet, options = options)
94-
assertEquals(
95-
client.address.lowercase(),
96-
client.libXMTPClient?.accountAddress()?.lowercase()
97-
)
94+
assert(client.canMessageV3(listOf(client.address)))
9895

9996
val bundle = client.privateKeyBundle
10097
val clientFromV1Bundle = Client().buildFromBundle(bundle, account = fakeWallet, options = options)
@@ -103,9 +100,12 @@ class ClientTest {
103100
client.privateKeyBundleV1.identityKey,
104101
clientFromV1Bundle.privateKeyBundleV1.identityKey,
105102
)
103+
104+
assert(clientFromV1Bundle.canMessageV3(listOf(client.address)))
105+
106106
assertEquals(
107-
client.libXMTPClient?.accountAddress(),
108-
clientFromV1Bundle.libXMTPClient?.accountAddress()
107+
client.address,
108+
clientFromV1Bundle.address
109109
)
110110
}
111111

@@ -122,8 +122,7 @@ class ClientTest {
122122
appContext = context
123123
)
124124
)
125-
val v3Client = client.libXMTPClient
126-
assertEquals(client.address.lowercase(), v3Client?.accountAddress()?.lowercase())
125+
assert(client.canMessageV3(listOf(client.address)))
127126
}
128127

129128
@Test
@@ -139,16 +138,14 @@ class ClientTest {
139138
appContext = context
140139
)
141140
)
142-
val v3Client = client.libXMTPClient
143-
assertEquals(client.address.lowercase(), v3Client?.accountAddress()?.lowercase())
141+
assert(client.canMessageV3(listOf(client.address)))
144142
}
145143

146144
@Test
147145
fun testDoesNotCreateAV3Client() {
148146
val fakeWallet = PrivateKeyBuilder()
149147
val client = Client().create(account = fakeWallet)
150-
val v3Client = client.libXMTPClient
151-
assertNull(v3Client)
148+
assert(!client.canMessageV3(listOf(client.address)))
152149
}
153150

154151
@Test

library/src/androidTest/java/org/xmtp/android/library/GroupTest.kt

+8-5
Original file line numberDiff line numberDiff line change
@@ -241,22 +241,25 @@ class GroupTest {
241241
@Test
242242
fun testCanStreamGroupMessages() = kotlinx.coroutines.test.runTest {
243243
val group = boClient.conversations.newGroup(listOf(alix.walletAddress.lowercase()))
244+
alixClient.conversations.syncGroups()
245+
val alixGroup = alixClient.conversations.listGroups().first()
244246
group.streamMessages().test {
245-
group.send("hi")
247+
alixGroup.send("hi")
246248
assertEquals("hi", awaitItem().body)
247-
group.send("hi again")
249+
alixGroup.send("hi again")
248250
assertEquals("hi again", awaitItem().body)
249251
}
250252
}
251253

252254
@Test
253255
fun testCanStreamDecryptedGroupMessages() = kotlinx.coroutines.test.runTest {
254256
val group = boClient.conversations.newGroup(listOf(alix.walletAddress))
255-
257+
alixClient.conversations.syncGroups()
258+
val alixGroup = alixClient.conversations.listGroups().first()
256259
group.streamDecryptedMessages().test {
257-
group.send("hi")
260+
alixGroup.send("hi")
258261
assertEquals("hi", awaitItem().encodedContent.content.toStringUtf8())
259-
group.send("hi again")
262+
alixGroup.send("hi again")
260263
assertEquals("hi again", awaitItem().encodedContent.content.toStringUtf8())
261264
}
262265
}

library/src/main/java/org/xmtp/android/library/Client.kt

+5-4
Original file line numberDiff line numberDiff line change
@@ -578,11 +578,12 @@ class Client() {
578578
return runBlocking { query(Topic.contact(peerAddress)).envelopesList.size > 0 }
579579
}
580580

581-
fun canMessage(addresses: List<String>): Boolean {
582-
return runBlocking {
583-
libXMTPClient != null && !libXMTPClient!!.canMessage(addresses.map { it })
584-
.contains(false)
581+
fun canMessageV3(addresses: List<String>): Boolean {
582+
if (libXMTPClient == null) return false
583+
val statuses = runBlocking {
584+
libXMTPClient!!.canMessage(addresses)
585585
}
586+
return !statuses.contains(false)
586587
}
587588

588589
val privateKeyBundle: PrivateKeyBundle

library/src/main/java/org/xmtp/android/library/Conversations.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ data class Conversations(
100100
) {
101101
throw XMTPException("Recipient is sender")
102102
}
103-
if (!client.canMessage(accountAddresses)) {
103+
if (!client.canMessageV3(accountAddresses)) {
104104
throw XMTPException("Recipient not on network")
105105
}
106106

0 commit comments

Comments
 (0)