From b809d2f63f31a16f36d1d0a9e14ad190603108f6 Mon Sep 17 00:00:00 2001 From: Nando Vieira Date: Thu, 17 Sep 2026 10:51:10 -0700 Subject: [PATCH] Accept --contract-id on all contract commands. --- FULL_HELP_DOCS.md | 16 +++---- .../soroban-test/tests/it/contract_id_flag.rs | 44 +++++++++++++++++++ cmd/crates/soroban-test/tests/it/main.rs | 1 + .../src/commands/contract/alias/add.rs | 2 +- .../src/commands/contract/fetch.rs | 8 +++- .../src/commands/contract/invoke.rs | 6 ++- cmd/soroban-cli/src/key.rs | 3 +- 7 files changed, 67 insertions(+), 13 deletions(-) create mode 100644 cmd/crates/soroban-test/tests/it/contract_id_flag.rs diff --git a/FULL_HELP_DOCS.md b/FULL_HELP_DOCS.md index 6a15af08c8..cf01199951 100644 --- a/FULL_HELP_DOCS.md +++ b/FULL_HELP_DOCS.md @@ -210,7 +210,7 @@ Remove contract alias Add contract alias -**Usage:** `stellar contract alias add [OPTIONS] --id ` +**Usage:** `stellar contract alias add [OPTIONS] --contract-id ` ###### **Arguments:** @@ -223,7 +223,7 @@ Add contract alias ###### **Options:** - `--overwrite` — Overwrite the contract alias if it already exists -- `--id ` — The contract id that will be associated with the alias +- `--contract-id ` [alias: `id`] — The contract id that will be associated with the alias ###### **RPC Options:** @@ -437,7 +437,7 @@ If no keys are specified the contract itself is extended. - `--ledgers-to-extend ` — Number of ledgers to extend the entries - `--ttl-ledger-only` — Only print the new Time To Live ledger -- `--id ` — Contract ID to which owns the data entries. If no keys provided the Contract's instance will be extended +- `--contract-id ` [alias: `id`] — Contract ID to which owns the data entries. If no keys provided the Contract's instance will be extended - `--key ` — Storage key (symbols only) - `--key-xdr ` — Storage key (base64-encoded XDR) - `--wasm ` — Path to Wasm file of contract code to extend @@ -558,7 +558,7 @@ Fetch a contract's Wasm binary ###### **Options:** -- `--id ` — Contract ID to fetch +- `--contract-id ` [alias: `id`] — Contract ID to fetch - `--wasm-hash ` — Wasm to fetch - `-o`, `--out-file ` — Where to write output otherwise stdout is used @@ -991,7 +991,7 @@ Generates an "implicit CLI" for the specified contract on-the-fly using the cont stellar contract invoke ... -- --help -**Usage:** `stellar contract invoke [OPTIONS] --id --source-account [-- ...]` +**Usage:** `stellar contract invoke [OPTIONS] --contract-id --source-account [-- ...]` ###### **Arguments:** @@ -1003,7 +1003,7 @@ stellar contract invoke ... -- --help ###### **Options:** -- `--id ` — Contract ID to invoke +- `--contract-id ` [alias: `id`] — Contract ID to invoke - `--is-view` — ⚠️ Deprecated, use `--send=no`. View the result simulating and do not sign and submit transaction - `--send ` — Whether or not to send a transaction @@ -1078,7 +1078,7 @@ Print the current value of a contract-data ledger entry - `json`: Json - `xdr`: XDR -- `--id ` — Contract ID to which owns the data entries. If no keys provided the Contract's instance will be extended +- `--contract-id ` [alias: `id`] — Contract ID to which owns the data entries. If no keys provided the Contract's instance will be extended - `--key ` — Storage key (symbols only) - `--key-xdr ` — Storage key (base64-encoded XDR) - `--wasm ` — Path to Wasm file of contract code to extend @@ -1112,7 +1112,7 @@ If no keys are specificed the contract itself is restored. ###### **Options:** -- `--id ` — Contract ID to which owns the data entries. If no keys provided the Contract's instance will be extended +- `--contract-id ` [alias: `id`] — Contract ID to which owns the data entries. If no keys provided the Contract's instance will be extended - `--key ` — Storage key (symbols only) - `--key-xdr ` — Storage key (base64-encoded XDR) - `--wasm ` — Path to Wasm file of contract code to extend diff --git a/cmd/crates/soroban-test/tests/it/contract_id_flag.rs b/cmd/crates/soroban-test/tests/it/contract_id_flag.rs new file mode 100644 index 0000000000..c6a0f692fa --- /dev/null +++ b/cmd/crates/soroban-test/tests/it/contract_id_flag.rs @@ -0,0 +1,44 @@ +use soroban_test::TestEnv; + +// Every contract subcommand that references an existing contract should expose +// `--contract-id` as the canonical flag with `--id` kept as an alias, matching +// `stellar contract info`. +fn assert_contract_id_flag(subcommand: &[&str]) { + let sandbox = TestEnv::default(); + let help = sandbox + .new_assert_cmd("contract") + .args(subcommand) + .arg("--help") + .assert() + .success() + .get_output() + .stdout + .clone(); + let help = String::from_utf8(help).unwrap(); + + assert!( + help.contains("--contract-id"), + "`contract {}` help is missing --contract-id:\n{help}", + subcommand.join(" ") + ); + assert!( + help.contains("--id"), + "`contract {}` help is missing the --id alias:\n{help}", + subcommand.join(" ") + ); +} + +#[test] +fn contract_id_flag_is_consistent_across_commands() { + for subcommand in [ + &["invoke"][..], + &["fetch"][..], + &["read"][..], + &["extend"][..], + &["restore"][..], + &["info", "interface"][..], + &["alias", "add"][..], + ] { + assert_contract_id_flag(subcommand); + } +} diff --git a/cmd/crates/soroban-test/tests/it/main.rs b/cmd/crates/soroban-test/tests/it/main.rs index 61b62b6b6b..623fac2449 100644 --- a/cmd/crates/soroban-test/tests/it/main.rs +++ b/cmd/crates/soroban-test/tests/it/main.rs @@ -2,6 +2,7 @@ mod build; mod config; #[cfg(unix)] mod container; +mod contract_id_flag; #[cfg(feature = "emulator-tests")] mod emulator; mod help; diff --git a/cmd/soroban-cli/src/commands/contract/alias/add.rs b/cmd/soroban-cli/src/commands/contract/alias/add.rs index 985cc2dc8a..d64fb4da3d 100644 --- a/cmd/soroban-cli/src/commands/contract/alias/add.rs +++ b/cmd/soroban-cli/src/commands/contract/alias/add.rs @@ -23,7 +23,7 @@ pub struct Cmd { pub overwrite: bool, /// The contract id that will be associated with the alias. - #[arg(long = "id")] + #[arg(long = "contract-id", visible_alias = "id")] pub contract_id: stellar_strkey::Contract, } diff --git a/cmd/soroban-cli/src/commands/contract/fetch.rs b/cmd/soroban-cli/src/commands/contract/fetch.rs index a02bf98869..0ee32aba2a 100644 --- a/cmd/soroban-cli/src/commands/contract/fetch.rs +++ b/cmd/soroban-cli/src/commands/contract/fetch.rs @@ -20,7 +20,11 @@ use crate::{ #[group(skip)] pub struct Cmd { /// Contract ID to fetch - #[arg(long = "id", env = "STELLAR_CONTRACT_ID")] + #[arg( + long = "contract-id", + visible_alias = "id", + env = "STELLAR_CONTRACT_ID" + )] pub contract_id: Option, /// Wasm to fetch #[arg(long = "wasm-hash", conflicts_with = "contract_id")] @@ -67,7 +71,7 @@ pub enum Error { Wasm(#[from] wasm::Error), #[error("wasm hash is invalid {0:?}")] InvalidWasmHash(String), - #[error("must provide one of --wasm-hash, or --id")] + #[error("must provide one of --wasm-hash, or --contract-id")] MissingArg, } diff --git a/cmd/soroban-cli/src/commands/contract/invoke.rs b/cmd/soroban-cli/src/commands/contract/invoke.rs index e1c9497ef5..90058a5501 100644 --- a/cmd/soroban-cli/src/commands/contract/invoke.rs +++ b/cmd/soroban-cli/src/commands/contract/invoke.rs @@ -49,7 +49,11 @@ use soroban_spec_tools::contract; #[group(skip)] pub struct Cmd { /// Contract ID to invoke - #[arg(long = "id", env = "STELLAR_CONTRACT_ID")] + #[arg( + long = "contract-id", + visible_alias = "id", + env = "STELLAR_CONTRACT_ID" + )] pub contract_id: config::UnresolvedContract, // For testing only diff --git a/cmd/soroban-cli/src/key.rs b/cmd/soroban-cli/src/key.rs index b9d06acef0..aeaa5d0456 100644 --- a/cmd/soroban-cli/src/key.rs +++ b/cmd/soroban-cli/src/key.rs @@ -30,7 +30,8 @@ pub struct Args { /// Contract ID to which owns the data entries. /// If no keys provided the Contract's instance will be extended #[arg( - long = "id", + long = "contract-id", + visible_alias = "id", required_unless_present = "wasm", required_unless_present = "wasm_hash" )]