mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-14 14:24:32 +00:00
5e87624315
although they are technically different, but in reality, many networks are using the same id for ChainId dan NetworkId. in this commit, we set networkid from config file's chainId.
65 lines
1.8 KiB
Nim
65 lines
1.8 KiB
Nim
import
|
|
std/[os, parseopt],
|
|
unittest2, stew/byteutils,
|
|
eth/common/eth_types,
|
|
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
|
|
|
|
func toAddress(a, b, c: int): EthAddress =
|
|
result[17] = a.byte
|
|
result[18] = b.byte
|
|
result[19] = c.byte
|
|
|
|
proc miscMain*() =
|
|
suite "Misc test suite":
|
|
test "EthAddress to int":
|
|
check toAddress(0xff).toInt == 0xFF
|
|
check toAddress(0x10, 0x0).toInt == 0x1000
|
|
check toAddress(0x10, 0x0, 0x0).toInt == 0x100000
|
|
|
|
const genesisFile = "tests" / "customgenesis" / "calaveras.json"
|
|
test "networkid cli":
|
|
var msg: string
|
|
var opt = initOptParser("--customnetwork:" & genesisFile & " --networkid:345")
|
|
let res = processArguments(msg, opt)
|
|
if res != Success:
|
|
echo msg
|
|
quit(QuitFailure)
|
|
|
|
let conf = getConfiguration()
|
|
check conf.net.networkId == 345.NetworkId
|
|
|
|
test "networkid first, customnetwork next":
|
|
var msg: string
|
|
var opt = initOptParser("--networkid:678 --customnetwork:" & genesisFile)
|
|
let res = processArguments(msg, opt)
|
|
if res != Success:
|
|
echo msg
|
|
quit(QuitFailure)
|
|
|
|
let conf = getConfiguration()
|
|
check conf.net.networkId == 678.NetworkId
|
|
|
|
test "networkid not set, copy from chainId of customnetwork":
|
|
let conf = getConfiguration()
|
|
conf.net.flags.excl NetworkIdSet
|
|
var msg: string
|
|
var opt = initOptParser("--customnetwork:" & genesisFile)
|
|
let res = processArguments(msg, opt)
|
|
if res != Success:
|
|
echo msg
|
|
quit(QuitFailure)
|
|
|
|
check conf.net.networkId == 123.NetworkId
|
|
|
|
when isMainModule:
|
|
miscMain()
|