Skip to content

Commit

Permalink
update the test and return a list of installations
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Sep 26, 2024
1 parent f508b76 commit 2b0532c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 27 deletions.
44 changes: 22 additions & 22 deletions library/src/androidTest/java/org/xmtp/android/library/GroupTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ class GroupTest {
alixGroup.addMembers(listOf(caro.walletAddress))
boGroup.sync()
}
assertEquals(alixGroup.members().size, 3)
assertEquals(boGroup.members().size, 3)
assertEquals(runBlocking { alixGroup.members().size }, 3)
assertEquals(runBlocking { boGroup.members().size }, 3)

// All members also defaults remove to admin only now.
assertThrows(XMTPException::class.java) {
Expand All @@ -95,8 +95,8 @@ class GroupTest {
}
}

assertEquals(alixGroup.members().size, 3)
assertEquals(boGroup.members().size, 3)
assertEquals(runBlocking { alixGroup.members().size }, 3)
assertEquals(runBlocking { boGroup.members().size }, 3)

assertEquals(boGroup.permissionPolicySet().addMemberPolicy, PermissionOption.Allow)
assertEquals(alixGroup.permissionPolicySet().addMemberPolicy, PermissionOption.Allow)
Expand Down Expand Up @@ -135,31 +135,31 @@ class GroupTest {
alixGroup.sync()
}

assertEquals(alixGroup.members().size, 3)
assertEquals(boGroup.members().size, 3)
assertEquals(runBlocking { alixGroup.members().size }, 3)
assertEquals(runBlocking { boGroup.members().size }, 3)

assertThrows(XMTPException::class.java) {
runBlocking { alixGroup.removeMembers(listOf(caro.walletAddress)) }
}
runBlocking { boGroup.sync() }

assertEquals(alixGroup.members().size, 3)
assertEquals(boGroup.members().size, 3)
assertEquals(runBlocking { alixGroup.members().size }, 3)
assertEquals(runBlocking { boGroup.members().size }, 3)
runBlocking {
boGroup.removeMembers(listOf(caro.walletAddress))
alixGroup.sync()
}

assertEquals(alixGroup.members().size, 2)
assertEquals(boGroup.members().size, 2)
assertEquals(runBlocking { alixGroup.members().size }, 2)
assertEquals(runBlocking { boGroup.members().size }, 2)

assertThrows(XMTPException::class.java) {
runBlocking { alixGroup.addMembers(listOf(caro.walletAddress)) }
}
runBlocking { boGroup.sync() }

assertEquals(alixGroup.members().size, 2)
assertEquals(boGroup.members().size, 2)
assertEquals(runBlocking { alixGroup.members().size }, 2)
assertEquals(runBlocking { boGroup.members().size }, 2)

assertEquals(boGroup.permissionPolicySet().addMemberPolicy, PermissionOption.Admin)
assertEquals(alixGroup.permissionPolicySet().addMemberPolicy, PermissionOption.Admin)
Expand All @@ -183,7 +183,7 @@ class GroupTest {
)
}
assertEquals(
group.members().map { it.inboxId }.sorted(),
runBlocking { group.members().map { it.inboxId }.sorted() },
listOf(
caroClient.inboxId,
alixClient.inboxId,
Expand All @@ -200,7 +200,7 @@ class GroupTest {
)

assertEquals(
group.peerInboxIds().sorted(),
runBlocking { group.peerInboxIds().sorted() },
listOf(
caroClient.inboxId,
alixClient.inboxId,
Expand Down Expand Up @@ -238,7 +238,7 @@ class GroupTest {
val group = runBlocking { boClient.conversations.newGroup(listOf(alix.walletAddress)) }
runBlocking { group.addMembers(listOf(caro.walletAddress)) }
assertEquals(
group.members(boClient).map { it.inboxId }.sorted(),
runBlocking { group.members().map { it.inboxId }.sorted() },
listOf(
caroClient.inboxId,
alixClient.inboxId,
Expand All @@ -259,7 +259,7 @@ class GroupTest {
}
runBlocking { group.removeMembers(listOf(caro.walletAddress)) }
assertEquals(
group.members(boClient).map { it.inboxId }.sorted(),
runBlocking { group.members().map { it.inboxId }.sorted() },
listOf(
alixClient.inboxId,
boClient.inboxId
Expand Down Expand Up @@ -291,7 +291,7 @@ class GroupTest {
boGroup.sync()
}
assertEquals(
boGroup.members().map { it.inboxId }.sorted(),
runBlocking { boGroup.members().map { it.inboxId }.sorted() },
listOf(
alixClient.inboxId,
boClient.inboxId
Expand All @@ -303,7 +303,7 @@ class GroupTest {
val group = runBlocking { boClient.conversations.newGroup(listOf(alix.walletAddress)) }
runBlocking { group.addMembersByInboxId(listOf(caroClient.inboxId)) }
assertEquals(
group.members().map { it.inboxId }.sorted(),
runBlocking { group.members().map { it.inboxId }.sorted() },
listOf(
caroClient.inboxId,
alixClient.inboxId,
Expand All @@ -324,7 +324,7 @@ class GroupTest {
}
runBlocking { group.removeMembersByInboxId(listOf(caroClient.inboxId)) }
assertEquals(
group.members().map { it.inboxId }.sorted(),
runBlocking { group.members().map { it.inboxId }.sorted() },
listOf(
alixClient.inboxId,
boClient.inboxId
Expand Down Expand Up @@ -808,21 +808,21 @@ class GroupTest {
assert(!boClient.contacts.isInboxDenied(alixClient.inboxId))

boClient.contacts.allowInboxes(listOf(alixClient.inboxId))
var alixMember = boGroup.members(boClient).firstOrNull { it.inboxId == alixClient.inboxId }
var alixMember = boGroup.members().firstOrNull { it.inboxId == alixClient.inboxId }
assertEquals(alixMember!!.consentState, ConsentState.ALLOWED)

assert(boClient.contacts.isInboxAllowed(alixClient.inboxId))
assert(!boClient.contacts.isInboxDenied(alixClient.inboxId))

boClient.contacts.denyInboxes(listOf(alixClient.inboxId))
alixMember = boGroup.members(boClient).firstOrNull { it.inboxId == alixClient.inboxId }
alixMember = boGroup.members().firstOrNull { it.inboxId == alixClient.inboxId }
assertEquals(alixMember!!.consentState, ConsentState.DENIED)

assert(!boClient.contacts.isInboxAllowed(alixClient.inboxId))
assert(boClient.contacts.isInboxDenied(alixClient.inboxId))

boClient.contacts.allow(listOf(alixClient.address))
alixMember = boGroup.members(boClient).firstOrNull { it.inboxId == alixClient.inboxId }
alixMember = boGroup.members().firstOrNull { it.inboxId == alixClient.inboxId }
assertEquals(alixMember!!.consentState, ConsentState.ALLOWED)
assert(boClient.contacts.isInboxAllowed(alixClient.inboxId))
assert(!boClient.contacts.isInboxDenied(alixClient.inboxId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ sealed class Conversation {
}
}

suspend fun peerAddresses(): List<String> {
fun peerAddresses(): List<String> {
return when (this) {
is V1 -> listOf(conversationV1.peerAddress)
is V2 -> listOf(conversationV2.peerAddress)
is Group -> group.peerInboxIds()
is Group -> runBlocking { group.peerInboxIds() }
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package uniffi.xmtpv3.org.xmtp.android.library.libxmtp

import org.xmtp.android.library.toHex
import uniffi.xmtpv3.FfiInboxState

class InboxState(private val ffiInboxState: FfiInboxState) {
Expand All @@ -9,8 +8,8 @@ class InboxState(private val ffiInboxState: FfiInboxState) {
val addresses: List<String>
get() = ffiInboxState.accountAddresses

val installationIds: List<String>
get() = ffiInboxState.installationIds.map { it.toHex() }
val installations: List<Installation>
get() = ffiInboxState.installations.map { Installation(it) }

val recoveryAddress: String
get() = ffiInboxState.recoveryAddress
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package uniffi.xmtpv3.org.xmtp.android.library.libxmtp

import org.xmtp.android.library.toHex
import uniffi.xmtpv3.FfiInstallation
import java.util.Date

class Installation(private val ffiInstallation: FfiInstallation) {
val installationId: String
get() = ffiInstallation.id.toHex()
val createdAt: Date?
get() = ffiInstallation.clientTimestampNs?.let {
Date(it.toLong())
}
}

0 comments on commit 2b0532c

Please sign in to comment.