Skip to content

Commit

Permalink
Added test for genesis hash (#7909)
Browse files Browse the repository at this point in the history
Added a test to verify that genesis hash doesn't change.
  • Loading branch information
mm-near authored and nikurt committed Nov 7, 2022
1 parent 4161011 commit 156a6fc
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions nearcore/src/runtime/mod.rs
Expand Up @@ -1634,6 +1634,7 @@ impl node_runtime::adapter::ViewRuntimeAdapter for NightshadeRuntime {
mod test {
use std::collections::BTreeSet;

use near_chain::{Chain, ChainGenesis};
use near_primitives::types::validator_stake::ValidatorStake;
use num_rational::Ratio;

Expand Down Expand Up @@ -3250,4 +3251,40 @@ mod test {
let view_state_value = view_state.get(&key).unwrap().unwrap();
assert_eq!(state_value, view_state_value);
}

/// Check that mainnet genesis hash still matches, to make sure that we're still backwards compatible.
#[test]
fn test_genesis_hash() {
let genesis = near_mainnet_res::mainnet_genesis();
let chain_genesis = ChainGenesis::new(&genesis);
let store = near_store::test_utils::create_test_store();

let tempdir = tempfile::tempdir().unwrap();
let runtime = Arc::new(NightshadeRuntime::test_with_runtime_config_store(
tempdir.path(),
store.clone(),
&genesis,
TrackedConfig::new_empty(),
RuntimeConfigStore::new(None),
));

let block = Chain::make_genesis_block(&*runtime, &chain_genesis).unwrap();
assert_eq!(
block.header().hash().to_string(),
"EPnLgE7iEq9s7yTkos96M3cWymH5avBAPm3qx3NXqR8H"
);

let epoch_manager = EpochManager::new_from_genesis_config(store, &genesis.config).unwrap();
let epoch_info = epoch_manager.get_epoch_info(&EpochId::default()).unwrap();
// Verify the order of the block producers.
assert_eq!(
[
1, 0, 1, 0, 0, 3, 3, 2, 2, 3, 0, 2, 0, 0, 1, 1, 1, 1, 3, 2, 3, 2, 0, 3, 3, 3, 0, 3,
1, 3, 1, 0, 1, 2, 3, 0, 1, 0, 0, 0, 2, 2, 2, 3, 3, 3, 3, 1, 2, 0, 1, 0, 1, 0, 3, 2,
1, 2, 0, 1, 3, 3, 1, 2, 1, 2, 1, 0, 2, 3, 1, 2, 1, 2, 3, 2, 0, 3, 3, 2, 0, 0, 2, 3,
0, 3, 0, 2, 3, 1, 1, 2, 1, 0, 1, 2, 2, 1, 2, 0
],
epoch_info.block_producers_settlement()
);
}
}

0 comments on commit 156a6fc

Please sign in to comment.