Skip to content

Commit

Permalink
Update canMessage function to work with an instance of ApiClient
Browse files Browse the repository at this point in the history
  • Loading branch information
giovasdistillery committed Nov 28, 2023
1 parent 8230503 commit d45fb24
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 12 additions & 10 deletions library/src/androidTest/java/org/xmtp/android/library/ClientTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.xmtp.android.library

import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Assert.assertEquals
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.xmtp.android.library.messages.PrivateKeyBuilder
Expand Down Expand Up @@ -37,7 +36,7 @@ class ClientTest {
val client = Client().buildFrom(v1Copy)
assertEquals(
wallet.address,
client.address
client.address,
)
}

Expand All @@ -50,11 +49,11 @@ class ClientTest {
assertEquals(client.address, clientFromV1Bundle.address)
assertEquals(
client.privateKeyBundleV1?.identityKey,
clientFromV1Bundle.privateKeyBundleV1?.identityKey
clientFromV1Bundle.privateKeyBundleV1?.identityKey,
)
assertEquals(
client.privateKeyBundleV1?.preKeysList,
clientFromV1Bundle.privateKeyBundleV1?.preKeysList
clientFromV1Bundle.privateKeyBundleV1?.preKeysList,
)
}

Expand All @@ -67,13 +66,14 @@ class ClientTest {
assertEquals(client.address, clientFromV1Bundle.address)
assertEquals(
client.privateKeyBundleV1?.identityKey,
clientFromV1Bundle.privateKeyBundleV1?.identityKey
clientFromV1Bundle.privateKeyBundleV1?.identityKey,
)
assertEquals(
client.privateKeyBundleV1?.preKeysList,
clientFromV1Bundle.privateKeyBundleV1?.preKeysList
clientFromV1Bundle.privateKeyBundleV1?.preKeysList,
)
}

@Test
fun testCanMessage() {
val fixtures = fixtures()
Expand All @@ -83,17 +83,19 @@ class ClientTest {
assert(canMessage)
assert(!cannotMessage)
}

@Test
fun testPublicCanMessage() {
val aliceWallet = PrivateKeyBuilder()
val fixtures = fixtures()
val aliceWallet = fixtures.aliceClient
val notOnNetwork = PrivateKeyBuilder()
val identity = PrivateKeyBuilder().getPrivateKey()
val authorized = aliceWallet.createIdentity(identity)
val authorized = fixtures.aliceAccount.createIdentity(identity)
val authToken = authorized.createAuthToken()
val api = GRPCApiClient(environment = XMTPEnvironment.DEV, secure = false)
val api = fixtures.aliceClient.apiClient
api.setAuthToken(authToken)

val canMessage = Client.canMessage(aliceWallet.address, apiClient = api)
val canMessage = Client.canMessage(aliceWallet.address, apiClient = api)
val cannotMessage = Client.canMessage(notOnNetwork.address, apiClient = api)
assert(canMessage)
assert(!cannotMessage)
Expand Down
2 changes: 1 addition & 1 deletion library/src/main/java/org/xmtp/android/library/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class Client() {
)
)
}
fun canMessage(peerAddress: String, options: ClientOptions? = null, apiClient: GRPCApiClient? = null): Boolean {
fun canMessage(peerAddress: String, options: ClientOptions? = null, apiClient: ApiClient? = null): Boolean {
val clientOptions = options ?: ClientOptions()
val api = apiClient ?: GRPCApiClient(environment = clientOptions.api.env, secure = clientOptions.api.isSecure)
return runBlocking { api.queryTopic(Topic.contact(peerAddress)).envelopesList.size > 0 }
Expand Down

0 comments on commit d45fb24

Please sign in to comment.