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

fix: Fix Date formatting for consent proofs #241

Merged
merged 2 commits into from
May 7, 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
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,9 @@ class ConversationTest {
(topic.equals(steveConversation.topic) || topic.equals(bobConversation.topic))
}
assertEquals(3, messages.size)
assertTrue(isSteveOrBobConversation(messages[0].topic))
assertTrue(isSteveOrBobConversation(messages[1].topic))
assertTrue(isSteveOrBobConversation(messages[2].topic))
assertTrue("isSteveOrBobConversation message 0", isSteveOrBobConversation(messages[0].topic))
assertTrue("isSteveOrBobConversation message 1", isSteveOrBobConversation(messages[1].topic))
assertTrue("isSteveOrBobConversation message 2", isSteveOrBobConversation(messages[2].topic))
}

@Test
Expand Down Expand Up @@ -790,27 +790,27 @@ class ConversationTest {
val isAllowed = bobConversation.consentState() == ConsentState.ALLOWED

// Conversations you start should start as allowed
assertTrue(isAllowed)
assertTrue(bobClient.contacts.isAllowed(alice.walletAddress))
assertTrue("Bob convo should be allowed", isAllowed)
assertTrue("Bob contacts should be allowed", bobClient.contacts.isAllowed(alice.walletAddress))

runBlocking {
bobClient.contacts.deny(listOf(alice.walletAddress))
bobClient.contacts.refreshConsentList()
}
val isDenied = bobConversation.consentState() == ConsentState.DENIED
assertEquals(bobClient.contacts.consentList.entries.size, 1)
assertTrue(isDenied)
assertTrue("Bob Conversation should be denied", isDenied)

val aliceConversation = runBlocking { aliceClient.conversations.list()[0] }
val isUnknown = aliceConversation.consentState() == ConsentState.UNKNOWN

// Conversations started with you should start as unknown
assertTrue(isUnknown)
assertTrue("Alice conversation should be unknown", isUnknown)

runBlocking { aliceClient.contacts.allow(listOf(bob.walletAddress)) }

val isBobAllowed = aliceConversation.consentState() == ConsentState.ALLOWED
assertTrue(isBobAllowed)
assertTrue("Bob should be allowed from alice conversation", isBobAllowed)

val aliceClient2 = Client().create(aliceWallet)
val aliceConversation2 = runBlocking { aliceClient2.conversations.list()[0] }
Expand All @@ -820,7 +820,7 @@ class ConversationTest {
// Allow state should sync across clients
val isBobAllowed2 = aliceConversation2.consentState() == ConsentState.ALLOWED

assertTrue(isBobAllowed2)
assertTrue("Bob should be allowed from conversation 2", isBobAllowed2)
}

@Test
Expand All @@ -830,13 +830,13 @@ class ConversationTest {
val isAllowed = bobConversation.consentState() == ConsentState.ALLOWED

// Conversations you start should start as allowed
assertTrue(isAllowed)
assertTrue("Bob convo should be allowed", isAllowed)

val aliceConversation = runBlocking { aliceClient.conversations.list()[0] }
val isUnknown = aliceConversation.consentState() == ConsentState.UNKNOWN

// Conversations you receive should start as unknown
assertTrue(isUnknown)
assertTrue("Alice convo should be unknown", isUnknown)

runBlocking {
aliceConversation.send(content = "hey bob")
Expand All @@ -845,7 +845,7 @@ class ConversationTest {
val isNowAllowed = aliceConversation.consentState() == ConsentState.ALLOWED

// Conversations you send a message to get marked as allowed
assertTrue(isNowAllowed)
assertTrue("Should now be allowed", isNowAllowed)
}

@Test
Expand All @@ -857,12 +857,12 @@ class ConversationTest {
bobClient.contacts.refreshConsentList()
Thread.sleep(1000)
assertEquals(bobClient.contacts.consentList.entries.size, 2)
assertTrue(bobConversation.consentState() == ConsentState.ALLOWED)
assertTrue(caroConversation.consentState() == ConsentState.ALLOWED)
assertTrue("Bob convo should be allowed", bobConversation.consentState() == ConsentState.ALLOWED)
assertTrue("Caro convo should be allowed", caroConversation.consentState() == ConsentState.ALLOWED)
bobClient.contacts.deny(listOf(alice.walletAddress, fixtures.caro.walletAddress))
assertEquals(bobClient.contacts.consentList.entries.size, 2)
assertTrue(bobConversation.consentState() == ConsentState.DENIED)
assertTrue(caroConversation.consentState() == ConsentState.DENIED)
assertTrue("Bob convo should be denied", bobConversation.consentState() == ConsentState.DENIED)
assertTrue("Caro convo should be denied", caroConversation.consentState() == ConsentState.DENIED)
}
}

Expand All @@ -880,13 +880,13 @@ class ConversationTest {
val preferenceList = Topic.preferenceList(validId).description

// check if validation of topics accepts all types
assertTrue(Topic.isValidTopic(privateStore))
assertTrue(Topic.isValidTopic(contact))
assertTrue(Topic.isValidTopic(userIntro))
assertTrue(Topic.isValidTopic(userInvite))
assertTrue(Topic.isValidTopic(directMessageV1))
assertTrue(Topic.isValidTopic(directMessageV2))
assertTrue(Topic.isValidTopic(preferenceList))
assertTrue("Private Store should be valid topic", Topic.isValidTopic(privateStore))
assertTrue("Contact should be valid topic", Topic.isValidTopic(contact))
assertTrue("User Intro should be valid topic", Topic.isValidTopic(userIntro))
assertTrue("userInvite should be valid topic", Topic.isValidTopic(userInvite))
assertTrue("directMessageV1 should be valid topic", Topic.isValidTopic(directMessageV1))
assertTrue("directMessageV2 should be valid topic", Topic.isValidTopic(directMessageV2))
assertTrue("preferenceList should be valid topic", Topic.isValidTopic(preferenceList))
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@ class ConversationsTest {
val alixConversation = alixConversations.find {
it.topic == boConversation.topic
}
assertNotNull(alixConversation)
assertNotNull("Alix Conversation should exist " + alixConversations.size, alixConversation)
// Commenting out for now, the signature being created is not valid
// val isAllowed = runBlocking { alixClient.contacts.isAllowed(boClient.address) }
// assertTrue(isAllowed)
val isAllowed = runBlocking { alixClient.contacts.isAllowed(boClient.address) }
assertTrue(isAllowed)
}

@Test
Expand Down Expand Up @@ -268,8 +268,8 @@ class ConversationsTest {
}
val alixConversations = runBlocking { alixClient.conversations.list() }
val alixConversation = alixConversations.find { it.topic == boConversation.topic }
assertNotNull(alixConversation)
assertNotNull("Alix conversation should exist" + alixConversations.size, alixConversation)
val isAllowed = runBlocking { alixClient.contacts.isAllowed(boClient.address) }
assertFalse(isAllowed)
assertFalse("Should not be allowed", isAllowed)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fun Signature.enableIdentityText(key: ByteArray): String =
("XMTP : Enable Identity\n" + "${key.toHex()}\n" + "\n" + "For more info: https://xmtp.org/signatures/")

fun Signature.consentProofText(peerAddress: String, timestamp: Long): String {
val formatter = SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss 'GMT'")
val formatter = SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'")
formatter.timeZone = TimeZone.getTimeZone("UTC")
val timestampString = formatter.format(timestamp)
return ("XMTP : Grant inbox consent to sender\n" + "\n" + "Current Time: ${timestampString}\n" + "From Address: ${peerAddress}\n" + "\n" + "For more info: https://xmtp.org/signatures/")
Expand Down
Loading