|
1 |
| -use std::collections::{BTreeMap, HashMap, HashSet}; |
2 |
| -use std::sync::Arc; |
| 1 | +use std::collections::{HashMap, HashSet}; |
3 | 2 |
|
4 | 3 | use near_crypto::PublicKey;
|
5 | 4 | use near_primitives::account::{AccessKey, Account, AccountContract};
|
@@ -392,6 +391,14 @@ impl TestGenesisBuilder {
|
392 | 391 | self
|
393 | 392 | }
|
394 | 393 |
|
| 394 | + /// Creates epoch config builder compatible with the current genesis builder state |
| 395 | + pub fn derive_epoch_config_builder(&self) -> TestEpochConfigBuilder { |
| 396 | + TestEpochConfigBuilder::new() |
| 397 | + .epoch_length(self.epoch_length) |
| 398 | + .shard_layout(self.shard_layout.clone()) |
| 399 | + .validators_spec(self.validators_spec.clone()) |
| 400 | + } |
| 401 | + |
395 | 402 | pub fn build(self) -> Genesis {
|
396 | 403 | if self
|
397 | 404 | .user_accounts
|
@@ -512,6 +519,16 @@ impl TestGenesisBuilder {
|
512 | 519 | contents: GenesisContents::Records { records: GenesisRecords(records) },
|
513 | 520 | }
|
514 | 521 | }
|
| 522 | + |
| 523 | + // Builds genesis along with epoch config store containing single epoch config |
| 524 | + // for the genesis protocol version. |
| 525 | + pub fn build_with_simple_epoch_config_store(self) -> (Genesis, EpochConfigStore) { |
| 526 | + let epoch_config = self.derive_epoch_config_builder().build(); |
| 527 | + let genesis = self.build(); |
| 528 | + let epoch_config_store = |
| 529 | + EpochConfigStore::test_single_version(genesis.config.protocol_version, epoch_config); |
| 530 | + (genesis, epoch_config_store) |
| 531 | + } |
515 | 532 | }
|
516 | 533 |
|
517 | 534 | impl ValidatorsSpec {
|
@@ -671,21 +688,17 @@ pub fn build_genesis_and_epoch_config_store<'a>(
|
671 | 688 | .genesis_time_from_clock(&FakeClock::default().clock())
|
672 | 689 | .protocol_version(protocol_version)
|
673 | 690 | .epoch_length(epoch_length)
|
674 |
| - .shard_layout(shard_layout.clone()) |
675 |
| - .validators_spec(validators_spec.clone()) |
| 691 | + .shard_layout(shard_layout) |
| 692 | + .validators_spec(validators_spec) |
676 | 693 | .add_user_accounts_simple(accounts, 1_000_000 * ONE_NEAR)
|
677 | 694 | .gas_limit_one_petagas();
|
678 |
| - let epoch_config_builder = TestEpochConfigBuilder::new() |
679 |
| - .epoch_length(epoch_length) |
680 |
| - .shard_layout(shard_layout) |
681 |
| - .validators_spec(validators_spec); |
| 695 | + let epoch_config_builder = genesis_builder.derive_epoch_config_builder(); |
682 | 696 | let genesis_builder = customize_genesis_builder(genesis_builder);
|
683 | 697 | let epoch_config_builder = customize_epoch_config_builder(epoch_config_builder);
|
684 | 698 |
|
685 | 699 | let genesis = genesis_builder.build();
|
686 | 700 | let epoch_config = epoch_config_builder.build();
|
687 |
| - let epoch_config_store = |
688 |
| - EpochConfigStore::test(BTreeMap::from([(protocol_version, Arc::new(epoch_config))])); |
| 701 | + let epoch_config_store = EpochConfigStore::test_single_version(protocol_version, epoch_config); |
689 | 702 |
|
690 | 703 | (genesis, epoch_config_store)
|
691 | 704 | }
|
0 commit comments