Skip to content

Commit

Permalink
Add a test for members inconsistencies when creating new installations
Browse files Browse the repository at this point in the history
  • Loading branch information
nmalzieu committed Aug 5, 2024
1 parent e6aa77b commit 5a03514
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions example/src/tests/groupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
GroupUpdatedContent,
GroupUpdatedCodec,
} from '../../../src/index'
import { Wallet } from 'ethers'

Check warning on line 21 in example/src/tests/groupTests.ts

View workflow job for this annotation

GitHub Actions / lint

`ethers` import should occur before import of `react-native-fs`

export const groupTests: Test[] = []
let counter = 1
Expand Down Expand Up @@ -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 })
Expand Down

0 comments on commit 5a03514

Please sign in to comment.