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
Show file tree
Hide file tree
Changes from 4 commits
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
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ repositories {
dependencies {
implementation project(':expo-modules-core')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
implementation "org.xmtp:android:0.14.15"
implementation "org.xmtp:android:0.14.16"
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'com.facebook.react:react-native:0.71.3'
implementation "com.daveanthonythomas.moshipack:moshipack:1.0.1"
Expand Down
66 changes: 66 additions & 0 deletions example/src/tests/groupTests.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import RNFS from 'react-native-fs'
import { DecodedMessage } from 'xmtp-react-native-sdk/lib/DecodedMessage'

import {

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

View workflow job for this annotation

GitHub Actions / lint

Replace `⏎··Test,⏎··assert,⏎··createClients,⏎··delayToPropogate,⏎` with `·Test,·assert,·createClients,·delayToPropogate·`
Test,
assert,
createClients,
delayToPropogate,
} from './test-utils'
import {

Check warning on line 10 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 @@ -17,6 +17,7 @@
GroupUpdatedContent,
GroupUpdatedCodec,
} from '../../../src/index'
import { Wallet } from 'ethers'

Check warning on line 20 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 @@ -2046,6 +2047,71 @@
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.findGroup(group.id)
const client2Group = await client2.conversations.findGroup(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
2 changes: 1 addition & 1 deletion ios/XMTPReactNative.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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.13.15"
s.dependency "XMTP", "= 0.13.16"
end
Loading