Skip to content

Commit

Permalink
[CLI] Add dev inspect to CLI (#19972)
Browse files Browse the repository at this point in the history
## Description 

This PR adds a `dev-inspect` flag to all executing-related commands.

## Test plan 

Existing tests.

```
sui client split-coin --coin-id 0x167f03292b0689800a149b62d6ac2f5163e1dd4995964195c521e0f3ff46183a --count 2 --dev-inspect
Dev inspect completed, execution status: success
╭───────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Transaction Effects                                                                               │
├───────────────────────────────────────────────────────────────────────────────────────────────────┤
│ Digest: EHA6riF3SUU7UCa6xi11yTs3pN8exdzhF8hoNfiTGFF6                                              │
│ Status: Success                                                                                   │
│ Executed Epoch: 1                                                                                 │
│                                                                                                   │
│ Created Objects:                                                                                  │
│  ┌──                                                                                              │
│  │ ID: 0x3232cf6376bd59392f453b3ec15d0a98178e35c9966c2e23e797ccbc84c342e0                         │
│  │ Owner: Account Address ( 0xa24c44f9e1f09e3675d39c50f6182b36e5e8a8c39b677666910c8091d681bd8c )  │
│  │ Version: 3                                                                                     │
│  │ Digest: BqjHeBCvAwT3GdpqEK2JoeGTjmRSD68i8nuRQ51k8UBk                                           │
│  └──                                                                                              │
│ Mutated Objects:                                                                                  │
│  ┌──                                                                                              │
│  │ ID: 0x167f03292b0689800a149b62d6ac2f5163e1dd4995964195c521e0f3ff46183a                         │
│  │ Owner: Account Address ( 0xa24c44f9e1f09e3675d39c50f6182b36e5e8a8c39b677666910c8091d681bd8c )  │
│  │ Version: 3                                                                                     │
│  │ Digest: 3XpnrJY6nBve6GGVepHyN9j3ht7KyvunQiJdhGy1rbLH                                           │
│  └──                                                                                              │
│  ┌──                                                                                              │
│  │ ID: 0x87b0a482a46961d091743e6669d797c836a49e9b8c6c8ba31b127d8c42ace233                         │
│  │ Owner: Account Address ( 0xa24c44f9e1f09e3675d39c50f6182b36e5e8a8c39b677666910c8091d681bd8c )  │
│  │ Version: 3                                                                                     │
│  │ Digest: 3PYdrT9b13m8zsG4gCcTiUEeJsEEvanmmCpZP6PE6BNc                                           │
│  └──                                                                                              │
│ Gas Object:                                                                                       │
│  ┌──                                                                                              │
│  │ ID: 0x87b0a482a46961d091743e6669d797c836a49e9b8c6c8ba31b127d8c42ace233                         │
│  │ Owner: Account Address ( 0xa24c44f9e1f09e3675d39c50f6182b36e5e8a8c39b677666910c8091d681bd8c )  │
│  │ Version: 3                                                                                     │
│  │ Digest: 3PYdrT9b13m8zsG4gCcTiUEeJsEEvanmmCpZP6PE6BNc                                           │
│  └──                                                                                              │
│ Gas Cost Summary:                                                                                 │
│    Storage Cost: 2964000 MIST                                                                     │
│    Computation Cost: 1000000 MIST                                                                 │
│    Storage Rebate: 978120 MIST                                                                    │
│    Non-refundable Storage Fee: 9880 MIST                                                          │
│                                                                                                   │
│ Transaction Dependencies:                                                                         │
│    AFFmrzPEf73hmgZkeEQbAMr2br6JKQZsiFUNoAPrDq94                                                   │
│    AJudmLDT8jJ6uyh1gqZVF5gZ61GwuKx882BJkbkJMrXa                                                   │
╰───────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─────────────────────────────╮
│ No transaction block events │
╰─────────────────────────────╯
Execution Result  Mutable Reference Outputs    Sui Argument: Input(0)
    Sui TypeTag: SuiTypeTag("0x2::coin::Coin<0x2::sui::SUI>")
    Bytes: [22, 127, 3, 41, 43, 6, 137, 128, 10, 20, 155, 98, 214, 172, 47, 81, 99, 225, 221, 73, 149, 150, 65, 149, 197, 33, 224, 243, 255, 70, 24, 58, 0, 232, 118, 72, 23, 0, 0, 0]
  Return values
```
---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [x] CLI: You can now pass `--dev-inspect` flag to all relevant `sui
client` commands, similarly to the existing `--dry-run` flag.
- [ ] Rust SDK:
- [ ] REST API:
  • Loading branch information
stefan-mysten authored Oct 23, 2024
1 parent ac10df6 commit 4a2d6fb
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 5 deletions.
86 changes: 81 additions & 5 deletions crates/sui/src/client_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ use sui_source_validation::{BytecodeSourceVerifier, ValidationMode};
use shared_crypto::intent::Intent;
use sui_json::SuiJsonValue;
use sui_json_rpc_types::{
Coin, DryRunTransactionBlockResponse, DynamicFieldPage, SuiCoinMetadata, SuiData,
SuiExecutionStatus, SuiObjectData, SuiObjectDataOptions, SuiObjectResponse,
SuiObjectResponseQuery, SuiParsedData, SuiProtocolConfigValue, SuiRawData,
Coin, DevInspectArgs, DevInspectResults, DryRunTransactionBlockResponse, DynamicFieldPage,
SuiCoinMetadata, SuiData, SuiExecutionStatus, SuiObjectData, SuiObjectDataOptions,
SuiObjectResponse, SuiObjectResponseQuery, SuiParsedData, SuiProtocolConfigValue, SuiRawData,
SuiTransactionBlockEffects, SuiTransactionBlockEffectsAPI, SuiTransactionBlockResponse,
SuiTransactionBlockResponseOptions,
};
Expand Down Expand Up @@ -76,6 +76,7 @@ use sui_types::{
object::Owner,
parse_sui_type_tag,
signature::GenericSignature,
sui_serde,
transaction::{
SenderSignedData, Transaction, TransactionData, TransactionDataAPI, TransactionKind,
},
Expand Down Expand Up @@ -593,6 +594,9 @@ pub struct Opts {
/// Perform a dry run of the transaction, without executing it.
#[arg(long)]
pub dry_run: bool,
/// Perform a dev inspect
#[arg(long)]
pub dev_inspect: bool,
/// Instead of executing the transaction, serialize the bcs bytes of the unsigned transaction data
/// (TransactionData) using base64 encoding, and print out the string <TX_BYTES>. The string can
/// be used to execute transaction with `sui client execute-signed-tx --tx-bytes <TX_BYTES>`.
Expand Down Expand Up @@ -623,6 +627,7 @@ impl Opts {
Self {
gas_budget: Some(gas_budget),
dry_run: false,
dev_inspect: false,
serialize_unsigned_transaction: false,
serialize_signed_transaction: false,
}
Expand All @@ -633,6 +638,7 @@ impl Opts {
Self {
gas_budget: Some(gas_budget),
dry_run: true,
dev_inspect: false,
serialize_unsigned_transaction: false,
serialize_signed_transaction: false,
}
Expand Down Expand Up @@ -2226,6 +2232,9 @@ impl Display for SuiClientCommandResult {
SuiClientCommandResult::DryRun(response) => {
writeln!(f, "{}", Pretty(response))?;
}
SuiClientCommandResult::DevInspect(response) => {
writeln!(f, "{}", Pretty(response))?;
}
}
write!(f, "{}", writer.trim_end_matches('\n'))
}
Expand Down Expand Up @@ -2328,6 +2337,7 @@ impl SuiClientCommandResult {
| SuiClientCommandResult::Balance(_, _)
| SuiClientCommandResult::ChainIdentifier(_)
| SuiClientCommandResult::DynamicFieldQuery(_)
| SuiClientCommandResult::DevInspect(_)
| SuiClientCommandResult::Envs(_, _)
| SuiClientCommandResult::Gas(_)
| SuiClientCommandResult::NewAddress(_)
Expand Down Expand Up @@ -2477,6 +2487,7 @@ pub enum SuiClientCommandResult {
ChainIdentifier(String),
DynamicFieldQuery(DynamicFieldPage),
DryRun(DryRunTransactionBlockResponse),
DevInspect(DevInspectResults),
Envs(Vec<SuiEnv>, Option<String>),
Gas(Vec<GasCoin>),
NewAddress(NewAddressOutput),
Expand Down Expand Up @@ -2799,8 +2810,15 @@ pub(crate) async fn dry_run_or_execute_or_serialize(
gas: Option<ObjectID>,
opts: Opts,
) -> Result<SuiClientCommandResult, anyhow::Error> {
let (dry_run, gas_budget, serialize_unsigned_transaction, serialize_signed_transaction) = (
let (
dry_run,
dev_inspect,
gas_budget,
serialize_unsigned_transaction,
serialize_signed_transaction,
) = (
opts.dry_run,
opts.dev_inspect,
opts.gas_budget,
opts.serialize_unsigned_transaction,
opts.serialize_signed_transaction,
Expand All @@ -2815,12 +2833,27 @@ pub(crate) async fn dry_run_or_execute_or_serialize(
context.get_reference_gas_price().await?
};

let client = context.get_client().await?;

if dev_inspect {
return execute_dev_inspect(
context,
signer,
tx_kind,
gas_budget,
gas_price,
gas_payment,
None,
None,
)
.await;
}

let gas = match gas_payment {
Some(obj_ids) => Some(obj_ids),
None => gas.map(|x| vec![x]),
};

let client = context.get_client().await?;
if dry_run {
return execute_dry_run(
context,
Expand Down Expand Up @@ -2905,6 +2938,49 @@ pub(crate) async fn dry_run_or_execute_or_serialize(
}
}

async fn execute_dev_inspect(
context: &mut WalletContext,
signer: SuiAddress,
tx_kind: TransactionKind,
gas_budget: Option<u64>,
gas_price: u64,
gas_payment: Option<Vec<ObjectID>>,
gas_sponsor: Option<SuiAddress>,
skip_checks: Option<bool>,
) -> Result<SuiClientCommandResult, anyhow::Error> {
let client = context.get_client().await?;
let gas_budget = gas_budget.map(sui_serde::BigInt::from);
let mut gas_objs = vec![];
let gas_objects = if let Some(gas_payment) = gas_payment {
for o in gas_payment.iter() {
let obj_ref = context.get_object_ref(*o).await?;
gas_objs.push(obj_ref);
}
Some(gas_objs)
} else {
None
};

let dev_inspect_args = DevInspectArgs {
gas_sponsor,
gas_budget,
gas_objects,
skip_checks,
show_raw_txn_data_and_effects: None,
};
let dev_inspect_result = client
.read_api()
.dev_inspect_transaction_block(
signer,
tx_kind,
Some(sui_serde::BigInt::from(gas_price)),
None,
Some(dev_inspect_args),
)
.await?;
Ok(SuiClientCommandResult::DevInspect(dev_inspect_result))
}

pub(crate) async fn prerender_clever_errors(
effects: &mut SuiTransactionBlockEffects,
read_api: &ReadApi,
Expand Down
3 changes: 3 additions & 0 deletions crates/sui/src/client_ptb/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub const SUMMARY: &str = "summary";
pub const GAS_COIN: &str = "gas-coin";
pub const JSON: &str = "json";
pub const DRY_RUN: &str = "dry-run";
pub const DEV_INSPECT: &str = "dev-inspect";
pub const SERIALIZE_UNSIGNED: &str = "serialize-unsigned-transaction";
pub const SERIALIZE_SIGNED: &str = "serialize-signed-transaction";

Expand Down Expand Up @@ -74,6 +75,7 @@ pub const COMMANDS: &[&str] = &[
GAS_COIN,
JSON,
DRY_RUN,
DEV_INSPECT,
SERIALIZE_UNSIGNED,
SERIALIZE_SIGNED,
];
Expand Down Expand Up @@ -111,6 +113,7 @@ pub struct ProgramMetadata {
pub gas_object_id: Option<Spanned<ObjectID>>,
pub json_set: bool,
pub dry_run_set: bool,
pub dev_inspect_set: bool,
pub gas_budget: Option<Spanned<u64>>,
}

Expand Down
4 changes: 4 additions & 0 deletions crates/sui/src/client_ptb/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ struct ProgramParsingState {
serialize_signed_set: bool,
json_set: bool,
dry_run_set: bool,
dev_inspect_set: bool,
gas_object_id: Option<Spanned<ObjectID>>,
gas_budget: Option<Spanned<u64>>,
}
Expand All @@ -63,6 +64,7 @@ impl<'a, I: Iterator<Item = &'a str>> ProgramParser<'a, I> {
serialize_signed_set: false,
json_set: false,
dry_run_set: false,
dev_inspect_set: false,
gas_object_id: None,
gas_budget: None,
},
Expand Down Expand Up @@ -110,6 +112,7 @@ impl<'a, I: Iterator<Item = &'a str>> ProgramParser<'a, I> {
L(T::Command, A::SUMMARY) => flag!(summary_set),
L(T::Command, A::JSON) => flag!(json_set),
L(T::Command, A::DRY_RUN) => flag!(dry_run_set),
L(T::Command, A::DEV_INSPECT) => flag!(dev_inspect_set),
L(T::Command, A::PREVIEW) => flag!(preview_set),
L(T::Command, A::WARN_SHADOWS) => flag!(warn_shadows_set),
L(T::Command, A::GAS_COIN) => {
Expand Down Expand Up @@ -207,6 +210,7 @@ impl<'a, I: Iterator<Item = &'a str>> ProgramParser<'a, I> {
gas_object_id: self.state.gas_object_id,
json_set: self.state.json_set,
dry_run_set: self.state.dry_run_set,
dev_inspect_set: self.state.dev_inspect_set,
gas_budget: self.state.gas_budget,
},
))
Expand Down
5 changes: 5 additions & 0 deletions crates/sui/src/client_ptb/ptb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ impl PTB {
gas: program_metadata.gas_object_id.map(|x| x.value),
rest: Opts {
dry_run: program_metadata.dry_run_set,
dev_inspect: program_metadata.dev_inspect_set,
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,
Expand Down Expand Up @@ -295,6 +296,10 @@ pub fn ptb_description() -> clap::Command {
--"dry-run"
"Perform a dry run of the PTB instead of executing it."
))
.arg(arg!(
--"dev-inspect"
"Perform a dev-inspect of the PTB instead of executing it."
))
.arg(arg!(
--"gas-coin" <ID> ...
"The object ID of the gas coin to use. If not specified, it will try to use the first \
Expand Down
Loading

0 comments on commit 4a2d6fb

Please sign in to comment.