2021-09-11 14:58:01 +00:00
|
|
|
import
|
|
|
|
std/[os],
|
|
|
|
pkg/[unittest2, confutils],
|
|
|
|
eth/[p2p, common],
|
2021-09-16 15:59:46 +00:00
|
|
|
../nimbus/[config, chain_config],
|
|
|
|
./test_helpers
|
2021-09-11 14:58:01 +00:00
|
|
|
|
|
|
|
proc `==`(a, b: ChainId): bool =
|
|
|
|
a.int == b.int
|
|
|
|
|
|
|
|
proc configurationMain*() =
|
|
|
|
suite "configuration test suite":
|
2021-09-16 15:59:46 +00:00
|
|
|
const
|
|
|
|
genesisFile = "tests" / "customgenesis" / "calaveras.json"
|
|
|
|
bootNode = "enode://a24ac7c5484ef4ed0c5eb2d36620ba4e4aa13b8c84684e1b4aab0cebea2ae45cb4d375b77eab56516d34bfbd3c1a833fc51296ff084b770b94fb9028c4d25ccf@52.169.42.101:30303"
|
2021-09-11 14:58:01 +00:00
|
|
|
|
|
|
|
test "data-dir and key-store":
|
2021-09-16 15:59:46 +00:00
|
|
|
let conf = makeTestConfig()
|
2021-09-11 14:58:01 +00:00
|
|
|
check conf.dataDir.string == defaultDataDir()
|
|
|
|
check conf.keyStore.string == defaultKeystoreDir()
|
|
|
|
|
|
|
|
let cc = makeConfig(@["-d:apple\\bin", "-k:banana/bin"])
|
|
|
|
check cc.dataDir.string == "apple\\bin"
|
|
|
|
check cc.keyStore.string == "banana/bin"
|
|
|
|
|
|
|
|
let dd = makeConfig(@["--data-dir:apple\\bin", "--key-store:banana/bin"])
|
|
|
|
check dd.dataDir.string == "apple\\bin"
|
|
|
|
check dd.keyStore.string == "banana/bin"
|
|
|
|
|
|
|
|
test "prune-mode":
|
2021-09-16 15:59:46 +00:00
|
|
|
let aa = makeTestConfig()
|
2021-09-11 14:58:01 +00:00
|
|
|
check aa.pruneMode == PruneMode.Full
|
|
|
|
|
|
|
|
let bb = makeConfig(@["--prune-mode:full"])
|
|
|
|
check bb.pruneMode == PruneMode.Full
|
|
|
|
|
|
|
|
let cc = makeConfig(@["--prune-mode:archive"])
|
|
|
|
check cc.pruneMode == PruneMode.Archive
|
|
|
|
|
|
|
|
let dd = makeConfig(@["-p:archive"])
|
|
|
|
check dd.pruneMode == PruneMode.Archive
|
|
|
|
|
|
|
|
test "import":
|
2021-09-16 15:59:46 +00:00
|
|
|
let aa = makeTestConfig()
|
|
|
|
check aa.cmd == NimbusCmd.noCommand
|
2021-09-11 14:58:01 +00:00
|
|
|
|
2021-09-16 15:59:46 +00:00
|
|
|
let bb = makeConfig(@["import", genesisFile])
|
|
|
|
check bb.cmd == NimbusCmd.`import`
|
|
|
|
check bb.blocksFile.string == genesisFile
|
2021-09-11 14:58:01 +00:00
|
|
|
|
|
|
|
test "network-id":
|
2021-09-16 15:59:46 +00:00
|
|
|
let aa = makeTestConfig()
|
|
|
|
check aa.networkId == MainNet
|
|
|
|
check aa.networkParams != NetworkParams()
|
2021-09-11 14:58:01 +00:00
|
|
|
|
2021-09-16 15:59:46 +00:00
|
|
|
let conf = makeConfig(@["--custom-network:" & genesisFile, "--network:345"])
|
|
|
|
check conf.networkId == 345.NetworkId
|
2021-09-11 14:58:01 +00:00
|
|
|
|
|
|
|
test "network-id first, custom-network next":
|
2021-09-16 15:59:46 +00:00
|
|
|
let conf = makeConfig(@["--network:678", "--custom-network:" & genesisFile])
|
|
|
|
check conf.networkId == 678.NetworkId
|
|
|
|
|
|
|
|
test "network-id set, no custom-network":
|
|
|
|
let conf = makeConfig(@["--network:678"])
|
|
|
|
check conf.networkId == 678.NetworkId
|
|
|
|
check conf.networkParams == NetworkParams()
|
2021-09-11 14:58:01 +00:00
|
|
|
|
2021-10-05 23:31:35 +00:00
|
|
|
test "network-id not set, copy from chainId of custom network":
|
2021-09-11 14:58:01 +00:00
|
|
|
let conf = makeConfig(@["--custom-network:" & genesisFile])
|
2021-09-16 15:59:46 +00:00
|
|
|
check conf.networkId == 123.NetworkId
|
2021-09-11 14:58:01 +00:00
|
|
|
|
|
|
|
test "network-id not set, goerli set":
|
2021-09-16 15:59:46 +00:00
|
|
|
let conf = makeConfig(@["--network:goerli"])
|
|
|
|
check conf.networkId == GoerliNet
|
2021-09-11 14:58:01 +00:00
|
|
|
|
|
|
|
test "network-id set, goerli set":
|
2021-09-16 15:59:46 +00:00
|
|
|
let conf = makeConfig(@["--network:goerli", "--network:123"])
|
|
|
|
check conf.networkId == 123.NetworkId
|
|
|
|
|
|
|
|
test "rpc-api":
|
|
|
|
let conf = makeTestConfig()
|
|
|
|
let flags = conf.getRpcFlags()
|
|
|
|
check RpcFlag.Eth in flags
|
|
|
|
|
|
|
|
let aa = makeConfig(@["--rpc-api:eth"])
|
|
|
|
let ax = aa.getRpcFlags()
|
|
|
|
check RpcFlag.Eth in ax
|
|
|
|
|
|
|
|
let bb = makeConfig(@["--rpc-api:eth", "--rpc-api:debug"])
|
|
|
|
let bx = bb.getRpcFlags()
|
|
|
|
check RpcFlag.Eth in bx
|
|
|
|
check RpcFlag.Debug in bx
|
|
|
|
|
|
|
|
let cc = makeConfig(@["--rpc-api:eth,debug"])
|
|
|
|
let cx = cc.getRpcFlags()
|
|
|
|
check RpcFlag.Eth in cx
|
|
|
|
check RpcFlag.Debug in cx
|
|
|
|
|
|
|
|
test "ws-api":
|
|
|
|
let conf = makeTestConfig()
|
|
|
|
let flags = conf.getWsFlags()
|
|
|
|
check RpcFlag.Eth in flags
|
|
|
|
|
|
|
|
let aa = makeConfig(@["--ws-api:eth"])
|
|
|
|
let ax = aa.getWsFlags()
|
|
|
|
check RpcFlag.Eth in ax
|
|
|
|
|
|
|
|
let bb = makeConfig(@["--ws-api:eth", "--ws-api:debug"])
|
|
|
|
let bx = bb.getWsFlags()
|
|
|
|
check RpcFlag.Eth in bx
|
|
|
|
check RpcFlag.Debug in bx
|
|
|
|
|
|
|
|
let cc = makeConfig(@["--ws-api:eth,debug"])
|
|
|
|
let cx = cc.getWsFlags()
|
|
|
|
check RpcFlag.Eth in cx
|
|
|
|
check RpcFlag.Debug in cx
|
|
|
|
|
|
|
|
test "protocols":
|
|
|
|
let conf = makeTestConfig()
|
|
|
|
let flags = conf.getProtocolFlags()
|
|
|
|
check ProtocolFlag.Eth in flags
|
|
|
|
|
|
|
|
let aa = makeConfig(@["--protocols:les"])
|
|
|
|
let ax = aa.getProtocolFlags()
|
|
|
|
check ProtocolFlag.Les in ax
|
|
|
|
|
|
|
|
let bb = makeConfig(@["--protocols:eth", "--protocols:les"])
|
|
|
|
let bx = bb.getProtocolFlags()
|
|
|
|
check ProtocolFlag.Eth in bx
|
|
|
|
check ProtocolFlag.Les in bx
|
|
|
|
|
|
|
|
let cc = makeConfig(@["--protocols:eth,les"])
|
|
|
|
let cx = cc.getProtocolFlags()
|
|
|
|
check ProtocolFlag.Eth in cx
|
|
|
|
check ProtocolFlag.Les in cx
|
|
|
|
|
|
|
|
test "bootstrap-node and bootstrap-file":
|
|
|
|
let conf = makeTestConfig()
|
|
|
|
let bootnodes = conf.getBootnodes()
|
|
|
|
let bootNodeLen = bootnodes.len
|
|
|
|
check bootNodeLen > 0 # mainnet bootnodes
|
|
|
|
|
|
|
|
let aa = makeConfig(@["--bootstrap-node:" & bootNode])
|
|
|
|
let ax = aa.getBootNodes()
|
|
|
|
check ax.len == bootNodeLen + 1
|
|
|
|
|
|
|
|
const
|
|
|
|
bootFilePath = "tests" / "bootstrap"
|
|
|
|
bootFileAppend = bootFilePath / "append_bootnodes.txt"
|
|
|
|
bootFileOverride = bootFilePath / "override_bootnodes.txt"
|
|
|
|
|
|
|
|
let bb = makeConfig(@["--bootstrap-file:" & bootFileAppend])
|
|
|
|
let bx = bb.getBootNodes()
|
|
|
|
check bx.len == bootNodeLen + 3
|
|
|
|
|
|
|
|
let cc = makeConfig(@["--bootstrap-file:" & bootFileOverride])
|
|
|
|
let cx = cc.getBootNodes()
|
|
|
|
check cx.len == 3
|
|
|
|
|
|
|
|
test "static-peers":
|
|
|
|
let conf = makeTestConfig()
|
|
|
|
check conf.getStaticPeers().len == 0
|
|
|
|
|
|
|
|
let aa = makeConfig(@["--static-peers:" & bootNode])
|
|
|
|
check aa.getStaticPeers().len == 1
|
|
|
|
|
|
|
|
let bb = makeConfig(@["--static-peers:" & bootNode & "," & bootNode])
|
|
|
|
check bb.getStaticPeers().len == 2
|
|
|
|
|
|
|
|
let cc = makeConfig(@["--static-peers:" & bootNode, "--static-peers:" & bootNode])
|
|
|
|
check cc.getStaticPeers().len == 2
|
|
|
|
|
|
|
|
test "chainId of custom-network is oneof std network":
|
|
|
|
const
|
|
|
|
chainid1 = "tests" / "customgenesis" / "chainid1.json"
|
|
|
|
|
|
|
|
let conf = makeConfig(@["--custom-network:" & chainid1])
|
|
|
|
check conf.networkId == 1.NetworkId
|
|
|
|
check conf.networkParams.config.londonBlock == 1337
|
|
|
|
check conf.getBootnodes().len == 0
|
2021-09-11 14:58:01 +00:00
|
|
|
|
|
|
|
when isMainModule:
|
|
|
|
configurationMain()
|