From 3c4880d4e66a90e8e925cd2931ce60624b343259 Mon Sep 17 00:00:00 2001 From: kele-leanes Date: Mon, 11 Mar 2024 16:44:32 -0300 Subject: [PATCH 1/5] add message streaming tests with delay --- example/src/tests.ts | 147 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) diff --git a/example/src/tests.ts b/example/src/tests.ts index b04f39ed3..00e300c8d 100644 --- a/example/src/tests.ts +++ b/example/src/tests.ts @@ -80,6 +80,10 @@ function delayToPropogate(): Promise { return new Promise((r) => setTimeout(r, 100)) } +function sleep(ms: number) { + return new Promise((resolve) => setTimeout(resolve, ms)) +} + const hkdfNoSalt = new ArrayBuffer(0) async function hkdfHmacKey( @@ -553,6 +557,84 @@ test('can stream messages', async () => { return true }) +test('can stream messages with delay', async () => { + const bob = await Client.createRandom({ env: 'local' }) + await delayToPropogate() + const alice = await Client.createRandom({ env: 'local' }) + await delayToPropogate() + + // Record new conversation stream + const allConversations: Conversation[] = [] + await alice.conversations.stream(async (conversation) => { + allConversations.push(conversation) + }) + + // Start Bob starts a new conversation. + const bobConvo = await bob.conversations.newConversation(alice.address, { + conversationID: 'https://example.com/alice-and-bob', + metadata: { + title: 'Alice and Bob', + }, + }) + await delayToPropogate() + + await sleep(15000) + + assert(bobConvo.clientAddress === bob.address, 'Unexpected client address') + assert(!!bobConvo.topic, 'Missing topic' + bobConvo.topic) + assert( + bobConvo.context?.conversationID === 'https://example.com/alice-and-bob', + 'Unexpected conversationID' + bobConvo.context?.conversationID + ) + assert( + bobConvo.context?.metadata?.title === 'Alice and Bob', + 'Unexpected metadata title' + bobConvo.context?.metadata?.title + ) + assert(!!bobConvo.createdAt, 'Missing createdAt' + bobConvo.createdAt) + assert( + allConversations.length === 1, + 'Unexpected all conversations count' + allConversations.length + ) + assert( + allConversations[0].topic === bobConvo.topic, + 'Unexpected all conversations topic' + allConversations[0].topic + ) + + const aliceConvo = (await alice.conversations.list())[0] + assert(!!aliceConvo, 'missing conversation') + + // Record message stream for this conversation + const convoMessages: DecodedMessage[] = [] + await aliceConvo.streamMessages(async (message) => { + convoMessages.push(message) + }) + + for (let i = 0; i < 5; i++) { + await bobConvo.send({ text: `Message ${i}` }) + await delayToPropogate() + } + + await sleep(15000) + + assert( + convoMessages.length === 5, + 'Unexpected convo messages count' + convoMessages.length + ) + for (let i = 0; i < 5; i++) { + assert( + convoMessages[i].content() === `Message ${i}`, + 'Unexpected convo message content' + convoMessages[i].content() + ) + assert( + convoMessages[i].topic === bobConvo.topic, + 'Unexpected convo message topic' + convoMessages[i].topic + ) + } + alice.conversations.cancelStream() + + return true +}) + test('remote attachments should work', async () => { const alice = await Client.createRandom({ env: 'local', @@ -734,6 +816,71 @@ test('can stream all messages', async () => { return true }) +test('can stream all msgs with delay', async () => { + const bo = await Client.createRandom({ env: 'local' }) + await delayToPropogate() + const alix = await Client.createRandom({ env: 'local' }) + await delayToPropogate() + + // Record message stream across all conversations + const allMessages: DecodedMessage[] = [] + await alix.conversations.streamAllMessages(async (message) => { + allMessages.push(message) + }) + + // Start Bob starts a new conversation. + const boConvo = await bo.conversations.newConversation(alix.address) + await delayToPropogate() + + for (let i = 0; i < 5; i++) { + await boConvo.send({ text: `Message ${i}` }) + await delayToPropogate() + } + + await sleep(15000) + + assert( + allMessages.length === 5, + 'Unexpected all messages count ' + allMessages.length + ) + + // Starts a new conversation. + const caro = await Client.createRandom({ env: 'local' }) + const caroConvo = await caro.conversations.newConversation(alix.address) + await delayToPropogate() + for (let i = 0; i < 5; i++) { + await caroConvo.send({ text: `Message ${i}` }) + await delayToPropogate() + } + + await sleep(15000) + + assert( + allMessages.length === 10, + 'Unexpected all messages count ' + allMessages.length + ) + + alix.conversations.cancelStreamAllMessages() + + await alix.conversations.streamAllMessages(async (message) => { + allMessages.push(message) + }) + + for (let i = 0; i < 5; i++) { + await boConvo.send({ text: `Message ${i}` }) + await delayToPropogate() + } + + await sleep(15000) + + assert( + allMessages.length > 10, + 'Unexpected all messages count ' + allMessages.length + ) + + return true +}) + test('canManagePreferences', async () => { const bo = await Client.createRandom({ env: 'local' }) const alix = await Client.createRandom({ env: 'local' }) From 6f885129660b78e213b81012d81dcf21e37755a6 Mon Sep 17 00:00:00 2001 From: kele-leanes Date: Mon, 11 Mar 2024 17:51:43 -0300 Subject: [PATCH 2/5] refactor conversation streaming and add delay --- example/src/tests.ts | 98 +++++++++++++------------------------------- 1 file changed, 28 insertions(+), 70 deletions(-) diff --git a/example/src/tests.ts b/example/src/tests.ts index 00e300c8d..75fda1d71 100644 --- a/example/src/tests.ts +++ b/example/src/tests.ts @@ -557,81 +557,45 @@ test('can stream messages', async () => { return true }) -test('can stream messages with delay', async () => { - const bob = await Client.createRandom({ env: 'local' }) +test('can stream conversations with delay', async () => { + const bo = await Client.createRandom({ env: 'local' }) await delayToPropogate() - const alice = await Client.createRandom({ env: 'local' }) + const alix = await Client.createRandom({ env: 'local' }) await delayToPropogate() - // Record new conversation stream - const allConversations: Conversation[] = [] - await alice.conversations.stream(async (conversation) => { - allConversations.push(conversation) + const allConvos: Conversation[] = [] + await alix.conversations.stream(async (convo) => { + allConvos.push(convo) }) - // Start Bob starts a new conversation. - const bobConvo = await bob.conversations.newConversation(alice.address, { - conversationID: 'https://example.com/alice-and-bob', - metadata: { - title: 'Alice and Bob', - }, - }) + await bo.conversations.newConversation(alix.address) await delayToPropogate() - await sleep(15000) + await bo.conversations.newConversation(alix.address, { + conversationID: 'convo-2', + metadata: {}, + }) + await delayToPropogate() - assert(bobConvo.clientAddress === bob.address, 'Unexpected client address') - assert(!!bobConvo.topic, 'Missing topic' + bobConvo.topic) - assert( - bobConvo.context?.conversationID === 'https://example.com/alice-and-bob', - 'Unexpected conversationID' + bobConvo.context?.conversationID - ) - assert( - bobConvo.context?.metadata?.title === 'Alice and Bob', - 'Unexpected metadata title' + bobConvo.context?.metadata?.title - ) - assert(!!bobConvo.createdAt, 'Missing createdAt' + bobConvo.createdAt) assert( - allConversations.length === 1, - 'Unexpected all conversations count' + allConversations.length - ) - assert( - allConversations[0].topic === bobConvo.topic, - 'Unexpected all conversations topic' + allConversations[0].topic + allConvos.length === 2, + 'Unexpected all convos count ' + allConvos.length ) - const aliceConvo = (await alice.conversations.list())[0] - assert(!!aliceConvo, 'missing conversation') + await sleep(15000) - // Record message stream for this conversation - const convoMessages: DecodedMessage[] = [] - await aliceConvo.streamMessages(async (message) => { - convoMessages.push(message) + await bo.conversations.newConversation(alix.address, { + conversationID: 'convo-3', + metadata: {}, }) - - for (let i = 0; i < 5; i++) { - await bobConvo.send({ text: `Message ${i}` }) - await delayToPropogate() - } - - await sleep(15000) + await delayToPropogate() assert( - convoMessages.length === 5, - 'Unexpected convo messages count' + convoMessages.length + allConvos.length === 3, + 'Unexpected all convos count ' + allConvos.length ) - for (let i = 0; i < 5; i++) { - assert( - convoMessages[i].content() === `Message ${i}`, - 'Unexpected convo message content' + convoMessages[i].content() - ) - assert( - convoMessages[i].topic === bobConvo.topic, - 'Unexpected convo message topic' + convoMessages[i].topic - ) - } - alice.conversations.cancelStream() + alix.conversations.cancelStream() return true }) @@ -837,47 +801,41 @@ test('can stream all msgs with delay', async () => { await delayToPropogate() } - await sleep(15000) - assert( allMessages.length === 5, 'Unexpected all messages count ' + allMessages.length ) + await sleep(15000) // Starts a new conversation. const caro = await Client.createRandom({ env: 'local' }) const caroConvo = await caro.conversations.newConversation(alix.address) await delayToPropogate() + for (let i = 0; i < 5; i++) { await caroConvo.send({ text: `Message ${i}` }) await delayToPropogate() } - await sleep(15000) - assert( allMessages.length === 10, 'Unexpected all messages count ' + allMessages.length ) - alix.conversations.cancelStreamAllMessages() - - await alix.conversations.streamAllMessages(async (message) => { - allMessages.push(message) - }) + await sleep(15000) for (let i = 0; i < 5; i++) { await boConvo.send({ text: `Message ${i}` }) await delayToPropogate() } - await sleep(15000) - assert( - allMessages.length > 10, + allMessages.length === 15, 'Unexpected all messages count ' + allMessages.length ) + alix.conversations.cancelStreamAllMessages() + return true }) From 36be6be67d9ebe84014689360172a4d91060f0ad Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Wed, 13 Mar 2024 11:31:09 -0700 Subject: [PATCH 3/5] fix: streaming issues --- example/ios/Podfile.lock | 14 +++++++------- ios/XMTPReactNative.podspec | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index e3227fe70..a30aca5a1 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -56,7 +56,7 @@ PODS: - hermes-engine/Pre-built (= 0.71.14) - hermes-engine/Pre-built (0.71.14) - libevent (2.1.12) - - LibXMTP (0.4.3-beta1) + - LibXMTP (0.4.3-beta2) - Logging (1.0.0) - MessagePacker (0.4.7) - MMKV (1.3.3): @@ -445,16 +445,16 @@ PODS: - GenericJSON (~> 2.0) - Logging (~> 1.0.0) - secp256k1.swift (~> 0.1) - - XMTP (0.9.0): + - XMTP (0.9.1): - Connect-Swift (= 0.3.0) - GzipSwift - - LibXMTP (= 0.4.3-beta1) + - LibXMTP (= 0.4.3-beta2) - web3.swift - XMTPReactNative (0.1.0): - ExpoModulesCore - MessagePacker - secp256k1.swift - - XMTP (= 0.9.0) + - XMTP (= 0.9.1) - Yoga (1.14.0) DEPENDENCIES: @@ -701,7 +701,7 @@ SPEC CHECKSUMS: GzipSwift: 893f3e48e597a1a4f62fafcb6514220fcf8287fa hermes-engine: d7cc127932c89c53374452d6f93473f1970d8e88 libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913 - LibXMTP: ddfcde5d4c9b3baa34b038956a7aad46e1da6391 + LibXMTP: ef1e7d04de6b7f0cb88f7678be44bb6329263f6c Logging: 9ef4ecb546ad3169398d5a723bc9bea1c46bef26 MessagePacker: ab2fe250e86ea7aedd1a9ee47a37083edd41fd02 MMKV: f902fb6719da13c2ab0965233d8963a59416f911 @@ -751,8 +751,8 @@ SPEC CHECKSUMS: secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634 SwiftProtobuf: b02b5075dcf60c9f5f403000b3b0c202a11b6ae1 web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959 - XMTP: f539ad61202ae67ed813f2dd756875c31ce9a677 - XMTPReactNative: 845b4760d768d2971e478c46f80d4302de90b6a4 + XMTP: 1d6bbf66833dc71763de3345f63801dbc6c6de27 + XMTPReactNative: 28a3ff58d411efe05cf6ee4429b315e5e3bd169a Yoga: e71803b4c1fff832ccf9b92541e00f9b873119b9 PODFILE CHECKSUM: 95d6ace79946933ecf80684613842ee553dd76a2 diff --git a/ios/XMTPReactNative.podspec b/ios/XMTPReactNative.podspec index c0804cd36..0c40a3feb 100644 --- a/ios/XMTPReactNative.podspec +++ b/ios/XMTPReactNative.podspec @@ -26,5 +26,5 @@ Pod::Spec.new do |s| s.source_files = "**/*.{h,m,swift}" s.dependency 'secp256k1.swift' s.dependency "MessagePacker" - s.dependency "XMTP", "= 0.9.0" + s.dependency "XMTP", "= 0.9.1" end From bffdad6338d3fc5ed214d6cd15e63b6d11aaa334 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Wed, 13 Mar 2024 11:45:41 -0700 Subject: [PATCH 4/5] fix: make the test use dev --- example/src/tests.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/src/tests.ts b/example/src/tests.ts index 0d231c8b0..79b2e2fba 100644 --- a/example/src/tests.ts +++ b/example/src/tests.ts @@ -626,9 +626,9 @@ test('can stream messages', async () => { }) test('can stream conversations with delay', async () => { - const bo = await Client.createRandom({ env: 'local' }) + const bo = await Client.createRandom({ env: 'dev' }) await delayToPropogate() - const alix = await Client.createRandom({ env: 'local' }) + const alix = await Client.createRandom({ env: 'dev' }) await delayToPropogate() const allConvos: Conversation[] = [] From 7a4552d68743017df80e63392e867a59c5b88463 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Wed, 13 Mar 2024 11:51:34 -0700 Subject: [PATCH 5/5] make the test point at dev --- example/src/tests.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/example/src/tests.ts b/example/src/tests.ts index 79b2e2fba..9431bc9ce 100644 --- a/example/src/tests.ts +++ b/example/src/tests.ts @@ -849,9 +849,9 @@ test('can stream all messages', async () => { }) test('can stream all msgs with delay', async () => { - const bo = await Client.createRandom({ env: 'local' }) + const bo = await Client.createRandom({ env: 'dev' }) await delayToPropogate() - const alix = await Client.createRandom({ env: 'local' }) + const alix = await Client.createRandom({ env: 'dev' }) await delayToPropogate() // Record message stream across all conversations @@ -876,7 +876,7 @@ test('can stream all msgs with delay', async () => { await sleep(15000) // Starts a new conversation. - const caro = await Client.createRandom({ env: 'local' }) + const caro = await Client.createRandom({ env: 'dev' }) const caroConvo = await caro.conversations.newConversation(alix.address) await delayToPropogate()