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

group preference actions #180

Merged
merged 14 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 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
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)
Comment on lines +432 to +434
Copy link
Contributor

@nplasterer nplasterer Feb 21, 2024

Choose a reason for hiding this comment

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

I assumed that this test should fail now since the default is allow on newGroup? Possibly do you need to call refreshConsentList() to get the latest results.


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
Loading