From 573659e385eddf7eac27e47d14782d35da76b455 Mon Sep 17 00:00:00 2001 From: sagar sapkota Date: Mon, 9 Sep 2024 15:54:16 +0545 Subject: [PATCH] storage type mismatch issue fixed, ttl_extend verification on unit test --- contracts/asset_manager/src/contract.rs | 3 ++- contracts/asset_manager/src/states.rs | 4 ++-- .../asset_manager/src/tests/asset_manager_test.rs | 15 +++++++++++---- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/contracts/asset_manager/src/contract.rs b/contracts/asset_manager/src/contract.rs index 5108966..5ff6d43 100644 --- a/contracts/asset_manager/src/contract.rs +++ b/contracts/asset_manager/src/contract.rs @@ -1,5 +1,5 @@ use soroban_sdk::{ - contract, contractimpl, panic_with_error, token, Address, Bytes, BytesN, Env, String, Vec, + contract, contractimpl, panic_with_error, token, Address, Bytes, BytesN, Env, String, Vec }; mod xcall { soroban_sdk::contractimport!(file = "../../wasm/xcall.wasm"); @@ -108,6 +108,7 @@ impl AssetManager { return Ok(Self::calculate_limit(&env, balance, token)?); } + fn get_token_balance(env: &Env, token: Address) -> u128 { let token_client = token::Client::new(env, &token); return token_client.balance(&env.current_contract_address()) as u128; diff --git a/contracts/asset_manager/src/states.rs b/contracts/asset_manager/src/states.rs index bfc7ee4..7bf1a60 100644 --- a/contracts/asset_manager/src/states.rs +++ b/contracts/asset_manager/src/states.rs @@ -48,7 +48,7 @@ pub fn read_token_data(env: &Env, token_address: Address) -> Option { pub fn write_tokens(e: &Env, token: Address) { let key = DataKey::Tokens; - let mut tokens: Vec
= match e.storage().instance().get(&key) { + let mut tokens: Vec
= match e.storage().persistent().get(&key) { Some(names) => names, None => Vec::new(&e), }; @@ -72,7 +72,7 @@ pub fn extent_ttl(e: &Env) { .instance() .extend_ttl(INSTANCE_LIFETIME_THRESHOLD, INSTANCE_BUMP_AMOUNT); - let tokens = read_tokens(&e.clone()); + let tokens = read_tokens(&e); e.storage().persistent().extend_ttl( &DataKey::Tokens, INSTANCE_LIFETIME_THRESHOLD, diff --git a/contracts/asset_manager/src/tests/asset_manager_test.rs b/contracts/asset_manager/src/tests/asset_manager_test.rs index a3111ff..afb2654 100644 --- a/contracts/asset_manager/src/tests/asset_manager_test.rs +++ b/contracts/asset_manager/src/tests/asset_manager_test.rs @@ -1,10 +1,9 @@ #![cfg(test)] extern crate std; -use crate::contract::AssetManagerClient; +use crate::{contract::AssetManagerClient, storage_types::DataKey}; use soroban_sdk::{ - testutils::{Address as _, AuthorizedFunction, AuthorizedInvocation}, - token, Address, Bytes, IntoVal, String, Symbol, Vec, + testutils::{storage::Persistent, Address as _, AuthorizedFunction, AuthorizedInvocation}, token, Address, Bytes, IntoVal, String, Symbol, Vec }; use soroban_rlp::balanced::messages::{deposit_revert::DepositRevert, withdraw_to::WithdrawTo}; @@ -523,6 +522,14 @@ fn test_extend_ttl() { ctx.init_context(&client); client.configure_rate_limit(&ctx.token, &300, &300); - + let token = ctx.token; + client.extend_ttl(); + + ctx.env.as_contract(&client.address, || { + let key = DataKey::TokenData(token.clone()); + let before_ttl = ctx.env.storage().persistent().get_ttl(&key); + std::println!("before ttl is: {:?}", before_ttl); + }); + }