Skip to content

Commit

Permalink
fix(cli): fix cli_tests made by #2574
Browse files Browse the repository at this point in the history
Signed-off-by: salaheldinsoliman <[email protected]>
  • Loading branch information
salaheldinsoliman committed Nov 8, 2024
1 parent 3cc3077 commit 429171c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
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)]
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 @@ -3011,23 +3011,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 @@ -2976,7 +2976,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 @@ -2991,7 +2991,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 @@ -3007,7 +3007,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 @@ -3859,7 +3859,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

0 comments on commit 429171c

Please sign in to comment.