@@ -2,6 +2,7 @@ package org.xmtp.android.library
2
2
3
3
import androidx.test.ext.junit.runners.AndroidJUnit4
4
4
import com.google.protobuf.kotlin.toByteStringUtf8
5
+ import kotlinx.coroutines.runBlocking
5
6
import org.junit.Assert.assertEquals
6
7
import org.junit.Assert.assertTrue
7
8
import org.junit.Test
@@ -58,13 +59,16 @@ class CodecTest {
58
59
Client .register(codec = NumberCodec ())
59
60
val fixtures = fixtures()
60
61
val aliceClient = fixtures.aliceClient
61
- val aliceConversation =
62
+ val aliceConversation = runBlocking {
62
63
aliceClient.conversations.newConversation(fixtures.bob.walletAddress)
63
- aliceConversation.send(
64
- content = 3.14 ,
65
- options = SendOptions (contentType = NumberCodec ().contentType),
66
- )
67
- val messages = aliceConversation.messages()
64
+ }
65
+ runBlocking {
66
+ aliceConversation.send(
67
+ content = 3.14 ,
68
+ options = SendOptions (contentType = NumberCodec ().contentType),
69
+ )
70
+ }
71
+ val messages = runBlocking { aliceConversation.messages() }
68
72
assertEquals(messages.size, 1 )
69
73
if (messages.size == 1 ) {
70
74
val content: Double? = messages[0 ].content()
@@ -78,15 +82,18 @@ class CodecTest {
78
82
Client .register(codec = CompositeCodec ())
79
83
val fixtures = fixtures()
80
84
val aliceClient = fixtures.aliceClient
81
- val aliceConversation =
85
+ val aliceConversation = runBlocking {
82
86
aliceClient.conversations.newConversation(fixtures.bob.walletAddress)
87
+ }
83
88
val textContent = TextCodec ().encode(content = " hiya" )
84
89
val source = DecodedComposite (encodedContent = textContent)
85
- aliceConversation.send(
86
- content = source,
87
- options = SendOptions (contentType = CompositeCodec ().contentType),
88
- )
89
- val messages = aliceConversation.messages()
90
+ runBlocking {
91
+ aliceConversation.send(
92
+ content = source,
93
+ options = SendOptions (contentType = CompositeCodec ().contentType),
94
+ )
95
+ }
96
+ val messages = runBlocking { aliceConversation.messages() }
90
97
val decoded: DecodedComposite ? = messages[0 ].content()
91
98
assertEquals(" hiya" , decoded?.content())
92
99
}
@@ -97,8 +104,9 @@ class CodecTest {
97
104
Client .register(codec = NumberCodec ())
98
105
val fixtures = fixtures()
99
106
val aliceClient = fixtures.aliceClient!!
100
- val aliceConversation =
107
+ val aliceConversation = runBlocking {
101
108
aliceClient.conversations.newConversation(fixtures.bob.walletAddress)
109
+ }
102
110
val textContent = TextCodec ().encode(content = " sup" )
103
111
val numberContent = NumberCodec ().encode(content = 3.14 )
104
112
val source = DecodedComposite (
@@ -107,11 +115,13 @@ class CodecTest {
107
115
DecodedComposite (parts = listOf (DecodedComposite (encodedContent = numberContent))),
108
116
),
109
117
)
110
- aliceConversation.send(
111
- content = source,
112
- options = SendOptions (contentType = CompositeCodec ().contentType),
113
- )
114
- val messages = aliceConversation.messages()
118
+ runBlocking {
119
+ aliceConversation.send(
120
+ content = source,
121
+ options = SendOptions (contentType = CompositeCodec ().contentType),
122
+ )
123
+ }
124
+ val messages = runBlocking { aliceConversation.messages() }
115
125
val decoded: DecodedComposite ? = messages[0 ].content()
116
126
val part1 = decoded!! .parts[0 ]
117
127
val part2 = decoded.parts[1 ].parts[0 ]
@@ -124,14 +134,17 @@ class CodecTest {
124
134
val codec = NumberCodec ()
125
135
Client .register(codec = codec)
126
136
val fixtures = fixtures()
127
- val aliceClient = fixtures.aliceClient!!
128
- val aliceConversation =
137
+ val aliceClient = fixtures.aliceClient
138
+ val aliceConversation = runBlocking {
129
139
aliceClient.conversations.newConversation(fixtures.bob.walletAddress)
130
- aliceConversation.send(
131
- content = 3.14 ,
132
- options = SendOptions (contentType = codec.contentType),
133
- )
134
- val messages = aliceConversation.messages()
140
+ }
141
+ runBlocking {
142
+ aliceConversation.send(
143
+ content = 3.14 ,
144
+ options = SendOptions (contentType = codec.contentType),
145
+ )
146
+ }
147
+ val messages = runBlocking { aliceConversation.messages() }
135
148
assert (messages.isNotEmpty())
136
149
137
150
val message = MessageV2Builder .buildEncode(
@@ -156,12 +169,14 @@ class CodecTest {
156
169
repeat(5 ) {
157
170
val account = PrivateKeyBuilder ()
158
171
val client = Client ().create(account, clientOptions)
159
- conversations.add(
160
- alixClient.conversations.newConversation(
161
- client.address,
162
- context = InvitationV1ContextBuilder .buildFromConversation(conversationId = " hi" )
172
+ runBlocking {
173
+ conversations.add(
174
+ alixClient.conversations.newConversation(
175
+ client.address,
176
+ context = InvitationV1ContextBuilder .buildFromConversation(conversationId = " hi" )
177
+ )
163
178
)
164
- )
179
+ }
165
180
}
166
181
167
182
val thirtyDayPeriodsSinceEpoch = Instant .now().epochSecond / 60 / 60 / 24 / 30
0 commit comments