Skip to content

Commit

Permalink
storage type mismatch issue fixed, ttl_extend verification on unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
sagars committed Sep 9, 2024
1 parent ca312c3 commit 573659e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
3 changes: 2 additions & 1 deletion contracts/asset_manager/src/contract.rs
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions contracts/asset_manager/src/states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub fn read_token_data(env: &Env, token_address: Address) -> Option<TokenData> {

pub fn write_tokens(e: &Env, token: Address) {
let key = DataKey::Tokens;
let mut tokens: Vec<Address> = match e.storage().instance().get(&key) {
let mut tokens: Vec<Address> = match e.storage().persistent().get(&key) {
Some(names) => names,
None => Vec::new(&e),
};
Expand All @@ -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,
Expand Down
15 changes: 11 additions & 4 deletions contracts/asset_manager/src/tests/asset_manager_test.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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);
});

}

0 comments on commit 573659e

Please sign in to comment.