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
14 changes: 10 additions & 4 deletions contracts/admin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl AdminContract {
/// Set the cooldown period (in seconds) between admin actions.
pub fn set_admin_cooldown(env: Env, admin: Address, seconds: u64) -> Result<(), ContractError> {
admin.require_auth();

let stored_admin: Address = env
.storage()
.instance()
Expand All @@ -62,7 +62,9 @@ impl AdminContract {
return Err(ContractError::Unauthorized);
}

env.storage().persistent().set(&DataKey::AdminCooldownSeconds, &seconds);
env.storage()
.persistent()
.set(&DataKey::AdminCooldownSeconds, &seconds);
Ok(())
}

Expand All @@ -75,9 +77,13 @@ impl AdminContract {
}

/// Check and enforce admin cooldown for a specific function.
pub fn check_admin_cooldown(env: Env, admin: Address, function_name: Symbol) -> Result<(), ContractError> {
pub fn check_admin_cooldown(
env: Env,
admin: Address,
function_name: Symbol,
) -> Result<(), ContractError> {
admin.require_auth();

let stored_admin: Address = env
.storage()
.instance()
Expand Down
8 changes: 4 additions & 4 deletions contracts/admin/tests/gas_snap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ fn snapshot_check_admin_cooldown() {
fixture.initialize();
let client = fixture.client();
client.set_admin_cooldown(&fixture.admin, &300);

let func_name = Symbol::new(&fixture.env, "test_action");

reset_budget(&fixture.env);
Expand Down Expand Up @@ -208,12 +208,12 @@ fn rejects_cooldown_when_active() {
fixture.initialize();
let client = fixture.client();
client.set_admin_cooldown(&fixture.admin, &300);

let func_name = Symbol::new(&fixture.env, "test_action");

// First call should succeed (would panic on Err since this is the non-try_ client method)
client.check_admin_cooldown(&fixture.admin, &func_name);

// Immediate second call should fail due to cooldown
assert_eq!(
client.try_check_admin_cooldown(&fixture.admin, &func_name),
Expand Down
16 changes: 9 additions & 7 deletions contracts/migrate/tests/err_migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ impl Fixture {
let admin = Address::generate(&env);
let client = MigrateContractClient::new(&env, &contract_id);
client.initialize(&admin, &initial_version);
Self {
env,
client,
admin,
}
Self { env, client, admin }
}
}

Expand All @@ -54,7 +50,10 @@ fn successful_migration_bumps_version() {
fn migration_can_skip_multiple_versions() {
let f = Fixture::new(1);

assert_eq!(f.client.try_migrate_error_data(&f.admin, &1, &5), Ok(Ok(())));
assert_eq!(
f.client.try_migrate_error_data(&f.admin, &1, &5),
Ok(Ok(()))
);
assert_eq!(f.client.current_version(), 5);
}

Expand All @@ -64,7 +63,10 @@ fn migrate_from_non_default_start() {
// migrate forward — demonstrating non-default starting points work.
let f = Fixture::new(2);

assert_eq!(f.client.try_migrate_error_data(&f.admin, &2, &3), Ok(Ok(())));
assert_eq!(
f.client.try_migrate_error_data(&f.admin, &2, &3),
Ok(Ok(()))
);
assert_eq!(f.client.current_version(), 3);
}

Expand Down
Loading