Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interactor - fix ExpectError #1817

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl TxExpect {
self.message.check(tx_response.tx_error.message.as_str()),
"{}result message mismatch. Want: {}. Have: {}.",
&self.additional_error_message,
&self.status,
&self.message,
&tx_response.tx_error.message,
);
}
Expand Down
45 changes: 19 additions & 26 deletions sdk/core/src/retrieve_tx_on_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,14 @@ pub async fn retrieve_tx_on_network<GatewayProxy: GatewayAsyncService>(
}

let result = parse_reason(&reason);
let transaction_info_with_results = proxy
.request(GetTxInfo::new(&tx_hash).with_results())
.await
.unwrap();

match result {
Ok((code, err)) => {
info!("Transaction failed. Code: {code}, message: {err}");
panic!("Transaction failed. Code: {code}, message: {err}")
},
Err(err) => {
info!("Reason parsing error for failed transaction: {err}");
panic!("Reason parsing error for failed transaction: {err}")
},
}
info!("Transaction failed: {}", result);

return transaction_info_with_results;
},
_ => {
continue;
Expand Down Expand Up @@ -85,22 +82,18 @@ pub async fn retrieve_tx_on_network<GatewayProxy: GatewayAsyncService>(
TransactionOnNetwork::default()
}

pub fn parse_reason(reason: &str) -> Result<(u64, String), String> {
let parts: Vec<&str> = reason.split('@').collect();

if parts.len() < 2 {
return Err("Invalid reason format".to_string());
pub fn parse_reason(reason: &str) -> String {
let parts: Vec<&str> = reason.split('@').filter(|part| !part.is_empty()).collect();
let mut responses: Vec<String> = Vec::new();
for part in &parts {
match u64::from_str_radix(part, 16) {
Ok(error_code) => responses.push(error_code.to_string()),
Err(_) => responses.push(
String::from_utf8(hex::decode(part).expect("Failed to decode error message"))
.expect("Failed to decode error message as UTF-8"),
),
}
}

let error_code_hex = parts[1];
let error_message_hex = parts[2];

let error_code =
u64::from_str_radix(error_code_hex, 16).expect("Failed to decode error code as u64");

let error_message =
String::from_utf8(hex::decode(error_message_hex).expect("Failed to decode error message"))
.expect("Failed to decode error message as UTF-8");

Ok((error_code, error_message))
responses.join(" ")
}
Loading