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
6 changes: 5 additions & 1 deletion soroban/contracts/farming-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ impl FarmingPool {

// ── Pause / Unpause ───────────────────────────────────────────────────────

/// Admin: pause the pool. While paused, `lock_assets` and `unlock_assets` are blocked.
/// Admin: pause the pool. While paused, `lock_assets`, `unlock_assets`, `stake`,
/// `unstake`, and `set_boost` are blocked.
///
/// Emits a `("pool", "paused")` event.
pub fn pause(env: Env) -> Result<(), PoolError> {
Expand Down Expand Up @@ -437,6 +438,7 @@ impl FarmingPool {
/// Stake `amount` tokens. If a prior stake exists, earned credits are checkpointed first.
pub fn stake(env: Env, from: Address, amount: i128) -> Result<(), PoolError> {
from.require_auth();
assert!(!pool_is_paused(&env), "pool is paused");
require_initialized(&env)?;
assert!(amount > 0, "amount must be positive");
bump_instance(&env);
Expand Down Expand Up @@ -469,6 +471,7 @@ impl FarmingPool {
/// Unstake all tokens. Returns the total credits earned.
pub fn unstake(env: Env, from: Address) -> Result<i128, PoolError> {
from.require_auth();
assert!(!pool_is_paused(&env), "pool is paused");
require_initialized(&env)?;
bump_instance(&env);

Expand Down Expand Up @@ -496,6 +499,7 @@ impl FarmingPool {
/// Emits a `boost_applied` event.
pub fn set_boost(env: Env, user: Address, allocation_pct: u32) -> Result<(), PoolError> {
user.require_auth();
assert!(!pool_is_paused(&env), "pool is paused");
require_initialized(&env)?;
assert!(
allocation_pct >= 1 && allocation_pct <= 100,
Expand Down
65 changes: 65 additions & 0 deletions soroban/contracts/farming-pool/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,71 @@ fn test_unpause_emits_event() {
);
}

#[test]
fn test_pause_blocks_stake() {
let t = setup(1, 1);
t.client.pause();
assert!(t.client.try_stake(&t.user, &100i128).is_err());
}

#[test]
fn test_unpause_restores_stake() {
let t = setup(1, 1);
t.client.pause();
t.client.unpause();
t.client.stake(&t.user, &500);
assert_eq!(t.client.get_stake(&t.user).unwrap().amount, 500);
}

#[test]
fn test_pause_blocks_unstake() {
let t = setup(1, 1);
t.client.stake(&t.user, &1_000);
t.client.pause();
assert!(t.client.try_unstake(&t.user).is_err());
}

#[test]
fn test_unpause_restores_unstake() {
let t = setup(1, 1);
t.client.stake(&t.user, &1_000);
t.client.pause();
t.client.unpause();
t.client.unstake(&t.user);
assert!(t.client.get_stake(&t.user).is_none());
}

#[test]
fn test_pause_blocks_set_boost() {
let t = setup(1, 1);
t.client.stake(&t.user, &1_000);
t.client.pause();
assert!(t.client.try_set_boost(&t.user, &50u32).is_err());
}

#[test]
fn test_unpause_restores_set_boost() {
let t = setup(1, 1);
t.client.stake(&t.user, &1_000);
t.client.pause();
t.client.unpause();
t.client.set_boost(&t.user, &50u32);
assert_eq!(
t.client.get_boost_config(&t.user).unwrap().allocation_pct,
50
);
}

#[test]
fn test_set_global_multiplier_callable_while_paused() {
let t = setup(1, 1);
t.client.stake(&t.user, &1_000);
t.client.set_boost(&t.user, &50u32);
t.client.pause();
t.client.set_global_multiplier(&3u32);
assert_eq!(t.client.get_boost_config(&t.user).unwrap().multiplier, 3);
}

// ── multi-user isolation ──────────────────────────────────────────────────────

#[test]
Expand Down
Loading
Loading