Skip to content

Commit

Permalink
add non-decreasing test
Browse files Browse the repository at this point in the history
  • Loading branch information
Cifko committed Apr 16, 2024
1 parent 545dd8c commit 7b41d15
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions base_layer/core/src/consensus/consensus_manager.rs
Expand Up @@ -323,9 +323,8 @@ mod tests {
use super::*;
use crate::consensus::ConsensusConstantsBuilder;

#[test]
fn test_epoch_to_height_and_back() {
let manager = ConsensusManager::builder(Network::LocalNet)
fn create_manager() -> ConsensusManager {
ConsensusManager::builder(Network::LocalNet)
.add_consensus_constants(
ConsensusConstantsBuilder::new(Network::LocalNet)
.with_effective_height(0)
Expand Down Expand Up @@ -363,7 +362,12 @@ mod tests {
.build(),
)
.build()
.unwrap();
.unwrap()
}

#[test]
fn test_epoch_to_height_and_back() {
let manager = create_manager();
assert_eq!(manager.block_height_to_epoch(99), VnEpoch(6)); // The next epoch should change at 105
assert_eq!(manager.block_height_to_epoch(100), VnEpoch(7)); // But with the new length the epoch should change right away
assert_eq!(manager.block_height_to_epoch(199), VnEpoch(23)); // The next epoch should change at 202
Expand All @@ -377,4 +381,14 @@ mod tests {
);
}
}

#[test]
fn test_epoch_is_non_decreasing() {
let manager = create_manager();
let mut epoch = manager.block_height_to_epoch(0).as_u64();
for height in 0..600 {
assert!(manager.block_height_to_epoch(height).as_u64() >= epoch);
epoch = manager.block_height_to_epoch(height).as_u64();
}
}
}

0 comments on commit 7b41d15

Please sign in to comment.