Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-marinica authored and thounyy committed Sep 28, 2023
1 parent 9ecb60f commit 3c58c35
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
));
}

Expand Down
4 changes: 3 additions & 1 deletion framework/scenario/src/scenario/model/step/sc_call_step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ impl ScCallStep {
}

pub fn multi_esdt_transfer<T>(mut self, tokens: T) -> Self
where T: IntoIterator<Item = TxESDT> {
where
T: IntoIterator<Item = TxESDT>,
{
if self.tx.egld_value.value > 0u32.into() {
panic!("Cannot transfer both EGLD and ESDT");
}
Expand Down
73 changes: 48 additions & 25 deletions framework/scenario/src/scenario/model/transaction/tx_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,20 @@ impl TxResponse {

fn process_out_from_log(&self) -> Option<Vec<Vec<u8>>> {
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
}
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -455,12 +453,17 @@ mod tests {
}
"#;

let tx_on_network: TransactionOnNetwork = serde_json::from_str::<TransactionInfo>(data).unwrap().data.unwrap().transaction;
let tx_on_network: TransactionOnNetwork = serde_json::from_str::<TransactionInfo>(data)
.unwrap()
.data
.unwrap()
.transaction;
let tx_response = TxResponse::from_network_tx(tx_on_network);

let expected: Vec<Vec<u8>> = vec![
hex::decode("0000000c5745474c442d64376336626200000000000000000000000803856446ff9a304b").unwrap(),
hex::decode("10").unwrap()
hex::decode("0000000c5745474c442d64376336626200000000000000000000000803856446ff9a304b")
.unwrap(),
hex::decode("10").unwrap(),
];

assert_eq!(tx_response.out, expected)
Expand Down Expand Up @@ -538,12 +541,16 @@ mod tests {
}
"#;

let tx_on_network: TransactionOnNetwork = serde_json::from_str::<TransactionInfo>(data).unwrap().data.unwrap().transaction;
let tx_on_network: TransactionOnNetwork = serde_json::from_str::<TransactionInfo>(data)
.unwrap()
.data
.unwrap()
.transaction;
let tx_response = TxResponse::from_network_tx(tx_on_network);

let expected: Vec<Vec<u8>> = vec![
hex::decode("0a").unwrap(),
hex::decode("0218711a00").unwrap()
hex::decode("0218711a00").unwrap(),
];

assert_eq!(tx_response.out, expected)
Expand Down Expand Up @@ -622,12 +629,16 @@ mod tests {
}
"#;

let tx_on_network: TransactionOnNetwork = serde_json::from_str::<TransactionInfo>(data).unwrap().data.unwrap().transaction;
let tx_on_network: TransactionOnNetwork = serde_json::from_str::<TransactionInfo>(data)
.unwrap()
.data
.unwrap()
.transaction;
let tx_response = TxResponse::from_network_tx(tx_on_network);

let expected: Vec<Vec<u8>> = vec![
hex::decode("0a").unwrap(),
hex::decode("0218711a00").unwrap()
hex::decode("0218711a00").unwrap(),
];

assert_eq!(tx_response.out, expected)
Expand Down Expand Up @@ -750,7 +761,11 @@ mod tests {
}
"#;

let tx_on_network: TransactionOnNetwork = serde_json::from_str::<TransactionInfo>(data).unwrap().data.unwrap().transaction;
let tx_on_network: TransactionOnNetwork = serde_json::from_str::<TransactionInfo>(data)
.unwrap()
.data
.unwrap()
.transaction;
let tx_response = TxResponse::from_network_tx(tx_on_network);

let expected: Vec<Vec<u8>> = vec![];
Expand Down Expand Up @@ -875,7 +890,11 @@ mod tests {
}
"#;

let tx_on_network: TransactionOnNetwork = serde_json::from_str::<TransactionInfo>(data).unwrap().data.unwrap().transaction;
let tx_on_network: TransactionOnNetwork = serde_json::from_str::<TransactionInfo>(data)
.unwrap()
.data
.unwrap()
.transaction;
let tx_response = TxResponse::from_network_tx(tx_on_network);

let expected: Vec<Vec<u8>> = vec![];
Expand Down Expand Up @@ -1000,11 +1019,15 @@ mod tests {
}
"#;

let tx_on_network: TransactionOnNetwork = serde_json::from_str::<TransactionInfo>(data).unwrap().data.unwrap().transaction;
let tx_on_network: TransactionOnNetwork = serde_json::from_str::<TransactionInfo>(data)
.unwrap()
.data
.unwrap()
.transaction;
let tx_response = TxResponse::from_network_tx(tx_on_network);

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

assert_eq!(tx_response.out, expected)
}
}
}

0 comments on commit 3c58c35

Please sign in to comment.