@@ -2,10 +2,9 @@ package org.xmtp.android.library
2
2
3
3
import androidx.test.ext.junit.runners.AndroidJUnit4
4
4
import androidx.test.platform.app.InstrumentationRegistry
5
+ import kotlinx.coroutines.runBlocking
5
6
import org.junit.Assert.assertEquals
6
- import org.junit.Assert.assertNull
7
7
import org.junit.Assert.fail
8
- import org.junit.Ignore
9
8
import org.junit.Test
10
9
import org.junit.runner.RunWith
11
10
import org.xmtp.android.library.messages.PrivateKeyBuilder
@@ -27,8 +26,8 @@ class ClientTest {
27
26
fun testHasPrivateKeyBundleV1 () {
28
27
val fakeWallet = PrivateKeyBuilder ()
29
28
val client = Client ().create(account = fakeWallet)
30
- assertEquals(1 , client.privateKeyBundleV1? .preKeysList?.size)
31
- val preKey = client.privateKeyBundleV1? .preKeysList?.get(0 )
29
+ assertEquals(1 , client.privateKeyBundleV1.preKeysList?.size)
30
+ val preKey = client.privateKeyBundleV1.preKeysList?.get(0 )
32
31
assert (preKey?.publicKey?.hasSignature() ? : false )
33
32
}
34
33
@@ -51,15 +50,15 @@ class ClientTest {
51
50
val fakeWallet = PrivateKeyBuilder ()
52
51
val client = Client ().create(account = fakeWallet)
53
52
val bundle = client.privateKeyBundle
54
- val clientFromV1Bundle = Client ().buildFromBundle(bundle!! )
53
+ val clientFromV1Bundle = Client ().buildFromBundle(bundle)
55
54
assertEquals(client.address, clientFromV1Bundle.address)
56
55
assertEquals(
57
- client.privateKeyBundleV1? .identityKey,
58
- clientFromV1Bundle.privateKeyBundleV1? .identityKey,
56
+ client.privateKeyBundleV1.identityKey,
57
+ clientFromV1Bundle.privateKeyBundleV1.identityKey,
59
58
)
60
59
assertEquals(
61
- client.privateKeyBundleV1? .preKeysList,
62
- clientFromV1Bundle.privateKeyBundleV1? .preKeysList,
60
+ client.privateKeyBundleV1.preKeysList,
61
+ clientFromV1Bundle.privateKeyBundleV1.preKeysList,
63
62
)
64
63
}
65
64
@@ -68,15 +67,15 @@ class ClientTest {
68
67
val fakeWallet = PrivateKeyBuilder ()
69
68
val client = Client ().create(account = fakeWallet)
70
69
val bundleV1 = client.v1keys
71
- val clientFromV1Bundle = Client ().buildFromV1Bundle(bundleV1!! )
70
+ val clientFromV1Bundle = Client ().buildFromV1Bundle(bundleV1)
72
71
assertEquals(client.address, clientFromV1Bundle.address)
73
72
assertEquals(
74
- client.privateKeyBundleV1? .identityKey,
75
- clientFromV1Bundle.privateKeyBundleV1? .identityKey,
73
+ client.privateKeyBundleV1.identityKey,
74
+ clientFromV1Bundle.privateKeyBundleV1.identityKey,
76
75
)
77
76
assertEquals(
78
- client.privateKeyBundleV1? .preKeysList,
79
- clientFromV1Bundle.privateKeyBundleV1? .preKeysList,
77
+ client.privateKeyBundleV1.preKeysList,
78
+ clientFromV1Bundle.privateKeyBundleV1.preKeysList,
80
79
)
81
80
}
82
81
@@ -91,21 +90,22 @@ class ClientTest {
91
90
)
92
91
val client =
93
92
Client ().create(account = fakeWallet, options = options)
94
- assertEquals(
95
- client.address.lowercase(),
96
- client.libXMTPClient?.accountAddress()?.lowercase()
97
- )
93
+ assert (client.canMessageV3(listOf (client.address)))
98
94
99
95
val bundle = client.privateKeyBundle
100
- val clientFromV1Bundle = Client ().buildFromBundle(bundle, account = fakeWallet, options = options)
96
+ val clientFromV1Bundle =
97
+ Client ().buildFromBundle(bundle, account = fakeWallet, options = options)
101
98
assertEquals(client.address, clientFromV1Bundle.address)
102
99
assertEquals(
103
100
client.privateKeyBundleV1.identityKey,
104
101
clientFromV1Bundle.privateKeyBundleV1.identityKey,
105
102
)
103
+
104
+ assert (clientFromV1Bundle.canMessageV3(listOf (client.address)))
105
+
106
106
assertEquals(
107
- client.libXMTPClient?.accountAddress() ,
108
- clientFromV1Bundle.libXMTPClient?.accountAddress()
107
+ client.address ,
108
+ clientFromV1Bundle.address
109
109
)
110
110
}
111
111
@@ -122,16 +122,78 @@ class ClientTest {
122
122
appContext = context
123
123
)
124
124
)
125
- val v3Client = client.libXMTPClient
126
- assertEquals(client.address.lowercase(), v3Client?.accountAddress()?.lowercase())
125
+ assert (client.canMessageV3(listOf (client.address)))
126
+ }
127
+
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
+
152
+ runBlocking {
153
+ client.conversations.newGroup(listOf (client2.address))
154
+ client.conversations.syncGroups()
155
+ assertEquals(client.conversations.listGroups().size, 1 )
156
+ }
157
+
158
+ client.deleteLocalDatabase()
159
+
160
+ client =
161
+ Client ().create(
162
+ account = fakeWallet,
163
+ options = ClientOptions (
164
+ ClientOptions .Api (XMTPEnvironment .LOCAL , false ),
165
+ enableAlphaMls = true ,
166
+ appContext = context
167
+ )
168
+ )
169
+
170
+ runBlocking {
171
+ client.conversations.syncGroups()
172
+ assertEquals(client.conversations.listGroups().size, 0 )
173
+ }
174
+ }
175
+
176
+ @Test
177
+ fun testCreatesAV3DevClient () {
178
+ val context = InstrumentationRegistry .getInstrumentation().targetContext
179
+ val fakeWallet = PrivateKeyBuilder ()
180
+ val client =
181
+ Client ().create(
182
+ account = fakeWallet,
183
+ options = ClientOptions (
184
+ ClientOptions .Api (XMTPEnvironment .DEV , true ),
185
+ enableAlphaMls = true ,
186
+ appContext = context
187
+ )
188
+ )
189
+ assert (client.canMessageV3(listOf (client.address)))
127
190
}
128
191
129
192
@Test
130
193
fun testDoesNotCreateAV3Client () {
131
194
val fakeWallet = PrivateKeyBuilder ()
132
195
val client = Client ().create(account = fakeWallet)
133
- val v3Client = client.libXMTPClient
134
- assertNull(v3Client)
196
+ assert (! client.canMessageV3(listOf (client.address)))
135
197
}
136
198
137
199
@Test
@@ -145,13 +207,12 @@ class ClientTest {
145
207
}
146
208
147
209
@Test
148
- @Ignore(" CI Issues" )
149
210
fun testPublicCanMessage () {
150
211
val aliceWallet = PrivateKeyBuilder ()
151
212
val notOnNetwork = PrivateKeyBuilder ()
152
213
val opts = ClientOptions (ClientOptions .Api (XMTPEnvironment .LOCAL , false ))
153
214
val aliceClient = Client ().create(aliceWallet, opts)
154
- aliceClient.ensureUserContactPublished()
215
+ runBlocking { aliceClient.ensureUserContactPublished() }
155
216
156
217
val canMessage = Client .canMessage(aliceWallet.address, opts)
157
218
val cannotMessage = Client .canMessage(notOnNetwork.address, opts)
@@ -161,7 +222,6 @@ class ClientTest {
161
222
}
162
223
163
224
@Test
164
- @Ignore(" CI Issues" )
165
225
fun testPreEnableIdentityCallback () {
166
226
val fakeWallet = PrivateKeyBuilder ()
167
227
val expectation = CompletableFuture <Unit >()
@@ -184,7 +244,6 @@ class ClientTest {
184
244
}
185
245
186
246
@Test
187
- @Ignore(" CI Issues" )
188
247
fun testPreCreateIdentityCallback () {
189
248
val fakeWallet = PrivateKeyBuilder ()
190
249
val expectation = CompletableFuture <Unit >()
0 commit comments