Skip to content

Commit

Permalink
fix: removed unused methods on messages, removed commented lines on u…
Browse files Browse the repository at this point in the history
…nittests (#14)

* chore: removed unused methods on messages, removed commented lines on unittests

* chore: second commit for git

* fix: testing unit tests fails on ci/cd

* ci: check with rust 1.81.0

---------

Co-authored-by: sagar sapkota <[email protected]>
Co-authored-by: DeepakBomjan <[email protected]>
  • Loading branch information
3 people authored Oct 22, 2024
1 parent 0c6b468 commit 72f8619
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 172 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/soroban-codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ jobs:
uses: actions/checkout@v3
with:
submodules: true
- name: Install Rust
run: rustup update stable
# - name: Install Rust
# run: rustup update stable
## Temporary workaround to fix codecov issue with latest version (1.82.0)
- name: Install Rust 1.81.0
run: |
rustup install 1.81.0
rustup default 1.81.0
- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2
- name: Install cargo-llvm-cov
Expand All @@ -40,4 +45,4 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
files: lcov.info
flags: rust
fail_ci_if_error: true
fail_ci_if_error: true
2 changes: 1 addition & 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, token, Address, Bytes, BytesN, Env, String, Vec,
};
mod xcall {
soroban_sdk::contractimport!(file = "../../wasm/xcall.wasm");
Expand Down
55 changes: 2 additions & 53 deletions contracts/asset_manager/src/tests/asset_manager_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ fn test_set_admin() {

let new_admin: Address = Address::generate(&ctx.env);
client.set_admin(&new_admin);

assert_eq!(
ctx.env.auths(),
std::vec![(
Expand Down Expand Up @@ -57,9 +58,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 +84,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 +132,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 +143,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 +153,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 +239,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 72f8619

Please sign in to comment.