diff --git a/cmd/crates/soroban-test/src/lib.rs b/cmd/crates/soroban-test/src/lib.rs index 1b8522da7c..bda6ec420f 100644 --- a/cmd/crates/soroban-test/src/lib.rs +++ b/cmd/crates/soroban-test/src/lib.rs @@ -30,7 +30,7 @@ use assert_fs::{fixture::FixtureError, prelude::PathChild, TempDir}; use fs_extra::dir::CopyOptions; use soroban_cli::{ - commands::{config, contract, contract::invoke, global, identity}, + commands::{config, contract, contract::invoke, global, keys}, CommandParser, Pwd, }; @@ -82,6 +82,13 @@ impl TestEnv { pub fn new() -> Result { let this = TempDir::new().map(|temp_dir| TestEnv { temp_dir })?; std::env::set_var("XDG_CONFIG_HOME", this.temp_dir.as_os_str()); + this.new_assert_cmd("keys") + .arg("generate") + .arg("test") + .arg("-d") + .arg("--no-fund") + .assert(); + std::env::set_var("SOROBAN_ACCOUNT", "test"); Ok(this) } @@ -156,17 +163,17 @@ impl TestEnv { &self.temp_dir } - /// Returns the public key corresponding to the test identity's `hd_path` + /// Returns the public key corresponding to the test keys's `hd_path` pub fn test_address(&self, hd_path: usize) -> String { - self.cmd::(&format!("--hd-path={hd_path}")) + self.cmd::(&format!("--hd-path={hd_path}")) .public_key() .unwrap() .to_string() } - /// Returns the private key corresponding to the test identity's `hd_path` + /// Returns the private key corresponding to the test keys's `hd_path` pub fn test_show(&self, hd_path: usize) -> String { - self.cmd::(&format!("--hd-path={hd_path}")) + self.cmd::(&format!("--hd-path={hd_path}")) .private_key() .unwrap() .to_string() diff --git a/cmd/crates/soroban-test/tests/it/config.rs b/cmd/crates/soroban-test/tests/it/config.rs index 40bbdd682e..fe81a00c5c 100644 --- a/cmd/crates/soroban-test/tests/it/config.rs +++ b/cmd/crates/soroban-test/tests/it/config.rs @@ -2,7 +2,7 @@ use assert_fs::TempDir; use soroban_test::TestEnv; use std::{fs, path::Path}; -use crate::util::{add_identity, add_test_id, SecretKind, DEFAULT_SEED_PHRASE}; +use crate::util::{add_key, add_test_id, SecretKind, DEFAULT_SEED_PHRASE}; use soroban_cli::commands::network; const NETWORK_PASSPHRASE: &str = "Local Sandbox Stellar Network ; September 2022"; @@ -137,24 +137,24 @@ fn multiple_networks() { } #[test] -fn read_identity() { +fn read_key() { let sandbox = TestEnv::default(); let dir = sandbox.dir().as_ref(); add_test_id(dir); let ident_dir = dir.join(".soroban/identity"); assert!(ident_dir.exists()); sandbox - .new_assert_cmd("identity") + .new_assert_cmd("keys") .arg("ls") .assert() .stdout("test_id\n"); } #[test] -fn generate_identity() { +fn generate_key() { let sandbox = TestEnv::default(); sandbox - .new_assert_cmd("identity") + .new_assert_cmd("keys") .arg("generate") .arg("--network=futurenet") .arg("--no-fund") @@ -166,7 +166,7 @@ fn generate_identity() { .success(); sandbox - .new_assert_cmd("identity") + .new_assert_cmd("keys") .arg("ls") .assert() .stdout("test\n"); @@ -182,7 +182,7 @@ fn generate_identity() { fn seed_phrase() { let sandbox = TestEnv::default(); let dir = sandbox.dir(); - add_identity( + add_key( dir, "test_seed", SecretKind::Seed, @@ -210,7 +210,7 @@ fn use_env() { let sandbox = TestEnv::default(); sandbox - .new_assert_cmd("identity") + .new_assert_cmd("keys") .env( "SOROBAN_SECRET_KEY", "SDIY6AQQ75WMD4W46EYB7O6UYMHOCGQHLAQGQTKHDX4J2DYQCHVCQYFD", @@ -222,7 +222,7 @@ fn use_env() { .success(); sandbox - .new_assert_cmd("identity") + .new_assert_cmd("keys") .arg("show") .arg("bob") .assert() diff --git a/cmd/crates/soroban-test/tests/it/hello_world.rs b/cmd/crates/soroban-test/tests/it/hello_world.rs index 38b78ee38a..4c45403a13 100644 --- a/cmd/crates/soroban-test/tests/it/hello_world.rs +++ b/cmd/crates/soroban-test/tests/it/hello_world.rs @@ -1,7 +1,4 @@ -use soroban_cli::commands::{ - config::identity, - contract::{self, fetch}, -}; +use soroban_cli::commands::contract::{self, fetch}; use soroban_test::TestEnv; use std::path::PathBuf; @@ -11,13 +8,6 @@ use crate::util::{ TEST_SALT, }; - - - - - - - #[tokio::test] async fn fetch() { if !is_rpc() { diff --git a/cmd/crates/soroban-test/tests/it/integration/hello_world.rs b/cmd/crates/soroban-test/tests/it/integration/hello_world.rs index fed4f44937..7714f70dd4 100644 --- a/cmd/crates/soroban-test/tests/it/integration/hello_world.rs +++ b/cmd/crates/soroban-test/tests/it/integration/hello_world.rs @@ -1,6 +1,6 @@ use soroban_cli::commands::{ - config::identity, contract::{self, fetch}, + keys, }; use soroban_test::TestEnv; @@ -111,7 +111,7 @@ fn invoke_auth(sandbox: &TestEnv, id: &str) { async fn invoke_auth_with_identity(sandbox: &TestEnv, id: &str) { sandbox - .cmd::("test -d ") + .cmd::("test -d ") .run() .await .unwrap(); diff --git a/cmd/crates/soroban-test/tests/it/integration/util.rs b/cmd/crates/soroban-test/tests/it/integration/util.rs index 4cc41474fd..ea27680b76 100644 --- a/cmd/crates/soroban-test/tests/it/integration/util.rs +++ b/cmd/crates/soroban-test/tests/it/integration/util.rs @@ -2,14 +2,14 @@ use soroban_cli::commands::contract; use soroban_test::{TestEnv, Wasm}; use std::{fmt::Display, path::Path}; -use crate::util::{add_identity, SecretKind}; +use crate::util::{add_key, SecretKind}; pub const HELLO_WORLD: &Wasm = &Wasm::Custom("test-wasms", "test_hello_world"); pub const CUSTOM_TYPES: &Wasm = &Wasm::Custom("test-wasms", "test_custom_types"); pub fn add_test_seed(dir: &Path) -> String { let name = "test_seed"; - add_identity( + add_key( dir, name, SecretKind::Seed, diff --git a/cmd/crates/soroban-test/tests/it/integration/wrap.rs b/cmd/crates/soroban-test/tests/it/integration/wrap.rs index f1a453e7a1..e8f7aedf31 100644 --- a/cmd/crates/soroban-test/tests/it/integration/wrap.rs +++ b/cmd/crates/soroban-test/tests/it/integration/wrap.rs @@ -1,9 +1,6 @@ use soroban_cli::CommandParser; use soroban_cli::{ - commands::{ - config::{self}, - lab::token::wrap, - }, + commands::{keys, lab::token::wrap}, utils::contract_id_hash_from_asset, }; use soroban_test::TestEnv; @@ -14,14 +11,16 @@ use super::util::network_passphrase; #[ignore] async fn burn() { let sandbox = &TestEnv::default(); - let address = config::identity::address::Cmd::parse("--hd-path=0") + let network_passphrase = network_passphrase().unwrap(); + println!("NETWORK_PASSPHRASE: {network_passphrase:?}"); + let address = keys::address::Cmd::parse("test") .unwrap() .public_key() .unwrap(); let asset = format!("native:{address}"); 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().unwrap()).unwrap(); + let hash = contract_id_hash_from_asset(&asset, &network_passphrase).unwrap(); let id = stellar_strkey::Contract(hash.0).to_string(); assert_eq!( "CAMTHSPKXZJIRTUXQP5QWJIFH3XIDMKLFAWVQOFOXPTKAW5GKV37ZC4N", @@ -33,6 +32,7 @@ async fn burn() { .invoke(&[ "--id", &id, + "--source=test", "--", "authorized", "--id", @@ -44,7 +44,16 @@ async fn burn() { assert_eq!( "\"9223372036854775807\"", sandbox - .invoke(&["--id", &id, "--", "balance", "--id", &address.to_string()]) + .invoke(&[ + "--id", + &id, + "--source", + "test", + "--", + "balance", + "--id", + &address.to_string() + ]) .await .unwrap(), ); @@ -55,6 +64,7 @@ async fn burn() { .invoke(&[ "--id", &id, + "--source=test", "--", "burn", "--id", @@ -68,12 +78,20 @@ async fn burn() { assert_eq!( "\"9223372036854775707\"", sandbox - .invoke(&["--id", &id, "--", "balance", "--id", &address.to_string()]) + .invoke(&[ + "--id", + &id, + "--source=test", + "--", + "balance", + "--id", + &address.to_string() + ]) .await .unwrap(), ); } fn wrap_cmd(asset: &str) -> wrap::Cmd { - wrap::Cmd::parse_arg_vec(&[&format!("--asset={asset}")]).unwrap() + wrap::Cmd::parse_arg_vec(&["--source=test", &format!("--asset={asset}")]).unwrap() } diff --git a/cmd/crates/soroban-test/tests/it/util.rs b/cmd/crates/soroban-test/tests/it/util.rs index 0bff32a8b8..6d62510126 100644 --- a/cmd/crates/soroban-test/tests/it/util.rs +++ b/cmd/crates/soroban-test/tests/it/util.rs @@ -15,7 +15,7 @@ pub enum SecretKind { } #[allow(clippy::needless_pass_by_value)] -pub fn add_identity(dir: &Path, name: &str, kind: SecretKind, data: &str) { +pub fn add_key(dir: &Path, name: &str, kind: SecretKind, data: &str) { let secret = match kind { SecretKind::Seed => Secret::SeedPhrase { seed_phrase: data.to_string(), @@ -32,7 +32,7 @@ pub fn add_identity(dir: &Path, name: &str, kind: SecretKind, data: &str) { pub fn add_test_id(dir: &Path) -> String { let name = "test_id"; - add_identity( + add_key( dir, name, SecretKind::Key, diff --git a/cmd/soroban-cli/src/commands/config/locator.rs b/cmd/soroban-cli/src/commands/config/locator.rs index f065f72603..2ec449231e 100644 --- a/cmd/soroban-cli/src/commands/config/locator.rs +++ b/cmd/soroban-cli/src/commands/config/locator.rs @@ -58,6 +58,8 @@ pub enum Error { ConfigMissing(String, String), #[error(transparent)] String(#[from] std::string::FromUtf8Error), + #[error(transparent)] + Secret(#[from] crate::commands::config::secret::Error), } #[derive(Debug, clap::Args, Default, Clone)] diff --git a/cmd/soroban-cli/src/commands/contract/invoke.rs b/cmd/soroban-cli/src/commands/contract/invoke.rs index c72048b68b..14b8bd982a 100644 --- a/cmd/soroban-cli/src/commands/contract/invoke.rs +++ b/cmd/soroban-cli/src/commands/contract/invoke.rs @@ -185,8 +185,8 @@ impl Cmd { if let Some(mut val) = matches_.get_raw(&name) { let mut s = val.next().unwrap().to_string_lossy().to_string(); if matches!(i.type_, ScSpecTypeDef::Address) { - let cmd = crate::commands::identity::address::Cmd { - name: Some(s.clone()), + let cmd = crate::commands::keys::address::Cmd { + name: s.clone(), hd_path: Some(0), locator: self.config.locator.clone(), }; diff --git a/cmd/soroban-cli/src/commands/identity/add.rs b/cmd/soroban-cli/src/commands/keys/add.rs similarity index 100% rename from cmd/soroban-cli/src/commands/identity/add.rs rename to cmd/soroban-cli/src/commands/keys/add.rs diff --git a/cmd/soroban-cli/src/commands/identity/address.rs b/cmd/soroban-cli/src/commands/keys/address.rs similarity index 70% rename from cmd/soroban-cli/src/commands/identity/address.rs rename to cmd/soroban-cli/src/commands/keys/address.rs index cdd318ff1d..d13381b49d 100644 --- a/cmd/soroban-cli/src/commands/identity/address.rs +++ b/cmd/soroban-cli/src/commands/keys/address.rs @@ -1,7 +1,6 @@ -use super::super::config::{ - locator, - secret::{self, Secret}, -}; +use crate::commands::config::secret; + +use super::super::config::locator; use clap::arg; #[derive(thiserror::Error, Debug)] @@ -20,7 +19,7 @@ pub enum Error { #[group(skip)] pub struct Cmd { /// Name of identity to lookup, default test identity used if not provided - pub name: Option, + pub name: String, /// If identity is a seed phrase use this hd path, default is 0 #[arg(long)] @@ -37,20 +36,14 @@ impl Cmd { } pub fn private_key(&self) -> Result { - Ok(if let Some(name) = &self.name { - self.locator.read_identity(name)? - } else { - Secret::test_seed_phrase()? - } - .key_pair(self.hd_path)?) + Ok(self + .locator + .read_identity(&self.name)? + .key_pair(self.hd_path)?) } pub fn public_key(&self) -> Result { - if let Some(Ok(key)) = self - .name - .as_deref() - .map(stellar_strkey::ed25519::PublicKey::from_string) - { + if let Ok(key) = stellar_strkey::ed25519::PublicKey::from_string(&self.name) { Ok(key) } else { Ok(stellar_strkey::ed25519::PublicKey::from_payload( diff --git a/cmd/soroban-cli/src/commands/identity/fund.rs b/cmd/soroban-cli/src/commands/keys/fund.rs similarity index 100% rename from cmd/soroban-cli/src/commands/identity/fund.rs rename to cmd/soroban-cli/src/commands/keys/fund.rs diff --git a/cmd/soroban-cli/src/commands/identity/generate.rs b/cmd/soroban-cli/src/commands/keys/generate.rs similarity index 100% rename from cmd/soroban-cli/src/commands/identity/generate.rs rename to cmd/soroban-cli/src/commands/keys/generate.rs diff --git a/cmd/soroban-cli/src/commands/identity/ls.rs b/cmd/soroban-cli/src/commands/keys/ls.rs similarity index 82% rename from cmd/soroban-cli/src/commands/identity/ls.rs rename to cmd/soroban-cli/src/commands/keys/ls.rs index 276232a64c..bc46ffcd85 100644 --- a/cmd/soroban-cli/src/commands/identity/ls.rs +++ b/cmd/soroban-cli/src/commands/keys/ls.rs @@ -26,7 +26,12 @@ impl Cmd { } pub fn ls(&self) -> Result, Error> { - Ok(self.config_locator.list_identities()?) + let mut list = self.config_locator.list_identities()?; + let test = "test".to_string(); + if !list.contains(&test) { + list.push(test); + } + Ok(list) } pub fn ls_l(&self) -> Result, Error> { diff --git a/cmd/soroban-cli/src/commands/identity/mod.rs b/cmd/soroban-cli/src/commands/keys/mod.rs similarity index 100% rename from cmd/soroban-cli/src/commands/identity/mod.rs rename to cmd/soroban-cli/src/commands/keys/mod.rs diff --git a/cmd/soroban-cli/src/commands/identity/rm.rs b/cmd/soroban-cli/src/commands/keys/rm.rs similarity index 100% rename from cmd/soroban-cli/src/commands/identity/rm.rs rename to cmd/soroban-cli/src/commands/keys/rm.rs diff --git a/cmd/soroban-cli/src/commands/identity/show.rs b/cmd/soroban-cli/src/commands/keys/show.rs similarity index 78% rename from cmd/soroban-cli/src/commands/identity/show.rs rename to cmd/soroban-cli/src/commands/keys/show.rs index 45afc4436d..b99478cbc7 100644 --- a/cmd/soroban-cli/src/commands/identity/show.rs +++ b/cmd/soroban-cli/src/commands/keys/show.rs @@ -18,7 +18,7 @@ pub enum Error { #[group(skip)] pub struct Cmd { /// Name of identity to lookup, default is test identity - pub name: Option, + pub name: String, /// If identity is a seed phrase use this hd path, default is 0 #[arg(long)] @@ -35,11 +35,9 @@ impl Cmd { } pub fn private_key(&self) -> Result { - Ok(if let Some(name) = &self.name { - self.locator.read_identity(name)? - } else { - secret::Secret::test_seed_phrase()? - } - .private_key(self.hd_path)?) + Ok(self + .locator + .read_identity(&self.name)? + .private_key(self.hd_path)?) } } diff --git a/cmd/soroban-cli/src/commands/mod.rs b/cmd/soroban-cli/src/commands/mod.rs index 1e4628b50c..f41d55e26c 100644 --- a/cmd/soroban-cli/src/commands/mod.rs +++ b/cmd/soroban-cli/src/commands/mod.rs @@ -7,7 +7,7 @@ pub mod config; pub mod contract; pub mod events; pub mod global; -pub mod identity; +pub mod keys; pub mod lab; pub mod network; pub mod plugin; @@ -98,7 +98,7 @@ impl Root { Cmd::Lab(lab) => lab.run().await?, Cmd::Network(network) => network.run()?, Cmd::Version(version) => version.run(), - Cmd::Identity(id) => id.run().await?, + Cmd::Keys(id) => id.run().await?, }; Ok(()) } @@ -123,8 +123,8 @@ pub enum Cmd { /// Watch the network for contract events Events(events::Cmd), /// Create and manage identities including keys and addresses - #[command(subcommand, visible_alias = "id")] - Identity(identity::Cmd), + #[command(subcommand)] + Keys(keys::Cmd), /// Experiment with early features and expert tools #[command(subcommand)] Lab(lab::Cmd), @@ -143,7 +143,7 @@ pub enum Error { #[error(transparent)] Events(#[from] events::Error), #[error(transparent)] - Identity(#[from] identity::Error), + Keys(#[from] keys::Error), #[error(transparent)] Lab(#[from] lab::Error), #[error(transparent)] diff --git a/cmd/soroban-rpc/internal/test/cli_test.go b/cmd/soroban-rpc/internal/test/cli_test.go index 29767d54ad..37278e598e 100644 --- a/cmd/soroban-rpc/internal/test/cli_test.go +++ b/cmd/soroban-rpc/internal/test/cli_test.go @@ -278,12 +278,13 @@ func runCLICommand(t *testing.T, cmd string) *icmd.Result { c.Env = append(os.Environ(), fmt.Sprintf("SOROBAN_RPC_URL=http://localhost:%d/", sorobanRPCPort), fmt.Sprintf("SOROBAN_NETWORK_PASSPHRASE=%s", StandaloneNetworkPassphrase), + fmt.Sprintf("SOROBAN_ACCOUNT=%s", "test"), ) return icmd.RunCmd(c) } func getCLIDefaultAccount(t *testing.T) string { - return runSuccessfulCLICmd(t, "identity address --hd-path 0") + return "GDIY6AQQ75WMD4W46EYB7O6UYMHOCGQHLAQGQTKHDX4J2DYQCHVCR4W4" } func NewCLITest(t *testing.T) *Test {