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 d75ef654b..98c287ed6 100644 --- a/library/src/androidTest/java/org/xmtp/android/library/ClientTest.kt +++ b/library/src/androidTest/java/org/xmtp/android/library/ClientTest.kt @@ -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 @@ -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 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 d621ec4b3..7b39f3a04 100644 --- a/library/src/main/java/org/xmtp/android/library/Client.kt +++ b/library/src/main/java/org/xmtp/android/library/Client.kt @@ -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" @@ -161,7 +161,7 @@ class Client() { privateKeyBundleV1: PrivateKeyBundleV1, apiClient: ApiClient, libXMTPClient: FfiXmtpClient? = null, - dbPath: String = "" + dbPath: String = "", ) : this() { this.address = address this.privateKeyBundleV1 = privateKeyBundleV1 @@ -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,