Skip to content

Commit

Permalink
removed unused methods on messages, removed commented lines on unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
sagars committed Oct 21, 2024
1 parent 0c6b468 commit 58ef3ef
Show file tree
Hide file tree
Showing 8 changed files with 2 additions and 168 deletions.
54 changes: 1 addition & 53 deletions contracts/asset_manager/src/tests/asset_manager_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ fn test_configure_rate_limit_panic() {
let percentage = &10001;
client.configure_rate_limit(&ctx.token, period, percentage);

let limit = client.get_withdraw_limit(&ctx.token);
// let verified = client.verify_withdraw(&ctx.token, &limit);
// assert_eq!(verified, true);
}

#[test]
Expand All @@ -86,9 +83,7 @@ fn test_configure_rate_limit() {
);
let token_data = client.get_rate_limit(&ctx.token);
assert_eq!(token_data.3, 0);
let limit = client.get_withdraw_limit(&ctx.token);
// let verified = client.verify_withdraw(&ctx.token, &limit);
// assert_eq!(verified, true);

}

#[test]
Expand Down Expand Up @@ -136,7 +131,6 @@ fn test_veryfy_rate_limit() {
let percentage = &300;
client.configure_rate_limit(&ctx.token, period, percentage);

//let token_client = token::Client::new(&ctx.env, &ctx.token);
let stellar_asset_client: token::StellarAssetClient =
token::StellarAssetClient::new(&ctx.env, &ctx.token);
let amount_i128: i128 = 100000i128;
Expand All @@ -148,7 +142,6 @@ fn test_veryfy_rate_limit() {
ctx.mint_native_token(&ctx.depositor, 500u128);
assert_eq!(ctx.get_native_token_balance(&ctx.depositor), 500u128);

//token_client.approve(&ctx.depositor, &ctx.registry, &(amount_i128+amount_i128), &1312000);
client.deposit(
&ctx.depositor,
&ctx.token,
Expand All @@ -159,52 +152,8 @@ fn test_veryfy_rate_limit() {

let limit = client.get_withdraw_limit(&ctx.token);
assert_eq!(limit, 3000);
// let verified = client.verify_withdraw(&ctx.token, &(amount - 3000 - 1));
// assert_eq!(verified, true);
}

// #[test]
// #[should_panic(expected = "HostError: Error(Contract, #5)")]
// fn test_veryfy_rate_limit_panic_exceeds_withdraw_limit() {
// let ctx = TestContext::default();
// let client = AssetManagerClient::new(&ctx.env, &ctx.registry);
// ctx.init_context(&client);
// let period = &300;
// let percentage = &300;
// client.configure_rate_limit(&ctx.token, period, percentage);

// let token_client = token::Client::new(&ctx.env, &ctx.token);
// let stellar_asset_client: token::StellarAssetClient =
// token::StellarAssetClient::new(&ctx.env, &ctx.token);
// let amount_i128: i128 = 100000i128;
// let amount = &(amount_i128 as u128);
// let mint_amount = &(amount_i128 + amount_i128);

// stellar_asset_client.mint(&ctx.depositor, mint_amount);

// ctx.mint_native_token(&ctx.depositor, 500u128);
// assert_eq!(ctx.get_native_token_balance(&ctx.depositor), 500u128);

// token_client.approve(
// &ctx.depositor,
// &ctx.registry,
// &(amount_i128 + amount_i128),
// &1312000,
// );
// client.deposit(
// &ctx.depositor,
// &ctx.token,
// &amount,
// &Option::Some(String::from_str(&ctx.env, "")),
// &Option::Some(Bytes::from_array(&ctx.env, &[0u8; 32])),
// );

// let limit = client.get_withdraw_limit(&ctx.token);
// assert_eq!(limit, 3000);
// // let verified = client.verify_withdraw(&ctx.token, &(amount - 3000 + 1));
// // assert_eq!(verified, true);
// }

#[test]
fn test_deposit_with_to_and_without_data() {
let ctx = TestContext::default();
Expand Down Expand Up @@ -289,7 +238,6 @@ fn test_handle_call_message_for_withdraw_to() {
ctx.env.mock_all_auths();

ctx.init_context(&client);
//client.configure_rate_limit(&ctx.token, &300, &300);

let bnusd_amount = 100000u128;
let token_client = token::Client::new(&ctx.env, &ctx.token);
Expand Down
48 changes: 1 addition & 47 deletions libs/soroban-rlp/src/balanced/address_utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use soroban_sdk::{xdr::ToXdr, xdr::FromXdr, Bytes, Env, String};
use soroban_sdk::{Bytes, String};

pub fn is_valid_string_address(address: &String) -> bool {
if address.len() != 56 {
Expand Down Expand Up @@ -47,50 +47,4 @@ fn is_valid_base32(byte: u8) -> bool {
b'A'..=b'Z' | b'2'..=b'7' => true,
_ => false,
}
}

pub fn get_address_from(network_address: &String, env: &Env) -> String {
let mut nid = Bytes::new(&env);
let mut account = Bytes::new(&env);

let addr_slice = get_bytes_from_string(&env,network_address.clone());

let mut has_seperator = false;
for (index, value) in addr_slice.clone().iter().enumerate() {
if has_seperator {
account.append(&addr_slice.slice(index as u32..addr_slice.len()));
break;
} else if value == 47 {
has_seperator = true;
} else {
nid.push_back(value)
}
}

if !has_seperator {
panic!("Invalid network address")
}


get_string_from_bytes(&env, account)

}

pub fn get_bytes_from_string(env: &Env, value: String) -> Bytes {
let bytes = value.to_xdr(&env);

if bytes.get(6).unwrap() > 0 {
panic!("Invalid network address length")
}

let value_len = bytes.get(7).unwrap();
let slice = bytes.slice(8..value_len as u32 + 8);
slice
}

pub fn get_string_from_bytes(e: &Env, bytes: Bytes) -> String {
let mut bytes_xdr = bytes.to_xdr(&e);
bytes_xdr.set(3, 14);

String::from_xdr(&e, &bytes_xdr).unwrap()
}
8 changes: 0 additions & 8 deletions libs/soroban-rlp/src/balanced/messages/configure_protocols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ impl ConfigureProtocols {
}
}

pub fn sources(&self) -> &Vec<String> {
&self.sources
}

pub fn destinations(&self) -> &Vec<String> {
&self.destinations
}

pub fn encode(&self, e: &Env, method: String) -> Bytes {
let mut list: Vec<Bytes> = Vec::new(&e);
list.push_back(encoder::encode_string(&e, method));
Expand Down
8 changes: 0 additions & 8 deletions libs/soroban-rlp/src/balanced/messages/cross_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ impl CrossTransfer {
}
}

pub fn from(&self) -> &String {
&self.from
}

pub fn to(&self) -> &String {
&self.to
}

pub fn encode(&self, e: &Env, method: String) -> Bytes {
let mut list: Vec<Bytes> = Vec::new(&e);
list.push_back(encoder::encode_string(&e, method));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ impl CrossTransferRevert{
}
}

pub fn to(&self) -> &Address {
&self.to
}

pub fn amount(&self) -> &u128 {
&self.amount
}

pub fn encode(&self, e: &Env, method: String) -> Bytes {
let mut list: Vec<Bytes> = Vec::new(&e);

Expand Down
20 changes: 0 additions & 20 deletions libs/soroban-rlp/src/balanced/messages/deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,6 @@ impl Deposit {
}
}

pub fn token_address(&self) -> &String {
&self.token_address
}

pub fn from(&self) -> &String {
&self.from
}

pub fn to(&self) -> &String {
&self.to
}

pub fn amount(&self) -> &u128 {
&self.amount
}

pub fn data(&self) -> &Bytes {
&self.data
}

pub fn encode(&self, e: &Env, method: String) -> Bytes {
let mut list: Vec<Bytes> = Vec::new(&e);
list.push_back(encoder::encode_string(&e, method));
Expand Down
12 changes: 0 additions & 12 deletions libs/soroban-rlp/src/balanced/messages/deposit_revert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,6 @@ impl DepositRevert{
}
}

pub fn token_address(&self) -> &Address {
&self.token_address
}

pub fn to(&self) -> &Address {
&self.to
}

pub fn amount(&self) -> &u128 {
&self.amount
}

pub fn encode(&self, e: &Env, method: String) -> Bytes {
let mut list: Vec<Bytes> = Vec::new(&e);
list.push_back(encoder::encode_string(&e, method));
Expand Down
12 changes: 0 additions & 12 deletions libs/soroban-rlp/src/balanced/messages/withdraw_to.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,6 @@ impl WithdrawTo{
}
}

pub fn token_address(&self) -> &String {
&self.token_address
}

pub fn to(&self) -> &String {
&self.to
}

pub fn amount(&self) -> &u128 {
&self.amount
}

pub fn encode(&self, e: &Env, method: String) -> Bytes {
let mut list: Vec<Bytes> = Vec::new(&e);
list.push_back(encoder::encode_string(&e, method));
Expand Down

0 comments on commit 58ef3ef

Please sign in to comment.