Skip to content

Commit

Permalink
Merge branch 'main' into fix/1759-followup
Browse files Browse the repository at this point in the history
  • Loading branch information
elizabethengelman authored Jan 22, 2025
2 parents 550b5f5 + f189a6a commit 5cc2698
Show file tree
Hide file tree
Showing 43 changed files with 731 additions and 268 deletions.
9 changes: 5 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

157 changes: 131 additions & 26 deletions FULL_HELP_DOCS.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cmd/crates/soroban-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ impl TestEnv {

/// Returns the public key corresponding to the test keys's `hd_path`
pub fn test_address(&self, hd_path: usize) -> String {
self.cmd::<keys::address::Cmd>(&format!("--hd-path={hd_path}"))
self.cmd::<keys::public_key::Cmd>(&format!("--hd-path={hd_path}"))
.public_key()
.unwrap()
.to_string()
Expand Down
92 changes: 92 additions & 0 deletions cmd/crates/soroban-test/tests/it/integration/tx/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,71 @@ async fn create_account() {
invoke_hello_world(sandbox, &id);
}

#[tokio::test]
async fn create_account_with_alias() {
let sandbox = &TestEnv::new();
sandbox
.new_assert_cmd("keys")
.args(["generate", "--no-fund", "new"])
.assert()
.success();
let test = test_address(sandbox);
let client = sandbox.client();
let test_account = client.get_account(&test).await.unwrap();
println!("test account has a balance of {}", test_account.balance);
let starting_balance = ONE_XLM * 100;
sandbox
.new_assert_cmd("tx")
.args([
"new",
"create-account",
"--destination",
"new",
"--starting-balance",
starting_balance.to_string().as_str(),
])
.assert()
.success();
let test_account_after = client.get_account(&test).await.unwrap();
assert!(test_account_after.balance < test_account.balance);
let id = deploy_contract(sandbox, HELLO_WORLD, DeployKind::Normal, Some("new")).await;
println!("{id}");
invoke_hello_world(sandbox, &id);
}

#[tokio::test]
async fn payment_with_alias() {
let sandbox = &TestEnv::new();
let client = sandbox.client();
let (test, test1) = setup_accounts(sandbox);
let test_account = client.get_account(&test).await.unwrap();
println!("test account has a balance of {}", test_account.balance);

let before = client.get_account(&test).await.unwrap();
let test1_account_entry_before = client.get_account(&test1).await.unwrap();

sandbox
.new_assert_cmd("tx")
.args([
"new",
"payment",
"--destination",
"test1",
"--amount",
ONE_XLM.to_string().as_str(),
])
.assert()
.success();
let test1_account_entry = client.get_account(&test1).await.unwrap();
assert_eq!(
ONE_XLM,
test1_account_entry.balance - test1_account_entry_before.balance,
"Should have One XLM more"
);
let after = client.get_account(&test).await.unwrap();
assert_eq!(before.balance - 10_000_100, after.balance);
}

#[tokio::test]
async fn payment() {
let sandbox = &TestEnv::new();
Expand Down Expand Up @@ -172,6 +237,33 @@ async fn account_merge() {
assert_eq!(before.balance + before1.balance - fee, after.balance);
}

#[tokio::test]
async fn account_merge_with_alias() {
let sandbox = &TestEnv::new();
let client = sandbox.client();
let (test, test1) = setup_accounts(sandbox);
let before = client.get_account(&test).await.unwrap();
let before1 = client.get_account(&test1).await.unwrap();
let fee = 100;
sandbox
.new_assert_cmd("tx")
.args([
"new",
"account-merge",
"--source",
"test1",
"--account",
"test",
"--fee",
fee.to_string().as_str(),
])
.assert()
.success();
let after = client.get_account(&test).await.unwrap();
assert!(client.get_account(&test1).await.is_err());
assert_eq!(before.balance + before1.balance - fee, after.balance);
}

#[tokio::test]
async fn set_trustline_flags() {
let sandbox = &TestEnv::new();
Expand Down
1 change: 1 addition & 0 deletions cmd/soroban-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ wasm-gen = "0.1.4"
zeroize = "1.8.1"
keyring = { version = "3", features = ["apple-native", "windows-native", "sync-secret-service"] }
whoami = "1.5.2"
serde_with = "3.11.0"
license-fetcher = "0.5.0"


Expand Down
8 changes: 7 additions & 1 deletion cmd/soroban-cli/src/commands/contract/arg_parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,5 +269,11 @@ fn resolve_address(addr_or_alias: &str, config: &config::Args) -> Result<String,
}

fn resolve_signer(addr_or_alias: &str, config: &config::Args) -> Option<SigningKey> {
config.locator.key(addr_or_alias).ok()?.key_pair(None).ok()
config
.locator
.read_key(addr_or_alias)
.ok()?
.private_key(None)
.ok()
.map(|pk| SigningKey::from_bytes(&pk.0))
}
6 changes: 3 additions & 3 deletions cmd/soroban-cli/src/commands/contract/deploy/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use soroban_spec_tools::contract as contract_spec;
use crate::{
assembled::simulate_and_assemble_transaction,
commands::{
contract::{self, arg_parsing, id::wasm::get_contract_id, install},
contract::{self, arg_parsing, id::wasm::get_contract_id, upload},
global,
txn_result::{TxnEnvelopeResult, TxnResult},
NetworkRunnable, HEADING_RPC,
Expand Down Expand Up @@ -73,7 +73,7 @@ pub struct Cmd {
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
Install(#[from] install::Error),
Install(#[from] upload::Error),
#[error("error parsing int: {0}")]
ParseIntError(#[from] ParseIntError),
#[error("internal conversion error: {0}")]
Expand Down Expand Up @@ -180,7 +180,7 @@ impl NetworkRunnable for Cmd {
let hash = if self.fee.build_only || self.fee.sim_only {
wasm::Args { wasm: wasm.clone() }.hash()?
} else {
install::Cmd {
upload::Cmd {
wasm: wasm::Args { wasm: wasm.clone() },
config: config.clone(),
fee: self.fee.clone(),
Expand Down
9 changes: 5 additions & 4 deletions cmd/soroban-cli/src/commands/contract/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ pub mod id;
pub mod info;
pub mod init;
pub mod inspect;
pub mod install;
pub mod invoke;
pub mod optimize;
pub mod read;
pub mod restore;
pub mod upload;

use crate::commands::global;

Expand Down Expand Up @@ -66,7 +66,8 @@ pub enum Cmd {
Inspect(inspect::Cmd),

/// Install a WASM file to the ledger without creating a contract instance
Install(install::Cmd),
#[command(visible_alias = "install")]
Upload(upload::Cmd),

/// Invoke a contract function
///
Expand Down Expand Up @@ -126,7 +127,7 @@ pub enum Error {
Inspect(#[from] inspect::Error),

#[error(transparent)]
Install(#[from] install::Error),
Install(#[from] upload::Error),

#[error(transparent)]
Invoke(#[from] invoke::Error),
Expand Down Expand Up @@ -154,7 +155,7 @@ impl Cmd {
Cmd::Info(info) => info.run(global_args).await?,
Cmd::Init(init) => init.run(global_args)?,
Cmd::Inspect(inspect) => inspect.run(global_args)?,
Cmd::Install(install) => install.run(global_args).await?,
Cmd::Upload(install) => install.run(global_args).await?,
Cmd::Invoke(invoke) => invoke.run(global_args).await?,
Cmd::Optimize(optimize) => optimize.run()?,
Cmd::Fetch(fetch) => fetch.run().await?,
Expand Down
34 changes: 30 additions & 4 deletions cmd/soroban-cli/src/commands/keys/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@ use clap::command;

use crate::{
commands::global,
config::{address::KeyName, locator, secret},
config::{
address::KeyName,
key::{self, Key},
locator,
secret::{self, Secret},
},
print::Print,
};

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
Secret(#[from] secret::Error),

#[error(transparent)]
Key(#[from] key::Error),
#[error(transparent)]
Config(#[from] locator::Error),
}
Expand All @@ -26,14 +32,34 @@ pub struct Cmd {

#[command(flatten)]
pub config_locator: locator::Args,

/// Add a public key, ed25519, or muxed account, e.g. G1.., M2..
#[arg(long, conflicts_with = "seed_phrase", conflicts_with = "secret_key")]
pub public_key: Option<String>,
}

impl Cmd {
pub fn run(&self, global_args: &global::Args) -> Result<(), Error> {
let key = if let Some(key) = self.public_key.as_ref() {
key.parse()?
} else {
self.secrets.read_secret()?.into()
};

let print = Print::new(global_args.quiet);
let secret = self.secrets.read_secret()?;
let path = self.config_locator.write_identity(&self.name, &secret)?;
let path = self.config_locator.write_key(&self.name, &key)?;

if let Key::Secret(Secret::SeedPhrase { seed_phrase }) = key {
if seed_phrase.split_whitespace().count() < 24 {
print.warnln("The provided seed phrase lacks sufficient entropy and should be avoided. Using a 24-word seed phrase is a safer option.".to_string());
print.warnln(
"To generate a new key, use the `stellar keys generate` command.".to_string(),
);
}
}

print.checkln(format!("Key saved with alias {:?} in {path:?}", self.name));

Ok(())
}
}
6 changes: 3 additions & 3 deletions cmd/soroban-cli/src/commands/keys/fund.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use clap::command;

use crate::{commands::global, config::network, print::Print};

use super::address;
use super::public_key;

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
Address(#[from] address::Error),
Address(#[from] public_key::Error),
#[error(transparent)]
Network(#[from] network::Error),
}
Expand All @@ -19,7 +19,7 @@ pub struct Cmd {
pub network: network::Args,
/// Address to fund
#[command(flatten)]
pub address: address::Cmd,
pub address: public_key::Cmd,
}

impl Cmd {
Expand Down
9 changes: 5 additions & 4 deletions cmd/soroban-cli/src/commands/keys/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use super::super::config::{
locator, network,
secret::{self, Secret},
};

use crate::{
commands::global,
config::address::KeyName,
Expand Down Expand Up @@ -178,7 +179,7 @@ impl Cmd {

#[cfg(test)]
mod tests {
use crate::config::{address::KeyName, secret::Secret};
use crate::config::{address::KeyName, key::Key, secret::Secret};
use keyring::{mock, set_default_credential_builder};

fn set_up_test() -> (super::locator::Args, super::Cmd) {
Expand Down Expand Up @@ -220,7 +221,7 @@ mod tests {
let result = cmd.run(&global_args).await;
assert!(result.is_ok());
let identity = test_locator.read_identity("test_name").unwrap();
assert!(matches!(identity, Secret::SeedPhrase { .. }));
assert!(matches!(identity, Key::Secret(Secret::SeedPhrase { .. })));
}

#[tokio::test]
Expand All @@ -232,7 +233,7 @@ mod tests {
let result = cmd.run(&global_args).await;
assert!(result.is_ok());
let identity = test_locator.read_identity("test_name").unwrap();
assert!(matches!(identity, Secret::SecretKey { .. }));
assert!(matches!(identity, Key::Secret(Secret::SecretKey { .. })));
}

#[tokio::test]
Expand All @@ -245,6 +246,6 @@ mod tests {
let result = cmd.run(&global_args).await;
assert!(result.is_ok());
let identity = test_locator.read_identity("test_name").unwrap();
assert!(matches!(identity, Secret::SecureStore { .. }));
assert!(matches!(identity, Key::Secret(Secret::SecureStore { .. })));
}
}
Loading

0 comments on commit 5cc2698

Please sign in to comment.