Skip to content
Merged
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
9 changes: 9 additions & 0 deletions apexchainx_calculator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ const PAUSED_KEY: Symbol = symbol_short!("PAUSED");
/// Pause metadata (reason, timestamp, caller). (#66)
const PAUSE_INFO_KEY: Symbol = symbol_short!("PAUSEINF");

/// Maximum length (in bytes) for the pause reason string. (#68)
const MAX_REASON_LEN: usize = 256;

/// Cumulative SLA statistics (SLAStats struct). (#29)
const STATS_KEY: Symbol = symbol_short!("STATS");

Expand Down Expand Up @@ -247,6 +250,8 @@ pub enum SLAError {
InvalidPenaltyAmount = 14,
/// Computed reward amount is invalid (e.g., zero or negative). (SC-W5-046)
InvalidRewardAmount = 15,
/// Input parameter violates documented constraints (e.g., reason too long). (#68)
InvalidInput = 16,
}

// -----------------------------------------------------------------------
Expand Down Expand Up @@ -782,6 +787,10 @@ impl SLACalculatorContract {
Self::check_version(&env)?;
Self::require_admin(&env, &caller)?;

if reason.len() > MAX_REASON_LEN as u32 {
return Err(SLAError::InvalidInput);
}

let paused_at = env.ledger().timestamp();
env.storage().instance().set(&PAUSED_KEY, &true);
env.storage().instance().set(
Expand Down
9 changes: 9 additions & 0 deletions apexchainx_calculator/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1918,6 +1918,15 @@ fn test_pause_stores_reason_and_timestamp() {
let _ = info.paused_at;
}

#[test]
#[should_panic(expected = "#16")]
fn test_pause_rejects_long_reason() {
let (env, client, actors) = setup();
// 257-byte reason exceeds MAX_REASON_LEN (256)
let long_reason = soroban_sdk::String::from_str(&env, &"A".repeat(257));
client.pause(&actors.admin, &long_reason);
}

#[test]
fn test_unpause_clears_pause_info() {
let (env, client, actors) = setup();
Expand Down
Loading