Skip to content

Commit fc4bbca

Browse files
committed
impl
1 parent 834caf0 commit fc4bbca

File tree

4 files changed

+32
-11
lines changed

4 files changed

+32
-11
lines changed

core/chain-configs/src/test_genesis.rs

+16
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,14 @@ impl TestGenesisBuilder {
392392
self
393393
}
394394

395+
/// Creates epoch config builder compatible with the current genesis builder state
396+
pub fn derive_epoch_config_builder(&self) -> TestEpochConfigBuilder {
397+
TestEpochConfigBuilder::new()
398+
.epoch_length(self.epoch_length)
399+
.shard_layout(self.shard_layout.clone())
400+
.validators_spec(self.validators_spec.clone())
401+
}
402+
395403
pub fn build(self) -> Genesis {
396404
if self
397405
.user_accounts
@@ -512,6 +520,14 @@ impl TestGenesisBuilder {
512520
contents: GenesisContents::Records { records: GenesisRecords(records) },
513521
}
514522
}
523+
524+
pub fn build_with_simple_epoch_config_store(self) -> (Genesis, EpochConfigStore) {
525+
let epoch_config = self.derive_epoch_config_builder().build();
526+
let genesis = self.build();
527+
let epoch_config_store =
528+
EpochConfigStore::test_single_version(genesis.config.protocol_version, epoch_config);
529+
(genesis, epoch_config_store)
530+
}
515531
}
516532

517533
impl ValidatorsSpec {

core/primitives/src/epoch_manager.rs

+7
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,13 @@ impl EpochConfigStore {
631631
Self { store }
632632
}
633633

634+
pub fn test_single_version(
635+
protocol_version: ProtocolVersion,
636+
epoch_config: EpochConfig,
637+
) -> Self {
638+
Self::test(BTreeMap::from([(protocol_version, Arc::new(epoch_config))]))
639+
}
640+
634641
/// Returns the EpochConfig for the given protocol version.
635642
/// This panics if no config is found for the given version, thus the initialization via `for_chain_id` should
636643
/// only be performed for chains with some configs stored in files.

test-loop-tests/src/builder.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use near_chain_configs::test_genesis::TestGenesisBuilder;
12
use std::collections::{HashMap, HashSet};
23
use std::sync::{Arc, Mutex};
34
use tempfile::TempDir;
@@ -306,6 +307,12 @@ impl TestLoopBuilder {
306307
}
307308
}
308309

310+
// Creates TestLoop-compatible genesis builder
311+
pub(crate) fn new_genesis_builder() -> TestGenesisBuilder {
312+
TestGenesisBuilder::new()
313+
.genesis_time_from_clock(&near_async::time::FakeClock::default().clock())
314+
}
315+
309316
/// Get the clock for the test loop.
310317
pub(crate) fn clock(&self) -> Clock {
311318
self.test_loop.clock()

test-loop-tests/src/tests/global_contracts.rs

+2-11
Original file line numberDiff line numberDiff line change
@@ -181,24 +181,15 @@ impl GlobalContractsTestEnv {
181181
let validators_spec =
182182
ValidatorsSpec::desired_roles(&block_and_chunk_producers, &chunk_validators_only);
183183

184-
let genesis = TestGenesisBuilder::new()
185-
.genesis_time_from_clock(&near_async::time::FakeClock::default().clock())
184+
let (genesis, epoch_config_store) = TestLoopBuilder::new_genesis_builder()
186185
.validators_spec(validators_spec.clone())
187186
.shard_layout(shard_layout.clone())
188187
.add_user_accounts_simple(
189188
&[account_shard_0.clone(), account_shard_1.clone(), deploy_account.clone()],
190189
initial_balance,
191190
)
192191
.gas_prices(GAS_PRICE, GAS_PRICE)
193-
.build();
194-
let epoch_config = TestEpochConfigBuilder::new()
195-
.shard_layout(shard_layout)
196-
.validators_spec(validators_spec)
197-
.build();
198-
let epoch_config_store = EpochConfigStore::test(BTreeMap::from([(
199-
genesis.config.protocol_version,
200-
Arc::new(epoch_config),
201-
)]));
192+
.build_with_simple_epoch_config_store();
202193

203194
let clients = block_and_chunk_producers
204195
.iter()

0 commit comments

Comments
 (0)