Skip to content

Commit

Permalink
xcall param removed from handle call message of bnUSD and xcall manager
Browse files Browse the repository at this point in the history
  • Loading branch information
sagars committed Sep 4, 2024
1 parent b8b91a0 commit aed6084
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
5 changes: 3 additions & 2 deletions contracts/balanced_dollar/src/balanced_dollar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
config::{get_config, set_config, ConfigData},
xcall_manager_interface::XcallManagerClient,
};
use soroban_rlp::address_utils::is_valid_bytes_address;
use soroban_rlp::address_utils::{get_address_from, is_valid_bytes_address};
use soroban_rlp::messages::{
cross_transfer::CrossTransfer, cross_transfer_revert::CrossTransferRevert,
};
Expand Down Expand Up @@ -72,7 +72,6 @@ fn verify_protocol(

pub fn _handle_call_message(
e: Env,
xcall_address: Address,
from: String,
data: Bytes,
protocols: Vec<String>,
Expand All @@ -91,6 +90,8 @@ pub fn _handle_call_message(
let to_network_address: Address = get_address(message.to, &e)?;
_mint(&e, to_network_address, message.amount as i128);
} else if method == String::from_str(&e, &CROSS_TRANSFER_REVERT) {
let from_xcall = get_address_from(&from, &e);
let xcall_address = Address::from_string(&from_xcall.into());
if xcall != xcall_address {
return Err(ContractError::OnlyCallService);
}
Expand Down
3 changes: 1 addition & 2 deletions contracts/balanced_dollar/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,11 @@ impl BalancedDollar {

pub fn handle_call_message(
e: Env,
xcall: Address,
from: String,
data: Bytes,
protocols: Vec<String>,
) -> Result<(), ContractError> {
return balanced_dollar::_handle_call_message(e, xcall, from, data, protocols);
return balanced_dollar::_handle_call_message(e, from, data, protocols);
}

pub fn is_initialized(e: Env) -> bool {
Expand Down
22 changes: 14 additions & 8 deletions contracts/balanced_dollar/src/tests/balanced_dollar_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ fn test_handle_call_message_for_cross_transfer() {
assert_eq!(client.balance(withdrawer_address), 0);

let sources = Vec::from_array(&ctx.env, [ctx.centralized_connection.to_string()]);
client.handle_call_message(&ctx.xcall, &ctx.icon_bn_usd, &data, &sources);
client.handle_call_message( &ctx.icon_bn_usd, &data, &sources);
assert_eq!(client.balance(withdrawer_address), bnusd_amount as i128)
}

Expand Down Expand Up @@ -156,7 +156,7 @@ fn test_handle_call_message_for_cross_transfer_invalid_addres_fail() {
// assert_eq!(client.balance(withdrawer_address), 0);

let sources = Vec::from_array(&ctx.env, [ctx.centralized_connection.to_string()]);
client.handle_call_message(&ctx.xcall, &ctx.icon_bn_usd, &data, &sources);
client.handle_call_message(&ctx.icon_bn_usd, &data, &sources);
// assert_eq!(client.balance(withdrawer_address), bnusd_amount as i128)
}

Expand Down Expand Up @@ -197,7 +197,7 @@ fn test_handle_call_message_for_cross_transfer_panic_for_protocol_mismatch() {
assert_eq!(client.balance(withdrawer_address), 0);

let sources = Vec::from_array(&ctx.env, [ctx.xcall.to_string()]);
client.handle_call_message(&ctx.xcall, &ctx.icon_bn_usd, &data, &sources);
client.handle_call_message( &ctx.icon_bn_usd, &data, &sources);

assert_eq!(client.balance(withdrawer_address), bnusd_amount as i128)
}
Expand Down Expand Up @@ -239,7 +239,7 @@ fn test_handle_call_message_for_cross_transfer_panic_for_icon_bnusd() {
assert_eq!(client.balance(withdrawer_address), 0);

let sources = Vec::from_array(&ctx.env, [ctx.centralized_connection.to_string()]);
client.handle_call_message(&ctx.xcall, &ctx.icon_governance, &data, &sources);
client.handle_call_message( &ctx.icon_governance, &data, &sources);

assert_eq!(client.balance(withdrawer_address), bnusd_amount as i128)
}
Expand Down Expand Up @@ -282,7 +282,7 @@ fn test_handle_call_message_for_cross_transfer_panic_for_wront_message_type() {
assert_eq!(client.balance(withdrawer_address), 0);

let sources = Vec::from_array(&ctx.env, [ctx.centralized_connection.to_string()]);
client.handle_call_message(&ctx.xcall, &ctx.icon_bn_usd, &data, &sources);
client.handle_call_message( &ctx.icon_bn_usd, &data, &sources);

assert_eq!(client.balance(withdrawer_address), bnusd_amount as i128)
}
Expand All @@ -306,7 +306,6 @@ fn test_handle_call_message_for_cross_transfer_revert() {

let sources = Vec::from_array(&ctx.env, [ctx.centralized_connection.to_string()]);
client.handle_call_message(
&ctx.xcall,
&ctx.xcall_client.get_network_address(),
&data,
&sources,
Expand Down Expand Up @@ -334,9 +333,16 @@ fn test_handle_call_message_for_cross_transfer_revert_panic_for_xcall() {
assert_eq!(client.balance(&ctx.withdrawer), 0);

let sources = Vec::from_array(&ctx.env, [ctx.centralized_connection.to_string()]);
let wrong_network_address: String = String::from_str(
&ctx.env,
&std::format!(
"{}/{}",
"soroban",
"CBEPDNVYXQGWB5YUBXKJWYJA7OXTZW5LFLNO5JRRGE6Z6C5OSUZPCCEL"
),
);
client.handle_call_message(
&ctx.centralized_connection,
&ctx.xcall_client.get_network_address(),
&wrong_network_address,
&data,
&sources,
);
Expand Down
1 change: 0 additions & 1 deletion contracts/xcall_manager/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ impl XcallManager {

pub fn handle_call_message(
e: Env,
_xcall: Address,
from: String,
data: Bytes,
protocols: Vec<String>,
Expand Down
14 changes: 7 additions & 7 deletions contracts/xcall_manager/src/tests/xcall_manager_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ fn test_handle_call_message_for_configure_protocols_panic_for_action_not_whiteli
assert_eq!(decoded.sources, sources);
assert_eq!(decoded.destinations, destinations);
let (s, _) = client.get_protocols();
client.handle_call_message(&ctx.xcall, &ctx.icon_governance, &data, &s);
client.handle_call_message( &ctx.icon_governance, &data, &s);

let (s, d) = client.get_protocols();
assert_eq!(s, sources);
Expand Down Expand Up @@ -158,7 +158,7 @@ fn test_handle_call_message_for_configure_protocols() {
assert_eq!(decoded.sources, sources);
assert_eq!(decoded.destinations, destinations);
let (s, _) = client.get_protocols();
client.handle_call_message(&ctx.xcall, &ctx.icon_governance, &data, &s);
client.handle_call_message( &ctx.icon_governance, &data, &s);

let (s, d) = client.get_protocols();
assert_eq!(s, sources);
Expand Down Expand Up @@ -200,7 +200,7 @@ fn test_get_modified_proposals() {
.encode(&ctx.env, String::from_str(&ctx.env, "ConfigureProtocols"));
client.white_list_actions(&data);
let (s, _) = client.get_protocols();
client.handle_call_message(&ctx.xcall, &ctx.icon_governance, &data, &s);
client.handle_call_message( &ctx.icon_governance, &data, &s);

client.propose_removal(&String::from_str(&ctx.env, "stellar/address"));

Expand Down Expand Up @@ -230,7 +230,7 @@ fn test_get_modified_proposals_panic_no_proposed_removal() {
.encode(&ctx.env, String::from_str(&ctx.env, "ConfigureProtocols"));
client.white_list_actions(&data);
let (s, _) = client.get_protocols();
client.handle_call_message(&ctx.xcall, &ctx.icon_governance, &data, &s);
client.handle_call_message(&ctx.icon_governance, &data, &s);

let updated_protocal = vec![&ctx.env, String::from_str(&ctx.env, "stellar/address1")];
assert_eq!(updated_protocal, client.get_modified_protocols());
Expand Down Expand Up @@ -261,7 +261,7 @@ fn test_handle_call_message_for_configure_protocols_panic_for_only_icon_governan
assert_eq!(decoded.sources, sources);
assert_eq!(decoded.destinations, destinations);
let (s, _) = client.get_protocols();
client.handle_call_message(&ctx.xcall, &ctx.xcall_network_address, &data, &s);
client.handle_call_message(&ctx.xcall_network_address, &data, &s);

let (s, d) = client.get_protocols();
assert_eq!(s, sources);
Expand Down Expand Up @@ -293,7 +293,7 @@ fn test_handle_call_message_for_configure_protocols_panic_for_protocol_mismatch(
assert_eq!(decoded.sources, sources);
assert_eq!(decoded.destinations, destinations);
let s = Vec::from_array(&ctx.env, [ctx.xcall.to_string()]);
client.handle_call_message(&ctx.xcall, &ctx.icon_governance, &data, &s);
client.handle_call_message( &ctx.icon_governance, &data, &s);

let (s, d) = client.get_protocols();
assert_eq!(s, sources);
Expand Down Expand Up @@ -328,7 +328,7 @@ fn test_handle_call_message_for_configure_protocols_panic_for_unknown_mesage_typ
assert_eq!(decoded.sources, sources);
assert_eq!(decoded.destinations, destinations);
let s = Vec::from_array(&ctx.env, [ctx.centralized_connection.to_string()]);
client.handle_call_message(&ctx.xcall, &ctx.icon_governance, &data, &s);
client.handle_call_message(&ctx.icon_governance, &data, &s);

let (s, d) = client.get_protocols();
assert_eq!(s, sources);
Expand Down

0 comments on commit aed6084

Please sign in to comment.