Skip to content

Commit

Permalink
try to figure out how to resubscribe to the callback
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Jun 28, 2024
1 parent 7550a1d commit ab7293a
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 222 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,6 @@ class ContactsTest {
assertEquals(contactBundle?.walletAddress, fixtures.bob.walletAddress)
}

@Test
fun testCachesContacts() {
val fixtures = fixtures()
runBlocking { fixtures.bobClient.ensureUserContactPublished() }
// Look up the first time
fixtures.aliceClient.contacts.find(fixtures.bob.walletAddress)
fixtures.fakeApiClient.assertNoQuery {
val contactBundle = fixtures.aliceClient.contacts.find(fixtures.bob.walletAddress)
assertEquals(contactBundle?.walletAddress, fixtures.bob.walletAddress)
}
assert(fixtures.aliceClient.contacts.has(fixtures.bob.walletAddress))
}

@Test
fun testAllowAddress() {
val fixtures = fixtures()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import java.util.Date

@RunWith(AndroidJUnit4::class)
class ConversationTest {
lateinit var fakeApiClient: FakeApiClient
lateinit var aliceWallet: PrivateKeyBuilder
lateinit var bobWallet: PrivateKeyBuilder
lateinit var alice: PrivateKey
Expand All @@ -65,7 +64,6 @@ class ConversationTest {
alice = fixtures.alice
bobWallet = fixtures.bobAccount
bob = fixtures.bob
fakeApiClient = fixtures.fakeApiClient
aliceClient = fixtures.aliceClient
bobClient = fixtures.bobClient
}
Expand Down Expand Up @@ -123,14 +121,7 @@ class ConversationTest {
runBlocking { aliceClient.conversations.newConversation(bob.walletAddress) }
assertEquals(conversation.peerAddress, bob.walletAddress)
assertEquals(conversation.createdAt, someTimeAgo)
val existingMessages = fakeApiClient.published.size
conversation = runBlocking { bobClient.conversations.newConversation(alice.walletAddress) }

assertEquals(
"published more messages when we shouldn't have",
existingMessages,
fakeApiClient.published.size,
)
assertEquals(conversation.peerAddress, alice.walletAddress)
assertEquals(conversation.createdAt, someTimeAgo)
}
Expand All @@ -144,14 +135,6 @@ class ConversationTest {
)
}
var conversation: Conversation? = null
fakeApiClient.assertNoPublish {
runBlocking {
conversation = bobClient.conversations.newConversation(
alice.walletAddress,
context = InvitationV1ContextBuilder.buildFromConversation("http://example.com/2"),
)
}
}
assertEquals(
"made new conversation instead of using existing one",
conversation!!.topic,
Expand Down Expand Up @@ -408,15 +391,6 @@ class ConversationTest {
}
}

@Test
fun testCanUseCachedConversation() {
runBlocking { bobClient.conversations.newConversation(alice.walletAddress) }

fakeApiClient.assertNoQuery {
runBlocking { bobClient.conversations.newConversation(alice.walletAddress) }
}
}

@Test
@Ignore("Rust seems to be Flaky with V1")
fun testCanPaginateV1Messages() {
Expand Down Expand Up @@ -496,9 +470,18 @@ class ConversationTest {
(topic.equals(steveConversation.topic) || topic.equals(bobConversation.topic))
}
assertEquals(3, messages.size)
assertTrue("isSteveOrBobConversation message 0", isSteveOrBobConversation(messages[0].topic))
assertTrue("isSteveOrBobConversation message 1", isSteveOrBobConversation(messages[1].topic))
assertTrue("isSteveOrBobConversation message 2", 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 @@ -778,7 +761,6 @@ class ConversationTest {
}.build()

val client = Client().create(account = PrivateKeyBuilder(key))
assertEquals(client.apiClient.environment, XMTPEnvironment.DEV)
runBlocking {
val conversations = client.conversations.list()
assertEquals(1, conversations.size)
Expand Down Expand Up @@ -827,7 +809,10 @@ class ConversationTest {
val isAllowed = bobConversation.consentState() == ConsentState.ALLOWED
// Conversations you start should start as allowed
assertTrue("Bob convo should be allowed", isAllowed)
assertTrue("Bob contacts should be allowed", bobClient.contacts.isAllowed(alice.walletAddress))
assertTrue(
"Bob contacts should be allowed",
bobClient.contacts.isAllowed(alice.walletAddress)
)

runBlocking {
bobClient.contacts.deny(listOf(alice.walletAddress))
Expand Down Expand Up @@ -896,12 +881,24 @@ class ConversationTest {
bobClient.contacts.refreshConsentList()
Thread.sleep(1000)
assertEquals(bobClient.contacts.consentList.entries.size, 2)
assertTrue("Bob convo should be allowed", bobConversation.consentState() == ConsentState.ALLOWED)
assertTrue("Caro convo should be allowed", 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("Bob convo should be denied", bobConversation.consentState() == ConsentState.DENIED)
assertTrue("Caro convo should be denied", 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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import java.util.Date

@RunWith(AndroidJUnit4::class)
class ConversationsTest {
lateinit var fakeApiClient: FakeApiClient
lateinit var alixWallet: PrivateKeyBuilder
lateinit var boWallet: PrivateKeyBuilder
lateinit var alix: PrivateKey
Expand All @@ -53,7 +52,6 @@ class ConversationsTest {
alix = fixtures.alice
boWallet = fixtures.bobAccount
bo = fixtures.bob
fakeApiClient = fixtures.fakeApiClient
alixClient = fixtures.aliceClient
boClient = fixtures.bobClient
caroClient = fixtures.caroClient
Expand Down Expand Up @@ -128,7 +126,7 @@ class ConversationsTest {
runBlocking { boConversation.send(text = "Message $i") }
sleep(1000)
}
assertEquals(allMessages.size, 5)
assertEquals(5, allMessages.size)

val caroConversation =
runBlocking { caroClient.conversations.newConversation(alixClient.address) }
Expand All @@ -139,7 +137,7 @@ class ConversationsTest {
sleep(1000)
}

assertEquals(allMessages.size, 10)
assertEquals(10, allMessages.size)

job.cancel()

Expand All @@ -158,7 +156,7 @@ class ConversationsTest {
sleep(1000)
}

assertEquals(allMessages.size, 15)
assertEquals(15, allMessages.size)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class InvitationTest {
}.build()

val client = Client().create(account = PrivateKeyBuilder(key))
Assert.assertEquals(client.apiClient.environment, XMTPEnvironment.DEV)
val conversations = runBlocking { client.conversations.list() }
assertEquals(1, conversations.size)
val message = runBlocking { conversations[0].messages().firstOrNull() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class LocalInstrumentedTest {
)
)
val client = Client().create(aliceWallet, clientOptions)
assertEquals(XMTPEnvironment.LOCAL, client.apiClient.environment)
runBlocking {
client.publishUserContact()
}
Expand All @@ -71,7 +70,6 @@ class LocalInstrumentedTest {
)
}
val api = GRPCApiClient(
environment = XMTPEnvironment.LOCAL,
rustV2Client = v2Client
)
api.setAuthToken(authToken)
Expand Down Expand Up @@ -107,7 +105,6 @@ class LocalInstrumentedTest {
)
}
val api = GRPCApiClient(
environment = XMTPEnvironment.LOCAL,
rustV2Client = v2Client
)
api.setAuthToken(authToken)
Expand All @@ -126,7 +123,6 @@ class LocalInstrumentedTest {
val clientOptions =
ClientOptions(api = ClientOptions.Api(env = XMTPEnvironment.LOCAL, isSecure = false))
val client = Client().create(account = aliceWallet, options = clientOptions)
assertEquals(XMTPEnvironment.LOCAL, client.apiClient.environment)
val contact = client.getUserContact(peerAddress = aliceWallet.address)
assertEquals(
contact?.v2?.keyBundle?.identityKey?.secp256K1Uncompressed,
Expand Down Expand Up @@ -774,7 +770,6 @@ class LocalInstrumentedTest {
)
}
val api = GRPCApiClient(
environment = XMTPEnvironment.LOCAL,
rustV2Client = v2Client
)
api.setAuthToken(authToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ class MessageTest {
}.build()

val client = Client().create(account = PrivateKeyBuilder(key))
assertEquals(client.apiClient.environment, XMTPEnvironment.DEV)
runBlocking {
val convo = client.conversations.list()[0]
val message = convo.messages()[0]
Expand Down Expand Up @@ -196,7 +195,6 @@ class MessageTest {
}.build()

val client = Client().create(account = PrivateKeyBuilder(key))
assertEquals(client.apiClient.environment, XMTPEnvironment.DEV)
runBlocking {
val convo = client.conversations.list()[0]
convo.send(
Expand Down Expand Up @@ -234,7 +232,6 @@ class MessageTest {
}.build()
}.build()
val client = Client().create(account = PrivateKeyBuilder(key))
assertEquals(client.apiClient.environment, XMTPEnvironment.DEV)
val conversations = runBlocking { client.conversations.list() }
assertEquals(201, conversations.size)
}
Expand Down
Loading

0 comments on commit ab7293a

Please sign in to comment.