Skip to content

Commit

Permalink
Merge branch 'main' into add-long-list-for-identity
Browse files Browse the repository at this point in the history
  • Loading branch information
elizabethengelman authored Nov 22, 2023
2 parents 001ba51 + 7f8ad60 commit e918b49
Show file tree
Hide file tree
Showing 29 changed files with 531 additions and 263 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/soroban-rpc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ jobs:
env:
SOROBAN_RPC_INTEGRATION_TESTS_ENABLED: true
SOROBAN_RPC_INTEGRATION_TESTS_CAPTIVE_CORE_BIN: /usr/bin/stellar-core
PROTOCOL_20_CORE_DEBIAN_PKG_VERSION: 19.14.1-1547.f2d06fbce.focal
PROTOCOL_20_CORE_DEBIAN_PKG_VERSION: 19.14.1-1553.f4c4e2fca.focal
steps:
- uses: actions/checkout@v3
with:
Expand Down
6 changes: 3 additions & 3 deletions cmd/crates/soroban-spec-typescript/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,12 @@ pub fn entry_to_ts(entry: &Entry) -> String {
output = format!(r#"return {output};"#);
};
let parse_result_xdr = if return_type == "void" {
r#"parseResultXdr: () => {}"#.to_owned()
r"parseResultXdr: () => {}".to_owned()
} else {
format!(
r#"parseResultXdr: (xdr): {return_type} => {{
r"parseResultXdr: (xdr): {return_type} => {{
{output}
}}"#
}}"
)
};
let js_name = jsify_name(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"dependencies": {
"@stellar/freighter-api": "1.5.1",
"buffer": "6.0.3",
"soroban-client": "1.0.0-beta.2"
"soroban-client": "1.0.0-beta.3"
},
"scripts": {
"build": "node ./scripts/build.mjs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {

export type Tx = Transaction<Memo<MemoType>, Operation[]>;

export class SendFailedError extends Error { }
/**
* Get account details from the Soroban network for the publicKey currently
* selected in Freighter. If not connected to Freighter, return null.
Expand Down Expand Up @@ -82,7 +83,7 @@ export async function invoke<R extends ResponseTypes, T = string>({
contractId,
wallet,
}: InvokeArgs<R, T>): Promise<T | string | SomeRpcResponse> {
wallet = wallet ?? (await import("@stellar/freighter-api"));
wallet = wallet ?? (await import("@stellar/freighter-api")).default;
let parse = parseResultXdr;
const server = new SorobanClient.Server(rpcUrl, {
allowHttp: rpcUrl.startsWith("http://"),
Expand Down Expand Up @@ -162,7 +163,11 @@ export async function invoke<R extends ResponseTypes, T = string>({
if ("returnValue" in raw) return parse(raw.returnValue!);

// otherwise, it returned the result of `sendTransaction`
if ("errorResultXdr" in raw) return parse(raw.errorResultXdr!);
if ("errorResult" in raw) {
throw new SendFailedError(
`errorResult.result(): ${JSON.stringify(raw.errorResult?.result())}`
)
}

// if neither of these are present, something went wrong
console.error("Don't know how to parse result! Returning full RPC response.");
Expand Down
10 changes: 5 additions & 5 deletions cmd/crates/soroban-test/tests/it/arg_parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fn parse_i256() {

#[test]
fn parse_bytes() {
let b = from_string_primitive(r#"beefface"#, &ScSpecTypeDef::Bytes).unwrap();
let b = from_string_primitive(r"beefface", &ScSpecTypeDef::Bytes).unwrap();
assert_eq!(
b,
ScVal::Bytes(ScBytes(vec![0xbe, 0xef, 0xfa, 0xce].try_into().unwrap()))
Expand All @@ -100,7 +100,7 @@ fn parse_bytes() {

#[test]
fn parse_bytes_when_hex_is_all_numbers() {
let b = from_string_primitive(r#"4554"#, &ScSpecTypeDef::Bytes).unwrap();
let b = from_string_primitive(r"4554", &ScSpecTypeDef::Bytes).unwrap();
assert_eq!(
b,
ScVal::Bytes(ScBytes(vec![0x45, 0x54].try_into().unwrap()))
Expand All @@ -111,7 +111,7 @@ fn parse_bytes_when_hex_is_all_numbers() {
#[test]
fn parse_bytesn() {
let b = from_string_primitive(
r#"beefface"#,
r"beefface",
&ScSpecTypeDef::BytesN(ScSpecTypeBytesN { n: 4 }),
)
.unwrap();
Expand All @@ -124,8 +124,8 @@ fn parse_bytesn() {

#[test]
fn parse_bytesn_when_hex_is_all_numbers() {
let b = from_string_primitive(r#"4554"#, &ScSpecTypeDef::BytesN(ScSpecTypeBytesN { n: 2 }))
.unwrap();
let b =
from_string_primitive(r"4554", &ScSpecTypeDef::BytesN(ScSpecTypeBytesN { n: 2 })).unwrap();
assert_eq!(
b,
ScVal::Bytes(ScBytes(vec![0x45, 0x54].try_into().unwrap()))
Expand Down
1 change: 1 addition & 0 deletions cmd/crates/soroban-test/tests/it/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ mod custom_types;
mod dotenv;
mod hello_world;
mod util;
mod wrap;
79 changes: 79 additions & 0 deletions cmd/crates/soroban-test/tests/it/integration/wrap.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
use soroban_cli::CommandParser;
use soroban_cli::{
commands::{
config::{self},
lab::token::wrap,
},
utils::contract_id_hash_from_asset,
};
use soroban_test::TestEnv;

use super::util::network_passphrase;

#[tokio::test]
#[ignore]
async fn burn() {
let sandbox = &TestEnv::default();
let address = config::identity::address::Cmd::parse("--hd-path=0")
.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 id = stellar_strkey::Contract(hash.0).to_string();
assert_eq!(
"CAMTHSPKXZJIRTUXQP5QWJIFH3XIDMKLFAWVQOFOXPTKAW5GKV37ZC4N",
id
);
assert_eq!(
"true",
sandbox
.invoke(&[
"--id",
&id,
"--",
"authorized",
"--id",
&address.to_string()
])
.await
.unwrap()
);
assert_eq!(
"\"9223372036854775807\"",
sandbox
.invoke(&["--id", &id, "--", "balance", "--id", &address.to_string()])
.await
.unwrap(),
);

println!(
"{}",
sandbox
.invoke(&[
"--id",
&id,
"--",
"burn",
"--id",
&address.to_string(),
"--amount=100"
])
.await
.unwrap()
);

assert_eq!(
"\"9223372036854775707\"",
sandbox
.invoke(&["--id", &id, "--", "balance", "--id", &address.to_string()])
.await
.unwrap(),
);
}

fn wrap_cmd(asset: &str) -> wrap::Cmd {
wrap::Cmd::parse_arg_vec(&[&format!("--asset={asset}")]).unwrap()
}
10 changes: 8 additions & 2 deletions cmd/soroban-cli/src/commands/contract/bindings/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,17 @@ pub enum Error {
Fetch(#[from] fetch::Error),
#[error(transparent)]
Spec(#[from] contract_spec::Error),
#[error(transparent)]
Wasm(#[from] wasm::Error),
#[error("Failed to get file name from path: {0:?}")]
FailedToGetFileName(PathBuf),
}

impl Cmd {
pub async fn run(&self) -> Result<(), Error> {
let spec = if let Some(wasm) = &self.wasm {
let wasm: wasm::Args = wasm.into();
wasm.parse().unwrap().spec
wasm.parse()?.spec
} else {
let fetch = contract::fetch::Cmd {
contract_id: self.contract_id.clone(),
Expand Down Expand Up @@ -100,7 +104,9 @@ impl Cmd {
.ok()
.unwrap_or_else(Network::futurenet);
let absolute_path = self.output_dir.canonicalize()?;
let file_name = absolute_path.file_name().unwrap();
let file_name = absolute_path
.file_name()
.ok_or_else(|| Error::FailedToGetFileName(absolute_path.clone()))?;
let contract_name = &file_name
.to_str()
.ok_or_else(|| Error::NotUtf8(file_name.to_os_string()))?;
Expand Down
8 changes: 3 additions & 5 deletions cmd/soroban-cli/src/commands/contract/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ pub enum Error {
Config(#[from] config::Error),
#[error(transparent)]
StrKey(#[from] stellar_strkey::DecodeError),
#[error(transparent)]
Infallible(#[from] std::convert::Infallible),
}

impl Cmd {
Expand Down Expand Up @@ -204,11 +206,7 @@ fn get_contract_id(
contract_id_preimage: ContractIdPreimage,
network_passphrase: &str,
) -> Result<Hash, Error> {
let network_id = Hash(
Sha256::digest(network_passphrase.as_bytes())
.try_into()
.unwrap(),
);
let network_id = Hash(Sha256::digest(network_passphrase.as_bytes()).try_into()?);
let preimage = HashIdPreimage::ContractId(HashIdPreimageContractId {
network_id,
contract_id_preimage,
Expand Down
16 changes: 11 additions & 5 deletions cmd/soroban-cli/src/commands/contract/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,12 @@ impl Cmd {
cmd = cmd.subcommand(build_custom_cmd(&name.to_string_lossy(), &spec)?);
}
cmd.build();
let long_help = cmd.render_long_help();
let mut matches_ = cmd.get_matches_from(&self.slop);
let (function, matches_) = &matches_.remove_subcommand().unwrap();
let Some((function, matches_)) = &matches_.remove_subcommand() else {
println!("{long_help}");
std::process::exit(1);
};

let func = spec.find_function(function)?;
// create parsed_args in same order as the inputs to func
Expand All @@ -177,7 +181,7 @@ impl Cmd {
.inputs
.iter()
.map(|i| {
let name = i.name.to_string().unwrap();
let name = i.name.to_string()?;
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) {
Expand Down Expand Up @@ -205,7 +209,10 @@ impl Cmd {
&std::fs::read(arg_path)
.map_err(|_| Error::MissingFileArg(arg_path.clone()))?,
)
.unwrap())
.map_err(|()| Error::CannotParseArg {
arg: name.clone(),
error: soroban_spec_tools::Error::Unknown,
})?)
} else {
let file_contents = std::fs::read_to_string(arg_path)
.map_err(|_| Error::MissingFileArg(arg_path.clone()))?;
Expand Down Expand Up @@ -414,7 +421,6 @@ fn build_custom_cmd(name: &str, spec: &Spec) -> Result<clap::Command, Error> {
if kebab_name != name {
cmd = cmd.alias(kebab_name);
}
let func = spec.find_function(name).unwrap();
let doc: &'static str = Box::leak(func.doc.to_string_lossy().into_boxed_str());
let long_doc: &'static str = Box::leak(arg_file_help(doc).into_boxed_str());

Expand All @@ -428,7 +434,7 @@ fn build_custom_cmd(name: &str, spec: &Spec) -> Result<clap::Command, Error> {
.alias(name.to_kebab_case())
.num_args(1)
.value_parser(clap::builder::NonEmptyStringValueParser::new())
.long_help(spec.doc(name, type_).unwrap());
.long_help(spec.doc(name, type_)?);

file_arg = file_arg
.long(&file_arg_name)
Expand Down
4 changes: 3 additions & 1 deletion cmd/soroban-cli/src/commands/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pub enum Error {
ExecutableNotFound(String, String),
#[error(transparent)]
Which(#[from] which::Error),
#[error(transparent)]
Regex(#[from] regex::Error),
}

const SUBCOMMAND_TOLERANCE: f64 = 0.75;
Expand Down Expand Up @@ -82,7 +84,7 @@ pub fn list() -> Result<Vec<String>, Error> {
} else {
r"^soroban-.*"
};
let re = regex::Regex::new(re_str).unwrap();
let re = regex::Regex::new(re_str)?;
Ok(which::which_re(re)?
.filter_map(|b| {
let s = b.file_name()?.to_str()?;
Expand Down
Loading

0 comments on commit e918b49

Please sign in to comment.