Skip to content

Commit

Permalink
Merge branch 'main' into upgrade-typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
fnando authored Nov 7, 2024
2 parents 9bc9fb7 + eb4c0de commit f623dca
Show file tree
Hide file tree
Showing 11 changed files with 431 additions and 46 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

complete:
if: always()
needs: [fmt, check-generated-full-help-docs, build-and-test, publish-dry-run]
needs: [fmt, cargo-deny, check-generated-full-help-docs, build-and-test, publish-dry-run]
runs-on: ubuntu-latest
steps:
- if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
Expand All @@ -30,6 +30,19 @@ jobs:
- run: rustup update
- run: cargo fmt --all --check

cargo-deny:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
check: [advisories, bans, licenses, sources]
continue-on-error: ${{ matrix.check == 'advisories' || matrix.check == 'bans' || matrix.check == 'licenses' }}
steps:
- uses: actions/checkout@v3
- uses: EmbarkStudios/cargo-deny-action@b01e7a8cfb1f496c52d77361e84c1840d8246393
with:
command: check ${{ matrix.check }}

check-generated-full-help-docs:
runs-on: ubuntu-latest-16-cores
steps:
Expand Down
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
38 changes: 19 additions & 19 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions FULL_HELP_DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,7 @@ Generate a new identity with a seed phrase, currently 12 words
* `--fund` — Fund generated key pair

Default value: `false`
* `--overwrite` — Overwrite existing identity if it already exists



Expand Down
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"));
}
7 changes: 6 additions & 1 deletion cmd/crates/stellar-ledger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ version.workspace = true
edition = "2021"
rust-version.workspace = true

# This crate has not yet ever been published. Skip publishing until these
# security issues are addressed:
# https://github.com/stellar/stellar-cli/issues/1706
publish = false

[dependencies]
soroban-spec = { workspace = true }
thiserror = "1.0.32"
Expand Down Expand Up @@ -47,7 +52,7 @@ once_cell = "1.19.0"
pretty_assertions = "1.2.1"
serial_test = "3.0.0"
httpmock = "0.7.0-rc.1"
test-case = "*"
test-case = "3.3.1"
testcontainers = "0.20.1"


Expand Down
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(())
}
}
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, "❗️");
Loading

0 comments on commit f623dca

Please sign in to comment.