Skip to content

Commit 07486c6

Browse files
committed
write a test for it
1 parent 023d150 commit 07486c6

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

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

+44
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.xmtp.android.library
22

33
import androidx.test.ext.junit.runners.AndroidJUnit4
44
import androidx.test.platform.app.InstrumentationRegistry
5+
import kotlinx.coroutines.runBlocking
56
import org.junit.Assert.assertEquals
67
import org.junit.Assert.fail
78
import org.junit.Ignore
@@ -124,6 +125,49 @@ class ClientTest {
124125
assert(client.canMessageV3(listOf(client.address)))
125126
}
126127

128+
@Test
129+
fun testCanDeleteDatabase() {
130+
val context = InstrumentationRegistry.getInstrumentation().targetContext
131+
val fakeWallet = PrivateKeyBuilder()
132+
val fakeWallet2 = PrivateKeyBuilder()
133+
var client =
134+
Client().create(
135+
account = fakeWallet,
136+
options = ClientOptions(
137+
ClientOptions.Api(XMTPEnvironment.LOCAL, false),
138+
enableAlphaMls = true,
139+
appContext = context
140+
)
141+
)
142+
val client2 =
143+
Client().create(
144+
account = fakeWallet2,
145+
options = ClientOptions(
146+
ClientOptions.Api(XMTPEnvironment.LOCAL, false),
147+
enableAlphaMls = true,
148+
appContext = context
149+
)
150+
)
151+
client.conversations.newGroup(listOf(client2.address,))
152+
runBlocking { client.conversations.syncGroups() }
153+
assertEquals(client.conversations.listGroups().size, 1)
154+
155+
client.deleteLocalDatabase()
156+
157+
client =
158+
Client().create(
159+
account = fakeWallet,
160+
options = ClientOptions(
161+
ClientOptions.Api(XMTPEnvironment.LOCAL, false),
162+
enableAlphaMls = true,
163+
appContext = context
164+
)
165+
)
166+
167+
runBlocking { client.conversations.syncGroups() }
168+
assertEquals(client.conversations.listGroups().size, 0)
169+
}
170+
127171
@Test
128172
fun testCreatesAV3DevClient() {
129173
val context = InstrumentationRegistry.getInstrumentation().targetContext

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ class Client() {
8282
lateinit var apiClient: ApiClient
8383
lateinit var contacts: Contacts
8484
lateinit var conversations: Conversations
85-
var dbPath: String = ""
8685
var logger: XMTPLogger = XMTPLogger()
8786
val libXMTPVersion: String = getVersionInfo()
8887
private var libXMTPClient: FfiXmtpClient? = null
88+
private var dbPath: String = ""
8989

9090
companion object {
9191
private const val TAG = "Client"
@@ -161,7 +161,7 @@ class Client() {
161161
privateKeyBundleV1: PrivateKeyBundleV1,
162162
apiClient: ApiClient,
163163
libXMTPClient: FfiXmtpClient? = null,
164-
dbPath: String = ""
164+
dbPath: String = "",
165165
) : this() {
166166
this.address = address
167167
this.privateKeyBundleV1 = privateKeyBundleV1
@@ -182,7 +182,7 @@ class Client() {
182182
val clientOptions = options ?: ClientOptions()
183183
val apiClient =
184184
GRPCApiClient(environment = clientOptions.api.env, secure = clientOptions.api.isSecure)
185-
val (v3Client, dbPath) = if (isAlphaMlsEnabled(options)) {
185+
val (v3Client, dbPath) = if (isAlphaMlsEnabled(options)) {
186186
runBlocking {
187187
ffiXmtpClient(
188188
options,

0 commit comments

Comments
 (0)