From cb532a151ab8de84578e311f90511377a1290e4d Mon Sep 17 00:00:00 2001 From: Itshypen <075bct064.ranju@pcampus.edu.np> Date: Wed, 13 Nov 2024 23:26:53 +0545 Subject: [PATCH] fix: return type defined --- contracts/asset_manager/src/contract.rs | 31 ++++++++++--------- contracts/asset_manager/src/storage_types.rs | 19 +++++++++++- .../src/tests/asset_manager_test.rs | 12 +------ 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/contracts/asset_manager/src/contract.rs b/contracts/asset_manager/src/contract.rs index 1f5e0b6..ac3ad5a 100644 --- a/contracts/asset_manager/src/contract.rs +++ b/contracts/asset_manager/src/contract.rs @@ -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, @@ -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) { @@ -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 { diff --git a/contracts/asset_manager/src/storage_types.rs b/contracts/asset_manager/src/storage_types.rs index 7080536..5a64e42 100644 --- a/contracts/asset_manager/src/storage_types.rs +++ b/contracts/asset_manager/src/storage_types.rs @@ -1,4 +1,4 @@ -use soroban_sdk::{contracttype, Address}; +use soroban_sdk::{contracttype, Address, String}; pub(crate) const POINTS: u128 = 10000; @@ -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, +} + diff --git a/contracts/asset_manager/src/tests/asset_manager_test.rs b/contracts/asset_manager/src/tests/asset_manager_test.rs index 50e50e0..451d47e 100644 --- a/contracts/asset_manager/src/tests/asset_manager_test.rs +++ b/contracts/asset_manager/src/tests/asset_manager_test.rs @@ -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] @@ -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();