Skip to content

Commit

Permalink
Merge branch 'noe/members-inconsistence-test' of https://github.com/x…
Browse files Browse the repository at this point in the history
…mtp/xmtp-react-native into noe/members-inconsistence-test
  • Loading branch information
nplasterer committed Aug 7, 2024
2 parents 0da6e9e + 5a03514 commit 5b9374c
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 @@ -17,6 +17,7 @@ import {
GroupUpdatedContent,
GroupUpdatedCodec,
} from '../../../src/index'
import { Wallet } from 'ethers'

export const groupTests: Test[] = []
let counter = 1
Expand Down Expand Up @@ -2046,6 +2047,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 5b9374c

Please sign in to comment.