From 3c58c355a854fead523955f0d95b9d3e164cb2c0 Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Tue, 26 Sep 2023 15:06:31 +0300 Subject: [PATCH] fmt --- .../tests/transfer_role_whitebox_test.rs | 24 +++--- .../tests/gov_module_whitebox_test.rs | 16 ++-- .../tests/staking_module_whitebox_test.rs | 5 +- .../src/scenario/model/step/sc_call_step.rs | 4 +- .../scenario/model/transaction/tx_response.rs | 73 ++++++++++++------- 5 files changed, 67 insertions(+), 55 deletions(-) diff --git a/contracts/feature-tests/composability/transfer-role-features/tests/transfer_role_whitebox_test.rs b/contracts/feature-tests/composability/transfer-role-features/tests/transfer_role_whitebox_test.rs index c5af4e7712..f57e403f5a 100644 --- a/contracts/feature-tests/composability/transfer-role-features/tests/transfer_role_whitebox_test.rs +++ b/contracts/feature-tests/composability/transfer-role-features/tests/transfer_role_whitebox_test.rs @@ -92,11 +92,9 @@ fn test_transfer_role() { // transfer to user - ok world.whitebox_call( &transfer_role_features_whitebox, - ScCallStep::new().from(USER_ADDRESS_EXPR).esdt_transfer( - TRANSFER_TOKEN_ID, - 0, - "100", - ), + ScCallStep::new() + .from(USER_ADDRESS_EXPR) + .esdt_transfer(TRANSFER_TOKEN_ID, 0, "100"), |sc| { let payments = ManagedVec::from_single_item(EsdtTokenPayment::new( managed_token_id!(TRANSFER_TOKEN_ID), @@ -149,11 +147,9 @@ fn test_transfer_role() { // transfer to sc - ok world.whitebox_call( &transfer_role_features_whitebox, - ScCallStep::new().from(USER_ADDRESS_EXPR).esdt_transfer( - TRANSFER_TOKEN_ID, - 0, - "100", - ), + ScCallStep::new() + .from(USER_ADDRESS_EXPR) + .esdt_transfer(TRANSFER_TOKEN_ID, 0, "100"), |sc| { let payments = ManagedVec::from_single_item(EsdtTokenPayment::new( managed_token_id!(TRANSFER_TOKEN_ID), @@ -183,11 +179,9 @@ fn test_transfer_role() { // transfer to sc - reject world.whitebox_call( &transfer_role_features_whitebox, - ScCallStep::new().from(USER_ADDRESS_EXPR).esdt_transfer( - TRANSFER_TOKEN_ID, - 0, - "100", - ), + ScCallStep::new() + .from(USER_ADDRESS_EXPR) + .esdt_transfer(TRANSFER_TOKEN_ID, 0, "100"), |sc| { let payments = ManagedVec::from_single_item(EsdtTokenPayment::new( managed_token_id!(TRANSFER_TOKEN_ID), diff --git a/contracts/feature-tests/use-module/tests/gov_module_whitebox_test.rs b/contracts/feature-tests/use-module/tests/gov_module_whitebox_test.rs index 3329b748d9..23c7eb8dec 100644 --- a/contracts/feature-tests/use-module/tests/gov_module_whitebox_test.rs +++ b/contracts/feature-tests/use-module/tests/gov_module_whitebox_test.rs @@ -118,11 +118,9 @@ pub fn propose( world.whitebox_call( &use_module_whitebox, - ScCallStep::new().from(proposer).esdt_transfer( - GOV_TOKEN_ID, - 0, - gov_token_amount, - ), + ScCallStep::new() + .from(proposer) + .esdt_transfer(GOV_TOKEN_ID, 0, gov_token_amount), |sc| { let mut args_managed = ManagedVec::new(); for arg in args { @@ -254,11 +252,9 @@ fn test_change_gov_config() { // owner downvote world.whitebox_call( &use_module_whitebox, - ScCallStep::new().from(OWNER_ADDRESS_EXPR).esdt_transfer( - GOV_TOKEN_ID, - 0, - "200", - ), + ScCallStep::new() + .from(OWNER_ADDRESS_EXPR) + .esdt_transfer(GOV_TOKEN_ID, 0, "200"), |sc| { sc.vote(proposal_id, VoteType::DownVote); }, diff --git a/contracts/feature-tests/use-module/tests/staking_module_whitebox_test.rs b/contracts/feature-tests/use-module/tests/staking_module_whitebox_test.rs index 920701173e..832c9ec63f 100644 --- a/contracts/feature-tests/use-module/tests/staking_module_whitebox_test.rs +++ b/contracts/feature-tests/use-module/tests/staking_module_whitebox_test.rs @@ -388,10 +388,7 @@ fn test_staking_module() { world.check_state_step(CheckStateStep::new().put_account( ALICE_ADDRESS_EXPR, - CheckAccount::new().esdt_balance( - STAKING_TOKEN_ID_EXPR, - INITIAL_BALANCE - SLASH_AMOUNT, - ), + CheckAccount::new().esdt_balance(STAKING_TOKEN_ID_EXPR, INITIAL_BALANCE - SLASH_AMOUNT), )); } diff --git a/framework/scenario/src/scenario/model/step/sc_call_step.rs b/framework/scenario/src/scenario/model/step/sc_call_step.rs index b221da3167..3a22c087cf 100644 --- a/framework/scenario/src/scenario/model/step/sc_call_step.rs +++ b/framework/scenario/src/scenario/model/step/sc_call_step.rs @@ -91,7 +91,9 @@ impl ScCallStep { } pub fn multi_esdt_transfer(mut self, tokens: T) -> Self - where T: IntoIterator { + where + T: IntoIterator, + { if self.tx.egld_value.value > 0u32.into() { panic!("Cannot transfer both EGLD and ESDT"); } diff --git a/framework/scenario/src/scenario/model/transaction/tx_response.rs b/framework/scenario/src/scenario/model/transaction/tx_response.rs index 1ab567aba7..68167affdb 100644 --- a/framework/scenario/src/scenario/model/transaction/tx_response.rs +++ b/framework/scenario/src/scenario/model/transaction/tx_response.rs @@ -136,22 +136,20 @@ impl TxResponse { fn process_out_from_log(&self) -> Option>> { if let Some(logs) = &self.api_logs { - logs.events - .iter() - .rev() - .find_map(|event| { - if event.identifier == "writeLog" { - if let Some(data) = &event.data { - let decoded_data = String::from_utf8(base64::decode(data).unwrap()).unwrap(); - if decoded_data.starts_with('@') { - let out = decode_scr_data_or_panic(decoded_data.as_str()); - return Some(out) - } + logs.events.iter().rev().find_map(|event| { + if event.identifier == "writeLog" { + if let Some(data) = &event.data { + let decoded_data = + String::from_utf8(base64::decode(data).unwrap()).unwrap(); + if decoded_data.starts_with('@') { + let out = decode_scr_data_or_panic(decoded_data.as_str()); + return Some(out); } } + } - None - }) + None + }) } else { None } @@ -207,8 +205,8 @@ impl TxResponse { #[cfg(test)] mod tests { - use multiversx_sdk::data::transaction::{TransactionInfo, TransactionOnNetwork}; use crate::scenario_model::TxResponse; + use multiversx_sdk::data::transaction::{TransactionInfo, TransactionOnNetwork}; #[test] fn test_with_tx_that_has_sc_result() { @@ -455,12 +453,17 @@ mod tests { } "#; - let tx_on_network: TransactionOnNetwork = serde_json::from_str::(data).unwrap().data.unwrap().transaction; + let tx_on_network: TransactionOnNetwork = serde_json::from_str::(data) + .unwrap() + .data + .unwrap() + .transaction; let tx_response = TxResponse::from_network_tx(tx_on_network); let expected: Vec> = vec![ - hex::decode("0000000c5745474c442d64376336626200000000000000000000000803856446ff9a304b").unwrap(), - hex::decode("10").unwrap() + hex::decode("0000000c5745474c442d64376336626200000000000000000000000803856446ff9a304b") + .unwrap(), + hex::decode("10").unwrap(), ]; assert_eq!(tx_response.out, expected) @@ -538,12 +541,16 @@ mod tests { } "#; - let tx_on_network: TransactionOnNetwork = serde_json::from_str::(data).unwrap().data.unwrap().transaction; + let tx_on_network: TransactionOnNetwork = serde_json::from_str::(data) + .unwrap() + .data + .unwrap() + .transaction; let tx_response = TxResponse::from_network_tx(tx_on_network); let expected: Vec> = vec![ hex::decode("0a").unwrap(), - hex::decode("0218711a00").unwrap() + hex::decode("0218711a00").unwrap(), ]; assert_eq!(tx_response.out, expected) @@ -622,12 +629,16 @@ mod tests { } "#; - let tx_on_network: TransactionOnNetwork = serde_json::from_str::(data).unwrap().data.unwrap().transaction; + let tx_on_network: TransactionOnNetwork = serde_json::from_str::(data) + .unwrap() + .data + .unwrap() + .transaction; let tx_response = TxResponse::from_network_tx(tx_on_network); let expected: Vec> = vec![ hex::decode("0a").unwrap(), - hex::decode("0218711a00").unwrap() + hex::decode("0218711a00").unwrap(), ]; assert_eq!(tx_response.out, expected) @@ -750,7 +761,11 @@ mod tests { } "#; - let tx_on_network: TransactionOnNetwork = serde_json::from_str::(data).unwrap().data.unwrap().transaction; + let tx_on_network: TransactionOnNetwork = serde_json::from_str::(data) + .unwrap() + .data + .unwrap() + .transaction; let tx_response = TxResponse::from_network_tx(tx_on_network); let expected: Vec> = vec![]; @@ -875,7 +890,11 @@ mod tests { } "#; - let tx_on_network: TransactionOnNetwork = serde_json::from_str::(data).unwrap().data.unwrap().transaction; + let tx_on_network: TransactionOnNetwork = serde_json::from_str::(data) + .unwrap() + .data + .unwrap() + .transaction; let tx_response = TxResponse::from_network_tx(tx_on_network); let expected: Vec> = vec![]; @@ -1000,11 +1019,15 @@ mod tests { } "#; - let tx_on_network: TransactionOnNetwork = serde_json::from_str::(data).unwrap().data.unwrap().transaction; + let tx_on_network: TransactionOnNetwork = serde_json::from_str::(data) + .unwrap() + .data + .unwrap() + .transaction; let tx_response = TxResponse::from_network_tx(tx_on_network); let expected: Vec> = vec![]; assert_eq!(tx_response.out, expected) } -} \ No newline at end of file +}