From 6716abfb4da03249d3d5e54d77f87aa4fcc4935c Mon Sep 17 00:00:00 2001 From: Igor Artamonov Date: Wed, 21 Aug 2019 17:39:20 -0400 Subject: [PATCH] problem: unable to run without default options --- .../dshackle/config/UpstreamsConfigReader.kt | 3 ++- .../config/UpstreamsConfigReaderSpec.groovy | 23 +++++++++++++++++++ src/test/resources/upstreams-no-defaults.yaml | 9 ++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/upstreams-no-defaults.yaml diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/UpstreamsConfigReader.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/UpstreamsConfigReader.kt index 5eb58f39..60fde658 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/UpstreamsConfigReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/UpstreamsConfigReader.kt @@ -201,7 +201,8 @@ class UpstreamsConfigReader { } private fun getList(mappingNode: MappingNode?, key: String): CollectionNode? { - return getValue(mappingNode, key, CollectionNode::class.java) as CollectionNode + val value = getValue(mappingNode, key, CollectionNode::class.java) ?: return null + return value as CollectionNode } private fun getListOfString(mappingNode: MappingNode?, key: String): List? { diff --git a/src/test/groovy/io/emeraldpay/dshackle/config/UpstreamsConfigReaderSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/config/UpstreamsConfigReaderSpec.groovy index 0dbef1ff..81232d19 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/config/UpstreamsConfigReaderSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/config/UpstreamsConfigReaderSpec.groovy @@ -136,4 +136,27 @@ class UpstreamsConfigReaderSpec extends Specification { "\${PASSWORD}" | "1a68f20154fc258fe4149c199ad8f281" } + def "Parse config without defaults"() { + setup: + def config = this.class.getClassLoader().getResourceAsStream("upstreams-no-defaults.yaml") + when: + def act = reader.read(config) + then: + act != null + act.version == "v1" + with(act.defaultOptions) { + size() == 0 + } + 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("http://localhost:8545") + ws == null + } + } + } } diff --git a/src/test/resources/upstreams-no-defaults.yaml b/src/test/resources/upstreams-no-defaults.yaml new file mode 100644 index 00000000..627094b4 --- /dev/null +++ b/src/test/resources/upstreams-no-defaults.yaml @@ -0,0 +1,9 @@ +version: v1 + +upstreams: + - id: local + chain: ethereum + connection: + ethereum: + rpc: + url: "http://localhost:8545" \ No newline at end of file