diff --git a/src/constants.rs b/src/constants.rs index fe0938be..cbc306ad 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -1,7 +1,8 @@ //! Named constants shared across the contract. //! //! Hoisted here so magic numbers (`9999`, `10000`, `86400`) appear exactly -//! once in the codebase (#482). +//! once in the codebase (#482). All callers import these constants rather +//! than using local literals (#671). /// Basis-point denominator: 10_000 bps == 100%. pub(crate) const BPS_DENOMINATOR: u32 = 10_000; diff --git a/src/tests/test_lifecycle.rs b/src/tests/test_lifecycle.rs index aa831a23..edf843f2 100644 --- a/src/tests/test_lifecycle.rs +++ b/src/tests/test_lifecycle.rs @@ -1,5 +1,5 @@ use super::helpers::*; -use crate::{Category, VotingKey, SECONDS_PER_DAY}; +use crate::{lifecycle::calculate_deadline, Category, Error, VotingKey, SECONDS_PER_DAY}; use soroban_sdk::{FromVal, String, TryFromVal}; // ── lifecycle events ──────────────────────────────────────────────────────────── @@ -430,3 +430,31 @@ fn test_multi_step_sequence() { let id = client.create_campaign(¶ms); client.cancel_campaign(&id); } + +// ── calculate_deadline ─────────────────────────────────────────────────────────── + +#[test] +fn test_calculate_deadline_happy_path() { + let current_time = 1_000_000; + let duration_days = 30; + let expected = current_time + duration_days * SECONDS_PER_DAY; + assert_eq!( + calculate_deadline(current_time, duration_days).unwrap(), + expected + ); +} + +#[test] +fn test_calculate_deadline_zero_days() { + let current_time = 1_000_000; + assert_eq!(calculate_deadline(current_time, 0).unwrap(), current_time); +} + +#[test] +fn test_calculate_deadline_overflow_rejected() { + let huge_days = u64::MAX / SECONDS_PER_DAY + 1; + assert_eq!( + calculate_deadline(0, huge_days), + Err(Error::ValidationFailed) + ); +}