Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test for members inconsistencies when creating new installations #458

Merged
merged 5 commits into from
Aug 7, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions example/src/tests/groupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
delayToPropogate,
isIos,
} from './test-utils'
import {

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

View workflow job for this annotation

GitHub Actions / lint

There should be at least one empty line between import groups
Client,
Conversation,
Group,
Expand All @@ -18,6 +18,7 @@
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 @@
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
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Total nit but you can actually call just find_group directly in V3 instead of iterating over the list.

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
Loading