mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-10 20:36:31 +00:00
215e9856d3
* Rearrange/rename test_kintsugu => test_custom_network why: Debug, fix and test more general problems related to running nimbus on a custom network. * Update UInt265/Json parser for --custom-network command line option why: As found out with the Kintsugi configuration, block number and balance have the same Nim type which led to misunderstandings. This patch makes sure that UInt265 encoded string values "0x11" decodes to 17, and "b" and "11" to 11. * Refactored genesis.toBlock() => genesis.toBlockHeader() why: The function toBlock(g,db) may return different results depending on whether the db descriptor argument is nil, or initialised. This is due to the db.config data sub-descriptor which may give various outcomes for the baseFee field of the genesis header. Also, the version where db is non-nil initialised is used internally only. So the public rewrite toBlockHeader() that replaces the toBlock() function expects a full set of NetworkParams. * update comments * Rename toBlockHeader() => toGenesisHeader() why: Polymorphic prototype used for BaseChainDB or NetworkParams argument. With a BaseChainDB descriptor argument, the name shall imply that the header is generated from the config fields rather than fetched from the database. * Added command line option --static-peers-file why: Handy feature to keep peer nodes in a file, similar to the --bootstrap-file option.
75 lines
2.8 KiB
Nim
75 lines
2.8 KiB
Nim
import
|
|
std/[os],
|
|
unittest2, eth/common, nimcrypto/hash,
|
|
../nimbus/[genesis, config, chain_config]
|
|
|
|
const
|
|
baseDir = [".", "tests", ".." / "tests", $DirSep] # path containg repo
|
|
repoDir = ["customgenesis", "status"] # alternative repo paths
|
|
|
|
proc findFilePath(file: string): string =
|
|
result = "?unknown?" / file
|
|
for dir in baseDir:
|
|
for repo in repoDir:
|
|
let path = dir / repo / file
|
|
if path.fileExists:
|
|
return path
|
|
|
|
proc genesisTest() =
|
|
suite "Genesis":
|
|
test "Correct mainnet hash":
|
|
let b = networkParams(MainNet).toGenesisHeader
|
|
check(b.blockHash == "D4E56740F876AEF8C010B86A40D5F56745A118D0906A34E69AEC8C0DB1CB8FA3".toDigest)
|
|
|
|
test "Correct ropstennet hash":
|
|
let b = networkParams(RopstenNet).toGenesisHeader
|
|
check(b.blockHash == "41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d".toDigest)
|
|
|
|
test "Correct rinkebynet hash":
|
|
let b = networkParams(RinkebyNet).toGenesisHeader
|
|
check(b.blockHash == "6341fd3daf94b748c72ced5a5b26028f2474f5f00d824504e4fa37a75767e177".toDigest)
|
|
|
|
test "Correct goerlinet hash":
|
|
let b = networkParams(GoerliNet).toGenesisHeader
|
|
check(b.blockHash == "bf7e331f7f7c1dd2e05159666b3bf8bc7a8a3a9eb1d518969eab529dd9b88c1a".toDigest)
|
|
|
|
proc customGenesisTest() =
|
|
suite "Custom Genesis":
|
|
test "loadCustomGenesis":
|
|
var cga, cgb, cgc: NetworkParams
|
|
check loadNetworkParams("berlin2000.json".findFilePath, cga)
|
|
check loadNetworkParams("chainid7.json".findFilePath, cgb)
|
|
check loadNetworkParams("noconfig.json".findFilePath, cgc)
|
|
check cga.config.poaEngine == false
|
|
check cgb.config.poaEngine == false
|
|
check cgc.config.poaEngine == false
|
|
|
|
test "calaveras.json":
|
|
var cg: NetworkParams
|
|
check loadNetworkParams("calaveras.json".findFilePath, cg)
|
|
let h = cg.toGenesisHeader
|
|
let stateRoot = "664c93de37eb4a72953ea42b8c046cdb64c9f0b0bca5505ade8d970d49ebdb8c".toDigest
|
|
let genesisHash = "eb9233d066c275efcdfed8037f4fc082770176aefdbcb7691c71da412a5670f2".toDigest
|
|
check h.stateRoot == stateRoot
|
|
check h.blockHash == genesisHash
|
|
check cg.config.poaEngine == true
|
|
check cg.config.cliquePeriod == 30
|
|
check cg.config.cliqueEpoch == 30000
|
|
|
|
test "kintsugi.json":
|
|
var cg: NetworkParams
|
|
check loadNetworkParams("kintsugi.json".findFilePath, cg)
|
|
let h = cg.toGenesisHeader
|
|
let stateRoot = "3b84f313bfd49c03cc94729ade2e0de220688f813c0c895a99bd46ecc9f45e1e".toDigest
|
|
let genesisHash = "a28d8d73e087a01d09d8cb806f60863652f30b6b6dfa4e0157501ff07d422399".toDigest
|
|
check h.stateRoot == stateRoot
|
|
check h.blockHash == genesisHash
|
|
check cg.config.poaEngine == false
|
|
|
|
proc genesisMain*() =
|
|
genesisTest()
|
|
customGenesisTest()
|
|
|
|
when isMainModule:
|
|
genesisMain()
|