Skip to content

Commit

Permalink
fix: return type defined
Browse files Browse the repository at this point in the history
  • Loading branch information
Itshyphen committed Nov 13, 2024
1 parent 726c8cc commit cb532a1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 27 deletions.
31 changes: 16 additions & 15 deletions contracts/asset_manager/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod xcall {
}
use crate::errors::ContractError;
use crate::states::{self};
use crate::storage_types::{ConfigData, RateLimit};
use crate::{
states::{
extent_ttl, has_upgrade_authority, read_administrator,write_administrator,
Expand Down Expand Up @@ -42,14 +43,14 @@ impl AssetManager {
Ok(())
}

pub fn get_config(env: Env) -> (Address, Address, Address, String, Address) {
(
states::read_xcall(&env),
states::read_xcall_manager(&env),
states::read_native_address(&env),
states::read_icon_asset_manager(&env),
states::read_upgrade_authority(&env),
)
pub fn get_config(env: Env) -> ConfigData {
ConfigData {
xcall: states::read_xcall(&env),
xcall_manager: states::read_xcall_manager(&env),
native_address: states::read_native_address(&env),
icon_asset_manager: states::read_icon_asset_manager(&env),
upgrade_authority: states::read_upgrade_authority(&env),
}
}

pub fn set_admin(env: Env, new_admin: Address) {
Expand Down Expand Up @@ -81,13 +82,13 @@ impl AssetManager {
Ok(())
}

pub fn get_rate_limit(env: Env, token_address: Address) -> Result<(u64, u32, u64, u64), ContractError> {
Ok((
states::read_period(&env, token_address.clone()),
states::read_percentage(&env, token_address.clone()),
states::read_last_update(&env, token_address.clone()),
states::read_current_limit(&env, token_address),
))
pub fn get_rate_limit(env: Env, token_address: Address) -> RateLimit {
RateLimit {
period: states::read_period(&env, token_address.clone()),
percentage: states::read_percentage(&env, token_address.clone()),
last_update: states::read_last_update(&env, token_address.clone()),
current_limit: states::read_current_limit(&env, token_address),
}
}

pub fn reset_limit(env: Env, token: Address) -> Result<bool, ContractError> {
Expand Down
19 changes: 18 additions & 1 deletion contracts/asset_manager/src/storage_types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use soroban_sdk::{contracttype, Address};
use soroban_sdk::{contracttype, Address, String};

pub(crate) const POINTS: u128 = 10000;

Expand All @@ -17,3 +17,20 @@ pub enum DataKey {
CurrentLimit(Address),
}

#[contracttype]
pub struct ConfigData {
pub xcall: Address,
pub xcall_manager: Address,
pub native_address: Address,
pub icon_asset_manager: String,
pub upgrade_authority: Address,
}

#[contracttype]
pub struct RateLimit {
pub period: u64,
pub percentage: u32,
pub last_update: u64,
pub current_limit: u64,
}

12 changes: 1 addition & 11 deletions contracts/asset_manager/src/tests/asset_manager_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fn test_configure_rate_limit() {
)]
);
let token_data = client.get_rate_limit(&ctx.token);
assert_eq!(token_data.3, 0);
assert_eq!(token_data.last_update, 0);
}

#[test]
Expand Down Expand Up @@ -463,16 +463,6 @@ fn test_handle_call_message_for_deposit_rollback_panic_with_only_call_service()
assert_eq!(token_client.balance(&ctx.withdrawer), bnusd_amount as i128)
}

#[test]
fn test_extend_ttl() {
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.extend_ttl();
}

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

0 comments on commit cb532a1

Please sign in to comment.