@@ -21,29 +21,29 @@ import io.emeraldpay.api.proto.BlockchainGrpc
2121import io.emeraldpay.api.proto.BlockchainOuterClass
2222import io.emeraldpay.etherjar.rpc.Conversion
2323import io.emeraldpay.etherjar.rpc.RpcCall
24- import io.emeraldpay.etherjar.rpc.ktor .CoroutineBatchItem
24+ import io.emeraldpay.etherjar.rpc.kotlin .CoroutineBatchItem
2525import io.grpc.stub.StreamObserver
2626import io.kotest.core.spec.style.ShouldSpec
2727import io.kotest.matchers.shouldBe
2828import io.kotest.matchers.shouldNotBe
2929import kotlinx.coroutines.test.runTest
3030
3131class EmeraldKotlinTransportTest : ShouldSpec ({
32-
32+
3333 should("convert to correct Protobuf ") {
3434 val transport = EmeraldKotlinTransport .newBuilder()
3535 .connectTo("localhost:2449")
3636 .chain(Chain .ETHEREUM )
3737 .build()
38-
38+
3939 val items = listOf(
4040 CoroutineBatchItem (RpcCall .create("eth_test", Int ::class.java), 1),
4141 CoroutineBatchItem (RpcCall .create("eth_test2", Int ::class.java, listOf("test", 14)), 2)
4242 )
43-
43+
4444 val idMapping = mutableMapOf<Int , CoroutineBatchItem <* , * >>()
4545 val request = transport.convert(items, idMapping)
46-
46+
4747 val expected = BlockchainOuterClass .NativeCallRequest .newBuilder()
4848 .setChainValue(Chain .ETHEREUM .id)
4949 .addItems(
@@ -59,33 +59,33 @@ class EmeraldKotlinTransportTest : ShouldSpec({
5959 .setPayload(ByteString .copyFromUtf8("[\"test\",14]"))
6060 )
6161 .build()
62-
62+
6363 request shouldBe expected
6464 transport.close()
6565 }
66-
66+
6767 should("throw exception on invalid param") {
6868 val transport = EmeraldKotlinTransport .newBuilder()
6969 .connectTo("localhost:2449")
7070 .chain(Chain .ETHEREUM )
7171 .build()
72-
72+
7373 val items = listOf(
7474 CoroutineBatchItem (RpcCall .create("eth_test", Int ::class.java, listOf(Any ())), 1)
7575 )
76-
76+
7777 val idMapping = mutableMapOf<Int , CoroutineBatchItem <* , * >>()
78-
78+
7979 try {
8080 transport.convert(items, idMapping)
8181 assert (false) { " Should have thrown exception" }
8282 } catch (e: Exception ) {
8383 // Expected
8484 }
85-
85+
8686 transport.close()
8787 }
88-
88+
8989 should("use selector") {
9090 val selector = BlockchainOuterClass .Selector .newBuilder()
9191 .setAndSelector(
@@ -106,20 +106,20 @@ class EmeraldKotlinTransportTest : ShouldSpec({
106106 )
107107 )
108108 .build()
109-
109+
110110 val transport = EmeraldKotlinTransport .newBuilder()
111111 .connectTo("localhost:2449")
112112 .chain(Chain .ETHEREUM )
113113 .build()
114114 .copyWithSelector(selector)
115-
115+
116116 val items = listOf(
117117 CoroutineBatchItem (RpcCall .create("eth_test", Int ::class.java, listOf("hello")), 1)
118118 )
119-
119+
120120 val idMapping = mutableMapOf<Int , CoroutineBatchItem <* , * >>()
121121 val request = transport.convert(items, idMapping)
122-
122+
123123 val expected = BlockchainOuterClass .NativeCallRequest .newBuilder()
124124 .setChainValue(Chain .ETHEREUM .id)
125125 .setSelector(selector)
@@ -130,25 +130,25 @@ class EmeraldKotlinTransportTest : ShouldSpec({
130130 .setPayload(ByteString .copyFromUtf8("[\"hello\"]"))
131131 )
132132 .build()
133-
133+
134134 request shouldBe expected
135135 transport.close()
136136 }
137-
137+
138138 should("redefine chain") {
139139 val transport = EmeraldKotlinTransport .newBuilder()
140140 .connectTo("localhost:2449")
141141 .chain(Chain .ETHEREUM )
142142 .build()
143143 .copyForChain(Chain .ETHEREUM_CLASSIC )
144-
144+
145145 val items = listOf(
146146 CoroutineBatchItem (RpcCall .create("eth_test", Int ::class.java), 1)
147147 )
148-
148+
149149 val idMapping = mutableMapOf<Int , CoroutineBatchItem <* , * >>()
150150 val request = transport.convert(items, idMapping)
151-
151+
152152 val expected = BlockchainOuterClass .NativeCallRequest .newBuilder()
153153 .setChainValue(Chain .ETHEREUM_CLASSIC .id)
154154 .addItems(
@@ -158,23 +158,23 @@ class EmeraldKotlinTransportTest : ShouldSpec({
158158 .setPayload(ByteString .copyFromUtf8("[]"))
159159 )
160160 .build()
161-
161+
162162 request shouldBe expected
163163 transport.close()
164164 }
165-
165+
166166 should("make actual call") {
167167 runTest {
168168 var actualRequest : BlockchainOuterClass .NativeCallRequest ? = null
169-
169+
170170 val mockImpl = object : BlockchainGrpc .BlockchainImplBase () {
171171 override fun nativeCall(
172172 request: BlockchainOuterClass .NativeCallRequest ,
173173 responseObserver: StreamObserver <BlockchainOuterClass .NativeCallReplyItem >
174174 ) {
175175 actualRequest = request
176176 println("requested $request")
177-
177+
178178 responseObserver.onNext(
179179 BlockchainOuterClass .NativeCallReplyItem .newBuilder()
180180 .setId(1)
@@ -185,32 +185,32 @@ class EmeraldKotlinTransportTest : ShouldSpec({
185185 responseObserver.onCompleted()
186186 }
187187 }
188-
188+
189189 val channel = MockServer .createChannelFor(mockImpl)
190190 val transport = EmeraldKotlinTransport .newBuilder()
191191 .connectUsing(channel)
192192 .chain(Chain .ETHEREUM )
193193 .build()
194-
194+
195195 val items = listOf(
196196 CoroutineBatchItem (
197197 RpcCall .create("eth_test").converted(Long ::class.java, Conversion .asLong),
198198 1
199199 )
200200 )
201-
201+
202202 val result = transport.execute(items)
203-
203+
204204 result.size shouldBe 1
205205 result[0 ].error shouldBe null
206206 result[0 ].value shouldBe 0xab5461ca4b100L
207-
207+
208208 actualRequest shouldNotBe null
209-
209+
210210 transport.close()
211211 }
212212 }
213-
213+
214214 should("handle error response") {
215215 runTest {
216216 val mockImpl = object : BlockchainGrpc .BlockchainImplBase () {
@@ -228,24 +228,24 @@ class EmeraldKotlinTransportTest : ShouldSpec({
228228 responseObserver.onCompleted()
229229 }
230230 }
231-
231+
232232 val channel = MockServer .createChannelFor(mockImpl)
233233 val transport = EmeraldKotlinTransport .newBuilder()
234234 .connectUsing(channel)
235235 .chain(Chain .ETHEREUM )
236236 .build()
237-
237+
238238 val items = listOf(
239239 CoroutineBatchItem (RpcCall .create("eth_test", String ::class.java), 1)
240240 )
241-
241+
242242 val result = transport.execute(items)
243-
243+
244244 result.size shouldBe 1
245245 result[0 ].error shouldNotBe null
246246 result[0 ].error!!.message shouldBe " RPC Error -32603: Test error"
247-
247+
248248 transport.close()
249249 }
250250 }
251- })
251+ })
0 commit comments