@@ -16,9 +16,12 @@
|
||||
*/
|
||||
package io.emeraldpay.dshackle.config
|
||||
|
||||
|
||||
import io.emeraldpay.dshackle.test.TestingCommons
|
||||
import spock.lang.Specification
|
||||
|
||||
import java.time.Duration
|
||||
|
||||
class UpstreamsConfigReaderSpec extends Specification {
|
||||
|
||||
UpstreamsConfigReader reader = new UpstreamsConfigReader(TestingCommons.fileResolver())
|
||||
@@ -481,4 +484,156 @@ class UpstreamsConfigReaderSpec extends Specification {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def "Merge options for disableValidation"() {
|
||||
expect:
|
||||
def a = new UpstreamsConfig.PartialOptions().tap { disableValidation = base }
|
||||
def b = new UpstreamsConfig.PartialOptions().tap { disableValidation = overwrite }
|
||||
def result = a.merge(b).buildOptions()
|
||||
result.disableValidation == exp
|
||||
|
||||
where:
|
||||
base | overwrite | exp
|
||||
true | true | true
|
||||
true | false | false
|
||||
true | null | true
|
||||
|
||||
false | true | true
|
||||
false | false | false
|
||||
false | null | false
|
||||
|
||||
null | true | true
|
||||
null | false | false
|
||||
null | null | false
|
||||
}
|
||||
|
||||
def "Merge options for providesBalance"() {
|
||||
expect:
|
||||
def a = new UpstreamsConfig.PartialOptions().tap { providesBalance = base }
|
||||
def b = new UpstreamsConfig.PartialOptions().tap { providesBalance = overwrite }
|
||||
def result = a.merge(b).buildOptions()
|
||||
result.providesBalance == exp
|
||||
|
||||
where:
|
||||
base | overwrite | exp
|
||||
true | true | true
|
||||
true | false | false
|
||||
true | null | true
|
||||
|
||||
false | true | true
|
||||
false | false | false
|
||||
false | null | false
|
||||
|
||||
null | true | true
|
||||
null | false | false
|
||||
null | null | null
|
||||
}
|
||||
|
||||
def "Merge options for validatePeers"() {
|
||||
expect:
|
||||
def a = new UpstreamsConfig.PartialOptions().tap { validatePeers = base }
|
||||
def b = new UpstreamsConfig.PartialOptions().tap { validatePeers = overwrite }
|
||||
def result = a.merge(b).buildOptions()
|
||||
result.validatePeers == exp
|
||||
|
||||
where:
|
||||
base | overwrite | exp
|
||||
true | true | true
|
||||
true | false | false
|
||||
true | null | true
|
||||
|
||||
false | true | true
|
||||
false | false | false
|
||||
false | null | false
|
||||
|
||||
null | true | true
|
||||
null | false | false
|
||||
null | null | true
|
||||
}
|
||||
|
||||
def "Merge options for validateSyncing"() {
|
||||
expect:
|
||||
def a = new UpstreamsConfig.PartialOptions().tap { validateSyncing = base }
|
||||
def b = new UpstreamsConfig.PartialOptions().tap { validateSyncing = overwrite }
|
||||
def result = a.merge(b).buildOptions()
|
||||
result.validateSyncing == exp
|
||||
|
||||
where:
|
||||
base | overwrite | exp
|
||||
true | true | true
|
||||
true | false | false
|
||||
true | null | true
|
||||
|
||||
false | true | true
|
||||
false | false | false
|
||||
false | null | false
|
||||
|
||||
null | true | true
|
||||
null | false | false
|
||||
null | null | true
|
||||
}
|
||||
|
||||
def "Merge options for timeout"() {
|
||||
expect:
|
||||
def a = new UpstreamsConfig.PartialOptions().tap {
|
||||
timeout = base == null ? null : Duration.ofSeconds(base)
|
||||
}
|
||||
def b = new UpstreamsConfig.PartialOptions().tap {
|
||||
timeout = overwrite == null ? null : Duration.ofSeconds(overwrite)
|
||||
}
|
||||
def result = a.merge(b).buildOptions()
|
||||
def expValue = exp == null ? Duration.ofSeconds(60) : Duration.ofSeconds(exp)
|
||||
result.timeout == expValue
|
||||
|
||||
where:
|
||||
base | overwrite | exp
|
||||
1 | 2 | 2
|
||||
3 | 4 | 4
|
||||
5 | null | 5
|
||||
null | 6 | 6
|
||||
null | null | null
|
||||
}
|
||||
|
||||
def "Merge options for minPeers"() {
|
||||
expect:
|
||||
def a = new UpstreamsConfig.PartialOptions().tap { minPeers = base }
|
||||
def b = new UpstreamsConfig.PartialOptions().tap { minPeers = overwrite }
|
||||
def result = a.merge(b).buildOptions()
|
||||
result.minPeers == exp
|
||||
|
||||
where:
|
||||
base | overwrite | exp
|
||||
1 | 2 | 2
|
||||
3 | 4 | 4
|
||||
5 | null | 5
|
||||
null | 6 | 6
|
||||
null | null | 1
|
||||
}
|
||||
|
||||
def "Merge options for validationInterval"() {
|
||||
expect:
|
||||
def a = new UpstreamsConfig.PartialOptions().tap { validationInterval = base }
|
||||
def b = new UpstreamsConfig.PartialOptions().tap { validationInterval = overwrite }
|
||||
def result = a.merge(b).buildOptions()
|
||||
result.validationInterval == exp
|
||||
|
||||
where:
|
||||
base | overwrite | exp
|
||||
1 | 2 | 2
|
||||
3 | 4 | 4
|
||||
5 | null | 5
|
||||
null | 6 | 6
|
||||
null | null | 30
|
||||
}
|
||||
|
||||
def "Options with default values"() {
|
||||
setup:
|
||||
def partialOptions = new UpstreamsConfig.PartialOptions()
|
||||
when:
|
||||
def options = partialOptions.buildOptions()
|
||||
then:
|
||||
options == new UpstreamsConfig.Options(
|
||||
false, 30, Duration.ofSeconds(60), null, true, 1, true
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,9 +83,9 @@ class EthereumPosRpcUpstreamMock extends EthereumPosRpcUpstream {
|
||||
}
|
||||
|
||||
static Options getOpts() {
|
||||
def opt = UpstreamsConfig.Options.getDefaults()
|
||||
def opt = UpstreamsConfig.PartialOptions.getDefaults()
|
||||
opt.setDisableValidation(true)
|
||||
return opt
|
||||
return opt.buildOptions()
|
||||
}
|
||||
|
||||
void nextBlock(BlockContainer block) {
|
||||
|
||||
@@ -60,7 +60,7 @@ class EthereumRpcUpstreamMock extends EthereumRpcUpstream {
|
||||
|
||||
EthereumRpcUpstreamMock(@NotNull String id, @NotNull Chain chain, @NotNull Reader<JsonRpcRequest, JsonRpcResponse> api, CallMethods methods) {
|
||||
super(id, id.hashCode().byteValue(), chain,
|
||||
UpstreamsConfig.Options.getDefaults(),
|
||||
UpstreamsConfig.PartialOptions.getDefaults().buildOptions(),
|
||||
UpstreamsConfig.UpstreamRole.PRIMARY,
|
||||
methods,
|
||||
new QuorumForLabels.QuorumItem(1, new UpstreamsConfig.Labels()),
|
||||
|
||||
@@ -54,7 +54,7 @@ class FilteredApisSpec extends Specification {
|
||||
"test",
|
||||
(byte)123,
|
||||
Chain.ETHEREUM,
|
||||
new UpstreamsConfig.Options(),
|
||||
new UpstreamsConfig.PartialOptions().buildOptions(),
|
||||
UpstreamsConfig.UpstreamRole.PRIMARY,
|
||||
ethereumTargets,
|
||||
new QuorumForLabels.QuorumItem(1, UpstreamsConfig.Labels.fromMap(it)),
|
||||
|
||||
@@ -30,7 +30,7 @@ class EthereumUpstreamValidatorSpec extends Specification {
|
||||
|
||||
def "Resolve to final availability"() {
|
||||
setup:
|
||||
def validator = new EthereumUpstreamValidator(Stub(EthereumUpstream), UpstreamsConfig.Options.getDefaults())
|
||||
def validator = new EthereumUpstreamValidator(Stub(EthereumUpstream), UpstreamsConfig.PartialOptions.getDefaults().buildOptions())
|
||||
expect:
|
||||
validator.resolve(Tuples.of(sync, peers)) == exp
|
||||
where:
|
||||
@@ -48,9 +48,9 @@ class EthereumUpstreamValidatorSpec extends Specification {
|
||||
|
||||
def "Doesnt check eth_syncing when disabled"() {
|
||||
setup:
|
||||
def options = UpstreamsConfig.Options.getDefaults().tap {
|
||||
def options = UpstreamsConfig.PartialOptions.getDefaults().tap {
|
||||
it.validateSyncing = false
|
||||
}
|
||||
}.buildOptions()
|
||||
def up = Mock(EthereumUpstream)
|
||||
def validator = new EthereumUpstreamValidator(up, options)
|
||||
|
||||
@@ -63,9 +63,9 @@ class EthereumUpstreamValidatorSpec extends Specification {
|
||||
|
||||
def "Syncing is OK when false returned from upstream"() {
|
||||
setup:
|
||||
def options = UpstreamsConfig.Options.getDefaults().tap {
|
||||
def options = UpstreamsConfig.PartialOptions.getDefaults().tap {
|
||||
it.validateSyncing = true
|
||||
}
|
||||
}.buildOptions()
|
||||
def up = TestingCommons.upstream(
|
||||
new ApiReaderMock().tap {
|
||||
answer("eth_syncing", [], false)
|
||||
@@ -81,9 +81,9 @@ class EthereumUpstreamValidatorSpec extends Specification {
|
||||
|
||||
def "Syncing is SYNCING when state returned from upstream"() {
|
||||
setup:
|
||||
def options = UpstreamsConfig.Options.getDefaults().tap {
|
||||
def options = UpstreamsConfig.PartialOptions.getDefaults().tap {
|
||||
it.validateSyncing = true
|
||||
}
|
||||
}.buildOptions()
|
||||
def up = TestingCommons.upstream(
|
||||
new ApiReaderMock().tap {
|
||||
answer("eth_syncing", [], [startingBlock: 100, currentBlock: 50])
|
||||
@@ -99,9 +99,9 @@ class EthereumUpstreamValidatorSpec extends Specification {
|
||||
|
||||
def "Syncing is UNAVAILABLE when error returned from upstream"() {
|
||||
setup:
|
||||
def options = UpstreamsConfig.Options.getDefaults().tap {
|
||||
def options = UpstreamsConfig.PartialOptions.getDefaults().tap {
|
||||
it.validateSyncing = true
|
||||
}
|
||||
}.buildOptions()
|
||||
def up = TestingCommons.upstream(
|
||||
new ApiReaderMock().tap {
|
||||
answer("eth_syncing", [], new RpcResponseError(RpcResponseError.CODE_METHOD_NOT_EXIST, "Unavailable"))
|
||||
@@ -117,10 +117,10 @@ class EthereumUpstreamValidatorSpec extends Specification {
|
||||
|
||||
def "Doesnt validate peers when disabled"() {
|
||||
setup:
|
||||
def options = UpstreamsConfig.Options.getDefaults().tap {
|
||||
def options = UpstreamsConfig.PartialOptions.getDefaults().tap {
|
||||
it.validatePeers = false
|
||||
it.minPeers = 10
|
||||
}
|
||||
}.buildOptions()
|
||||
def up = Mock(EthereumUpstream)
|
||||
def validator = new EthereumUpstreamValidator(up, options)
|
||||
|
||||
@@ -133,10 +133,10 @@ class EthereumUpstreamValidatorSpec extends Specification {
|
||||
|
||||
def "Doesnt validate peers when zero peers is expected"() {
|
||||
setup:
|
||||
def options = UpstreamsConfig.Options.getDefaults().tap {
|
||||
def options = UpstreamsConfig.PartialOptions.getDefaults().tap {
|
||||
it.validatePeers = true
|
||||
it.minPeers = 0
|
||||
}
|
||||
}.buildOptions()
|
||||
def up = Mock(EthereumUpstream)
|
||||
def validator = new EthereumUpstreamValidator(up, options)
|
||||
|
||||
@@ -149,10 +149,10 @@ class EthereumUpstreamValidatorSpec extends Specification {
|
||||
|
||||
def "Peers is IMMATURE when state returned too few peers"() {
|
||||
setup:
|
||||
def options = UpstreamsConfig.Options.getDefaults().tap {
|
||||
def options = UpstreamsConfig.PartialOptions.getDefaults().tap {
|
||||
it.validatePeers = true
|
||||
it.minPeers = 10
|
||||
}
|
||||
}.buildOptions()
|
||||
def up = TestingCommons.upstream(
|
||||
new ApiReaderMock().tap {
|
||||
answer("net_peerCount", [], "0x5")
|
||||
@@ -168,10 +168,10 @@ class EthereumUpstreamValidatorSpec extends Specification {
|
||||
|
||||
def "Peers is OK when state returned exactly min peers"() {
|
||||
setup:
|
||||
def options = UpstreamsConfig.Options.getDefaults().tap {
|
||||
def options = UpstreamsConfig.PartialOptions.getDefaults().tap {
|
||||
it.validatePeers = true
|
||||
it.minPeers = 10
|
||||
}
|
||||
}.buildOptions()
|
||||
def up = TestingCommons.upstream(
|
||||
new ApiReaderMock().tap {
|
||||
answer("net_peerCount", [], "0xa")
|
||||
@@ -187,10 +187,10 @@ class EthereumUpstreamValidatorSpec extends Specification {
|
||||
|
||||
def "Peers is OK when state returned more than enough peers"() {
|
||||
setup:
|
||||
def options = UpstreamsConfig.Options.getDefaults().tap {
|
||||
def options = UpstreamsConfig.PartialOptions.getDefaults().tap {
|
||||
it.validatePeers = true
|
||||
it.minPeers = 10
|
||||
}
|
||||
}.buildOptions()
|
||||
def up = TestingCommons.upstream(
|
||||
new ApiReaderMock().tap {
|
||||
answer("net_peerCount", [], "0xff")
|
||||
@@ -206,10 +206,10 @@ class EthereumUpstreamValidatorSpec extends Specification {
|
||||
|
||||
def "Peers is UNAVAILABLE when state returned error"() {
|
||||
setup:
|
||||
def options = UpstreamsConfig.Options.getDefaults().tap {
|
||||
def options = UpstreamsConfig.PartialOptions.getDefaults().tap {
|
||||
it.validatePeers = true
|
||||
it.minPeers = 10
|
||||
}
|
||||
}.buildOptions()
|
||||
def up = TestingCommons.upstream(
|
||||
new ApiReaderMock().tap {
|
||||
answer("net_peerCount", [], new RpcResponseError(RpcResponseError.CODE_METHOD_NOT_EXIST, "Unavailable"))
|
||||
|
||||
Reference in New Issue
Block a user