From 4199c02eef984794a986b989ac4fd2b2b50045ca Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Fri, 30 Aug 2024 17:43:52 -0600 Subject: [PATCH 1/4] test for streaming weirdness --- example/ios/Podfile.lock | 14 +- example/src/tests/groupTests.ts | 3822 ++++++++++++++++--------------- 2 files changed, 1941 insertions(+), 1895 deletions(-) diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index f0b559124..183c410d4 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.5.8-beta1) + - LibXMTP (0.5.8-beta3) - Logging (1.0.0) - MessagePacker (0.4.7) - MMKV (1.3.9): @@ -449,16 +449,16 @@ PODS: - GenericJSON (~> 2.0) - Logging (~> 1.0.0) - secp256k1.swift (~> 0.1) - - XMTP (0.14.9): + - XMTP (0.14.10): - Connect-Swift (= 0.12.0) - GzipSwift - - LibXMTP (= 0.5.8-beta1) + - LibXMTP (= 0.5.8-beta3) - web3.swift - XMTPReactNative (0.1.0): - ExpoModulesCore - MessagePacker - secp256k1.swift - - XMTP (= 0.14.9) + - XMTP (= 0.14.10) - Yoga (1.14.0) DEPENDENCIES: @@ -711,7 +711,7 @@ SPEC CHECKSUMS: GzipSwift: 893f3e48e597a1a4f62fafcb6514220fcf8287fa hermes-engine: d7cc127932c89c53374452d6f93473f1970d8e88 libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913 - LibXMTP: b7f9a97c56120771b3e99017f3454063f0388fb6 + LibXMTP: c7cad19e8ac4721254df8f5b3c60677362b5f0d3 Logging: 9ef4ecb546ad3169398d5a723bc9bea1c46bef26 MessagePacker: ab2fe250e86ea7aedd1a9ee47a37083edd41fd02 MMKV: 817ba1eea17421547e01e087285606eb270a8dcb @@ -763,8 +763,8 @@ SPEC CHECKSUMS: secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634 SwiftProtobuf: 407a385e97fd206c4fbe880cc84123989167e0d1 web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959 - XMTP: ba28e0b3732e20beff61d2f9b7fe38561f5a6f72 - XMTPReactNative: 8c15853c59fffddffa1c19b68acd766929ca10b2 + XMTP: f6464951bba381352f838986a2b75dc14fc1e2cf + XMTPReactNative: ce44b033a57907e5e9747927614e980099b5b2f4 Yoga: e71803b4c1fff832ccf9b92541e00f9b873119b9 PODFILE CHECKSUM: 0e6fe50018f34e575d38dc6a1fdf1f99c9596cdd diff --git a/example/src/tests/groupTests.ts b/example/src/tests/groupTests.ts index afaf70472..244f839ca 100644 --- a/example/src/tests/groupTests.ts +++ b/example/src/tests/groupTests.ts @@ -42,2177 +42,2223 @@ async function createGroups( return groups } -test('can make a MLS V3 client', async () => { - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const keyBytes = new Uint8Array([ - 233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64, - 166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, 145, - ]) - const client = await Client.createRandom({ - env: 'local', - appVersion: 'Testing/0.0.0', - enableV3: true, - dbEncryptionKey: keyBytes, - }) - - const inboxId = await Client.getOrCreateInboxId(client.address, { - env: 'local', - }) +// test('can make a MLS V3 client', async () => { +// // eslint-disable-next-line @typescript-eslint/no-unused-vars +// const keyBytes = new Uint8Array([ +// 233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64, +// 166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, 145, +// ]) +// const client = await Client.createRandom({ +// env: 'local', +// appVersion: 'Testing/0.0.0', +// enableV3: true, +// dbEncryptionKey: keyBytes, +// }) + +// const inboxId = await Client.getOrCreateInboxId(client.address, { +// env: 'local', +// }) + +// assert( +// client.inboxId === inboxId, +// `inboxIds should match but were ${client.inboxId} and ${inboxId}` +// ) +// return true +// }) - assert( - client.inboxId === inboxId, - `inboxIds should match but were ${client.inboxId} and ${inboxId}` - ) - return true -}) +// test('can revoke all other installations', async () => { +// const keyBytes = new Uint8Array([ +// 233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64, +// 166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, 145, +// ]) +// const alixWallet = Wallet.createRandom() + +// const alix = await Client.create(alixWallet, { +// env: 'local', +// appVersion: 'Testing/0.0.0', +// enableV3: true, +// dbEncryptionKey: keyBytes, +// }) +// await alix.deleteLocalDatabase() + +// const alix2 = await Client.create(alixWallet, { +// env: 'local', +// appVersion: 'Testing/0.0.0', +// enableV3: true, +// dbEncryptionKey: keyBytes, +// }) + +// const inboxState = await alix2.inboxState(true) +// assert( +// inboxState.installationIds.length === 2, +// `installationIds length should be 2 but was ${inboxState.installationIds.length}` +// ) + +// await alix2.revokeAllOtherInstallations(alixWallet) + +// const inboxState2 = await alix2.inboxState(true) +// assert( +// inboxState2.installationIds.length === 1, +// `installationIds length should be 1 but was ${inboxState2.installationIds.length}` +// ) +// return true +// }) -test('can revoke all other installations', async () => { - const keyBytes = new Uint8Array([ - 233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64, - 166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, 145, - ]) - const alixWallet = Wallet.createRandom() - - const alix = await Client.create(alixWallet, { - env: 'local', - appVersion: 'Testing/0.0.0', - enableV3: true, - dbEncryptionKey: keyBytes, - }) - await alix.deleteLocalDatabase() - - const alix2 = await Client.create(alixWallet, { - env: 'local', - appVersion: 'Testing/0.0.0', - enableV3: true, - dbEncryptionKey: keyBytes, - }) - - const inboxState = await alix2.inboxState(true) - assert( - inboxState.installationIds.length === 2, - `installationIds length should be 2 but was ${inboxState.installationIds.length}` - ) +// test('calls preAuthenticateToInboxCallback when supplied', async () => { +// let isCallbackCalled = 0 +// let isPreAuthCalled = false +// const preAuthenticateToInboxCallback = () => { +// isCallbackCalled++ +// isPreAuthCalled = true +// } +// const preEnableIdentityCallback = () => { +// isCallbackCalled++ +// } +// const preCreateIdentityCallback = () => { +// isCallbackCalled++ +// } +// const keyBytes = new Uint8Array([ +// 233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64, +// 166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, 145, +// ]) + +// await Client.createRandom({ +// env: 'local', +// enableV3: true, +// preEnableIdentityCallback, +// preCreateIdentityCallback, +// preAuthenticateToInboxCallback, +// dbEncryptionKey: keyBytes, +// }) + +// assert( +// isCallbackCalled === 3, +// `callback should be called 3 times but was ${isCallbackCalled}` +// ) + +// if (!isPreAuthCalled) { +// throw new Error('preAuthenticateToInboxCallback not called') +// } - await alix2.revokeAllOtherInstallations(alixWallet) +// return true +// }) - const inboxState2 = await alix2.inboxState(true) - assert( - inboxState2.installationIds.length === 1, - `installationIds length should be 1 but was ${inboxState2.installationIds.length}` - ) - return true -}) +// test('can delete a local database', async () => { +// let [client, anotherClient] = await createClients(2) + +// await client.conversations.newGroup([anotherClient.address]) +// await client.conversations.syncGroups() +// assert( +// (await client.conversations.listGroups()).length === 1, +// `should have a group size of 1 but was ${ +// (await client.conversations.listGroups()).length +// }` +// ) + +// assert( +// client.dbPath !== '', +// `client dbPath should be set but was ${client.dbPath}` +// ) +// await client.deleteLocalDatabase() +// client = await Client.createRandom({ +// env: 'local', +// appVersion: 'Testing/0.0.0', +// enableV3: true, +// dbEncryptionKey: new Uint8Array([ +// 233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64, +// 166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, +// 145, +// ]), +// }) +// await client.conversations.syncGroups() +// assert( +// (await client.conversations.listGroups()).length === 0, +// `should have a group size of 0 but was ${ +// (await client.conversations.listGroups()).length +// }` +// ) -test('calls preAuthenticateToInboxCallback when supplied', async () => { - let isCallbackCalled = 0 - let isPreAuthCalled = false - const preAuthenticateToInboxCallback = () => { - isCallbackCalled++ - isPreAuthCalled = true - } - const preEnableIdentityCallback = () => { - isCallbackCalled++ - } - const preCreateIdentityCallback = () => { - isCallbackCalled++ - } - const keyBytes = new Uint8Array([ - 233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64, - 166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, 145, - ]) - - await Client.createRandom({ - env: 'local', - enableV3: true, - preEnableIdentityCallback, - preCreateIdentityCallback, - preAuthenticateToInboxCallback, - dbEncryptionKey: keyBytes, - }) +// return true +// }) - assert( - isCallbackCalled === 3, - `callback should be called 3 times but was ${isCallbackCalled}` - ) +// test('can make a MLS V3 client with encryption key and database directory', async () => { +// // eslint-disable-next-line @typescript-eslint/no-unused-vars +// const dbDirPath = `${RNFS.DocumentDirectoryPath}/xmtp_db` +// const directoryExists = await RNFS.exists(dbDirPath) +// if (!directoryExists) { +// await RNFS.mkdir(dbDirPath) +// } +// const key = new Uint8Array([ +// 233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64, +// 166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, 145, +// ]) + +// const client = await Client.createRandom({ +// env: 'local', +// appVersion: 'Testing/0.0.0', +// enableV3: true, +// dbEncryptionKey: key, +// dbDirectory: dbDirPath, +// }) + +// const anotherClient = await Client.createRandom({ +// env: 'local', +// appVersion: 'Testing/0.0.0', +// enableV3: true, +// dbEncryptionKey: key, +// }) + +// await client.conversations.newGroup([anotherClient.address]) +// assert( +// (await client.conversations.listGroups()).length === 1, +// `should have a group size of 1 but was ${ +// (await client.conversations.listGroups()).length +// }` +// ) + +// const bundle = await client.exportKeyBundle() +// const clientFromBundle = await Client.createFromKeyBundle(bundle, { +// env: 'local', +// appVersion: 'Testing/0.0.0', +// enableV3: true, +// dbEncryptionKey: key, +// dbDirectory: dbDirPath, +// }) + +// assert( +// clientFromBundle.address === client.address, +// `clients dont match ${client.address} and ${clientFromBundle.address}` +// ) + +// assert( +// (await clientFromBundle.conversations.listGroups()).length === 1, +// `should have a group size of 1 but was ${ +// (await clientFromBundle.conversations.listGroups()).length +// }` +// ) +// return true +// }) - if (!isPreAuthCalled) { - throw new Error('preAuthenticateToInboxCallback not called') - } +// test('testing large group listing with metadata performance', async () => { +// const [alixClient, boClient] = await createClients(2) - return true -}) +// await createGroups(alixClient, [boClient], 50, 10) -test('can delete a local database', async () => { - let [client, anotherClient] = await createClients(2) +// let start = Date.now() +// let groups = await alixClient.conversations.listGroups() +// let end = Date.now() +// console.log(`Alix loaded ${groups.length} groups in ${end - start}ms`) - await client.conversations.newGroup([anotherClient.address]) - await client.conversations.syncGroups() - assert( - (await client.conversations.listGroups()).length === 1, - `should have a group size of 1 but was ${ - (await client.conversations.listGroups()).length - }` - ) +// start = Date.now() +// await alixClient.conversations.syncGroups() +// end = Date.now() +// console.log(`Alix synced ${groups.length} groups in ${end - start}ms`) - assert( - client.dbPath !== '', - `client dbPath should be set but was ${client.dbPath}` - ) - await client.deleteLocalDatabase() - client = await Client.createRandom({ - env: 'local', - appVersion: 'Testing/0.0.0', - enableV3: true, - dbEncryptionKey: new Uint8Array([ - 233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64, - 166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, - 145, - ]), - }) - await client.conversations.syncGroups() - assert( - (await client.conversations.listGroups()).length === 0, - `should have a group size of 0 but was ${ - (await client.conversations.listGroups()).length - }` - ) +// start = Date.now() +// await boClient.conversations.syncGroups() +// end = Date.now() +// console.log(`Bo synced ${groups.length} groups in ${end - start}ms`) - return true -}) +// start = Date.now() +// groups = await boClient.conversations.listGroups() +// end = Date.now() +// console.log(`Bo loaded ${groups.length} groups in ${end - start}ms`) -test('can make a MLS V3 client with encryption key and database directory', async () => { - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const dbDirPath = `${RNFS.DocumentDirectoryPath}/xmtp_db` - const directoryExists = await RNFS.exists(dbDirPath) - if (!directoryExists) { - await RNFS.mkdir(dbDirPath) - } - const key = new Uint8Array([ - 233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64, - 166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, 145, - ]) - - const client = await Client.createRandom({ - env: 'local', - appVersion: 'Testing/0.0.0', - enableV3: true, - dbEncryptionKey: key, - dbDirectory: dbDirPath, - }) - - const anotherClient = await Client.createRandom({ - env: 'local', - appVersion: 'Testing/0.0.0', - enableV3: true, - dbEncryptionKey: key, - }) - - await client.conversations.newGroup([anotherClient.address]) - assert( - (await client.conversations.listGroups()).length === 1, - `should have a group size of 1 but was ${ - (await client.conversations.listGroups()).length - }` - ) +// return true +// }) - const bundle = await client.exportKeyBundle() - const clientFromBundle = await Client.createFromKeyBundle(bundle, { - env: 'local', - appVersion: 'Testing/0.0.0', - enableV3: true, - dbEncryptionKey: key, - dbDirectory: dbDirPath, - }) +// test('can drop a local database', async () => { +// const [client, anotherClient] = await createClients(2) + +// const group = await client.conversations.newGroup([anotherClient.address]) +// await client.conversations.syncGroups() +// assert( +// (await client.conversations.listGroups()).length === 1, +// `should have a group size of 1 but was ${ +// (await client.conversations.listGroups()).length +// }` +// ) + +// await client.dropLocalDatabaseConnection() + +// try { +// await group.send('hi') +// // eslint-disable-next-line @typescript-eslint/no-unused-vars +// } catch (error) { +// await client.reconnectLocalDatabase() +// await group.send('hi') +// return true +// } +// throw new Error('should throw when local database not connected') +// }) - assert( - clientFromBundle.address === client.address, - `clients dont match ${client.address} and ${clientFromBundle.address}` - ) +// test('can drop client from memory', async () => { +// const [client, anotherClient] = await createClients(2) +// await client.dropLocalDatabaseConnection() +// await anotherClient.dropLocalDatabaseConnection() + +// await client.reconnectLocalDatabase() +// await Client.dropClient(anotherClient.inboxId) +// try { +// await anotherClient.reconnectLocalDatabase() +// return false +// // eslint-disable-next-line @typescript-eslint/no-unused-vars +// } catch (error) { +// // We cannot reconnect anotherClient because it was successfully dropped +// return true +// } +// }) - assert( - (await clientFromBundle.conversations.listGroups()).length === 1, - `should have a group size of 1 but was ${ - (await clientFromBundle.conversations.listGroups()).length - }` - ) - return true -}) +// test('can get a inboxId from an address', async () => { +// const [alix, bo] = await createClients(2) -test('testing large group listing with metadata performance', async () => { - const [alixClient, boClient] = await createClients(2) +// const boInboxId = await alix.findInboxIdFromAddress(bo.address) +// assert(boInboxId === bo.inboxId, `${boInboxId} should match ${bo.inboxId}`) +// return true +// }) - await createGroups(alixClient, [boClient], 50, 10) +// test('can make a MLS V3 client from bundle', async () => { +// const key = new Uint8Array([ +// 233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64, +// 166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, 145, +// ]) + +// const client = await Client.createRandom({ +// env: 'local', +// appVersion: 'Testing/0.0.0', +// enableV3: true, +// dbEncryptionKey: key, +// }) + +// const anotherClient = await Client.createRandom({ +// env: 'local', +// appVersion: 'Testing/0.0.0', +// enableV3: true, +// dbEncryptionKey: key, +// }) + +// const group1 = await client.conversations.newGroup([anotherClient.address]) + +// assert( +// group1.client.address === client.address, +// `clients dont match ${client.address} and ${group1.client.address}` +// ) + +// const bundle = await client.exportKeyBundle() +// const client2 = await Client.createFromKeyBundle(bundle, { +// env: 'local', +// appVersion: 'Testing/0.0.0', +// enableV3: true, +// dbEncryptionKey: key, +// }) + +// assert( +// client.address === client2.address, +// `clients dont match ${client2.address} and ${client.address}` +// ) + +// assert( +// client.inboxId === client2.inboxId, +// `clients dont match ${client2.inboxId} and ${client.inboxId}` +// ) + +// assert( +// client.installationId === client2.installationId, +// `clients dont match ${client2.installationId} and ${client.installationId}` +// ) + +// const randomClient = await Client.createRandom({ +// env: 'local', +// appVersion: 'Testing/0.0.0', +// enableV3: true, +// dbEncryptionKey: key, +// }) + +// const group = await client2.conversations.newGroup([randomClient.address]) + +// assert( +// group.client.address === client2.address, +// `clients dont match ${client2.address} and ${group.client.address}` +// ) - let start = Date.now() - let groups = await alixClient.conversations.listGroups() - let end = Date.now() - console.log(`Alix loaded ${groups.length} groups in ${end - start}ms`) +// return true +// }) - start = Date.now() - await alixClient.conversations.syncGroups() - end = Date.now() - console.log(`Alix synced ${groups.length} groups in ${end - start}ms`) +// test('production MLS V3 client creation does not error', async () => { +// const key = new Uint8Array([ +// 233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64, +// 166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, 145, +// ]) + +// try { +// await Client.createRandom({ +// env: 'production', +// appVersion: 'Testing/0.0.0', +// enableV3: true, +// dbEncryptionKey: key, +// }) +// // eslint-disable-next-line @typescript-eslint/no-unused-vars +// } catch (error) { +// throw error +// } +// return true +// }) - start = Date.now() - await boClient.conversations.syncGroups() - end = Date.now() - console.log(`Bo synced ${groups.length} groups in ${end - start}ms`) +// test('group message delivery status', async () => { +// const [alixClient, boClient] = await createClients(2) +// const alixGroup = await alixClient.conversations.newGroup([boClient.address]) - start = Date.now() - groups = await boClient.conversations.listGroups() - end = Date.now() - console.log(`Bo loaded ${groups.length} groups in ${end - start}ms`) +// await alixGroup.send('hello, world') - return true -}) +// const alixMessages: DecodedMessage[] = await alixGroup.messages() -test('can drop a local database', async () => { - const [client, anotherClient] = await createClients(2) +// assert( +// alixMessages.length === 2, +// `the messages length should be 2 but was ${alixMessages.length}` +// ) - const group = await client.conversations.newGroup([anotherClient.address]) - await client.conversations.syncGroups() - assert( - (await client.conversations.listGroups()).length === 1, - `should have a group size of 1 but was ${ - (await client.conversations.listGroups()).length - }` - ) +// const alixMessagesFiltered: DecodedMessage[] = await alixGroup.messages({ +// deliveryStatus: MessageDeliveryStatus.PUBLISHED, +// }) - await client.dropLocalDatabaseConnection() +// assert( +// alixMessagesFiltered.length === 2, +// `the messages length should be 2 but was ${alixMessagesFiltered.length}` +// ) - try { - await group.send('hi') - // eslint-disable-next-line @typescript-eslint/no-unused-vars - } catch (error) { - await client.reconnectLocalDatabase() - await group.send('hi') - return true - } - throw new Error('should throw when local database not connected') -}) +// await alixGroup.sync() +// const alixMessages2: DecodedMessage[] = await alixGroup.messages() -test('can drop client from memory', async () => { - const [client, anotherClient] = await createClients(2) - await client.dropLocalDatabaseConnection() - await anotherClient.dropLocalDatabaseConnection() - - await client.reconnectLocalDatabase() - await Client.dropClient(anotherClient.inboxId) - try { - await anotherClient.reconnectLocalDatabase() - return false - // eslint-disable-next-line @typescript-eslint/no-unused-vars - } catch (error) { - // We cannot reconnect anotherClient because it was successfully dropped - return true - } -}) +// assert( +// alixMessages2.length === 2, +// `the messages length should be 2 but was ${alixMessages.length}` +// ) -test('can get a inboxId from an address', async () => { - const [alix, bo] = await createClients(2) +// assert( +// alixMessages2[0].deliveryStatus === 'PUBLISHED', +// `the message should have a delivery status of PUBLISHED but was ${alixMessages2[0].deliveryStatus}` +// ) - const boInboxId = await alix.findInboxIdFromAddress(bo.address) - assert(boInboxId === bo.inboxId, `${boInboxId} should match ${bo.inboxId}`) - return true -}) +// await boClient.conversations.syncGroups() +// const boGroup = (await boClient.conversations.listGroups())[0] +// await boGroup.sync() +// const boMessages: DecodedMessage[] = await boGroup.messages() -test('can make a MLS V3 client from bundle', async () => { - const key = new Uint8Array([ - 233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64, - 166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, 145, - ]) +// assert( +// boMessages.length === 1, +// `the messages length should be 1 but was ${boMessages.length}` +// ) - const client = await Client.createRandom({ - env: 'local', - appVersion: 'Testing/0.0.0', - enableV3: true, - dbEncryptionKey: key, - }) +// assert( +// boMessages[0].deliveryStatus === 'PUBLISHED', +// `the message should have a delivery status of PUBLISHED but was ${boMessages[0].deliveryStatus}` +// ) - const anotherClient = await Client.createRandom({ - env: 'local', - appVersion: 'Testing/0.0.0', - enableV3: true, - dbEncryptionKey: key, - }) +// return true +// }) - const group1 = await client.conversations.newGroup([anotherClient.address]) +// test('can find a group by id', async () => { +// const [alixClient, boClient] = await createClients(2) +// const alixGroup = await alixClient.conversations.newGroup([boClient.address]) - assert( - group1.client.address === client.address, - `clients dont match ${client.address} and ${group1.client.address}` - ) +// await boClient.conversations.syncGroups() +// const boGroup = await boClient.conversations.findGroup(alixGroup.id) - const bundle = await client.exportKeyBundle() - const client2 = await Client.createFromKeyBundle(bundle, { - env: 'local', - appVersion: 'Testing/0.0.0', - enableV3: true, - dbEncryptionKey: key, - }) +// assert( +// boGroup?.id === alixGroup.id, +// `bo ${boGroup?.id} does not match alix ${alixGroup.id}` +// ) +// return true +// }) - assert( - client.address === client2.address, - `clients dont match ${client2.address} and ${client.address}` - ) +// test('can find a message by id', async () => { +// const [alixClient, boClient] = await createClients(2) +// const alixGroup = await alixClient.conversations.newGroup([boClient.address]) +// const alixMessageId = await alixGroup.send('Hello') - assert( - client.inboxId === client2.inboxId, - `clients dont match ${client2.inboxId} and ${client.inboxId}` - ) +// await boClient.conversations.syncGroups() +// const boGroup = await boClient.conversations.findGroup(alixGroup.id) +// await boGroup?.sync() +// const boMessage = await boClient.conversations.findV3Message(alixMessageId) - assert( - client.installationId === client2.installationId, - `clients dont match ${client2.installationId} and ${client.installationId}` - ) +// assert( +// boMessage?.id === alixMessageId, +// `bo message ${boMessage?.id} does not match ${alixMessageId}` +// ) +// return true +// }) - const randomClient = await Client.createRandom({ - env: 'local', - appVersion: 'Testing/0.0.0', - enableV3: true, - dbEncryptionKey: key, - }) +// test('who added me to a group', async () => { +// const [alixClient, boClient] = await createClients(2) +// await alixClient.conversations.newGroup([boClient.address]) - const group = await client2.conversations.newGroup([randomClient.address]) +// await boClient.conversations.syncGroups() +// const boGroup = (await boClient.conversations.listGroups())[0] +// const addedByInboxId = await boGroup.addedByInboxId - assert( - group.client.address === client2.address, - `clients dont match ${client2.address} and ${group.client.address}` - ) +// assert( +// addedByInboxId === alixClient.inboxId, +// `addedByInboxId ${addedByInboxId} does not match ${alixClient.inboxId}` +// ) +// return true +// }) - return true -}) +// test('can get members of a group', async () => { +// const [alixClient, boClient] = await createClients(2) +// const group = await alixClient.conversations.newGroup([boClient.address]) + +// const members = group.members + +// assert(members.length === 2, `Should be 2 members but was ${members.length}`) + +// // We can not be sure of the order that members will be returned in +// for (const member of members) { +// // Alix created the group so they are a super admin +// if ( +// member.addresses[0].toLocaleLowerCase() === +// alixClient.address.toLocaleLowerCase() +// ) { +// assert( +// member.permissionLevel === 'super_admin', +// `Should be super_admin but was ${member.permissionLevel}` +// ) +// } +// // Bo did not create the group so he defaults to permission level "member" +// if ( +// member.addresses[0].toLocaleLowerCase() === +// boClient.address.toLocaleLowerCase() +// ) { +// assert( +// member.permissionLevel === 'member', +// `Should be member but was ${member.permissionLevel}` +// ) +// } +// } +// return true +// }) -test('production MLS V3 client creation does not error', async () => { - const key = new Uint8Array([ - 233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64, - 166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, 145, - ]) - - try { - await Client.createRandom({ - env: 'production', - appVersion: 'Testing/0.0.0', - enableV3: true, - dbEncryptionKey: key, - }) - // eslint-disable-next-line @typescript-eslint/no-unused-vars - } catch (error) { - throw error - } - return true -}) +// test('can message in a group', async () => { +// // Create three MLS enabled Clients +// const [alixClient, boClient, caroClient] = await createClients(3) -test('group message delivery status', async () => { - const [alixClient, boClient] = await createClients(2) - const alixGroup = await alixClient.conversations.newGroup([boClient.address]) +// // alix's num groups start at 0 +// let alixGroups = await alixClient.conversations.listGroups() +// if (alixGroups.length !== 0) { +// throw new Error('num groups should be 0') +// } - await alixGroup.send('hello, world') +// // alix creates a group +// const alixGroup = await alixClient.conversations.newGroup([ +// boClient.address, +// caroClient.address, +// ]) + +// // alix's num groups == 1 +// await alixClient.conversations.syncGroups() +// alixGroups = await alixClient.conversations.listGroups() +// if (alixGroups.length !== 1) { +// throw new Error('num groups should be 1') +// } - const alixMessages: DecodedMessage[] = await alixGroup.messages() +// // alix group should match create time from list function +// assert(alixGroups[0].createdAt === alixGroup.createdAt, 'group create time') - assert( - alixMessages.length === 2, - `the messages length should be 2 but was ${alixMessages.length}` - ) +// // alix can confirm memberInboxIds +// await alixGroup.sync() +// const memberInboxIds = await alixGroup.memberInboxIds() +// if (memberInboxIds.length !== 3) { +// throw new Error('num group members should be 3') +// } - const alixMessagesFiltered: DecodedMessage[] = await alixGroup.messages({ - deliveryStatus: MessageDeliveryStatus.PUBLISHED, - }) +// if ( +// !( +// memberInboxIds.includes(alixClient.inboxId) && +// memberInboxIds.includes(boClient.inboxId) && +// memberInboxIds.includes(caroClient.inboxId) +// ) +// ) { +// throw new Error('missing address') +// } - assert( - alixMessagesFiltered.length === 2, - `the messages length should be 2 but was ${alixMessagesFiltered.length}` - ) +// // alix can send messages +// await alixGroup.send('hello, world') +// await alixGroup.send('gm') + +// // bo's num groups == 1 +// await boClient.conversations.syncGroups() +// const boGroups = await boClient.conversations.listGroups() +// if (boGroups.length !== 1) { +// throw new Error( +// 'num groups for bo should be 1, but it is' + boGroups.length +// ) +// } +// await delayToPropogate() +// // bo can read messages from alix +// await boGroups[0].sync() +// const boMessages: DecodedMessage[] = await boGroups[0].messages() + +// if (boMessages.length !== 2) { +// throw new Error( +// 'num messages for bo should be 2, but it is' + boMessages.length +// ) +// } +// if (boMessages[0].content() !== 'gm') { +// throw new Error("newest message should be 'gm'") +// } +// if (boMessages[1].content() !== 'hello, world') { +// throw new Error("newest message should be 'hello, world'") +// } +// // bo can send a message +// await boGroups[0].send('hey guys!') + +// // caro's num groups == 1 +// await caroClient.conversations.syncGroups() +// const caroGroups = await caroClient.conversations.listGroups() +// if (caroGroups.length !== 1) { +// throw new Error( +// 'num groups for caro should be 1, but it is' + caroGroups.length +// ) +// } - await alixGroup.sync() - const alixMessages2: DecodedMessage[] = await alixGroup.messages() +// // caro can read messages from alix and bo +// await caroGroups[0].sync() +// const caroMessages = await caroGroups[0].messages() - assert( - alixMessages2.length === 2, - `the messages length should be 2 but was ${alixMessages.length}` - ) +// if (caroMessages.length !== 3) { +// throw new Error(`length should be 3 but was ${caroMessages.length}`) +// } +// if (caroMessages[0].content() !== 'hey guys!') { +// throw new Error( +// `newest Message should be 'hey guys!' but was ${caroMessages[0].content()}` +// ) +// } +// if (caroMessages[1].content() !== 'gm') { +// throw new Error( +// `second Message should be 'gm' but was ${caroMessages[1].content()}` +// ) +// } - assert( - alixMessages2[0].deliveryStatus === 'PUBLISHED', - `the message should have a delivery status of PUBLISHED but was ${alixMessages2[0].deliveryStatus}` - ) +// return true +// }) - await boClient.conversations.syncGroups() - const boGroup = (await boClient.conversations.listGroups())[0] - await boGroup.sync() - const boMessages: DecodedMessage[] = await boGroup.messages() +// test('unpublished messages handling', async () => { +// // Initialize fixture clients +// const [alixClient, boClient] = await createClients(3) - assert( - boMessages.length === 1, - `the messages length should be 1 but was ${boMessages.length}` - ) +// // Create a new group with Bob and Alice +// const boGroup = await boClient.conversations.newGroup([alixClient.address]) - assert( - boMessages[0].deliveryStatus === 'PUBLISHED', - `the message should have a delivery status of PUBLISHED but was ${boMessages[0].deliveryStatus}` - ) +// // Sync Alice's client to get the new group +// await alixClient.conversations.syncGroups() +// const alixGroup = await alixClient.conversations.findGroup(boGroup.id) +// if (!alixGroup) { +// throw new Error(`Group not found for id: ${boGroup.id}`) +// } - return true -}) +// // Check if the group is allowed initially +// let isGroupAllowed = await alixClient.contacts.isGroupAllowed(boGroup.id) +// if (isGroupAllowed) { +// throw new Error('Group should not be allowed initially') +// } -test('can find a group by id', async () => { - const [alixClient, boClient] = await createClients(2) - const alixGroup = await alixClient.conversations.newGroup([boClient.address]) +// // Prepare a message in the group +// const preparedMessageId = await alixGroup.prepareMessage('Test text') - await boClient.conversations.syncGroups() - const boGroup = await boClient.conversations.findGroup(alixGroup.id) +// // Check if the group is allowed after preparing the message +// isGroupAllowed = await alixClient.contacts.isGroupAllowed(boGroup.id) +// if (!isGroupAllowed) { +// throw new Error('Group should be allowed after preparing a message') +// } - assert( - boGroup?.id === alixGroup.id, - `bo ${boGroup?.id} does not match alix ${alixGroup.id}` - ) - return true -}) +// // Verify the message count in the group +// let messageCount = (await alixGroup.messages()).length +// if (messageCount !== 1) { +// throw new Error(`Message count should be 1, but it is ${messageCount}`) +// } -test('can find a message by id', async () => { - const [alixClient, boClient] = await createClients(2) - const alixGroup = await alixClient.conversations.newGroup([boClient.address]) - const alixMessageId = await alixGroup.send('Hello') +// // Verify the count of published and unpublished messages +// let messageCountPublished = ( +// await alixGroup.messages({ +// deliveryStatus: MessageDeliveryStatus.PUBLISHED, +// }) +// ).length +// let messageCountUnpublished = ( +// await alixGroup.messages({ +// deliveryStatus: MessageDeliveryStatus.UNPUBLISHED, +// }) +// ).length +// if (messageCountPublished !== 0) { +// throw new Error( +// `Published message count should be 0, but it is ${messageCountPublished}` +// ) +// } +// if (messageCountUnpublished !== 1) { +// throw new Error( +// `Unpublished message count should be 1, but it is ${messageCountUnpublished}` +// ) +// } - await boClient.conversations.syncGroups() - const boGroup = await boClient.conversations.findGroup(alixGroup.id) - await boGroup?.sync() - const boMessage = await boClient.conversations.findV3Message(alixMessageId) +// // Publish the prepared message +// await alixGroup.publishPreparedMessages() + +// // Sync the group after publishing the message +// await alixGroup.sync() + +// // Verify the message counts again +// messageCountPublished = ( +// await alixGroup.messages({ +// deliveryStatus: MessageDeliveryStatus.PUBLISHED, +// }) +// ).length +// messageCountUnpublished = ( +// await alixGroup.messages({ +// deliveryStatus: MessageDeliveryStatus.UNPUBLISHED, +// }) +// ).length +// messageCount = (await alixGroup.messages()).length +// if (messageCountPublished !== 1) { +// throw new Error( +// `Published message count should be 1, but it is ${messageCountPublished}` +// ) +// } +// if (messageCountUnpublished !== 0) { +// throw new Error( +// `Unpublished message count should be 0, but it is ${messageCountUnpublished}` +// ) +// } +// if (messageCount !== 1) { +// throw new Error(`Message count should be 1, but it is ${messageCount}`) +// } - assert( - boMessage?.id === alixMessageId, - `bo message ${boMessage?.id} does not match ${alixMessageId}` - ) - return true -}) +// // Retrieve all messages and verify the prepared message ID +// const messages = await alixGroup.messages() +// if (preparedMessageId !== messages[0].id) { +// throw new Error(`Message ID should match the prepared message ID`) +// } -test('who added me to a group', async () => { - const [alixClient, boClient] = await createClients(2) - await alixClient.conversations.newGroup([boClient.address]) +// return true +// }) - await boClient.conversations.syncGroups() - const boGroup = (await boClient.conversations.listGroups())[0] - const addedByInboxId = await boGroup.addedByInboxId +// test('can add members to a group', async () => { +// // Create three MLS enabled Clients +// const [alixClient, boClient, caroClient] = await createClients(3) - assert( - addedByInboxId === alixClient.inboxId, - `addedByInboxId ${addedByInboxId} does not match ${alixClient.inboxId}` - ) - return true -}) +// // alix's num groups start at 0 +// let alixGroups = await alixClient.conversations.listGroups() +// if (alixGroups.length !== 0) { +// throw new Error('num groups should be 0') +// } -test('can get members of a group', async () => { - const [alixClient, boClient] = await createClients(2) - const group = await alixClient.conversations.newGroup([boClient.address]) - - const members = group.members - - assert(members.length === 2, `Should be 2 members but was ${members.length}`) - - // We can not be sure of the order that members will be returned in - for (const member of members) { - // Alix created the group so they are a super admin - if ( - member.addresses[0].toLocaleLowerCase() === - alixClient.address.toLocaleLowerCase() - ) { - assert( - member.permissionLevel === 'super_admin', - `Should be super_admin but was ${member.permissionLevel}` - ) - } - // Bo did not create the group so he defaults to permission level "member" - if ( - member.addresses[0].toLocaleLowerCase() === - boClient.address.toLocaleLowerCase() - ) { - assert( - member.permissionLevel === 'member', - `Should be member but was ${member.permissionLevel}` - ) - } - } - return true -}) +// // bo's num groups start at 0 +// let boGroups = await boClient.conversations.listGroups() +// if (boGroups.length !== 0) { +// throw new Error('num groups should be 0') +// } -test('can message in a group', async () => { - // Create three MLS enabled Clients - const [alixClient, boClient, caroClient] = await createClients(3) +// // caro's num groups start at 0 +// let caroGroups = await caroClient.conversations.listGroups() +// if (caroGroups.length !== 0) { +// throw new Error('num groups should be 0') +// } - // alix's num groups start at 0 - let alixGroups = await alixClient.conversations.listGroups() - if (alixGroups.length !== 0) { - throw new Error('num groups should be 0') - } +// // alix creates a group +// const alixGroup = await alixClient.conversations.newGroup([boClient.address]) - // alix creates a group - const alixGroup = await alixClient.conversations.newGroup([ - boClient.address, - caroClient.address, - ]) - - // alix's num groups == 1 - await alixClient.conversations.syncGroups() - alixGroups = await alixClient.conversations.listGroups() - if (alixGroups.length !== 1) { - throw new Error('num groups should be 1') - } +// // alix's num groups == 1 +// await alixClient.conversations.syncGroups() +// alixGroups = await alixClient.conversations.listGroups() +// if (alixGroups.length !== 1) { +// throw new Error('num groups should be 1') +// } - // alix group should match create time from list function - assert(alixGroups[0].createdAt === alixGroup.createdAt, 'group create time') +// // alix can confirm memberInboxIds +// await alixGroup.sync() +// const memberInboxIds = await alixGroup.memberInboxIds() +// if (memberInboxIds.length !== 2) { +// throw new Error('num group members should be 2') +// } +// if ( +// !( +// memberInboxIds.includes(alixClient.inboxId) && +// memberInboxIds.includes(boClient.inboxId) +// ) +// ) { +// throw new Error('missing address') +// } - // alix can confirm memberInboxIds - await alixGroup.sync() - const memberInboxIds = await alixGroup.memberInboxIds() - if (memberInboxIds.length !== 3) { - throw new Error('num group members should be 3') - } +// // alix can send messages +// await alixGroup.send('hello, world') +// await alixGroup.send('gm') + +// // bo's num groups == 1 +// await boClient.conversations.syncGroups() +// boGroups = await boClient.conversations.listGroups() +// if (boGroups.length !== 1) { +// throw new Error( +// 'num groups for bo should be 1, but it is' + boGroups.length +// ) +// } - if ( - !( - memberInboxIds.includes(alixClient.inboxId) && - memberInboxIds.includes(boClient.inboxId) && - memberInboxIds.includes(caroClient.inboxId) - ) - ) { - throw new Error('missing address') - } +// await alixGroup.addMembers([caroClient.address]) - // alix can send messages - await alixGroup.send('hello, world') - await alixGroup.send('gm') - - // bo's num groups == 1 - await boClient.conversations.syncGroups() - const boGroups = await boClient.conversations.listGroups() - if (boGroups.length !== 1) { - throw new Error( - 'num groups for bo should be 1, but it is' + boGroups.length - ) - } - await delayToPropogate() - // bo can read messages from alix - await boGroups[0].sync() - const boMessages: DecodedMessage[] = await boGroups[0].messages() - - if (boMessages.length !== 2) { - throw new Error( - 'num messages for bo should be 2, but it is' + boMessages.length - ) - } - if (boMessages[0].content() !== 'gm') { - throw new Error("newest message should be 'gm'") - } - if (boMessages[1].content() !== 'hello, world') { - throw new Error("newest message should be 'hello, world'") - } - // bo can send a message - await boGroups[0].send('hey guys!') - - // caro's num groups == 1 - await caroClient.conversations.syncGroups() - const caroGroups = await caroClient.conversations.listGroups() - if (caroGroups.length !== 1) { - throw new Error( - 'num groups for caro should be 1, but it is' + caroGroups.length - ) - } +// // caro's num groups == 1 +// await caroClient.conversations.syncGroups() +// caroGroups = await caroClient.conversations.listGroups() +// if (caroGroups.length !== 1) { +// throw new Error( +// 'num groups for caro should be 1, but it is' + caroGroups.length +// ) +// } +// await caroGroups[0].sync() +// const caroMessages = await caroGroups[0].messages() +// if (caroMessages.length !== 0) { +// throw new Error('num messages for caro should be 0') +// } - // caro can read messages from alix and bo - await caroGroups[0].sync() - const caroMessages = await caroGroups[0].messages() +// await boGroups[0].sync() +// const boGroupMembers = await boGroups[0].memberInboxIds() +// if (boGroupMembers.length !== 3) { +// throw new Error('num group members should be 3') +// } - if (caroMessages.length !== 3) { - throw new Error(`length should be 3 but was ${caroMessages.length}`) - } - if (caroMessages[0].content() !== 'hey guys!') { - throw new Error( - `newest Message should be 'hey guys!' but was ${caroMessages[0].content()}` - ) - } - if (caroMessages[1].content() !== 'gm') { - throw new Error( - `second Message should be 'gm' but was ${caroMessages[1].content()}` - ) - } +// return true +// }) - return true -}) +// test('can remove members from a group', async () => { +// // Create three MLS enabled Clients +// const [alixClient, boClient, caroClient] = await createClients(3) -test('unpublished messages handling', async () => { - // Initialize fixture clients - const [alixClient, boClient] = await createClients(3) +// // alix's num groups start at 0 +// let alixGroups = await alixClient.conversations.listGroups() +// if (alixGroups.length !== 0) { +// throw new Error('num groups should be 0') +// } - // Create a new group with Bob and Alice - const boGroup = await boClient.conversations.newGroup([alixClient.address]) +// // bo's num groups start at 0 +// let boGroups = await boClient.conversations.listGroups() +// assert(boGroups.length === 0, 'num groups should be 0') - // Sync Alice's client to get the new group - await alixClient.conversations.syncGroups() - const alixGroup = await alixClient.conversations.findGroup(boGroup.id) - if (!alixGroup) { - throw new Error(`Group not found for id: ${boGroup.id}`) - } +// // caro's num groups start at 0 +// let caroGroups = await caroClient.conversations.listGroups() +// if (caroGroups.length !== 0) { +// throw new Error('num groups should be 0') +// } - // Check if the group is allowed initially - let isGroupAllowed = await alixClient.contacts.isGroupAllowed(boGroup.id) - if (isGroupAllowed) { - throw new Error('Group should not be allowed initially') - } +// // alix creates a group +// const alixGroup = await alixClient.conversations.newGroup([ +// boClient.address, +// caroClient.address, +// ]) + +// // alix's num groups == 1 +// await alixClient.conversations.syncGroups() +// alixGroups = await alixClient.conversations.listGroups() +// if (alixGroups.length !== 1) { +// throw new Error('num groups should be 1') +// } + +// // alix can confirm memberInboxIds +// await alixGroup.sync() +// const memberInboxIds = await alixGroup.memberInboxIds() +// if (memberInboxIds.length !== 3) { +// throw new Error('num group members should be 3') +// } +// if ( +// !( +// memberInboxIds.includes(alixClient.inboxId) && +// memberInboxIds.includes(boClient.inboxId) +// ) +// ) { +// throw new Error('missing address') +// } - // Prepare a message in the group - const preparedMessageId = await alixGroup.prepareMessage('Test text') +// // alix can send messages +// await alixGroup.send('hello, world') +// await alixGroup.send('gm') + +// // bo's num groups == 1 +// await boClient.conversations.syncGroups() +// boGroups = await boClient.conversations.listGroups() +// if (boGroups.length !== 1) { +// throw new Error( +// 'num groups for bo should be 1, but it is' + boGroups.length +// ) +// } - // Check if the group is allowed after preparing the message - isGroupAllowed = await alixClient.contacts.isGroupAllowed(boGroup.id) - if (!isGroupAllowed) { - throw new Error('Group should be allowed after preparing a message') - } +// // caro's num groups == 1 +// await caroClient.conversations.syncGroups() +// caroGroups = await caroClient.conversations.listGroups() +// if (caroGroups.length !== 1) { +// throw new Error( +// 'num groups for caro should be 1, but it is' + caroGroups.length +// ) +// } - // Verify the message count in the group - let messageCount = (await alixGroup.messages()).length - if (messageCount !== 1) { - throw new Error(`Message count should be 1, but it is ${messageCount}`) - } +// await caroGroups[0].sync() +// if (!caroGroups[0].isActive()) { +// throw new Error('caros group should be active') +// } - // Verify the count of published and unpublished messages - let messageCountPublished = ( - await alixGroup.messages({ - deliveryStatus: MessageDeliveryStatus.PUBLISHED, - }) - ).length - let messageCountUnpublished = ( - await alixGroup.messages({ - deliveryStatus: MessageDeliveryStatus.UNPUBLISHED, - }) - ).length - if (messageCountPublished !== 0) { - throw new Error( - `Published message count should be 0, but it is ${messageCountPublished}` - ) - } - if (messageCountUnpublished !== 1) { - throw new Error( - `Unpublished message count should be 1, but it is ${messageCountUnpublished}` - ) - } +// await alixGroup.removeMembers([caroClient.address]) +// await alixGroup.sync() +// const alixGroupMembers = await alixGroup.memberInboxIds() +// if (alixGroupMembers.length !== 2) { +// throw new Error( +// 'num group members should be 2 but was' + alixGroupMembers.length +// ) +// } - // Publish the prepared message - await alixGroup.publishPreparedMessages() +// await caroGroups[0].sync() +// if (await caroGroups[0].isActive()) { +// throw new Error('caros group should not be active') +// } - // Sync the group after publishing the message - await alixGroup.sync() +// const caroGroupMembers = await caroGroups[0].memberInboxIds() +// if (caroGroupMembers.length !== 2) { +// throw new Error( +// 'num group members should be 2 but was' + caroGroupMembers.length +// ) +// } - // Verify the message counts again - messageCountPublished = ( - await alixGroup.messages({ - deliveryStatus: MessageDeliveryStatus.PUBLISHED, - }) - ).length - messageCountUnpublished = ( - await alixGroup.messages({ - deliveryStatus: MessageDeliveryStatus.UNPUBLISHED, - }) - ).length - messageCount = (await alixGroup.messages()).length - if (messageCountPublished !== 1) { - throw new Error( - `Published message count should be 1, but it is ${messageCountPublished}` - ) - } - if (messageCountUnpublished !== 0) { - throw new Error( - `Unpublished message count should be 0, but it is ${messageCountUnpublished}` - ) - } - if (messageCount !== 1) { - throw new Error(`Message count should be 1, but it is ${messageCount}`) - } +// return true +// }) - // Retrieve all messages and verify the prepared message ID - const messages = await alixGroup.messages() - if (preparedMessageId !== messages[0].id) { - throw new Error(`Message ID should match the prepared message ID`) - } +// test('can remove and add members from a group by inbox id', async () => { +// // Create three MLS enabled Clients +// const [alixClient, boClient, caroClient] = await createClients(3) + +// // alix creates a group +// const alixGroup = await alixClient.conversations.newGroup([ +// boClient.address, +// caroClient.address, +// ]) + +// // alix can confirm memberInboxIds +// await alixGroup.sync() +// const memberInboxIds = await alixGroup.memberInboxIds() +// if (memberInboxIds.length !== 3) { +// throw new Error('num group members should be 3') +// } - return true -}) +// await alixGroup.removeMembersByInboxId([caroClient.inboxId]) +// await alixGroup.sync() +// const alixGroupMembers = await alixGroup.memberInboxIds() +// if (alixGroupMembers.length !== 2) { +// throw new Error('num group members should be 2') +// } -test('can add members to a group', async () => { - // Create three MLS enabled Clients - const [alixClient, boClient, caroClient] = await createClients(3) +// await alixGroup.addMembersByInboxId([caroClient.inboxId]) +// await alixGroup.sync() +// const alixGroupMembers2 = await alixGroup.memberInboxIds() +// if (alixGroupMembers2.length !== 3) { +// throw new Error('num group members should be 3') +// } - // alix's num groups start at 0 - let alixGroups = await alixClient.conversations.listGroups() - if (alixGroups.length !== 0) { - throw new Error('num groups should be 0') - } +// return true +// }) - // bo's num groups start at 0 - let boGroups = await boClient.conversations.listGroups() - if (boGroups.length !== 0) { - throw new Error('num groups should be 0') - } +test('can cancel streams', async () => { + const [alix, bo] = await createClients(2) + let messageCallbacks = 0 - // caro's num groups start at 0 - let caroGroups = await caroClient.conversations.listGroups() - if (caroGroups.length !== 0) { - throw new Error('num groups should be 0') - } + await bo.conversations.streamAllMessages(async () => { + messageCallbacks++ + }, true) - // alix creates a group - const alixGroup = await alixClient.conversations.newGroup([boClient.address]) + const group = await alix.conversations.newGroup([bo.address]) + await group.send('hello') + await delayToPropogate() - // alix's num groups == 1 - await alixClient.conversations.syncGroups() - alixGroups = await alixClient.conversations.listGroups() - if (alixGroups.length !== 1) { - throw new Error('num groups should be 1') - } + assert( + messageCallbacks === 1, + 'message stream should have received 1 message' + ) - // alix can confirm memberInboxIds - await alixGroup.sync() - const memberInboxIds = await alixGroup.memberInboxIds() - if (memberInboxIds.length !== 2) { - throw new Error('num group members should be 2') - } - if ( - !( - memberInboxIds.includes(alixClient.inboxId) && - memberInboxIds.includes(boClient.inboxId) - ) - ) { - throw new Error('missing address') - } + await bo.conversations.cancelStreamAllMessages() + await delayToPropogate() - // alix can send messages - await alixGroup.send('hello, world') - await alixGroup.send('gm') - - // bo's num groups == 1 - await boClient.conversations.syncGroups() - boGroups = await boClient.conversations.listGroups() - if (boGroups.length !== 1) { - throw new Error( - 'num groups for bo should be 1, but it is' + boGroups.length - ) - } + await group.send('hello') + // await group.send('hello') + // await group.send('hello') - await alixGroup.addMembers([caroClient.address]) + await delayToPropogate() - // caro's num groups == 1 - await caroClient.conversations.syncGroups() - caroGroups = await caroClient.conversations.listGroups() - if (caroGroups.length !== 1) { - throw new Error( - 'num groups for caro should be 1, but it is' + caroGroups.length - ) - } - await caroGroups[0].sync() - const caroMessages = await caroGroups[0].messages() - if (caroMessages.length !== 0) { - throw new Error('num messages for caro should be 0') - } + assert( + messageCallbacks === 1, + 'message stream should still only received 1 message' + ) - await boGroups[0].sync() - const boGroupMembers = await boGroups[0].memberInboxIds() - if (boGroupMembers.length !== 3) { - throw new Error('num group members should be 3') - } + // await bo.conversations.streamAllMessages(async () => { + // messageCallbacks++ + // }, true) + + // await group.send('hello') + // await delayToPropogate() + + // assert( + // messageCallbacks === 2, + // 'message stream should have received 2 message' + // ) return true }) -test('can remove members from a group', async () => { - // Create three MLS enabled Clients - const [alixClient, boClient, caroClient] = await createClients(3) - - // alix's num groups start at 0 - let alixGroups = await alixClient.conversations.listGroups() - if (alixGroups.length !== 0) { - throw new Error('num groups should be 0') - } +// test('can stream both groups and messages at same time', async () => { +// const [alix, bo] = await createClients(2) - // bo's num groups start at 0 - let boGroups = await boClient.conversations.listGroups() - assert(boGroups.length === 0, 'num groups should be 0') +// let groupCallbacks = 0 +// let messageCallbacks = 0 +// await bo.conversations.streamGroups(async () => { +// groupCallbacks++ +// }) - // caro's num groups start at 0 - let caroGroups = await caroClient.conversations.listGroups() - if (caroGroups.length !== 0) { - throw new Error('num groups should be 0') - } +// await bo.conversations.streamAllMessages(async () => { +// messageCallbacks++ +// }, true) - // alix creates a group - const alixGroup = await alixClient.conversations.newGroup([ - boClient.address, - caroClient.address, - ]) - - // alix's num groups == 1 - await alixClient.conversations.syncGroups() - alixGroups = await alixClient.conversations.listGroups() - if (alixGroups.length !== 1) { - throw new Error('num groups should be 1') - } +// const group = await alix.conversations.newGroup([bo.address]) +// await group.send('hello') - // alix can confirm memberInboxIds - await alixGroup.sync() - const memberInboxIds = await alixGroup.memberInboxIds() - if (memberInboxIds.length !== 3) { - throw new Error('num group members should be 3') - } - if ( - !( - memberInboxIds.includes(alixClient.inboxId) && - memberInboxIds.includes(boClient.inboxId) - ) - ) { - throw new Error('missing address') - } - - // alix can send messages - await alixGroup.send('hello, world') - await alixGroup.send('gm') - - // bo's num groups == 1 - await boClient.conversations.syncGroups() - boGroups = await boClient.conversations.listGroups() - if (boGroups.length !== 1) { - throw new Error( - 'num groups for bo should be 1, but it is' + boGroups.length - ) - } - - // caro's num groups == 1 - await caroClient.conversations.syncGroups() - caroGroups = await caroClient.conversations.listGroups() - if (caroGroups.length !== 1) { - throw new Error( - 'num groups for caro should be 1, but it is' + caroGroups.length - ) - } - - await caroGroups[0].sync() - if (!caroGroups[0].isActive()) { - throw new Error('caros group should be active') - } - - await alixGroup.removeMembers([caroClient.address]) - await alixGroup.sync() - const alixGroupMembers = await alixGroup.memberInboxIds() - if (alixGroupMembers.length !== 2) { - throw new Error( - 'num group members should be 2 but was' + alixGroupMembers.length - ) - } - - await caroGroups[0].sync() - if (await caroGroups[0].isActive()) { - throw new Error('caros group should not be active') - } - - const caroGroupMembers = await caroGroups[0].memberInboxIds() - if (caroGroupMembers.length !== 2) { - throw new Error( - 'num group members should be 2 but was' + caroGroupMembers.length - ) - } - - return true -}) - -test('can remove and add members from a group by inbox id', async () => { - // Create three MLS enabled Clients - const [alixClient, boClient, caroClient] = await createClients(3) - - // alix creates a group - const alixGroup = await alixClient.conversations.newGroup([ - boClient.address, - caroClient.address, - ]) - - // alix can confirm memberInboxIds - await alixGroup.sync() - const memberInboxIds = await alixGroup.memberInboxIds() - if (memberInboxIds.length !== 3) { - throw new Error('num group members should be 3') - } - - await alixGroup.removeMembersByInboxId([caroClient.inboxId]) - await alixGroup.sync() - const alixGroupMembers = await alixGroup.memberInboxIds() - if (alixGroupMembers.length !== 2) { - throw new Error('num group members should be 2') - } - - await alixGroup.addMembersByInboxId([caroClient.inboxId]) - await alixGroup.sync() - const alixGroupMembers2 = await alixGroup.memberInboxIds() - if (alixGroupMembers2.length !== 3) { - throw new Error('num group members should be 3') - } - - return true -}) - -test('can stream both groups and messages at same time', async () => { - const [alix, bo] = await createClients(2) - - let groupCallbacks = 0 - let messageCallbacks = 0 - await bo.conversations.streamGroups(async () => { - groupCallbacks++ - }) - - await bo.conversations.streamAllMessages(async () => { - messageCallbacks++ - }, true) - - const group = await alix.conversations.newGroup([bo.address]) - await group.send('hello') - - await delayToPropogate() - // await new Promise((resolve) => setTimeout(resolve, 10000)) - assert( - messageCallbacks === 1, - 'message stream should have received 1 message' - ) - assert(groupCallbacks === 1, 'group stream should have received 1 group') - return true -}) - -test('can stream groups', async () => { - const [alixClient, boClient, caroClient] = await createClients(3) - - // Start streaming groups - const groups: Group[] = [] - const cancelStreamGroups = await alixClient.conversations.streamGroups( - async (group: Group) => { - groups.push(group) - } - ) - - // caro creates a group with alix, so stream callback is fired - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const caroGroup = await caroClient.conversations.newGroup([ - alixClient.address, - ]) - await delayToPropogate() - if ((groups.length as number) !== 1) { - throw Error('Unexpected num groups (should be 1): ' + groups.length) - } - - assert(groups[0].members.length === 2, 'should be 2') - - // bo creates a group with alix so a stream callback is fired - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const boGroup = await boClient.conversations.newGroup([alixClient.address]) - await delayToPropogate() - if ((groups.length as number) !== 2) { - throw Error('Unexpected num groups (should be 2): ' + groups.length) - } - - // * Note alix creating a group does not trigger alix conversations - // group stream. Workaround is to syncGroups after you create and list manually - // See https://github.com/xmtp/libxmtp/issues/504 - - // alix creates a group - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const alixGroup = await alixClient.conversations.newGroup([ - boClient.address, - caroClient.address, - ]) - await delayToPropogate() - if (groups.length !== 3) { - throw Error('Expected group length 3 but it is: ' + groups.length) - } - // Sync groups after creation if you created a group - const listedGroups = await alixClient.conversations.listGroups() - await delayToPropogate() - groups.push(listedGroups[listedGroups.length - 1]) - if ((groups.length as number) !== 4) { - throw Error('Expected group length 4 but it is: ' + groups.length) - } - - cancelStreamGroups() - await delayToPropogate() - - // Creating a group should no longer trigger stream groups - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const caroSecond = await caroClient.conversations.newGroup([ - alixClient.address, - ]) - await delayToPropogate() - if ((groups.length as number) !== 4) { - throw Error('Unexpected num groups (should be 4): ' + groups.length) - } - - return true -}) - -test('can list groups', async () => { - const [alixClient, boClient] = await createClients(2) - - const group1 = await boClient.conversations.newGroup([alixClient.address], { - name: 'group1 name', - imageUrlSquare: 'www.group1image.com', - }) - const group2 = await boClient.conversations.newGroup([alixClient.address], { - name: 'group2 name', - imageUrlSquare: 'www.group2image.com', - }) - - const boGroups = await boClient.conversations.listGroups() - await alixClient.conversations.syncGroups() - const alixGroups = await alixClient.conversations.listGroups() - - assert( - boGroups.length === alixGroups.length, - `group lengths should be the same but bo was ${boGroups.length} and alix was ${alixGroups.length}` - ) - - const boGroup1 = await boClient.conversations.findGroup(group1.id) - const boGroup2 = await boClient.conversations.findGroup(group2.id) - - const alixGroup1 = await alixClient.conversations.findGroup(group1.id) - const alixGroup2 = await alixClient.conversations.findGroup(group2.id) - - assert( - boGroup2?.name === 'group2 name', - `Group 2 name for bo should be group2 name but was ${boGroup2?.name}` - ) - - assert( - boGroup1?.imageUrlSquare === 'www.group1image.com', - `Group 2 url for bo should be www.group1image.com but was ${boGroup1?.imageUrlSquare}` - ) - - assert( - alixGroup1?.name === 'group1 name', - `Group 1 name for alix should be group1 name but was ${alixGroup1?.name}` - ) - - assert( - alixGroup2?.imageUrlSquare === 'www.group2image.com', - `Group 2 url for alix should be www.group2image.com but was ${alixGroup2?.imageUrlSquare}` - ) - - assert(boGroup1?.isGroupActive === true, `Group 1 should be active for bo`) - - return true -}) - -test('can list all groups and conversations', async () => { - const [alixClient, boClient, caroClient] = await createClients(3) - - // Add one group and one conversation - const boGroup = await boClient.conversations.newGroup([alixClient.address]) - const alixConversation = await alixClient.conversations.newConversation( - caroClient.address - ) - - const listedContainers = await alixClient.conversations.listAll() - - // Verify information in listed containers is correct - // BUG - List All returns in Chronological order on iOS - // and reverse Chronological order on Android - const first = 0 - const second = 1 - if ( - listedContainers[first].topic !== boGroup.topic || - listedContainers[first].version !== ConversationVersion.GROUP || - listedContainers[second].version !== ConversationVersion.DIRECT || - listedContainers[second].createdAt !== alixConversation.createdAt - ) { - throw Error('Listed containers should match streamed containers') - } - - return true -}) - -test('can stream all groups and conversations', async () => { - const [alixClient, boClient, caroClient] = await createClients(3) - - // Start streaming groups and conversations - const containers: ConversationContainer[] = [] - const cancelStreamAll = await alixClient.conversations.streamAll( - async (conversationContainer: ConversationContainer) => { - containers.push(conversationContainer) - } - ) - - // bo creates a group with alix, so stream callback is fired - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const boGroup = await boClient.conversations.newGroup([alixClient.address]) - await delayToPropogate() - if ((containers.length as number) !== 1) { - throw Error('Unexpected num groups (should be 1): ' + containers.length) - } - - // bo creates a v2 Conversation with alix so a stream callback is fired - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const boConversation = await boClient.conversations.newConversation( - alixClient.address - ) - await delayToPropogate() - if ((containers.length as number) !== 2) { - throw Error('Unexpected num groups (should be 2): ' + containers.length) - } +// await delayToPropogate() +// // await new Promise((resolve) => setTimeout(resolve, 10000)) +// assert( +// messageCallbacks === 1, +// 'message stream should have received 1 message' +// ) +// assert(groupCallbacks === 1, 'group stream should have received 1 group') +// return true +// }) - if ( - containers[1].version === ConversationVersion.DIRECT && - boConversation.conversationID !== - (containers[1] as Conversation).conversationID - ) { - throw Error( - 'Conversation from streamed all should match conversationID with created conversation' - ) - } +// test('can stream groups', async () => { +// const [alixClient, boClient, caroClient] = await createClients(3) + +// // Start streaming groups +// const groups: Group[] = [] +// const cancelStreamGroups = await alixClient.conversations.streamGroups( +// async (group: Group) => { +// groups.push(group) +// } +// ) + +// // caro creates a group with alix, so stream callback is fired +// // eslint-disable-next-line @typescript-eslint/no-unused-vars +// const caroGroup = await caroClient.conversations.newGroup([ +// alixClient.address, +// ]) +// await delayToPropogate() +// if ((groups.length as number) !== 1) { +// throw Error('Unexpected num groups (should be 1): ' + groups.length) +// } - // * Note alix creating a v2 Conversation does trigger alix conversations - // stream. +// assert(groups[0].members.length === 2, 'should be 2') - // alix creates a V2 Conversationgroup - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const alixConversation = await alixClient.conversations.newConversation( - caroClient.address - ) - await delayToPropogate() - if (containers.length !== 3) { - throw Error('Expected group length 3 but it is: ' + containers.length) - } +// // bo creates a group with alix so a stream callback is fired +// // eslint-disable-next-line @typescript-eslint/no-unused-vars +// const boGroup = await boClient.conversations.newGroup([alixClient.address]) +// await delayToPropogate() +// if ((groups.length as number) !== 2) { +// throw Error('Unexpected num groups (should be 2): ' + groups.length) +// } - cancelStreamAll() - await delayToPropogate() +// // * Note alix creating a group does not trigger alix conversations +// // group stream. Workaround is to syncGroups after you create and list manually +// // See https://github.com/xmtp/libxmtp/issues/504 - // Creating a group should no longer trigger stream groups - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const caroConversation = await caroClient.conversations.newGroup([ - alixClient.address, - ]) - await delayToPropogate() - if ((containers.length as number) !== 3) { - throw Error('Unexpected num groups (should be 3): ' + containers.length) - } +// // alix creates a group +// // eslint-disable-next-line @typescript-eslint/no-unused-vars +// const alixGroup = await alixClient.conversations.newGroup([ +// boClient.address, +// caroClient.address, +// ]) +// await delayToPropogate() +// if (groups.length !== 3) { +// throw Error('Expected group length 3 but it is: ' + groups.length) +// } +// // Sync groups after creation if you created a group +// const listedGroups = await alixClient.conversations.listGroups() +// await delayToPropogate() +// groups.push(listedGroups[listedGroups.length - 1]) +// if ((groups.length as number) !== 4) { +// throw Error('Expected group length 4 but it is: ' + groups.length) +// } - return true -}) +// cancelStreamGroups() +// await delayToPropogate() -test('canMessage', async () => { - const [bo, alix, caro] = await createClients(3) +// // Creating a group should no longer trigger stream groups +// // eslint-disable-next-line @typescript-eslint/no-unused-vars +// const caroSecond = await caroClient.conversations.newGroup([ +// alixClient.address, +// ]) +// await delayToPropogate() +// if ((groups.length as number) !== 4) { +// throw Error('Unexpected num groups (should be 4): ' + groups.length) +// } - const canMessage = await bo.canMessage(alix.address) - if (!canMessage) { - throw new Error('should be able to message v2 client') - } +// return true +// }) - const canMessageV3 = await caro.canGroupMessage([ - caro.address, - alix.address, - '0x0000000000000000000000000000000000000000', - ]) +// test('can list groups', async () => { +// const [alixClient, boClient] = await createClients(2) - assert( - canMessageV3['0x0000000000000000000000000000000000000000'] === false, - `should not be able to message 0x0000000000000000000000000000000000000000` - ) +// const group1 = await boClient.conversations.newGroup([alixClient.address], { +// name: 'group1 name', +// imageUrlSquare: 'www.group1image.com', +// }) +// const group2 = await boClient.conversations.newGroup([alixClient.address], { +// name: 'group2 name', +// imageUrlSquare: 'www.group2image.com', +// }) - assert( - canMessageV3[caro.address.toLowerCase()] === true, - `should be able to message ${caro.address}` - ) +// const boGroups = await boClient.conversations.listGroups() +// await alixClient.conversations.syncGroups() +// const alixGroups = await alixClient.conversations.listGroups() - assert( - canMessageV3[alix.address.toLowerCase()] === true, - `should be able to message ${alix.address}` - ) +// assert( +// boGroups.length === alixGroups.length, +// `group lengths should be the same but bo was ${boGroups.length} and alix was ${alixGroups.length}` +// ) - return true -}) +// const boGroup1 = await boClient.conversations.findGroup(group1.id) +// const boGroup2 = await boClient.conversations.findGroup(group2.id) -test('can stream group messages', async () => { - // Create three MLS enabled Clients - const [alixClient, boClient, caroClient] = await createClients(3) - - // alix creates a group - const alixGroup = await alixClient.conversations.newGroup([ - boClient.address, - caroClient.address, - ]) - - // Record message stream for this group - const groupMessages: DecodedMessage[] = [] - const cancelGroupMessageStream = await alixGroup.streamGroupMessages( - async (message) => { - groupMessages.push(message) - } - ) +// const alixGroup1 = await alixClient.conversations.findGroup(group1.id) +// const alixGroup2 = await alixClient.conversations.findGroup(group2.id) - // bo's num groups == 1 - await boClient.conversations.syncGroups() - const boGroup = (await boClient.conversations.listGroups())[0] +// assert( +// boGroup2?.name === 'group2 name', +// `Group 2 name for bo should be group2 name but was ${boGroup2?.name}` +// ) - for (let i = 0; i < 5; i++) { - await boGroup.send({ text: `Message ${i}` }) - await delayToPropogate() - } +// assert( +// boGroup1?.imageUrlSquare === 'www.group1image.com', +// `Group 2 url for bo should be www.group1image.com but was ${boGroup1?.imageUrlSquare}` +// ) - if (groupMessages.length !== 5) { - throw Error('Unexpected convo messages count ' + groupMessages.length) - } - for (let i = 0; i < 5; i++) { - if (groupMessages[i].content() !== `Message ${i}`) { - throw Error( - 'Unexpected group message content ' + groupMessages[i].content() - ) - } - } +// assert( +// alixGroup1?.name === 'group1 name', +// `Group 1 name for alix should be group1 name but was ${alixGroup1?.name}` +// ) - cancelGroupMessageStream() - for (let i = 0; i < 5; i++) { - await boGroup.send({ text: `Message ${i}` }) - } +// assert( +// alixGroup2?.imageUrlSquare === 'www.group2image.com', +// `Group 2 url for alix should be www.group2image.com but was ${alixGroup2?.imageUrlSquare}` +// ) - if (groupMessages.length !== 5) { - throw Error('Unexpected convo messages count ' + groupMessages.length) - } +// assert(boGroup1?.isGroupActive === true, `Group 1 should be active for bo`) - return true -}) +// return true +// }) -test('can stream all messages', async () => { - const [alix, bo, caro] = await createClients(3) +// test('can list all groups and conversations', async () => { +// const [alixClient, boClient, caroClient] = await createClients(3) + +// // Add one group and one conversation +// const boGroup = await boClient.conversations.newGroup([alixClient.address]) +// const alixConversation = await alixClient.conversations.newConversation( +// caroClient.address +// ) + +// const listedContainers = await alixClient.conversations.listAll() + +// // Verify information in listed containers is correct +// // BUG - List All returns in Chronological order on iOS +// // and reverse Chronological order on Android +// const first = 0 +// const second = 1 +// if ( +// listedContainers[first].topic !== boGroup.topic || +// listedContainers[first].version !== ConversationVersion.GROUP || +// listedContainers[second].version !== ConversationVersion.DIRECT || +// listedContainers[second].createdAt !== alixConversation.createdAt +// ) { +// throw Error('Listed containers should match streamed containers') +// } - await delayToPropogate() +// return true +// }) - // Record message stream across all conversations - const allMessages: DecodedMessage[] = [] - await alix.conversations.streamAllMessages(async (message) => { - allMessages.push(message) - }) +// test('can stream all groups and conversations', async () => { +// const [alixClient, boClient, caroClient] = await createClients(3) - // Start bo starts a new conversation. - const boConvo = await bo.conversations.newConversation(alix.address) - await delayToPropogate() +// // Start streaming groups and conversations +// const containers: ConversationContainer[] = [] +// const cancelStreamAll = await alixClient.conversations.streamAll( +// async (conversationContainer: ConversationContainer) => { +// containers.push(conversationContainer) +// } +// ) - for (let i = 0; i < 5; i++) { - await boConvo.send({ text: `Message ${i}` }) - await delayToPropogate() - } +// // bo creates a group with alix, so stream callback is fired +// // eslint-disable-next-line @typescript-eslint/no-unused-vars +// const boGroup = await boClient.conversations.newGroup([alixClient.address]) +// await delayToPropogate() +// if ((containers.length as number) !== 1) { +// throw Error('Unexpected num groups (should be 1): ' + containers.length) +// } - const count = allMessages.length - if (count !== 5) { - throw Error('Unexpected all messages count ' + allMessages.length) - } +// // bo creates a v2 Conversation with alix so a stream callback is fired +// // eslint-disable-next-line @typescript-eslint/no-unused-vars +// const boConversation = await boClient.conversations.newConversation( +// alixClient.address +// ) +// await delayToPropogate() +// if ((containers.length as number) !== 2) { +// throw Error('Unexpected num groups (should be 2): ' + containers.length) +// } - const caroConvo = await caro.conversations.newConversation(alix.address) - const caroGroup = await caro.conversations.newGroup([alix.address]) - await delayToPropogate() - for (let i = 0; i < 5; i++) { - await caroConvo.send({ text: `Message ${i}` }) - await caroGroup.send({ text: `Message ${i}` }) - await delayToPropogate() - } +// if ( +// containers[1].version === ConversationVersion.DIRECT && +// boConversation.conversationID !== +// (containers[1] as Conversation).conversationID +// ) { +// throw Error( +// 'Conversation from streamed all should match conversationID with created conversation' +// ) +// } - if (allMessages.length !== 10) { - throw Error('Unexpected all messages count ' + allMessages.length) - } +// // * Note alix creating a v2 Conversation does trigger alix conversations +// // stream. - alix.conversations.cancelStreamAllMessages() +// // alix creates a V2 Conversationgroup +// // eslint-disable-next-line @typescript-eslint/no-unused-vars +// const alixConversation = await alixClient.conversations.newConversation( +// caroClient.address +// ) +// await delayToPropogate() +// if (containers.length !== 3) { +// throw Error('Expected group length 3 but it is: ' + containers.length) +// } - await alix.conversations.streamAllMessages(async (message) => { - allMessages.push(message) - }, true) +// cancelStreamAll() +// await delayToPropogate() - for (let i = 0; i < 5; i++) { - await boConvo.send({ text: `Message ${i}` }) - await caroGroup.send({ text: `Message ${i}` }) - await delayToPropogate() - } - if (allMessages.length <= 15) { - throw Error('Unexpected all messages count ' + allMessages.length) - } +// // Creating a group should no longer trigger stream groups +// // eslint-disable-next-line @typescript-eslint/no-unused-vars +// const caroConversation = await caroClient.conversations.newGroup([ +// alixClient.address, +// ]) +// await delayToPropogate() +// if ((containers.length as number) !== 3) { +// throw Error('Unexpected num groups (should be 3): ' + containers.length) +// } - return true -}) +// return true +// }) -test('can make a group with metadata', async () => { - const [alix, bo] = await createClients(2) - bo.register(new GroupUpdatedCodec()) +// test('canMessage', async () => { +// const [bo, alix, caro] = await createClients(3) - const alixGroup = await alix.conversations.newGroup([bo.address], { - name: 'Start Name', - imageUrlSquare: 'starturl.com', - description: 'a fun description', - }) +// const canMessage = await bo.canMessage(alix.address) +// if (!canMessage) { +// throw new Error('should be able to message v2 client') +// } - const groupName1 = await alixGroup.groupName() - const groupImageUrl1 = await alixGroup.groupImageUrlSquare() - const groupDescription1 = await alixGroup.groupDescription() - assert( - groupName1 === 'Start Name', - `the group should start with a name of Start Name not ${groupName1}` - ) +// const canMessageV3 = await caro.canGroupMessage([ +// caro.address, +// alix.address, +// '0x0000000000000000000000000000000000000000', +// ]) - assert( - groupImageUrl1 === 'starturl.com', - `the group should start with a name of starturl.com not ${groupImageUrl1}` - ) +// assert( +// canMessageV3['0x0000000000000000000000000000000000000000'] === false, +// `should not be able to message 0x0000000000000000000000000000000000000000` +// ) - assert( - groupDescription1 === 'a fun description', - `the group should start with a name of a fun description not ${groupDescription1}` - ) +// assert( +// canMessageV3[caro.address.toLowerCase()] === true, +// `should be able to message ${caro.address}` +// ) - await alixGroup.updateGroupName('New Name') - await alixGroup.updateGroupImageUrlSquare('newurl.com') - await alixGroup.updateGroupDescription('a new group description') - await alixGroup.sync() - await bo.conversations.syncGroups() - const boGroups = await bo.conversations.listGroups() - const boGroup = boGroups[0] - await boGroup.sync() - - const groupName2 = await alixGroup.groupName() - const groupImageUrl2 = await alixGroup.groupImageUrlSquare() - const groupDescription2 = await alixGroup.groupDescription() - assert( - groupName2 === 'New Name', - `the group should start with a name of New Name not ${groupName2}` - ) +// assert( +// canMessageV3[alix.address.toLowerCase()] === true, +// `should be able to message ${alix.address}` +// ) - assert( - groupImageUrl2 === 'newurl.com', - `the group should start with a name of newurl.com not ${groupImageUrl2}` - ) +// return true +// }) - assert( - groupDescription2 === 'a new group description', - `the group should start with a name of a new group description not ${groupDescription2}` - ) +// test('can stream group messages', async () => { +// // Create three MLS enabled Clients +// const [alixClient, boClient, caroClient] = await createClients(3) + +// // alix creates a group +// const alixGroup = await alixClient.conversations.newGroup([ +// boClient.address, +// caroClient.address, +// ]) + +// // Record message stream for this group +// const groupMessages: DecodedMessage[] = [] +// const cancelGroupMessageStream = await alixGroup.streamGroupMessages( +// async (message) => { +// groupMessages.push(message) +// } +// ) + +// // bo's num groups == 1 +// await boClient.conversations.syncGroups() +// const boGroup = (await boClient.conversations.listGroups())[0] + +// for (let i = 0; i < 5; i++) { +// await boGroup.send({ text: `Message ${i}` }) +// await delayToPropogate() +// } - const groupName3 = await boGroup.groupName() - const groupImageUrl3 = await boGroup.groupImageUrlSquare() - assert( - groupName3 === 'New Name', - `the group should start with a name of New Name not ${groupName3}` - ) +// if (groupMessages.length !== 5) { +// throw Error('Unexpected convo messages count ' + groupMessages.length) +// } +// for (let i = 0; i < 5; i++) { +// if (groupMessages[i].content() !== `Message ${i}`) { +// throw Error( +// 'Unexpected group message content ' + groupMessages[i].content() +// ) +// } +// } - assert( - groupImageUrl3 === 'newurl.com', - `the group should start with a name of newurl.com not ${groupImageUrl3}` - ) +// cancelGroupMessageStream() +// for (let i = 0; i < 5; i++) { +// await boGroup.send({ text: `Message ${i}` }) +// } - const boMessages = await boGroup.messages() - assert( - boMessages[0].contentTypeId === 'xmtp.org/group_updated:1.0', - 'Unexpected message content ' + JSON.stringify(boMessages[0].contentTypeId) - ) +// if (groupMessages.length !== 5) { +// throw Error('Unexpected convo messages count ' + groupMessages.length) +// } - const message = boMessages[1].content() as GroupUpdatedContent - assert( - message.metadataFieldsChanged[0].fieldName === 'group_image_url_square', - `the metadata field changed should be group_image_url_square but was ${message.metadataFieldsChanged[0].fieldName}` - ) - const message2 = boMessages[0].content() as GroupUpdatedContent - assert( - message2.metadataFieldsChanged[0].fieldName === 'description', - `the metadata field changed should be description but was ${message2.metadataFieldsChanged[0].fieldName}` - ) - return true -}) +// return true +// }) -test('can make a group with admin permissions', async () => { - const [adminClient, anotherClient] = await createClients(2) +// test('can stream all messages', async () => { +// const [alix, bo, caro] = await createClients(3) - const group = await adminClient.conversations.newGroup( - [anotherClient.address], - { permissionLevel: 'admin_only' } - ) +// await delayToPropogate() - if ((await group.permissionPolicySet()).addMemberPolicy !== 'admin') { - throw Error( - `Group permission level should be admin but was ${ - (await group.permissionPolicySet()).addMemberPolicy - }` - ) - } +// // Record message stream across all conversations +// const allMessages: DecodedMessage[] = [] +// await alix.conversations.streamAllMessages(async (message) => { +// allMessages.push(message) +// }) - const isSuperAdmin = await group.isSuperAdmin(adminClient.inboxId) - if (!isSuperAdmin) { - throw Error(`adminClient should be the super admin`) - } +// // Start bo starts a new conversation. +// const boConvo = await bo.conversations.newConversation(alix.address) +// await delayToPropogate() - // Creator id not working, see https://github.com/xmtp/libxmtp/issues/788 - // if (group.creatorInboxId !== adminClient.inboxId) { - // throw Error( - // `adminClient should be the creator but was ${group.creatorInboxId}` - // ) - // } +// for (let i = 0; i < 5; i++) { +// await boConvo.send({ text: `Message ${i}` }) +// await delayToPropogate() +// } - return true -}) +// const count = allMessages.length +// if (count !== 5) { +// throw Error('Unexpected all messages count ' + allMessages.length) +// } -test('can paginate group messages', async () => { - // Create three MLS enabled Clients - const [alixClient, boClient] = await createClients(2) +// const caroConvo = await caro.conversations.newConversation(alix.address) +// const caroGroup = await caro.conversations.newGroup([alix.address]) +// await delayToPropogate() +// for (let i = 0; i < 5; i++) { +// await caroConvo.send({ text: `Message ${i}` }) +// await caroGroup.send({ text: `Message ${i}` }) +// await delayToPropogate() +// } - // alix creates a group - const alixGroup = await alixClient.conversations.newGroup([boClient.address]) +// if (allMessages.length !== 10) { +// throw Error('Unexpected all messages count ' + allMessages.length) +// } - // alix can send messages - await alixGroup.send('hello, world') - await alixGroup.send('gm') +// alix.conversations.cancelStreamAllMessages() - await boClient.conversations.syncGroups() - const boGroups = await boClient.conversations.listGroups() - if (boGroups.length !== 1) { - throw new Error( - 'num groups for bo should be 1, but it is' + boGroups.length - ) - } - await delayToPropogate() - // bo can read messages from alix - await boGroups[0].sync() - const boMessages: DecodedMessage[] = await boGroups[0].messages({ - limit: 1, - }) - - if (boMessages.length !== 1) { - throw Error(`Should limit just 1 message but was ${boMessages.length}`) - } +// await alix.conversations.streamAllMessages(async (message) => { +// allMessages.push(message) +// }, true) - return true -}) +// for (let i = 0; i < 5; i++) { +// await boConvo.send({ text: `Message ${i}` }) +// await caroGroup.send({ text: `Message ${i}` }) +// await delayToPropogate() +// } +// if (allMessages.length <= 15) { +// throw Error('Unexpected all messages count ' + allMessages.length) +// } -test('can stream all group messages', async () => { - const [alix, bo, caro] = await createClients(3) +// return true +// }) - await delayToPropogate() +// test('can make a group with metadata', async () => { +// const [alix, bo] = await createClients(2) +// bo.register(new GroupUpdatedCodec()) + +// const alixGroup = await alix.conversations.newGroup([bo.address], { +// name: 'Start Name', +// imageUrlSquare: 'starturl.com', +// description: 'a fun description', +// }) + +// const groupName1 = await alixGroup.groupName() +// const groupImageUrl1 = await alixGroup.groupImageUrlSquare() +// const groupDescription1 = await alixGroup.groupDescription() +// assert( +// groupName1 === 'Start Name', +// `the group should start with a name of Start Name not ${groupName1}` +// ) + +// assert( +// groupImageUrl1 === 'starturl.com', +// `the group should start with a name of starturl.com not ${groupImageUrl1}` +// ) + +// assert( +// groupDescription1 === 'a fun description', +// `the group should start with a name of a fun description not ${groupDescription1}` +// ) + +// await alixGroup.updateGroupName('New Name') +// await alixGroup.updateGroupImageUrlSquare('newurl.com') +// await alixGroup.updateGroupDescription('a new group description') +// await alixGroup.sync() +// await bo.conversations.syncGroups() +// const boGroups = await bo.conversations.listGroups() +// const boGroup = boGroups[0] +// await boGroup.sync() + +// const groupName2 = await alixGroup.groupName() +// const groupImageUrl2 = await alixGroup.groupImageUrlSquare() +// const groupDescription2 = await alixGroup.groupDescription() +// assert( +// groupName2 === 'New Name', +// `the group should start with a name of New Name not ${groupName2}` +// ) + +// assert( +// groupImageUrl2 === 'newurl.com', +// `the group should start with a name of newurl.com not ${groupImageUrl2}` +// ) + +// assert( +// groupDescription2 === 'a new group description', +// `the group should start with a name of a new group description not ${groupDescription2}` +// ) + +// const groupName3 = await boGroup.groupName() +// const groupImageUrl3 = await boGroup.groupImageUrlSquare() +// assert( +// groupName3 === 'New Name', +// `the group should start with a name of New Name not ${groupName3}` +// ) + +// assert( +// groupImageUrl3 === 'newurl.com', +// `the group should start with a name of newurl.com not ${groupImageUrl3}` +// ) + +// const boMessages = await boGroup.messages() +// assert( +// boMessages[0].contentTypeId === 'xmtp.org/group_updated:1.0', +// 'Unexpected message content ' + JSON.stringify(boMessages[0].contentTypeId) +// ) + +// const message = boMessages[1].content() as GroupUpdatedContent +// assert( +// message.metadataFieldsChanged[0].fieldName === 'group_image_url_square', +// `the metadata field changed should be group_image_url_square but was ${message.metadataFieldsChanged[0].fieldName}` +// ) +// const message2 = boMessages[0].content() as GroupUpdatedContent +// assert( +// message2.metadataFieldsChanged[0].fieldName === 'description', +// `the metadata field changed should be description but was ${message2.metadataFieldsChanged[0].fieldName}` +// ) +// return true +// }) - // Start bo starts a new group. - const boGroup = await bo.conversations.newGroup([alix.address]) - await delayToPropogate() +// test('can make a group with admin permissions', async () => { +// const [adminClient, anotherClient] = await createClients(2) - // Starts a new conversation. - const caroGroup = await caro.conversations.newGroup([alix.address]) - - // Record message stream across all conversations - const allMessages: DecodedMessage[] = [] - // If we don't call syncGroups here, the streamAllGroupMessages will not - // stream the first message. Feels like a bug. - await alix.conversations.syncGroups() - await alix.conversations.streamAllGroupMessages(async (message) => { - allMessages.push(message) - }) - - for (let i = 0; i < 5; i++) { - await boGroup.send({ text: `Message ${i}` }) - await delayToPropogate() - } +// const group = await adminClient.conversations.newGroup( +// [anotherClient.address], +// { permissionLevel: 'admin_only' } +// ) - const count = allMessages.length - if (count !== 5) { - throw Error('Unexpected all messages count first' + allMessages.length) - } +// if ((await group.permissionPolicySet()).addMemberPolicy !== 'admin') { +// throw Error( +// `Group permission level should be admin but was ${ +// (await group.permissionPolicySet()).addMemberPolicy +// }` +// ) +// } - await delayToPropogate() - for (let i = 0; i < 5; i++) { - await caroGroup.send({ text: `Message ${i}` }) - await delayToPropogate() - } +// const isSuperAdmin = await group.isSuperAdmin(adminClient.inboxId) +// if (!isSuperAdmin) { +// throw Error(`adminClient should be the super admin`) +// } - if (allMessages.length !== 10) { - throw Error('Unexpected all messages count second' + allMessages.length) - } +// // Creator id not working, see https://github.com/xmtp/libxmtp/issues/788 +// // if (group.creatorInboxId !== adminClient.inboxId) { +// // throw Error( +// // `adminClient should be the creator but was ${group.creatorInboxId}` +// // ) +// // } - alix.conversations.cancelStreamAllGroupMessages() - await delayToPropogate() - await alix.conversations.streamAllGroupMessages(async (message) => { - allMessages.push(message) - }) +// return true +// }) - for (let i = 0; i < 5; i++) { - await boGroup.send({ text: `Message ${i}` }) - await delayToPropogate() - } - if (allMessages.length <= 10) { - throw Error('Unexpected all messages count ' + allMessages.length) - } +// test('can paginate group messages', async () => { +// // Create three MLS enabled Clients +// const [alixClient, boClient] = await createClients(2) - return true -}) +// // alix creates a group +// const alixGroup = await alixClient.conversations.newGroup([boClient.address]) -test('can streamAll from multiple clients', async () => { - const [alix, bo, caro] = await createClients(3) +// // alix can send messages +// await alixGroup.send('hello, world') +// await alixGroup.send('gm') - // Setup stream alls - const allBoConversations: any[] = [] - const allAliConversations: any[] = [] +// await boClient.conversations.syncGroups() +// const boGroups = await boClient.conversations.listGroups() +// if (boGroups.length !== 1) { +// throw new Error( +// 'num groups for bo should be 1, but it is' + boGroups.length +// ) +// } +// await delayToPropogate() +// // bo can read messages from alix +// await boGroups[0].sync() +// const boMessages: DecodedMessage[] = await boGroups[0].messages({ +// limit: 1, +// }) + +// if (boMessages.length !== 1) { +// throw Error(`Should limit just 1 message but was ${boMessages.length}`) +// } - await bo.conversations.streamAll(async (conversation) => { - allBoConversations.push(conversation) - }) - await alix.conversations.streamAll(async (conversation) => { - allAliConversations.push(conversation) - }) +// return true +// }) - // Start Caro starts a new conversation. - await caro.conversations.newConversation(alix.address) - await delayToPropogate() - if (allBoConversations.length !== 0) { - throw Error( - 'Unexpected all conversations count for Bo ' + - allBoConversations.length + - ' and Alix had ' + - allAliConversations.length - ) - } - if (allAliConversations.length !== 1) { - throw Error( - 'Unexpected all conversations count ' + allAliConversations.length - ) - } - return true -}) +// test('can stream all group messages', async () => { +// const [alix, bo, caro] = await createClients(3) -test('can streamAll from multiple clients - swapped orderring', async () => { - const [alix, bo, caro] = await createClients(3) +// await delayToPropogate() - // Setup stream alls - const allBoConversations: any[] = [] - const allAliConversations: any[] = [] +// // Start bo starts a new group. +// const boGroup = await bo.conversations.newGroup([alix.address]) +// await delayToPropogate() - await alix.conversations.streamAll(async (conversation) => { - allAliConversations.push(conversation) - }) +// // Starts a new conversation. +// const caroGroup = await caro.conversations.newGroup([alix.address]) + +// // Record message stream across all conversations +// const allMessages: DecodedMessage[] = [] +// // If we don't call syncGroups here, the streamAllGroupMessages will not +// // stream the first message. Feels like a bug. +// await alix.conversations.syncGroups() +// await alix.conversations.streamAllGroupMessages(async (message) => { +// allMessages.push(message) +// }) + +// for (let i = 0; i < 5; i++) { +// await boGroup.send({ text: `Message ${i}` }) +// await delayToPropogate() +// } - await bo.conversations.streamAll(async (conversation) => { - allBoConversations.push(conversation) - }) +// const count = allMessages.length +// if (count !== 5) { +// throw Error('Unexpected all messages count first' + allMessages.length) +// } - // Start Caro starts a new conversation. - await caro.conversations.newConversation(alix.address) - await delayToPropogate() - if (allBoConversations.length !== 0) { - throw Error( - 'Unexpected all conversations count for Bo ' + - allBoConversations.length + - ' and Alix had ' + - allAliConversations.length - ) - } - if (allAliConversations.length !== 1) { - throw Error( - 'Unexpected all conversations count ' + allAliConversations.length - ) - } - return true -}) +// await delayToPropogate() +// for (let i = 0; i < 5; i++) { +// await caroGroup.send({ text: `Message ${i}` }) +// await delayToPropogate() +// } -test('can streamAllMessages from multiple clients', async () => { - const [alix, bo, caro] = await createClients(3) +// if (allMessages.length !== 10) { +// throw Error('Unexpected all messages count second' + allMessages.length) +// } - // Setup stream - const allBoMessages: any[] = [] - const allAliMessages: any[] = [] +// alix.conversations.cancelStreamAllGroupMessages() +// await delayToPropogate() +// await alix.conversations.streamAllGroupMessages(async (message) => { +// allMessages.push(message) +// }) - await bo.conversations.streamAllMessages(async (conversation) => { - allBoMessages.push(conversation) - }, true) - await alix.conversations.streamAllMessages(async (conversation) => { - allAliMessages.push(conversation) - }, true) +// for (let i = 0; i < 5; i++) { +// await boGroup.send({ text: `Message ${i}` }) +// await delayToPropogate() +// } +// if (allMessages.length <= 10) { +// throw Error('Unexpected all messages count ' + allMessages.length) +// } - // Start Caro starts a new conversation. - const caroConversation = await caro.conversations.newConversation( - alix.address - ) - await caroConversation.send({ text: `Message` }) - await delayToPropogate() - if (allBoMessages.length !== 0) { - throw Error('Unexpected all messages count for Bo ' + allBoMessages.length) - } +// return true +// }) - if (allAliMessages.length !== 1) { - throw Error( - 'Unexpected all conversations count for Ali ' + allAliMessages.length - ) - } +// test('can streamAll from multiple clients', async () => { +// const [alix, bo, caro] = await createClients(3) - return true -}) +// // Setup stream alls +// const allBoConversations: any[] = [] +// const allAliConversations: any[] = [] -test('can streamAllMessages from multiple clients - swapped', async () => { - const [alix, bo, caro] = await createClients(3) +// await bo.conversations.streamAll(async (conversation) => { +// allBoConversations.push(conversation) +// }) +// await alix.conversations.streamAll(async (conversation) => { +// allAliConversations.push(conversation) +// }) - // Setup stream - const allBoMessages: any[] = [] - const allAliMessages: any[] = [] - const caroGroup = await caro.conversations.newGroup([alix.address]) +// // Start Caro starts a new conversation. +// await caro.conversations.newConversation(alix.address) +// await delayToPropogate() +// if (allBoConversations.length !== 0) { +// throw Error( +// 'Unexpected all conversations count for Bo ' + +// allBoConversations.length + +// ' and Alix had ' + +// allAliConversations.length +// ) +// } +// if (allAliConversations.length !== 1) { +// throw Error( +// 'Unexpected all conversations count ' + allAliConversations.length +// ) +// } +// return true +// }) - await alix.conversations.streamAllMessages(async (conversation) => { - allAliMessages.push(conversation) - }, true) - await bo.conversations.streamAllMessages(async (conversation) => { - allBoMessages.push(conversation) - }, true) +// test('can streamAll from multiple clients - swapped orderring', async () => { +// const [alix, bo, caro] = await createClients(3) - // Start Caro starts a new conversation. - const caroConvo = await caro.conversations.newConversation(alix.address) - await delayToPropogate() - await caroConvo.send({ text: `Message` }) - await caroGroup.send({ text: `Message` }) - await delayToPropogate() - if (allBoMessages.length !== 0) { - throw Error( - 'Unexpected all conversations count for Bo ' + allBoMessages.length - ) - } +// // Setup stream alls +// const allBoConversations: any[] = [] +// const allAliConversations: any[] = [] - if (allAliMessages.length !== 2) { - throw Error( - 'Unexpected all conversations count for Ali ' + allAliMessages.length - ) - } +// await alix.conversations.streamAll(async (conversation) => { +// allAliConversations.push(conversation) +// }) - return true -}) +// await bo.conversations.streamAll(async (conversation) => { +// allBoConversations.push(conversation) +// }) -test('can stream all group Messages from multiple clients', async () => { - const [alix, bo, caro] = await createClients(3) +// // Start Caro starts a new conversation. +// await caro.conversations.newConversation(alix.address) +// await delayToPropogate() +// if (allBoConversations.length !== 0) { +// throw Error( +// 'Unexpected all conversations count for Bo ' + +// allBoConversations.length + +// ' and Alix had ' + +// allAliConversations.length +// ) +// } +// if (allAliConversations.length !== 1) { +// throw Error( +// 'Unexpected all conversations count ' + allAliConversations.length +// ) +// } +// return true +// }) - // Setup stream - const allAlixMessages: DecodedMessage[] = [] - const allBoMessages: DecodedMessage[] = [] - const alixGroup = await caro.conversations.newGroup([alix.address]) - const boGroup = await caro.conversations.newGroup([bo.address]) +// test('can streamAllMessages from multiple clients', async () => { +// const [alix, bo, caro] = await createClients(3) - await alixGroup.streamGroupMessages(async (message) => { - allAlixMessages.push(message) - }) - await boGroup.streamGroupMessages(async (message) => { - allBoMessages.push(message) - }) +// // Setup stream +// const allBoMessages: any[] = [] +// const allAliMessages: any[] = [] - // Start Caro starts a new conversation. - await delayToPropogate() - await alixGroup.send({ text: `Message` }) - await delayToPropogate() - if (allBoMessages.length !== 0) { - throw Error('Unexpected all messages count for Bo ' + allBoMessages.length) - } +// await bo.conversations.streamAllMessages(async (conversation) => { +// allBoMessages.push(conversation) +// }, true) +// await alix.conversations.streamAllMessages(async (conversation) => { +// allAliMessages.push(conversation) +// }, true) - if (allAlixMessages.length !== 1) { - throw Error( - 'Unexpected all messages count for Ali ' + allAlixMessages.length - ) - } +// // Start Caro starts a new conversation. +// const caroConversation = await caro.conversations.newConversation( +// alix.address +// ) +// await caroConversation.send({ text: `Message` }) +// await delayToPropogate() +// if (allBoMessages.length !== 0) { +// throw Error('Unexpected all messages count for Bo ' + allBoMessages.length) +// } - await alix.conversations.syncGroups() - const alixConv = (await alix.conversations.listGroups())[0] - await alixConv.send({ text: `Message` }) - await delayToPropogate() - if (allBoMessages.length !== 0) { - throw Error('Unexpected all messages count for Bo ' + allBoMessages.length) - } - // @ts-ignore-next-line - if (allAlixMessages.length !== 2) { - throw Error( - 'Unexpected all messages count for Ali ' + allAlixMessages.length - ) - } +// if (allAliMessages.length !== 1) { +// throw Error( +// 'Unexpected all conversations count for Ali ' + allAliMessages.length +// ) +// } - return true -}) +// return true +// }) -test('can stream all group Messages from multiple clients - swapped', async () => { - const [alix, bo, caro] = await createClients(3) +// test('can streamAllMessages from multiple clients - swapped', async () => { +// const [alix, bo, caro] = await createClients(3) - // Setup stream - const allAlixMessages: DecodedMessage[] = [] - const allBoMessages: DecodedMessage[] = [] - const alixGroup = await caro.conversations.newGroup([alix.address]) - const boGroup = await caro.conversations.newGroup([bo.address]) +// // Setup stream +// const allBoMessages: any[] = [] +// const allAliMessages: any[] = [] +// const caroGroup = await caro.conversations.newGroup([alix.address]) - await boGroup.streamGroupMessages(async (message) => { - allBoMessages.push(message) - }) - await alixGroup.streamGroupMessages(async (message) => { - allAlixMessages.push(message) - }) +// await alix.conversations.streamAllMessages(async (conversation) => { +// allAliMessages.push(conversation) +// }, true) +// await bo.conversations.streamAllMessages(async (conversation) => { +// allBoMessages.push(conversation) +// }, true) - // Start Caro starts a new conversation. - await delayToPropogate() - await alixGroup.send({ text: `Message` }) - await delayToPropogate() - if (allBoMessages.length !== 0) { - throw Error('Unexpected all messages count for Bo ' + allBoMessages.length) - } +// // Start Caro starts a new conversation. +// const caroConvo = await caro.conversations.newConversation(alix.address) +// await delayToPropogate() +// await caroConvo.send({ text: `Message` }) +// await caroGroup.send({ text: `Message` }) +// await delayToPropogate() +// if (allBoMessages.length !== 0) { +// throw Error( +// 'Unexpected all conversations count for Bo ' + allBoMessages.length +// ) +// } - if (allAlixMessages.length !== 1) { - throw Error( - 'Unexpected all messages count for Ali ' + allAlixMessages.length - ) - } +// if (allAliMessages.length !== 2) { +// throw Error( +// 'Unexpected all conversations count for Ali ' + allAliMessages.length +// ) +// } - await alix.conversations.syncGroups() - const alixConv = (await alix.conversations.listGroups())[0] - await alixConv.send({ text: `Message` }) - await delayToPropogate() - if (allBoMessages.length !== 0) { - throw Error('Unexpected all messages count for Bo ' + allBoMessages.length) - } - // @ts-ignore-next-line - if (allAlixMessages.length !== 2) { - throw Error( - 'Unexpected all messages count for Ali ' + allAlixMessages.length - ) - } +// return true +// }) - return true -}) +// test('can stream all group Messages from multiple clients', async () => { +// const [alix, bo, caro] = await createClients(3) -test('creating a group should allow group', async () => { - const [alix, bo] = await createClients(2) +// // Setup stream +// const allAlixMessages: DecodedMessage[] = [] +// const allBoMessages: DecodedMessage[] = [] +// const alixGroup = await caro.conversations.newGroup([alix.address]) +// const boGroup = await caro.conversations.newGroup([bo.address]) - const group = await alix.conversations.newGroup([bo.address]) - const consent = await alix.contacts.isGroupAllowed(group.id) - const groupConsent = await group.isAllowed() +// await alixGroup.streamGroupMessages(async (message) => { +// allAlixMessages.push(message) +// }) +// await boGroup.streamGroupMessages(async (message) => { +// allBoMessages.push(message) +// }) - if (!consent || !groupConsent) { - throw Error('Group should be allowed') - } +// // Start Caro starts a new conversation. +// await delayToPropogate() +// await alixGroup.send({ text: `Message` }) +// await delayToPropogate() +// if (allBoMessages.length !== 0) { +// throw Error('Unexpected all messages count for Bo ' + allBoMessages.length) +// } - const state = await group.consentState() - assert( - state === 'allowed', - `the message should have a consent state of allowed but was ${state}` - ) +// if (allAlixMessages.length !== 1) { +// throw Error( +// 'Unexpected all messages count for Ali ' + allAlixMessages.length +// ) +// } - const consentList = await alix.contacts.consentList() - assert( - consentList[0].permissionType === 'allowed', - `the message should have a consent state of allowed but was ${consentList[0].permissionType}` - ) +// await alix.conversations.syncGroups() +// const alixConv = (await alix.conversations.listGroups())[0] +// await alixConv.send({ text: `Message` }) +// await delayToPropogate() +// if (allBoMessages.length !== 0) { +// throw Error('Unexpected all messages count for Bo ' + allBoMessages.length) +// } +// // @ts-ignore-next-line +// if (allAlixMessages.length !== 2) { +// throw Error( +// 'Unexpected all messages count for Ali ' + allAlixMessages.length +// ) +// } - return true -}) +// return true +// }) -test('can allow a group', async () => { - const [alix, bo] = await createClients(2) - const alixGroup = await alix.conversations.newGroup([bo.address]) - const startConsent = await bo.contacts.isGroupAllowed(alixGroup.id) - if (startConsent) { - throw Error('Group should not be allowed') - } - await bo.contacts.allowGroups([alixGroup.id]) - const isAllowed = await bo.contacts.isGroupAllowed(alixGroup.id) - if (!isAllowed) { - throw Error('Group should be allowed') - } +// test('can stream all group Messages from multiple clients - swapped', async () => { +// const [alix, bo, caro] = await createClients(3) - return true -}) +// // Setup stream +// const allAlixMessages: DecodedMessage[] = [] +// const allBoMessages: DecodedMessage[] = [] +// const alixGroup = await caro.conversations.newGroup([alix.address]) +// const boGroup = await caro.conversations.newGroup([bo.address]) -test('can deny a group', async () => { - const [alix, bo] = await createClients(2) - const alixGroup = await alix.conversations.newGroup([bo.address]) - const startConsent = await bo.contacts.isGroupDenied(alixGroup.id) - if (startConsent) { - throw Error('Group should be unknown') - } - await bo.contacts.denyGroups([alixGroup.id]) - await bo.conversations.syncGroups() - const boGroups = await bo.conversations.listGroups() - const isDenied = await bo.contacts.isGroupDenied(alixGroup.id) - const isGroupDenied = await boGroups[0].isDenied() - if (!isDenied || !isGroupDenied) { - throw Error('Group should be denied') - } - await bo.contacts.allowGroups([alixGroup.id]) - const isAllowed = await bo.contacts.isGroupAllowed(alixGroup.id) - if (!isAllowed) { - throw Error('Group should be allowed') - } +// await boGroup.streamGroupMessages(async (message) => { +// allBoMessages.push(message) +// }) +// await alixGroup.streamGroupMessages(async (message) => { +// allAlixMessages.push(message) +// }) - return true -}) +// // Start Caro starts a new conversation. +// await delayToPropogate() +// await alixGroup.send({ text: `Message` }) +// await delayToPropogate() +// if (allBoMessages.length !== 0) { +// throw Error('Unexpected all messages count for Bo ' + allBoMessages.length) +// } -test('can allow and deny a inbox id', async () => { - const [alix, bo] = await createClients(2) - const startConsent = await bo.contacts.isInboxAllowed(alix.inboxId) - if (startConsent) { - throw Error('inbox id should be unknown') - } - await bo.contacts.denyInboxes([alix.inboxId]) - const isDenied = await bo.contacts.isInboxDenied(alix.inboxId) - if (!isDenied) { - throw Error('inbox id should be denied') - } - await bo.contacts.allowInboxes([alix.inboxId]) - const isAllowed = await bo.contacts.isInboxAllowed(alix.inboxId) - if (!isAllowed) { - throw Error('inbox id should be allowed') - } +// if (allAlixMessages.length !== 1) { +// throw Error( +// 'Unexpected all messages count for Ali ' + allAlixMessages.length +// ) +// } - const consentList = await bo.contacts.consentList() - assert( - consentList[0].entryType === 'inbox_id', - `the message should have a type of inbox_id but was ${consentList[0].entryType}` - ) +// await alix.conversations.syncGroups() +// const alixConv = (await alix.conversations.listGroups())[0] +// await alixConv.send({ text: `Message` }) +// await delayToPropogate() +// if (allBoMessages.length !== 0) { +// throw Error('Unexpected all messages count for Bo ' + allBoMessages.length) +// } +// // @ts-ignore-next-line +// if (allAlixMessages.length !== 2) { +// throw Error( +// 'Unexpected all messages count for Ali ' + allAlixMessages.length +// ) +// } - return true -}) +// return true +// }) -test('can check if group is allowed', async () => { - const [alix, bo] = await createClients(2) - const alixGroup = await alix.conversations.newGroup([bo.address]) - const startConsent = await bo.contacts.isGroupAllowed(alixGroup.id) - if (startConsent) { - throw Error('Group should not be allowed by default') - } - await bo.contacts.allowGroups([alixGroup.id]) - const consent = await bo.contacts.isGroupAllowed(alixGroup.id) - if (!consent) { - throw Error('Group should be allowed') - } +// test('creating a group should allow group', async () => { +// const [alix, bo] = await createClients(2) - return true -}) +// const group = await alix.conversations.newGroup([bo.address]) +// const consent = await alix.contacts.isGroupAllowed(group.id) +// const groupConsent = await group.isAllowed() -test('can check if group is denied', async () => { - const [alix, bo] = await createClients(2) - const alixGroup = await alix.conversations.newGroup([bo.address]) - const startConsent = await bo.contacts.isGroupDenied(alixGroup.id) - if (startConsent) { - throw Error('Group should not be denied by default') - } - await bo.contacts.denyGroups([alixGroup.id]) - const consent = await bo.contacts.isGroupDenied(alixGroup.id) - if (!consent) { - throw Error('Group should be denied') - } - return true -}) +// if (!consent || !groupConsent) { +// throw Error('Group should be allowed') +// } -test('sync function behaves as expected', async () => { - const [alix, bo, caro] = await createClients(3) - const alixGroup = await alix.conversations.newGroup([bo.address]) +// const state = await group.consentState() +// assert( +// state === 'allowed', +// `the message should have a consent state of allowed but was ${state}` +// ) - await alixGroup.send({ text: 'hello' }) +// const consentList = await alix.contacts.consentList() +// assert( +// consentList[0].permissionType === 'allowed', +// `the message should have a consent state of allowed but was ${consentList[0].permissionType}` +// ) - // List groups will return empty until the first sync - let boGroups = await bo.conversations.listGroups() - assert(boGroups.length === 0, 'num groups for bo is 0 until we sync') +// return true +// }) - await bo.conversations.syncGroups() +// test('can allow a group', async () => { +// const [alix, bo] = await createClients(2) +// const alixGroup = await alix.conversations.newGroup([bo.address]) +// const startConsent = await bo.contacts.isGroupAllowed(alixGroup.id) +// if (startConsent) { +// throw Error('Group should not be allowed') +// } +// await bo.contacts.allowGroups([alixGroup.id]) +// const isAllowed = await bo.contacts.isGroupAllowed(alixGroup.id) +// if (!isAllowed) { +// throw Error('Group should be allowed') +// } - boGroups = await bo.conversations.listGroups() - assert(boGroups.length === 1, 'num groups for bo is 1') +// return true +// }) - // Num members will include the initial num of members even before sync - let numMembers = (await boGroups[0].memberInboxIds()).length - assert(numMembers === 2, 'num members should be 2') +// test('can deny a group', async () => { +// const [alix, bo] = await createClients(2) +// const alixGroup = await alix.conversations.newGroup([bo.address]) +// const startConsent = await bo.contacts.isGroupDenied(alixGroup.id) +// if (startConsent) { +// throw Error('Group should be unknown') +// } +// await bo.contacts.denyGroups([alixGroup.id]) +// await bo.conversations.syncGroups() +// const boGroups = await bo.conversations.listGroups() +// const isDenied = await bo.contacts.isGroupDenied(alixGroup.id) +// const isGroupDenied = await boGroups[0].isDenied() +// if (!isDenied || !isGroupDenied) { +// throw Error('Group should be denied') +// } +// await bo.contacts.allowGroups([alixGroup.id]) +// const isAllowed = await bo.contacts.isGroupAllowed(alixGroup.id) +// if (!isAllowed) { +// throw Error('Group should be allowed') +// } - // Num messages for a group will be 0 until we sync the group - let numMessages = (await boGroups[0].messages()).length - assert(numMessages === 0, 'num members should be 1') +// return true +// }) - await bo.conversations.syncGroups() +// test('can allow and deny a inbox id', async () => { +// const [alix, bo] = await createClients(2) +// const startConsent = await bo.contacts.isInboxAllowed(alix.inboxId) +// if (startConsent) { +// throw Error('inbox id should be unknown') +// } +// await bo.contacts.denyInboxes([alix.inboxId]) +// const isDenied = await bo.contacts.isInboxDenied(alix.inboxId) +// if (!isDenied) { +// throw Error('inbox id should be denied') +// } +// await bo.contacts.allowInboxes([alix.inboxId]) +// const isAllowed = await bo.contacts.isInboxAllowed(alix.inboxId) +// if (!isAllowed) { +// throw Error('inbox id should be allowed') +// } - // Num messages is still 0 because we didnt sync the group itself - numMessages = (await boGroups[0].messages()).length - assert(numMessages === 0, 'num messages should be 0') +// const consentList = await bo.contacts.consentList() +// assert( +// consentList[0].entryType === 'inbox_id', +// `the message should have a type of inbox_id but was ${consentList[0].entryType}` +// ) - await boGroups[0].sync() +// return true +// }) - // after syncing the group we now see the correct number of messages - numMessages = (await boGroups[0].messages()).length - assert(numMessages === 1, 'num members should be 1') +// test('can check if group is allowed', async () => { +// const [alix, bo] = await createClients(2) +// const alixGroup = await alix.conversations.newGroup([bo.address]) +// const startConsent = await bo.contacts.isGroupAllowed(alixGroup.id) +// if (startConsent) { +// throw Error('Group should not be allowed by default') +// } +// await bo.contacts.allowGroups([alixGroup.id]) +// const consent = await bo.contacts.isGroupAllowed(alixGroup.id) +// if (!consent) { +// throw Error('Group should be allowed') +// } - await alixGroup.addMembers([caro.address]) +// return true +// }) - numMembers = (await boGroups[0].memberInboxIds()).length - assert(numMembers === 2, 'num members should be 2') +// test('can check if group is denied', async () => { +// const [alix, bo] = await createClients(2) +// const alixGroup = await alix.conversations.newGroup([bo.address]) +// const startConsent = await bo.contacts.isGroupDenied(alixGroup.id) +// if (startConsent) { +// throw Error('Group should not be denied by default') +// } +// await bo.contacts.denyGroups([alixGroup.id]) +// const consent = await bo.contacts.isGroupDenied(alixGroup.id) +// if (!consent) { +// throw Error('Group should be denied') +// } +// return true +// }) - await bo.conversations.syncGroups() +// test('sync function behaves as expected', async () => { +// const [alix, bo, caro] = await createClients(3) +// const alixGroup = await alix.conversations.newGroup([bo.address]) - // Even though we synced the groups, we need to sync the group itself to see the new member - numMembers = (await boGroups[0].memberInboxIds()).length - assert(numMembers === 2, 'num members should be 2') +// await alixGroup.send({ text: 'hello' }) - await boGroups[0].sync() +// // List groups will return empty until the first sync +// let boGroups = await bo.conversations.listGroups() +// assert(boGroups.length === 0, 'num groups for bo is 0 until we sync') - numMembers = (await boGroups[0].memberInboxIds()).length - assert(numMembers === 3, 'num members should be 3') +// await bo.conversations.syncGroups() - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const _alixGroup2 = await alix.conversations.newGroup([ - bo.address, - caro.address, - ]) - await bo.conversations.syncGroups() - boGroups = await bo.conversations.listGroups() - assert(boGroups.length === 2, 'num groups for bo is 2') +// boGroups = await bo.conversations.listGroups() +// assert(boGroups.length === 1, 'num groups for bo is 1') - // Even before syncing the group, syncGroups will return the initial number of members - numMembers = (await boGroups[1].memberInboxIds()).length - assert(numMembers === 3, 'num members should be 3') +// // Num members will include the initial num of members even before sync +// let numMembers = (await boGroups[0].memberInboxIds()).length +// assert(numMembers === 2, 'num members should be 2') - return true -}) +// // Num messages for a group will be 0 until we sync the group +// let numMessages = (await boGroups[0].messages()).length +// assert(numMessages === 0, 'num members should be 1') -test('can read and update group name', async () => { - const [alix, bo, caro] = await createClients(3) - const alixGroup = await alix.conversations.newGroup([bo.address]) +// await bo.conversations.syncGroups() - await alixGroup.sync() - let groupName = await alixGroup.groupName() +// // Num messages is still 0 because we didnt sync the group itself +// numMessages = (await boGroups[0].messages()).length +// assert(numMessages === 0, 'num messages should be 0') - assert(groupName === '', 'group name should be empty string') +// await boGroups[0].sync() - await alixGroup.updateGroupName('Test name update 1') +// // after syncing the group we now see the correct number of messages +// numMessages = (await boGroups[0].messages()).length +// assert(numMessages === 1, 'num members should be 1') - await alixGroup.sync() - groupName = await alixGroup.groupName() +// await alixGroup.addMembers([caro.address]) - assert( - groupName === 'Test name update 1', - 'group name should be "Test name update 1"' - ) +// numMembers = (await boGroups[0].memberInboxIds()).length +// assert(numMembers === 2, 'num members should be 2') - await bo.conversations.syncGroups() - const boGroup = (await bo.conversations.listGroups())[0] - groupName = await boGroup.groupName() +// await bo.conversations.syncGroups() - assert(groupName === '', 'group name should be empty string') +// // Even though we synced the groups, we need to sync the group itself to see the new member +// numMembers = (await boGroups[0].memberInboxIds()).length +// assert(numMembers === 2, 'num members should be 2') - await boGroup.sync() +// await boGroups[0].sync() - groupName = await boGroup.groupName() +// numMembers = (await boGroups[0].memberInboxIds()).length +// assert(numMembers === 3, 'num members should be 3') - assert( - groupName === 'Test name update 1', - 'group name should be "Test name update 1"' - ) +// // eslint-disable-next-line @typescript-eslint/no-unused-vars +// const _alixGroup2 = await alix.conversations.newGroup([ +// bo.address, +// caro.address, +// ]) +// await bo.conversations.syncGroups() +// boGroups = await bo.conversations.listGroups() +// assert(boGroups.length === 2, 'num groups for bo is 2') - await alixGroup.addMembers([caro.address]) - await caro.conversations.syncGroups() - const caroGroup = (await caro.conversations.listGroups())[0] +// // Even before syncing the group, syncGroups will return the initial number of members +// numMembers = (await boGroups[1].memberInboxIds()).length +// assert(numMembers === 3, 'num members should be 3') - await caroGroup.sync() - groupName = await caroGroup.groupName() - assert( - groupName === 'Test name update 1', - 'group name should be "Test name update 1"' - ) - return true -}) +// return true +// }) -test('can list groups does not fork', async () => { - const [alix, bo] = await createClients(2) - console.log('created clients') - let groupCallbacks = 0 - //#region Stream groups - await bo.conversations.streamGroups(async () => { - console.log('group received') - groupCallbacks++ - }) - //#region Stream All Messages - await bo.conversations.streamAllMessages(async () => { - console.log('message received') - }, true) - //#endregion - // #region create group - const alixGroup = await alix.conversations.newGroup([bo.address]) - await alixGroup.updateGroupName('hello') - await alixGroup.send('hello1') - console.log('sent group message') - // #endregion - // #region sync groups - await bo.conversations.syncGroups() - // #endregion - const boGroups = await bo.conversations.listGroups() - assert(boGroups.length === 1, 'bo should have 1 group') - const boGroup = boGroups[0] - await boGroup.sync() - - const boMessages1 = await boGroup.messages() - assert( - boMessages1.length === 2, - `should have 2 messages on first load received ${boMessages1.length}` - ) - await boGroup.send('hello2') - await boGroup.send('hello3') - await alixGroup.sync() - const alixMessages = await alixGroup.messages() - for (const message of alixMessages) { - console.log( - 'message', - message.contentTypeId, - message.contentTypeId === 'xmtp.org/text:1.0' - ? message.content() - : 'Group Updated' - ) - } - // alix sees 3 messages - assert( - alixMessages.length === 5, - `should have 5 messages on first load received ${alixMessages.length}` - ) - await alixGroup.send('hello4') - await boGroup.sync() - const boMessages2 = await boGroup.messages() - for (const message of boMessages2) { - console.log( - 'message', - message.contentTypeId, - message.contentTypeId === 'xmtp.org/text:1.0' - ? message.content() - : 'Group Updated' - ) - } - // bo sees 4 messages - assert( - boMessages2.length === 5, - `should have 5 messages on second load received ${boMessages2.length}` - ) +// test('can read and update group name', async () => { +// const [alix, bo, caro] = await createClients(3) +// const alixGroup = await alix.conversations.newGroup([bo.address]) - assert(groupCallbacks === 1, 'group stream should have received 1 group') +// await alixGroup.sync() +// let groupName = await alixGroup.groupName() - return true -}) +// assert(groupName === '', 'group name should be empty string') -test('can create new installation without breaking group', async () => { - const keyBytes = new Uint8Array([ - 233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64, - 166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, 145, - ]) - const wallet1 = Wallet.createRandom() - const wallet2 = Wallet.createRandom() +// await alixGroup.updateGroupName('Test name update 1') - const client1 = await Client.create(wallet1, { - env: 'local', - appVersion: 'Testing/0.0.0', - enableV3: true, - dbEncryptionKey: keyBytes, - }) - const client2 = await Client.create(wallet2, { - env: 'local', - appVersion: 'Testing/0.0.0', - enableV3: true, - dbEncryptionKey: keyBytes, - }) +// await alixGroup.sync() +// groupName = await alixGroup.groupName() - const group = await client1.conversations.newGroup([wallet2.address]) +// assert( +// groupName === 'Test name update 1', +// 'group name should be "Test name update 1"' +// ) - await client1.conversations.syncGroups() - await client2.conversations.syncGroups() +// await bo.conversations.syncGroups() +// const boGroup = (await bo.conversations.listGroups())[0] +// groupName = await boGroup.groupName() - const client1Group = await client1.conversations.findGroup(group.id) - const client2Group = await client2.conversations.findGroup(group.id) +// assert(groupName === '', 'group name should be empty string') - await client1Group?.sync() - await client2Group?.sync() +// await boGroup.sync() - assert(client1Group?.members?.length === 2, `client 1 should see 2 members`) +// groupName = await boGroup.groupName() - assert( - (await client2Group?.membersList())?.length === 2, - `client 2 should see 2 members` - ) +// assert( +// groupName === 'Test name update 1', +// 'group name should be "Test name update 1"' +// ) - await client2.deleteLocalDatabase() +// await alixGroup.addMembers([caro.address]) +// await caro.conversations.syncGroups() +// const caroGroup = (await caro.conversations.listGroups())[0] - // Recreating a client with wallet 2 (new installation!) - await Client.create(wallet2, { - env: 'local', - appVersion: 'Testing/0.0.0', - enableV3: true, - dbEncryptionKey: keyBytes, - }) +// await caroGroup.sync() +// groupName = await caroGroup.groupName() +// assert( +// groupName === 'Test name update 1', +// 'group name should be "Test name update 1"' +// ) +// return true +// }) - await client1Group?.send('This message will break the group') - assert( - client1Group?.members?.length === 2, - `client 1 should still see the 2 members` - ) +// test('can list groups does not fork', async () => { +// const [alix, bo] = await createClients(2) +// console.log('created clients') +// let groupCallbacks = 0 +// //#region Stream groups +// await bo.conversations.streamGroups(async () => { +// console.log('group received') +// groupCallbacks++ +// }) +// //#region Stream All Messages +// await bo.conversations.streamAllMessages(async () => { +// console.log('message received') +// }, true) +// //#endregion +// // #region create group +// const alixGroup = await alix.conversations.newGroup([bo.address]) +// await alixGroup.updateGroupName('hello') +// await alixGroup.send('hello1') +// console.log('sent group message') +// // #endregion +// // #region sync groups +// await bo.conversations.syncGroups() +// // #endregion +// const boGroups = await bo.conversations.listGroups() +// assert(boGroups.length === 1, 'bo should have 1 group') +// const boGroup = boGroups[0] +// await boGroup.sync() + +// const boMessages1 = await boGroup.messages() +// assert( +// boMessages1.length === 2, +// `should have 2 messages on first load received ${boMessages1.length}` +// ) +// await boGroup.send('hello2') +// await boGroup.send('hello3') +// await alixGroup.sync() +// const alixMessages = await alixGroup.messages() +// for (const message of alixMessages) { +// console.log( +// 'message', +// message.contentTypeId, +// message.contentTypeId === 'xmtp.org/text:1.0' +// ? message.content() +// : 'Group Updated' +// ) +// } +// // alix sees 3 messages +// assert( +// alixMessages.length === 5, +// `should have 5 messages on first load received ${alixMessages.length}` +// ) +// await alixGroup.send('hello4') +// await boGroup.sync() +// const boMessages2 = await boGroup.messages() +// for (const message of boMessages2) { +// console.log( +// 'message', +// message.contentTypeId, +// message.contentTypeId === 'xmtp.org/text:1.0' +// ? message.content() +// : 'Group Updated' +// ) +// } +// // bo sees 4 messages +// assert( +// boMessages2.length === 5, +// `should have 5 messages on second load received ${boMessages2.length}` +// ) - return true -}) +// assert(groupCallbacks === 1, 'group stream should have received 1 group') -test('can list many groups members in parallel', async () => { - const [alix, bo] = await createClients(2) - const groups: Group[] = await createGroups(alix, [bo], 20, 0) +// return true +// }) - try { - await Promise.all(groups.slice(0, 10).map((g) => g.membersList())) - } catch (e) { - throw new Error(`Failed listing 10 groups members with ${e}`) - } +// test('can create new installation without breaking group', async () => { +// const keyBytes = new Uint8Array([ +// 233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64, +// 166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, 145, +// ]) +// const wallet1 = Wallet.createRandom() +// const wallet2 = Wallet.createRandom() + +// const client1 = await Client.create(wallet1, { +// env: 'local', +// appVersion: 'Testing/0.0.0', +// enableV3: true, +// dbEncryptionKey: keyBytes, +// }) +// const client2 = await Client.create(wallet2, { +// env: 'local', +// appVersion: 'Testing/0.0.0', +// enableV3: true, +// dbEncryptionKey: keyBytes, +// }) + +// const group = await client1.conversations.newGroup([wallet2.address]) + +// await client1.conversations.syncGroups() +// await client2.conversations.syncGroups() + +// const client1Group = await client1.conversations.findGroup(group.id) +// const client2Group = await client2.conversations.findGroup(group.id) + +// await client1Group?.sync() +// await client2Group?.sync() + +// assert(client1Group?.members?.length === 2, `client 1 should see 2 members`) + +// assert( +// (await client2Group?.membersList())?.length === 2, +// `client 2 should see 2 members` +// ) + +// await client2.deleteLocalDatabase() + +// // Recreating a client with wallet 2 (new installation!) +// await Client.create(wallet2, { +// env: 'local', +// appVersion: 'Testing/0.0.0', +// enableV3: true, +// dbEncryptionKey: keyBytes, +// }) + +// await client1Group?.send('This message will break the group') +// assert( +// client1Group?.members?.length === 2, +// `client 1 should still see the 2 members` +// ) - try { - await Promise.all(groups.slice(0, 20).map((g) => g.membersList())) - } catch (e) { - throw new Error(`Failed listing 20 groups members with ${e}`) - } +// return true +// }) - return true -}) +// test('can list many groups members in parallel', async () => { +// const [alix, bo] = await createClients(2) +// const groups: Group[] = await createGroups(alix, [bo], 20, 0) -test('can sync all groups', async () => { - const [alix, bo] = await createClients(2) - const groups: Group[] = await createGroups(alix, [bo], 50, 0) +// try { +// await Promise.all(groups.slice(0, 10).map((g) => g.membersList())) +// } catch (e) { +// throw new Error(`Failed listing 10 groups members with ${e}`) +// } - const alixGroup = groups[0] - await bo.conversations.syncGroups() - const boGroup = await bo.conversations.findGroup(alixGroup.id) - await alixGroup.send('hi') - assert( - (await boGroup?.messages())?.length === 0, - `messages should be empty before sync but was ${boGroup?.messages?.length}` - ) +// try { +// await Promise.all(groups.slice(0, 20).map((g) => g.membersList())) +// } catch (e) { +// throw new Error(`Failed listing 20 groups members with ${e}`) +// } - const numGroupsSynced = await bo.conversations.syncAllGroups() - assert( - (await boGroup?.messages())?.length === 1, - `messages should be 4 after sync but was ${boGroup?.messages?.length}` - ) - assert( - numGroupsSynced === 50, - `should have synced 50 groups but synced ${numGroupsSynced}` - ) +// return true +// }) - for (const group of groups) { - await group.removeMembers([bo.address]) - } +// test('can sync all groups', async () => { +// const [alix, bo] = await createClients(2) +// const groups: Group[] = await createGroups(alix, [bo], 50, 0) + +// const alixGroup = groups[0] +// await bo.conversations.syncGroups() +// const boGroup = await bo.conversations.findGroup(alixGroup.id) +// await alixGroup.send('hi') +// assert( +// (await boGroup?.messages())?.length === 0, +// `messages should be empty before sync but was ${boGroup?.messages?.length}` +// ) + +// const numGroupsSynced = await bo.conversations.syncAllGroups() +// assert( +// (await boGroup?.messages())?.length === 1, +// `messages should be 4 after sync but was ${boGroup?.messages?.length}` +// ) +// assert( +// numGroupsSynced === 50, +// `should have synced 50 groups but synced ${numGroupsSynced}` +// ) + +// for (const group of groups) { +// await group.removeMembers([bo.address]) +// } - // First syncAllGroups after removal will still sync each group to set group inactive - // For some reason on Android (RN only), first syncAllGroups already returns 0 - const numGroupsSynced2 = await bo.conversations.syncAllGroups() - if (Platform.OS === 'ios') { - assert( - numGroupsSynced2 === 50, - `should have synced 50 groups but synced ${numGroupsSynced2}` - ) - } else { - assert( - numGroupsSynced2 === 0, - `should have synced 0 groups but synced ${numGroupsSynced2}` - ) - } +// // First syncAllGroups after removal will still sync each group to set group inactive +// // For some reason on Android (RN only), first syncAllGroups already returns 0 +// const numGroupsSynced2 = await bo.conversations.syncAllGroups() +// if (Platform.OS === 'ios') { +// assert( +// numGroupsSynced2 === 50, +// `should have synced 50 groups but synced ${numGroupsSynced2}` +// ) +// } else { +// assert( +// numGroupsSynced2 === 0, +// `should have synced 0 groups but synced ${numGroupsSynced2}` +// ) +// } - // Next syncAllGroups will not sync inactive groups - const numGroupsSynced3 = await bo.conversations.syncAllGroups() - assert( - numGroupsSynced3 === 0, - `should have synced 0 groups but synced ${numGroupsSynced3}` - ) - return true -}) +// // Next syncAllGroups will not sync inactive groups +// const numGroupsSynced3 = await bo.conversations.syncAllGroups() +// assert( +// numGroupsSynced3 === 0, +// `should have synced 0 groups but synced ${numGroupsSynced3}` +// ) +// return true +// }) // Commenting this out so it doesn't block people, but nice to have? // test('can stream messages for a long time', async () => { From d47485e7095d9e166935966bdef6450cdf980ad7 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Mon, 2 Sep 2024 21:09:33 -0600 Subject: [PATCH 2/4] Bump to working iOS version --- example/ios/Podfile.lock | 8 ++++---- example/src/tests/groupTests.ts | 4 ++-- ios/XMTPModule.swift | 1 + ios/XMTPReactNative.podspec | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 183c410d4..24d1238a1 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -449,7 +449,7 @@ PODS: - GenericJSON (~> 2.0) - Logging (~> 1.0.0) - secp256k1.swift (~> 0.1) - - XMTP (0.14.10): + - XMTP (0.14.11): - Connect-Swift (= 0.12.0) - GzipSwift - LibXMTP (= 0.5.8-beta3) @@ -458,7 +458,7 @@ PODS: - ExpoModulesCore - MessagePacker - secp256k1.swift - - XMTP (= 0.14.10) + - XMTP (= 0.14.11) - Yoga (1.14.0) DEPENDENCIES: @@ -763,8 +763,8 @@ SPEC CHECKSUMS: secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634 SwiftProtobuf: 407a385e97fd206c4fbe880cc84123989167e0d1 web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959 - XMTP: f6464951bba381352f838986a2b75dc14fc1e2cf - XMTPReactNative: ce44b033a57907e5e9747927614e980099b5b2f4 + XMTP: cb6058bf6e097b453c502b8dd00f7ddaf68a9c20 + XMTPReactNative: 2f169f481dc0c97acc90298525837f0d363bc33f Yoga: e71803b4c1fff832ccf9b92541e00f9b873119b9 PODFILE CHECKSUM: 0e6fe50018f34e575d38dc6a1fdf1f99c9596cdd diff --git a/example/src/tests/groupTests.ts b/example/src/tests/groupTests.ts index 244f839ca..286e9dfcf 100644 --- a/example/src/tests/groupTests.ts +++ b/example/src/tests/groupTests.ts @@ -978,8 +978,8 @@ test('can cancel streams', async () => { await delayToPropogate() await group.send('hello') - // await group.send('hello') - // await group.send('hello') + await group.send('hello') + await group.send('hello') await delayToPropogate() diff --git a/ios/XMTPModule.swift b/ios/XMTPModule.swift index b655a0c95..571875692 100644 --- a/ios/XMTPModule.swift +++ b/ios/XMTPModule.swift @@ -1298,6 +1298,7 @@ public class XMTPModule: Module { } AsyncFunction("unsubscribeFromAllMessages") { (inboxId: String) in + print("unsubscribeFromAllMessages") await subscriptionsManager.get(getMessagesKey(inboxId: inboxId))?.cancel() } diff --git a/ios/XMTPReactNative.podspec b/ios/XMTPReactNative.podspec index 071859e35..620d8d3f5 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.14.10" + s.dependency "XMTP", "= 0.14.11" end From 6473562036661b14cc79f964f94865f4c1206369 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Mon, 2 Sep 2024 21:28:04 -0600 Subject: [PATCH 3/4] fix: streams all messages can be canceled --- example/src/tests/groupTests.ts | 3816 +++++++++++++++---------------- ios/XMTPModule.swift | 1 - 2 files changed, 1908 insertions(+), 1909 deletions(-) diff --git a/example/src/tests/groupTests.ts b/example/src/tests/groupTests.ts index 286e9dfcf..76687ea69 100644 --- a/example/src/tests/groupTests.ts +++ b/example/src/tests/groupTests.ts @@ -42,920 +42,920 @@ async function createGroups( return groups } -// test('can make a MLS V3 client', async () => { -// // eslint-disable-next-line @typescript-eslint/no-unused-vars -// const keyBytes = new Uint8Array([ -// 233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64, -// 166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, 145, -// ]) -// const client = await Client.createRandom({ -// env: 'local', -// appVersion: 'Testing/0.0.0', -// enableV3: true, -// dbEncryptionKey: keyBytes, -// }) - -// const inboxId = await Client.getOrCreateInboxId(client.address, { -// env: 'local', -// }) - -// assert( -// client.inboxId === inboxId, -// `inboxIds should match but were ${client.inboxId} and ${inboxId}` -// ) -// return true -// }) +test('can make a MLS V3 client', async () => { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const keyBytes = new Uint8Array([ + 233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64, + 166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, 145, + ]) + const client = await Client.createRandom({ + env: 'local', + appVersion: 'Testing/0.0.0', + enableV3: true, + dbEncryptionKey: keyBytes, + }) + + const inboxId = await Client.getOrCreateInboxId(client.address, { + env: 'local', + }) -// test('can revoke all other installations', async () => { -// const keyBytes = new Uint8Array([ -// 233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64, -// 166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, 145, -// ]) -// const alixWallet = Wallet.createRandom() - -// const alix = await Client.create(alixWallet, { -// env: 'local', -// appVersion: 'Testing/0.0.0', -// enableV3: true, -// dbEncryptionKey: keyBytes, -// }) -// await alix.deleteLocalDatabase() - -// const alix2 = await Client.create(alixWallet, { -// env: 'local', -// appVersion: 'Testing/0.0.0', -// enableV3: true, -// dbEncryptionKey: keyBytes, -// }) - -// const inboxState = await alix2.inboxState(true) -// assert( -// inboxState.installationIds.length === 2, -// `installationIds length should be 2 but was ${inboxState.installationIds.length}` -// ) - -// await alix2.revokeAllOtherInstallations(alixWallet) - -// const inboxState2 = await alix2.inboxState(true) -// assert( -// inboxState2.installationIds.length === 1, -// `installationIds length should be 1 but was ${inboxState2.installationIds.length}` -// ) -// return true -// }) + assert( + client.inboxId === inboxId, + `inboxIds should match but were ${client.inboxId} and ${inboxId}` + ) + return true +}) -// test('calls preAuthenticateToInboxCallback when supplied', async () => { -// let isCallbackCalled = 0 -// let isPreAuthCalled = false -// const preAuthenticateToInboxCallback = () => { -// isCallbackCalled++ -// isPreAuthCalled = true -// } -// const preEnableIdentityCallback = () => { -// isCallbackCalled++ -// } -// const preCreateIdentityCallback = () => { -// isCallbackCalled++ -// } -// const keyBytes = new Uint8Array([ -// 233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64, -// 166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, 145, -// ]) - -// await Client.createRandom({ -// env: 'local', -// enableV3: true, -// preEnableIdentityCallback, -// preCreateIdentityCallback, -// preAuthenticateToInboxCallback, -// dbEncryptionKey: keyBytes, -// }) - -// assert( -// isCallbackCalled === 3, -// `callback should be called 3 times but was ${isCallbackCalled}` -// ) - -// if (!isPreAuthCalled) { -// throw new Error('preAuthenticateToInboxCallback not called') -// } +test('can revoke all other installations', async () => { + const keyBytes = new Uint8Array([ + 233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64, + 166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, 145, + ]) + const alixWallet = Wallet.createRandom() + + const alix = await Client.create(alixWallet, { + env: 'local', + appVersion: 'Testing/0.0.0', + enableV3: true, + dbEncryptionKey: keyBytes, + }) + await alix.deleteLocalDatabase() + + const alix2 = await Client.create(alixWallet, { + env: 'local', + appVersion: 'Testing/0.0.0', + enableV3: true, + dbEncryptionKey: keyBytes, + }) + + const inboxState = await alix2.inboxState(true) + assert( + inboxState.installationIds.length === 2, + `installationIds length should be 2 but was ${inboxState.installationIds.length}` + ) -// return true -// }) + await alix2.revokeAllOtherInstallations(alixWallet) -// test('can delete a local database', async () => { -// let [client, anotherClient] = await createClients(2) - -// await client.conversations.newGroup([anotherClient.address]) -// await client.conversations.syncGroups() -// assert( -// (await client.conversations.listGroups()).length === 1, -// `should have a group size of 1 but was ${ -// (await client.conversations.listGroups()).length -// }` -// ) - -// assert( -// client.dbPath !== '', -// `client dbPath should be set but was ${client.dbPath}` -// ) -// await client.deleteLocalDatabase() -// client = await Client.createRandom({ -// env: 'local', -// appVersion: 'Testing/0.0.0', -// enableV3: true, -// dbEncryptionKey: new Uint8Array([ -// 233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64, -// 166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, -// 145, -// ]), -// }) -// await client.conversations.syncGroups() -// assert( -// (await client.conversations.listGroups()).length === 0, -// `should have a group size of 0 but was ${ -// (await client.conversations.listGroups()).length -// }` -// ) + const inboxState2 = await alix2.inboxState(true) + assert( + inboxState2.installationIds.length === 1, + `installationIds length should be 1 but was ${inboxState2.installationIds.length}` + ) + return true +}) -// return true -// }) +test('calls preAuthenticateToInboxCallback when supplied', async () => { + let isCallbackCalled = 0 + let isPreAuthCalled = false + const preAuthenticateToInboxCallback = () => { + isCallbackCalled++ + isPreAuthCalled = true + } + const preEnableIdentityCallback = () => { + isCallbackCalled++ + } + const preCreateIdentityCallback = () => { + isCallbackCalled++ + } + const keyBytes = new Uint8Array([ + 233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64, + 166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, 145, + ]) + + await Client.createRandom({ + env: 'local', + enableV3: true, + preEnableIdentityCallback, + preCreateIdentityCallback, + preAuthenticateToInboxCallback, + dbEncryptionKey: keyBytes, + }) -// test('can make a MLS V3 client with encryption key and database directory', async () => { -// // eslint-disable-next-line @typescript-eslint/no-unused-vars -// const dbDirPath = `${RNFS.DocumentDirectoryPath}/xmtp_db` -// const directoryExists = await RNFS.exists(dbDirPath) -// if (!directoryExists) { -// await RNFS.mkdir(dbDirPath) -// } -// const key = new Uint8Array([ -// 233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64, -// 166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, 145, -// ]) - -// const client = await Client.createRandom({ -// env: 'local', -// appVersion: 'Testing/0.0.0', -// enableV3: true, -// dbEncryptionKey: key, -// dbDirectory: dbDirPath, -// }) - -// const anotherClient = await Client.createRandom({ -// env: 'local', -// appVersion: 'Testing/0.0.0', -// enableV3: true, -// dbEncryptionKey: key, -// }) - -// await client.conversations.newGroup([anotherClient.address]) -// assert( -// (await client.conversations.listGroups()).length === 1, -// `should have a group size of 1 but was ${ -// (await client.conversations.listGroups()).length -// }` -// ) - -// const bundle = await client.exportKeyBundle() -// const clientFromBundle = await Client.createFromKeyBundle(bundle, { -// env: 'local', -// appVersion: 'Testing/0.0.0', -// enableV3: true, -// dbEncryptionKey: key, -// dbDirectory: dbDirPath, -// }) - -// assert( -// clientFromBundle.address === client.address, -// `clients dont match ${client.address} and ${clientFromBundle.address}` -// ) - -// assert( -// (await clientFromBundle.conversations.listGroups()).length === 1, -// `should have a group size of 1 but was ${ -// (await clientFromBundle.conversations.listGroups()).length -// }` -// ) -// return true -// }) + assert( + isCallbackCalled === 3, + `callback should be called 3 times but was ${isCallbackCalled}` + ) -// test('testing large group listing with metadata performance', async () => { -// const [alixClient, boClient] = await createClients(2) + if (!isPreAuthCalled) { + throw new Error('preAuthenticateToInboxCallback not called') + } -// await createGroups(alixClient, [boClient], 50, 10) + return true +}) -// let start = Date.now() -// let groups = await alixClient.conversations.listGroups() -// let end = Date.now() -// console.log(`Alix loaded ${groups.length} groups in ${end - start}ms`) +test('can delete a local database', async () => { + let [client, anotherClient] = await createClients(2) -// start = Date.now() -// await alixClient.conversations.syncGroups() -// end = Date.now() -// console.log(`Alix synced ${groups.length} groups in ${end - start}ms`) + await client.conversations.newGroup([anotherClient.address]) + await client.conversations.syncGroups() + assert( + (await client.conversations.listGroups()).length === 1, + `should have a group size of 1 but was ${ + (await client.conversations.listGroups()).length + }` + ) -// start = Date.now() -// await boClient.conversations.syncGroups() -// end = Date.now() -// console.log(`Bo synced ${groups.length} groups in ${end - start}ms`) + assert( + client.dbPath !== '', + `client dbPath should be set but was ${client.dbPath}` + ) + await client.deleteLocalDatabase() + client = await Client.createRandom({ + env: 'local', + appVersion: 'Testing/0.0.0', + enableV3: true, + dbEncryptionKey: new Uint8Array([ + 233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64, + 166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, + 145, + ]), + }) + await client.conversations.syncGroups() + assert( + (await client.conversations.listGroups()).length === 0, + `should have a group size of 0 but was ${ + (await client.conversations.listGroups()).length + }` + ) -// start = Date.now() -// groups = await boClient.conversations.listGroups() -// end = Date.now() -// console.log(`Bo loaded ${groups.length} groups in ${end - start}ms`) + return true +}) -// return true -// }) +test('can make a MLS V3 client with encryption key and database directory', async () => { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const dbDirPath = `${RNFS.DocumentDirectoryPath}/xmtp_db` + const directoryExists = await RNFS.exists(dbDirPath) + if (!directoryExists) { + await RNFS.mkdir(dbDirPath) + } + const key = new Uint8Array([ + 233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64, + 166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, 145, + ]) + + const client = await Client.createRandom({ + env: 'local', + appVersion: 'Testing/0.0.0', + enableV3: true, + dbEncryptionKey: key, + dbDirectory: dbDirPath, + }) + + const anotherClient = await Client.createRandom({ + env: 'local', + appVersion: 'Testing/0.0.0', + enableV3: true, + dbEncryptionKey: key, + }) + + await client.conversations.newGroup([anotherClient.address]) + assert( + (await client.conversations.listGroups()).length === 1, + `should have a group size of 1 but was ${ + (await client.conversations.listGroups()).length + }` + ) -// test('can drop a local database', async () => { -// const [client, anotherClient] = await createClients(2) - -// const group = await client.conversations.newGroup([anotherClient.address]) -// await client.conversations.syncGroups() -// assert( -// (await client.conversations.listGroups()).length === 1, -// `should have a group size of 1 but was ${ -// (await client.conversations.listGroups()).length -// }` -// ) - -// await client.dropLocalDatabaseConnection() - -// try { -// await group.send('hi') -// // eslint-disable-next-line @typescript-eslint/no-unused-vars -// } catch (error) { -// await client.reconnectLocalDatabase() -// await group.send('hi') -// return true -// } -// throw new Error('should throw when local database not connected') -// }) + const bundle = await client.exportKeyBundle() + const clientFromBundle = await Client.createFromKeyBundle(bundle, { + env: 'local', + appVersion: 'Testing/0.0.0', + enableV3: true, + dbEncryptionKey: key, + dbDirectory: dbDirPath, + }) -// test('can drop client from memory', async () => { -// const [client, anotherClient] = await createClients(2) -// await client.dropLocalDatabaseConnection() -// await anotherClient.dropLocalDatabaseConnection() - -// await client.reconnectLocalDatabase() -// await Client.dropClient(anotherClient.inboxId) -// try { -// await anotherClient.reconnectLocalDatabase() -// return false -// // eslint-disable-next-line @typescript-eslint/no-unused-vars -// } catch (error) { -// // We cannot reconnect anotherClient because it was successfully dropped -// return true -// } -// }) + assert( + clientFromBundle.address === client.address, + `clients dont match ${client.address} and ${clientFromBundle.address}` + ) -// test('can get a inboxId from an address', async () => { -// const [alix, bo] = await createClients(2) + assert( + (await clientFromBundle.conversations.listGroups()).length === 1, + `should have a group size of 1 but was ${ + (await clientFromBundle.conversations.listGroups()).length + }` + ) + return true +}) -// const boInboxId = await alix.findInboxIdFromAddress(bo.address) -// assert(boInboxId === bo.inboxId, `${boInboxId} should match ${bo.inboxId}`) -// return true -// }) +test('testing large group listing with metadata performance', async () => { + const [alixClient, boClient] = await createClients(2) -// test('can make a MLS V3 client from bundle', async () => { -// const key = new Uint8Array([ -// 233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64, -// 166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, 145, -// ]) - -// const client = await Client.createRandom({ -// env: 'local', -// appVersion: 'Testing/0.0.0', -// enableV3: true, -// dbEncryptionKey: key, -// }) - -// const anotherClient = await Client.createRandom({ -// env: 'local', -// appVersion: 'Testing/0.0.0', -// enableV3: true, -// dbEncryptionKey: key, -// }) - -// const group1 = await client.conversations.newGroup([anotherClient.address]) - -// assert( -// group1.client.address === client.address, -// `clients dont match ${client.address} and ${group1.client.address}` -// ) - -// const bundle = await client.exportKeyBundle() -// const client2 = await Client.createFromKeyBundle(bundle, { -// env: 'local', -// appVersion: 'Testing/0.0.0', -// enableV3: true, -// dbEncryptionKey: key, -// }) - -// assert( -// client.address === client2.address, -// `clients dont match ${client2.address} and ${client.address}` -// ) - -// assert( -// client.inboxId === client2.inboxId, -// `clients dont match ${client2.inboxId} and ${client.inboxId}` -// ) - -// assert( -// client.installationId === client2.installationId, -// `clients dont match ${client2.installationId} and ${client.installationId}` -// ) - -// const randomClient = await Client.createRandom({ -// env: 'local', -// appVersion: 'Testing/0.0.0', -// enableV3: true, -// dbEncryptionKey: key, -// }) - -// const group = await client2.conversations.newGroup([randomClient.address]) - -// assert( -// group.client.address === client2.address, -// `clients dont match ${client2.address} and ${group.client.address}` -// ) + await createGroups(alixClient, [boClient], 50, 10) -// return true -// }) + let start = Date.now() + let groups = await alixClient.conversations.listGroups() + let end = Date.now() + console.log(`Alix loaded ${groups.length} groups in ${end - start}ms`) -// test('production MLS V3 client creation does not error', async () => { -// const key = new Uint8Array([ -// 233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64, -// 166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, 145, -// ]) - -// try { -// await Client.createRandom({ -// env: 'production', -// appVersion: 'Testing/0.0.0', -// enableV3: true, -// dbEncryptionKey: key, -// }) -// // eslint-disable-next-line @typescript-eslint/no-unused-vars -// } catch (error) { -// throw error -// } -// return true -// }) + start = Date.now() + await alixClient.conversations.syncGroups() + end = Date.now() + console.log(`Alix synced ${groups.length} groups in ${end - start}ms`) -// test('group message delivery status', async () => { -// const [alixClient, boClient] = await createClients(2) -// const alixGroup = await alixClient.conversations.newGroup([boClient.address]) + start = Date.now() + await boClient.conversations.syncGroups() + end = Date.now() + console.log(`Bo synced ${groups.length} groups in ${end - start}ms`) -// await alixGroup.send('hello, world') + start = Date.now() + groups = await boClient.conversations.listGroups() + end = Date.now() + console.log(`Bo loaded ${groups.length} groups in ${end - start}ms`) -// const alixMessages: DecodedMessage[] = await alixGroup.messages() + return true +}) -// assert( -// alixMessages.length === 2, -// `the messages length should be 2 but was ${alixMessages.length}` -// ) +test('can drop a local database', async () => { + const [client, anotherClient] = await createClients(2) -// const alixMessagesFiltered: DecodedMessage[] = await alixGroup.messages({ -// deliveryStatus: MessageDeliveryStatus.PUBLISHED, -// }) + const group = await client.conversations.newGroup([anotherClient.address]) + await client.conversations.syncGroups() + assert( + (await client.conversations.listGroups()).length === 1, + `should have a group size of 1 but was ${ + (await client.conversations.listGroups()).length + }` + ) -// assert( -// alixMessagesFiltered.length === 2, -// `the messages length should be 2 but was ${alixMessagesFiltered.length}` -// ) + await client.dropLocalDatabaseConnection() -// await alixGroup.sync() -// const alixMessages2: DecodedMessage[] = await alixGroup.messages() + try { + await group.send('hi') + // eslint-disable-next-line @typescript-eslint/no-unused-vars + } catch (error) { + await client.reconnectLocalDatabase() + await group.send('hi') + return true + } + throw new Error('should throw when local database not connected') +}) -// assert( -// alixMessages2.length === 2, -// `the messages length should be 2 but was ${alixMessages.length}` -// ) +test('can drop client from memory', async () => { + const [client, anotherClient] = await createClients(2) + await client.dropLocalDatabaseConnection() + await anotherClient.dropLocalDatabaseConnection() + + await client.reconnectLocalDatabase() + await Client.dropClient(anotherClient.inboxId) + try { + await anotherClient.reconnectLocalDatabase() + return false + // eslint-disable-next-line @typescript-eslint/no-unused-vars + } catch (error) { + // We cannot reconnect anotherClient because it was successfully dropped + return true + } +}) -// assert( -// alixMessages2[0].deliveryStatus === 'PUBLISHED', -// `the message should have a delivery status of PUBLISHED but was ${alixMessages2[0].deliveryStatus}` -// ) +test('can get a inboxId from an address', async () => { + const [alix, bo] = await createClients(2) -// await boClient.conversations.syncGroups() -// const boGroup = (await boClient.conversations.listGroups())[0] -// await boGroup.sync() -// const boMessages: DecodedMessage[] = await boGroup.messages() + const boInboxId = await alix.findInboxIdFromAddress(bo.address) + assert(boInboxId === bo.inboxId, `${boInboxId} should match ${bo.inboxId}`) + return true +}) -// assert( -// boMessages.length === 1, -// `the messages length should be 1 but was ${boMessages.length}` -// ) +test('can make a MLS V3 client from bundle', async () => { + const key = new Uint8Array([ + 233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64, + 166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, 145, + ]) -// assert( -// boMessages[0].deliveryStatus === 'PUBLISHED', -// `the message should have a delivery status of PUBLISHED but was ${boMessages[0].deliveryStatus}` -// ) + const client = await Client.createRandom({ + env: 'local', + appVersion: 'Testing/0.0.0', + enableV3: true, + dbEncryptionKey: key, + }) -// return true -// }) + const anotherClient = await Client.createRandom({ + env: 'local', + appVersion: 'Testing/0.0.0', + enableV3: true, + dbEncryptionKey: key, + }) -// test('can find a group by id', async () => { -// const [alixClient, boClient] = await createClients(2) -// const alixGroup = await alixClient.conversations.newGroup([boClient.address]) + const group1 = await client.conversations.newGroup([anotherClient.address]) -// await boClient.conversations.syncGroups() -// const boGroup = await boClient.conversations.findGroup(alixGroup.id) + assert( + group1.client.address === client.address, + `clients dont match ${client.address} and ${group1.client.address}` + ) -// assert( -// boGroup?.id === alixGroup.id, -// `bo ${boGroup?.id} does not match alix ${alixGroup.id}` -// ) -// return true -// }) + const bundle = await client.exportKeyBundle() + const client2 = await Client.createFromKeyBundle(bundle, { + env: 'local', + appVersion: 'Testing/0.0.0', + enableV3: true, + dbEncryptionKey: key, + }) -// test('can find a message by id', async () => { -// const [alixClient, boClient] = await createClients(2) -// const alixGroup = await alixClient.conversations.newGroup([boClient.address]) -// const alixMessageId = await alixGroup.send('Hello') + assert( + client.address === client2.address, + `clients dont match ${client2.address} and ${client.address}` + ) -// await boClient.conversations.syncGroups() -// const boGroup = await boClient.conversations.findGroup(alixGroup.id) -// await boGroup?.sync() -// const boMessage = await boClient.conversations.findV3Message(alixMessageId) + assert( + client.inboxId === client2.inboxId, + `clients dont match ${client2.inboxId} and ${client.inboxId}` + ) -// assert( -// boMessage?.id === alixMessageId, -// `bo message ${boMessage?.id} does not match ${alixMessageId}` -// ) -// return true -// }) + assert( + client.installationId === client2.installationId, + `clients dont match ${client2.installationId} and ${client.installationId}` + ) -// test('who added me to a group', async () => { -// const [alixClient, boClient] = await createClients(2) -// await alixClient.conversations.newGroup([boClient.address]) + const randomClient = await Client.createRandom({ + env: 'local', + appVersion: 'Testing/0.0.0', + enableV3: true, + dbEncryptionKey: key, + }) -// await boClient.conversations.syncGroups() -// const boGroup = (await boClient.conversations.listGroups())[0] -// const addedByInboxId = await boGroup.addedByInboxId + const group = await client2.conversations.newGroup([randomClient.address]) -// assert( -// addedByInboxId === alixClient.inboxId, -// `addedByInboxId ${addedByInboxId} does not match ${alixClient.inboxId}` -// ) -// return true -// }) + assert( + group.client.address === client2.address, + `clients dont match ${client2.address} and ${group.client.address}` + ) -// test('can get members of a group', async () => { -// const [alixClient, boClient] = await createClients(2) -// const group = await alixClient.conversations.newGroup([boClient.address]) - -// const members = group.members - -// assert(members.length === 2, `Should be 2 members but was ${members.length}`) - -// // We can not be sure of the order that members will be returned in -// for (const member of members) { -// // Alix created the group so they are a super admin -// if ( -// member.addresses[0].toLocaleLowerCase() === -// alixClient.address.toLocaleLowerCase() -// ) { -// assert( -// member.permissionLevel === 'super_admin', -// `Should be super_admin but was ${member.permissionLevel}` -// ) -// } -// // Bo did not create the group so he defaults to permission level "member" -// if ( -// member.addresses[0].toLocaleLowerCase() === -// boClient.address.toLocaleLowerCase() -// ) { -// assert( -// member.permissionLevel === 'member', -// `Should be member but was ${member.permissionLevel}` -// ) -// } -// } -// return true -// }) + return true +}) -// test('can message in a group', async () => { -// // Create three MLS enabled Clients -// const [alixClient, boClient, caroClient] = await createClients(3) +test('production MLS V3 client creation does not error', async () => { + const key = new Uint8Array([ + 233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64, + 166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, 145, + ]) + + try { + await Client.createRandom({ + env: 'production', + appVersion: 'Testing/0.0.0', + enableV3: true, + dbEncryptionKey: key, + }) + // eslint-disable-next-line @typescript-eslint/no-unused-vars + } catch (error) { + throw error + } + return true +}) -// // alix's num groups start at 0 -// let alixGroups = await alixClient.conversations.listGroups() -// if (alixGroups.length !== 0) { -// throw new Error('num groups should be 0') -// } +test('group message delivery status', async () => { + const [alixClient, boClient] = await createClients(2) + const alixGroup = await alixClient.conversations.newGroup([boClient.address]) -// // alix creates a group -// const alixGroup = await alixClient.conversations.newGroup([ -// boClient.address, -// caroClient.address, -// ]) - -// // alix's num groups == 1 -// await alixClient.conversations.syncGroups() -// alixGroups = await alixClient.conversations.listGroups() -// if (alixGroups.length !== 1) { -// throw new Error('num groups should be 1') -// } + await alixGroup.send('hello, world') -// // alix group should match create time from list function -// assert(alixGroups[0].createdAt === alixGroup.createdAt, 'group create time') + const alixMessages: DecodedMessage[] = await alixGroup.messages() -// // alix can confirm memberInboxIds -// await alixGroup.sync() -// const memberInboxIds = await alixGroup.memberInboxIds() -// if (memberInboxIds.length !== 3) { -// throw new Error('num group members should be 3') -// } + assert( + alixMessages.length === 2, + `the messages length should be 2 but was ${alixMessages.length}` + ) -// if ( -// !( -// memberInboxIds.includes(alixClient.inboxId) && -// memberInboxIds.includes(boClient.inboxId) && -// memberInboxIds.includes(caroClient.inboxId) -// ) -// ) { -// throw new Error('missing address') -// } + const alixMessagesFiltered: DecodedMessage[] = await alixGroup.messages({ + deliveryStatus: MessageDeliveryStatus.PUBLISHED, + }) -// // alix can send messages -// await alixGroup.send('hello, world') -// await alixGroup.send('gm') - -// // bo's num groups == 1 -// await boClient.conversations.syncGroups() -// const boGroups = await boClient.conversations.listGroups() -// if (boGroups.length !== 1) { -// throw new Error( -// 'num groups for bo should be 1, but it is' + boGroups.length -// ) -// } -// await delayToPropogate() -// // bo can read messages from alix -// await boGroups[0].sync() -// const boMessages: DecodedMessage[] = await boGroups[0].messages() - -// if (boMessages.length !== 2) { -// throw new Error( -// 'num messages for bo should be 2, but it is' + boMessages.length -// ) -// } -// if (boMessages[0].content() !== 'gm') { -// throw new Error("newest message should be 'gm'") -// } -// if (boMessages[1].content() !== 'hello, world') { -// throw new Error("newest message should be 'hello, world'") -// } -// // bo can send a message -// await boGroups[0].send('hey guys!') - -// // caro's num groups == 1 -// await caroClient.conversations.syncGroups() -// const caroGroups = await caroClient.conversations.listGroups() -// if (caroGroups.length !== 1) { -// throw new Error( -// 'num groups for caro should be 1, but it is' + caroGroups.length -// ) -// } + assert( + alixMessagesFiltered.length === 2, + `the messages length should be 2 but was ${alixMessagesFiltered.length}` + ) -// // caro can read messages from alix and bo -// await caroGroups[0].sync() -// const caroMessages = await caroGroups[0].messages() + await alixGroup.sync() + const alixMessages2: DecodedMessage[] = await alixGroup.messages() -// if (caroMessages.length !== 3) { -// throw new Error(`length should be 3 but was ${caroMessages.length}`) -// } -// if (caroMessages[0].content() !== 'hey guys!') { -// throw new Error( -// `newest Message should be 'hey guys!' but was ${caroMessages[0].content()}` -// ) -// } -// if (caroMessages[1].content() !== 'gm') { -// throw new Error( -// `second Message should be 'gm' but was ${caroMessages[1].content()}` -// ) -// } + assert( + alixMessages2.length === 2, + `the messages length should be 2 but was ${alixMessages.length}` + ) -// return true -// }) + assert( + alixMessages2[0].deliveryStatus === 'PUBLISHED', + `the message should have a delivery status of PUBLISHED but was ${alixMessages2[0].deliveryStatus}` + ) -// test('unpublished messages handling', async () => { -// // Initialize fixture clients -// const [alixClient, boClient] = await createClients(3) + await boClient.conversations.syncGroups() + const boGroup = (await boClient.conversations.listGroups())[0] + await boGroup.sync() + const boMessages: DecodedMessage[] = await boGroup.messages() -// // Create a new group with Bob and Alice -// const boGroup = await boClient.conversations.newGroup([alixClient.address]) + assert( + boMessages.length === 1, + `the messages length should be 1 but was ${boMessages.length}` + ) -// // Sync Alice's client to get the new group -// await alixClient.conversations.syncGroups() -// const alixGroup = await alixClient.conversations.findGroup(boGroup.id) -// if (!alixGroup) { -// throw new Error(`Group not found for id: ${boGroup.id}`) -// } + assert( + boMessages[0].deliveryStatus === 'PUBLISHED', + `the message should have a delivery status of PUBLISHED but was ${boMessages[0].deliveryStatus}` + ) -// // Check if the group is allowed initially -// let isGroupAllowed = await alixClient.contacts.isGroupAllowed(boGroup.id) -// if (isGroupAllowed) { -// throw new Error('Group should not be allowed initially') -// } + return true +}) -// // Prepare a message in the group -// const preparedMessageId = await alixGroup.prepareMessage('Test text') +test('can find a group by id', async () => { + const [alixClient, boClient] = await createClients(2) + const alixGroup = await alixClient.conversations.newGroup([boClient.address]) -// // Check if the group is allowed after preparing the message -// isGroupAllowed = await alixClient.contacts.isGroupAllowed(boGroup.id) -// if (!isGroupAllowed) { -// throw new Error('Group should be allowed after preparing a message') -// } + await boClient.conversations.syncGroups() + const boGroup = await boClient.conversations.findGroup(alixGroup.id) -// // Verify the message count in the group -// let messageCount = (await alixGroup.messages()).length -// if (messageCount !== 1) { -// throw new Error(`Message count should be 1, but it is ${messageCount}`) -// } + assert( + boGroup?.id === alixGroup.id, + `bo ${boGroup?.id} does not match alix ${alixGroup.id}` + ) + return true +}) -// // Verify the count of published and unpublished messages -// let messageCountPublished = ( -// await alixGroup.messages({ -// deliveryStatus: MessageDeliveryStatus.PUBLISHED, -// }) -// ).length -// let messageCountUnpublished = ( -// await alixGroup.messages({ -// deliveryStatus: MessageDeliveryStatus.UNPUBLISHED, -// }) -// ).length -// if (messageCountPublished !== 0) { -// throw new Error( -// `Published message count should be 0, but it is ${messageCountPublished}` -// ) -// } -// if (messageCountUnpublished !== 1) { -// throw new Error( -// `Unpublished message count should be 1, but it is ${messageCountUnpublished}` -// ) -// } +test('can find a message by id', async () => { + const [alixClient, boClient] = await createClients(2) + const alixGroup = await alixClient.conversations.newGroup([boClient.address]) + const alixMessageId = await alixGroup.send('Hello') -// // Publish the prepared message -// await alixGroup.publishPreparedMessages() - -// // Sync the group after publishing the message -// await alixGroup.sync() - -// // Verify the message counts again -// messageCountPublished = ( -// await alixGroup.messages({ -// deliveryStatus: MessageDeliveryStatus.PUBLISHED, -// }) -// ).length -// messageCountUnpublished = ( -// await alixGroup.messages({ -// deliveryStatus: MessageDeliveryStatus.UNPUBLISHED, -// }) -// ).length -// messageCount = (await alixGroup.messages()).length -// if (messageCountPublished !== 1) { -// throw new Error( -// `Published message count should be 1, but it is ${messageCountPublished}` -// ) -// } -// if (messageCountUnpublished !== 0) { -// throw new Error( -// `Unpublished message count should be 0, but it is ${messageCountUnpublished}` -// ) -// } -// if (messageCount !== 1) { -// throw new Error(`Message count should be 1, but it is ${messageCount}`) -// } + await boClient.conversations.syncGroups() + const boGroup = await boClient.conversations.findGroup(alixGroup.id) + await boGroup?.sync() + const boMessage = await boClient.conversations.findV3Message(alixMessageId) -// // Retrieve all messages and verify the prepared message ID -// const messages = await alixGroup.messages() -// if (preparedMessageId !== messages[0].id) { -// throw new Error(`Message ID should match the prepared message ID`) -// } + assert( + boMessage?.id === alixMessageId, + `bo message ${boMessage?.id} does not match ${alixMessageId}` + ) + return true +}) -// return true -// }) +test('who added me to a group', async () => { + const [alixClient, boClient] = await createClients(2) + await alixClient.conversations.newGroup([boClient.address]) -// test('can add members to a group', async () => { -// // Create three MLS enabled Clients -// const [alixClient, boClient, caroClient] = await createClients(3) + await boClient.conversations.syncGroups() + const boGroup = (await boClient.conversations.listGroups())[0] + const addedByInboxId = await boGroup.addedByInboxId -// // alix's num groups start at 0 -// let alixGroups = await alixClient.conversations.listGroups() -// if (alixGroups.length !== 0) { -// throw new Error('num groups should be 0') -// } + assert( + addedByInboxId === alixClient.inboxId, + `addedByInboxId ${addedByInboxId} does not match ${alixClient.inboxId}` + ) + return true +}) -// // bo's num groups start at 0 -// let boGroups = await boClient.conversations.listGroups() -// if (boGroups.length !== 0) { -// throw new Error('num groups should be 0') -// } +test('can get members of a group', async () => { + const [alixClient, boClient] = await createClients(2) + const group = await alixClient.conversations.newGroup([boClient.address]) + + const members = group.members + + assert(members.length === 2, `Should be 2 members but was ${members.length}`) + + // We can not be sure of the order that members will be returned in + for (const member of members) { + // Alix created the group so they are a super admin + if ( + member.addresses[0].toLocaleLowerCase() === + alixClient.address.toLocaleLowerCase() + ) { + assert( + member.permissionLevel === 'super_admin', + `Should be super_admin but was ${member.permissionLevel}` + ) + } + // Bo did not create the group so he defaults to permission level "member" + if ( + member.addresses[0].toLocaleLowerCase() === + boClient.address.toLocaleLowerCase() + ) { + assert( + member.permissionLevel === 'member', + `Should be member but was ${member.permissionLevel}` + ) + } + } + return true +}) -// // caro's num groups start at 0 -// let caroGroups = await caroClient.conversations.listGroups() -// if (caroGroups.length !== 0) { -// throw new Error('num groups should be 0') -// } +test('can message in a group', async () => { + // Create three MLS enabled Clients + const [alixClient, boClient, caroClient] = await createClients(3) -// // alix creates a group -// const alixGroup = await alixClient.conversations.newGroup([boClient.address]) + // alix's num groups start at 0 + let alixGroups = await alixClient.conversations.listGroups() + if (alixGroups.length !== 0) { + throw new Error('num groups should be 0') + } -// // alix's num groups == 1 -// await alixClient.conversations.syncGroups() -// alixGroups = await alixClient.conversations.listGroups() -// if (alixGroups.length !== 1) { -// throw new Error('num groups should be 1') -// } + // alix creates a group + const alixGroup = await alixClient.conversations.newGroup([ + boClient.address, + caroClient.address, + ]) + + // alix's num groups == 1 + await alixClient.conversations.syncGroups() + alixGroups = await alixClient.conversations.listGroups() + if (alixGroups.length !== 1) { + throw new Error('num groups should be 1') + } -// // alix can confirm memberInboxIds -// await alixGroup.sync() -// const memberInboxIds = await alixGroup.memberInboxIds() -// if (memberInboxIds.length !== 2) { -// throw new Error('num group members should be 2') -// } -// if ( -// !( -// memberInboxIds.includes(alixClient.inboxId) && -// memberInboxIds.includes(boClient.inboxId) -// ) -// ) { -// throw new Error('missing address') -// } + // alix group should match create time from list function + assert(alixGroups[0].createdAt === alixGroup.createdAt, 'group create time') -// // alix can send messages -// await alixGroup.send('hello, world') -// await alixGroup.send('gm') - -// // bo's num groups == 1 -// await boClient.conversations.syncGroups() -// boGroups = await boClient.conversations.listGroups() -// if (boGroups.length !== 1) { -// throw new Error( -// 'num groups for bo should be 1, but it is' + boGroups.length -// ) -// } + // alix can confirm memberInboxIds + await alixGroup.sync() + const memberInboxIds = await alixGroup.memberInboxIds() + if (memberInboxIds.length !== 3) { + throw new Error('num group members should be 3') + } -// await alixGroup.addMembers([caroClient.address]) + if ( + !( + memberInboxIds.includes(alixClient.inboxId) && + memberInboxIds.includes(boClient.inboxId) && + memberInboxIds.includes(caroClient.inboxId) + ) + ) { + throw new Error('missing address') + } -// // caro's num groups == 1 -// await caroClient.conversations.syncGroups() -// caroGroups = await caroClient.conversations.listGroups() -// if (caroGroups.length !== 1) { -// throw new Error( -// 'num groups for caro should be 1, but it is' + caroGroups.length -// ) -// } -// await caroGroups[0].sync() -// const caroMessages = await caroGroups[0].messages() -// if (caroMessages.length !== 0) { -// throw new Error('num messages for caro should be 0') -// } + // alix can send messages + await alixGroup.send('hello, world') + await alixGroup.send('gm') + + // bo's num groups == 1 + await boClient.conversations.syncGroups() + const boGroups = await boClient.conversations.listGroups() + if (boGroups.length !== 1) { + throw new Error( + 'num groups for bo should be 1, but it is' + boGroups.length + ) + } + await delayToPropogate() + // bo can read messages from alix + await boGroups[0].sync() + const boMessages: DecodedMessage[] = await boGroups[0].messages() + + if (boMessages.length !== 2) { + throw new Error( + 'num messages for bo should be 2, but it is' + boMessages.length + ) + } + if (boMessages[0].content() !== 'gm') { + throw new Error("newest message should be 'gm'") + } + if (boMessages[1].content() !== 'hello, world') { + throw new Error("newest message should be 'hello, world'") + } + // bo can send a message + await boGroups[0].send('hey guys!') + + // caro's num groups == 1 + await caroClient.conversations.syncGroups() + const caroGroups = await caroClient.conversations.listGroups() + if (caroGroups.length !== 1) { + throw new Error( + 'num groups for caro should be 1, but it is' + caroGroups.length + ) + } -// await boGroups[0].sync() -// const boGroupMembers = await boGroups[0].memberInboxIds() -// if (boGroupMembers.length !== 3) { -// throw new Error('num group members should be 3') -// } + // caro can read messages from alix and bo + await caroGroups[0].sync() + const caroMessages = await caroGroups[0].messages() -// return true -// }) + if (caroMessages.length !== 3) { + throw new Error(`length should be 3 but was ${caroMessages.length}`) + } + if (caroMessages[0].content() !== 'hey guys!') { + throw new Error( + `newest Message should be 'hey guys!' but was ${caroMessages[0].content()}` + ) + } + if (caroMessages[1].content() !== 'gm') { + throw new Error( + `second Message should be 'gm' but was ${caroMessages[1].content()}` + ) + } -// test('can remove members from a group', async () => { -// // Create three MLS enabled Clients -// const [alixClient, boClient, caroClient] = await createClients(3) + return true +}) -// // alix's num groups start at 0 -// let alixGroups = await alixClient.conversations.listGroups() -// if (alixGroups.length !== 0) { -// throw new Error('num groups should be 0') -// } +test('unpublished messages handling', async () => { + // Initialize fixture clients + const [alixClient, boClient] = await createClients(3) -// // bo's num groups start at 0 -// let boGroups = await boClient.conversations.listGroups() -// assert(boGroups.length === 0, 'num groups should be 0') + // Create a new group with Bob and Alice + const boGroup = await boClient.conversations.newGroup([alixClient.address]) -// // caro's num groups start at 0 -// let caroGroups = await caroClient.conversations.listGroups() -// if (caroGroups.length !== 0) { -// throw new Error('num groups should be 0') -// } + // Sync Alice's client to get the new group + await alixClient.conversations.syncGroups() + const alixGroup = await alixClient.conversations.findGroup(boGroup.id) + if (!alixGroup) { + throw new Error(`Group not found for id: ${boGroup.id}`) + } -// // alix creates a group -// const alixGroup = await alixClient.conversations.newGroup([ -// boClient.address, -// caroClient.address, -// ]) - -// // alix's num groups == 1 -// await alixClient.conversations.syncGroups() -// alixGroups = await alixClient.conversations.listGroups() -// if (alixGroups.length !== 1) { -// throw new Error('num groups should be 1') -// } + // Check if the group is allowed initially + let isGroupAllowed = await alixClient.contacts.isGroupAllowed(boGroup.id) + if (isGroupAllowed) { + throw new Error('Group should not be allowed initially') + } -// // alix can confirm memberInboxIds -// await alixGroup.sync() -// const memberInboxIds = await alixGroup.memberInboxIds() -// if (memberInboxIds.length !== 3) { -// throw new Error('num group members should be 3') -// } -// if ( -// !( -// memberInboxIds.includes(alixClient.inboxId) && -// memberInboxIds.includes(boClient.inboxId) -// ) -// ) { -// throw new Error('missing address') -// } + // Prepare a message in the group + const preparedMessageId = await alixGroup.prepareMessage('Test text') -// // alix can send messages -// await alixGroup.send('hello, world') -// await alixGroup.send('gm') - -// // bo's num groups == 1 -// await boClient.conversations.syncGroups() -// boGroups = await boClient.conversations.listGroups() -// if (boGroups.length !== 1) { -// throw new Error( -// 'num groups for bo should be 1, but it is' + boGroups.length -// ) -// } + // Check if the group is allowed after preparing the message + isGroupAllowed = await alixClient.contacts.isGroupAllowed(boGroup.id) + if (!isGroupAllowed) { + throw new Error('Group should be allowed after preparing a message') + } -// // caro's num groups == 1 -// await caroClient.conversations.syncGroups() -// caroGroups = await caroClient.conversations.listGroups() -// if (caroGroups.length !== 1) { -// throw new Error( -// 'num groups for caro should be 1, but it is' + caroGroups.length -// ) -// } + // Verify the message count in the group + let messageCount = (await alixGroup.messages()).length + if (messageCount !== 1) { + throw new Error(`Message count should be 1, but it is ${messageCount}`) + } -// await caroGroups[0].sync() -// if (!caroGroups[0].isActive()) { -// throw new Error('caros group should be active') -// } + // Verify the count of published and unpublished messages + let messageCountPublished = ( + await alixGroup.messages({ + deliveryStatus: MessageDeliveryStatus.PUBLISHED, + }) + ).length + let messageCountUnpublished = ( + await alixGroup.messages({ + deliveryStatus: MessageDeliveryStatus.UNPUBLISHED, + }) + ).length + if (messageCountPublished !== 0) { + throw new Error( + `Published message count should be 0, but it is ${messageCountPublished}` + ) + } + if (messageCountUnpublished !== 1) { + throw new Error( + `Unpublished message count should be 1, but it is ${messageCountUnpublished}` + ) + } -// await alixGroup.removeMembers([caroClient.address]) -// await alixGroup.sync() -// const alixGroupMembers = await alixGroup.memberInboxIds() -// if (alixGroupMembers.length !== 2) { -// throw new Error( -// 'num group members should be 2 but was' + alixGroupMembers.length -// ) -// } + // Publish the prepared message + await alixGroup.publishPreparedMessages() -// await caroGroups[0].sync() -// if (await caroGroups[0].isActive()) { -// throw new Error('caros group should not be active') -// } + // Sync the group after publishing the message + await alixGroup.sync() -// const caroGroupMembers = await caroGroups[0].memberInboxIds() -// if (caroGroupMembers.length !== 2) { -// throw new Error( -// 'num group members should be 2 but was' + caroGroupMembers.length -// ) -// } + // Verify the message counts again + messageCountPublished = ( + await alixGroup.messages({ + deliveryStatus: MessageDeliveryStatus.PUBLISHED, + }) + ).length + messageCountUnpublished = ( + await alixGroup.messages({ + deliveryStatus: MessageDeliveryStatus.UNPUBLISHED, + }) + ).length + messageCount = (await alixGroup.messages()).length + if (messageCountPublished !== 1) { + throw new Error( + `Published message count should be 1, but it is ${messageCountPublished}` + ) + } + if (messageCountUnpublished !== 0) { + throw new Error( + `Unpublished message count should be 0, but it is ${messageCountUnpublished}` + ) + } + if (messageCount !== 1) { + throw new Error(`Message count should be 1, but it is ${messageCount}`) + } + + // Retrieve all messages and verify the prepared message ID + const messages = await alixGroup.messages() + if (preparedMessageId !== messages[0].id) { + throw new Error(`Message ID should match the prepared message ID`) + } + + return true +}) + +test('can add members to a group', async () => { + // Create three MLS enabled Clients + const [alixClient, boClient, caroClient] = await createClients(3) + + // alix's num groups start at 0 + let alixGroups = await alixClient.conversations.listGroups() + if (alixGroups.length !== 0) { + throw new Error('num groups should be 0') + } + + // bo's num groups start at 0 + let boGroups = await boClient.conversations.listGroups() + if (boGroups.length !== 0) { + throw new Error('num groups should be 0') + } + + // caro's num groups start at 0 + let caroGroups = await caroClient.conversations.listGroups() + if (caroGroups.length !== 0) { + throw new Error('num groups should be 0') + } + + // alix creates a group + const alixGroup = await alixClient.conversations.newGroup([boClient.address]) + + // alix's num groups == 1 + await alixClient.conversations.syncGroups() + alixGroups = await alixClient.conversations.listGroups() + if (alixGroups.length !== 1) { + throw new Error('num groups should be 1') + } + + // alix can confirm memberInboxIds + await alixGroup.sync() + const memberInboxIds = await alixGroup.memberInboxIds() + if (memberInboxIds.length !== 2) { + throw new Error('num group members should be 2') + } + if ( + !( + memberInboxIds.includes(alixClient.inboxId) && + memberInboxIds.includes(boClient.inboxId) + ) + ) { + throw new Error('missing address') + } + + // alix can send messages + await alixGroup.send('hello, world') + await alixGroup.send('gm') + + // bo's num groups == 1 + await boClient.conversations.syncGroups() + boGroups = await boClient.conversations.listGroups() + if (boGroups.length !== 1) { + throw new Error( + 'num groups for bo should be 1, but it is' + boGroups.length + ) + } + + await alixGroup.addMembers([caroClient.address]) + + // caro's num groups == 1 + await caroClient.conversations.syncGroups() + caroGroups = await caroClient.conversations.listGroups() + if (caroGroups.length !== 1) { + throw new Error( + 'num groups for caro should be 1, but it is' + caroGroups.length + ) + } + await caroGroups[0].sync() + const caroMessages = await caroGroups[0].messages() + if (caroMessages.length !== 0) { + throw new Error('num messages for caro should be 0') + } + + await boGroups[0].sync() + const boGroupMembers = await boGroups[0].memberInboxIds() + if (boGroupMembers.length !== 3) { + throw new Error('num group members should be 3') + } + + return true +}) + +test('can remove members from a group', async () => { + // Create three MLS enabled Clients + const [alixClient, boClient, caroClient] = await createClients(3) + + // alix's num groups start at 0 + let alixGroups = await alixClient.conversations.listGroups() + if (alixGroups.length !== 0) { + throw new Error('num groups should be 0') + } + + // bo's num groups start at 0 + let boGroups = await boClient.conversations.listGroups() + assert(boGroups.length === 0, 'num groups should be 0') + + // caro's num groups start at 0 + let caroGroups = await caroClient.conversations.listGroups() + if (caroGroups.length !== 0) { + throw new Error('num groups should be 0') + } + + // alix creates a group + const alixGroup = await alixClient.conversations.newGroup([ + boClient.address, + caroClient.address, + ]) + + // alix's num groups == 1 + await alixClient.conversations.syncGroups() + alixGroups = await alixClient.conversations.listGroups() + if (alixGroups.length !== 1) { + throw new Error('num groups should be 1') + } + + // alix can confirm memberInboxIds + await alixGroup.sync() + const memberInboxIds = await alixGroup.memberInboxIds() + if (memberInboxIds.length !== 3) { + throw new Error('num group members should be 3') + } + if ( + !( + memberInboxIds.includes(alixClient.inboxId) && + memberInboxIds.includes(boClient.inboxId) + ) + ) { + throw new Error('missing address') + } + + // alix can send messages + await alixGroup.send('hello, world') + await alixGroup.send('gm') + + // bo's num groups == 1 + await boClient.conversations.syncGroups() + boGroups = await boClient.conversations.listGroups() + if (boGroups.length !== 1) { + throw new Error( + 'num groups for bo should be 1, but it is' + boGroups.length + ) + } + + // caro's num groups == 1 + await caroClient.conversations.syncGroups() + caroGroups = await caroClient.conversations.listGroups() + if (caroGroups.length !== 1) { + throw new Error( + 'num groups for caro should be 1, but it is' + caroGroups.length + ) + } + + await caroGroups[0].sync() + if (!caroGroups[0].isActive()) { + throw new Error('caros group should be active') + } + + await alixGroup.removeMembers([caroClient.address]) + await alixGroup.sync() + const alixGroupMembers = await alixGroup.memberInboxIds() + if (alixGroupMembers.length !== 2) { + throw new Error( + 'num group members should be 2 but was' + alixGroupMembers.length + ) + } + + await caroGroups[0].sync() + if (await caroGroups[0].isActive()) { + throw new Error('caros group should not be active') + } + + const caroGroupMembers = await caroGroups[0].memberInboxIds() + if (caroGroupMembers.length !== 2) { + throw new Error( + 'num group members should be 2 but was' + caroGroupMembers.length + ) + } -// return true -// }) + return true +}) -// test('can remove and add members from a group by inbox id', async () => { -// // Create three MLS enabled Clients -// const [alixClient, boClient, caroClient] = await createClients(3) - -// // alix creates a group -// const alixGroup = await alixClient.conversations.newGroup([ -// boClient.address, -// caroClient.address, -// ]) - -// // alix can confirm memberInboxIds -// await alixGroup.sync() -// const memberInboxIds = await alixGroup.memberInboxIds() -// if (memberInboxIds.length !== 3) { -// throw new Error('num group members should be 3') -// } +test('can remove and add members from a group by inbox id', async () => { + // Create three MLS enabled Clients + const [alixClient, boClient, caroClient] = await createClients(3) + + // alix creates a group + const alixGroup = await alixClient.conversations.newGroup([ + boClient.address, + caroClient.address, + ]) + + // alix can confirm memberInboxIds + await alixGroup.sync() + const memberInboxIds = await alixGroup.memberInboxIds() + if (memberInboxIds.length !== 3) { + throw new Error('num group members should be 3') + } -// await alixGroup.removeMembersByInboxId([caroClient.inboxId]) -// await alixGroup.sync() -// const alixGroupMembers = await alixGroup.memberInboxIds() -// if (alixGroupMembers.length !== 2) { -// throw new Error('num group members should be 2') -// } + await alixGroup.removeMembersByInboxId([caroClient.inboxId]) + await alixGroup.sync() + const alixGroupMembers = await alixGroup.memberInboxIds() + if (alixGroupMembers.length !== 2) { + throw new Error('num group members should be 2') + } -// await alixGroup.addMembersByInboxId([caroClient.inboxId]) -// await alixGroup.sync() -// const alixGroupMembers2 = await alixGroup.memberInboxIds() -// if (alixGroupMembers2.length !== 3) { -// throw new Error('num group members should be 3') -// } + await alixGroup.addMembersByInboxId([caroClient.inboxId]) + await alixGroup.sync() + const alixGroupMembers2 = await alixGroup.memberInboxIds() + if (alixGroupMembers2.length !== 3) { + throw new Error('num group members should be 3') + } -// return true -// }) + return true +}) test('can cancel streams', async () => { const [alix, bo] = await createClients(2) @@ -988,1277 +988,1277 @@ test('can cancel streams', async () => { 'message stream should still only received 1 message' ) - // await bo.conversations.streamAllMessages(async () => { - // messageCallbacks++ - // }, true) + await bo.conversations.streamAllMessages(async () => { + messageCallbacks++ + }, true) - // await group.send('hello') - // await delayToPropogate() + await group.send('hello') + await delayToPropogate() - // assert( - // messageCallbacks === 2, - // 'message stream should have received 2 message' - // ) + assert( + messageCallbacks === 2, + 'message stream should have received 2 message' + ) return true }) -// test('can stream both groups and messages at same time', async () => { -// const [alix, bo] = await createClients(2) +test('can stream both groups and messages at same time', async () => { + const [alix, bo] = await createClients(2) -// let groupCallbacks = 0 -// let messageCallbacks = 0 -// await bo.conversations.streamGroups(async () => { -// groupCallbacks++ -// }) + let groupCallbacks = 0 + let messageCallbacks = 0 + await bo.conversations.streamGroups(async () => { + groupCallbacks++ + }) -// await bo.conversations.streamAllMessages(async () => { -// messageCallbacks++ -// }, true) + await bo.conversations.streamAllMessages(async () => { + messageCallbacks++ + }, true) -// const group = await alix.conversations.newGroup([bo.address]) -// await group.send('hello') + const group = await alix.conversations.newGroup([bo.address]) + await group.send('hello') -// await delayToPropogate() -// // await new Promise((resolve) => setTimeout(resolve, 10000)) -// assert( -// messageCallbacks === 1, -// 'message stream should have received 1 message' -// ) -// assert(groupCallbacks === 1, 'group stream should have received 1 group') -// return true -// }) + await delayToPropogate() + // await new Promise((resolve) => setTimeout(resolve, 10000)) + assert( + messageCallbacks === 1, + 'message stream should have received 1 message' + ) + assert(groupCallbacks === 1, 'group stream should have received 1 group') + return true +}) -// test('can stream groups', async () => { -// const [alixClient, boClient, caroClient] = await createClients(3) - -// // Start streaming groups -// const groups: Group[] = [] -// const cancelStreamGroups = await alixClient.conversations.streamGroups( -// async (group: Group) => { -// groups.push(group) -// } -// ) - -// // caro creates a group with alix, so stream callback is fired -// // eslint-disable-next-line @typescript-eslint/no-unused-vars -// const caroGroup = await caroClient.conversations.newGroup([ -// alixClient.address, -// ]) -// await delayToPropogate() -// if ((groups.length as number) !== 1) { -// throw Error('Unexpected num groups (should be 1): ' + groups.length) -// } +test('can stream groups', async () => { + const [alixClient, boClient, caroClient] = await createClients(3) -// assert(groups[0].members.length === 2, 'should be 2') + // Start streaming groups + const groups: Group[] = [] + const cancelStreamGroups = await alixClient.conversations.streamGroups( + async (group: Group) => { + groups.push(group) + } + ) -// // bo creates a group with alix so a stream callback is fired -// // eslint-disable-next-line @typescript-eslint/no-unused-vars -// const boGroup = await boClient.conversations.newGroup([alixClient.address]) -// await delayToPropogate() -// if ((groups.length as number) !== 2) { -// throw Error('Unexpected num groups (should be 2): ' + groups.length) -// } + // caro creates a group with alix, so stream callback is fired + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const caroGroup = await caroClient.conversations.newGroup([ + alixClient.address, + ]) + await delayToPropogate() + if ((groups.length as number) !== 1) { + throw Error('Unexpected num groups (should be 1): ' + groups.length) + } -// // * Note alix creating a group does not trigger alix conversations -// // group stream. Workaround is to syncGroups after you create and list manually -// // See https://github.com/xmtp/libxmtp/issues/504 + assert(groups[0].members.length === 2, 'should be 2') -// // alix creates a group -// // eslint-disable-next-line @typescript-eslint/no-unused-vars -// const alixGroup = await alixClient.conversations.newGroup([ -// boClient.address, -// caroClient.address, -// ]) -// await delayToPropogate() -// if (groups.length !== 3) { -// throw Error('Expected group length 3 but it is: ' + groups.length) -// } -// // Sync groups after creation if you created a group -// const listedGroups = await alixClient.conversations.listGroups() -// await delayToPropogate() -// groups.push(listedGroups[listedGroups.length - 1]) -// if ((groups.length as number) !== 4) { -// throw Error('Expected group length 4 but it is: ' + groups.length) -// } + // bo creates a group with alix so a stream callback is fired + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const boGroup = await boClient.conversations.newGroup([alixClient.address]) + await delayToPropogate() + if ((groups.length as number) !== 2) { + throw Error('Unexpected num groups (should be 2): ' + groups.length) + } -// cancelStreamGroups() -// await delayToPropogate() + // * Note alix creating a group does not trigger alix conversations + // group stream. Workaround is to syncGroups after you create and list manually + // See https://github.com/xmtp/libxmtp/issues/504 -// // Creating a group should no longer trigger stream groups -// // eslint-disable-next-line @typescript-eslint/no-unused-vars -// const caroSecond = await caroClient.conversations.newGroup([ -// alixClient.address, -// ]) -// await delayToPropogate() -// if ((groups.length as number) !== 4) { -// throw Error('Unexpected num groups (should be 4): ' + groups.length) -// } + // alix creates a group + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const alixGroup = await alixClient.conversations.newGroup([ + boClient.address, + caroClient.address, + ]) + await delayToPropogate() + if (groups.length !== 3) { + throw Error('Expected group length 3 but it is: ' + groups.length) + } + // Sync groups after creation if you created a group + const listedGroups = await alixClient.conversations.listGroups() + await delayToPropogate() + groups.push(listedGroups[listedGroups.length - 1]) + if ((groups.length as number) !== 4) { + throw Error('Expected group length 4 but it is: ' + groups.length) + } -// return true -// }) + cancelStreamGroups() + await delayToPropogate() -// test('can list groups', async () => { -// const [alixClient, boClient] = await createClients(2) + // Creating a group should no longer trigger stream groups + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const caroSecond = await caroClient.conversations.newGroup([ + alixClient.address, + ]) + await delayToPropogate() + if ((groups.length as number) !== 4) { + throw Error('Unexpected num groups (should be 4): ' + groups.length) + } -// const group1 = await boClient.conversations.newGroup([alixClient.address], { -// name: 'group1 name', -// imageUrlSquare: 'www.group1image.com', -// }) -// const group2 = await boClient.conversations.newGroup([alixClient.address], { -// name: 'group2 name', -// imageUrlSquare: 'www.group2image.com', -// }) + return true +}) -// const boGroups = await boClient.conversations.listGroups() -// await alixClient.conversations.syncGroups() -// const alixGroups = await alixClient.conversations.listGroups() +test('can list groups', async () => { + const [alixClient, boClient] = await createClients(2) -// assert( -// boGroups.length === alixGroups.length, -// `group lengths should be the same but bo was ${boGroups.length} and alix was ${alixGroups.length}` -// ) + const group1 = await boClient.conversations.newGroup([alixClient.address], { + name: 'group1 name', + imageUrlSquare: 'www.group1image.com', + }) + const group2 = await boClient.conversations.newGroup([alixClient.address], { + name: 'group2 name', + imageUrlSquare: 'www.group2image.com', + }) -// const boGroup1 = await boClient.conversations.findGroup(group1.id) -// const boGroup2 = await boClient.conversations.findGroup(group2.id) + const boGroups = await boClient.conversations.listGroups() + await alixClient.conversations.syncGroups() + const alixGroups = await alixClient.conversations.listGroups() -// const alixGroup1 = await alixClient.conversations.findGroup(group1.id) -// const alixGroup2 = await alixClient.conversations.findGroup(group2.id) + assert( + boGroups.length === alixGroups.length, + `group lengths should be the same but bo was ${boGroups.length} and alix was ${alixGroups.length}` + ) -// assert( -// boGroup2?.name === 'group2 name', -// `Group 2 name for bo should be group2 name but was ${boGroup2?.name}` -// ) + const boGroup1 = await boClient.conversations.findGroup(group1.id) + const boGroup2 = await boClient.conversations.findGroup(group2.id) -// assert( -// boGroup1?.imageUrlSquare === 'www.group1image.com', -// `Group 2 url for bo should be www.group1image.com but was ${boGroup1?.imageUrlSquare}` -// ) + const alixGroup1 = await alixClient.conversations.findGroup(group1.id) + const alixGroup2 = await alixClient.conversations.findGroup(group2.id) -// assert( -// alixGroup1?.name === 'group1 name', -// `Group 1 name for alix should be group1 name but was ${alixGroup1?.name}` -// ) + assert( + boGroup2?.name === 'group2 name', + `Group 2 name for bo should be group2 name but was ${boGroup2?.name}` + ) -// assert( -// alixGroup2?.imageUrlSquare === 'www.group2image.com', -// `Group 2 url for alix should be www.group2image.com but was ${alixGroup2?.imageUrlSquare}` -// ) + assert( + boGroup1?.imageUrlSquare === 'www.group1image.com', + `Group 2 url for bo should be www.group1image.com but was ${boGroup1?.imageUrlSquare}` + ) -// assert(boGroup1?.isGroupActive === true, `Group 1 should be active for bo`) + assert( + alixGroup1?.name === 'group1 name', + `Group 1 name for alix should be group1 name but was ${alixGroup1?.name}` + ) -// return true -// }) + assert( + alixGroup2?.imageUrlSquare === 'www.group2image.com', + `Group 2 url for alix should be www.group2image.com but was ${alixGroup2?.imageUrlSquare}` + ) -// test('can list all groups and conversations', async () => { -// const [alixClient, boClient, caroClient] = await createClients(3) - -// // Add one group and one conversation -// const boGroup = await boClient.conversations.newGroup([alixClient.address]) -// const alixConversation = await alixClient.conversations.newConversation( -// caroClient.address -// ) - -// const listedContainers = await alixClient.conversations.listAll() - -// // Verify information in listed containers is correct -// // BUG - List All returns in Chronological order on iOS -// // and reverse Chronological order on Android -// const first = 0 -// const second = 1 -// if ( -// listedContainers[first].topic !== boGroup.topic || -// listedContainers[first].version !== ConversationVersion.GROUP || -// listedContainers[second].version !== ConversationVersion.DIRECT || -// listedContainers[second].createdAt !== alixConversation.createdAt -// ) { -// throw Error('Listed containers should match streamed containers') -// } + assert(boGroup1?.isGroupActive === true, `Group 1 should be active for bo`) -// return true -// }) + return true +}) -// test('can stream all groups and conversations', async () => { -// const [alixClient, boClient, caroClient] = await createClients(3) +test('can list all groups and conversations', async () => { + const [alixClient, boClient, caroClient] = await createClients(3) -// // Start streaming groups and conversations -// const containers: ConversationContainer[] = [] -// const cancelStreamAll = await alixClient.conversations.streamAll( -// async (conversationContainer: ConversationContainer) => { -// containers.push(conversationContainer) -// } -// ) + // Add one group and one conversation + const boGroup = await boClient.conversations.newGroup([alixClient.address]) + const alixConversation = await alixClient.conversations.newConversation( + caroClient.address + ) -// // bo creates a group with alix, so stream callback is fired -// // eslint-disable-next-line @typescript-eslint/no-unused-vars -// const boGroup = await boClient.conversations.newGroup([alixClient.address]) -// await delayToPropogate() -// if ((containers.length as number) !== 1) { -// throw Error('Unexpected num groups (should be 1): ' + containers.length) -// } + const listedContainers = await alixClient.conversations.listAll() + + // Verify information in listed containers is correct + // BUG - List All returns in Chronological order on iOS + // and reverse Chronological order on Android + const first = 0 + const second = 1 + if ( + listedContainers[first].topic !== boGroup.topic || + listedContainers[first].version !== ConversationVersion.GROUP || + listedContainers[second].version !== ConversationVersion.DIRECT || + listedContainers[second].createdAt !== alixConversation.createdAt + ) { + throw Error('Listed containers should match streamed containers') + } -// // bo creates a v2 Conversation with alix so a stream callback is fired -// // eslint-disable-next-line @typescript-eslint/no-unused-vars -// const boConversation = await boClient.conversations.newConversation( -// alixClient.address -// ) -// await delayToPropogate() -// if ((containers.length as number) !== 2) { -// throw Error('Unexpected num groups (should be 2): ' + containers.length) -// } + return true +}) -// if ( -// containers[1].version === ConversationVersion.DIRECT && -// boConversation.conversationID !== -// (containers[1] as Conversation).conversationID -// ) { -// throw Error( -// 'Conversation from streamed all should match conversationID with created conversation' -// ) -// } +test('can stream all groups and conversations', async () => { + const [alixClient, boClient, caroClient] = await createClients(3) -// // * Note alix creating a v2 Conversation does trigger alix conversations -// // stream. + // Start streaming groups and conversations + const containers: ConversationContainer[] = [] + const cancelStreamAll = await alixClient.conversations.streamAll( + async (conversationContainer: ConversationContainer) => { + containers.push(conversationContainer) + } + ) -// // alix creates a V2 Conversationgroup -// // eslint-disable-next-line @typescript-eslint/no-unused-vars -// const alixConversation = await alixClient.conversations.newConversation( -// caroClient.address -// ) -// await delayToPropogate() -// if (containers.length !== 3) { -// throw Error('Expected group length 3 but it is: ' + containers.length) -// } + // bo creates a group with alix, so stream callback is fired + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const boGroup = await boClient.conversations.newGroup([alixClient.address]) + await delayToPropogate() + if ((containers.length as number) !== 1) { + throw Error('Unexpected num groups (should be 1): ' + containers.length) + } -// cancelStreamAll() -// await delayToPropogate() + // bo creates a v2 Conversation with alix so a stream callback is fired + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const boConversation = await boClient.conversations.newConversation( + alixClient.address + ) + await delayToPropogate() + if ((containers.length as number) !== 2) { + throw Error('Unexpected num groups (should be 2): ' + containers.length) + } -// // Creating a group should no longer trigger stream groups -// // eslint-disable-next-line @typescript-eslint/no-unused-vars -// const caroConversation = await caroClient.conversations.newGroup([ -// alixClient.address, -// ]) -// await delayToPropogate() -// if ((containers.length as number) !== 3) { -// throw Error('Unexpected num groups (should be 3): ' + containers.length) -// } + if ( + containers[1].version === ConversationVersion.DIRECT && + boConversation.conversationID !== + (containers[1] as Conversation).conversationID + ) { + throw Error( + 'Conversation from streamed all should match conversationID with created conversation' + ) + } -// return true -// }) + // * Note alix creating a v2 Conversation does trigger alix conversations + // stream. -// test('canMessage', async () => { -// const [bo, alix, caro] = await createClients(3) + // alix creates a V2 Conversationgroup + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const alixConversation = await alixClient.conversations.newConversation( + caroClient.address + ) + await delayToPropogate() + if (containers.length !== 3) { + throw Error('Expected group length 3 but it is: ' + containers.length) + } -// const canMessage = await bo.canMessage(alix.address) -// if (!canMessage) { -// throw new Error('should be able to message v2 client') -// } + cancelStreamAll() + await delayToPropogate() -// const canMessageV3 = await caro.canGroupMessage([ -// caro.address, -// alix.address, -// '0x0000000000000000000000000000000000000000', -// ]) + // Creating a group should no longer trigger stream groups + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const caroConversation = await caroClient.conversations.newGroup([ + alixClient.address, + ]) + await delayToPropogate() + if ((containers.length as number) !== 3) { + throw Error('Unexpected num groups (should be 3): ' + containers.length) + } -// assert( -// canMessageV3['0x0000000000000000000000000000000000000000'] === false, -// `should not be able to message 0x0000000000000000000000000000000000000000` -// ) + return true +}) -// assert( -// canMessageV3[caro.address.toLowerCase()] === true, -// `should be able to message ${caro.address}` -// ) +test('canMessage', async () => { + const [bo, alix, caro] = await createClients(3) -// assert( -// canMessageV3[alix.address.toLowerCase()] === true, -// `should be able to message ${alix.address}` -// ) + const canMessage = await bo.canMessage(alix.address) + if (!canMessage) { + throw new Error('should be able to message v2 client') + } -// return true -// }) + const canMessageV3 = await caro.canGroupMessage([ + caro.address, + alix.address, + '0x0000000000000000000000000000000000000000', + ]) -// test('can stream group messages', async () => { -// // Create three MLS enabled Clients -// const [alixClient, boClient, caroClient] = await createClients(3) - -// // alix creates a group -// const alixGroup = await alixClient.conversations.newGroup([ -// boClient.address, -// caroClient.address, -// ]) - -// // Record message stream for this group -// const groupMessages: DecodedMessage[] = [] -// const cancelGroupMessageStream = await alixGroup.streamGroupMessages( -// async (message) => { -// groupMessages.push(message) -// } -// ) - -// // bo's num groups == 1 -// await boClient.conversations.syncGroups() -// const boGroup = (await boClient.conversations.listGroups())[0] - -// for (let i = 0; i < 5; i++) { -// await boGroup.send({ text: `Message ${i}` }) -// await delayToPropogate() -// } + assert( + canMessageV3['0x0000000000000000000000000000000000000000'] === false, + `should not be able to message 0x0000000000000000000000000000000000000000` + ) -// if (groupMessages.length !== 5) { -// throw Error('Unexpected convo messages count ' + groupMessages.length) -// } -// for (let i = 0; i < 5; i++) { -// if (groupMessages[i].content() !== `Message ${i}`) { -// throw Error( -// 'Unexpected group message content ' + groupMessages[i].content() -// ) -// } -// } + assert( + canMessageV3[caro.address.toLowerCase()] === true, + `should be able to message ${caro.address}` + ) -// cancelGroupMessageStream() -// for (let i = 0; i < 5; i++) { -// await boGroup.send({ text: `Message ${i}` }) -// } + assert( + canMessageV3[alix.address.toLowerCase()] === true, + `should be able to message ${alix.address}` + ) -// if (groupMessages.length !== 5) { -// throw Error('Unexpected convo messages count ' + groupMessages.length) -// } + return true +}) -// return true -// }) +test('can stream group messages', async () => { + // Create three MLS enabled Clients + const [alixClient, boClient, caroClient] = await createClients(3) + + // alix creates a group + const alixGroup = await alixClient.conversations.newGroup([ + boClient.address, + caroClient.address, + ]) + + // Record message stream for this group + const groupMessages: DecodedMessage[] = [] + const cancelGroupMessageStream = await alixGroup.streamGroupMessages( + async (message) => { + groupMessages.push(message) + } + ) -// test('can stream all messages', async () => { -// const [alix, bo, caro] = await createClients(3) + // bo's num groups == 1 + await boClient.conversations.syncGroups() + const boGroup = (await boClient.conversations.listGroups())[0] -// await delayToPropogate() + for (let i = 0; i < 5; i++) { + await boGroup.send({ text: `Message ${i}` }) + await delayToPropogate() + } -// // Record message stream across all conversations -// const allMessages: DecodedMessage[] = [] -// await alix.conversations.streamAllMessages(async (message) => { -// allMessages.push(message) -// }) + if (groupMessages.length !== 5) { + throw Error('Unexpected convo messages count ' + groupMessages.length) + } + for (let i = 0; i < 5; i++) { + if (groupMessages[i].content() !== `Message ${i}`) { + throw Error( + 'Unexpected group message content ' + groupMessages[i].content() + ) + } + } -// // Start bo starts a new conversation. -// const boConvo = await bo.conversations.newConversation(alix.address) -// await delayToPropogate() + cancelGroupMessageStream() + for (let i = 0; i < 5; i++) { + await boGroup.send({ text: `Message ${i}` }) + } -// for (let i = 0; i < 5; i++) { -// await boConvo.send({ text: `Message ${i}` }) -// await delayToPropogate() -// } + if (groupMessages.length !== 5) { + throw Error('Unexpected convo messages count ' + groupMessages.length) + } -// const count = allMessages.length -// if (count !== 5) { -// throw Error('Unexpected all messages count ' + allMessages.length) -// } + return true +}) -// const caroConvo = await caro.conversations.newConversation(alix.address) -// const caroGroup = await caro.conversations.newGroup([alix.address]) -// await delayToPropogate() -// for (let i = 0; i < 5; i++) { -// await caroConvo.send({ text: `Message ${i}` }) -// await caroGroup.send({ text: `Message ${i}` }) -// await delayToPropogate() -// } +test('can stream all messages', async () => { + const [alix, bo, caro] = await createClients(3) -// if (allMessages.length !== 10) { -// throw Error('Unexpected all messages count ' + allMessages.length) -// } + await delayToPropogate() -// alix.conversations.cancelStreamAllMessages() + // Record message stream across all conversations + const allMessages: DecodedMessage[] = [] + await alix.conversations.streamAllMessages(async (message) => { + allMessages.push(message) + }) -// await alix.conversations.streamAllMessages(async (message) => { -// allMessages.push(message) -// }, true) + // Start bo 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 caroGroup.send({ text: `Message ${i}` }) -// await delayToPropogate() -// } -// if (allMessages.length <= 15) { -// throw Error('Unexpected all messages count ' + allMessages.length) -// } + for (let i = 0; i < 5; i++) { + await boConvo.send({ text: `Message ${i}` }) + await delayToPropogate() + } -// return true -// }) + const count = allMessages.length + if (count !== 5) { + throw Error('Unexpected all messages count ' + allMessages.length) + } -// test('can make a group with metadata', async () => { -// const [alix, bo] = await createClients(2) -// bo.register(new GroupUpdatedCodec()) - -// const alixGroup = await alix.conversations.newGroup([bo.address], { -// name: 'Start Name', -// imageUrlSquare: 'starturl.com', -// description: 'a fun description', -// }) - -// const groupName1 = await alixGroup.groupName() -// const groupImageUrl1 = await alixGroup.groupImageUrlSquare() -// const groupDescription1 = await alixGroup.groupDescription() -// assert( -// groupName1 === 'Start Name', -// `the group should start with a name of Start Name not ${groupName1}` -// ) - -// assert( -// groupImageUrl1 === 'starturl.com', -// `the group should start with a name of starturl.com not ${groupImageUrl1}` -// ) - -// assert( -// groupDescription1 === 'a fun description', -// `the group should start with a name of a fun description not ${groupDescription1}` -// ) - -// await alixGroup.updateGroupName('New Name') -// await alixGroup.updateGroupImageUrlSquare('newurl.com') -// await alixGroup.updateGroupDescription('a new group description') -// await alixGroup.sync() -// await bo.conversations.syncGroups() -// const boGroups = await bo.conversations.listGroups() -// const boGroup = boGroups[0] -// await boGroup.sync() - -// const groupName2 = await alixGroup.groupName() -// const groupImageUrl2 = await alixGroup.groupImageUrlSquare() -// const groupDescription2 = await alixGroup.groupDescription() -// assert( -// groupName2 === 'New Name', -// `the group should start with a name of New Name not ${groupName2}` -// ) - -// assert( -// groupImageUrl2 === 'newurl.com', -// `the group should start with a name of newurl.com not ${groupImageUrl2}` -// ) - -// assert( -// groupDescription2 === 'a new group description', -// `the group should start with a name of a new group description not ${groupDescription2}` -// ) - -// const groupName3 = await boGroup.groupName() -// const groupImageUrl3 = await boGroup.groupImageUrlSquare() -// assert( -// groupName3 === 'New Name', -// `the group should start with a name of New Name not ${groupName3}` -// ) - -// assert( -// groupImageUrl3 === 'newurl.com', -// `the group should start with a name of newurl.com not ${groupImageUrl3}` -// ) - -// const boMessages = await boGroup.messages() -// assert( -// boMessages[0].contentTypeId === 'xmtp.org/group_updated:1.0', -// 'Unexpected message content ' + JSON.stringify(boMessages[0].contentTypeId) -// ) - -// const message = boMessages[1].content() as GroupUpdatedContent -// assert( -// message.metadataFieldsChanged[0].fieldName === 'group_image_url_square', -// `the metadata field changed should be group_image_url_square but was ${message.metadataFieldsChanged[0].fieldName}` -// ) -// const message2 = boMessages[0].content() as GroupUpdatedContent -// assert( -// message2.metadataFieldsChanged[0].fieldName === 'description', -// `the metadata field changed should be description but was ${message2.metadataFieldsChanged[0].fieldName}` -// ) -// return true -// }) + const caroConvo = await caro.conversations.newConversation(alix.address) + const caroGroup = await caro.conversations.newGroup([alix.address]) + await delayToPropogate() + for (let i = 0; i < 5; i++) { + await caroConvo.send({ text: `Message ${i}` }) + await caroGroup.send({ text: `Message ${i}` }) + await delayToPropogate() + } -// test('can make a group with admin permissions', async () => { -// const [adminClient, anotherClient] = await createClients(2) + if (allMessages.length !== 10) { + throw Error('Unexpected all messages count ' + allMessages.length) + } -// const group = await adminClient.conversations.newGroup( -// [anotherClient.address], -// { permissionLevel: 'admin_only' } -// ) + alix.conversations.cancelStreamAllMessages() -// if ((await group.permissionPolicySet()).addMemberPolicy !== 'admin') { -// throw Error( -// `Group permission level should be admin but was ${ -// (await group.permissionPolicySet()).addMemberPolicy -// }` -// ) -// } + await alix.conversations.streamAllMessages(async (message) => { + allMessages.push(message) + }, true) -// const isSuperAdmin = await group.isSuperAdmin(adminClient.inboxId) -// if (!isSuperAdmin) { -// throw Error(`adminClient should be the super admin`) -// } + for (let i = 0; i < 5; i++) { + await boConvo.send({ text: `Message ${i}` }) + await caroGroup.send({ text: `Message ${i}` }) + await delayToPropogate() + } + if (allMessages.length <= 15) { + throw Error('Unexpected all messages count ' + allMessages.length) + } -// // Creator id not working, see https://github.com/xmtp/libxmtp/issues/788 -// // if (group.creatorInboxId !== adminClient.inboxId) { -// // throw Error( -// // `adminClient should be the creator but was ${group.creatorInboxId}` -// // ) -// // } + return true +}) -// return true -// }) +test('can make a group with metadata', async () => { + const [alix, bo] = await createClients(2) + bo.register(new GroupUpdatedCodec()) -// test('can paginate group messages', async () => { -// // Create three MLS enabled Clients -// const [alixClient, boClient] = await createClients(2) + const alixGroup = await alix.conversations.newGroup([bo.address], { + name: 'Start Name', + imageUrlSquare: 'starturl.com', + description: 'a fun description', + }) -// // alix creates a group -// const alixGroup = await alixClient.conversations.newGroup([boClient.address]) + const groupName1 = await alixGroup.groupName() + const groupImageUrl1 = await alixGroup.groupImageUrlSquare() + const groupDescription1 = await alixGroup.groupDescription() + assert( + groupName1 === 'Start Name', + `the group should start with a name of Start Name not ${groupName1}` + ) -// // alix can send messages -// await alixGroup.send('hello, world') -// await alixGroup.send('gm') + assert( + groupImageUrl1 === 'starturl.com', + `the group should start with a name of starturl.com not ${groupImageUrl1}` + ) -// await boClient.conversations.syncGroups() -// const boGroups = await boClient.conversations.listGroups() -// if (boGroups.length !== 1) { -// throw new Error( -// 'num groups for bo should be 1, but it is' + boGroups.length -// ) -// } -// await delayToPropogate() -// // bo can read messages from alix -// await boGroups[0].sync() -// const boMessages: DecodedMessage[] = await boGroups[0].messages({ -// limit: 1, -// }) - -// if (boMessages.length !== 1) { -// throw Error(`Should limit just 1 message but was ${boMessages.length}`) -// } + assert( + groupDescription1 === 'a fun description', + `the group should start with a name of a fun description not ${groupDescription1}` + ) -// return true -// }) + await alixGroup.updateGroupName('New Name') + await alixGroup.updateGroupImageUrlSquare('newurl.com') + await alixGroup.updateGroupDescription('a new group description') + await alixGroup.sync() + await bo.conversations.syncGroups() + const boGroups = await bo.conversations.listGroups() + const boGroup = boGroups[0] + await boGroup.sync() + + const groupName2 = await alixGroup.groupName() + const groupImageUrl2 = await alixGroup.groupImageUrlSquare() + const groupDescription2 = await alixGroup.groupDescription() + assert( + groupName2 === 'New Name', + `the group should start with a name of New Name not ${groupName2}` + ) + + assert( + groupImageUrl2 === 'newurl.com', + `the group should start with a name of newurl.com not ${groupImageUrl2}` + ) + + assert( + groupDescription2 === 'a new group description', + `the group should start with a name of a new group description not ${groupDescription2}` + ) + + const groupName3 = await boGroup.groupName() + const groupImageUrl3 = await boGroup.groupImageUrlSquare() + assert( + groupName3 === 'New Name', + `the group should start with a name of New Name not ${groupName3}` + ) + + assert( + groupImageUrl3 === 'newurl.com', + `the group should start with a name of newurl.com not ${groupImageUrl3}` + ) + + const boMessages = await boGroup.messages() + assert( + boMessages[0].contentTypeId === 'xmtp.org/group_updated:1.0', + 'Unexpected message content ' + JSON.stringify(boMessages[0].contentTypeId) + ) + + const message = boMessages[1].content() as GroupUpdatedContent + assert( + message.metadataFieldsChanged[0].fieldName === 'group_image_url_square', + `the metadata field changed should be group_image_url_square but was ${message.metadataFieldsChanged[0].fieldName}` + ) + const message2 = boMessages[0].content() as GroupUpdatedContent + assert( + message2.metadataFieldsChanged[0].fieldName === 'description', + `the metadata field changed should be description but was ${message2.metadataFieldsChanged[0].fieldName}` + ) + return true +}) + +test('can make a group with admin permissions', async () => { + const [adminClient, anotherClient] = await createClients(2) + + const group = await adminClient.conversations.newGroup( + [anotherClient.address], + { permissionLevel: 'admin_only' } + ) + + if ((await group.permissionPolicySet()).addMemberPolicy !== 'admin') { + throw Error( + `Group permission level should be admin but was ${ + (await group.permissionPolicySet()).addMemberPolicy + }` + ) + } + + const isSuperAdmin = await group.isSuperAdmin(adminClient.inboxId) + if (!isSuperAdmin) { + throw Error(`adminClient should be the super admin`) + } + + // Creator id not working, see https://github.com/xmtp/libxmtp/issues/788 + // if (group.creatorInboxId !== adminClient.inboxId) { + // throw Error( + // `adminClient should be the creator but was ${group.creatorInboxId}` + // ) + // } + + return true +}) + +test('can paginate group messages', async () => { + // Create three MLS enabled Clients + const [alixClient, boClient] = await createClients(2) + + // alix creates a group + const alixGroup = await alixClient.conversations.newGroup([boClient.address]) + + // alix can send messages + await alixGroup.send('hello, world') + await alixGroup.send('gm') + + await boClient.conversations.syncGroups() + const boGroups = await boClient.conversations.listGroups() + if (boGroups.length !== 1) { + throw new Error( + 'num groups for bo should be 1, but it is' + boGroups.length + ) + } + await delayToPropogate() + // bo can read messages from alix + await boGroups[0].sync() + const boMessages: DecodedMessage[] = await boGroups[0].messages({ + limit: 1, + }) + + if (boMessages.length !== 1) { + throw Error(`Should limit just 1 message but was ${boMessages.length}`) + } + + return true +}) + +test('can stream all group messages', async () => { + const [alix, bo, caro] = await createClients(3) + + await delayToPropogate() + + // Start bo starts a new group. + const boGroup = await bo.conversations.newGroup([alix.address]) + await delayToPropogate() + + // Starts a new conversation. + const caroGroup = await caro.conversations.newGroup([alix.address]) + + // Record message stream across all conversations + const allMessages: DecodedMessage[] = [] + // If we don't call syncGroups here, the streamAllGroupMessages will not + // stream the first message. Feels like a bug. + await alix.conversations.syncGroups() + await alix.conversations.streamAllGroupMessages(async (message) => { + allMessages.push(message) + }) + + for (let i = 0; i < 5; i++) { + await boGroup.send({ text: `Message ${i}` }) + await delayToPropogate() + } + + const count = allMessages.length + if (count !== 5) { + throw Error('Unexpected all messages count first' + allMessages.length) + } + + await delayToPropogate() + for (let i = 0; i < 5; i++) { + await caroGroup.send({ text: `Message ${i}` }) + await delayToPropogate() + } + + if (allMessages.length !== 10) { + throw Error('Unexpected all messages count second' + allMessages.length) + } + + alix.conversations.cancelStreamAllGroupMessages() + await delayToPropogate() + await alix.conversations.streamAllGroupMessages(async (message) => { + allMessages.push(message) + }) + + for (let i = 0; i < 5; i++) { + await boGroup.send({ text: `Message ${i}` }) + await delayToPropogate() + } + if (allMessages.length <= 10) { + throw Error('Unexpected all messages count ' + allMessages.length) + } + + return true +}) + +test('can streamAll from multiple clients', async () => { + const [alix, bo, caro] = await createClients(3) + + // Setup stream alls + const allBoConversations: any[] = [] + const allAliConversations: any[] = [] -// test('can stream all group messages', async () => { -// const [alix, bo, caro] = await createClients(3) + await bo.conversations.streamAll(async (conversation) => { + allBoConversations.push(conversation) + }) + await alix.conversations.streamAll(async (conversation) => { + allAliConversations.push(conversation) + }) -// await delayToPropogate() + // Start Caro starts a new conversation. + await caro.conversations.newConversation(alix.address) + await delayToPropogate() + if (allBoConversations.length !== 0) { + throw Error( + 'Unexpected all conversations count for Bo ' + + allBoConversations.length + + ' and Alix had ' + + allAliConversations.length + ) + } + if (allAliConversations.length !== 1) { + throw Error( + 'Unexpected all conversations count ' + allAliConversations.length + ) + } + return true +}) -// // Start bo starts a new group. -// const boGroup = await bo.conversations.newGroup([alix.address]) -// await delayToPropogate() +test('can streamAll from multiple clients - swapped orderring', async () => { + const [alix, bo, caro] = await createClients(3) -// // Starts a new conversation. -// const caroGroup = await caro.conversations.newGroup([alix.address]) - -// // Record message stream across all conversations -// const allMessages: DecodedMessage[] = [] -// // If we don't call syncGroups here, the streamAllGroupMessages will not -// // stream the first message. Feels like a bug. -// await alix.conversations.syncGroups() -// await alix.conversations.streamAllGroupMessages(async (message) => { -// allMessages.push(message) -// }) - -// for (let i = 0; i < 5; i++) { -// await boGroup.send({ text: `Message ${i}` }) -// await delayToPropogate() -// } + // Setup stream alls + const allBoConversations: any[] = [] + const allAliConversations: any[] = [] -// const count = allMessages.length -// if (count !== 5) { -// throw Error('Unexpected all messages count first' + allMessages.length) -// } + await alix.conversations.streamAll(async (conversation) => { + allAliConversations.push(conversation) + }) -// await delayToPropogate() -// for (let i = 0; i < 5; i++) { -// await caroGroup.send({ text: `Message ${i}` }) -// await delayToPropogate() -// } + await bo.conversations.streamAll(async (conversation) => { + allBoConversations.push(conversation) + }) -// if (allMessages.length !== 10) { -// throw Error('Unexpected all messages count second' + allMessages.length) -// } + // Start Caro starts a new conversation. + await caro.conversations.newConversation(alix.address) + await delayToPropogate() + if (allBoConversations.length !== 0) { + throw Error( + 'Unexpected all conversations count for Bo ' + + allBoConversations.length + + ' and Alix had ' + + allAliConversations.length + ) + } + if (allAliConversations.length !== 1) { + throw Error( + 'Unexpected all conversations count ' + allAliConversations.length + ) + } + return true +}) -// alix.conversations.cancelStreamAllGroupMessages() -// await delayToPropogate() -// await alix.conversations.streamAllGroupMessages(async (message) => { -// allMessages.push(message) -// }) +test('can streamAllMessages from multiple clients', async () => { + const [alix, bo, caro] = await createClients(3) -// for (let i = 0; i < 5; i++) { -// await boGroup.send({ text: `Message ${i}` }) -// await delayToPropogate() -// } -// if (allMessages.length <= 10) { -// throw Error('Unexpected all messages count ' + allMessages.length) -// } + // Setup stream + const allBoMessages: any[] = [] + const allAliMessages: any[] = [] -// return true -// }) + await bo.conversations.streamAllMessages(async (conversation) => { + allBoMessages.push(conversation) + }, true) + await alix.conversations.streamAllMessages(async (conversation) => { + allAliMessages.push(conversation) + }, true) -// test('can streamAll from multiple clients', async () => { -// const [alix, bo, caro] = await createClients(3) + // Start Caro starts a new conversation. + const caroConversation = await caro.conversations.newConversation( + alix.address + ) + await caroConversation.send({ text: `Message` }) + await delayToPropogate() + if (allBoMessages.length !== 0) { + throw Error('Unexpected all messages count for Bo ' + allBoMessages.length) + } -// // Setup stream alls -// const allBoConversations: any[] = [] -// const allAliConversations: any[] = [] + if (allAliMessages.length !== 1) { + throw Error( + 'Unexpected all conversations count for Ali ' + allAliMessages.length + ) + } -// await bo.conversations.streamAll(async (conversation) => { -// allBoConversations.push(conversation) -// }) -// await alix.conversations.streamAll(async (conversation) => { -// allAliConversations.push(conversation) -// }) + return true +}) -// // Start Caro starts a new conversation. -// await caro.conversations.newConversation(alix.address) -// await delayToPropogate() -// if (allBoConversations.length !== 0) { -// throw Error( -// 'Unexpected all conversations count for Bo ' + -// allBoConversations.length + -// ' and Alix had ' + -// allAliConversations.length -// ) -// } -// if (allAliConversations.length !== 1) { -// throw Error( -// 'Unexpected all conversations count ' + allAliConversations.length -// ) -// } -// return true -// }) +test('can streamAllMessages from multiple clients - swapped', async () => { + const [alix, bo, caro] = await createClients(3) -// test('can streamAll from multiple clients - swapped orderring', async () => { -// const [alix, bo, caro] = await createClients(3) + // Setup stream + const allBoMessages: any[] = [] + const allAliMessages: any[] = [] + const caroGroup = await caro.conversations.newGroup([alix.address]) -// // Setup stream alls -// const allBoConversations: any[] = [] -// const allAliConversations: any[] = [] + await alix.conversations.streamAllMessages(async (conversation) => { + allAliMessages.push(conversation) + }, true) + await bo.conversations.streamAllMessages(async (conversation) => { + allBoMessages.push(conversation) + }, true) -// await alix.conversations.streamAll(async (conversation) => { -// allAliConversations.push(conversation) -// }) + // Start Caro starts a new conversation. + const caroConvo = await caro.conversations.newConversation(alix.address) + await delayToPropogate() + await caroConvo.send({ text: `Message` }) + await caroGroup.send({ text: `Message` }) + await delayToPropogate() + if (allBoMessages.length !== 0) { + throw Error( + 'Unexpected all conversations count for Bo ' + allBoMessages.length + ) + } -// await bo.conversations.streamAll(async (conversation) => { -// allBoConversations.push(conversation) -// }) + if (allAliMessages.length !== 2) { + throw Error( + 'Unexpected all conversations count for Ali ' + allAliMessages.length + ) + } -// // Start Caro starts a new conversation. -// await caro.conversations.newConversation(alix.address) -// await delayToPropogate() -// if (allBoConversations.length !== 0) { -// throw Error( -// 'Unexpected all conversations count for Bo ' + -// allBoConversations.length + -// ' and Alix had ' + -// allAliConversations.length -// ) -// } -// if (allAliConversations.length !== 1) { -// throw Error( -// 'Unexpected all conversations count ' + allAliConversations.length -// ) -// } -// return true -// }) + return true +}) -// test('can streamAllMessages from multiple clients', async () => { -// const [alix, bo, caro] = await createClients(3) +test('can stream all group Messages from multiple clients', async () => { + const [alix, bo, caro] = await createClients(3) -// // Setup stream -// const allBoMessages: any[] = [] -// const allAliMessages: any[] = [] + // Setup stream + const allAlixMessages: DecodedMessage[] = [] + const allBoMessages: DecodedMessage[] = [] + const alixGroup = await caro.conversations.newGroup([alix.address]) + const boGroup = await caro.conversations.newGroup([bo.address]) -// await bo.conversations.streamAllMessages(async (conversation) => { -// allBoMessages.push(conversation) -// }, true) -// await alix.conversations.streamAllMessages(async (conversation) => { -// allAliMessages.push(conversation) -// }, true) + await alixGroup.streamGroupMessages(async (message) => { + allAlixMessages.push(message) + }) + await boGroup.streamGroupMessages(async (message) => { + allBoMessages.push(message) + }) -// // Start Caro starts a new conversation. -// const caroConversation = await caro.conversations.newConversation( -// alix.address -// ) -// await caroConversation.send({ text: `Message` }) -// await delayToPropogate() -// if (allBoMessages.length !== 0) { -// throw Error('Unexpected all messages count for Bo ' + allBoMessages.length) -// } + // Start Caro starts a new conversation. + await delayToPropogate() + await alixGroup.send({ text: `Message` }) + await delayToPropogate() + if (allBoMessages.length !== 0) { + throw Error('Unexpected all messages count for Bo ' + allBoMessages.length) + } -// if (allAliMessages.length !== 1) { -// throw Error( -// 'Unexpected all conversations count for Ali ' + allAliMessages.length -// ) -// } + if (allAlixMessages.length !== 1) { + throw Error( + 'Unexpected all messages count for Ali ' + allAlixMessages.length + ) + } -// return true -// }) + await alix.conversations.syncGroups() + const alixConv = (await alix.conversations.listGroups())[0] + await alixConv.send({ text: `Message` }) + await delayToPropogate() + if (allBoMessages.length !== 0) { + throw Error('Unexpected all messages count for Bo ' + allBoMessages.length) + } + // @ts-ignore-next-line + if (allAlixMessages.length !== 2) { + throw Error( + 'Unexpected all messages count for Ali ' + allAlixMessages.length + ) + } -// test('can streamAllMessages from multiple clients - swapped', async () => { -// const [alix, bo, caro] = await createClients(3) + return true +}) -// // Setup stream -// const allBoMessages: any[] = [] -// const allAliMessages: any[] = [] -// const caroGroup = await caro.conversations.newGroup([alix.address]) +test('can stream all group Messages from multiple clients - swapped', async () => { + const [alix, bo, caro] = await createClients(3) -// await alix.conversations.streamAllMessages(async (conversation) => { -// allAliMessages.push(conversation) -// }, true) -// await bo.conversations.streamAllMessages(async (conversation) => { -// allBoMessages.push(conversation) -// }, true) + // Setup stream + const allAlixMessages: DecodedMessage[] = [] + const allBoMessages: DecodedMessage[] = [] + const alixGroup = await caro.conversations.newGroup([alix.address]) + const boGroup = await caro.conversations.newGroup([bo.address]) -// // Start Caro starts a new conversation. -// const caroConvo = await caro.conversations.newConversation(alix.address) -// await delayToPropogate() -// await caroConvo.send({ text: `Message` }) -// await caroGroup.send({ text: `Message` }) -// await delayToPropogate() -// if (allBoMessages.length !== 0) { -// throw Error( -// 'Unexpected all conversations count for Bo ' + allBoMessages.length -// ) -// } + await boGroup.streamGroupMessages(async (message) => { + allBoMessages.push(message) + }) + await alixGroup.streamGroupMessages(async (message) => { + allAlixMessages.push(message) + }) -// if (allAliMessages.length !== 2) { -// throw Error( -// 'Unexpected all conversations count for Ali ' + allAliMessages.length -// ) -// } + // Start Caro starts a new conversation. + await delayToPropogate() + await alixGroup.send({ text: `Message` }) + await delayToPropogate() + if (allBoMessages.length !== 0) { + throw Error('Unexpected all messages count for Bo ' + allBoMessages.length) + } -// return true -// }) + if (allAlixMessages.length !== 1) { + throw Error( + 'Unexpected all messages count for Ali ' + allAlixMessages.length + ) + } -// test('can stream all group Messages from multiple clients', async () => { -// const [alix, bo, caro] = await createClients(3) + await alix.conversations.syncGroups() + const alixConv = (await alix.conversations.listGroups())[0] + await alixConv.send({ text: `Message` }) + await delayToPropogate() + if (allBoMessages.length !== 0) { + throw Error('Unexpected all messages count for Bo ' + allBoMessages.length) + } + // @ts-ignore-next-line + if (allAlixMessages.length !== 2) { + throw Error( + 'Unexpected all messages count for Ali ' + allAlixMessages.length + ) + } -// // Setup stream -// const allAlixMessages: DecodedMessage[] = [] -// const allBoMessages: DecodedMessage[] = [] -// const alixGroup = await caro.conversations.newGroup([alix.address]) -// const boGroup = await caro.conversations.newGroup([bo.address]) + return true +}) -// await alixGroup.streamGroupMessages(async (message) => { -// allAlixMessages.push(message) -// }) -// await boGroup.streamGroupMessages(async (message) => { -// allBoMessages.push(message) -// }) +test('creating a group should allow group', async () => { + const [alix, bo] = await createClients(2) -// // Start Caro starts a new conversation. -// await delayToPropogate() -// await alixGroup.send({ text: `Message` }) -// await delayToPropogate() -// if (allBoMessages.length !== 0) { -// throw Error('Unexpected all messages count for Bo ' + allBoMessages.length) -// } + const group = await alix.conversations.newGroup([bo.address]) + const consent = await alix.contacts.isGroupAllowed(group.id) + const groupConsent = await group.isAllowed() -// if (allAlixMessages.length !== 1) { -// throw Error( -// 'Unexpected all messages count for Ali ' + allAlixMessages.length -// ) -// } + if (!consent || !groupConsent) { + throw Error('Group should be allowed') + } -// await alix.conversations.syncGroups() -// const alixConv = (await alix.conversations.listGroups())[0] -// await alixConv.send({ text: `Message` }) -// await delayToPropogate() -// if (allBoMessages.length !== 0) { -// throw Error('Unexpected all messages count for Bo ' + allBoMessages.length) -// } -// // @ts-ignore-next-line -// if (allAlixMessages.length !== 2) { -// throw Error( -// 'Unexpected all messages count for Ali ' + allAlixMessages.length -// ) -// } + const state = await group.consentState() + assert( + state === 'allowed', + `the message should have a consent state of allowed but was ${state}` + ) -// return true -// }) + const consentList = await alix.contacts.consentList() + assert( + consentList[0].permissionType === 'allowed', + `the message should have a consent state of allowed but was ${consentList[0].permissionType}` + ) + + return true +}) -// test('can stream all group Messages from multiple clients - swapped', async () => { -// const [alix, bo, caro] = await createClients(3) +test('can allow a group', async () => { + const [alix, bo] = await createClients(2) + const alixGroup = await alix.conversations.newGroup([bo.address]) + const startConsent = await bo.contacts.isGroupAllowed(alixGroup.id) + if (startConsent) { + throw Error('Group should not be allowed') + } + await bo.contacts.allowGroups([alixGroup.id]) + const isAllowed = await bo.contacts.isGroupAllowed(alixGroup.id) + if (!isAllowed) { + throw Error('Group should be allowed') + } -// // Setup stream -// const allAlixMessages: DecodedMessage[] = [] -// const allBoMessages: DecodedMessage[] = [] -// const alixGroup = await caro.conversations.newGroup([alix.address]) -// const boGroup = await caro.conversations.newGroup([bo.address]) + return true +}) -// await boGroup.streamGroupMessages(async (message) => { -// allBoMessages.push(message) -// }) -// await alixGroup.streamGroupMessages(async (message) => { -// allAlixMessages.push(message) -// }) +test('can deny a group', async () => { + const [alix, bo] = await createClients(2) + const alixGroup = await alix.conversations.newGroup([bo.address]) + const startConsent = await bo.contacts.isGroupDenied(alixGroup.id) + if (startConsent) { + throw Error('Group should be unknown') + } + await bo.contacts.denyGroups([alixGroup.id]) + await bo.conversations.syncGroups() + const boGroups = await bo.conversations.listGroups() + const isDenied = await bo.contacts.isGroupDenied(alixGroup.id) + const isGroupDenied = await boGroups[0].isDenied() + if (!isDenied || !isGroupDenied) { + throw Error('Group should be denied') + } + await bo.contacts.allowGroups([alixGroup.id]) + const isAllowed = await bo.contacts.isGroupAllowed(alixGroup.id) + if (!isAllowed) { + throw Error('Group should be allowed') + } -// // Start Caro starts a new conversation. -// await delayToPropogate() -// await alixGroup.send({ text: `Message` }) -// await delayToPropogate() -// if (allBoMessages.length !== 0) { -// throw Error('Unexpected all messages count for Bo ' + allBoMessages.length) -// } + return true +}) -// if (allAlixMessages.length !== 1) { -// throw Error( -// 'Unexpected all messages count for Ali ' + allAlixMessages.length -// ) -// } +test('can allow and deny a inbox id', async () => { + const [alix, bo] = await createClients(2) + const startConsent = await bo.contacts.isInboxAllowed(alix.inboxId) + if (startConsent) { + throw Error('inbox id should be unknown') + } + await bo.contacts.denyInboxes([alix.inboxId]) + const isDenied = await bo.contacts.isInboxDenied(alix.inboxId) + if (!isDenied) { + throw Error('inbox id should be denied') + } + await bo.contacts.allowInboxes([alix.inboxId]) + const isAllowed = await bo.contacts.isInboxAllowed(alix.inboxId) + if (!isAllowed) { + throw Error('inbox id should be allowed') + } -// await alix.conversations.syncGroups() -// const alixConv = (await alix.conversations.listGroups())[0] -// await alixConv.send({ text: `Message` }) -// await delayToPropogate() -// if (allBoMessages.length !== 0) { -// throw Error('Unexpected all messages count for Bo ' + allBoMessages.length) -// } -// // @ts-ignore-next-line -// if (allAlixMessages.length !== 2) { -// throw Error( -// 'Unexpected all messages count for Ali ' + allAlixMessages.length -// ) -// } + const consentList = await bo.contacts.consentList() + assert( + consentList[0].entryType === 'inbox_id', + `the message should have a type of inbox_id but was ${consentList[0].entryType}` + ) -// return true -// }) + return true +}) -// test('creating a group should allow group', async () => { -// const [alix, bo] = await createClients(2) +test('can check if group is allowed', async () => { + const [alix, bo] = await createClients(2) + const alixGroup = await alix.conversations.newGroup([bo.address]) + const startConsent = await bo.contacts.isGroupAllowed(alixGroup.id) + if (startConsent) { + throw Error('Group should not be allowed by default') + } + await bo.contacts.allowGroups([alixGroup.id]) + const consent = await bo.contacts.isGroupAllowed(alixGroup.id) + if (!consent) { + throw Error('Group should be allowed') + } -// const group = await alix.conversations.newGroup([bo.address]) -// const consent = await alix.contacts.isGroupAllowed(group.id) -// const groupConsent = await group.isAllowed() + return true +}) -// if (!consent || !groupConsent) { -// throw Error('Group should be allowed') -// } +test('can check if group is denied', async () => { + const [alix, bo] = await createClients(2) + const alixGroup = await alix.conversations.newGroup([bo.address]) + const startConsent = await bo.contacts.isGroupDenied(alixGroup.id) + if (startConsent) { + throw Error('Group should not be denied by default') + } + await bo.contacts.denyGroups([alixGroup.id]) + const consent = await bo.contacts.isGroupDenied(alixGroup.id) + if (!consent) { + throw Error('Group should be denied') + } + return true +}) -// const state = await group.consentState() -// assert( -// state === 'allowed', -// `the message should have a consent state of allowed but was ${state}` -// ) +test('sync function behaves as expected', async () => { + const [alix, bo, caro] = await createClients(3) + const alixGroup = await alix.conversations.newGroup([bo.address]) -// const consentList = await alix.contacts.consentList() -// assert( -// consentList[0].permissionType === 'allowed', -// `the message should have a consent state of allowed but was ${consentList[0].permissionType}` -// ) + await alixGroup.send({ text: 'hello' }) -// return true -// }) + // List groups will return empty until the first sync + let boGroups = await bo.conversations.listGroups() + assert(boGroups.length === 0, 'num groups for bo is 0 until we sync') -// test('can allow a group', async () => { -// const [alix, bo] = await createClients(2) -// const alixGroup = await alix.conversations.newGroup([bo.address]) -// const startConsent = await bo.contacts.isGroupAllowed(alixGroup.id) -// if (startConsent) { -// throw Error('Group should not be allowed') -// } -// await bo.contacts.allowGroups([alixGroup.id]) -// const isAllowed = await bo.contacts.isGroupAllowed(alixGroup.id) -// if (!isAllowed) { -// throw Error('Group should be allowed') -// } + await bo.conversations.syncGroups() -// return true -// }) + boGroups = await bo.conversations.listGroups() + assert(boGroups.length === 1, 'num groups for bo is 1') -// test('can deny a group', async () => { -// const [alix, bo] = await createClients(2) -// const alixGroup = await alix.conversations.newGroup([bo.address]) -// const startConsent = await bo.contacts.isGroupDenied(alixGroup.id) -// if (startConsent) { -// throw Error('Group should be unknown') -// } -// await bo.contacts.denyGroups([alixGroup.id]) -// await bo.conversations.syncGroups() -// const boGroups = await bo.conversations.listGroups() -// const isDenied = await bo.contacts.isGroupDenied(alixGroup.id) -// const isGroupDenied = await boGroups[0].isDenied() -// if (!isDenied || !isGroupDenied) { -// throw Error('Group should be denied') -// } -// await bo.contacts.allowGroups([alixGroup.id]) -// const isAllowed = await bo.contacts.isGroupAllowed(alixGroup.id) -// if (!isAllowed) { -// throw Error('Group should be allowed') -// } + // Num members will include the initial num of members even before sync + let numMembers = (await boGroups[0].memberInboxIds()).length + assert(numMembers === 2, 'num members should be 2') -// return true -// }) + // Num messages for a group will be 0 until we sync the group + let numMessages = (await boGroups[0].messages()).length + assert(numMessages === 0, 'num members should be 1') -// test('can allow and deny a inbox id', async () => { -// const [alix, bo] = await createClients(2) -// const startConsent = await bo.contacts.isInboxAllowed(alix.inboxId) -// if (startConsent) { -// throw Error('inbox id should be unknown') -// } -// await bo.contacts.denyInboxes([alix.inboxId]) -// const isDenied = await bo.contacts.isInboxDenied(alix.inboxId) -// if (!isDenied) { -// throw Error('inbox id should be denied') -// } -// await bo.contacts.allowInboxes([alix.inboxId]) -// const isAllowed = await bo.contacts.isInboxAllowed(alix.inboxId) -// if (!isAllowed) { -// throw Error('inbox id should be allowed') -// } + await bo.conversations.syncGroups() -// const consentList = await bo.contacts.consentList() -// assert( -// consentList[0].entryType === 'inbox_id', -// `the message should have a type of inbox_id but was ${consentList[0].entryType}` -// ) + // Num messages is still 0 because we didnt sync the group itself + numMessages = (await boGroups[0].messages()).length + assert(numMessages === 0, 'num messages should be 0') -// return true -// }) + await boGroups[0].sync() -// test('can check if group is allowed', async () => { -// const [alix, bo] = await createClients(2) -// const alixGroup = await alix.conversations.newGroup([bo.address]) -// const startConsent = await bo.contacts.isGroupAllowed(alixGroup.id) -// if (startConsent) { -// throw Error('Group should not be allowed by default') -// } -// await bo.contacts.allowGroups([alixGroup.id]) -// const consent = await bo.contacts.isGroupAllowed(alixGroup.id) -// if (!consent) { -// throw Error('Group should be allowed') -// } + // after syncing the group we now see the correct number of messages + numMessages = (await boGroups[0].messages()).length + assert(numMessages === 1, 'num members should be 1') -// return true -// }) + await alixGroup.addMembers([caro.address]) -// test('can check if group is denied', async () => { -// const [alix, bo] = await createClients(2) -// const alixGroup = await alix.conversations.newGroup([bo.address]) -// const startConsent = await bo.contacts.isGroupDenied(alixGroup.id) -// if (startConsent) { -// throw Error('Group should not be denied by default') -// } -// await bo.contacts.denyGroups([alixGroup.id]) -// const consent = await bo.contacts.isGroupDenied(alixGroup.id) -// if (!consent) { -// throw Error('Group should be denied') -// } -// return true -// }) + numMembers = (await boGroups[0].memberInboxIds()).length + assert(numMembers === 2, 'num members should be 2') -// test('sync function behaves as expected', async () => { -// const [alix, bo, caro] = await createClients(3) -// const alixGroup = await alix.conversations.newGroup([bo.address]) + await bo.conversations.syncGroups() -// await alixGroup.send({ text: 'hello' }) + // Even though we synced the groups, we need to sync the group itself to see the new member + numMembers = (await boGroups[0].memberInboxIds()).length + assert(numMembers === 2, 'num members should be 2') -// // List groups will return empty until the first sync -// let boGroups = await bo.conversations.listGroups() -// assert(boGroups.length === 0, 'num groups for bo is 0 until we sync') + await boGroups[0].sync() -// await bo.conversations.syncGroups() + numMembers = (await boGroups[0].memberInboxIds()).length + assert(numMembers === 3, 'num members should be 3') -// boGroups = await bo.conversations.listGroups() -// assert(boGroups.length === 1, 'num groups for bo is 1') + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const _alixGroup2 = await alix.conversations.newGroup([ + bo.address, + caro.address, + ]) + await bo.conversations.syncGroups() + boGroups = await bo.conversations.listGroups() + assert(boGroups.length === 2, 'num groups for bo is 2') -// // Num members will include the initial num of members even before sync -// let numMembers = (await boGroups[0].memberInboxIds()).length -// assert(numMembers === 2, 'num members should be 2') + // Even before syncing the group, syncGroups will return the initial number of members + numMembers = (await boGroups[1].memberInboxIds()).length + assert(numMembers === 3, 'num members should be 3') -// // Num messages for a group will be 0 until we sync the group -// let numMessages = (await boGroups[0].messages()).length -// assert(numMessages === 0, 'num members should be 1') + return true +}) -// await bo.conversations.syncGroups() +test('can read and update group name', async () => { + const [alix, bo, caro] = await createClients(3) + const alixGroup = await alix.conversations.newGroup([bo.address]) -// // Num messages is still 0 because we didnt sync the group itself -// numMessages = (await boGroups[0].messages()).length -// assert(numMessages === 0, 'num messages should be 0') + await alixGroup.sync() + let groupName = await alixGroup.groupName() -// await boGroups[0].sync() + assert(groupName === '', 'group name should be empty string') -// // after syncing the group we now see the correct number of messages -// numMessages = (await boGroups[0].messages()).length -// assert(numMessages === 1, 'num members should be 1') + await alixGroup.updateGroupName('Test name update 1') -// await alixGroup.addMembers([caro.address]) + await alixGroup.sync() + groupName = await alixGroup.groupName() -// numMembers = (await boGroups[0].memberInboxIds()).length -// assert(numMembers === 2, 'num members should be 2') + assert( + groupName === 'Test name update 1', + 'group name should be "Test name update 1"' + ) -// await bo.conversations.syncGroups() + await bo.conversations.syncGroups() + const boGroup = (await bo.conversations.listGroups())[0] + groupName = await boGroup.groupName() -// // Even though we synced the groups, we need to sync the group itself to see the new member -// numMembers = (await boGroups[0].memberInboxIds()).length -// assert(numMembers === 2, 'num members should be 2') + assert(groupName === '', 'group name should be empty string') -// await boGroups[0].sync() + await boGroup.sync() -// numMembers = (await boGroups[0].memberInboxIds()).length -// assert(numMembers === 3, 'num members should be 3') + groupName = await boGroup.groupName() -// // eslint-disable-next-line @typescript-eslint/no-unused-vars -// const _alixGroup2 = await alix.conversations.newGroup([ -// bo.address, -// caro.address, -// ]) -// await bo.conversations.syncGroups() -// boGroups = await bo.conversations.listGroups() -// assert(boGroups.length === 2, 'num groups for bo is 2') + assert( + groupName === 'Test name update 1', + 'group name should be "Test name update 1"' + ) -// // Even before syncing the group, syncGroups will return the initial number of members -// numMembers = (await boGroups[1].memberInboxIds()).length -// assert(numMembers === 3, 'num members should be 3') + await alixGroup.addMembers([caro.address]) + await caro.conversations.syncGroups() + const caroGroup = (await caro.conversations.listGroups())[0] -// return true -// }) + await caroGroup.sync() + groupName = await caroGroup.groupName() + assert( + groupName === 'Test name update 1', + 'group name should be "Test name update 1"' + ) + return true +}) -// test('can read and update group name', async () => { -// const [alix, bo, caro] = await createClients(3) -// const alixGroup = await alix.conversations.newGroup([bo.address]) +test('can list groups does not fork', async () => { + const [alix, bo] = await createClients(2) + console.log('created clients') + let groupCallbacks = 0 + //#region Stream groups + await bo.conversations.streamGroups(async () => { + console.log('group received') + groupCallbacks++ + }) + //#region Stream All Messages + await bo.conversations.streamAllMessages(async () => { + console.log('message received') + }, true) + //#endregion + // #region create group + const alixGroup = await alix.conversations.newGroup([bo.address]) + await alixGroup.updateGroupName('hello') + await alixGroup.send('hello1') + console.log('sent group message') + // #endregion + // #region sync groups + await bo.conversations.syncGroups() + // #endregion + const boGroups = await bo.conversations.listGroups() + assert(boGroups.length === 1, 'bo should have 1 group') + const boGroup = boGroups[0] + await boGroup.sync() + + const boMessages1 = await boGroup.messages() + assert( + boMessages1.length === 2, + `should have 2 messages on first load received ${boMessages1.length}` + ) + await boGroup.send('hello2') + await boGroup.send('hello3') + await alixGroup.sync() + const alixMessages = await alixGroup.messages() + for (const message of alixMessages) { + console.log( + 'message', + message.contentTypeId, + message.contentTypeId === 'xmtp.org/text:1.0' + ? message.content() + : 'Group Updated' + ) + } + // alix sees 3 messages + assert( + alixMessages.length === 5, + `should have 5 messages on first load received ${alixMessages.length}` + ) + await alixGroup.send('hello4') + await boGroup.sync() + const boMessages2 = await boGroup.messages() + for (const message of boMessages2) { + console.log( + 'message', + message.contentTypeId, + message.contentTypeId === 'xmtp.org/text:1.0' + ? message.content() + : 'Group Updated' + ) + } + // bo sees 4 messages + assert( + boMessages2.length === 5, + `should have 5 messages on second load received ${boMessages2.length}` + ) -// await alixGroup.sync() -// let groupName = await alixGroup.groupName() + assert(groupCallbacks === 1, 'group stream should have received 1 group') -// assert(groupName === '', 'group name should be empty string') + return true +}) -// await alixGroup.updateGroupName('Test name update 1') +test('can create new installation without breaking group', async () => { + const keyBytes = new Uint8Array([ + 233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64, + 166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, 145, + ]) + const wallet1 = Wallet.createRandom() + const wallet2 = Wallet.createRandom() -// await alixGroup.sync() -// groupName = await alixGroup.groupName() + const client1 = await Client.create(wallet1, { + env: 'local', + appVersion: 'Testing/0.0.0', + enableV3: true, + dbEncryptionKey: keyBytes, + }) + const client2 = await Client.create(wallet2, { + env: 'local', + appVersion: 'Testing/0.0.0', + enableV3: true, + dbEncryptionKey: keyBytes, + }) -// assert( -// groupName === 'Test name update 1', -// 'group name should be "Test name update 1"' -// ) + const group = await client1.conversations.newGroup([wallet2.address]) -// await bo.conversations.syncGroups() -// const boGroup = (await bo.conversations.listGroups())[0] -// groupName = await boGroup.groupName() + await client1.conversations.syncGroups() + await client2.conversations.syncGroups() -// assert(groupName === '', 'group name should be empty string') + const client1Group = await client1.conversations.findGroup(group.id) + const client2Group = await client2.conversations.findGroup(group.id) -// await boGroup.sync() + await client1Group?.sync() + await client2Group?.sync() -// groupName = await boGroup.groupName() + assert(client1Group?.members?.length === 2, `client 1 should see 2 members`) -// assert( -// groupName === 'Test name update 1', -// 'group name should be "Test name update 1"' -// ) + assert( + (await client2Group?.membersList())?.length === 2, + `client 2 should see 2 members` + ) -// await alixGroup.addMembers([caro.address]) -// await caro.conversations.syncGroups() -// const caroGroup = (await caro.conversations.listGroups())[0] + await client2.deleteLocalDatabase() -// await caroGroup.sync() -// groupName = await caroGroup.groupName() -// assert( -// groupName === 'Test name update 1', -// 'group name should be "Test name update 1"' -// ) -// return true -// }) + // Recreating a client with wallet 2 (new installation!) + await Client.create(wallet2, { + env: 'local', + appVersion: 'Testing/0.0.0', + enableV3: true, + dbEncryptionKey: keyBytes, + }) -// test('can list groups does not fork', async () => { -// const [alix, bo] = await createClients(2) -// console.log('created clients') -// let groupCallbacks = 0 -// //#region Stream groups -// await bo.conversations.streamGroups(async () => { -// console.log('group received') -// groupCallbacks++ -// }) -// //#region Stream All Messages -// await bo.conversations.streamAllMessages(async () => { -// console.log('message received') -// }, true) -// //#endregion -// // #region create group -// const alixGroup = await alix.conversations.newGroup([bo.address]) -// await alixGroup.updateGroupName('hello') -// await alixGroup.send('hello1') -// console.log('sent group message') -// // #endregion -// // #region sync groups -// await bo.conversations.syncGroups() -// // #endregion -// const boGroups = await bo.conversations.listGroups() -// assert(boGroups.length === 1, 'bo should have 1 group') -// const boGroup = boGroups[0] -// await boGroup.sync() - -// const boMessages1 = await boGroup.messages() -// assert( -// boMessages1.length === 2, -// `should have 2 messages on first load received ${boMessages1.length}` -// ) -// await boGroup.send('hello2') -// await boGroup.send('hello3') -// await alixGroup.sync() -// const alixMessages = await alixGroup.messages() -// for (const message of alixMessages) { -// console.log( -// 'message', -// message.contentTypeId, -// message.contentTypeId === 'xmtp.org/text:1.0' -// ? message.content() -// : 'Group Updated' -// ) -// } -// // alix sees 3 messages -// assert( -// alixMessages.length === 5, -// `should have 5 messages on first load received ${alixMessages.length}` -// ) -// await alixGroup.send('hello4') -// await boGroup.sync() -// const boMessages2 = await boGroup.messages() -// for (const message of boMessages2) { -// console.log( -// 'message', -// message.contentTypeId, -// message.contentTypeId === 'xmtp.org/text:1.0' -// ? message.content() -// : 'Group Updated' -// ) -// } -// // bo sees 4 messages -// assert( -// boMessages2.length === 5, -// `should have 5 messages on second load received ${boMessages2.length}` -// ) + await client1Group?.send('This message will break the group') + assert( + client1Group?.members?.length === 2, + `client 1 should still see the 2 members` + ) -// assert(groupCallbacks === 1, 'group stream should have received 1 group') + return true +}) -// return true -// }) +test('can list many groups members in parallel', async () => { + const [alix, bo] = await createClients(2) + const groups: Group[] = await createGroups(alix, [bo], 20, 0) -// test('can create new installation without breaking group', async () => { -// const keyBytes = new Uint8Array([ -// 233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64, -// 166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, 145, -// ]) -// const wallet1 = Wallet.createRandom() -// const wallet2 = Wallet.createRandom() - -// const client1 = await Client.create(wallet1, { -// env: 'local', -// appVersion: 'Testing/0.0.0', -// enableV3: true, -// dbEncryptionKey: keyBytes, -// }) -// const client2 = await Client.create(wallet2, { -// env: 'local', -// appVersion: 'Testing/0.0.0', -// enableV3: true, -// dbEncryptionKey: keyBytes, -// }) - -// const group = await client1.conversations.newGroup([wallet2.address]) - -// await client1.conversations.syncGroups() -// await client2.conversations.syncGroups() - -// const client1Group = await client1.conversations.findGroup(group.id) -// const client2Group = await client2.conversations.findGroup(group.id) - -// await client1Group?.sync() -// await client2Group?.sync() - -// assert(client1Group?.members?.length === 2, `client 1 should see 2 members`) - -// assert( -// (await client2Group?.membersList())?.length === 2, -// `client 2 should see 2 members` -// ) - -// await client2.deleteLocalDatabase() - -// // Recreating a client with wallet 2 (new installation!) -// await Client.create(wallet2, { -// env: 'local', -// appVersion: 'Testing/0.0.0', -// enableV3: true, -// dbEncryptionKey: keyBytes, -// }) - -// await client1Group?.send('This message will break the group') -// assert( -// client1Group?.members?.length === 2, -// `client 1 should still see the 2 members` -// ) + try { + await Promise.all(groups.slice(0, 10).map((g) => g.membersList())) + } catch (e) { + throw new Error(`Failed listing 10 groups members with ${e}`) + } -// return true -// }) + try { + await Promise.all(groups.slice(0, 20).map((g) => g.membersList())) + } catch (e) { + throw new Error(`Failed listing 20 groups members with ${e}`) + } -// test('can list many groups members in parallel', async () => { -// const [alix, bo] = await createClients(2) -// const groups: Group[] = await createGroups(alix, [bo], 20, 0) + return true +}) -// try { -// await Promise.all(groups.slice(0, 10).map((g) => g.membersList())) -// } catch (e) { -// throw new Error(`Failed listing 10 groups members with ${e}`) -// } +test('can sync all groups', async () => { + const [alix, bo] = await createClients(2) + const groups: Group[] = await createGroups(alix, [bo], 50, 0) -// try { -// await Promise.all(groups.slice(0, 20).map((g) => g.membersList())) -// } catch (e) { -// throw new Error(`Failed listing 20 groups members with ${e}`) -// } + const alixGroup = groups[0] + await bo.conversations.syncGroups() + const boGroup = await bo.conversations.findGroup(alixGroup.id) + await alixGroup.send('hi') + assert( + (await boGroup?.messages())?.length === 0, + `messages should be empty before sync but was ${boGroup?.messages?.length}` + ) -// return true -// }) + const numGroupsSynced = await bo.conversations.syncAllGroups() + assert( + (await boGroup?.messages())?.length === 1, + `messages should be 4 after sync but was ${boGroup?.messages?.length}` + ) + assert( + numGroupsSynced === 50, + `should have synced 50 groups but synced ${numGroupsSynced}` + ) -// test('can sync all groups', async () => { -// const [alix, bo] = await createClients(2) -// const groups: Group[] = await createGroups(alix, [bo], 50, 0) - -// const alixGroup = groups[0] -// await bo.conversations.syncGroups() -// const boGroup = await bo.conversations.findGroup(alixGroup.id) -// await alixGroup.send('hi') -// assert( -// (await boGroup?.messages())?.length === 0, -// `messages should be empty before sync but was ${boGroup?.messages?.length}` -// ) - -// const numGroupsSynced = await bo.conversations.syncAllGroups() -// assert( -// (await boGroup?.messages())?.length === 1, -// `messages should be 4 after sync but was ${boGroup?.messages?.length}` -// ) -// assert( -// numGroupsSynced === 50, -// `should have synced 50 groups but synced ${numGroupsSynced}` -// ) - -// for (const group of groups) { -// await group.removeMembers([bo.address]) -// } + for (const group of groups) { + await group.removeMembers([bo.address]) + } -// // First syncAllGroups after removal will still sync each group to set group inactive -// // For some reason on Android (RN only), first syncAllGroups already returns 0 -// const numGroupsSynced2 = await bo.conversations.syncAllGroups() -// if (Platform.OS === 'ios') { -// assert( -// numGroupsSynced2 === 50, -// `should have synced 50 groups but synced ${numGroupsSynced2}` -// ) -// } else { -// assert( -// numGroupsSynced2 === 0, -// `should have synced 0 groups but synced ${numGroupsSynced2}` -// ) -// } + // First syncAllGroups after removal will still sync each group to set group inactive + // For some reason on Android (RN only), first syncAllGroups already returns 0 + const numGroupsSynced2 = await bo.conversations.syncAllGroups() + if (Platform.OS === 'ios') { + assert( + numGroupsSynced2 === 50, + `should have synced 50 groups but synced ${numGroupsSynced2}` + ) + } else { + assert( + numGroupsSynced2 === 0, + `should have synced 0 groups but synced ${numGroupsSynced2}` + ) + } -// // Next syncAllGroups will not sync inactive groups -// const numGroupsSynced3 = await bo.conversations.syncAllGroups() -// assert( -// numGroupsSynced3 === 0, -// `should have synced 0 groups but synced ${numGroupsSynced3}` -// ) -// return true -// }) + // Next syncAllGroups will not sync inactive groups + const numGroupsSynced3 = await bo.conversations.syncAllGroups() + assert( + numGroupsSynced3 === 0, + `should have synced 0 groups but synced ${numGroupsSynced3}` + ) + return true +}) // Commenting this out so it doesn't block people, but nice to have? // test('can stream messages for a long time', async () => { diff --git a/ios/XMTPModule.swift b/ios/XMTPModule.swift index 571875692..b655a0c95 100644 --- a/ios/XMTPModule.swift +++ b/ios/XMTPModule.swift @@ -1298,7 +1298,6 @@ public class XMTPModule: Module { } AsyncFunction("unsubscribeFromAllMessages") { (inboxId: String) in - print("unsubscribeFromAllMessages") await subscriptionsManager.get(getMessagesKey(inboxId: inboxId))?.cancel() } From 72c82840d4d901bf6abdccd903ee43d253bddabe Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Mon, 2 Sep 2024 21:49:08 -0600 Subject: [PATCH 4/4] get all the tests passing --- example/src/tests/groupTests.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/example/src/tests/groupTests.ts b/example/src/tests/groupTests.ts index 76687ea69..2689e70d3 100644 --- a/example/src/tests/groupTests.ts +++ b/example/src/tests/groupTests.ts @@ -1,5 +1,6 @@ import { Wallet } from 'ethers' import { Platform } from 'expo-modules-core' +import RNFS from 'react-native-fs' import { DecodedMessage } from 'xmtp-react-native-sdk/lib/DecodedMessage' import { Test, assert, createClients, delayToPropogate } from './test-utils'