Skip to content

Commit 005741a

Browse files
committed
fix up the linter and some more tests
1 parent 9fe6b87 commit 005741a

File tree

8 files changed

+873
-867
lines changed

8 files changed

+873
-867
lines changed

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

+13
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ class ContactsTest {
2626
assertEquals(contactBundle?.walletAddress, fixtures.bob.walletAddress)
2727
}
2828

29+
@Test
30+
fun testCachesContacts() {
31+
val fixtures = fixtures()
32+
fixtures.bobClient.ensureUserContactPublished()
33+
// Look up the first time
34+
fixtures.aliceClient.contacts.find(fixtures.bob.walletAddress)
35+
fixtures.fakeApiClient.assertNoQuery {
36+
val contactBundle = fixtures.aliceClient.contacts.find(fixtures.bob.walletAddress)
37+
assertEquals(contactBundle?.walletAddress, fixtures.bob.walletAddress)
38+
}
39+
assert(fixtures.aliceClient.contacts.has(fixtures.bob.walletAddress))
40+
}
41+
2942
@Test
3043
fun testAllowAddress() {
3144
val fixtures = fixtures()

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

+837-845
Large diffs are not rendered by default.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import org.junit.Assert.assertEquals
99
import org.junit.Ignore
1010
import org.junit.Test
1111
import org.junit.runner.RunWith
12-
import org.web3j.crypto.Hash
1312
import org.web3j.utils.Numeric
1413
import org.xmtp.android.library.codecs.TextCodec
1514
import org.xmtp.android.library.messages.InvitationV1
@@ -269,6 +268,7 @@ class MessageTest {
269268
assertEquals("hello from kotlin", messages[0].body)
270269
assertEquals(convo.topic, messages[0].topic)
271270
}
271+
272272
@Test
273273
fun testGetsV2ID() {
274274
val envelopeMessageData =

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

+21-17
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import kotlinx.coroutines.flow.MutableSharedFlow
55
import kotlinx.coroutines.flow.first
66
import kotlinx.coroutines.flow.flowOf
77
import kotlinx.coroutines.runBlocking
8-
import org.junit.Assert
8+
import org.junit.Assert.assertEquals
99
import org.xmtp.android.library.codecs.Fetcher
1010
import org.xmtp.android.library.messages.ContactBundle
1111
import org.xmtp.android.library.messages.Envelope
@@ -44,11 +44,13 @@ class FakeWallet : SigningKey {
4444
}
4545

4646
override suspend fun sign(data: ByteArray): Signature {
47-
return privateKeyBuilder.sign(data)
47+
val signature = privateKeyBuilder.sign(data)
48+
return signature
4849
}
4950

5051
override suspend fun sign(message: String): Signature {
51-
return privateKeyBuilder.sign(message)
52+
val signature = privateKeyBuilder.sign(message)
53+
return signature
5254
}
5355

5456
override val address: String
@@ -66,13 +68,13 @@ class FakeApiClient : ApiClient {
6668
private var authToken: String? = null
6769
private val responses: MutableMap<String, List<Envelope>> = mutableMapOf()
6870
val published: MutableList<Envelope> = mutableListOf()
69-
private var forbiddingQueries = false
71+
var forbiddingQueries = false
7072
private var stream = FakeStreamHolder()
7173

7274
fun assertNoPublish(callback: () -> Unit) {
7375
val oldCount = published.size
7476
callback()
75-
Assert.assertEquals(oldCount, published.size)
77+
assertEquals(oldCount, published.size)
7678
}
7779

7880
fun assertNoQuery(callback: () -> Unit) {
@@ -104,14 +106,6 @@ class FakeApiClient : ApiClient {
104106
return query(topic = topic.description, pagination)
105107
}
106108

107-
override suspend fun batchQuery(requests: List<MessageApiOuterClass.QueryRequest>): MessageApiOuterClass.BatchQueryResponse {
108-
val response = query(requests.first().getContentTopics(0))
109-
110-
return MessageApiOuterClass.BatchQueryResponse.newBuilder().also {
111-
it.addResponses(response)
112-
}.build()
113-
}
114-
115109
suspend fun send(envelope: Envelope) {
116110
stream.emit(envelope)
117111
}
@@ -123,6 +117,16 @@ class FakeApiClient : ApiClient {
123117
return query(topic = topic, pagination = pagination).envelopesList
124118
}
125119

120+
override suspend fun batchQuery(requests: List<MessageApiOuterClass.QueryRequest>): MessageApiOuterClass.BatchQueryResponse {
121+
val responses = requests.map {
122+
query(it.getContentTopics(0), Pagination(after = Date(it.startTimeNs)))
123+
}
124+
125+
return MessageApiOuterClass.BatchQueryResponse.newBuilder().also {
126+
it.addAllResponses(responses)
127+
}.build()
128+
}
129+
126130
override suspend fun query(
127131
topic: String,
128132
pagination: Pagination?,
@@ -141,12 +145,14 @@ class FakeApiClient : ApiClient {
141145

142146
val startAt = pagination?.before
143147
if (startAt != null) {
144-
result = result.filter { it.timestampNs < startAt.time * 1_000_000 }
148+
result = result.filter { it.timestampNs < startAt.time }
145149
.sortedBy { it.timestampNs }.toMutableList()
146150
}
147151
val endAt = pagination?.after
148152
if (endAt != null) {
149-
result = result.filter { it.timestampNs > endAt.time * 1_000_000 }
153+
result = result.filter {
154+
it.timestampNs > endAt.time
155+
}
150156
.sortedBy { it.timestampNs }.toMutableList()
151157
}
152158
val limit = pagination?.limit
@@ -169,7 +175,6 @@ class FakeApiClient : ApiClient {
169175
MessageApiOuterClass.SortDirection.SORT_DIRECTION_ASCENDING -> {
170176
result = result.reversed().toMutableList()
171177
}
172-
173178
else -> Unit
174179
}
175180
}
@@ -186,7 +191,6 @@ class FakeApiClient : ApiClient {
186191
published.addAll(envelopes)
187192
return PublishResponse.newBuilder().build()
188193
}
189-
190194
override suspend fun subscribe2(request: Flow<MessageApiOuterClass.SubscribeRequest>): Flow<MessageApiOuterClass.Envelope> {
191195
val env = stream.counts().first()
192196

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

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import org.xmtp.proto.message.api.v1.MessageApiOuterClass.PublishResponse
1818
import org.xmtp.proto.message.api.v1.MessageApiOuterClass.QueryRequest
1919
import org.xmtp.proto.message.api.v1.MessageApiOuterClass.QueryResponse
2020
import org.xmtp.proto.message.api.v1.MessageApiOuterClass.SubscribeRequest
21-
import uniffi.xmtpv3.FfiV2ApiClient
2221
import java.io.Closeable
2322
import java.util.concurrent.TimeUnit
2423

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

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import uniffi.xmtpv3.FfiV2ApiClient
4545
import uniffi.xmtpv3.FfiXmtpClient
4646
import uniffi.xmtpv3.LegacyIdentitySource
4747
import uniffi.xmtpv3.createClient
48-
import uniffi.xmtpv3.createV2Client
4948
import uniffi.xmtpv3.getVersionInfo
5049
import java.io.File
5150
import java.nio.charset.StandardCharsets

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

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import kotlinx.coroutines.CancellationException
77
import kotlinx.coroutines.channels.awaitClose
88
import kotlinx.coroutines.flow.Flow
99
import kotlinx.coroutines.flow.MutableStateFlow
10-
import kotlinx.coroutines.flow.StateFlow
1110
import kotlinx.coroutines.flow.callbackFlow
1211
import kotlinx.coroutines.flow.flow
1312
import kotlinx.coroutines.flow.merge

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ enum class XMTPEnvironment(val rawValue: String) {
2828
}
2929

3030
fun getUrl(): String {
31-
return when(this) {
31+
return when (this) {
3232
DEV -> "https://${getValue()}:443"
3333
PRODUCTION -> "https://${getValue()}:443"
3434
LOCAL -> "http://${getValue()}:5556"

0 commit comments

Comments
 (0)