From e36d2f432a186f5da4334761a2898f63de3881e5 Mon Sep 17 00:00:00 2001 From: jangko Date: Thu, 22 Dec 2022 11:17:04 +0700 Subject: [PATCH] fix default --key-store location if --data-dir is custom --- nimbus/config.nim | 7 ++++++- tests/test_configuration.nim | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/nimbus/config.nim b/nimbus/config.nim index cfdb5b9af..9366369bb 100644 --- a/nimbus/config.nim +++ b/nimbus/config.nim @@ -23,7 +23,7 @@ import ], stew/shims/net as stewNet, eth/[common, net/nat, p2p/bootnodes, p2p/enode], - "."/[db/select_backend, + "."/[db/select_backend, constants, vm_compile_info, version ], common/chain_config @@ -733,6 +733,11 @@ proc makeConfig*(cmdLine = commandLineParams()): NimbusConf = result.rpcEnabled = result.rpcEnabled or rpcMustEnabled result.wsEnabled = result.wsEnabled or wsMustEnabled + # see issue #1346 + if result.keyStore.string == defaultKeystoreDir() and + result.dataDir.string != defaultDataDir(): + result.keyStore = OutDir(result.dataDir.string / "keystore") + when isMainModule: # for testing purpose discard makeConfig() diff --git a/tests/test_configuration.nim b/tests/test_configuration.nim index f65fb7c33..9bb1098c2 100644 --- a/tests/test_configuration.nim +++ b/tests/test_configuration.nim @@ -257,5 +257,24 @@ proc configurationMain*() = let pkhex2 = rc2.get.seckey.toRaw.to0xHex check pkhex1 == pkhex2 + test "default key-store and default data-dir": + let conf = makeTestConfig() + check conf.keyStore.string == conf.dataDir.string / "keystore" + + test "custom key-store and custom data-dir": + let conf = makeConfig(@["--key-store:banana", "--data-dir:apple"]) + check conf.keyStore.string == "banana" + check conf.dataDir.string == "apple" + + test "default key-store and custom data-dir": + let conf = makeConfig(@["--data-dir:apple"]) + check conf.dataDir.string == "apple" + check conf.keyStore.string == "apple" / "keystore" + + test "custom key-store and default data-dir": + let conf = makeConfig(@["--key-store:banana"]) + check conf.dataDir.string == defaultDataDir() + check conf.keyStore.string == "banana" + when isMainModule: configurationMain()