From 4370ca7ef50d76b822dbc87792c0315985286566 Mon Sep 17 00:00:00 2001 From: BiancaIalangi Date: Fri, 11 Oct 2024 19:57:21 +0300 Subject: [PATCH 1/3] intearctor - fix ExpectError --- .../adder/interact/src/basic_interact.rs | 15 +++---- .../scenario/model/transaction/tx_expect.rs | 2 +- sdk/core/src/retrieve_tx_on_network.rs | 45 ++++++++----------- 3 files changed, 27 insertions(+), 35 deletions(-) diff --git a/contracts/examples/adder/interact/src/basic_interact.rs b/contracts/examples/adder/interact/src/basic_interact.rs index f83ca84a26..b700a63665 100644 --- a/contracts/examples/adder/interact/src/basic_interact.rs +++ b/contracts/examples/adder/interact/src/basic_interact.rs @@ -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; @@ -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; } diff --git a/framework/scenario/src/scenario/model/transaction/tx_expect.rs b/framework/scenario/src/scenario/model/transaction/tx_expect.rs index d487a10db5..fe8f0f5eaa 100644 --- a/framework/scenario/src/scenario/model/transaction/tx_expect.rs +++ b/framework/scenario/src/scenario/model/transaction/tx_expect.rs @@ -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, ); } diff --git a/sdk/core/src/retrieve_tx_on_network.rs b/sdk/core/src/retrieve_tx_on_network.rs index c68a649d9c..4d68f64d5d 100644 --- a/sdk/core/src/retrieve_tx_on_network.rs +++ b/sdk/core/src/retrieve_tx_on_network.rs @@ -45,17 +45,14 @@ pub async fn retrieve_tx_on_network( } 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; @@ -85,22 +82,18 @@ pub async fn retrieve_tx_on_network( 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 = 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(" ") } From dfc8ff4a336d2a8896ba96c762a076ca5095c04b Mon Sep 17 00:00:00 2001 From: BiancaIalangi Date: Fri, 11 Oct 2024 20:00:22 +0300 Subject: [PATCH 2/3] interactor - replace println with info --- sdk/core/src/retrieve_tx_on_network.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/core/src/retrieve_tx_on_network.rs b/sdk/core/src/retrieve_tx_on_network.rs index 4d68f64d5d..95f644893b 100644 --- a/sdk/core/src/retrieve_tx_on_network.rs +++ b/sdk/core/src/retrieve_tx_on_network.rs @@ -50,7 +50,7 @@ pub async fn retrieve_tx_on_network( .await .unwrap(); - println!("Transaction failed: {}", result); + info!("Transaction failed: {}", result); return transaction_info_with_results; }, From 0723e817615437c04a2eb478dc589bc961c93555 Mon Sep 17 00:00:00 2001 From: BiancaIalangi Date: Mon, 14 Oct 2024 11:34:44 +0300 Subject: [PATCH 3/3] interactor - add chain simulator feature --- contracts/examples/adder/interact/src/basic_interact.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/contracts/examples/adder/interact/src/basic_interact.rs b/contracts/examples/adder/interact/src/basic_interact.rs index b700a63665..7e4ecda92e 100644 --- a/contracts/examples/adder/interact/src/basic_interact.rs +++ b/contracts/examples/adder/interact/src/basic_interact.rs @@ -277,6 +277,7 @@ impl AdderInteract { } #[tokio::test] +#[cfg(feature = "chain_simulator")] async fn simulator_upgrade_test() { let mut basic_interact = AdderInteract::init().await; let wallet_address = basic_interact.wallet_address.clone();