diff --git a/.github/workflows/soroban-codecov.yml b/.github/workflows/soroban-codecov.yml index 8ca37f4..5a35cb2 100644 --- a/.github/workflows/soroban-codecov.yml +++ b/.github/workflows/soroban-codecov.yml @@ -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 @@ -40,4 +45,4 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} files: lcov.info flags: rust - fail_ci_if_error: true \ No newline at end of file + fail_ci_if_error: true diff --git a/contracts/asset_manager/src/contract.rs b/contracts/asset_manager/src/contract.rs index e79c0f5..3697446 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, token, Address, Bytes, BytesN, Env, String, Vec, }; mod xcall { soroban_sdk::contractimport!(file = "../../wasm/xcall.wasm"); diff --git a/contracts/asset_manager/src/tests/asset_manager_test.rs b/contracts/asset_manager/src/tests/asset_manager_test.rs index 94b5ca7..2ee28e7 100644 --- a/contracts/asset_manager/src/tests/asset_manager_test.rs +++ b/contracts/asset_manager/src/tests/asset_manager_test.rs @@ -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![( @@ -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] @@ -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] @@ -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; @@ -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, @@ -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(); @@ -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); diff --git a/libs/soroban-rlp/src/balanced/address_utils.rs b/libs/soroban-rlp/src/balanced/address_utils.rs index e45995d..4fe201f 100644 --- a/libs/soroban-rlp/src/balanced/address_utils.rs +++ b/libs/soroban-rlp/src/balanced/address_utils.rs @@ -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 { @@ -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() } \ No newline at end of file diff --git a/libs/soroban-rlp/src/balanced/messages/configure_protocols.rs b/libs/soroban-rlp/src/balanced/messages/configure_protocols.rs index 2c7505c..8ff22f3 100644 --- a/libs/soroban-rlp/src/balanced/messages/configure_protocols.rs +++ b/libs/soroban-rlp/src/balanced/messages/configure_protocols.rs @@ -17,14 +17,6 @@ impl ConfigureProtocols { } } - pub fn sources(&self) -> &Vec { - &self.sources - } - - pub fn destinations(&self) -> &Vec { - &self.destinations - } - pub fn encode(&self, e: &Env, method: String) -> Bytes { let mut list: Vec = Vec::new(&e); list.push_back(encoder::encode_string(&e, method)); diff --git a/libs/soroban-rlp/src/balanced/messages/cross_transfer.rs b/libs/soroban-rlp/src/balanced/messages/cross_transfer.rs index 743277e..f1e0566 100644 --- a/libs/soroban-rlp/src/balanced/messages/cross_transfer.rs +++ b/libs/soroban-rlp/src/balanced/messages/cross_transfer.rs @@ -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 = Vec::new(&e); list.push_back(encoder::encode_string(&e, method)); diff --git a/libs/soroban-rlp/src/balanced/messages/cross_transfer_revert.rs b/libs/soroban-rlp/src/balanced/messages/cross_transfer_revert.rs index 9e2fef5..60e9d2a 100644 --- a/libs/soroban-rlp/src/balanced/messages/cross_transfer_revert.rs +++ b/libs/soroban-rlp/src/balanced/messages/cross_transfer_revert.rs @@ -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 = Vec::new(&e); diff --git a/libs/soroban-rlp/src/balanced/messages/deposit.rs b/libs/soroban-rlp/src/balanced/messages/deposit.rs index 720db75..cad238e 100644 --- a/libs/soroban-rlp/src/balanced/messages/deposit.rs +++ b/libs/soroban-rlp/src/balanced/messages/deposit.rs @@ -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 = Vec::new(&e); list.push_back(encoder::encode_string(&e, method)); diff --git a/libs/soroban-rlp/src/balanced/messages/deposit_revert.rs b/libs/soroban-rlp/src/balanced/messages/deposit_revert.rs index 8ad1742..1092fe9 100644 --- a/libs/soroban-rlp/src/balanced/messages/deposit_revert.rs +++ b/libs/soroban-rlp/src/balanced/messages/deposit_revert.rs @@ -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 = Vec::new(&e); list.push_back(encoder::encode_string(&e, method)); diff --git a/libs/soroban-rlp/src/balanced/messages/withdraw_to.rs b/libs/soroban-rlp/src/balanced/messages/withdraw_to.rs index ca06dd9..6eec7fe 100644 --- a/libs/soroban-rlp/src/balanced/messages/withdraw_to.rs +++ b/libs/soroban-rlp/src/balanced/messages/withdraw_to.rs @@ -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 = Vec::new(&e); list.push_back(encoder::encode_string(&e, method));