2023-11-01 03:32:09 +00:00
|
|
|
# Nimbus
|
2024-02-23 09:17:24 +00:00
|
|
|
# Copyright (c) 2019-2024 Status Research & Development GmbH
|
2023-11-01 03:32:09 +00:00
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
|
|
|
# http://opensource.org/licenses/MIT)
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except
|
|
|
|
# according to those terms.
|
|
|
|
|
2021-05-13 09:01:58 +00:00
|
|
|
import
|
|
|
|
std/[os],
|
2022-12-02 04:39:12 +00:00
|
|
|
unittest2,
|
|
|
|
../nimbus/config,
|
|
|
|
../nimbus/common/common
|
2018-08-01 12:50:44 +00:00
|
|
|
|
2022-02-11 16:28:39 +00:00
|
|
|
const
|
2022-03-16 09:13:17 +00:00
|
|
|
baseDir = [".", "tests", ".."/"tests", $DirSep] # path containg repo
|
|
|
|
repoDir = [".", "customgenesis"] # alternative repo paths
|
2022-02-11 16:28:39 +00:00
|
|
|
|
|
|
|
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
|
2021-05-13 09:01:58 +00:00
|
|
|
|
2024-10-16 01:34:12 +00:00
|
|
|
proc makeGenesis(networkId: NetworkId): Header =
|
2024-02-23 09:17:24 +00:00
|
|
|
let com = CommonRef.new(newCoreDbRef DefaultDbMemory, params = networkParams(networkId))
|
2022-12-02 04:39:12 +00:00
|
|
|
com.genesisHeader
|
|
|
|
|
2024-10-08 02:37:36 +00:00
|
|
|
proc proofOfStake(params: NetworkParams): bool =
|
|
|
|
let com = CommonRef.new(newCoreDbRef DefaultDbMemory,
|
|
|
|
networkId = params.config.chainId.NetworkId,
|
|
|
|
params = params)
|
|
|
|
let header = com.genesisHeader
|
|
|
|
com.proofOfStake(header)
|
|
|
|
|
2021-05-13 09:01:58 +00:00
|
|
|
proc genesisTest() =
|
2019-09-21 05:45:23 +00:00
|
|
|
suite "Genesis":
|
|
|
|
test "Correct mainnet hash":
|
2022-12-02 04:39:12 +00:00
|
|
|
let b = makeGenesis(MainNet)
|
2024-09-29 12:37:09 +00:00
|
|
|
check(b.blockHash == hash32"D4E56740F876AEF8C010B86A40D5F56745A118D0906A34E69AEC8C0DB1CB8FA3")
|
2020-04-09 10:06:08 +00:00
|
|
|
|
2022-07-01 20:16:26 +00:00
|
|
|
test "Correct sepolia hash":
|
2022-12-02 04:39:12 +00:00
|
|
|
let b = makeGenesis(SepoliaNet)
|
2024-09-29 12:37:09 +00:00
|
|
|
check b.blockHash == hash32"25a5cc106eea7138acab33231d7160d69cb777ee0c2c553fcddf5138993e6dd9"
|
2022-07-01 20:16:26 +00:00
|
|
|
|
2023-10-25 06:27:55 +00:00
|
|
|
test "Correct holesky hash":
|
|
|
|
let b = makeGenesis(HoleskyNet)
|
2024-09-29 12:37:09 +00:00
|
|
|
check b.blockHash == hash32"b5f7f912443c940f21fd611f12828d75b534364ed9e95ca4e307729a4661bde4"
|
|
|
|
check b.stateRoot == hash32"69D8C9D72F6FA4AD42D4702B433707212F90DB395EB54DC20BC85DE253788783"
|
2023-10-25 06:27:55 +00:00
|
|
|
|
2021-05-13 09:01:58 +00:00
|
|
|
proc customGenesisTest() =
|
|
|
|
suite "Custom Genesis":
|
|
|
|
test "loadCustomGenesis":
|
2021-09-16 15:59:46 +00:00
|
|
|
var cga, cgb, cgc: NetworkParams
|
2022-02-11 16:28:39 +00:00
|
|
|
check loadNetworkParams("berlin2000.json".findFilePath, cga)
|
|
|
|
check loadNetworkParams("chainid7.json".findFilePath, cgb)
|
|
|
|
check loadNetworkParams("noconfig.json".findFilePath, cgc)
|
2024-10-08 02:37:36 +00:00
|
|
|
check cga.proofOfStake() == false
|
|
|
|
check cgb.proofOfStake() == false
|
|
|
|
check cgc.proofOfStake() == false
|
2021-08-05 05:12:45 +00:00
|
|
|
|
2022-03-16 09:13:17 +00:00
|
|
|
test "Devnet4.json (aka Kintsugi in all but chainId)":
|
2022-02-11 16:28:39 +00:00
|
|
|
var cg: NetworkParams
|
2022-03-16 09:13:17 +00:00
|
|
|
check loadNetworkParams("devnet4.json".findFilePath, cg)
|
2024-02-23 09:17:24 +00:00
|
|
|
let com = CommonRef.new(newCoreDbRef DefaultDbMemory, params = cg)
|
2024-09-29 12:37:09 +00:00
|
|
|
let stateRoot = hash32"3b84f313bfd49c03cc94729ade2e0de220688f813c0c895a99bd46ecc9f45e1e"
|
|
|
|
let genesisHash = hash32"a28d8d73e087a01d09d8cb806f60863652f30b6b6dfa4e0157501ff07d422399"
|
2022-12-02 04:39:12 +00:00
|
|
|
check com.genesisHeader.stateRoot == stateRoot
|
|
|
|
check com.genesisHeader.blockHash == genesisHash
|
2024-10-08 02:37:36 +00:00
|
|
|
check com.proofOfStake(com.genesisHeader) == false
|
2022-02-11 16:28:39 +00:00
|
|
|
|
2022-03-16 09:13:17 +00:00
|
|
|
test "Devnet5.json (aka Kiln in all but chainId and TTD)":
|
|
|
|
var cg: NetworkParams
|
|
|
|
check loadNetworkParams("devnet5.json".findFilePath, cg)
|
2024-02-23 09:17:24 +00:00
|
|
|
let com = CommonRef.new(newCoreDbRef DefaultDbMemory, params = cg)
|
2024-09-29 12:37:09 +00:00
|
|
|
let stateRoot = hash32"52e628c7f35996ba5a0402d02b34535993c89ff7fc4c430b2763ada8554bee62"
|
|
|
|
let genesisHash = hash32"51c7fe41be669f69c45c33a56982cbde405313342d9e2b00d7c91a7b284dd4f8"
|
2022-12-02 04:39:12 +00:00
|
|
|
check com.genesisHeader.stateRoot == stateRoot
|
|
|
|
check com.genesisHeader.blockHash == genesisHash
|
2024-10-08 02:37:36 +00:00
|
|
|
check com.proofOfStake(com.genesisHeader) == false
|
2022-03-16 09:13:17 +00:00
|
|
|
|
2022-05-06 08:02:28 +00:00
|
|
|
test "Mainnet shadow fork 1":
|
|
|
|
var cg: NetworkParams
|
|
|
|
check loadNetworkParams("mainshadow1.json".findFilePath, cg)
|
2024-02-23 09:17:24 +00:00
|
|
|
let com = CommonRef.new(newCoreDbRef DefaultDbMemory, params = cg)
|
2024-09-29 12:37:09 +00:00
|
|
|
let stateRoot = hash32"d7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544"
|
|
|
|
let genesisHash = hash32"d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3"
|
2024-11-01 19:06:26 +00:00
|
|
|
let ttd = "46_089_003_871_917_200_000_000".parse(UInt256)
|
2022-12-02 04:39:12 +00:00
|
|
|
check com.genesisHeader.stateRoot == stateRoot
|
|
|
|
check com.genesisHeader.blockHash == genesisHash
|
|
|
|
check com.ttd.get == ttd
|
2024-10-08 02:37:36 +00:00
|
|
|
check com.proofOfStake(com.genesisHeader) == false
|
2022-05-06 08:02:28 +00:00
|
|
|
|
2023-11-29 02:03:19 +00:00
|
|
|
test "Geth shadow fork 1":
|
|
|
|
# parse using geth format should produce the same result with nimbus format
|
|
|
|
var cg: NetworkParams
|
|
|
|
check loadNetworkParams("geth_mainshadow1.json".findFilePath, cg)
|
2024-02-23 09:17:24 +00:00
|
|
|
let com = CommonRef.new(newCoreDbRef DefaultDbMemory, params = cg)
|
2024-09-29 12:37:09 +00:00
|
|
|
let stateRoot = hash32"d7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544"
|
|
|
|
let genesisHash = hash32"d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3"
|
2024-11-01 19:06:26 +00:00
|
|
|
let ttd = "46_089_003_871_917_200_000_000".parse(UInt256)
|
2023-11-29 02:03:19 +00:00
|
|
|
check com.genesisHeader.stateRoot == stateRoot
|
|
|
|
check com.genesisHeader.blockHash == genesisHash
|
|
|
|
check com.ttd.get == ttd
|
2024-10-08 02:37:36 +00:00
|
|
|
check com.proofOfStake(com.genesisHeader) == false
|
2023-11-29 02:03:19 +00:00
|
|
|
check cg.config.mergeNetsplitBlock.isSome
|
2024-06-14 07:31:08 +00:00
|
|
|
check cg.config.mergeNetsplitBlock.get == 14660963.BlockNumber
|
2023-11-29 02:03:19 +00:00
|
|
|
check cg.config.mergeNetsplitBlock == cg.config.mergeForkBlock
|
|
|
|
|
2023-10-25 06:27:55 +00:00
|
|
|
test "Holesky":
|
|
|
|
var cg: NetworkParams
|
|
|
|
check loadNetworkParams("holesky.json".findFilePath, cg)
|
2024-02-23 09:17:24 +00:00
|
|
|
let com = CommonRef.new(newCoreDbRef DefaultDbMemory, params = cg)
|
2024-09-29 12:37:09 +00:00
|
|
|
let stateRoot = hash32"69D8C9D72F6FA4AD42D4702B433707212F90DB395EB54DC20BC85DE253788783"
|
|
|
|
let genesisHash = hash32"b5f7f912443c940f21fd611f12828d75b534364ed9e95ca4e307729a4661bde4"
|
2023-10-25 06:27:55 +00:00
|
|
|
check com.genesisHeader.stateRoot == stateRoot
|
|
|
|
check com.genesisHeader.blockHash == genesisHash
|
|
|
|
check com.chainId == 17000.ChainId
|
|
|
|
|
2023-11-29 02:03:19 +00:00
|
|
|
test "Geth Holesky":
|
|
|
|
# parse using geth format should produce the same result with nimbus format
|
|
|
|
var cg: NetworkParams
|
|
|
|
check loadNetworkParams("geth_holesky.json".findFilePath, cg)
|
2024-02-23 09:17:24 +00:00
|
|
|
let com = CommonRef.new(newCoreDbRef DefaultDbMemory, params = cg)
|
2024-09-29 12:37:09 +00:00
|
|
|
let stateRoot = hash32"69D8C9D72F6FA4AD42D4702B433707212F90DB395EB54DC20BC85DE253788783"
|
|
|
|
let genesisHash = hash32"b5f7f912443c940f21fd611f12828d75b534364ed9e95ca4e307729a4661bde4"
|
2023-11-29 02:03:19 +00:00
|
|
|
check com.genesisHeader.stateRoot == stateRoot
|
|
|
|
check com.genesisHeader.blockHash == genesisHash
|
|
|
|
check com.chainId == 17000.ChainId
|
|
|
|
|
2021-05-13 09:01:58 +00:00
|
|
|
proc genesisMain*() =
|
|
|
|
genesisTest()
|
|
|
|
customGenesisTest()
|
|
|
|
|
2020-04-09 10:06:08 +00:00
|
|
|
when isMainModule:
|
2022-05-06 08:02:28 +00:00
|
|
|
genesisTest()
|
|
|
|
customGenesisTest()
|