fix streaming when response and error present in response (#469)

This commit is contained in:
Vyacheslav
2024-05-08 12:43:29 +03:00
committed by GitHub
parent e2949ec151
commit 289dae92a2
3 changed files with 91 additions and 42 deletions

View File

@@ -1,5 +1,6 @@
package io.emeraldpay.dshackle.upstream.rpcclient.stream
import io.emeraldpay.dshackle.upstream.ChainCallError
import io.emeraldpay.dshackle.upstream.stream.AggregateResponse
import io.emeraldpay.dshackle.upstream.stream.Chunk
import io.emeraldpay.dshackle.upstream.stream.SingleResponse
@@ -71,6 +72,28 @@ class JsonRpcStreamParserTest {
.verify(Duration.ofSeconds(1))
}
@Test
fun `if first part has result field and error then single response`() {
val statusCode = 200
val response =
@Suppress("ktlint:standard:max-line-length")
"{\"id\": 2,\"result\": null, \"error\":{\"code\":-32000,\"message\":\"tracing failed: fee cap less than block base fee\"}}".toByteArray()
val stream: Flux<ByteArray> = Flux.just(response)
StepVerifier.create(streamParser.streamParse(statusCode, stream))
.expectNext(
SingleResponse(
"null".toByteArray(),
ChainCallError(
-32000,
"tracing failed: fee cap less than block base fee",
),
),
)
.expectComplete()
.verify(Duration.ofSeconds(1))
}
@ParameterizedTest
@MethodSource("dataStream")
fun `if big result then stream response`(