Skip to content

Commit

Permalink
Create BroadcastReader based on quorum (#424)
Browse files Browse the repository at this point in the history
  • Loading branch information
KirillPamPam authored Feb 21, 2024
1 parent b23a5dc commit 8f0700a
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.emeraldpay.dshackle.reader

import io.emeraldpay.dshackle.quorum.BroadcastQuorum
import io.emeraldpay.dshackle.quorum.CallQuorum
import io.emeraldpay.dshackle.quorum.MaximumValueQuorum
import io.emeraldpay.dshackle.quorum.QuorumRpcReader
import io.emeraldpay.dshackle.reader.RpcReader.Result
import io.emeraldpay.dshackle.upstream.Multistream
Expand Down Expand Up @@ -65,7 +67,7 @@ interface RpcReaderFactory {

class Default : RpcReaderFactory {
override fun create(data: RpcReaderData): RpcReader {
if (data.method == "eth_sendRawTransaction" || data.method == "eth_getTransactionCount") {
if (data.quorum is MaximumValueQuorum || data.quorum is BroadcastQuorum) {
return BroadcastReader(data.multistream.getAll(), data.matcher, data.signer, data.quorum, data.tracer)
}
val apis = data.multistream.getApiSource(data.matcher)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package io.emeraldpay.dshackle.reader

import io.emeraldpay.dshackle.quorum.BroadcastQuorum
import io.emeraldpay.dshackle.quorum.MaximumValueQuorum
import io.emeraldpay.dshackle.upstream.Multistream
import io.emeraldpay.dshackle.upstream.Selector
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.MethodSource
import org.mockito.kotlin.mock
import org.springframework.cloud.sleuth.Tracer

class RpcReaderFactoryTest {
private val defaultFactory = RpcReaderFactory.Default()

@ParameterizedTest
@MethodSource("data")
fun `create BroadcastReader for MaximumValueQuorum and BroadcastQuorum`(
rpcReaderData: RpcReaderFactory.RpcReaderData,
) {
val reader = defaultFactory.create(rpcReaderData)

assertTrue(reader is BroadcastReader)
}

companion object {
private val ms = mock<Multistream>()
private val tracer = mock<Tracer>()

@JvmStatic
fun data(): List<Arguments> {
return listOf(
Arguments.of(
RpcReaderFactory.RpcReaderData(
ms,
"method",
Selector.empty,
MaximumValueQuorum(),
null,
tracer,
),
),
Arguments.of(
RpcReaderFactory.RpcReaderData(
ms,
"method",
Selector.empty,
BroadcastQuorum(),
null,
tracer,
),
),
)
}
}
}

0 comments on commit 8f0700a

Please sign in to comment.