Skip to content

Commit efa1b1f

Browse files
committed
test(types): add unit tests for PruningConfig enabled and effective_min_height
1 parent b7a90ad commit efa1b1f

1 file changed

Lines changed: 64 additions & 3 deletions

File tree

crates/types/src/config.rs

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,18 @@ pub struct PruningConfig {
134134
impl PruningConfig {
135135
/// Returns true if pruning is enabled, false otherwise.
136136
pub fn enabled(&self) -> bool {
137-
self.certificates_distance > 0 || self.certificates_before > Height::ZERO
137+
self.certificates_distance > 0 || self.certificates_before > Height::new(0)
138138
}
139139

140140
/// Calculates the effective minimum certificates height to keep based on
141141
/// the current height.
142142
pub fn effective_certificates_min_height(&self, current_height: Height) -> Height {
143-
if self.certificates_before > Height::ZERO {
143+
if self.certificates_before > Height::new(0) {
144144
self.certificates_before
145145
} else if self.certificates_distance > 0 {
146146
current_height.saturating_sub(self.certificates_distance)
147147
} else {
148-
Height::ZERO
148+
Height::new(0)
149149
}
150150
}
151151
}
@@ -398,5 +398,66 @@ mod tests {
398398
config.execution.persistence_backpressure_threshold = 0;
399399
assert!(config.validate().is_err());
400400
}
401+
402+
#[test]
403+
fn pruning_config_disabled_by_default() {
404+
let config = PruningConfig::default();
405+
assert!(!config.enabled());
406+
}
407+
408+
#[test]
409+
fn pruning_config_enabled_by_distance() {
410+
let config = PruningConfig {
411+
certificates_distance: 100,
412+
certificates_before: Height::new(0),
413+
};
414+
assert!(config.enabled());
415+
}
416+
417+
#[test]
418+
fn pruning_config_enabled_by_before() {
419+
let config = PruningConfig {
420+
certificates_distance: 0,
421+
certificates_before: Height::new(50),
422+
};
423+
assert!(config.enabled());
424+
}
425+
426+
#[test]
427+
fn pruning_config_effective_height_uses_before_over_distance() {
428+
let config = PruningConfig {
429+
certificates_distance: 10,
430+
certificates_before: Height::new(42),
431+
};
432+
let result = config.effective_certificates_min_height(Height::new(100));
433+
assert_eq!(result, Height::new(42));
434+
}
435+
436+
#[test]
437+
fn pruning_config_effective_height_distance() {
438+
let config = PruningConfig {
439+
certificates_distance: 30,
440+
certificates_before: Height::new(0),
441+
};
442+
let result = config.effective_certificates_min_height(Height::new(100));
443+
assert_eq!(result, Height::new(70));
444+
}
445+
446+
#[test]
447+
fn pruning_config_effective_height_saturates_at_zero() {
448+
let config = PruningConfig {
449+
certificates_distance: 200,
450+
certificates_before: Height::new(0),
451+
};
452+
let result = config.effective_certificates_min_height(Height::new(50));
453+
assert_eq!(result, Height::new(0));
454+
}
455+
456+
#[test]
457+
fn pruning_config_effective_height_disabled_returns_zero() {
458+
let config = PruningConfig::default();
459+
let result = config.effective_certificates_min_height(Height::new(999));
460+
assert_eq!(result, Height::new(0));
461+
}
401462
}
402463
}

0 commit comments

Comments
 (0)