Skip to content

Commit

Permalink
improve publicCanMessage test
Browse files Browse the repository at this point in the history
  • Loading branch information
kele-leanes committed Nov 28, 2023
1 parent 8c80e3f commit 8230503
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,17 @@ class ClientTest {
assert(!cannotMessage)
}
@Test
@Ignore("CI Issues")
fun testPublicCanMessage() {
val fixtures = fixtures()
val aliceWallet = PrivateKeyBuilder()
val notOnNetwork = PrivateKeyBuilder()
val clientOptions =
ClientOptions(api = ClientOptions.Api(env = XMTPEnvironment.LOCAL, isSecure = false, appVersion = "XMTPTest/v1.0.0"))
val canMessage = Client.canMessage(fixtures.bobClient.address, clientOptions)
val cannotMessage = Client.canMessage(notOnNetwork.address, clientOptions)
val identity = PrivateKeyBuilder().getPrivateKey()
val authorized = aliceWallet.createIdentity(identity)
val authToken = authorized.createAuthToken()
val api = GRPCApiClient(environment = XMTPEnvironment.DEV, secure = false)
api.setAuthToken(authToken)

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

Please sign in to comment.