Skip to content

Commit

Permalink
fix: reset limit admin check
Browse files Browse the repository at this point in the history
chore: add test for reset limit
  • Loading branch information
sagars authored and bishalbikram committed Nov 5, 2024
1 parent f81ebcf commit 143987d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
2 changes: 2 additions & 0 deletions contracts/asset_manager/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ impl AssetManager {
}

pub fn reset_limit(env: Env, token: Address) {
let admin = read_administrator(&env);
admin.require_auth();
let balance = Self::get_token_balance(&env, token.clone());
let mut data: TokenData = read_token_data(&env, token.clone());
data.current_limit = (balance * data.percentage as u128 / POINTS) as u64;
Expand Down
29 changes: 26 additions & 3 deletions contracts/asset_manager/src/tests/asset_manager_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn test_set_admin() {

let new_admin: Address = Address::generate(&ctx.env);
client.set_admin(&new_admin);

assert_eq!(
ctx.env.auths(),
std::vec![(
Expand All @@ -56,7 +56,6 @@ fn test_configure_rate_limit_panic() {
let period = &300;
let percentage = &10001;
client.configure_rate_limit(&ctx.token, period, percentage);

}

#[test]
Expand All @@ -83,7 +82,6 @@ fn test_configure_rate_limit() {
);
let token_data = client.get_rate_limit(&ctx.token);
assert_eq!(token_data.3, 0);

}

#[test]
Expand Down Expand Up @@ -482,6 +480,31 @@ fn test_extend_ttl() {
});
}

#[test]
fn test_reset_limit() {
let ctx = TestContext::default();
let client = AssetManagerClient::new(&ctx.env, &ctx.registry);
ctx.init_context(&client);

client.configure_rate_limit(&ctx.token, &300, &300);
client.reset_limit(&ctx.token);

assert_eq!(
ctx.env.auths(),
std::vec![(
ctx.admin.clone(),
AuthorizedInvocation {
function: AuthorizedFunction::Contract((
ctx.registry.clone(),
Symbol::new(&ctx.env, "reset_limit"),
(&ctx.token,).into_val(&ctx.env)
)),
sub_invocations: std::vec![]
}
)]
);
}

#[test]
fn test_set_upgrade_authority() {
let ctx = TestContext::default();
Expand Down

0 comments on commit 143987d

Please sign in to comment.