Skip to content

Commit 1b8c87a

Browse files
committedApr 3, 2024
add a test for validating performance
1 parent 6c44637 commit 1b8c87a

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
 

‎library/src/androidTest/java/org/xmtp/android/library/ConversationsTest.kt

+44
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.xmtp.android.library
22

3+
import android.util.Log
34
import androidx.test.ext.junit.runners.AndroidJUnit4
45
import kotlinx.coroutines.CoroutineScope
56
import kotlinx.coroutines.Dispatchers
@@ -21,6 +22,7 @@ import org.xmtp.android.library.messages.createDeterministic
2122
import org.xmtp.android.library.messages.getPublicKeyBundle
2223
import org.xmtp.android.library.messages.toPublicKeyBundle
2324
import org.xmtp.android.library.messages.walletAddress
25+
import org.xmtp.proto.keystore.api.v1.Keystore
2426
import java.lang.Thread.sleep
2527
import java.util.Date
2628

@@ -138,4 +140,46 @@ class ConversationsTest {
138140

139141
assertEquals(allMessages.size, 15)
140142
}
143+
144+
@Test
145+
fun testBigWallet() {
146+
val privateKeyData = listOf(0x08, 0x36, 0x20, 0x0f, 0xfa, 0xfa, 0x17, 0xa3, 0xcb, 0x8b, 0x54, 0xf2, 0x2d, 0x6a, 0xfa, 0x60, 0xb1, 0x3d, 0xa4, 0x87, 0x26, 0x54, 0x32, 0x41, 0xad, 0xc5, 0xc2, 0x50, 0xdb, 0xb0, 0xe0, 0xcd)
147+
.map { it.toByte() }
148+
.toByteArray()
149+
// Use hardcoded privateKey
150+
val privateKey = PrivateKeyBuilder.buildFromPrivateKeyData(privateKeyData)
151+
val privateKeyBuilder = PrivateKeyBuilder(privateKey)
152+
val options =
153+
ClientOptions(api = ClientOptions.Api(env = XMTPEnvironment.DEV))
154+
val client = Client().create(account = privateKeyBuilder, options = options)
155+
156+
runBlocking {
157+
val start = Date()
158+
val conversations = client.conversations.list()
159+
val end = Date()
160+
Log.d("LOPI", "Loaded ${conversations.size} conversations in ${(end.time - start.time) / 1000.0}s")
161+
162+
163+
val start2 = Date()
164+
val conversations2 = client.conversations.list()
165+
val end2 = Date()
166+
Log.d("LOPI", "Second time loaded ${conversations2.size} conversations in ${(end2.time - start2.time) / 1000.0}s")
167+
168+
val last500Topics = conversations.takeLast(2000).map { it.toTopicData().toByteString() }
169+
val client2 = Client().create(account = privateKeyBuilder, options = options)
170+
for (topic in last500Topics) {
171+
client2.conversations.importTopicData(Keystore.TopicMap.TopicData.parseFrom(topic))
172+
}
173+
174+
val start3 = Date()
175+
val conversations3 = client2.conversations.list()
176+
val end3 = Date()
177+
Log.d("LOPI", "Loaded ${conversations3.size} conversations in ${(end3.time - start3.time) / 1000.0}s")
178+
179+
val start4 = Date()
180+
val conversations4 = client2.conversations.list()
181+
val end4 = Date()
182+
Log.d("LOPI", "Second time loaded ${conversations4.size} conversations in ${(end4.time - start4.time) / 1000.0}s")
183+
}
184+
}
141185
}

0 commit comments

Comments
 (0)