Skip to content

Commit

Permalink
intearctor - fix ExpectError
Browse files Browse the repository at this point in the history
  • Loading branch information
BiancaIalangi committed Oct 11, 2024
1 parent dc2f0f8 commit 4370ca7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 35 deletions.
15 changes: 7 additions & 8 deletions contracts/examples/adder/interact/src/basic_interact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,12 @@ impl AdderInteract {
}
}

#[cfg(feature = "chain_simulator")]
#[tokio::test]
async fn simulator_upgrade_test() {
let mut basic_interact = AdderInteract::init().await;
// let wallet_address = basic_interact.wallet_address.clone();
let wallet_address = basic_interact.wallet_address.clone();
let adder_owner_address = basic_interact.adder_owner_address.clone();
// let error_not_owner = (4, "upgrade is allowed only for owner");
let error_not_owner = (4, "upgrade is allowed only for owner");

basic_interact.deploy().await;
basic_interact.add(1u32).await;
Expand All @@ -297,10 +296,10 @@ async fn simulator_upgrade_test() {
// Sum will be the updated value of 7
basic_interact.print_sum().await;

// basic_interact
// .upgrade(10u32, &wallet_address, Some(error_not_owner))
// .await;
basic_interact
.upgrade(10u32, &wallet_address, Some(error_not_owner))
.await;

// // Sum will remain 7
// basic_interact.print_sum().await;
// Sum will remain 7
basic_interact.print_sum().await;
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,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}")
},
}
println!("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(" ")
}

0 comments on commit 4370ca7

Please sign in to comment.