Skip to content

Commit

Permalink
fix: Fix Date formatting for consent proofs (#241)
Browse files Browse the repository at this point in the history
* fix: Fix Date formatting

Fix date formatting

* liniting

---------

Co-authored-by: Alex Risch <[email protected]>
  • Loading branch information
alexrisch and Alex Risch authored May 7, 2024
1 parent 38ffc03 commit d72b7b4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
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

0 comments on commit d72b7b4

Please sign in to comment.