diff --git a/example/src/tests/groupTests.ts b/example/src/tests/groupTests.ts index 68d6cd818..923cc2042 100644 --- a/example/src/tests/groupTests.ts +++ b/example/src/tests/groupTests.ts @@ -18,6 +18,7 @@ import { GroupUpdatedContent, GroupUpdatedCodec, } from '../../../src/index' +import { Wallet } from 'ethers' export const groupTests: Test[] = [] let counter = 1 @@ -1993,6 +1994,74 @@ test('can list groups does not fork', async () => { return true }) +test('can create new installation without breaking group', async () => { + const keyBytes = new Uint8Array([ + 233, 120, 198, 96, 154, 65, 132, 17, 132, 96, 250, 40, 103, 35, 125, 64, + 166, 83, 208, 224, 254, 44, 205, 227, 175, 49, 234, 129, 74, 252, 135, 145, + ]) + const wallet1 = new Wallet( + '0xc54c62dd3ad018ef94f20f0722cae33919e65270ad74f2d1794291088800f788' + ) + const wallet2 = new Wallet( + '0x8d40c1c40473975cc6bbdc0465e70cc2e98f45f3c3474ca9b809caa9c4f53c0b' + ) + const client1 = await Client.create(wallet1, { + env: 'local', + appVersion: 'Testing/0.0.0', + enableV3: true, + dbEncryptionKey: keyBytes, + }) + const client2 = await Client.create(wallet2, { + env: 'local', + appVersion: 'Testing/0.0.0', + enableV3: true, + dbEncryptionKey: keyBytes, + }) + + const group = await client1.conversations.newGroup([wallet2.address]) + + await client1.conversations.syncGroups() + await client2.conversations.syncGroups() + + const client1Group = (await client1.conversations.listGroups()).find( + (g) => g.id === group.id + ) + const client2Group = (await client2.conversations.listGroups()).find( + (g) => g.id === group.id + ) + await client1Group?.sync() + await client2Group?.sync() + + assert( + (await client1Group?.members())?.length === 2, + `client 1 should see 2 members` + ) + + assert( + (await client2Group?.members())?.length === 2, + `client 2 should see 2 members` + ) + + await client2.dropLocalDatabaseConnection() + await client2.deleteLocalDatabase() + + // Recreating a client with wallet 2 (new installation!) + await Client.create(wallet2, { + env: 'local', + appVersion: 'Testing/0.0.0', + enableV3: true, + dbEncryptionKey: keyBytes, + }) + + await client1Group?.send('This message will break the group') + assert( + (await client1Group?.members())?.length === 2, + `client 1 should still see the 2 members` + ) + + 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', enableV3: true })