Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/constants.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
30 changes: 29 additions & 1 deletion src/tests/test_lifecycle.rs
Original file line number Diff line number Diff line change
@@ -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 ────────────────────────────────────────────────────────────
Expand Down Expand Up @@ -430,3 +430,31 @@ fn test_multi_step_sequence() {
let id = client.create_campaign(&params);
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)
);
}
Loading