From 1da43462955c0e8da9b1f2b6dbaedded83af16d6 Mon Sep 17 00:00:00 2001 From: jangko Date: Thu, 5 Aug 2021 16:40:53 +0700 Subject: [PATCH] config: fixes bug networkid parser previously it mistakenly parse into the `result` now it correctly parse networkId into res. --- nimbus/config.nim | 2 +- tests/test_misc.nim | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/nimbus/config.nim b/nimbus/config.nim index 1ba3b37fe..1a45762ce 100644 --- a/nimbus/config.nim +++ b/nimbus/config.nim @@ -546,7 +546,7 @@ proc processNetArguments(key, value: string): ConfigStatus = var res = 0 result = processInteger(value, res) if result == Success: - config.net.setNetwork(NetworkId(result)) + config.net.setNetwork(NetworkId(res)) config.net.flags.incl NetworkIdSet elif skey == "nodiscover": config.net.flags.incl(NoDiscover) diff --git a/tests/test_misc.nim b/tests/test_misc.nim index afa2ca183..59870452f 100644 --- a/tests/test_misc.nim +++ b/tests/test_misc.nim @@ -1,11 +1,14 @@ import + std/[os, parseopt], unittest2, stew/byteutils, eth/common/eth_types, - ../nimbus/vm_internals + eth/p2p, + ../nimbus/vm_internals, + ../nimbus/config func toAddress(n: int): EthAddress = result[19] = n.byte - + func toAddress(a, b: int): EthAddress = result[18] = a.byte result[19] = b.byte @@ -22,5 +25,17 @@ proc miscMain*() = check toAddress(0x10, 0x0).toInt == 0x1000 check toAddress(0x10, 0x0, 0x0).toInt == 0x100000 + test "networkid cli": + var msg: string + const genesisFile = "tests" / "customgenesis" / "calaveras.json" + var opt = initOptParser("--customnetwork:" & genesisFile & " --networkid:123") + let res = processArguments(msg, opt) + if res != Success: + echo msg + quit(QuitFailure) + + let conf = getConfiguration() + check conf.net.networkId == 123.NetworkId + when isMainModule: miscMain()