From 3d38525680093385cbbaff72fa8c271db02626dc Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Fri, 19 May 2023 13:55:48 -0700 Subject: [PATCH] bench marking --- .../modules/xmtpreactnativesdk/XMTPModule.kt | 16 ++++++++++++---- example/src/ConversationListView.tsx | 9 +++++++++ ios/XMTPModule.swift | 8 ++++++-- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt index 0e39441d9..acb0b2ff4 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt @@ -124,10 +124,18 @@ class XMTPModule : Module() { // Generate a random wallet and set the client to that AsyncFunction("createRandom") { environment: String -> logV("createRandom") - val privateKey = PrivateKeyBuilder() - val options = - ClientOptions(api = apiEnvironments[environment] ?: apiEnvironments["dev"]!!) - val randomClient = Client().create(account = privateKey, options = options) + // Build from [8,54,32,15,250,250,23,163,203,139,84,242,45,106,250,96,177,61,164,135,38,84,50,65,173,197,194,80,219,176,224,205] + // or in hex 0836200ffafa17a3cb8b54f22d6afa60b13da48726543241adc5c250dbb0e0cd + // aka 2k many convos test wallet + // Create a ByteArray with the 32 bytes above + 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) + .map { it.toByte() } + .toByteArray() + // Use hardcoded privateKey + val privateKey = PrivateKeyBuilder.buildFromPrivateKeyData(privateKeyData) + val privateKeyBuilder = PrivateKeyBuilder(privateKey) + val options = ClientOptions(api = apiEnvironments[environment] ?: apiEnvironments["dev"]!!) + val randomClient = Client().create(account = privateKeyBuilder, options = options) clients[randomClient.address] = randomClient randomClient.address } diff --git a/example/src/ConversationListView.tsx b/example/src/ConversationListView.tsx index 51da1e031..e30d3aa16 100644 --- a/example/src/ConversationListView.tsx +++ b/example/src/ConversationListView.tsx @@ -18,11 +18,20 @@ export default function ConversationListView({ const [messageCount, setMessageCount] = useState(0); async function refreshConversations() { + // Write code to time this function and divide by number of conversations + // to get an idea of how long it takes to load a conversation. + let start = Date.now(); const conversations = await client.conversations.list(); + let end = Date.now(); + console.log( + `Loaded ${conversations.length} conversations in ${end - start}ms` + ); + const allMessages = await client.listBatchMessages( conversations.map((conversation) => conversation.topic), conversations.map((conversation) => conversation.conversationID) ); + setConversations(conversations); setMessageCount(allMessages.length); } diff --git a/ios/XMTPModule.swift b/ios/XMTPModule.swift index 2f422cb63..941d2a48a 100644 --- a/ios/XMTPModule.swift +++ b/ios/XMTPModule.swift @@ -124,8 +124,12 @@ public class XMTPModule: Module { // Generate a random wallet and set the client to that AsyncFunction("createRandom") { (environment: String) -> String in - let privateKey = try PrivateKey.generate() - let options = XMTP.ClientOptions(api: apiEnvironments[environment] ?? apiEnvironments["dev"]!) + // Data from hex: 0836200ffafa17a3cb8b54f22d6afa60b13da48726543241adc5c250dbb0e0cd + // aka 2k many convo test wallet + let privateKeyData = Data([8,54,32,15,250,250,23,163,203,139,84,242,45,106,250,96,177,61,164,135,38,84,50,65,173,197,194,80,219,176,224,205]) + let privateKey = try PrivateKey(privateKeyData) + // Use hardcoded privateKey for testing + let options = XMTP.ClientOptions(api: apiEnvironments[environment] ?? apiEnvironments["dev"]!) let client = try await Client.create(account: privateKey, options: options) self.clients[client.address] = client