-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce easier invite/intro decoding (#57)
* add api client with grpc kotlin * easier invite intro decoding for conversation stream * fix up the linter
- Loading branch information
1 parent
045748a
commit 035a94c
Showing
2 changed files
with
57 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
library/src/test/java/org/xmtp/android/library/ConversationsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.xmtp.android.library | ||
|
||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
import org.xmtp.android.library.codecs.TextCodec | ||
import org.xmtp.android.library.messages.EnvelopeBuilder | ||
import org.xmtp.android.library.messages.InvitationV1 | ||
import org.xmtp.android.library.messages.MessageBuilder | ||
import org.xmtp.android.library.messages.MessageV1Builder | ||
import org.xmtp.android.library.messages.PrivateKeyBuilder | ||
import org.xmtp.android.library.messages.SealedInvitationBuilder | ||
import org.xmtp.android.library.messages.Topic | ||
import org.xmtp.android.library.messages.createRandom | ||
import org.xmtp.android.library.messages.getPublicKeyBundle | ||
import org.xmtp.android.library.messages.toPublicKeyBundle | ||
import org.xmtp.android.library.messages.walletAddress | ||
import java.util.Date | ||
|
||
class ConversationsTest { | ||
|
||
@Test | ||
fun testCanGetConversationFromIntroEnvelope() { | ||
val fixtures = fixtures() | ||
val client = fixtures.aliceClient | ||
val created = Date() | ||
val newWallet = PrivateKeyBuilder() | ||
val newClient = Client().create(account = newWallet, apiClient = fixtures.fakeApiClient) | ||
val message = MessageV1Builder.buildEncode(sender = newClient.privateKeyBundleV1, recipient = fixtures.aliceClient.v1keys.toPublicKeyBundle(), message = TextCodec().encode(content = "hello").toByteArray(), timestamp = created) | ||
val envelope = EnvelopeBuilder.buildFromTopic(topic = Topic.userIntro(client.address), timestamp = created, message = MessageBuilder.buildFromMessageV1(v1 = message).toByteArray()) | ||
val conversation = client.conversations.fromIntro(envelope = envelope) | ||
assertEquals(conversation.peerAddress, newWallet.address) | ||
assertEquals(conversation.createdAt.time, created.time) | ||
} | ||
|
||
@Test | ||
fun testCanGetConversationFromInviteEnvelope() { | ||
val fixtures = fixtures() | ||
val client = fixtures.aliceClient | ||
val created = Date() | ||
val newWallet = PrivateKeyBuilder() | ||
val newClient = Client().create(account = newWallet, apiClient = fixtures.fakeApiClient) | ||
val invitation = InvitationV1.newBuilder().build().createRandom(context = null) | ||
val sealed = SealedInvitationBuilder.buildFromV1(sender = newClient.keys, recipient = client.keys.getPublicKeyBundle(), created = created, invitation = invitation) | ||
val peerAddress = fixtures.alice.walletAddress | ||
val envelope = EnvelopeBuilder.buildFromTopic(topic = Topic.userInvite(peerAddress), timestamp = created, message = sealed.toByteArray()) | ||
val conversation = client.conversations.fromInvite(envelope = envelope) | ||
assertEquals(conversation.peerAddress, newWallet.address) | ||
assertEquals(conversation.createdAt.time, created.time) | ||
} | ||
} |