Skip to content

Commit

Permalink
refactor: use NightshadeRuntime for chain garabage collection tests (#…
Browse files Browse the repository at this point in the history
…10694)

Part of #10678 and
#10634.

Tests are updated to reflect the actual behaviour of chain garbage
collection.
  • Loading branch information
pugachAG authored Mar 4, 2024
1 parent d5056de commit 6a68a2b
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 98 deletions.
2 changes: 1 addition & 1 deletion chain/chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ thiserror.workspace = true
tracing.workspace = true
yansi.workspace = true
easy-ext.workspace = true
tempfile.workspace = true

near-async.workspace = true
near-cache.workspace = true
Expand All @@ -52,7 +53,6 @@ near-mainnet-res.workspace = true
[dev-dependencies]
serde_json.workspace = true
primitive-types.workspace = true
tempfile.workspace = true
insta.workspace = true
assert_matches.workspace = true

Expand Down
34 changes: 21 additions & 13 deletions chain/chain/src/test_utils.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
mod kv_runtime;
mod validator_schedule;

use chrono::{DateTime, Utc};
use near_chain_configs::GenesisConfig;
use num_rational::Ratio;
use std::cmp::Ordering;
use std::sync::Arc;

pub use self::kv_runtime::account_id_to_shard_id;
pub use self::kv_runtime::KeyValueRuntime;
pub use self::kv_runtime::MockEpochManager;
pub use self::validator_schedule::ValidatorSchedule;
use crate::block_processing_utils::BlockNotInPoolError;
use crate::chain::Chain;
use crate::runtime::NightshadeRuntime;
use crate::store::ChainStoreAccess;
use crate::types::{AcceptedBlock, ChainConfig, ChainGenesis};
use crate::DoomslugThresholdMode;
use crate::{BlockProcessingArtifact, Provenance};
use chrono::{DateTime, Utc};
use near_chain_configs::Genesis;
use near_chain_primitives::Error;
use near_epoch_manager::shard_tracker::ShardTracker;
use near_epoch_manager::EpochManager;
use near_primitives::block::Block;
use near_primitives::hash::CryptoHash;
use near_primitives::static_clock::StaticClock;
Expand All @@ -27,10 +24,15 @@ use near_primitives::types::{AccountId, NumBlocks, NumShards};
use near_primitives::utils::MaybeValidated;
use near_primitives::validator_signer::InMemoryValidatorSigner;
use near_primitives::version::PROTOCOL_VERSION;
use near_store::genesis::initialize_genesis_state;
use near_store::test_utils::create_test_store;
use near_store::DBCol;
use num_rational::Ratio;
use tracing::debug;

pub use self::kv_runtime::{account_id_to_shard_id, KeyValueRuntime, MockEpochManager};
pub use self::validator_schedule::ValidatorSchedule;

pub fn get_chain() -> Chain {
get_chain_with_epoch_length_and_num_shards(10, 1)
}
Expand All @@ -48,13 +50,19 @@ pub fn get_chain_with_epoch_length_and_num_shards(
num_shards: NumShards,
) -> Chain {
let store = create_test_store();
let chain_genesis = ChainGenesis::new(&GenesisConfig::test());
let vs = ValidatorSchedule::new()
.block_producers_per_epoch(vec![vec!["test1".parse().unwrap()]])
.num_shards(num_shards);
let epoch_manager = MockEpochManager::new_with_validators(store.clone(), vs, epoch_length);
let mut genesis = Genesis::test_sharded(
vec!["test1".parse::<AccountId>().unwrap()],
1,
vec![1; num_shards as usize],
);
genesis.config.epoch_length = epoch_length;
let tempdir = tempfile::tempdir().unwrap();
initialize_genesis_state(store.clone(), &genesis, Some(tempdir.path()));
let chain_genesis = ChainGenesis::new(&genesis.config);
let epoch_manager = EpochManager::new_arc_handle(store.clone(), &genesis.config);
let shard_tracker = ShardTracker::new_empty(epoch_manager.clone());
let runtime = KeyValueRuntime::new(store, epoch_manager.as_ref());
let runtime =
NightshadeRuntime::test(tempdir.path(), store, &genesis.config, epoch_manager.clone());
Chain::new(
epoch_manager,
shard_tracker,
Expand Down
Loading

0 comments on commit 6a68a2b

Please sign in to comment.