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
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ impl WorkloadGovernor {
}
admin.require_auth();
storage::set_admin(&env, &admin);
storage::set_global_cap(&env, storage::GLOBAL_APP_LIMIT);
storage::bump_instance(&env);
events::emit_initialized(&env, &admin);
}
Expand Down
21 changes: 21 additions & 0 deletions src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,27 @@ pub(crate) fn extend_app_entry_ttl(
.extend_ttl(&key, APP_TTL_LEDGERS, APP_TTL_LEDGERS);
}

// ---------------------------------------------------------------------------
// Persistent storage — Global application cap
// ---------------------------------------------------------------------------
//
// Key: `symbol_short!("g_cap")`
// Value: `u32`

fn global_cap_key() -> Symbol {
symbol_short!("g_cap")
}

/// Returns the configured global application cap, defaulting to `GLOBAL_APP_LIMIT`.
pub(crate) fn get_global_cap(env: &Env) -> u32 {
env.storage().persistent().get(&global_cap_key()).unwrap_or(GLOBAL_APP_LIMIT)
}

/// Stores a new global application cap.
pub(crate) fn set_global_cap(env: &Env, cap: u32) {
env.storage().persistent().set(&global_cap_key(), &cap);
}

// ---------------------------------------------------------------------------
// Persistent storage — Admin
// ---------------------------------------------------------------------------
Expand Down
8 changes: 6 additions & 2 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,9 +528,11 @@ fn unit_event_initialized_has_two_topics() {
t.client.initialize(&admin);

let events = t.env.events().all();
let (_, topics, _): (_, soroban_sdk::Vec<soroban_sdk::Val>, soroban_sdk::Val) =
let (_, topics, data): (_, soroban_sdk::Vec<soroban_sdk::Val>, soroban_sdk::Val) =
events.last().unwrap();
assert_eq!(topics.len(), 2, "Expected 2-element topics tuple");
let payload = soroban_sdk::vec![&t.env, 1u32, admin.clone()];
assert_eq!(data, payload.into_val(&t.env));
}

#[test]
Expand All @@ -547,9 +549,11 @@ fn unit_event_application_submitted_has_two_topics() {

let events = t.env.events().all();
assert!(!events.is_empty());
let (_, topics, _): (_, soroban_sdk::Vec<soroban_sdk::Val>, soroban_sdk::Val) =
let (_, topics, data): (_, soroban_sdk::Vec<soroban_sdk::Val>, soroban_sdk::Val) =
events.last().unwrap();
assert_eq!(topics.len(), 2, "Expected 2-element topics tuple");
let payload = soroban_sdk::vec![&t.env, 1u32, contributor.clone(), org.clone(), 5u32];
assert_eq!(data, payload.into_val(&t.env));
}

// ---------------------------------------------------------------------------
Expand Down
Loading