Skip to content

Commit

Permalink
Merge branch 'main' into move-container-to-root
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmcculloch authored Nov 7, 2024
2 parents aaee636 + 9912694 commit 7f534d2
Show file tree
Hide file tree
Showing 14 changed files with 201 additions and 57 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ test_snapshots
.vscode/settings.json
.idea
local.sh
.stellar
65 changes: 49 additions & 16 deletions FULL_HELP_DOCS.md

Large diffs are not rendered by default.

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

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

Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"build": "tsc"
},
"dependencies": {
"buffer": "6.0.3",
"@stellar/stellar-sdk": "12.1.0"
"@stellar/stellar-sdk": "12.1.0",
"buffer": "6.0.3"
},
"devDependencies": {
"typescript": "5.3.3"
"typescript": "^5.6.2"
}
}
9 changes: 5 additions & 4 deletions cmd/crates/soroban-spec-typescript/ts-tests/package-lock.json

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

5 changes: 2 additions & 3 deletions cmd/crates/soroban-spec-typescript/ts-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
},
"devDependencies": {
"@ava/typescript": "^4.1.0",
"@stellar/stellar-sdk": "12.2.0",
"@types/node": "^20.4.9",
"@typescript-eslint/eslint-plugin": "^6.10.0",
"@typescript-eslint/parser": "^6.10.0",
"ava": "^5.3.1",
"dotenv": "^16.3.1",
"eslint": "^8.53.0",
"@stellar/stellar-sdk": "12.2.0",
"typescript": "^5.3.3"
"typescript": "^5.6.2"
},
"ava": {
"typescript": {
Expand All @@ -29,4 +29,3 @@
]
}
}

2 changes: 1 addition & 1 deletion cmd/crates/soroban-test/tests/it/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ mod constructor;
mod cookbook;
mod custom_types;
mod dotenv;
mod fund;
mod hello_world;
mod keys;
mod snapshot;
mod tx;
mod util;
Expand Down
23 changes: 0 additions & 23 deletions cmd/crates/soroban-test/tests/it/integration/fund.rs

This file was deleted.

76 changes: 76 additions & 0 deletions cmd/crates/soroban-test/tests/it/integration/keys.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
use predicates::prelude::predicate;
use soroban_test::AssertExt;
use soroban_test::TestEnv;

fn pubkey_for_identity(sandbox: &TestEnv, name: &str) -> String {
let output = sandbox
.new_assert_cmd("keys")
.arg("address")
.arg(name)
.assert()
.stdout_as_str();
return output;
}

#[tokio::test]
#[allow(clippy::too_many_lines)]
async fn fund() {
let sandbox = &TestEnv::new();
sandbox
.new_assert_cmd("keys")
.arg("generate")
.arg("test2")
.assert()
.success();
sandbox
.new_assert_cmd("keys")
.arg("fund")
.arg("test2")
.assert()
// Don't expect error if friendbot indicated that the account is
// already fully funded to the starting balance, because the
// user's goal is to get funded, and the account is funded
// so it is success much the same.
.success();
}

#[tokio::test]
#[allow(clippy::too_many_lines)]
async fn overwrite_identity() {
let sandbox = &TestEnv::new();
sandbox
.new_assert_cmd("keys")
.arg("generate")
.arg("test2")
.assert()
.success();

let initial_pubkey = sandbox
.new_assert_cmd("keys")
.arg("address")
.arg("test2")
.assert()
.stdout_as_str();

sandbox
.new_assert_cmd("keys")
.arg("generate")
.arg("test2")
.assert()
.stderr(predicate::str::contains(
"error: An identity with the name 'test2' already exists",
));

assert_eq!(initial_pubkey, pubkey_for_identity(&sandbox, "test2"));

sandbox
.new_assert_cmd("keys")
.arg("generate")
.arg("test2")
.arg("--overwrite")
.assert()
.stderr(predicate::str::contains("Overwriting identity 'test2'"))
.success();

assert_ne!(initial_pubkey, pubkey_for_identity(&sandbox, "test2"));
}
26 changes: 25 additions & 1 deletion cmd/soroban-cli/src/commands/keys/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ use crate::{commands::global, print::Print};
pub enum Error {
#[error(transparent)]
Config(#[from] locator::Error),

#[error(transparent)]
Secret(#[from] secret::Error),

#[error(transparent)]
Network(#[from] network::Error),

#[error("An identity with the name '{0}' already exists")]
IdentityAlreadyExists(String),
}

#[derive(Debug, clap::Parser, Clone)]
Expand Down Expand Up @@ -52,29 +57,47 @@ pub struct Cmd {
/// Fund generated key pair
#[arg(long, default_value = "false")]
pub fund: bool,

/// Overwrite existing identity if it already exists.
#[arg(long)]
pub overwrite: bool,
}

impl Cmd {
pub async fn run(&self, global_args: &global::Args) -> Result<(), Error> {
let print = Print::new(global_args.quiet);

if self.config_locator.read_identity(&self.name).is_ok() {
if !self.overwrite {
return Err(Error::IdentityAlreadyExists(self.name.clone()));
}

print.exclaimln(format!("Overwriting identity '{}'", &self.name));
}

if !self.fund {
Print::new(global_args.quiet).warnln(
print.warnln(
"Behavior of `generate` will change in the \
future, and it will no longer fund by default. If you want to fund please \
provide `--fund` flag. If you don't need to fund your keys in the future, ignore this \
warning. It can be suppressed with -q flag.",
);
}

let seed_phrase = if self.default_seed {
Secret::test_seed_phrase()
} else {
Secret::from_seed(self.seed.as_deref())
}?;

let secret = if self.as_secret {
seed_phrase.private_key(self.hd_path)?.into()
} else {
seed_phrase
};

self.config_locator.write_identity(&self.name, &secret)?;

if !self.no_fund {
let addr = secret.public_key(self.hd_path)?;
let network = self.network.get(&self.config_locator)?;
Expand All @@ -86,6 +109,7 @@ impl Cmd {
})
.unwrap_or_default();
}

Ok(())
}
}
14 changes: 11 additions & 3 deletions cmd/soroban-cli/src/config/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::str::FromStr;

use crate::xdr;

use super::{locator, secret};
use super::{locator, secret, Config};

/// Address can be either a public key or eventually an alias of a address.
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -31,8 +31,16 @@ impl FromStr for Address {
type Err = Error;

fn from_str(value: &str) -> Result<Self, Self::Err> {
Ok(xdr::MuxedAccount::from_str(value).map_or_else(
|_| Address::AliasOrSecret(value.to_string()),
let mut identity = value.to_string();

if value.is_empty() {
if let Ok(config) = Config::new() {
identity = config.defaults.identity.unwrap_or_default();
}
}

Ok(xdr::MuxedAccount::from_str(&identity).map_or_else(
|_| Address::AliasOrSecret(identity.to_string()),
Address::MuxedAccount,
))
}
Expand Down
7 changes: 6 additions & 1 deletion cmd/soroban-cli/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ pub struct Args {
#[command(flatten)]
pub network: network::Args,

#[arg(long, visible_alias = "source", env = "STELLAR_ACCOUNT")]
#[arg(
long,
visible_alias = "source",
env = "STELLAR_ACCOUNT",
default_value = ""
)]
/// Account that where transaction originates from. Alias `source`.
/// Can be an identity (--source alice), a public key (--source GDKW...),
/// a muxed account (--source MDA…), a secret key (--source SC36…),
Expand Down
1 change: 1 addition & 0 deletions cmd/soroban-cli/src/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,4 @@ create_print_functions!(plus, plusln, "➕");
create_print_functions!(save, saveln, "💾");
create_print_functions!(search, searchln, "🔎");
create_print_functions!(warn, warnln, "⚠️");
create_print_functions!(exclaim, exclaimln, "❗️");

0 comments on commit 7f534d2

Please sign in to comment.