Chains config refactoring (#311)

Generate code from chains config
This commit is contained in:
Vyacheslav
2023-09-29 13:36:34 +03:00
committed by GitHub
parent a2c5743fb2
commit ef6af898e0
80 changed files with 1527 additions and 1321 deletions

View File

@@ -6,6 +6,7 @@ import io.emeraldpay.api.proto.Common.ChainRef
import io.emeraldpay.dshackle.config.MainConfig
import io.emeraldpay.dshackle.config.MainConfigReader
import io.emeraldpay.dshackle.config.UpstreamsConfig
import io.emeraldpay.dshackle.foundation.ChainOptions
import io.github.ganchix.ganache.Account
import io.github.ganchix.ganache.GanacheContainer
import io.grpc.BindableService
@@ -43,8 +44,8 @@ class IntegrationTest {
withAccounts(
listOf(
Account.builder().privateKey(PRIVATE_KEY_0).balance(BigInteger.valueOf(2000000000000000000)).build(),
Account.builder().privateKey(PRIVATE_KEY_1).balance(BigInteger.valueOf(2000000000000000000)).build()
)
Account.builder().privateKey(PRIVATE_KEY_1).balance(BigInteger.valueOf(2000000000000000000)).build(),
),
)
}
@@ -82,7 +83,7 @@ class IntegrationTest {
val reader = MainConfigReader(fileResolver)
val config = reader.read(
ResourceUtils.getFile("classpath:integration/dshackle.yaml")
.inputStream()
.inputStream(),
)!!
patch(config)
return config
@@ -94,7 +95,7 @@ class IntegrationTest {
id = "ganache"
nodeId = 1
chain = "ethereum"
options = UpstreamsConfig.PartialOptions()
options = ChainOptions.PartialOptions()
.apply {
validateChain = false
}
@@ -102,12 +103,12 @@ class IntegrationTest {
execution = UpstreamsConfig.EthereumConnection().apply {
rpc = UpstreamsConfig.HttpEndpoint(
URI.create(
"http://" + ganacheContainer.getHost() + ":" + ganacheContainer.getMappedPort(8545) + "/"
)
"http://" + ganacheContainer.getHost() + ":" + ganacheContainer.getMappedPort(8545) + "/",
),
)
}
}
}
},
)
}
}

View File

@@ -1,51 +0,0 @@
package io.emeraldpay.dshackle.config
import io.emeraldpay.dshackle.Chain
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
internal class ChainsConfigTest {
@Test
fun patch() {
val orig = ChainsConfig(
mapOf(
Chain.BITCOIN__MAINNET to createRawChainConfig(0, 0),
Chain.ETHEREUM__MAINNET to createRawChainConfig(1, 2),
Chain.POLYGON_POS__MAINNET to createRawChainConfig(3, 4)
),
createRawChainConfig(1, 2)
)
val patch = ChainsConfig(
mapOf(
Chain.BITCOIN__MAINNET to createRawChainConfig(null, 10000),
Chain.POLYGON_POS__MAINNET to createRawChainConfig(10, 11),
Chain.ARBITRUM__MAINNET to createRawChainConfig(999, 999)
),
createRawChainConfig(100, null)
)
val res = orig.patch(patch)
assertEquals(
ChainsConfig(
mapOf(
Chain.BITCOIN__MAINNET to createRawChainConfig(0, 10000),
Chain.ETHEREUM__MAINNET to createRawChainConfig(1, 2),
Chain.POLYGON_POS__MAINNET to createRawChainConfig(10, 11),
Chain.ARBITRUM__MAINNET to createRawChainConfig(999, 999)
),
createRawChainConfig(100, 2)
),
res
)
}
private fun createRawChainConfig(syncingLagSize: Int?, laggingLagSize: Int?) =
ChainsConfig.RawChainConfig()
.apply {
this.syncingLagSize = syncingLagSize
this.laggingLagSize = laggingLagSize
}
}

View File

@@ -15,21 +15,21 @@ internal class UpstreamsConfigTest {
return Stream.of(
Arguments.of(
UpstreamsConfig.EthereumConnection(),
ConnectorMode.RPC_ONLY
ConnectorMode.RPC_ONLY,
),
Arguments.of(
UpstreamsConfig.EthereumConnection()
.apply {
ws = UpstreamsConfig.WsEndpoint(URI("ws://localhost:8546"))
},
ConnectorMode.WS_ONLY
ConnectorMode.WS_ONLY,
),
Arguments.of(
UpstreamsConfig.EthereumConnection()
.apply {
ws = UpstreamsConfig.WsEndpoint(URI("ws://localhost:8546"))
},
ConnectorMode.WS_ONLY
ConnectorMode.WS_ONLY,
),
Arguments.of(
UpstreamsConfig.EthereumConnection()
@@ -37,7 +37,7 @@ internal class UpstreamsConfigTest {
connectorMode = "RPC_REQUESTS_WITH_WS_HEAD"
ws = UpstreamsConfig.WsEndpoint(URI("ws://localhost:8546"))
},
ConnectorMode.RPC_REQUESTS_WITH_WS_HEAD
ConnectorMode.RPC_REQUESTS_WITH_WS_HEAD,
),
Arguments.of(
UpstreamsConfig.EthereumConnection()
@@ -45,7 +45,7 @@ internal class UpstreamsConfigTest {
connectorMode = "RPC_REQUESTS_WITH_MIXED_HEAD"
ws = UpstreamsConfig.WsEndpoint(URI("ws://localhost:8546"))
},
ConnectorMode.RPC_REQUESTS_WITH_MIXED_HEAD
ConnectorMode.RPC_REQUESTS_WITH_MIXED_HEAD,
),
Arguments.of(
UpstreamsConfig.EthereumConnection()
@@ -53,7 +53,7 @@ internal class UpstreamsConfigTest {
rpc = UpstreamsConfig.HttpEndpoint(URI("http://localhost:8546"))
ws = UpstreamsConfig.WsEndpoint(URI("ws://localhost:8546"))
},
ConnectorMode.RPC_REQUESTS_WITH_WS_HEAD
ConnectorMode.RPC_REQUESTS_WITH_WS_HEAD,
),
)
}