Upstream configuration improvement: (#149)
- now we can specify connector mode for better fine tuning of connection
This commit is contained in:
@@ -153,7 +153,7 @@ class UpstreamsConfigReaderSpec extends Specification {
|
||||
|
||||
def "Parse ethereum pos upstreams"() {
|
||||
setup:
|
||||
def config = this.class.getClassLoader().getResourceAsStream("upstreams-ethereum-pos.yaml")
|
||||
def config = this.class.getClassLoader().getResourceAsStream("configs/upstreams-ethereum-pos.yaml")
|
||||
when:
|
||||
def act = reader.readInternal(config)
|
||||
then:
|
||||
@@ -404,7 +404,7 @@ class UpstreamsConfigReaderSpec extends Specification {
|
||||
|
||||
def "Parse node id"() {
|
||||
setup:
|
||||
def config = this.class.getClassLoader().getResourceAsStream("upstreams-node-id.yaml")
|
||||
def config = this.class.getClassLoader().getResourceAsStream("configs/upstreams-node-id.yaml")
|
||||
when:
|
||||
def act = reader.readInternal(config)
|
||||
then:
|
||||
@@ -422,7 +422,7 @@ class UpstreamsConfigReaderSpec extends Specification {
|
||||
|
||||
def "Parse method groups"() {
|
||||
setup:
|
||||
def config = this.class.getClassLoader().getResourceAsStream("upstreams-method-groups.yaml")
|
||||
def config = this.class.getClassLoader().getResourceAsStream("configs/upstreams-method-groups.yaml")
|
||||
when:
|
||||
def act = reader.readInternal(config)
|
||||
then:
|
||||
@@ -459,4 +459,26 @@ class UpstreamsConfigReaderSpec extends Specification {
|
||||
validatePeers == true
|
||||
}
|
||||
}
|
||||
|
||||
def "Parse connector mode in connection config"() {
|
||||
setup:
|
||||
def config = this.class.getClassLoader().getResourceAsStream("configs/upstreams-connector-mode.yaml")
|
||||
when:
|
||||
def act = reader.readInternal(config)
|
||||
then:
|
||||
act != null
|
||||
act.upstreams.size() == 1
|
||||
with(act.upstreams.get(0)) {
|
||||
id == "local"
|
||||
chain == "ethereum"
|
||||
connection instanceof UpstreamsConfig.EthereumConnection
|
||||
with((UpstreamsConfig.EthereumConnection) connection) {
|
||||
rpc != null
|
||||
rpc.url == new URI("https://localhost:8546")
|
||||
ws != null
|
||||
ws.url == new URI("ws://localhost:8546")
|
||||
connectorMode == "RPC_REQUESTS_WITH_WS_HEAD"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ class FilteredApisSpec extends Specification {
|
||||
def httpFactory = Mock(HttpFactory) {
|
||||
create(_, _) >> TestingCommons.api().tap { it.id = "${i++}" }
|
||||
}
|
||||
def connectorFactory = new EthereumConnectorFactory(false, null, httpFactory, new MostWorkForkChoice(), BlockValidator.ALWAYS_VALID)
|
||||
def connectorFactory = new EthereumConnectorFactory(EthereumConnectorFactory.ConnectorMode.RPC_ONLY, null, httpFactory, new MostWorkForkChoice(), BlockValidator.ALWAYS_VALID)
|
||||
new EthereumRpcUpstream(
|
||||
"test",
|
||||
(byte)123,
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
12
src/test/resources/configs/upstreams-connector-mode.yaml
Normal file
12
src/test/resources/configs/upstreams-connector-mode.yaml
Normal file
@@ -0,0 +1,12 @@
|
||||
version: v1
|
||||
|
||||
upstreams:
|
||||
- id: local
|
||||
chain: ethereum
|
||||
connection:
|
||||
ethereum:
|
||||
connector-mode: RPC_REQUESTS_WITH_WS_HEAD
|
||||
ws:
|
||||
url: "ws://localhost:8546"
|
||||
rpc:
|
||||
url: "https://localhost:8546"
|
||||
Reference in New Issue
Block a user