From ea8408e3867ba3c4f3a1db8447c405afe6019bd9 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Fri, 20 Dec 2024 17:26:41 -0800 Subject: [PATCH 1/6] update history sync --- android/build.gradle | 2 +- .../expo/modules/xmtpreactnativesdk/XMTPModule.kt | 15 ++++----------- example/src/tests/conversationTests.ts | 10 +++++----- ios/XMTPReactNative.podspec | 2 +- 4 files changed, 11 insertions(+), 18 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 4bf6199f..f94c5781 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -98,7 +98,7 @@ repositories { dependencies { implementation project(':expo-modules-core') implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}" - implementation "org.xmtp:android:3.0.18" + implementation "org.xmtp:android:3.0.19" implementation 'com.google.code.gson:gson:2.10.1' implementation 'com.facebook.react:react-native:0.71.3' implementation "com.daveanthonythomas.moshipack:moshipack:1.0.1" diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt index dc080891..6b6eb783 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt @@ -192,7 +192,6 @@ class XMTPModule : Module() { } private var clients: MutableMap = mutableMapOf() - private var apiClient: XmtpApiClient? = null private var xmtpPush: XMTPPush? = null private var signer: ReactNativeSigner? = null private val isDebugEnabled = BuildConfig.DEBUG // TODO: consider making this configurable @@ -296,8 +295,7 @@ class XMTPModule : Module() { withContext(Dispatchers.IO) { logV("connectToApiBackend") val api = apiEnvironments(environment, null) - val xmtpApiClient = Client.connectToApiBackend(api) - apiClient = xmtpApiClient + Client.connectToApiBackend(api) } } @@ -311,11 +309,10 @@ class XMTPModule : Module() { hasPreAuthenticateToInboxCallback, ) val randomClient = - Client().create(account = privateKey, options = options, apiClient = apiClient) + Client().create(account = privateKey, options = options) ContentJson.Companion clients[randomClient.installationId] = randomClient - apiClient = randomClient.apiClient ClientWrapper.encodeToObj(randomClient) } } @@ -338,9 +335,8 @@ class XMTPModule : Module() { hasAuthInboxCallback, ) val client = - Client().create(account = reactSigner, options = options, apiClient = apiClient) + Client().create(account = reactSigner, options = options) clients[client.installationId] = client - apiClient = client.apiClient ContentJson.Companion signer = null sendEvent("authed", ClientWrapper.encodeToObj(client)) @@ -358,11 +354,9 @@ class XMTPModule : Module() { address = address, options = options, inboxId = inboxId, - apiClient = apiClient ) ContentJson.Companion clients[client.installationId] = client - apiClient = client.apiClient ClientWrapper.encodeToObj(client) } } @@ -472,7 +466,6 @@ class XMTPModule : Module() { peerAddresses, context, apiEnvironments(environment, null), - apiClient = apiClient ) } } @@ -482,7 +475,7 @@ class XMTPModule : Module() { try { logV("getOrCreateInboxId") Client.getOrCreateInboxId( - environment = apiEnvironments(environment, null), + api = apiEnvironments(environment, null), address = address ) } catch (e: Exception) { diff --git a/example/src/tests/conversationTests.ts b/example/src/tests/conversationTests.ts index de291169..ff4cf7a0 100644 --- a/example/src/tests/conversationTests.ts +++ b/example/src/tests/conversationTests.ts @@ -415,14 +415,14 @@ test('can filter sync all by consent', async () => { const boConvosFilteredUnknown = await boClient.conversations.syncAllConversations('unknown') - assert(boConvos === 4, `Conversation length should be 4 but was ${boConvos}`) + assert(boConvos === 5, `Conversation length should be 5 but was ${boConvos}`) assert( - boConvosFilteredAllowed === 2, - `Conversation length should be 2 but was ${boConvosFilteredAllowed}` + boConvosFilteredAllowed === 3, + `Conversation length should be 3 but was ${boConvosFilteredAllowed}` ) assert( - boConvosFilteredUnknown === 2, - `Conversation length should be 2 but was ${boConvosFilteredUnknown}` + boConvosFilteredUnknown === 3, + `Conversation length should be 3 but was ${boConvosFilteredUnknown}` ) return true diff --git a/ios/XMTPReactNative.podspec b/ios/XMTPReactNative.podspec index c5a62f4b..ec580de1 100644 --- a/ios/XMTPReactNative.podspec +++ b/ios/XMTPReactNative.podspec @@ -26,7 +26,7 @@ Pod::Spec.new do |s| s.source_files = "**/*.{h,m,swift}" s.dependency "MessagePacker" - s.dependency "XMTP", "= 3.0.19" + s.dependency "XMTP", "= 3.0.20" s.dependency 'CSecp256k1', '~> 0.2' s.dependency "SQLCipher", "= 4.5.7" end From db4e92629b56ae14bf603cb897078aee88cee8b5 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Fri, 20 Dec 2024 17:34:10 -0800 Subject: [PATCH 2/6] Create slimy-pugs-warn.md --- .changeset/slimy-pugs-warn.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/slimy-pugs-warn.md diff --git a/.changeset/slimy-pugs-warn.md b/.changeset/slimy-pugs-warn.md new file mode 100644 index 00000000..866deea6 --- /dev/null +++ b/.changeset/slimy-pugs-warn.md @@ -0,0 +1,6 @@ +--- +"@xmtp/react-native-sdk": patch +--- + +- Re-Enable History Sync +- Continued Performance improvements From 3e4275ad5e690dbe57519aa7a38d8068138b6b19 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Tue, 31 Dec 2024 14:32:51 -0800 Subject: [PATCH 3/6] re-enable message history syncing in iOS as well --- .../modules/xmtpreactnativesdk/XMTPModule.kt | 1 - example/ios/Podfile.lock | 16 ++++++------- ios/XMTPModule.swift | 23 ++++--------------- ios/XMTPReactNative.podspec | 2 +- 4 files changed, 13 insertions(+), 29 deletions(-) diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt index 6b6eb783..0ea37394 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt @@ -59,7 +59,6 @@ import org.xmtp.android.library.messages.PrivateKeyBuilder import org.xmtp.android.library.messages.Signature import org.xmtp.android.library.push.Service import org.xmtp.android.library.push.XMTPPush -import uniffi.xmtpv3.XmtpApiClient import uniffi.xmtpv3.org.xmtp.android.library.libxmtp.GroupPermissionPreconfiguration import uniffi.xmtpv3.org.xmtp.android.library.libxmtp.PermissionOption import java.io.BufferedReader diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 9ed12a86..64f3da2b 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -55,7 +55,7 @@ PODS: - hermes-engine/Pre-built (= 0.71.14) - hermes-engine/Pre-built (0.71.14) - libevent (2.1.12) - - LibXMTP (3.0.13) + - LibXMTP (3.0.15) - MessagePacker (0.4.7) - MMKV (2.0.0): - MMKVCore (~> 2.0.0) @@ -448,18 +448,18 @@ PODS: - SQLCipher/standard (4.5.7): - SQLCipher/common - SwiftProtobuf (1.28.2) - - XMTP (3.0.19): + - XMTP (3.0.21): - Connect-Swift (= 1.0.0) - CryptoSwift (= 1.8.3) - CSecp256k1 (~> 0.2) - - LibXMTP (= 3.0.13) + - LibXMTP (= 3.0.15) - SQLCipher (= 4.5.7) - - XMTPReactNative (3.1.3): + - XMTPReactNative (3.1.4): - CSecp256k1 (~> 0.2) - ExpoModulesCore - MessagePacker - SQLCipher (= 4.5.7) - - XMTP (= 3.0.19) + - XMTP (= 3.0.21) - Yoga (1.14.0) DEPENDENCIES: @@ -711,7 +711,7 @@ SPEC CHECKSUMS: glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b hermes-engine: d7cc127932c89c53374452d6f93473f1970d8e88 libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913 - LibXMTP: 3b4b45c0edd404de164e26c7920af5ea0ebb3e17 + LibXMTP: ad2c28778d7273c499b12dbf5493978c58d76858 MessagePacker: ab2fe250e86ea7aedd1a9ee47a37083edd41fd02 MMKV: f7d1d5945c8765f97f39c3d121f353d46735d801 MMKVCore: c04b296010fcb1d1638f2c69405096aac12f6390 @@ -762,8 +762,8 @@ SPEC CHECKSUMS: RNSVG: d00c8f91c3cbf6d476451313a18f04d220d4f396 SQLCipher: 5e6bfb47323635c8b657b1b27d25c5f1baf63bf5 SwiftProtobuf: 4dbaffec76a39a8dc5da23b40af1a5dc01a4c02d - XMTP: b5311154b2a3cda7c07ce78ae9fa6d111bac979d - XMTPReactNative: 0d7f1d9b444eaeb3ffaf0fd29c6b71a0d6b6a29a + XMTP: 2c5dd2116778d1b547ac99b5b2396318d02c24d1 + XMTPReactNative: 7745410f6367ed23198e546409d84987c6c5fea9 Yoga: e71803b4c1fff832ccf9b92541e00f9b873119b9 PODFILE CHECKSUM: 0e6fe50018f34e575d38dc6a1fdf1f99c9596cdd diff --git a/ios/XMTPModule.swift b/ios/XMTPModule.swift index 05d36c4f..1c9eaa37 100644 --- a/ios/XMTPModule.swift +++ b/ios/XMTPModule.swift @@ -31,7 +31,6 @@ actor IsolatedManager { public class XMTPModule: Module { var signer: ReactNativeSigner? let clientsManager = ClientsManager() - var apiClient: XmtpApiClient? let subscriptionsManager = IsolatedManager>() private var preAuthenticateToInboxCallbackDeferred: DispatchSemaphore? @@ -164,15 +163,6 @@ public class XMTPModule: Module { try await client.reconnectLocalDatabase() } - AsyncFunction("requestMessageHistorySync") { (installationId: String) in - guard - let client = await clientsManager.getClient(key: installationId) - else { - throw Error.noClient - } - try await client.requestMessageHistorySync() - } - AsyncFunction("getInboxState") { (installationId: String, refreshFromNetwork: Bool) -> String in guard @@ -222,10 +212,9 @@ public class XMTPModule: Module { AsyncFunction("connectToApiBackend") { (environment: String) in - let xmtpApiClient = try await XMTP.Client.connectToApiBackend( + try await XMTP.Client.connectToApiBackend( api: createApiClient(env: environment) ) - apiClient = xmtpApiClient } AsyncFunction("createRandom") { @@ -250,8 +239,7 @@ public class XMTPModule: Module { preAuthenticateToInboxCallback: preAuthenticateToInboxCallback ) let client = try await Client.create( - account: privateKey, options: options, apiClient: apiClient) - apiClient = client.apiClient + account: privateKey, options: options) await clientsManager.updateClient( key: client.installationID, client: client) return try ClientWrapper.encodeToObj(client) @@ -286,10 +274,9 @@ public class XMTPModule: Module { preAuthenticateToInboxCallback: preAuthenticateToInboxCallback ) let client = try await XMTP.Client.create( - account: signer, options: options, apiClient: apiClient) + account: signer, options: options) await self.clientsManager.updateClient( key: client.installationID, client: client) - apiClient = client.apiClient self.signer = nil self.sendEvent("authed", try ClientWrapper.encodeToObj(client)) } @@ -309,11 +296,9 @@ public class XMTPModule: Module { preAuthenticateToInboxCallback: preAuthenticateToInboxCallback ) let client = try await XMTP.Client.build( - address: address, options: options, inboxId: inboxId, - apiClient: apiClient) + address: address, options: options, inboxId: inboxId) await clientsManager.updateClient( key: client.installationID, client: client) - apiClient = client.apiClient return try ClientWrapper.encodeToObj(client) } diff --git a/ios/XMTPReactNative.podspec b/ios/XMTPReactNative.podspec index ec580de1..660887a6 100644 --- a/ios/XMTPReactNative.podspec +++ b/ios/XMTPReactNative.podspec @@ -26,7 +26,7 @@ Pod::Spec.new do |s| s.source_files = "**/*.{h,m,swift}" s.dependency "MessagePacker" - s.dependency "XMTP", "= 3.0.20" + s.dependency "XMTP", "= 3.0.21" s.dependency 'CSecp256k1', '~> 0.2' s.dependency "SQLCipher", "= 4.5.7" end From 1142bdc219df4e879fbff926707a1235ca571c28 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Wed, 1 Jan 2025 20:23:28 -0800 Subject: [PATCH 4/6] add performance tests for creating a new group --- .../modules/xmtpreactnativesdk/XMTPModule.kt | 7 --- example/src/tests/groupPerformanceTests.ts | 58 ++++++++++++++++++- example/src/tests/test-utils.ts | 8 ++- src/index.ts | 6 -- src/lib/Client.ts | 7 --- 5 files changed, 63 insertions(+), 23 deletions(-) diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt index 0ea37394..14f52d88 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt @@ -249,13 +249,6 @@ class XMTPModule : Module() { } } - AsyncFunction("requestMessageHistorySync") Coroutine { installationId: String -> - withContext(Dispatchers.IO) { - val client = clients[installationId] ?: throw XMTPException("No client") - client.requestMessageHistorySync() - } - } - AsyncFunction("getInboxState") Coroutine { installationId: String, refreshFromNetwork: Boolean -> withContext(Dispatchers.IO) { val client = clients[installationId] ?: throw XMTPException("No client") diff --git a/example/src/tests/groupPerformanceTests.ts b/example/src/tests/groupPerformanceTests.ts index df43994f..2dddba68 100644 --- a/example/src/tests/groupPerformanceTests.ts +++ b/example/src/tests/groupPerformanceTests.ts @@ -10,7 +10,7 @@ import { StaticAttachmentCodec, } from 'xmtp-react-native-sdk' -import { Test, assert } from './test-utils' +import { Test, assert, createClients } from './test-utils' export const groupPerformanceTests: Test[] = [] let counter = 1 @@ -127,3 +127,59 @@ test('building and creating', async () => { return true }) + +test('creating a new group', async () => { + const [alixClient, boClient, caroClient] = await createClients(3, 'dev') + + const start1 = performance.now() + await alixClient.conversations.newConversation(boClient.address) + const end1 = performance.now() + console.log(`Alix created a dm with Bo in ${end1 - start1}ms`) + + await boClient.conversations.syncAllConversations() + const start2 = performance.now() + await boClient.conversations.newConversation(alixClient.address) + const end2 = performance.now() + console.log(`Bo found a dm with Alix in ${end2 - start2}ms`) + + const start3 = performance.now() + await alixClient.conversations.newGroup([ + boClient.address, + caroClient.address, + ]) + const end3 = performance.now() + console.log(`Alix created a group with Bo and Caro in ${end3 - start3}ms`) + + const start4 = performance.now() + await alixClient.conversations.newGroup( + [boClient.address, caroClient.address], + { + permissionLevel: 'admin_only', + name: 'Group Name', + imageUrlSquare: 'imageurl.com', + description: 'group description', + pinnedFrameUrl: 'pinnedframe.com', + } + ) + const end4 = performance.now() + console.log( + `Alix created a group with Bo and Caro with metadata in ${end4 - start4}ms` + ) + assert( + end1 - start1 < 1000, + `Creating a new dm should be less than a second but was ${end1 - start1}` + ) + assert( + end2 - start2 < 1000, + `Finding a existing dm should be less than a second but was ${end2 - start2}` + ) + assert( + end3 - start3 < 1000, + `Creating a new group without metadata should be less than a second but was ${end3 - start3}` + ) + assert( + end4 - start4 < 1000, + `Creating a new group with metadata should be less than a second but was ${end4 - start4}` + ) + return true +}) diff --git a/example/src/tests/test-utils.ts b/example/src/tests/test-utils.ts index ce0f53f8..b3dd9b45 100644 --- a/example/src/tests/test-utils.ts +++ b/example/src/tests/test-utils.ts @@ -4,6 +4,7 @@ import { GroupUpdatedCodec, Group, RemoteAttachmentCodec, + XMTPEnvironment, } from 'xmtp-react-native-sdk' export type Test = { @@ -26,7 +27,10 @@ export function assert(condition: boolean, msg: string) { } } -export async function createClients(numClients: number): Promise { +export async function createClients( + numClients: number, + env?: XMTPEnvironment | undefined +): Promise { const clients = [] for (let i = 0; i < numClients; i++) { const keyBytes = new Uint8Array([ @@ -35,7 +39,7 @@ export async function createClients(numClients: number): Promise { 145, ]) const client = await Client.createRandom({ - env: 'local', + env: env ?? 'local', dbEncryptionKey: keyBytes, }) client.register(new GroupUpdatedCodec()) diff --git a/src/index.ts b/src/index.ts index be4acc4b..20e30f03 100644 --- a/src/index.ts +++ b/src/index.ts @@ -72,12 +72,6 @@ export async function reconnectLocalDatabase(installationId: InstallationId) { return XMTPModule.reconnectLocalDatabase(installationId) } -export async function requestMessageHistorySync( - installationId: InstallationId -) { - return XMTPModule.requestMessageHistorySync(installationId) -} - export async function getInboxState( installationId: InstallationId, refreshFromNetwork: boolean diff --git a/src/lib/Client.ts b/src/lib/Client.ts index 0689d659..1198a203 100644 --- a/src/lib/Client.ts +++ b/src/lib/Client.ts @@ -539,13 +539,6 @@ export class Client< return await XMTPModule.reconnectLocalDatabase(this.installationId) } - /** - * Make a request for a message history sync. - */ - async requestMessageHistorySync() { - return await XMTPModule.requestMessageHistorySync(this.installationId) - } - /** * Make a request for your inbox state. * From 57ae7dbd7cae9c4b07fbda1e0b094d8d27bc60a0 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Wed, 1 Jan 2025 20:36:07 -0800 Subject: [PATCH 5/6] remove ability to manually connect to database --- .../modules/xmtpreactnativesdk/XMTPModule.kt | 8 ------- example/src/tests/groupPerformanceTests.ts | 24 ------------------- ios/XMTPModule.swift | 7 ------ src/index.ts | 6 ----- src/lib/Client.ts | 10 -------- 5 files changed, 55 deletions(-) diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt index 14f52d88..4b33d7c5 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt @@ -283,14 +283,6 @@ class XMTPModule : Module() { signer?.handleSCW(id = requestID, signature = signature) } - AsyncFunction("connectToApiBackend") Coroutine { environment: String -> - withContext(Dispatchers.IO) { - logV("connectToApiBackend") - val api = apiEnvironments(environment, null) - Client.connectToApiBackend(api) - } - } - AsyncFunction("createRandom") Coroutine { hasPreAuthenticateToInboxCallback: Boolean?, dbEncryptionKey: List, authParams: String -> withContext(Dispatchers.IO) { logV("createRandom") diff --git a/example/src/tests/groupPerformanceTests.ts b/example/src/tests/groupPerformanceTests.ts index 2dddba68..fee7011a 100644 --- a/example/src/tests/groupPerformanceTests.ts +++ b/example/src/tests/groupPerformanceTests.ts @@ -88,26 +88,6 @@ test('building and creating', async () => { const end3 = performance.now() console.log(`Built a client with inboxId in ${end3 - start3}ms`) - await Client.connectToApiBackend('dev') - const start4 = performance.now() - await Client.createRandom({ - env: 'dev', - appVersion: 'Testing/0.0.0', - dbEncryptionKey: keyBytes, - dbDirectory: dbDirPath, - codecs: [ - new ReactionCodec(), - new ReplyCodec(), - new GroupUpdatedCodec(), - new StaticAttachmentCodec(), - new RemoteAttachmentCodec(), - ], - }) - const end4 = performance.now() - console.log( - `Created a client after connecting to backend in ${end4 - start4}ms` - ) - assert( end2 - start2 < end1 - start1, 'building a client should be faster than creating one' @@ -120,10 +100,6 @@ test('building and creating', async () => { end3 - start3 < end2 - start2, 'building a client with an inboxId should be faster than building without' ) - assert( - end4 - start4 < end1 - start1, - 'creating a client with an apiClient cached should be faster than creating one without' - ) return true }) diff --git a/ios/XMTPModule.swift b/ios/XMTPModule.swift index 1c9eaa37..ec1512cb 100644 --- a/ios/XMTPModule.swift +++ b/ios/XMTPModule.swift @@ -210,13 +210,6 @@ public class XMTPModule: Module { try signer?.handleSCW(id: requestID, signature: signature) } - AsyncFunction("connectToApiBackend") { - (environment: String) in - try await XMTP.Client.connectToApiBackend( - api: createApiClient(env: environment) - ) - } - AsyncFunction("createRandom") { ( hasAuthenticateToInboxCallback: Bool?, dbEncryptionKey: [UInt8], diff --git a/src/index.ts b/src/index.ts index 20e30f03..03b1ac36 100644 --- a/src/index.ts +++ b/src/index.ts @@ -113,12 +113,6 @@ export async function receiveSCWSignature( return await XMTPModule.receiveSCWSignature(requestID, signature) } -export async function connectToApiBackend( - environment: XMTPEnvironment -): Promise { - return await XMTPModule.connectToApiBackend(environment) -} - export async function createRandom( environment: 'local' | 'dev' | 'production', dbEncryptionKey: Uint8Array, diff --git a/src/lib/Client.ts b/src/lib/Client.ts index 1198a203..b207fd75 100644 --- a/src/lib/Client.ts +++ b/src/lib/Client.ts @@ -79,16 +79,6 @@ export class Client< } } - /** - * Connects to the XMTP api backend to speed up creating and building future clients. - * - * @param {XMTPEnvironment} env - Environment to connect to - * @returns {Promise} A Promise to let you know the api has been connected - */ - static async connectToApiBackend(env: XMTPEnvironment): Promise { - return await XMTPModule.connectToApiBackend(env) - } - /** * Creates a new instance of the XMTP Client with a randomly generated address. * From 033717134ebb733eef43b34ce36daa9ecf3a9f90 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Wed, 1 Jan 2025 20:49:40 -0800 Subject: [PATCH 6/6] add more performance tests --- example/src/tests/groupPerformanceTests.ts | 65 +++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/example/src/tests/groupPerformanceTests.ts b/example/src/tests/groupPerformanceTests.ts index fee7011a..42a01d96 100644 --- a/example/src/tests/groupPerformanceTests.ts +++ b/example/src/tests/groupPerformanceTests.ts @@ -104,7 +104,7 @@ test('building and creating', async () => { return true }) -test('creating a new group', async () => { +test('creating a new conversation', async () => { const [alixClient, boClient, caroClient] = await createClients(3, 'dev') const start1 = performance.now() @@ -159,3 +159,66 @@ test('creating a new group', async () => { ) return true }) + +test('sending messages in conversations', async () => { + const [alixClient, boClient, caroClient] = await createClients(10, 'local') + const alixDm = await alixClient.conversations.newConversation( + boClient.address + ) + const alixGroup = await alixClient.conversations.newGroup([ + boClient.address, + caroClient.address, + ]) + await boClient.conversations.syncAllConversations() + await caroClient.conversations.syncAllConversations() + const boDm = await alixClient.conversations.findConversation(alixDm.id) + const boGroup = await alixClient.conversations.findGroup(alixGroup.id) + const caroGroup = await alixClient.conversations.findConversation( + alixGroup.id + ) + + const start1 = performance.now() + await boDm?.send('message 1') + const end1 = performance.now() + console.log(`Bo sent message to dm in ${end1 - start1}ms`) + + const start2 = performance.now() + await alixDm.send('message 2') + const end2 = performance.now() + console.log(`Alix sent message to dm in ${end2 - start2}ms`) + + const start3 = performance.now() + await alixGroup.send('message 1') + const end3 = performance.now() + console.log(`Alix sent message to group in ${end3 - start3}ms`) + + const start4 = performance.now() + await caroGroup?.send('message 2') + const end4 = performance.now() + console.log(`Caro sent message to group in ${end4 - start4}ms`) + const start5 = performance.now() + await boGroup?.send('message 3') + const end5 = performance.now() + console.log(`Bo sent message to group in ${end5 - start5}ms`) + assert( + end1 - start1 < 500, + `Sending message to dm should take less than .5s but was ${end1 - start1}` + ) + assert( + end2 - start2 < 500, + `Sending message to dm should take less than .5s but was ${end2 - start2}` + ) + assert( + end3 - start3 < 500, + `Sending message to group should take less than .5s but was ${end3 - start3}` + ) + assert( + end4 - start4 < 500, + `Sending message to grop should take less than .5s but was ${end4 - start4}` + ) + assert( + end5 - start5 < 500, + `Sending message to grop should take less than .5s but was ${end5 - start5}` + ) + return true +})