Skip to content

Commit

Permalink
Merge pull request #1822 from multiversx/fix-parse-reason
Browse files Browse the repository at this point in the history
Fix parse reason
  • Loading branch information
BiancaIalangi authored Oct 21, 2024
2 parents 8103282 + e7cd0fc commit a2e0e61
Show file tree
Hide file tree
Showing 16 changed files with 242 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use basic_interact::{AdderInteract, Config};
#[cfg_attr(not(feature = "chain-simulator-tests"), ignore)]
async fn simulator_upgrade_test() {
let mut basic_interact = AdderInteract::init(Config::chain_simulator_config()).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 @@ -23,9 +23,9 @@ async fn simulator_upgrade_test() {
let sum = basic_interact.get_sum().await;
assert_eq!(sum, 7u32.into());

// 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
let sum = basic_interact.get_sum().await;
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ where
self.generate_blocks_until_tx_processed(&tx_hash)
.await
.unwrap();
let tx = retrieve_tx_on_network(&self.proxy, tx_hash.clone()).await;
let (tx, return_code) = retrieve_tx_on_network(&self.proxy, tx_hash.clone()).await;

sc_call_step.save_response(network_response::parse_tx_response(tx));
sc_call_step.save_response(network_response::parse_tx_response(tx, return_code));

if let Some(token_identifier) = sc_call_step.response().new_issued_token_identifier.clone()
{
Expand All @@ -51,7 +51,7 @@ where
.proxy
.request(SendTxRequest(&transaction))
.await
.unwrap();
.expect("Launch sc call failed");
println!("sc call tx hash: {tx_hash}");
info!("sc call tx hash: {}", tx_hash);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ where
self.generate_blocks_until_tx_processed(&tx_hash)
.await
.unwrap();
let tx = retrieve_tx_on_network(&self.proxy, tx_hash.clone()).await;
let (tx, return_code) = retrieve_tx_on_network(&self.proxy, tx_hash.clone()).await;

let addr = sc_deploy_step.tx.from.clone();
let nonce = tx.nonce;
sc_deploy_step.save_response(network_response::parse_tx_response(tx));
sc_deploy_step.save_response(network_response::parse_tx_response(tx, return_code));

let deploy_address = sc_deploy_step
.response()
Expand Down
5 changes: 2 additions & 3 deletions framework/snippets-base/src/multi/interactor_multi_sc_exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ where
let results = self.process_txs(txs).await;

for (i, sc_call_step) in buffer.refs.iter_mut().enumerate() {
sc_call_step.set_response(network_response::parse_tx_response(
results.get(i).unwrap().clone(),
));
let (tx, return_code) = results.get(i).unwrap().clone();
sc_call_step.set_response(network_response::parse_tx_response(tx, return_code));
}

for step in buffer.refs.iter_mut() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::sdk::data::transaction::{Transaction, TransactionOnNetwork};
use crate::{multiversx_sc::types::Address, InteractorBase, Sender};
use futures::future::join_all;
use multiversx_sc_scenario::imports::ReturnCode;
use multiversx_sdk::gateway::{GatewayAsyncService, SendTxRequest};
use multiversx_sdk::retrieve_tx_on_network;
use std::collections::HashSet;
Expand All @@ -25,7 +26,10 @@ where
}
}

pub(crate) async fn process_txs(&mut self, txs: Vec<Transaction>) -> Vec<TransactionOnNetwork> {
pub(crate) async fn process_txs(
&mut self,
txs: Vec<Transaction>,
) -> Vec<(TransactionOnNetwork, ReturnCode)> {
let mut futures = Vec::new();

for tx in &txs {
Expand Down
16 changes: 6 additions & 10 deletions framework/snippets-base/src/network_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::sdk::{
utils::base64_decode,
};
use multiversx_sc_scenario::{
imports::{Address, ESDTSystemSCAddress},
imports::{Address, ESDTSystemSCAddress, ReturnCode},
multiversx_chain_vm::{crypto_functions::keccak256, types::H256},
scenario_model::{Log, TxResponse, TxResponseStatus},
};
Expand All @@ -12,8 +12,8 @@ const SC_DEPLOY_PROCESSING_TYPE: &str = "SCDeployment";
const LOG_IDENTIFIER_SIGNAL_ERROR: &str = "signalError";

/// Creates a [`TxResponse`] from a [`TransactionOnNetwork`].
pub fn parse_tx_response(tx: TransactionOnNetwork) -> TxResponse {
let tx_error = process_signal_error(&tx);
pub fn parse_tx_response(tx: TransactionOnNetwork, return_code: ReturnCode) -> TxResponse {
let tx_error = process_signal_error(&tx, return_code);
if !tx_error.is_success() {
return TxResponse {
tx_error,
Expand All @@ -25,16 +25,12 @@ pub fn parse_tx_response(tx: TransactionOnNetwork) -> TxResponse {
process_success(&tx)
}

fn process_signal_error(tx: &TransactionOnNetwork) -> TxResponseStatus {
fn process_signal_error(tx: &TransactionOnNetwork, return_code: ReturnCode) -> TxResponseStatus {
if let Some(event) = find_log(tx, LOG_IDENTIFIER_SIGNAL_ERROR) {
let topics = event.topics.as_ref();
if let Some(error) = process_topics_error(topics) {
return TxResponseStatus::signal_error(&error);
}

let error_raw = base64_decode(topics.unwrap().get(1).unwrap());
let error = String::from_utf8(error_raw).unwrap();
return TxResponseStatus::signal_error(&error);
let error = topics.unwrap().first().unwrap();
return TxResponseStatus::new(return_code, error);
}

TxResponseStatus::default()
Expand Down
6 changes: 3 additions & 3 deletions framework/snippets-base/tests/test_tx_deployed_address.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use multiversx_sc_scenario::imports::Address;
use multiversx_sc_scenario::imports::{Address, ReturnCode};
use multiversx_sc_snippets_base::network_response;
use multiversx_sc_snippets_base::sdk::data::transaction::{TransactionInfo, TransactionOnNetwork};
use multiversx_sdk::bech32;
Expand Down Expand Up @@ -54,7 +54,7 @@ fn test_deployed_address() {
.data
.unwrap()
.transaction;
let tx_response = network_response::parse_tx_response(tx_on_network);
let tx_response = network_response::parse_tx_response(tx_on_network, ReturnCode::Success);
let opt_address = tx_response
.new_deployed_address
.map(|address| bech32::encode(&address));
Expand Down Expand Up @@ -123,7 +123,7 @@ fn test_deployed_address_should_be_none_if_not_a_sc_deployment_tx() {
.data
.unwrap()
.transaction;
let tx_response = network_response::parse_tx_response(tx_on_network);
let tx_response = network_response::parse_tx_response(tx_on_network, ReturnCode::Success);
let opt_address = tx_response.new_deployed_address;

let expected: Option<Address> = None;
Expand Down
13 changes: 7 additions & 6 deletions framework/snippets-base/tests/test_tx_issued_token_identifier.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use multiversx_sc_scenario::imports::ReturnCode;
use multiversx_sc_snippets_base::network_response;
use multiversx_sc_snippets_base::sdk::data::transaction::{TransactionInfo, TransactionOnNetwork};

Expand Down Expand Up @@ -203,7 +204,7 @@ fn test_process_issued_token_identifier_fungible() {
.data
.unwrap()
.transaction;
let tx_response = network_response::parse_tx_response(tx_on_network);
let tx_response = network_response::parse_tx_response(tx_on_network, ReturnCode::Success);

let expected: Option<String> = Some("EGLDMEX-95c6d5".to_string());

Expand Down Expand Up @@ -362,7 +363,7 @@ fn test_process_issued_token_identifier_semi_fungible() {
.data
.unwrap()
.transaction;
let tx_response = network_response::parse_tx_response(tx_on_network);
let tx_response = network_response::parse_tx_response(tx_on_network, ReturnCode::Success);

let expected: Option<String> = Some("DOPETEST-77200c".to_string());

Expand Down Expand Up @@ -618,7 +619,7 @@ fn test_process_issued_token_identifier_non_fungible() {
.data
.unwrap()
.transaction;
let tx_response = network_response::parse_tx_response(tx_on_network);
let tx_response = network_response::parse_tx_response(tx_on_network, ReturnCode::Success);

let expected: Option<String> = Some("GEN-868593".to_string());

Expand Down Expand Up @@ -919,7 +920,7 @@ fn test_process_issued_token_identifier_meta_esdt() {
.data
.unwrap()
.transaction;
let tx_response = network_response::parse_tx_response(tx_on_network);
let tx_response = network_response::parse_tx_response(tx_on_network, ReturnCode::Success);

let expected: Option<String> = Some("AVASH-7d8b5d".to_string());

Expand Down Expand Up @@ -1152,7 +1153,7 @@ fn test_set_special_roles_should_not_process_issued_token_identifier() {
.data
.unwrap()
.transaction;
let tx_response = network_response::parse_tx_response(tx_on_network);
let tx_response = network_response::parse_tx_response(tx_on_network, ReturnCode::Success);

let expected: Option<String> = None;

Expand Down Expand Up @@ -1414,7 +1415,7 @@ fn test_multisig_issue_nft_and_set_all_roles() {
.data
.unwrap()
.transaction;
let tx_response = network_response::parse_tx_response(tx_on_network);
let tx_response = network_response::parse_tx_response(tx_on_network, ReturnCode::Success);

let expected = Some("TESTCOLL1-5aa80c".to_string());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use multiversx_sc_scenario::imports::ReturnCode;
use multiversx_sc_snippets_base::network_response;
use multiversx_sc_snippets_base::sdk::data::transaction::{TransactionInfo, TransactionOnNetwork};

Expand Down Expand Up @@ -79,7 +80,7 @@ fn test_with_multi_contract_same_shard_tx_that_has_no_sc_result() {
.data
.unwrap()
.transaction;
let tx_response = network_response::parse_tx_response(tx_on_network);
let tx_response = network_response::parse_tx_response(tx_on_network, ReturnCode::Success);

let expected: Vec<Vec<u8>> = vec![
hex::decode("0a").unwrap(),
Expand Down Expand Up @@ -211,7 +212,7 @@ fn test_with_multi_contract_cross_shard_tx_that_has_no_callback() {
.data
.unwrap()
.transaction;
let tx_response = network_response::parse_tx_response(tx_on_network);
let tx_response = network_response::parse_tx_response(tx_on_network, ReturnCode::Success);

let expected: Vec<Vec<u8>> = vec![];

Expand Down Expand Up @@ -340,7 +341,7 @@ fn test_with_multi_contract_cross_shard_tx_that_has_non_returning_callback() {
.data
.unwrap()
.transaction;
let tx_response = network_response::parse_tx_response(tx_on_network);
let tx_response = network_response::parse_tx_response(tx_on_network, ReturnCode::Success);

let expected: Vec<Vec<u8>> = vec![];

Expand Down Expand Up @@ -469,7 +470,7 @@ fn test_with_multi_contract_cross_shard_tx_that_has_returning_callback() {
.data
.unwrap()
.transaction;
let tx_response = network_response::parse_tx_response(tx_on_network);
let tx_response = network_response::parse_tx_response(tx_on_network, ReturnCode::Success);

let expected: Vec<Vec<u8>> = vec![];

Expand Down
3 changes: 2 additions & 1 deletion framework/snippets-base/tests/test_tx_multiple_sc_results.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use multiversx_sc_scenario::imports::ReturnCode;
use multiversx_sc_snippets_base::network_response::{self, is_out_scr};
use multiversx_sc_snippets_base::sdk::data::transaction::{TransactionInfo, TransactionOnNetwork};

Expand Down Expand Up @@ -285,5 +286,5 @@ fn test_transaction_multiple_sc_results() {
assert!(is_out_scr(
&tx_on_network.smart_contract_results.get(2).unwrap()
));
let _ = network_response::parse_tx_response(tx_on_network);
let _ = network_response::parse_tx_response(tx_on_network, ReturnCode::Success);
}
5 changes: 3 additions & 2 deletions framework/snippets-base/tests/test_tx_sc_result.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use multiversx_sc_scenario::imports::ReturnCode;
use multiversx_sc_snippets_base::network_response;
use multiversx_sc_snippets_base::sdk::data::transaction::{TransactionInfo, TransactionOnNetwork};

Expand Down Expand Up @@ -251,7 +252,7 @@ fn test_with_tx_that_has_sc_result() {
.data
.unwrap()
.transaction;
let tx_response = network_response::parse_tx_response(tx_on_network);
let tx_response = network_response::parse_tx_response(tx_on_network, ReturnCode::Success);

let expected: Vec<Vec<u8>> = vec![
hex::decode("0000000c5745474c442d64376336626200000000000000000000000803856446ff9a304b")
Expand Down Expand Up @@ -339,7 +340,7 @@ fn test_with_tx_that_has_no_sc_result() {
.data
.unwrap()
.transaction;
let tx_response = network_response::parse_tx_response(tx_on_network);
let tx_response = network_response::parse_tx_response(tx_on_network, ReturnCode::Success);

let expected: Vec<Vec<u8>> = vec![
hex::decode("0a").unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pub mod bech32;
pub mod crypto;
pub mod data;
pub mod gateway;
mod retrieve_tx_on_network;
pub mod retrieve_tx_on_network;
pub mod test_wallets;
pub mod utils;
pub mod wallet;
Expand Down
Loading

0 comments on commit a2e0e61

Please sign in to comment.