Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eagr committed Dec 20, 2024
1 parent 64ae526 commit c556314
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
8 changes: 4 additions & 4 deletions chain/epoch-manager/src/validator_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1038,10 +1038,10 @@ mod tests {
// Given `epoch_info` and `proposals` above, the sample at a given height is deterministic.
let height = 42;
let expected_assignments = vec![
vec![(4, 56), (1, 168), (2, 300), (3, 84), (0, 364)],
vec![(3, 70), (1, 300), (4, 42), (2, 266), (0, 308)],
vec![(4, 42), (1, 238), (3, 42), (0, 450), (2, 196)],
vec![(2, 238), (1, 294), (3, 64), (0, 378)],
vec![(2, 192), (0, 396), (1, 280)],
vec![(1, 216), (2, 264), (0, 396)],
vec![(0, 396), (2, 288), (1, 192)],
vec![(2, 256), (1, 312), (0, 312)],
];
assert_eq!(epoch_info.sample_chunk_validators(height), expected_assignments);
}
Expand Down
22 changes: 22 additions & 0 deletions core/chain-configs/src/test_genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,28 @@ pub struct GenesisAndEpochConfigParams<'a> {
/// one epoch config for your test. Otherwise, just use builders directly.
///
/// ```
/// use near_chain_configs::test_genesis::build_genesis_and_epoch_config_store;
/// use near_chain_configs::test_genesis::GenesisAndEpochConfigParams;
/// use near_chain_configs::test_genesis::ValidatorsSpec;
/// use near_primitives::shard_layout::ShardLayout;
/// use near_primitives::test_utils::create_test_signer;
/// use near_primitives::types::AccountId;
/// use near_primitives::types::AccountInfo;
///
/// const ONE_NEAR: u128 = 1_000_000_000_000_000_000_000_000;
///
/// let protocol_version = 73;
/// let epoch_length = 10;
/// let accounts = (0..6).map(|i| format!("test{}", i).parse().unwrap()).collect::<Vec<AccountId>>();
/// let shard_layout = ShardLayout::multi_shard(6, 1);
/// let validators = vec![
/// AccountInfo {
/// account_id: accounts[0].clone(),
/// public_key: create_test_signer(accounts[0].as_str()).public_key(),
/// amount: 62500 * ONE_NEAR,
/// },
/// ];
/// let validators_spec = ValidatorsSpec::raw(validators, 3, 3, 3);
/// let (genesis, epoch_config_store) = build_genesis_and_epoch_config_store(
/// GenesisAndEpochConfigParams {
/// protocol_version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn slow_test_fix_cp_stake_threshold() {
AccountInfo {
account_id: accounts[2].clone(),
public_key: create_test_signer(accounts[2].as_str()).public_key(),
// cp min stake ratio was (1 / 62500) / num_shards before the fix
// cp min stake ratio was `(1 / 62500) / num_shards` before the fix
// stake is right at threshold, and proposal should not be approved
amount: ((30 + 30) * 62500 / 62500 / num_shards) as u128 * ONE_NEAR,
},
Expand Down Expand Up @@ -109,7 +109,7 @@ fn slow_test_fix_cp_stake_threshold() {
.unwrap();
let protocol_version =
client.epoch_manager.get_epoch_protocol_version(&epoch_id).unwrap();
// exits when protocol version catches up the fix
// exits when protocol version catches up with the fix
protocol_version >= ProtocolFeature::FixChunkProducerStakingThreshold.protocol_version()
},
Duration::seconds(4 * epoch_length as i64),
Expand All @@ -126,9 +126,8 @@ fn slow_test_fix_cp_stake_threshold() {
// ensure loop is exited because of condition is met
assert!(epoch_height < 5);

// after the fix, threshold is raised to approximately 6x of the previous in this case
// (reason of "approximately 6x": ./fix_stake_threshold.rs, but it's irrelevant here)
// so test3's proposal will not be approved
// threshold is raised to approximately 6x of the previous in this case as threshold is
// no longer divided by num_shards (6), so test3's proposal won't be approved
let validators = get_epoch_all_validators(client);
if validators.len() == 2 {
assert_eq!(validators, vec![String::from("test0"), String::from("test1")]);
Expand Down

0 comments on commit c556314

Please sign in to comment.