Handle trace and debug bounds (#570)

This commit is contained in:
KirillPamPam
2024-09-16 17:42:37 +04:00
committed by GitHub
parent f916f0a682
commit f739920ceb
11 changed files with 166 additions and 35 deletions

View File

@@ -0,0 +1,52 @@
package io.emeraldpay.dshackle.upstream.error
import io.emeraldpay.dshackle.upstream.ChainRequest
import io.emeraldpay.dshackle.upstream.Upstream
import io.emeraldpay.dshackle.upstream.lowerbound.LowerBoundType
import io.emeraldpay.dshackle.upstream.rpcclient.ListParams
import org.junit.jupiter.api.Test
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.Arguments.of
import org.junit.jupiter.params.provider.MethodSource
import org.mockito.Mockito.mock
import org.mockito.kotlin.verify
class EthereumTraceLowerBoundErrorHandlerTest {
@ParameterizedTest
@MethodSource("requests")
fun `update lower bound`(request: ChainRequest) {
val upstream = mock<Upstream>()
val handler = EthereumTraceLowerBoundErrorHandler
handler.handle(upstream, request, "missing trie node d5648cc9aef48154159d53800f2f")
verify(upstream).updateLowerBound(213229736, LowerBoundType.TRACE)
}
@Test
fun `update lower bound base on regexp`() {
val upstream = mock<Upstream>()
val handler = EthereumTraceLowerBoundErrorHandler
handler.handle(upstream, ChainRequest("trace_block", ListParams("0xCB5A0A8")), "block #1 not found")
verify(upstream).updateLowerBound(213229736, LowerBoundType.TRACE)
}
companion object {
@JvmStatic
fun requests(): List<Arguments> =
listOf(
of(ChainRequest("trace_block", ListParams("0xCB5A0A8"))),
of(ChainRequest("arbtrace_block", ListParams("0xCB5A0A8"))),
of(ChainRequest("debug_traceBlockByNumber", ListParams("0xCB5A0A8", mapOf("tracer" to "tracer")))),
of(ChainRequest("trace_callMany", ListParams(arrayOf(mapOf("val" to 1)), "0xCB5A0A8"))),
of(ChainRequest("arbtrace_callMany", ListParams(arrayOf(mapOf("val" to 1)), "0xCB5A0A8"))),
of(ChainRequest("debug_traceCall", ListParams(mapOf("val" to 1), "0xCB5A0A8", mapOf("val" to 1)))),
of(ChainRequest("trace_call", ListParams(mapOf("val" to 1), arrayOf(mapOf("val" to 1)), "0xCB5A0A8"))),
of(ChainRequest("arbtrace_call", ListParams(mapOf("val" to 1), arrayOf(mapOf("val" to 1)), "0xCB5A0A8"))),
)
}
}

View File

@@ -86,6 +86,7 @@ class RecursiveLowerBoundServiceTest {
.expectSubscription()
.expectNoEvent(Duration.ofSeconds(15))
.expectNextMatches { it.lowerBound == 17964844L && it.type == LowerBoundType.STATE }
.expectNextMatches { it.lowerBound == 17964844L && it.type == LowerBoundType.TRACE }
.expectNextMatches { it.lowerBound == 17964844L && it.type == LowerBoundType.BLOCK }
.expectNextMatches { it.lowerBound == 17964844L && it.type == LowerBoundType.TX }
.expectNextMatches { it.lowerBound == 17964844L && it.type == LowerBoundType.LOGS }
@@ -97,6 +98,7 @@ class RecursiveLowerBoundServiceTest {
.hasSameElementsAs(
listOf(
LowerBoundData(17964844L, LowerBoundType.STATE),
LowerBoundData(17964844L, LowerBoundType.TRACE),
LowerBoundData(17964844L, LowerBoundType.BLOCK),
LowerBoundData(17964844L, LowerBoundType.TX),
LowerBoundData(17964844L, LowerBoundType.LOGS),