chore: make timestamp fork tests better (#6499)

This commit is contained in:
Dan Cline
2024-02-08 21:11:59 -05:00
committed by GitHub
parent e9f6f7e9de
commit 51ffa822c3
5 changed files with 10 additions and 20 deletions

View File

@ -42,7 +42,7 @@ bytes.workspace = true
byteorder = "1"
clap = { workspace = true, features = ["derive"], optional = true }
derive_more = "0.99"
itertools = "0.11"
itertools.workspace = true
modular-bitfield = "0.11.2"
num_enum = "0.7"
once_cell.workspace = true

View File

@ -1769,25 +1769,15 @@ Post-merge hard forks (timestamp based):
// Tests that all predefined timestamps are correctly set up in the chainspecs
#[test]
fn test_predefined_chain_spec_fork_timestamps() {
fn ensure_timestamp_fork_conditions(spec: &ChainSpec, known_timestamp_based_forks: usize) {
// This is a sanity test that ensures we always set all currently known fork timestamps,
// this will fail if a new timestamp based fork condition has added to the hardforks but
// no corresponding entry in the ForkTimestamp types, See also
// [ForkTimestamps::from_hardforks]
let predefined = [&MAINNET, &SEPOLIA, &HOLESKY, &GOERLI];
let num_timestamp_based_forks =
spec.hardforks.values().copied().filter(ForkCondition::is_timestamp).count();
assert_eq!(num_timestamp_based_forks, known_timestamp_based_forks);
for spec in predefined.iter() {
let expected_timestamp_forks = &spec.fork_timestamps;
let got_timestamp_forks = ForkTimestamps::from_hardforks(&spec.hardforks);
// ensures all timestamp forks are set
assert!(spec.fork_timestamps.shanghai.is_some());
// make sure they're the same
assert_eq!(expected_timestamp_forks, &got_timestamp_forks);
}
// currently there are 2 timestamp forks known for mainnet: shanghai, cancun
ensure_timestamp_fork_conditions(&MAINNET, 2);
// currently there are 2 timestamp forks known for sepolia: shanghai, cancun
ensure_timestamp_fork_conditions(&SEPOLIA, 2);
}
// Tests that we skip any fork blocks in block #0 (the genesis ruleset)