Skip to content

Commit

Permalink
Merge branch 'main' into feat/os-keychain-followup
Browse files Browse the repository at this point in the history
  • Loading branch information
elizabethengelman authored Jan 13, 2025
2 parents a23be7a + 6425231 commit 7b8d00c
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ jobs:
- os: ubuntu-latest-16-cores
target: x86_64-unknown-linux-gnu
cargo-hack-feature-options: --feature-powerset
additional-deb-packages: libudev-dev
additional-deb-packages: libudev-dev libdbus-1-dev
# TODO: add back ARM support
#- os: ubuntu-latest-16-cores
# target: aarch64-unknown-linux-gnu
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
with:
debug-only: false
days-before-stale: 30
days-before-close: 30
stale-issue-message: 'This issue is stale because it has been assigned for 30 days with no activity. It will be closed in 30 days unless the stale label is removed, and the assignee is removed or updated.'
stale-pr-message: 'This pull request is stale because it has been open for 30 days with no activity. It will be closed in 30 days unless the stale label is removed.'
days-before-close: 90
stale-issue-message: 'This issue is stale because it has been assigned for 30 days with no activity. It will be closed in 90 days unless the stale label is removed, and the assignee is removed or updated.'
stale-pr-message: 'This pull request is stale because it has been open for 30 days with no activity. It will be closed in 90 days unless the stale label is removed.'
stale-issue-label: stale
stale-pr-label: stale
remove-stale-when-updated: true
Expand Down
1 change: 1 addition & 0 deletions FULL_HELP_DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ Deploy builtin Soroban Asset Contract
* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction and only write the base64 xdr to stdout
* `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout
* `--alias <ALIAS>` — The alias that will be used to save the assets's id. Whenever used, `--alias` will always overwrite the existing contract id configuration without asking for confirmation



Expand Down
1 change: 1 addition & 0 deletions cmd/soroban-cli/src/commands/contract/deploy.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::commands::global;

pub mod asset;
pub mod utils;
pub mod wasm;

#[derive(Debug, clap::Subcommand)]
Expand Down
22 changes: 22 additions & 0 deletions cmd/soroban-cli/src/commands/contract/deploy/asset.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::config::locator;
use crate::xdr::{
Asset, ContractDataDurability, ContractExecutable, ContractIdPreimage, CreateContractArgs,
Error as XdrError, Hash, HostFunction, InvokeHostFunctionOp, LedgerKey::ContractData,
Expand All @@ -21,6 +22,8 @@ use crate::{
utils::contract_id_hash_from_asset,
};

use crate::commands::contract::deploy::utils::alias_validator;

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("error parsing int: {0}")]
Expand All @@ -39,6 +42,8 @@ pub enum Error {
Network(#[from] network::Error),
#[error(transparent)]
Builder(#[from] builder::Error),
#[error(transparent)]
Locator(#[from] locator::Error),
}

impl From<Infallible> for Error {
Expand All @@ -56,8 +61,15 @@ pub struct Cmd {

#[command(flatten)]
pub config: config::Args,

#[command(flatten)]
pub fee: crate::fee::Args,

/// The alias that will be used to save the assets's id.
/// Whenever used, `--alias` will always overwrite the existing contract id
/// configuration without asking for confirmation.
#[arg(long, value_parser = clap::builder::ValueParser::new(alias_validator))]
pub alias: Option<String>,
}

impl Cmd {
Expand All @@ -66,6 +78,16 @@ impl Cmd {
match res {
TxnEnvelopeResult::TxnEnvelope(tx) => println!("{}", tx.to_xdr_base64(Limits::none())?),
TxnEnvelopeResult::Res(contract) => {
let network = self.config.get_network()?;

if let Some(alias) = self.alias.clone() {
self.config.locator.save_contract_id(
&network.network_passphrase,
&contract,
&alias,
)?;
}

println!("{contract}");
}
}
Expand Down
56 changes: 56 additions & 0 deletions cmd/soroban-cli/src/commands/contract/deploy/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use regex::Regex;

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(
"alias must be 1-30 chars long, and have only letters, numbers, underscores and dashes"
)]
InvalidAliasFormat { alias: String },
}

pub fn alias_validator(alias: &str) -> Result<String, Error> {
let regex = Regex::new(r"^[a-zA-Z0-9_-]{1,30}$").unwrap();

if regex.is_match(alias) {
Ok(alias.into())
} else {
Err(Error::InvalidAliasFormat {
alias: alias.into(),
})
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_alias_validator_with_valid_inputs() {
let valid_inputs = [
"hello",
"123",
"hello123",
"hello_123",
"123_hello",
"123-hello",
"hello-123",
"HeLlo-123",
];

for input in valid_inputs {
let result = alias_validator(input);
assert!(result.is_ok());
assert!(result.unwrap() == input);
}
}

#[test]
fn test_alias_validator_with_invalid_inputs() {
let invalid_inputs = ["", "invalid!", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"];

for input in invalid_inputs {
let result = alias_validator(input);
assert!(result.is_err());
}
}
}
44 changes: 1 addition & 43 deletions cmd/soroban-cli/src/commands/contract/deploy/wasm.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::commands::contract::deploy::utils::alias_validator;
use std::array::TryFromSliceError;
use std::ffi::OsString;
use std::fmt::Debug;
Expand All @@ -12,7 +13,6 @@ use crate::xdr::{
};
use clap::{arg, command, Parser};
use rand::Rng;
use regex::Regex;

use soroban_spec_tools::contract as contract_spec;

Expand Down Expand Up @@ -152,18 +152,6 @@ impl Cmd {
}
}

fn alias_validator(alias: &str) -> Result<String, Error> {
let regex = Regex::new(r"^[a-zA-Z0-9_-]{1,30}$").unwrap();

if regex.is_match(alias) {
Ok(alias.into())
} else {
Err(Error::InvalidAliasFormat {
alias: alias.into(),
})
}
}

#[async_trait::async_trait]
impl NetworkRunnable for Cmd {
type Error = Error;
Expand Down Expand Up @@ -390,34 +378,4 @@ mod tests {

assert!(result.is_ok());
}

#[test]
fn test_alias_validator_with_valid_inputs() {
let valid_inputs = [
"hello",
"123",
"hello123",
"hello_123",
"123_hello",
"123-hello",
"hello-123",
"HeLlo-123",
];

for input in valid_inputs {
let result = alias_validator(input);
assert!(result.is_ok());
assert!(result.unwrap() == input);
}
}

#[test]
fn test_alias_validator_with_invalid_inputs() {
let invalid_inputs = ["", "invalid!", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"];

for input in invalid_inputs {
let result = alias_validator(input);
assert!(result.is_err());
}
}
}

0 comments on commit 7b8d00c

Please sign in to comment.