diff --git a/FULL_HELP_DOCS.md b/FULL_HELP_DOCS.md index b7480cb5ed..b48e337b31 100644 --- a/FULL_HELP_DOCS.md +++ b/FULL_HELP_DOCS.md @@ -111,13 +111,11 @@ Utilities to deploy a Stellar Asset Contract or get its id Get Id of builtin Soroban Asset Contract. Deprecated, use `stellar contract id asset` instead -**Usage:** `stellar contract asset id [OPTIONS] --asset --source-account ` +**Usage:** `stellar contract asset id [OPTIONS] --asset --network --source-account ` ###### **Options:** * `--asset ` — ID of the Stellar classic asset to wrap, e.g. "USDC:G...5" -* `--rpc-url ` — RPC server endpoint -* `--network-passphrase ` — Network passphrase to sign the transaction sent to the rpc server * `--network ` — Name of network to use from config * `--source-account ` — Account that signs the final transaction. Alias `source`. Can be an identity (--source alice), a secret key (--source SC36…), or a seed phrase (--source "kite urban…") * `--hd-path ` — If using a seed phrase, which hierarchical deterministic path to use, e.g. `m/44'/148'/{hd_path}`. Example: `--hd-path 1`. Default: `0` @@ -130,13 +128,11 @@ Get Id of builtin Soroban Asset Contract. Deprecated, use `stellar contract id a Deploy builtin Soroban Asset Contract -**Usage:** `stellar contract asset deploy [OPTIONS] --asset --source-account ` +**Usage:** `stellar contract asset deploy [OPTIONS] --asset --network --source-account ` ###### **Options:** * `--asset ` — ID of the Stellar classic asset to wrap, e.g. "USDC:G...5" -* `--rpc-url ` — RPC server endpoint -* `--network-passphrase ` — Network passphrase to sign the transaction sent to the rpc server * `--network ` — Name of network to use from config * `--source-account ` — Account that signs the final transaction. Alias `source`. Can be an identity (--source alice), a secret key (--source SC36…), or a seed phrase (--source "kite urban…") * `--hd-path ` — If using a seed phrase, which hierarchical deterministic path to use, e.g. `m/44'/148'/{hd_path}`. Example: `--hd-path 1`. Default: `0` @@ -171,7 +167,7 @@ Utilities to manage contract aliases Remove contract alias -**Usage:** `stellar contract alias remove [OPTIONS] ` +**Usage:** `stellar contract alias remove [OPTIONS] --network ` ###### **Arguments:** @@ -181,8 +177,6 @@ Remove contract alias * `--global` — Use global config * `--config-dir ` — Location of config directory, default is "." -* `--rpc-url ` — RPC server endpoint -* `--network-passphrase ` — Network passphrase to sign the transaction sent to the rpc server * `--network ` — Name of network to use from config @@ -191,7 +185,7 @@ Remove contract alias Add contract alias -**Usage:** `stellar contract alias add [OPTIONS] --id ` +**Usage:** `stellar contract alias add [OPTIONS] --network --id ` ###### **Arguments:** @@ -201,8 +195,6 @@ Add contract alias * `--global` — Use global config * `--config-dir ` — Location of config directory, default is "." -* `--rpc-url ` — RPC server endpoint -* `--network-passphrase ` — Network passphrase to sign the transaction sent to the rpc server * `--network ` — Name of network to use from config * `--overwrite` — Overwrite the contract alias if it already exists * `--id ` — The contract id that will be associated with the alias @@ -213,7 +205,7 @@ Add contract alias Show the contract id associated with a given alias -**Usage:** `stellar contract alias show [OPTIONS] ` +**Usage:** `stellar contract alias show [OPTIONS] --network ` ###### **Arguments:** @@ -223,8 +215,6 @@ Show the contract id associated with a given alias * `--global` — Use global config * `--config-dir ` — Location of config directory, default is "." -* `--rpc-url ` — RPC server endpoint -* `--network-passphrase ` — Network passphrase to sign the transaction sent to the rpc server * `--network ` — Name of network to use from config @@ -284,7 +274,7 @@ Generate Rust bindings Generate a TypeScript / JavaScript package -**Usage:** `stellar contract bindings typescript [OPTIONS] --output-dir --contract-id ` +**Usage:** `stellar contract bindings typescript [OPTIONS] --output-dir --contract-id --network ` ###### **Options:** @@ -294,8 +284,6 @@ Generate a TypeScript / JavaScript package * `--contract-id ` — The contract ID/address on the network * `--global` — Use global config * `--config-dir ` — Location of config directory, default is "." -* `--rpc-url ` — RPC server endpoint -* `--network-passphrase ` — Network passphrase to sign the transaction sent to the rpc server * `--network ` — Name of network to use from config @@ -339,7 +327,7 @@ Extend the time to live ledger of a contract-data ledger entry. If no keys are specified the contract itself is extended. -**Usage:** `stellar contract extend [OPTIONS] --ledgers-to-extend --source-account ` +**Usage:** `stellar contract extend [OPTIONS] --ledgers-to-extend --network --source-account ` ###### **Options:** @@ -360,8 +348,6 @@ If no keys are specified the contract itself is extended. - `temporary`: Temporary -* `--rpc-url ` — RPC server endpoint -* `--network-passphrase ` — Network passphrase to sign the transaction sent to the rpc server * `--network ` — Name of network to use from config * `--source-account ` — Account that signs the final transaction. Alias `source`. Can be an identity (--source alice), a secret key (--source SC36…), or a seed phrase (--source "kite urban…") * `--hd-path ` — If using a seed phrase, which hierarchical deterministic path to use, e.g. `m/44'/148'/{hd_path}`. Example: `--hd-path 1`. Default: `0` @@ -381,15 +367,13 @@ If no keys are specified the contract itself is extended. Deploy a wasm contract -**Usage:** `stellar contract deploy [OPTIONS] --source-account <--wasm |--wasm-hash >` +**Usage:** `stellar contract deploy [OPTIONS] --network --source-account <--wasm |--wasm-hash >` ###### **Options:** * `--wasm ` — WASM file to deploy * `--wasm-hash ` — Hash of the already installed/deployed WASM file * `--salt ` — Custom salt 32-byte salt for the token id -* `--rpc-url ` — RPC server endpoint -* `--network-passphrase ` — Network passphrase to sign the transaction sent to the rpc server * `--network ` — Name of network to use from config * `--source-account ` — Account that signs the final transaction. Alias `source`. Can be an identity (--source alice), a secret key (--source SC36…), or a seed phrase (--source "kite urban…") * `--hd-path ` — If using a seed phrase, which hierarchical deterministic path to use, e.g. `m/44'/148'/{hd_path}`. Example: `--hd-path 1`. Default: `0` @@ -413,7 +397,7 @@ Deploy a wasm contract Fetch a contract's Wasm binary -**Usage:** `stellar contract fetch [OPTIONS] --id ` +**Usage:** `stellar contract fetch [OPTIONS] --id --network ` ###### **Options:** @@ -421,8 +405,6 @@ Fetch a contract's Wasm binary * `-o`, `--out-file ` — Where to write output otherwise stdout is used * `--global` — Use global config * `--config-dir ` — Location of config directory, default is "." -* `--rpc-url ` — RPC server endpoint -* `--network-passphrase ` — Network passphrase to sign the transaction sent to the rpc server * `--network ` — Name of network to use from config @@ -444,13 +426,11 @@ Generate the contract id for a given contract or asset Deploy builtin Soroban Asset Contract -**Usage:** `stellar contract id asset [OPTIONS] --asset --source-account ` +**Usage:** `stellar contract id asset [OPTIONS] --asset --network --source-account ` ###### **Options:** * `--asset ` — ID of the Stellar classic asset to wrap, e.g. "USDC:G...5" -* `--rpc-url ` — RPC server endpoint -* `--network-passphrase ` — Network passphrase to sign the transaction sent to the rpc server * `--network ` — Name of network to use from config * `--source-account ` — Account that signs the final transaction. Alias `source`. Can be an identity (--source alice), a secret key (--source SC36…), or a seed phrase (--source "kite urban…") * `--hd-path ` — If using a seed phrase, which hierarchical deterministic path to use, e.g. `m/44'/148'/{hd_path}`. Example: `--hd-path 1`. Default: `0` @@ -463,13 +443,11 @@ Deploy builtin Soroban Asset Contract Deploy normal Wasm Contract -**Usage:** `stellar contract id wasm [OPTIONS] --salt --source-account ` +**Usage:** `stellar contract id wasm [OPTIONS] --salt --network --source-account ` ###### **Options:** * `--salt ` — ID of the Soroban contract -* `--rpc-url ` — RPC server endpoint -* `--network-passphrase ` — Network passphrase to sign the transaction sent to the rpc server * `--network ` — Name of network to use from config * `--source-account ` — Account that signs the final transaction. Alias `source`. Can be an identity (--source alice), a secret key (--source SC36…), or a seed phrase (--source "kite urban…") * `--hd-path ` — If using a seed phrase, which hierarchical deterministic path to use, e.g. `m/44'/148'/{hd_path}`. Example: `--hd-path 1`. Default: `0` @@ -502,15 +480,13 @@ The data outputted by this command is a stream of `SCSpecEntry` XDR values. See Outputs no data when no data is present in the contract. -**Usage:** `stellar contract info interface [OPTIONS] <--wasm |--wasm-hash |--id >` +**Usage:** `stellar contract info interface [OPTIONS] --network <--wasm |--wasm-hash |--id >` ###### **Options:** * `--wasm ` — Wasm file to extract the data from * `--wasm-hash ` — Wasm hash to get the data for * `--id ` — Contract id to get the data for -* `--rpc-url ` — RPC server endpoint -* `--network-passphrase ` — Network passphrase to sign the transaction sent to the rpc server * `--network ` — Name of network to use from config * `--global` — Use global config * `--config-dir ` — Location of config directory, default is "." @@ -541,15 +517,13 @@ The data outputted by this command is a stream of `SCMetaEntry` XDR values. See Outputs no data when no data is present in the contract. -**Usage:** `stellar contract info meta [OPTIONS] <--wasm |--wasm-hash |--id >` +**Usage:** `stellar contract info meta [OPTIONS] --network <--wasm |--wasm-hash |--id >` ###### **Options:** * `--wasm ` — Wasm file to extract the data from * `--wasm-hash ` — Wasm hash to get the data for * `--id ` — Contract id to get the data for -* `--rpc-url ` — RPC server endpoint -* `--network-passphrase ` — Network passphrase to sign the transaction sent to the rpc server * `--network ` — Name of network to use from config * `--global` — Use global config * `--config-dir ` — Location of config directory, default is "." @@ -580,15 +554,13 @@ The data outputted by this command is a stream of `SCEnvMetaEntry` XDR values. S Outputs no data when no data is present in the contract. -**Usage:** `stellar contract info env-meta [OPTIONS] <--wasm |--wasm-hash |--id >` +**Usage:** `stellar contract info env-meta [OPTIONS] --network <--wasm |--wasm-hash |--id >` ###### **Options:** * `--wasm ` — Wasm file to extract the data from * `--wasm-hash ` — Wasm hash to get the data for * `--id ` — Contract id to get the data for -* `--rpc-url ` — RPC server endpoint -* `--network-passphrase ` — Network passphrase to sign the transaction sent to the rpc server * `--network ` — Name of network to use from config * `--global` — Use global config * `--config-dir ` — Location of config directory, default is "." @@ -662,12 +634,10 @@ Inspect a WASM file listing contract functions, meta, etc Install a WASM file to the ledger without creating a contract instance -**Usage:** `stellar contract install [OPTIONS] --source-account --wasm ` +**Usage:** `stellar contract install [OPTIONS] --network --source-account --wasm ` ###### **Options:** -* `--rpc-url ` — RPC server endpoint -* `--network-passphrase ` — Network passphrase to sign the transaction sent to the rpc server * `--network ` — Name of network to use from config * `--source-account ` — Account that signs the final transaction. Alias `source`. Can be an identity (--source alice), a secret key (--source SC36…), or a seed phrase (--source "kite urban…") * `--hd-path ` — If using a seed phrase, which hierarchical deterministic path to use, e.g. `m/44'/148'/{hd_path}`. Example: `--hd-path 1`. Default: `0` @@ -695,7 +665,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] --id --network --source-account [-- ...]` ###### **Arguments:** @@ -705,8 +675,6 @@ stellar contract invoke ... -- --help * `--id ` — Contract ID to invoke * `--is-view` — View the result simulating and do not sign and submit transaction. Deprecated use `--send=no` -* `--rpc-url ` — RPC server endpoint -* `--network-passphrase ` — Network passphrase to sign the transaction sent to the rpc server * `--network ` — Name of network to use from config * `--source-account ` — Account that signs the final transaction. Alias `source`. Can be an identity (--source alice), a secret key (--source SC36…), or a seed phrase (--source "kite urban…") * `--hd-path ` — If using a seed phrase, which hierarchical deterministic path to use, e.g. `m/44'/148'/{hd_path}`. Example: `--hd-path 1`. Default: `0` @@ -751,7 +719,7 @@ Optimize a WASM file Print the current value of a contract-data ledger entry -**Usage:** `stellar contract read [OPTIONS] --source-account ` +**Usage:** `stellar contract read [OPTIONS] --network --source-account ` ###### **Options:** @@ -782,8 +750,6 @@ Print the current value of a contract-data ledger entry - `temporary`: Temporary -* `--rpc-url ` — RPC server endpoint -* `--network-passphrase ` — Network passphrase to sign the transaction sent to the rpc server * `--network ` — Name of network to use from config * `--source-account ` — Account that signs the final transaction. Alias `source`. Can be an identity (--source alice), a secret key (--source SC36…), or a seed phrase (--source "kite urban…") * `--hd-path ` — If using a seed phrase, which hierarchical deterministic path to use, e.g. `m/44'/148'/{hd_path}`. Example: `--hd-path 1`. Default: `0` @@ -798,7 +764,7 @@ Restore an evicted value for a contract-data legder entry. If no keys are specificed the contract itself is restored. -**Usage:** `stellar contract restore [OPTIONS] --source-account ` +**Usage:** `stellar contract restore [OPTIONS] --network --source-account ` ###### **Options:** @@ -819,8 +785,6 @@ If no keys are specificed the contract itself is restored. * `--ledgers-to-extend ` — Number of ledgers to extend the entry * `--ttl-ledger-only` — Only print the new Time To Live ledger -* `--rpc-url ` — RPC server endpoint -* `--network-passphrase ` — Network passphrase to sign the transaction sent to the rpc server * `--network ` — Name of network to use from config * `--source-account ` — Account that signs the final transaction. Alias `source`. Can be an identity (--source alice), a secret key (--source SC36…), or a seed phrase (--source "kite urban…") * `--hd-path ` — If using a seed phrase, which hierarchical deterministic path to use, e.g. `m/44'/148'/{hd_path}`. Example: `--hd-path 1`. Default: `0` @@ -840,7 +804,7 @@ If no keys are specificed the contract itself is restored. Watch the network for contract events -**Usage:** `stellar events [OPTIONS]` +**Usage:** `stellar events [OPTIONS] --network ` ###### **Options:** @@ -879,8 +843,6 @@ Watch the network for contract events * `--global` — Use global config * `--config-dir ` — Location of config directory, default is "." -* `--rpc-url ` — RPC server endpoint -* `--network-passphrase ` — Network passphrase to sign the transaction sent to the rpc server * `--network ` — Name of network to use from config @@ -944,7 +906,7 @@ Given an identity return its address (public key) Fund an identity on a test network -**Usage:** `stellar keys fund [OPTIONS] ` +**Usage:** `stellar keys fund [OPTIONS] --network ` ###### **Arguments:** @@ -952,8 +914,6 @@ Fund an identity on a test network ###### **Options:** -* `--rpc-url ` — RPC server endpoint -* `--network-passphrase ` — Network passphrase to sign the transaction sent to the rpc server * `--network ` — Name of network to use from config * `--hd-path ` — If identity is a seed phrase use this hd path, default is 0 * `--global` — Use global config @@ -965,7 +925,7 @@ Fund an identity on a test network Generate a new identity with a seed phrase, currently 12 words -**Usage:** `stellar keys generate [OPTIONS] ` +**Usage:** `stellar keys generate [OPTIONS] --network ` ###### **Arguments:** @@ -980,8 +940,6 @@ Generate a new identity with a seed phrase, currently 12 words * `--config-dir ` — Location of config directory, default is "." * `--hd-path ` — When generating a secret key, which `hd_path` should be used from the original `seed_phrase` * `-d`, `--default-seed` — Generate the default seed phrase. Useful for testing. Equivalent to --seed 0000000000000000 -* `--rpc-url ` — RPC server endpoint -* `--network-passphrase ` — Network passphrase to sign the transaction sent to the rpc server * `--network ` — Name of network to use from config @@ -1258,7 +1216,7 @@ Contract addresses include the related wasm, contract data. If a contract is a Stellar asset contract, it includes the asset issuer's account and trust lines, but does not include all the trust lines of other accounts holding the asset. To include them specify the addresses of relevant accounts. -**Usage:** `stellar snapshot create [OPTIONS] --output ` +**Usage:** `stellar snapshot create [OPTIONS] --output --network ` ###### **Options:** @@ -1274,8 +1232,6 @@ If a contract is a Stellar asset contract, it includes the asset issuer's accoun Default value: `snapshot.json` * `--global` — Use global config * `--config-dir ` — Location of config directory, default is "." -* `--rpc-url ` — RPC server endpoint -* `--network-passphrase ` — Network passphrase to sign the transaction sent to the rpc server * `--network ` — Name of network to use from config * `--archive-url ` — Archive URL @@ -1298,12 +1254,10 @@ Sign, Simulate, and Send transactions Simulate a transaction envelope from stdin -**Usage:** `stellar tx simulate [OPTIONS] --source-account ` +**Usage:** `stellar tx simulate [OPTIONS] --network --source-account ` ###### **Options:** -* `--rpc-url ` — RPC server endpoint -* `--network-passphrase ` — Network passphrase to sign the transaction sent to the rpc server * `--network ` — Name of network to use from config * `--source-account ` — Account that signs the final transaction. Alias `source`. Can be an identity (--source alice), a secret key (--source SC36…), or a seed phrase (--source "kite urban…") * `--hd-path ` — If using a seed phrase, which hierarchical deterministic path to use, e.g. `m/44'/148'/{hd_path}`. Example: `--hd-path 1`. Default: `0` @@ -1316,12 +1270,10 @@ Simulate a transaction envelope from stdin Calculate the hash of a transaction envelope from stdin -**Usage:** `stellar tx hash [OPTIONS]` +**Usage:** `stellar tx hash --network ` ###### **Options:** -* `--rpc-url ` — RPC server endpoint -* `--network-passphrase ` — Network passphrase to sign the transaction sent to the rpc server * `--network ` — Name of network to use from config diff --git a/cmd/crates/soroban-spec-typescript/ts-tests/.env b/cmd/crates/soroban-spec-typescript/ts-tests/.env index 93bb4be673..cb3d0c6316 100644 --- a/cmd/crates/soroban-spec-typescript/ts-tests/.env +++ b/cmd/crates/soroban-spec-typescript/ts-tests/.env @@ -1,3 +1,4 @@ +SOROBAN_NETWORK=local SOROBAN_NETWORK_PASSPHRASE="Standalone Network ; February 2017" SOROBAN_RPC_URL="http://localhost:8000/soroban/rpc" SOROBAN_FRIENDBOT_URL="http://localhost:8000/friendbot" diff --git a/cmd/crates/soroban-spec-typescript/ts-tests/initialize.sh b/cmd/crates/soroban-spec-typescript/ts-tests/initialize.sh index d85eff115f..d4cc25bd33 100755 --- a/cmd/crates/soroban-spec-typescript/ts-tests/initialize.sh +++ b/cmd/crates/soroban-spec-typescript/ts-tests/initialize.sh @@ -26,17 +26,17 @@ fi exe() { echo"${@/eval/}" ; "$@" ; } function fund_all() { - exe eval "./soroban keys generate root" - exe eval "./soroban keys fund root" + exe eval "./stellar keys generate root" + exe eval "./stellar keys fund root" } function deploy() { - exe eval "(./soroban contract deploy --quiet --source root --wasm $1 --ignore-checks) > $2" + exe eval "(./stellar contract deploy --quiet --source root --wasm $1 --ignore-checks) > $2" } function deploy_all() { deploy ../../../../target/wasm32-unknown-unknown/test-wasms/test_custom_types.wasm contract-id-custom-types.txt } function bind() { - exe eval "./soroban contract bindings typescript --contract-id $(cat $1) --output-dir ./node_modules/$2 --overwrite" + exe eval "./stellar contract bindings typescript --contract-id $(cat $1) --output-dir ./node_modules/$2 --overwrite" } function bind_all() { bind contract-id-custom-types.txt test-custom-types diff --git a/cmd/crates/soroban-spec-typescript/ts-tests/soroban b/cmd/crates/soroban-spec-typescript/ts-tests/soroban deleted file mode 100755 index d98f247c9d..0000000000 --- a/cmd/crates/soroban-spec-typescript/ts-tests/soroban +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -cargo run --quiet -p soroban-cli -- "$@" diff --git a/cmd/crates/soroban-spec-typescript/ts-tests/src/util.ts b/cmd/crates/soroban-spec-typescript/ts-tests/src/util.ts index a5315a6432..c2408f1805 100644 --- a/cmd/crates/soroban-spec-typescript/ts-tests/src/util.ts +++ b/cmd/crates/soroban-spec-typescript/ts-tests/src/util.ts @@ -3,7 +3,7 @@ import { Address, Keypair } from "@stellar/stellar-sdk"; import { basicNodeSigner } from "@stellar/stellar-sdk/contract"; const rootKeypair = Keypair.fromSecret( - spawnSync("./soroban", ["keys", "show", "root"], { + spawnSync("./stellar", ["keys", "show", "root"], { shell: true, encoding: "utf8", }).stdout.trim(), diff --git a/cmd/crates/soroban-spec-typescript/ts-tests/stellar b/cmd/crates/soroban-spec-typescript/ts-tests/stellar new file mode 100755 index 0000000000..e37763becb --- /dev/null +++ b/cmd/crates/soroban-spec-typescript/ts-tests/stellar @@ -0,0 +1,3 @@ +#!/bin/bash + +cargo run --quiet -p stellar-cli -- "$@" diff --git a/cmd/crates/soroban-test/src/lib.rs b/cmd/crates/soroban-test/src/lib.rs index 544e2d59e4..b4955641d2 100644 --- a/cmd/crates/soroban-test/src/lib.rs +++ b/cmd/crates/soroban-test/src/lib.rs @@ -64,6 +64,7 @@ pub struct TestEnv { impl Default for TestEnv { fn default() -> Self { let temp_dir = TempDir::new().unwrap(); + Self { temp_dir, rpc_url: "http://localhost:8889/soroban/rpc".to_string(), @@ -90,43 +91,13 @@ impl TestEnv { f(&test_env); } - pub fn with_default_network(f: F) { - let test_env = TestEnv::new(); - f(&test_env); - } - - pub fn with_port(host_port: u16) -> TestEnv { - Self::with_rpc_url(&format!("http://localhost:{host_port}/soroban/rpc")) - } - - pub fn with_rpc_url(rpc_url: &str) -> TestEnv { - let env = TestEnv { - rpc_url: rpc_url.to_string(), - ..Default::default() - }; - env.generate_account("test", None).assert().success(); - env - } - - pub fn new() -> TestEnv { - if let Ok(rpc_url) = std::env::var("SOROBAN_RPC_URL") { - return Self::with_rpc_url(&rpc_url); - } - let host_port = std::env::var("SOROBAN_PORT") - .as_deref() - .ok() - .and_then(|n| n.parse().ok()) - .unwrap_or(8000); - Self::with_port(host_port) - } /// Create a new `assert_cmd::Command` for a given subcommand and set's the current directory /// to be the internal `temp_dir`. pub fn new_assert_cmd(&self, subcommand: &str) -> Command { let mut cmd: Command = self.bin(); cmd.arg(subcommand) .env("SOROBAN_ACCOUNT", TEST_ACCOUNT) - .env("SOROBAN_RPC_URL", &self.rpc_url) - .env("SOROBAN_NETWORK_PASSPHRASE", LOCAL_NETWORK_PASSPHRASE) + .env("SOROBAN_NETWORK", "local") .env("XDG_CONFIG_HOME", self.temp_dir.join("config").as_os_str()) .env("XDG_DATA_HOME", self.temp_dir.join("data").as_os_str()) .current_dir(&self.temp_dir); @@ -134,15 +105,18 @@ impl TestEnv { } pub fn bin(&self) -> Command { - Command::cargo_bin("soroban").unwrap_or_else(|_| Command::new("soroban")) + Command::cargo_bin("stellar").unwrap_or_else(|_| Command::new("stellar")) } pub fn generate_account(&self, account: &str, seed: Option) -> Command { let mut cmd = self.new_assert_cmd("keys"); + cmd.arg("generate").arg(account); + if let Some(seed) = seed { cmd.arg(format!("--seed={seed}")); } + cmd } @@ -204,12 +178,7 @@ impl TestEnv { &self, command_str: &[I], ) -> T { - let mut arg = vec![ - "--network=local", - "--rpc-url=http", - "--network-passphrase=AA", - "--source-account=test", - ]; + let mut arg = vec!["--network=local", "--source-account=test"]; let input = command_str .iter() .map(AsRef::as_ref) @@ -223,9 +192,7 @@ impl TestEnv { let config_dir = Some(self.dir().to_path_buf()); config::Args { network: network::Args { - rpc_url: Some(self.rpc_url.clone()), - network_passphrase: Some(LOCAL_NETWORK_PASSPHRASE.to_string()), - network: None, + network: "local".to_string(), }, source_account: account.to_string(), locator: config::locator::Args { @@ -279,13 +246,6 @@ impl TestEnv { .to_string() } - /// Copy the contents of the current `TestEnv` to another `TestEnv` - pub fn fork(&self) -> Result { - let this = TestEnv::new(); - self.save(&this.temp_dir)?; - Ok(this) - } - /// Save the current state of the `TestEnv` to the given directory. pub fn save(&self, dst: &Path) -> Result<(), Error> { fs_extra::dir::copy(&self.temp_dir, dst, &CopyOptions::new())?; diff --git a/cmd/crates/soroban-test/tests/it/config.rs b/cmd/crates/soroban-test/tests/it/config.rs index 70dfaa6934..8c92372657 100644 --- a/cmd/crates/soroban-test/tests/it/config.rs +++ b/cmd/crates/soroban-test/tests/it/config.rs @@ -25,9 +25,13 @@ fn set_and_remove_network() { let dir = sandbox.dir().join(".soroban").join("network"); let mut read_dir = std::fs::read_dir(dir).unwrap(); let file = read_dir.next().unwrap().unwrap(); + assert_eq!(file.file_name().to_str().unwrap(), "local.toml"); + let res = ls(sandbox); - assert_eq!(res[0], "local"); + + assert_eq!(res[1], "local"); + sandbox .new_assert_cmd("network") .arg("rm") @@ -117,7 +121,7 @@ fn set_and_remove_global_network() { .arg("ls") .arg("--global") .assert() - .stdout("global\n"); + .stdout("futurenet\nglobal\nlocal\nmainnet\ntestnet\n"); sandbox .new_assert_cmd("network") @@ -133,7 +137,7 @@ fn set_and_remove_global_network() { .env("XDG_CONFIG_HOME", dir.to_str().unwrap()) .arg("ls") .assert() - .stdout("\n"); + .stdout("futurenet\nlocal\nmainnet\ntestnet\n"); } #[test] diff --git a/cmd/crates/soroban-test/tests/it/integration/wrap.rs b/cmd/crates/soroban-test/tests/it/integration/wrap.rs index c43f5b0077..6a1d8b4845 100644 --- a/cmd/crates/soroban-test/tests/it/integration/wrap.rs +++ b/cmd/crates/soroban-test/tests/it/integration/wrap.rs @@ -4,8 +4,7 @@ use soroban_test::{AssertExt, TestEnv, LOCAL_NETWORK_PASSPHRASE}; #[tokio::test] #[ignore] async fn burn() { - let sandbox = &TestEnv::new(); - let network_passphrase = LOCAL_NETWORK_PASSPHRASE.to_string(); + let sandbox = &TestEnv::default(); let address = sandbox .new_assert_cmd("keys") .arg("address") @@ -22,11 +21,11 @@ async fn burn() { .arg(&asset) .assert() .success(); - // wrap_cmd(&asset).run().await.unwrap(); + let asset = soroban_cli::utils::parsing::parse_asset(&asset).unwrap(); let hash = contract_id_hash_from_asset(&asset, &network_passphrase); let id = stellar_strkey::Contract(hash.0).to_string(); - println!("{id}, {address}"); + sandbox .new_assert_cmd("contract") .args([ @@ -40,6 +39,7 @@ async fn burn() { ]) .assert() .stdout("\"9223372036854775807\"\n"); + sandbox .new_assert_cmd("contract") .arg("invoke") @@ -53,6 +53,7 @@ async fn burn() { ]) .assert() .stdout("true\n"); + sandbox .new_assert_cmd("contract") .args([ @@ -66,6 +67,7 @@ async fn burn() { ]) .assert() .stdout("\"9223372036854775807\"\n"); + sandbox .new_assert_cmd("contract") .arg("invoke") @@ -84,7 +86,6 @@ async fn burn() { .stdout("") .stderr(""); - println!("hi"); sandbox .new_assert_cmd("contract") .args([ diff --git a/cmd/soroban-cli/src/commands/network/add.rs b/cmd/soroban-cli/src/commands/network/add.rs index 20b1afa7b8..2d50ce59d7 100644 --- a/cmd/soroban-cli/src/commands/network/add.rs +++ b/cmd/soroban-cli/src/commands/network/add.rs @@ -1,3 +1,4 @@ +use crate::commands::HEADING_RPC; use crate::config::{locator, network, secret}; use clap::command; @@ -16,8 +17,21 @@ pub struct Cmd { /// Name of network pub name: String, - #[command(flatten)] - pub network: network::Network, + /// RPC server endpoint + #[arg( + long = "rpc-url", + env = "STELLAR_RPC_URL", + help_heading = HEADING_RPC, + )] + pub rpc_url: String, + + /// Network passphrase to sign the transaction sent to the rpc server + #[arg( + long, + env = "STELLAR_NETWORK_PASSPHRASE", + help_heading = HEADING_RPC, + )] + pub network_passphrase: String, #[command(flatten)] pub config_locator: locator::Args, @@ -25,8 +39,12 @@ pub struct Cmd { impl Cmd { pub fn run(&self) -> Result<(), Error> { - Ok(self - .config_locator - .write_network(&self.name, &self.network)?) + let network = network::Network { + rpc_url: self.rpc_url.clone(), + network_passphrase: self.network_passphrase.clone(), + name: self.name.clone(), + }; + + Ok(self.config_locator.write_network(&self.name, &network)?) } } diff --git a/cmd/soroban-cli/src/config/locator.rs b/cmd/soroban-cli/src/config/locator.rs index 86d1004f6d..82ce2eee53 100644 --- a/cmd/soroban-cli/src/config/locator.rs +++ b/cmd/soroban-cli/src/config/locator.rs @@ -192,7 +192,11 @@ impl Args { .flatten() .map(|x| x.0); let default_networks = network::DEFAULTS.keys().map(ToString::to_string); - Ok(saved_networks.chain(default_networks).unique().collect()) + Ok(saved_networks + .chain(default_networks) + .unique() + .sorted_by(Ord::cmp) + .collect()) } pub fn list_networks_long(&self) -> Result, Error> { @@ -210,7 +214,10 @@ impl Args { let default_networks = network::DEFAULTS .into_iter() .map(|(name, network)| ((*name).to_string(), network.into(), "Default".to_owned())); - Ok(saved_networks.chain(default_networks).collect()) + Ok(saved_networks + .chain(default_networks) + .sorted_by(|a, b| Ord::cmp(&a.0, &b.0)) + .collect()) } pub fn read_identity(&self, name: &str) -> Result { diff --git a/cmd/soroban-cli/src/config/network.rs b/cmd/soroban-cli/src/config/network.rs index 9e1eabee39..8a8ce83979 100644 --- a/cmd/soroban-cli/src/config/network.rs +++ b/cmd/soroban-cli/src/config/network.rs @@ -38,72 +38,35 @@ pub enum Error { #[derive(Debug, clap::Args, Clone, Default)] #[group(skip)] pub struct Args { - /// RPC server endpoint - #[arg( - long = "rpc-url", - requires = "network_passphrase", - required_unless_present = "network", - env = "STELLAR_RPC_URL", - help_heading = HEADING_RPC, - )] - pub rpc_url: Option, - /// Network passphrase to sign the transaction sent to the rpc server - #[arg( - long = "network-passphrase", - requires = "rpc_url", - required_unless_present = "network", - env = "STELLAR_NETWORK_PASSPHRASE", - help_heading = HEADING_RPC, - )] - pub network_passphrase: Option, /// Name of network to use from config #[arg( long, - required_unless_present = "rpc_url", - required_unless_present = "network_passphrase", env = "STELLAR_NETWORK", help_heading = HEADING_RPC, )] - pub network: Option, + pub network: String, } impl Args { pub fn get(&self, locator: &locator::Args) -> Result { - if let Some(name) = self.network.as_deref() { - if let Ok(network) = locator.read_network(name) { - return Ok(network); - } - } - if let (Some(rpc_url), Some(network_passphrase)) = - (self.rpc_url.clone(), self.network_passphrase.clone()) - { - Ok(Network { - rpc_url, - network_passphrase, - }) + if let Ok(network) = locator.read_network(self.network.as_str()) { + Ok(network) } else { Err(Error::Network) } } } -#[derive(Debug, clap::Args, Serialize, Deserialize, Clone)] -#[group(skip)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct Network { /// RPC server endpoint - #[arg( - long = "rpc-url", - env = "STELLAR_RPC_URL", - help_heading = HEADING_RPC, - )] pub rpc_url: String, + /// Network passphrase to sign the transaction sent to the rpc server - #[arg( - long, - env = "STELLAR_NETWORK_PASSPHRASE", - help_heading = HEADING_RPC, - )] pub network_passphrase: String, + + /// The alias name for the network entry + pub name: String, } impl Network { @@ -178,31 +141,36 @@ impl Network { } } -pub static DEFAULTS: phf::Map<&'static str, (&'static str, &'static str)> = phf_map! { +pub static DEFAULTS: phf::Map<&'static str, (&'static str, &'static str, &'static str)> = phf_map! { "local" => ( + "local", "http://localhost:8000/rpc", passphrase::LOCAL, ), "futurenet" => ( + "futurenet", "https://rpc-futurenet.stellar.org:443", passphrase::FUTURENET, ), "testnet" => ( + "testnet", "https://soroban-testnet.stellar.org", passphrase::TESTNET, ), "mainnet" => ( + "mainnet", "Bring Your Own: https://developers.stellar.org/docs/data/rpc/rpc-providers", passphrase::MAINNET, ), }; -impl From<&(&str, &str)> for Network { +impl From<&(&str, &str, &str)> for Network { /// Convert the return value of `DEFAULTS.get()` into a Network - fn from(n: &(&str, &str)) -> Self { + fn from(n: &(&str, &str, &str)) -> Self { Self { - rpc_url: n.0.to_string(), - network_passphrase: n.1.to_string(), + name: n.0.to_string(), + rpc_url: n.1.to_string(), + network_passphrase: n.2.to_string(), } } }