diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 0f23166df..a2f8a1719 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.11.5): + - XMTP (0.11.6): - Connect-Swift (= 0.12.0) - GzipSwift - LibXMTP (= 0.5.1-beta1) @@ -458,7 +458,7 @@ PODS: - ExpoModulesCore - MessagePacker - secp256k1.swift - - XMTP (= 0.11.5) + - XMTP (= 0.11.6) - Yoga (1.14.0) DEPENDENCIES: @@ -763,8 +763,8 @@ SPEC CHECKSUMS: secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634 SwiftProtobuf: 407a385e97fd206c4fbe880cc84123989167e0d1 web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959 - XMTP: 3947ed08f7b1c50878b145e4990e604abf741ba9 - XMTPReactNative: 08e92e5c83de18c18af7e9251f348495a3f41e15 + XMTP: 5986c7bc1400b8b054569d4c7c6d2f673d992be1 + XMTPReactNative: ed4824399c26767008b8266992085461f0cece98 Yoga: e71803b4c1fff832ccf9b92541e00f9b873119b9 PODFILE CHECKSUM: 95d6ace79946933ecf80684613842ee553dd76a2 diff --git a/example/src/tests/groupTests.ts b/example/src/tests/groupTests.ts index 620f19c66..b351309bb 100644 --- a/example/src/tests/groupTests.ts +++ b/example/src/tests/groupTests.ts @@ -23,1611 +23,1608 @@ function test(name: string, perform: () => Promise) { groupTests.push({ name: String(counter++) + '. ' + name, run: perform }) } -test('reproduce streaming error', async () => { - const [alix, bo] = await createClients(2) - console.log('created clients') - - let groupCallbacks = 0 - let messageCallbacks = 0 - await bo.conversations.streamGroups(async () => { - console.log('message received') - groupCallbacks++ +test('can make a MLS V3 client', async () => { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const client = await Client.createRandom({ + env: 'local', + appVersion: 'Testing/0.0.0', + enableAlphaMls: true, }) - await bo.conversations.streamAllMessages(async () => { - console.log('message received') - messageCallbacks++ - }, true) - - const group = await alix.conversations.newGroup([bo.address]) - await group.send('hello') - - await delayToPropogate() - await new Promise((resolve) => setTimeout(resolve, 10000)) - assert(groupCallbacks === 1, 'group stream should have received 1 group') // <--- Fails here - assert( - messageCallbacks === 1, - 'message stream should have received 1 message' - ) return true }) -// test('can make a MLS V3 client', async () => { -// // eslint-disable-next-line @typescript-eslint/no-unused-vars -// const client = await Client.createRandom({ -// env: 'local', -// appVersion: 'Testing/0.0.0', -// enableAlphaMls: true, -// }) - -// 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 -// }` -// ) - -// await client.deleteLocalDatabase() -// client = await Client.createRandom({ -// env: 'local', -// appVersion: 'Testing/0.0.0', -// enableAlphaMls: 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 -// }` -// ) - -// 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', -// enableAlphaMls: true, -// dbEncryptionKey: key, -// dbDirectory: dbDirPath, -// }) - -// const anotherClient = await Client.createRandom({ -// env: 'local', -// appVersion: 'Testing/0.0.0', -// enableAlphaMls: 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', -// enableAlphaMls: 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 -// }) - -// 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') -// }) - -// 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', -// enableAlphaMls: true, -// dbEncryptionKey: key, -// }) - -// const anotherClient = await Client.createRandom({ -// env: 'local', -// appVersion: 'Testing/0.0.0', -// enableAlphaMls: 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', -// enableAlphaMls: 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', -// enableAlphaMls: 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}` -// ) - -// return true -// }) - -// test('production MLS V3 client creation throws 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', -// enableAlphaMls: true, -// dbEncryptionKey: key, -// }) -// // eslint-disable-next-line @typescript-eslint/no-unused-vars -// } catch (error) { -// return true -// } -// throw new Error( -// 'should throw error on MLS V3 client create when environment is not local' -// ) -// }) - -// test('group message delivery status', async () => { -// const [alixClient, boClient] = await createClients(2) -// const alixGroup = await alixClient.conversations.newGroup([boClient.address]) - -// await alixGroup.send('hello, world') +test('can delete a local database', async () => { + let [client, anotherClient] = await createClients(2) -// const alixMessages: DecodedMessage[] = await alixGroup.messages() + 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( -// alixMessages.length === 2, -// `the messages length should be 2 but was ${alixMessages.length}` -// ) + await client.deleteLocalDatabase() + client = await Client.createRandom({ + env: 'local', + appVersion: 'Testing/0.0.0', + enableAlphaMls: 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 alixMessagesFiltered: DecodedMessage[] = await alixGroup.messages({ -// deliveryStatus: MessageDeliveryStatus.UNPUBLISHED, -// }) + return true +}) -// assert( -// alixMessagesFiltered.length === 1, -// `the messages length should be 1 but was ${alixMessagesFiltered.length}` -// ) +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', + enableAlphaMls: true, + dbEncryptionKey: key, + dbDirectory: dbDirPath, + }) -// await alixGroup.sync() -// const alixMessages2: DecodedMessage[] = await alixGroup.messages() + const anotherClient = await Client.createRandom({ + env: 'local', + appVersion: 'Testing/0.0.0', + enableAlphaMls: true, + dbEncryptionKey: key, + }) -// assert( -// alixMessages2.length === 2, -// `the messages length should be 2 but was ${alixMessages.length}` -// ) + 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 + }` + ) -// assert( -// alixMessages2[0].deliveryStatus === 'PUBLISHED', -// `the message should have a delivery status of PUBLISHED but was ${alixMessages2[0].deliveryStatus}` -// ) + const bundle = await client.exportKeyBundle() + const clientFromBundle = await Client.createFromKeyBundle(bundle, { + env: 'local', + appVersion: 'Testing/0.0.0', + enableAlphaMls: true, + dbEncryptionKey: key, + dbDirectory: dbDirPath, + }) -// await boClient.conversations.syncGroups() -// const boGroup = (await boClient.conversations.listGroups())[0] -// await boGroup.sync() -// const boMessages: DecodedMessage[] = await boGroup.messages() + assert( + clientFromBundle.address === client.address, + `clients dont match ${client.address} and ${clientFromBundle.address}` + ) -// assert( -// boMessages.length === 1, -// `the messages length should be 1 but was ${boMessages.length}` -// ) + assert( + (await clientFromBundle.conversations.listGroups()).length === 1, + `should have a group size of 1 but was ${ + (await clientFromBundle.conversations.listGroups()).length + }` + ) + return true +}) -// assert( -// boMessages[0].deliveryStatus === 'PUBLISHED', -// `the message should have a delivery status of PUBLISHED but was ${boMessages[0].deliveryStatus}` -// ) +test('can drop a local database', async () => { + const [client, anotherClient] = await createClients(2) -// return true -// }) + 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 + }` + ) -// test('who added me to a group', async () => { -// const [alixClient, boClient] = await createClients(2) -// await alixClient.conversations.newGroup([boClient.address]) + 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') +}) -// await boClient.conversations.syncGroups() -// const boGroup = (await boClient.conversations.listGroups())[0] -// const addedByInboxId = await boGroup.addedByInboxId() +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', + enableAlphaMls: true, + dbEncryptionKey: key, + }) -// assert( -// addedByInboxId === alixClient.inboxId, -// `addedByInboxId ${addedByInboxId} does not match ${alixClient.inboxId}` -// ) -// return true -// }) + const anotherClient = await Client.createRandom({ + env: 'local', + appVersion: 'Testing/0.0.0', + enableAlphaMls: true, + dbEncryptionKey: key, + }) -// test('can get members of a group', async () => { -// const [alixClient, boClient] = await createClients(2) -// const group = await alixClient.conversations.newGroup([boClient.address]) - -// const members = await 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 -// }) + const group1 = await client.conversations.newGroup([anotherClient.address]) -// test('can message in a group', async () => { -// // Create three MLS enabled Clients -// const [alixClient, boClient, caroClient] = await createClients(3) + assert( + group1.client.address === client.address, + `clients dont match ${client.address} and ${group1.client.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') -// } + const bundle = await client.exportKeyBundle() + const client2 = await Client.createFromKeyBundle(bundle, { + env: 'local', + appVersion: 'Testing/0.0.0', + enableAlphaMls: true, + dbEncryptionKey: key, + }) -// // 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') -// } + assert( + client.address === client2.address, + `clients dont match ${client2.address} and ${client.address}` + ) -// // alix group should match create time from list function -// assert(alixGroups[0].createdAt === alixGroup.createdAt, 'group create time') + assert( + client.inboxId === client2.inboxId, + `clients dont match ${client2.inboxId} and ${client.inboxId}` + ) -// // 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 peerInboxIds = await alixGroup.peerInboxIds -// if (peerInboxIds.length !== 2) { -// throw new Error('num peer group members should be 2') -// } -// if ( -// !( -// memberInboxIds.includes(alixClient.inboxId) && -// memberInboxIds.includes(boClient.inboxId) && -// memberInboxIds.includes(caroClient.inboxId) -// ) -// ) { -// throw new Error('missing address') -// } + assert( + client.installationId === client2.installationId, + `clients dont match ${client2.installationId} and ${client.installationId}` + ) -// if ( -// !( -// peerInboxIds.includes(boClient.inboxId) && -// peerInboxIds.includes(caroClient.inboxId) -// ) -// ) { -// throw new Error('should include self') -// } + const randomClient = await Client.createRandom({ + env: 'local', + appVersion: 'Testing/0.0.0', + enableAlphaMls: true, + dbEncryptionKey: key, + }) -// // 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 -// ) -// } + const group = await client2.conversations.newGroup([randomClient.address]) -// // caro can read messages from alix and bo -// await caroGroups[0].sync() -// const caroMessages = await caroGroups[0].messages() + assert( + group.client.address === client2.address, + `clients dont match ${client2.address} and ${group.client.address}` + ) -// 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('production MLS V3 client creation throws 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', + enableAlphaMls: true, + dbEncryptionKey: key, + }) + // eslint-disable-next-line @typescript-eslint/no-unused-vars + } catch (error) { + return true + } + throw new Error( + 'should throw error on MLS V3 client create when environment is not local' + ) +}) -// test('can add members to 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') -// // 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') -// } + const alixMessages: DecodedMessage[] = await alixGroup.messages() -// // 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') -// } + assert( + alixMessages.length === 2, + `the messages length should be 2 but was ${alixMessages.length}` + ) -// // alix creates a group -// const alixGroup = await alixClient.conversations.newGroup([boClient.address]) + const alixMessagesFiltered: DecodedMessage[] = await alixGroup.messages({ + deliveryStatus: MessageDeliveryStatus.UNPUBLISHED, + }) -// // 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( + alixMessagesFiltered.length === 1, + `the messages length should be 1 but was ${alixMessagesFiltered.length}` + ) -// // 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 alixGroup.sync() + const alixMessages2: DecodedMessage[] = await alixGroup.messages() -// // 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 -// ) -// } + assert( + alixMessages2.length === 2, + `the messages length should be 2 but was ${alixMessages.length}` + ) -// await alixGroup.addMembers([caroClient.address]) + assert( + alixMessages2[0].deliveryStatus === 'PUBLISHED', + `the message should have a delivery status of PUBLISHED but was ${alixMessages2[0].deliveryStatus}` + ) -// // 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 boClient.conversations.syncGroups() + const boGroup = (await boClient.conversations.listGroups())[0] + await boGroup.sync() + const boMessages: DecodedMessage[] = await boGroup.messages() -// await boGroups[0].sync() -// const boGroupMembers = await boGroups[0].memberInboxIds() -// if (boGroupMembers.length !== 3) { -// throw new Error('num group members should be 3') -// } + assert( + boMessages.length === 1, + `the messages length should be 1 but was ${boMessages.length}` + ) -// return true -// }) + assert( + boMessages[0].deliveryStatus === 'PUBLISHED', + `the message should have a delivery status of PUBLISHED but was ${boMessages[0].deliveryStatus}` + ) -// 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('who added me to a group', async () => { + const [alixClient, boClient] = await createClients(2) + await alixClient.conversations.newGroup([boClient.address]) -// // bo's num groups start at 0 -// let boGroups = await boClient.conversations.listGroups() -// assert(boGroups.length === 0, 'num groups should be 0') + await boClient.conversations.syncGroups() + const boGroup = (await boClient.conversations.listGroups())[0] + const addedByInboxId = await boGroup.addedByInboxId() -// // 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') -// } + assert( + addedByInboxId === alixClient.inboxId, + `addedByInboxId ${addedByInboxId} does not match ${alixClient.inboxId}` + ) + return 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') -// } +test('can get members of a group', async () => { + const [alixClient, boClient] = await createClients(2) + const group = await alixClient.conversations.newGroup([boClient.address]) + + const members = await 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 +}) -// // 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') -// } +test('can message in 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') + } + + // 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 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 !== 3) { + throw new Error('num group members should be 3') + } + const peerInboxIds = await alixGroup.peerInboxIds + if (peerInboxIds.length !== 2) { + throw new Error('num peer group members should be 2') + } + if ( + !( + memberInboxIds.includes(alixClient.inboxId) && + memberInboxIds.includes(boClient.inboxId) && + memberInboxIds.includes(caroClient.inboxId) + ) + ) { + throw new Error('missing address') + } + + if ( + !( + peerInboxIds.includes(boClient.inboxId) && + peerInboxIds.includes(caroClient.inboxId) + ) + ) { + throw new Error('should include self') + } + + // 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 can read messages from alix and bo + await caroGroups[0].sync() + const caroMessages = await caroGroups[0].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()}` + ) + } -// // 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 -// ) -// } + return true +}) -// // 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 -// ) -// } +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') + } -// await caroGroups[0].sync() -// if (!caroGroups[0].isActive()) { -// throw new Error('caros group should be active') -// } + return true +}) -// 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 -// ) -// } +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() + // should be 3 since they wont get new updates to the group after being removed + if (caroGroupMembers.length !== 3) { + throw new Error( + 'num group members should be 3 but was' + caroGroupMembers.length + ) + } -// await caroGroups[0].sync() -// if (await caroGroups[0].isActive()) { -// throw new Error('caros group should not be active') -// } + return true +}) -// const caroGroupMembers = await caroGroups[0].memberInboxIds() -// // should be 3 since they wont get new updates to the group after being removed -// if (caroGroupMembers.length !== 3) { -// throw new Error( -// 'num group members should be 3 but was' + caroGroupMembers.length -// ) -// } +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 -// }) + 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 stream both groups and messages at same time', async () => { + const [alix, bo] = await createClients(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') -// } + let groupCallbacks = 0 + let messageCallbacks = 0 + await bo.conversations.streamGroups(async () => { + groupCallbacks++ + }) -// 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 bo.conversations.streamAllMessages(async () => { + messageCallbacks++ + }, true) -// return true -// }) + const group = await alix.conversations.newGroup([bo.address]) + await group.send('hello') -// 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) -// } + 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 +}) -// // 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) -// } +test('can stream groups', async () => { + const [alixClient, boClient, caroClient] = await createClients(3) -// // * 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 + // Start streaming groups + const groups: Group[] = [] + const cancelStreamGroups = await alixClient.conversations.streamGroups( + async (group: Group) => { + groups.push(group) + } + ) -// // 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 !== 2) { -// throw Error('Expected group length 2 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) !== 3) { -// throw Error('Expected group length 3 but it is: ' + 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) + } -// cancelStreamGroups() -// await delayToPropogate() + // 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 !== 2) { + throw Error('Expected group length 2 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) !== 3) { + throw Error('Expected group length 3 but it is: ' + groups.length) + } -// // 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) !== 3) { -// throw Error('Unexpected num groups (should be 3): ' + groups.length) -// } + cancelStreamGroups() + await delayToPropogate() -// return true -// }) + // 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) !== 3) { + throw Error('Unexpected num groups (should be 3): ' + groups.length) + } -// 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 = isIos() ? 1 : 0 -// const second = isIos() ? 0 : 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 +}) -// return true -// }) +test('can list all groups and conversations', async () => { + const [alixClient, boClient, caroClient] = await createClients(3) -// test('can stream 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 + ) -// // Start streaming groups and conversations -// const containers: ConversationContainer[] = [] -// const cancelStreamAll = await alixClient.conversations.streamAll( -// async (conversationContainer: ConversationContainer) => { -// containers.push(conversationContainer) -// } -// ) + 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 = isIos() ? 1 : 0 + const second = isIos() ? 0 : 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 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) -// } + return true +}) -// // 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) -// } +test('can stream all groups and conversations', async () => { + const [alixClient, boClient, caroClient] = await createClients(3) -// 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' -// ) -// } + // Start streaming groups and conversations + const containers: ConversationContainer[] = [] + const cancelStreamAll = await alixClient.conversations.streamAll( + async (conversationContainer: ConversationContainer) => { + containers.push(conversationContainer) + } + ) -// // * Note alix creating a v2 Conversation does trigger alix conversations -// // stream. + // 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) + } + + 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' + ) + } + + // * Note alix creating a v2 Conversation does trigger alix conversations + // stream. + + // 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) + } -// // 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) -// } + cancelStreamAll() + await delayToPropogate() -// cancelStreamAll() -// await delayToPropogate() + // 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) + } -// // 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('canMessage', async () => { + const [bo, alix, caro] = await createClients(3) -// test('canMessage', async () => { -// const [bo, alix, caro] = await createClients(3) + const canMessage = await bo.canMessage(alix.address) + if (!canMessage) { + throw new Error('should be able to message v2 client') + } -// const canMessage = await bo.canMessage(alix.address) -// if (!canMessage) { -// throw new Error('should be able to message v2 client') -// } + const canMessageV3 = await caro.canGroupMessage([ + caro.address, + alix.address, + '0x0000000000000000000000000000000000000000', + ]) -// const canMessageV3 = await caro.canGroupMessage([ -// caro.address, -// alix.address, -// '0x0000000000000000000000000000000000000000', -// ]) + assert( + canMessageV3['0x0000000000000000000000000000000000000000'] === false, + `should not be able to message 0x0000000000000000000000000000000000000000` + ) -// assert( -// canMessageV3['0x0000000000000000000000000000000000000000'] === false, -// `should not be able to message 0x0000000000000000000000000000000000000000` -// ) + assert( + canMessageV3[caro.address.toLowerCase()] === true, + `should be able to message ${caro.address}` + ) -// assert( -// canMessageV3[caro.address.toLowerCase()] === true, -// `should be able to message ${caro.address}` -// ) + assert( + canMessageV3[alix.address.toLowerCase()] === true, + `should be able to message ${alix.address}` + ) -// assert( -// canMessageV3[alix.address.toLowerCase()] === true, -// `should be able to message ${alix.address}` -// ) + 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 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() -// } + // 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() + } + + 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() + ) + } + } + + cancelGroupMessageStream() + for (let i = 0; i < 5; i++) { + await boGroup.send({ text: `Message ${i}` }) + } + + if (groupMessages.length !== 5) { + throw Error('Unexpected convo messages count ' + groupMessages.length) + } -// 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() -// ) -// } -// } + return true +}) -// cancelGroupMessageStream() -// for (let i = 0; i < 5; i++) { -// await boGroup.send({ text: `Message ${i}` }) -// } +test('can stream all messages', async () => { + const [alix, bo, caro] = await createClients(3) -// if (groupMessages.length !== 5) { -// throw Error('Unexpected convo messages count ' + groupMessages.length) -// } + 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 messages', async () => { -// const [alix, bo, caro] = await createClients(3) + // Start bo starts a new conversation. + const boConvo = await bo.conversations.newConversation(alix.address) + await delayToPropogate() -// await delayToPropogate() + for (let i = 0; i < 5; i++) { + await boConvo.send({ text: `Message ${i}` }) + await delayToPropogate() + } -// // Record message stream across all conversations -// const allMessages: DecodedMessage[] = [] -// await alix.conversations.streamAllMessages(async (message) => { -// allMessages.push(message) -// }) + const count = allMessages.length + if (count !== 5) { + throw Error('Unexpected all messages count ' + allMessages.length) + } -// // Start bo starts a new conversation. -// const boConvo = await bo.conversations.newConversation(alix.address) -// await delayToPropogate() + 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() + } -// for (let i = 0; i < 5; i++) { -// await boConvo.send({ text: `Message ${i}` }) -// await delayToPropogate() -// } + if (allMessages.length !== 10) { + throw Error('Unexpected all messages count ' + allMessages.length) + } -// const count = allMessages.length -// if (count !== 5) { -// throw Error('Unexpected all messages count ' + allMessages.length) -// } + alix.conversations.cancelStreamAllMessages() -// 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() -// } + await alix.conversations.streamAllMessages(async (message) => { + allMessages.push(message) + }, true) -// if (allMessages.length !== 10) { -// throw Error('Unexpected all messages count ' + allMessages.length) -// } + 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) + } -// alix.conversations.cancelStreamAllMessages() + return true +}) -// await alix.conversations.streamAllMessages(async (message) => { -// allMessages.push(message) -// }, true) +test('can make a group with admin permissions', async () => { + const [adminClient, anotherClient] = await createClients(2) -// 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) -// } + const group = await adminClient.conversations.newGroup( + [anotherClient.address], + 'admin_only' + ) -// return true -// }) + if (group.permissionLevel !== 'admin_only') { + throw Error( + `Group permission level should be admin_only but was ${group.permissionLevel}` + ) + } -// test('can make a group with admin permissions', async () => { -// const [adminClient, anotherClient] = await createClients(2) + const isAdmin = await group.isAdmin(adminClient.inboxId) + if (!isAdmin) { + throw Error(`adminClient should be the admin`) + } -// const group = await adminClient.conversations.newGroup( -// [anotherClient.address], -// 'admin_only' -// ) + // 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}` + // ) + // } -// if (group.permissionLevel !== 'admin_only') { -// throw Error( -// `Group permission level should be admin_only but was ${group.permissionLevel}` -// ) -// } + return true +}) -// const isAdmin = await group.isAdmin(adminClient.inboxId) -// if (!isAdmin) { -// throw Error(`adminClient should be the admin`) -// } +test('can paginate group messages', async () => { + // Create three MLS enabled Clients + const [alixClient, boClient] = await createClients(2) -// // 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 creates a group + const alixGroup = await alixClient.conversations.newGroup([boClient.address]) -// return true -// }) + // alix can send messages + await alixGroup.send('hello, world') + await alixGroup.send('gm') -// test('can paginate group messages', async () => { -// // Create three MLS enabled Clients -// const [alixClient, boClient] = await createClients(2) + 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, + }) -// // alix creates a group -// const alixGroup = await alixClient.conversations.newGroup([boClient.address]) + if (boMessages.length !== 1) { + throw Error(`Should limit just 1 message but was ${boMessages.length}`) + } -// // alix can send messages -// await alixGroup.send('hello, world') -// await alixGroup.send('gm') + return true +}) -// 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}`) -// } +test('can stream all group messages', async () => { + const [alix, bo, caro] = await createClients(3) -// return true -// }) + await delayToPropogate() -// test('can stream all group messages', async () => { -// const [alix, bo, caro] = await createClients(3) + // Start bo starts a new group. + const boGroup = await bo.conversations.newGroup([alix.address]) + await delayToPropogate() -// await delayToPropogate() + // Starts a new conversation. + const caroGroup = await caro.conversations.newGroup([alix.address]) -// // Start bo starts a new group. -// const boGroup = await bo.conversations.newGroup([alix.address]) -// await delayToPropogate() + // 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) + }) -// // 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() -// } + 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) -// } + 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() -// } + 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) -// } + 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) -// }) + 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) -// } + 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 -// }) + return true +}) -// test('can streamAll from multiple clients', async () => { -// const [alix, bo, caro] = await createClients(3) +test('can streamAll from multiple clients', async () => { + const [alix, bo, caro] = await createClients(3) -// // Setup stream alls -// const allBoConversations: any[] = [] -// const allAliConversations: any[] = [] + // Setup stream alls + const allBoConversations: any[] = [] + const allAliConversations: any[] = [] -// await bo.conversations.streamAll(async (conversation) => { -// allBoConversations.push(conversation) -// }) -// await alix.conversations.streamAll(async (conversation) => { -// allAliConversations.push(conversation) -// }) + await bo.conversations.streamAll(async (conversation) => { + allBoConversations.push(conversation) + }) + await alix.conversations.streamAll(async (conversation) => { + allAliConversations.push(conversation) + }) -// // 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 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 streamAll from multiple clients - swapped orderring', 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 alls -// const allBoConversations: any[] = [] -// const allAliConversations: any[] = [] + // Setup stream alls + const allBoConversations: any[] = [] + const allAliConversations: any[] = [] -// await alix.conversations.streamAll(async (conversation) => { -// allAliConversations.push(conversation) -// }) + await alix.conversations.streamAll(async (conversation) => { + allAliConversations.push(conversation) + }) -// await bo.conversations.streamAll(async (conversation) => { -// allBoConversations.push(conversation) -// }) + await bo.conversations.streamAll(async (conversation) => { + allBoConversations.push(conversation) + }) -// // 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 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', async () => { -// const [alix, bo, caro] = await createClients(3) +test('can streamAllMessages from multiple clients', async () => { + const [alix, bo, caro] = await createClients(3) -// // Setup stream -// const allBoMessages: any[] = [] -// const allAliMessages: any[] = [] + // Setup stream + const allBoMessages: any[] = [] + const allAliMessages: any[] = [] -// await bo.conversations.streamAllMessages(async (conversation) => { -// allBoMessages.push(conversation) -// }, true) -// await alix.conversations.streamAllMessages(async (conversation) => { -// allAliMessages.push(conversation) -// }, true) + await bo.conversations.streamAllMessages(async (conversation) => { + allBoMessages.push(conversation) + }, true) + await alix.conversations.streamAllMessages(async (conversation) => { + allAliMessages.push(conversation) + }, true) -// // 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. + 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) + } -// if (allAliMessages.length !== 1) { -// throw Error( -// 'Unexpected all conversations count for Ali ' + allAliMessages.length -// ) -// } + if (allAliMessages.length !== 1) { + throw Error( + 'Unexpected all conversations count for Ali ' + allAliMessages.length + ) + } -// return true -// }) + return true +}) -// test('can streamAllMessages 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 allBoMessages: any[] = [] -// const allAliMessages: any[] = [] -// const caroGroup = await caro.conversations.newGroup([alix.address]) + // Setup stream + const allBoMessages: any[] = [] + const allAliMessages: any[] = [] + const caroGroup = await caro.conversations.newGroup([alix.address]) -// await alix.conversations.streamAllMessages(async (conversation) => { -// allAliMessages.push(conversation) -// }, true) -// await bo.conversations.streamAllMessages(async (conversation) => { -// allBoMessages.push(conversation) -// }, true) + 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. -// 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 -// ) -// } + // 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 (allAliMessages.length !== 2) { + throw Error( + 'Unexpected all conversations count for Ali ' + allAliMessages.length + ) + } -// if (allAliMessages.length !== 2) { -// throw Error( -// 'Unexpected all conversations count for Ali ' + allAliMessages.length -// ) -// } + return true +}) -// return true -// }) +test('can stream all group Messages 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 allAlixMessages: DecodedMessage[] = [] + const allBoMessages: DecodedMessage[] = [] + const alixGroup = await caro.conversations.newGroup([alix.address]) + const boGroup = await caro.conversations.newGroup([bo.address]) -// // 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 alixGroup.streamGroupMessages(async (message) => { + allAlixMessages.push(message) + }) + await boGroup.streamGroupMessages(async (message) => { + allBoMessages.push(message) + }) -// await alixGroup.streamGroupMessages(async (message) => { -// allAlixMessages.push(message) -// }) -// await boGroup.streamGroupMessages(async (message) => { -// allBoMessages.push(message) -// }) + // 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 (allAlixMessages.length !== 1) { + throw Error( + 'Unexpected all messages count for Ali ' + allAlixMessages.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 + ) + } -// // 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 - swapped', 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 boGroup.streamGroupMessages(async (message) => { + allBoMessages.push(message) + }) + await alixGroup.streamGroupMessages(async (message) => { + allAlixMessages.push(message) + }) -// test('can stream all group Messages from multiple clients - swapped', async () => { -// const [alix, bo, caro] = await createClients(3) + // 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 (allAlixMessages.length !== 1) { + throw Error( + 'Unexpected all messages count for Ali ' + allAlixMessages.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 + ) + } -// // 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('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}` + ) -// 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 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') + } -// if (!consent || !groupConsent) { -// throw Error('Group should be allowed') -// } + return true +}) -// const state = await group.consentState() -// assert( -// state === 'allowed', -// `the message should have a consent state of allowed but was ${state}` -// ) +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') + } -// 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 +}) -// return true -// }) +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') + } + + 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}` + ) -// 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') -// } + 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('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') -// } + return true +}) -// return true -// }) +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 +}) -// 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') -// } +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 bo.contacts.consentList() -// assert( -// consentList[0].entryType === 'inbox_id', -// `the message should have a type of inbox_id but was ${consentList[0].entryType}` -// ) + 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 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 bo.conversations.syncGroups() -// return true -// }) + boGroups = await bo.conversations.listGroups() + assert(boGroups.length === 1, 'num groups for bo is 1') -// 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 -// }) + // 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('sync function behaves as expected', async () => { -// const [alix, bo, caro] = await createClients(3) -// const alixGroup = await alix.conversations.newGroup([bo.address]) + // 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') -// await alixGroup.send({ text: 'hello' }) + await bo.conversations.syncGroups() -// // 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') + // 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 bo.conversations.syncGroups() + await boGroups[0].sync() -// boGroups = await bo.conversations.listGroups() -// assert(boGroups.length === 1, 'num groups for bo is 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') -// // 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') + await alixGroup.addMembers([caro.address]) -// // 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') + numMembers = (await boGroups[0].memberInboxIds()).length + assert(numMembers === 2, 'num members should be 2') -// await bo.conversations.syncGroups() + await bo.conversations.syncGroups() -// // 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') + // 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 boGroups[0].sync() + await boGroups[0].sync() -// // 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') + numMembers = (await boGroups[0].memberInboxIds()).length + assert(numMembers === 3, 'num members should be 3') -// await alixGroup.addMembers([caro.address]) + // 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') -// 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') -// await bo.conversations.syncGroups() + return true +}) -// // 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') +test('can read and update group name', async () => { + const [alix, bo, caro] = await createClients(3) + const alixGroup = await alix.conversations.newGroup([bo.address]) -// await boGroups[0].sync() + await alixGroup.sync() + let groupName = await alixGroup.groupName() -// numMembers = (await boGroups[0].memberInboxIds()).length -// assert(numMembers === 3, 'num members should be 3') + assert(groupName === '', 'group name should be empty string') -// // 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.updateGroupName('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.sync() + groupName = await alixGroup.groupName() -// return true -// }) + assert( + groupName === 'Test name update 1', + 'group name should be "Test name update 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() + const boGroup = (await bo.conversations.listGroups())[0] + groupName = await boGroup.groupName() -// await alixGroup.sync() -// let groupName = await alixGroup.groupName() + assert(groupName === '', 'group name should be empty string') -// assert(groupName === '', 'group name should be empty string') + await boGroup.sync() -// await alixGroup.updateGroupName('Test name update 1') + groupName = await boGroup.groupName() -// await alixGroup.sync() -// groupName = await alixGroup.groupName() + assert( + groupName === 'Test name update 1', + 'group name should be "Test name update 1"' + ) -// assert( -// groupName === 'Test name update 1', -// 'group name should be "Test name update 1"' -// ) + await alixGroup.addMembers([caro.address]) + await caro.conversations.syncGroups() + const caroGroup = (await caro.conversations.listGroups())[0] -// await bo.conversations.syncGroups() -// const boGroup = (await bo.conversations.listGroups())[0] -// groupName = await boGroup.groupName() + await caroGroup.sync() + groupName = await caroGroup.groupName() + assert( + groupName === 'Test name update 1', + 'group name should be "Test name update 1"' + ) + return true +}) -// assert(groupName === '', 'group name should be empty string') +// Commenting this out so it doesn't block people, but nice to have? +// test('can stream messages for a long time', async () => { +// const bo = await Client.createRandom({ env: 'local', enableAlphaMls: true }) +// await delayToPropogate() +// const alix = await Client.createRandom({ env: 'local', enableAlphaMls: true }) +// await delayToPropogate() +// const caro = await Client.createRandom({ env: 'local', enableAlphaMls: true }) +// await delayToPropogate() -// await boGroup.sync() +// // Setup stream alls +// const allBoMessages: any[] = [] +// const allAliMessages: any[] = [] -// groupName = await boGroup.groupName() +// const group = await caro.conversations.newGroup([alix.address]) +// await bo.conversations.streamAllMessages(async (conversation) => { +// allBoMessages.push(conversation) +// }, true) +// await alix.conversations.streamAllMessages(async (conversation) => { +// allAliMessages.push(conversation) +// }, true) -// assert( -// groupName === 'Test name update 1', -// 'group name should be "Test name update 1"' -// ) +// // Wait for 15 minutes +// await delayToPropogate(15 * 1000 * 60) -// await alixGroup.addMembers([caro.address]) -// await caro.conversations.syncGroups() -// const caroGroup = (await caro.conversations.listGroups())[0] +// // Start Caro starts a new conversation. +// const convo = await caro.conversations.newConversation(alix.address) +// await group.send({ text: 'hello' }) +// await convo.send({ text: 'hello' }) +// await delayToPropogate() +// if (allBoMessages.length !== 0) { +// throw Error('Unexpected all conversations count ' + allBoMessages.length) +// } +// if (allAliMessages.length !== 2) { +// throw Error('Unexpected all conversations count ' + allAliMessages.length) +// } -// await caroGroup.sync() -// groupName = await caroGroup.groupName() -// assert( -// groupName === 'Test name update 1', -// 'group name should be "Test name update 1"' -// ) // return true // }) - -// // Commenting this out so it doesn't block people, but nice to have? -// // test('can stream messages for a long time', async () => { -// // const bo = await Client.createRandom({ env: 'local', enableAlphaMls: true }) -// // await delayToPropogate() -// // const alix = await Client.createRandom({ env: 'local', enableAlphaMls: true }) -// // await delayToPropogate() -// // const caro = await Client.createRandom({ env: 'local', enableAlphaMls: true }) -// // await delayToPropogate() - -// // // Setup stream alls -// // const allBoMessages: any[] = [] -// // const allAliMessages: any[] = [] - -// // const group = await caro.conversations.newGroup([alix.address]) -// // await bo.conversations.streamAllMessages(async (conversation) => { -// // allBoMessages.push(conversation) -// // }, true) -// // await alix.conversations.streamAllMessages(async (conversation) => { -// // allAliMessages.push(conversation) -// // }, true) - -// // // Wait for 15 minutes -// // await delayToPropogate(15 * 1000 * 60) - -// // // Start Caro starts a new conversation. -// // const convo = await caro.conversations.newConversation(alix.address) -// // await group.send({ text: 'hello' }) -// // await convo.send({ text: 'hello' }) -// // await delayToPropogate() -// // if (allBoMessages.length !== 0) { -// // throw Error('Unexpected all conversations count ' + allBoMessages.length) -// // } -// // if (allAliMessages.length !== 2) { -// // throw Error('Unexpected all conversations count ' + allAliMessages.length) -// // } - -// // return true -// // }) diff --git a/ios/XMTPReactNative.podspec b/ios/XMTPReactNative.podspec index a84d0f4a8..2f02bee6b 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.11.5" + s.dependency "XMTP", "= 0.11.6" end