Skip to content

Commit

Permalink
group preference actions (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
tuddman authored Feb 21, 2024
1 parent 9f81f85 commit e1eec1d
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 79 deletions.
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ dependencies {
implementation 'org.web3j:crypto:5.0.0'
implementation "net.java.dev.jna:jna:5.13.0@aar"
api 'com.google.protobuf:protobuf-kotlin-lite:3.22.3'
api 'org.xmtp:proto-kotlin:3.40.1'
api 'org.xmtp:proto-kotlin:3.43.2'

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'app.cash.turbine:turbine:0.12.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class ContactsTest {
fun testNormalizesAddresses() {
val fixtures = fixtures()
fixtures.bobClient.ensureUserContactPublished()
val bobAddressLowercased = fixtures.bobClient.address?.lowercase()
val bobContact = fixtures.aliceClient.getUserContact(peerAddress = bobAddressLowercased!!)
val bobAddressLowerCased = fixtures.bobClient.address.lowercase()
val bobContact = fixtures.aliceClient.getUserContact(peerAddress = bobAddressLowerCased)
assert(bobContact != null)
}

Expand Down Expand Up @@ -54,7 +54,7 @@ class ContactsTest {
}

@Test
fun testBlockAddress() {
fun testDenyAddress() {
val fixtures = fixtures()

val contacts = fixtures.bobClient.contacts
Expand Down
74 changes: 62 additions & 12 deletions library/src/androidTest/java/org/xmtp/android/library/GroupTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ import uniffi.xmtpv3.GroupPermissions

@RunWith(AndroidJUnit4::class)
class GroupTest {
lateinit var fakeApiClient: FakeApiClient
lateinit var alixWallet: PrivateKeyBuilder
lateinit var boWallet: PrivateKeyBuilder
lateinit var alix: PrivateKey
lateinit var alixClient: Client
lateinit var bo: PrivateKey
lateinit var boClient: Client
lateinit var caroWallet: PrivateKeyBuilder
lateinit var caro: PrivateKey
lateinit var caroClient: Client
lateinit var fixtures: Fixtures
private lateinit var fakeApiClient: FakeApiClient
private lateinit var alixWallet: PrivateKeyBuilder
private lateinit var boWallet: PrivateKeyBuilder
private lateinit var alix: PrivateKey
private lateinit var alixClient: Client
private lateinit var bo: PrivateKey
private lateinit var boClient: Client
private lateinit var caroWallet: PrivateKeyBuilder
private lateinit var caro: PrivateKey
private lateinit var caroClient: Client
private lateinit var fixtures: Fixtures

@Before
fun setUp() {
Expand Down Expand Up @@ -99,6 +99,9 @@ class GroupTest {
assert(boGroup.id.isNotEmpty())
assert(alixGroup.id.isNotEmpty())

assertEquals(boClient.contacts.consentList.groupState(boGroup.id), ConsentState.ALLOWED)
assertEquals(alixClient.contacts.consentList.groupState(alixGroup.id), ConsentState.UNKNOWN)

boGroup.addMembers(listOf(caro.walletAddress))
runBlocking { alixGroup.sync() }
assertEquals(alixGroup.memberAddresses().size, 3)
Expand Down Expand Up @@ -239,7 +242,7 @@ class GroupTest {

@Test
fun testCannotSendMessageToGroupMemberNotOnV3() {
var fakeApiClient = FakeApiClient()
val fakeApiClient = FakeApiClient()
val chuxAccount = PrivateKeyBuilder()
val chux: PrivateKey = chuxAccount.getPrivateKey()
val chuxClient: Client = Client().create(account = chuxAccount, apiClient = fakeApiClient)
Expand All @@ -263,6 +266,16 @@ class GroupTest {
}
}

@Test
fun testGroupStartsWithAllowedState() {
val group = boClient.conversations.newGroup(listOf(alix.walletAddress))
group.send("howdy")
group.send("gm")
runBlocking { group.sync() }
assert(boClient.contacts.isGroupAllowed(group.id))
assertEquals(boClient.contacts.consentList.groupState(group.id), ConsentState.ALLOWED)
}

@Test
fun testCanSendMessageToGroup() {
val group = boClient.conversations.newGroup(listOf(alix.walletAddress))
Expand Down Expand Up @@ -406,4 +419,41 @@ class GroupTest {
assertEquals(conversation.topic, awaitItem().topic)
}
}

@Test
fun testCanAllowGroup() {
val group = boClient.conversations.newGroup(
listOf(
alix.walletAddress,
caro.walletAddress
)
)

var result = boClient.contacts.isGroupAllowed(group.id)

assert(!result)

boClient.contacts.allowGroup(listOf(group.id))

result = boClient.contacts.isGroupAllowed(group.id)
assert(result)
}

@Test
fun testCanDenyGroup() {
val group = boClient.conversations.newGroup(
listOf(
alix.walletAddress,
caro.walletAddress
)
)
var result = boClient.contacts.isGroupAllowed(group.id)

assert(!result)

boClient.contacts.denyGroup(listOf(group.id))

result = boClient.contacts.isGroupDenied(group.id)
assert(result)
}
}
Loading

0 comments on commit e1eec1d

Please sign in to comment.