Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): fix cli_tests made by #2574 #3970

Merged
merged 9 commits into from
Nov 9, 2024
38 changes: 30 additions & 8 deletions crates/iota/src/client_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ pub struct Opts {
/// If not provided, all fields are displayed.
/// The fields are: effects, input, events, object_changes,
/// balance_changes.
#[clap(long, required = false, value_delimiter = ',', num_args = 0.., value_parser = parse_emit_option)]
#[clap(long, required = false, num_args = 0.., value_parser = parse_emit_option, default_value = "effects,input,events,object_changes,balance_changes")]
pub emit: HashSet<EmitOption>,
}

Expand Down Expand Up @@ -2986,7 +2986,7 @@ pub(crate) async fn dry_run_or_execute_or_serialize(
))
} else {
let transaction = Transaction::new(sender_signed_data);
let response = client
let mut response = client
.quorum_driver_api()
.execute_transaction_block(
transaction,
Expand All @@ -2995,9 +2995,17 @@ pub(crate) async fn dry_run_or_execute_or_serialize(
)
.await?;

let errors: &Vec<String> = response.errors.as_ref();
if !errors.is_empty() {
return Err(anyhow!("Error executing transaction: {errors:#?}"));
if let Some(effects) = response.effects.as_mut() {
prerender_clever_errors(effects, client.read_api()).await;
}
let effects = response.effects.as_ref().ok_or_else(|| {
anyhow!("Effects from IotaTransactionBlockResult should not be empty")
})?;
if let IotaExecutionStatus::Failure { error } = effects.status() {
return Err(anyhow!(
"Error executing transaction '{}': {error}",
response.digest
));
}
Ok(IotaClientCommandResult::TransactionBlock(response))
}
Expand Down Expand Up @@ -3030,13 +3038,27 @@ fn opts_from_cli(opts: HashSet<EmitOption>) -> IotaTransactionBlockResponseOptio
show_events: opts.contains(&EmitOption::Events),
show_object_changes: opts.contains(&EmitOption::ObjectChanges),
show_balance_changes: opts.contains(&EmitOption::BalanceChanges),
show_effects: opts.contains(&EmitOption::Effects),
show_effects: true,
show_raw_effects: false,
show_raw_input: false,
}
}
}

fn parse_emit_option(s: &str) -> Result<EmitOption, String> {
EmitOption::from_str(s).map_err(|_| format!("Invalid emit option: {}", s))
fn parse_emit_option(s: &str) -> Result<HashSet<EmitOption>, String> {
DaughterOfMars marked this conversation as resolved.
Show resolved Hide resolved
let mut options = HashSet::new();

// Split the input string by commas and try to parse each part
for part in s.split(',') {
let part = part.trim(); // Trim whitespace
match EmitOption::from_str(part) {
Ok(option) => {
options.insert(option);
}
Err(_) => return Err(format!("Invalid emit option: {}", part)), /* Return error if
* invalid */
}
}

Ok(options)
}
3 changes: 2 additions & 1 deletion crates/iota/tests/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4333,9 +4333,10 @@ async fn test_call_command_emit_args() -> Result<(), anyhow::Error> {
if let Some(tx_block_response) = start_call_result.tx_block_response() {
// Assert Balance Changes are present in the response
assert!(tx_block_response.balance_changes.is_some());
// effects are always in the response
assert!(tx_block_response.effects.is_some());

// Assert every other field is not present in the response
assert!(tx_block_response.effects.is_none());
assert!(tx_block_response.object_changes.is_none());
assert!(tx_block_response.events.is_none());
assert!(tx_block_response.transaction.is_none());
Expand Down
Loading