Upstream configuration improvement: (#149)

- now we can specify connector mode for better fine tuning of connection
This commit is contained in:
a10zn8
2023-02-27 14:22:50 +05:00
committed by GitHub
parent 1ec3d44484
commit 00a1490726
14 changed files with 220 additions and 32 deletions

View File

@@ -0,0 +1,61 @@
package io.emeraldpay.dshackle.config
import io.emeraldpay.dshackle.upstream.ethereum.connectors.EthereumConnectorFactory.ConnectorMode
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.MethodSource
import java.net.URI
import java.util.stream.Stream
internal class UpstreamsConfigTest {
companion object {
@JvmStatic
fun data(): Stream<Arguments> {
return Stream.of(
Arguments.of(
UpstreamsConfig.EthereumConnection(),
ConnectorMode.RPC_ONLY
),
Arguments.of(
UpstreamsConfig.EthereumConnection()
.apply {
ws = UpstreamsConfig.WsEndpoint(URI("ws://localhost:8546"))
},
ConnectorMode.WS_ONLY
),
Arguments.of(
UpstreamsConfig.EthereumConnection()
.apply {
preferHttp = true
ws = UpstreamsConfig.WsEndpoint(URI("ws://localhost:8546"))
},
ConnectorMode.RPC_REQUESTS_WITH_MIXED_HEAD
),
Arguments.of(
UpstreamsConfig.EthereumConnection()
.apply {
connectorMode = "RPC_REQUESTS_WITH_WS_HEAD"
ws = UpstreamsConfig.WsEndpoint(URI("ws://localhost:8546"))
},
ConnectorMode.RPC_REQUESTS_WITH_WS_HEAD
),
Arguments.of(
UpstreamsConfig.EthereumConnection()
.apply {
preferHttp = true
connectorMode = "RPC_REQUESTS_WITH_WS_HEAD"
ws = UpstreamsConfig.WsEndpoint(URI("ws://localhost:8546"))
},
ConnectorMode.RPC_REQUESTS_WITH_MIXED_HEAD
),
)
}
}
@ParameterizedTest
@MethodSource("data")
fun testKeepForwarded(input: UpstreamsConfig.EthereumConnection, expected: ConnectorMode) {
assertEquals(expected, input.resolveMode())
}
}