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
47 changes: 26 additions & 21 deletions crates/iota/src/client_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ pub struct Opts {
/// The fields are: effects, input, events, object_changes,
/// balance_changes.
#[clap(long, required = false, value_delimiter = ',', num_args = 0.., value_parser = parse_emit_option)]
DaughterOfMars marked this conversation as resolved.
Show resolved Hide resolved
pub emit: HashSet<EmitOption>,
pub emit: Option<HashSet<EmitOption>>,
}

/// Global options with gas
Expand All @@ -683,7 +683,7 @@ impl Opts {
dry_run: false,
serialize_unsigned_transaction: false,
serialize_signed_transaction: false,
emit: HashSet::new(),
emit: None,
}
}
/// Uses the passed gas_budget for the gas budget variable, sets dry run to
Expand All @@ -695,7 +695,7 @@ impl Opts {
dry_run: true,
serialize_unsigned_transaction: false,
serialize_signed_transaction: false,
emit: HashSet::new(),
emit: None,
}
}

Expand All @@ -708,7 +708,7 @@ impl Opts {
dry_run: false,
serialize_unsigned_transaction: false,
serialize_signed_transaction: false,
emit,
emit: Some(emit),
}
}
}
Expand Down Expand Up @@ -3016,23 +3016,28 @@ pub(crate) async fn prerender_clever_errors(
}
}

fn opts_from_cli(opts: HashSet<EmitOption>) -> IotaTransactionBlockResponseOptions {
if opts.is_empty() {
IotaTransactionBlockResponseOptions::new()
.with_effects()
.with_input()
.with_events()
.with_object_changes()
.with_balance_changes()
} else {
IotaTransactionBlockResponseOptions {
show_input: opts.contains(&EmitOption::Input),
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_raw_effects: false,
show_raw_input: false,
fn opts_from_cli(opts: Option<HashSet<EmitOption>>) -> IotaTransactionBlockResponseOptions {
match opts {
None => {
// If `opts` is None, use default settings
IotaTransactionBlockResponseOptions::new()
.with_effects()
.with_input()
.with_events()
.with_object_changes()
.with_balance_changes()
}
Some(options) => {
// If `opts` has a `HashSet`, use its contents to customize settings
IotaTransactionBlockResponseOptions {
show_input: options.contains(&EmitOption::Input),
show_events: options.contains(&EmitOption::Events),
show_object_changes: options.contains(&EmitOption::ObjectChanges),
show_balance_changes: options.contains(&EmitOption::BalanceChanges),
show_effects: options.contains(&EmitOption::Effects),
show_raw_effects: false,
show_raw_input: false,
}
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions crates/iota/src/client_ptb/ptb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Modifications Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use std::collections::HashSet;

use anyhow::{Error, anyhow, ensure};
use clap::{Args, ValueHint, arg};
use iota_json_rpc_types::{IotaExecutionStatus, IotaTransactionBlockEffectsAPI};
Expand Down Expand Up @@ -156,7 +154,7 @@ impl PTB {
gas_budget: program_metadata.gas_budget.map(|x| x.value),
serialize_unsigned_transaction: program_metadata.serialize_unsigned_set,
serialize_signed_transaction: program_metadata.serialize_signed_set,
emit: HashSet::new(),
emit: None,
},
};

Expand Down
8 changes: 4 additions & 4 deletions crates/iota/tests/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2982,7 +2982,7 @@ async fn test_serialize_tx() -> Result<(), anyhow::Error> {
dry_run: false,
serialize_unsigned_transaction: true,
serialize_signed_transaction: false,
emit: HashSet::new(),
emit: None,
},
}
.execute(context)
Expand All @@ -2997,7 +2997,7 @@ async fn test_serialize_tx() -> Result<(), anyhow::Error> {
dry_run: false,
serialize_unsigned_transaction: false,
serialize_signed_transaction: true,
emit: HashSet::new(),
emit: None,
},
}
.execute(context)
Expand All @@ -3013,7 +3013,7 @@ async fn test_serialize_tx() -> Result<(), anyhow::Error> {
dry_run: false,
serialize_unsigned_transaction: false,
serialize_signed_transaction: true,
emit: HashSet::new(),
emit: None,
},
}
.execute(context)
Expand Down Expand Up @@ -3865,7 +3865,7 @@ async fn test_gas_estimation() -> Result<(), anyhow::Error> {
dry_run: false,
serialize_unsigned_transaction: false,
serialize_signed_transaction: false,
emit: HashSet::new(),
emit: None,
},
}
.execute(context)
Expand Down
Loading