Skip to content

Commit 9ec4e25

Browse files
pugachAGshreyan-gupta
authored andcommitted
test: remove build_genesis_and_epoch_config_store (near#13004)
This PR replaces `build_genesis_and_epoch_config_store` with direct usage of builders introduced in near#12995.
1 parent ec41f25 commit 9ec4e25

19 files changed

+211
-403
lines changed

core/chain-configs/src/test_genesis.rs

+1-78
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use near_primitives::types::{
1212
};
1313
use near_primitives::utils::from_timestamp;
1414
use near_primitives::version::PROTOCOL_VERSION;
15-
use near_time::{Clock, FakeClock};
15+
use near_time::Clock;
1616
use num_rational::Rational32;
1717

1818
use crate::{
@@ -628,80 +628,3 @@ fn derive_validator_setup(specs: ValidatorsSpec) -> DerivedValidatorSetup {
628628
},
629629
}
630630
}
631-
632-
pub struct GenesisAndEpochConfigParams<'a> {
633-
pub epoch_length: BlockHeightDelta,
634-
pub protocol_version: ProtocolVersion,
635-
pub shard_layout: ShardLayout,
636-
pub validators_spec: ValidatorsSpec,
637-
pub accounts: &'a Vec<AccountId>,
638-
}
639-
640-
/// Handy factory for building test genesis and epoch config store. Use it if it is enough to have
641-
/// one epoch config for your test. Otherwise, just use builders directly.
642-
///
643-
/// ```
644-
/// use near_chain_configs::test_genesis::build_genesis_and_epoch_config_store;
645-
/// use near_chain_configs::test_genesis::GenesisAndEpochConfigParams;
646-
/// use near_chain_configs::test_genesis::ValidatorsSpec;
647-
/// use near_primitives::shard_layout::ShardLayout;
648-
/// use near_primitives::test_utils::create_test_signer;
649-
/// use near_primitives::types::AccountId;
650-
/// use near_primitives::types::AccountInfo;
651-
///
652-
/// const ONE_NEAR: u128 = 1_000_000_000_000_000_000_000_000;
653-
///
654-
/// let protocol_version = 73;
655-
/// let epoch_length = 10;
656-
/// let accounts = (0..6).map(|i| format!("test{}", i).parse().unwrap()).collect::<Vec<AccountId>>();
657-
/// let shard_layout = ShardLayout::multi_shard(6, 1);
658-
/// let validators = vec![
659-
/// AccountInfo {
660-
/// account_id: accounts[0].clone(),
661-
/// public_key: create_test_signer(accounts[0].as_str()).public_key(),
662-
/// amount: 62500 * ONE_NEAR,
663-
/// },
664-
/// ];
665-
/// let validators_spec = ValidatorsSpec::raw(validators, 3, 3, 3);
666-
/// let (genesis, epoch_config_store) = build_genesis_and_epoch_config_store(
667-
/// GenesisAndEpochConfigParams {
668-
/// protocol_version,
669-
/// epoch_length,
670-
/// accounts: &accounts,
671-
/// shard_layout,
672-
/// validators_spec,
673-
/// },
674-
/// |genesis_builder| genesis_builder.genesis_height(10000).transaction_validity_period(1000),
675-
/// |epoch_config_builder| epoch_config_builder.shuffle_shard_assignment_for_chunk_producers(true),
676-
/// );
677-
/// ```
678-
pub fn build_genesis_and_epoch_config_store<'a>(
679-
params: GenesisAndEpochConfigParams<'a>,
680-
customize_genesis_builder: impl FnOnce(TestGenesisBuilder) -> TestGenesisBuilder,
681-
customize_epoch_config_builder: impl FnOnce(TestEpochConfigBuilder) -> TestEpochConfigBuilder,
682-
) -> (Genesis, EpochConfigStore) {
683-
let GenesisAndEpochConfigParams {
684-
epoch_length,
685-
protocol_version,
686-
shard_layout,
687-
validators_spec,
688-
accounts,
689-
} = params;
690-
691-
let genesis_builder = TestGenesisBuilder::new()
692-
.genesis_time_from_clock(&FakeClock::default().clock())
693-
.protocol_version(protocol_version)
694-
.epoch_length(epoch_length)
695-
.shard_layout(shard_layout)
696-
.validators_spec(validators_spec)
697-
.add_user_accounts_simple(accounts, 1_000_000 * ONE_NEAR)
698-
.gas_limit_one_petagas();
699-
let genesis_builder = customize_genesis_builder(genesis_builder);
700-
let genesis = genesis_builder.build();
701-
702-
let epoch_config_builder = TestEpochConfigBuilder::from_genesis(&genesis);
703-
let epoch_config_builder = customize_epoch_config_builder(epoch_config_builder);
704-
let epoch_config_store = epoch_config_builder.build_store_for_single_version(protocol_version);
705-
706-
(genesis, epoch_config_store)
707-
}

integration-tests/src/tests/features/in_memory_tries.rs

+13-23
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ use near_async::messaging::CanSend;
22
use near_async::time::{FakeClock, Utc};
33
use near_chain::{Block, Provenance};
44
use near_chain_configs::test_genesis::{
5-
GenesisAndEpochConfigParams, TestGenesisBuilder, ValidatorsSpec,
6-
build_genesis_and_epoch_config_store,
5+
TestEpochConfigBuilder, TestGenesisBuilder, ValidatorsSpec,
76
};
87
use near_chunks::shards_manager_actor::CHUNK_REQUEST_SWITCH_TO_FULL_FETCH;
98
use near_chunks::test_utils::ShardsManagerResendChunkRequests;
@@ -14,7 +13,6 @@ use near_primitives::shard_layout::ShardLayout;
1413
use near_primitives::test_utils::create_user_test_signer;
1514
use near_primitives::transaction::SignedTransaction;
1615
use near_primitives::types::EpochId;
17-
use near_primitives::version::PROTOCOL_VERSION;
1816
use near_primitives_core::types::AccountId;
1917
use near_store::test_utils::create_test_store;
2018
use near_store::{ShardUId, TrieConfig};
@@ -42,7 +40,6 @@ fn slow_test_in_memory_trie_node_consistency() {
4240

4341
let genesis = TestGenesisBuilder::new()
4442
.genesis_time_from_clock(&clock.clock())
45-
.protocol_version(PROTOCOL_VERSION)
4643
.epoch_length(epoch_length)
4744
.shard_layout(shard_layout)
4845
.validators_spec(validators_spec)
@@ -419,31 +416,24 @@ fn test_in_memory_trie_consistency_with_state_sync_base_case(track_all_shards: b
419416

420417
let mut clock = FakeClock::new(Utc::UNIX_EPOCH);
421418

422-
let epoch_length = 10;
423419
let shard_layout = ShardLayout::simple_v1(&["account3", "account5", "account7"]);
424420
let validators_spec = ValidatorsSpec::desired_roles(
425421
&accounts[0..NUM_VALIDATORS].iter().map(|a| a.as_str()).collect::<Vec<_>>(),
426422
&[],
427423
);
428424

429-
let (genesis, epoch_config_store) = build_genesis_and_epoch_config_store(
430-
GenesisAndEpochConfigParams {
431-
epoch_length,
432-
protocol_version: PROTOCOL_VERSION,
433-
shard_layout,
434-
validators_spec,
435-
accounts: &accounts,
436-
},
437-
|genesis_builder| {
438-
genesis_builder
439-
.genesis_time_from_clock(&clock.clock())
440-
.genesis_height(10000)
441-
.transaction_validity_period(1000)
442-
},
443-
|epoch_config_builder| {
444-
epoch_config_builder.minimum_validators_per_shard(NUM_VALIDATORS_PER_SHARD as u64)
445-
},
446-
);
425+
let genesis = TestGenesisBuilder::new()
426+
.genesis_time_from_clock(&clock.clock())
427+
.genesis_height(10000)
428+
.epoch_length(10)
429+
.transaction_validity_period(1000)
430+
.shard_layout(shard_layout)
431+
.validators_spec(validators_spec)
432+
.add_user_accounts_simple(&accounts, initial_balance)
433+
.build();
434+
let epoch_config_store = TestEpochConfigBuilder::from_genesis(&genesis)
435+
.minimum_validators_per_shard(NUM_VALIDATORS_PER_SHARD as u64)
436+
.build_store_for_single_version(genesis.config.protocol_version);
447437

448438
let stores = (0..NUM_VALIDATORS).map(|_| create_test_store()).collect::<Vec<_>>();
449439
let mut env = TestEnv::builder(&genesis.config)

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

+11-16
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ use near_async::test_loop::futures::TestLoopFutureSpawner;
2424
use near_async::test_loop::sender::TestLoopSender;
2525
use near_async::time::Duration;
2626
use near_chain::{ChainStoreAccess, ReceiptFilter, get_incoming_receipts_for_shard};
27-
use near_chain_configs::test_genesis::{
28-
GenesisAndEpochConfigParams, ValidatorsSpec, build_genesis_and_epoch_config_store,
29-
};
27+
use near_chain_configs::test_genesis::{TestEpochConfigBuilder, ValidatorsSpec};
3028
use near_client::Client;
3129
use near_client::client_actor::ClientActorInner;
3230
use near_crypto::Signer;
@@ -46,7 +44,6 @@ use near_primitives::shard_layout::ShardLayout;
4644
use near_primitives::test_utils::create_user_test_signer;
4745
use near_primitives::transaction::SignedTransaction;
4846
use near_primitives::types::{AccountId, BlockHeight, Nonce, ShardId, ShardIndex};
49-
use near_primitives::version::PROTOCOL_VERSION;
5047
use near_store::adapter::StoreAdapter;
5148
use near_store::trie::outgoing_metadata::{ReceiptGroupsConfig, ReceiptGroupsQueue};
5249
use near_store::trie::receipts_column_helper::{ShardsOutgoingReceiptBuffer, TrieQueue};
@@ -61,8 +58,8 @@ use testlib::bandwidth_scheduler::{
6158

6259
use crate::builder::TestLoopBuilder;
6360
use crate::env::{TestData, TestLoopEnv};
64-
use crate::utils::TGAS;
6561
use crate::utils::transactions::{TransactionRunner, run_txs_parallel};
62+
use crate::utils::{ONE_NEAR, TGAS};
6663

6764
/// 3 shards, random receipt sizes
6865
#[test]
@@ -155,17 +152,15 @@ fn run_bandwidth_scheduler_test(scenario: TestScenario, tx_concurrency: usize) -
155152

156153
// Build TestLoop
157154
let validators_spec = ValidatorsSpec::desired_roles(&[node_account.as_str()], &[]);
158-
let (genesis, epoch_config_store) = build_genesis_and_epoch_config_store(
159-
GenesisAndEpochConfigParams {
160-
epoch_length,
161-
protocol_version: PROTOCOL_VERSION,
162-
shard_layout,
163-
validators_spec,
164-
accounts: &all_accounts,
165-
},
166-
|genesis_builder| genesis_builder.genesis_height(10000).transaction_validity_period(1000),
167-
|epoch_config_builder| epoch_config_builder,
168-
);
155+
let genesis = TestLoopBuilder::new_genesis_builder()
156+
.epoch_length(epoch_length)
157+
.shard_layout(shard_layout)
158+
.validators_spec(validators_spec)
159+
.add_user_accounts_simple(&all_accounts, 1_000_000 * ONE_NEAR)
160+
.genesis_height(10000)
161+
.transaction_validity_period(1000)
162+
.build();
163+
let epoch_config_store = TestEpochConfigBuilder::build_store_from_genesis(&genesis);
169164

170165
let TestLoopEnv { mut test_loop, datas: node_datas, tempdir } = TestLoopBuilder::new()
171166
.genesis(genesis)

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

+13-20
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
use crate::builder::TestLoopBuilder;
22
use crate::env::TestLoopEnv;
3+
use crate::utils::ONE_NEAR;
34
use crate::utils::validators::get_epoch_all_validators;
45
use itertools::Itertools;
56
use near_async::test_loop::data::TestLoopData;
67
use near_async::time::Duration;
7-
use near_chain_configs::test_genesis::{
8-
GenesisAndEpochConfigParams, ValidatorsSpec, build_genesis_and_epoch_config_store,
9-
};
8+
use near_chain_configs::test_genesis::{TestEpochConfigBuilder, ValidatorsSpec};
109
use near_o11y::testonly::init_test_logger;
1110
use near_primitives::shard_layout::ShardLayout;
1211
use near_primitives::types::AccountId;
13-
use near_primitives::version::PROTOCOL_VERSION;
1412

1513
const NUM_ACCOUNTS: usize = 8;
1614
const NUM_PRODUCER_ACCOUNTS: usize = 6;
@@ -77,22 +75,17 @@ fn run_test_chunk_validator_kickout(accounts: Vec<AccountId>, test_case: TestCas
7775
let validators_spec =
7876
ValidatorsSpec::desired_roles(block_and_chunk_producers, chunk_validators_only);
7977

80-
let (genesis, epoch_config_store) = build_genesis_and_epoch_config_store(
81-
GenesisAndEpochConfigParams {
82-
epoch_length,
83-
protocol_version: PROTOCOL_VERSION,
84-
shard_layout,
85-
validators_spec,
86-
accounts: &accounts,
87-
},
88-
|genesis_builder| genesis_builder,
89-
|epoch_config_builder| {
90-
epoch_config_builder
91-
// Set up config to kick out only chunk validators for low performance.
92-
.kickouts_for_chunk_validators_only()
93-
.target_validator_mandates_per_shard(num_validator_mandates_per_shard)
94-
},
95-
);
78+
let genesis = TestLoopBuilder::new_genesis_builder()
79+
.epoch_length(epoch_length)
80+
.shard_layout(shard_layout)
81+
.validators_spec(validators_spec)
82+
.add_user_accounts_simple(&accounts, 1_000_000 * ONE_NEAR)
83+
.build();
84+
let epoch_config_store = TestEpochConfigBuilder::from_genesis(&genesis)
85+
// Set up config to kick out only chunk validators for low performance.
86+
.kickouts_for_chunk_validators_only()
87+
.target_validator_mandates_per_shard(num_validator_mandates_per_shard)
88+
.build_store_for_single_version(genesis.config.protocol_version);
9689

9790
let TestLoopEnv { mut test_loop, datas: node_datas, tempdir } =
9891
builder.genesis(genesis).epoch_config_store(epoch_config_store).clients(clients).build();

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

+13-18
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,16 @@ use itertools::Itertools;
44
use near_async::test_loop::TestLoopV2;
55
use near_async::test_loop::data::{TestLoopData, TestLoopDataHandle};
66
use near_async::time::Duration;
7-
use near_chain_configs::test_genesis::{
8-
GenesisAndEpochConfigParams, ValidatorsSpec, build_genesis_and_epoch_config_store,
9-
};
7+
use near_chain_configs::test_genesis::{TestEpochConfigBuilder, ValidatorsSpec};
108
use near_client::client_actor::ClientActorInner;
119
use near_o11y::testonly::init_test_logger;
1210
use near_primitives::shard_layout::ShardLayout;
1311
use near_primitives::types::{AccountId, BlockHeight};
14-
use near_primitives::version::PROTOCOL_VERSION;
1512

1613
use crate::builder::TestLoopBuilder;
1714
use crate::env::{TestData, TestLoopEnv};
18-
use crate::utils::TGAS;
1915
use crate::utils::transactions::{call_contract, check_txs, deploy_contract, make_accounts};
16+
use crate::utils::{ONE_NEAR, TGAS};
2017

2118
const NUM_ACCOUNTS: usize = 100;
2219
const NUM_PRODUCERS: usize = 2;
@@ -79,19 +76,17 @@ fn setup(accounts: &Vec<AccountId>) -> (TestLoopEnv, AccountId) {
7976
let shard_layout = ShardLayout::simple_v1(&["account3", "account5", "account7"]);
8077
let validators_spec = ValidatorsSpec::desired_roles(&producers, &validators);
8178

82-
let (genesis, epoch_config_store) = build_genesis_and_epoch_config_store(
83-
GenesisAndEpochConfigParams {
84-
epoch_length,
85-
protocol_version: PROTOCOL_VERSION,
86-
shard_layout,
87-
validators_spec,
88-
accounts: &accounts,
89-
},
90-
|genesis_builder| genesis_builder.genesis_height(10000).transaction_validity_period(1000),
91-
|epoch_config_builder| {
92-
epoch_config_builder.shuffle_shard_assignment_for_chunk_producers(true)
93-
},
94-
);
79+
let genesis = TestLoopBuilder::new_genesis_builder()
80+
.epoch_length(epoch_length)
81+
.shard_layout(shard_layout)
82+
.validators_spec(validators_spec)
83+
.add_user_accounts_simple(&accounts, 1_000_000 * ONE_NEAR)
84+
.genesis_height(10000)
85+
.transaction_validity_period(1000)
86+
.build();
87+
let epoch_config_store = TestEpochConfigBuilder::from_genesis(&genesis)
88+
.shuffle_shard_assignment_for_chunk_producers(true)
89+
.build_store_for_single_version(genesis.config.protocol_version);
9590

9691
let env = TestLoopBuilder::new()
9792
.genesis(genesis)

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

+11-14
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use near_async::time::Duration;
22
use near_chain::ChainStoreAccess;
3-
use near_chain_configs::test_genesis::{
4-
GenesisAndEpochConfigParams, ValidatorsSpec, build_genesis_and_epoch_config_store,
5-
};
3+
use near_chain_configs::test_genesis::{TestEpochConfigBuilder, ValidatorsSpec};
64
use near_client::Client;
75
use near_o11y::testonly::init_test_logger;
86
use near_primitives::shard_layout::ShardLayout;
@@ -11,6 +9,7 @@ use near_primitives::version::{PROTOCOL_VERSION, ProtocolFeature};
119

1210
use crate::builder::TestLoopBuilder;
1311
use crate::env::TestLoopEnv;
12+
use crate::utils::ONE_NEAR;
1413

1514
const NUM_SHARDS: usize = 4;
1615

@@ -34,17 +33,15 @@ fn test_congestion_control_genesis_bootstrap() {
3433
let shard_layout = ShardLayout::simple_v1(&["account3", "account5", "account7"]);
3534
let validators_spec = ValidatorsSpec::desired_roles(&accounts[0..1], &accounts[1..2]);
3635

37-
let (genesis, epoch_config_store) = build_genesis_and_epoch_config_store(
38-
GenesisAndEpochConfigParams {
39-
epoch_length,
40-
protocol_version: PROTOCOL_VERSION,
41-
shard_layout,
42-
validators_spec,
43-
accounts: &clients,
44-
},
45-
|genesis_builder| genesis_builder,
46-
|epoch_config_builder| epoch_config_builder.minimum_validators_per_shard(1),
47-
);
36+
let genesis = TestLoopBuilder::new_genesis_builder()
37+
.epoch_length(epoch_length)
38+
.shard_layout(shard_layout)
39+
.validators_spec(validators_spec)
40+
.add_user_accounts_simple(&clients, 1_000_000 * ONE_NEAR)
41+
.build();
42+
let epoch_config_store = TestEpochConfigBuilder::from_genesis(&genesis)
43+
.minimum_validators_per_shard(1)
44+
.build_store_for_single_version(genesis.config.protocol_version);
4845

4946
let TestLoopEnv { mut test_loop, datas: node_datas, tempdir } = builder
5047
.genesis(genesis)

0 commit comments

Comments
 (0)