Skip to content

Commit

Permalink
write a test for it
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Feb 23, 2024
1 parent 023d150 commit 07486c6
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.xmtp.android.library

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
import org.junit.Assert.fail
import org.junit.Ignore
Expand Down Expand Up @@ -124,6 +125,49 @@ class ClientTest {
assert(client.canMessageV3(listOf(client.address)))
}

@Test
fun testCanDeleteDatabase() {
val context = InstrumentationRegistry.getInstrumentation().targetContext
val fakeWallet = PrivateKeyBuilder()
val fakeWallet2 = PrivateKeyBuilder()
var client =
Client().create(
account = fakeWallet,
options = ClientOptions(
ClientOptions.Api(XMTPEnvironment.LOCAL, false),
enableAlphaMls = true,
appContext = context
)
)
val client2 =
Client().create(
account = fakeWallet2,
options = ClientOptions(
ClientOptions.Api(XMTPEnvironment.LOCAL, false),
enableAlphaMls = true,
appContext = context
)
)
client.conversations.newGroup(listOf(client2.address,))
runBlocking { client.conversations.syncGroups() }
assertEquals(client.conversations.listGroups().size, 1)

client.deleteLocalDatabase()

client =
Client().create(
account = fakeWallet,
options = ClientOptions(
ClientOptions.Api(XMTPEnvironment.LOCAL, false),
enableAlphaMls = true,
appContext = context
)
)

runBlocking { client.conversations.syncGroups() }
assertEquals(client.conversations.listGroups().size, 0)
}

@Test
fun testCreatesAV3DevClient() {
val context = InstrumentationRegistry.getInstrumentation().targetContext
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 @@ -82,10 +82,10 @@ class Client() {
lateinit var apiClient: ApiClient
lateinit var contacts: Contacts
lateinit var conversations: Conversations
var dbPath: String = ""
var logger: XMTPLogger = XMTPLogger()
val libXMTPVersion: String = getVersionInfo()
private var libXMTPClient: FfiXmtpClient? = null
private var dbPath: String = ""

companion object {
private const val TAG = "Client"
Expand Down Expand Up @@ -161,7 +161,7 @@ class Client() {
privateKeyBundleV1: PrivateKeyBundleV1,
apiClient: ApiClient,
libXMTPClient: FfiXmtpClient? = null,
dbPath: String = ""
dbPath: String = "",
) : this() {
this.address = address
this.privateKeyBundleV1 = privateKeyBundleV1
Expand All @@ -182,7 +182,7 @@ class Client() {
val clientOptions = options ?: ClientOptions()
val apiClient =
GRPCApiClient(environment = clientOptions.api.env, secure = clientOptions.api.isSecure)
val (v3Client, dbPath) = if (isAlphaMlsEnabled(options)) {
val (v3Client, dbPath) = if (isAlphaMlsEnabled(options)) {
runBlocking {
ffiXmtpClient(
options,
Expand Down

0 comments on commit 07486c6

Please sign in to comment.