Skip to content

Commit

Permalink
fix(CLI): update xdr and bump -> extend (#1031)
Browse files Browse the repository at this point in the history
  • Loading branch information
willemneal authored Oct 23, 2023
1 parent 2d13040 commit ad28238
Show file tree
Hide file tree
Showing 52 changed files with 1,821 additions and 2,848 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ path = "cmd/soroban-cli"
version = "20.0.0-rc1"
git = "https://github.com/stellar/rs-stellar-xdr"
rev = "9c97e4fa909a0b6455547a4f4a95800696b2a69a"
default-features = false
default-features = true

[workspace.dependencies]
base64 = "0.21.2"
Expand Down
4 changes: 2 additions & 2 deletions cmd/crates/soroban-spec-json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::{fs, io};
pub mod types;

use sha2::{Digest, Sha256};
use stellar_xdr::ScSpecEntry;

use stellar_xdr::curr::ScSpecEntry;
use types::Entry;

use soroban_spec::read::{from_wasm, FromWasmError};
Expand All @@ -16,7 +16,7 @@ pub enum GenerateFromFileError {
#[error("sha256 does not match, expected: {expected}")]
VerifySha256 { expected: String },
#[error("parsing contract spec: {0}")]
Parse(stellar_xdr::Error),
Parse(stellar_xdr::curr::Error),
#[error("getting contract spec: {0}")]
GetSpec(FromWasmError),
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/crates/soroban-spec-json/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use serde::Serialize;
use stellar_xdr::{
use stellar_xdr::curr::{
ScSpecEntry, ScSpecFunctionInputV0, ScSpecTypeDef, ScSpecUdtEnumCaseV0,
ScSpecUdtErrorEnumCaseV0, ScSpecUdtStructFieldV0, ScSpecUdtUnionCaseV0,
};
Expand Down
30 changes: 13 additions & 17 deletions cmd/crates/soroban-spec-tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::str::FromStr;

use itertools::Itertools;
use serde_json::{json, Value};
use stellar_xdr::{
use stellar_xdr::curr::{
AccountId, BytesM, ContractExecutable, Error as XdrError, Hash, Int128Parts, Int256Parts,
PublicKey, ScAddress, ScBytes, ScContractInstance, ScMap, ScMapEntry, ScNonceKey, ScSpecEntry,
ScSpecFunctionV0, ScSpecTypeDef as ScType, ScSpecTypeMap, ScSpecTypeOption, ScSpecTypeResult,
Expand Down Expand Up @@ -1025,9 +1025,9 @@ pub fn to_json(v: &ScVal) -> Result<Value, Error> {
..
}) => json!({ "hash": hash }),
ScVal::ContractInstance(ScContractInstance {
executable: ContractExecutable::Token,
executable: ContractExecutable::StellarAsset,
..
}) => json!({"token": true}),
}) => json!({"SAC": true}),
ScVal::LedgerKeyNonce(ScNonceKey { nonce }) => {
Value::Number(serde_json::Number::from(*nonce))
}
Expand Down Expand Up @@ -1175,11 +1175,10 @@ impl Spec {
.iter()
.map(|f| {
Some(match f {
stellar_xdr::ScSpecUdtUnionCaseV0::VoidV0(ScSpecUdtUnionCaseVoidV0 {
name,
..
}) => name.to_string_lossy(),
stellar_xdr::ScSpecUdtUnionCaseV0::TupleV0(ScSpecUdtUnionCaseTupleV0 {
ScSpecUdtUnionCaseV0::VoidV0(ScSpecUdtUnionCaseVoidV0 { name, .. }) => {
name.to_string_lossy()
}
ScSpecUdtUnionCaseV0::TupleV0(ScSpecUdtUnionCaseTupleV0 {
name,
type_,
..
Expand Down Expand Up @@ -1331,14 +1330,11 @@ impl Spec {
.cases
.iter()
.map(|case| match case {
stellar_xdr::ScSpecUdtUnionCaseV0::VoidV0(ScSpecUdtUnionCaseVoidV0 {
name,
..
}) => Some(format!("\"{}\"", name.to_string_lossy())),
stellar_xdr::ScSpecUdtUnionCaseV0::TupleV0(ScSpecUdtUnionCaseTupleV0 {
name,
type_,
..
ScSpecUdtUnionCaseV0::VoidV0(ScSpecUdtUnionCaseVoidV0 { name, .. }) => {
Some(format!("\"{}\"", name.to_string_lossy()))
}
ScSpecUdtUnionCaseV0::TupleV0(ScSpecUdtUnionCaseTupleV0 {
name, type_, ..
}) => {
if type_.len() == 1 {
let single = self.example(&type_[0])?;
Expand All @@ -1362,7 +1358,7 @@ impl Spec {
mod tests {
use super::*;

use stellar_xdr::ScSpecTypeBytesN;
use stellar_xdr::curr::ScSpecTypeBytesN;

#[test]
fn from_json_primitives_bytesn() {
Expand Down
13 changes: 5 additions & 8 deletions cmd/crates/soroban-spec-tools/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
io::{self, Cursor},
};

use stellar_xdr::{
use stellar_xdr::curr::{
DepthLimitedRead, ReadXdr, ScEnvMetaEntry, ScMetaEntry, ScMetaV0, ScSpecEntry,
ScSpecFunctionV0, ScSpecUdtEnumV0, ScSpecUdtErrorEnumV0, ScSpecUdtStructV0, ScSpecUdtUnionV0,
StringM,
Expand Down Expand Up @@ -33,7 +33,7 @@ pub enum Error {
error: wasmparser::BinaryReaderError,
},
#[error("xdr processing error: {0}")]
Xdr(#[from] stellar_xdr::Error),
Xdr(#[from] stellar_xdr::curr::Error),

#[error(transparent)]
Parser(#[from] wasmparser::BinaryReaderError),
Expand Down Expand Up @@ -62,8 +62,7 @@ impl ContractSpec {
env_meta_base64 = Some(base64.encode(env_meta));
let cursor = Cursor::new(env_meta);
let mut depth_limit_read = DepthLimitedRead::new(cursor, 100);
ScEnvMetaEntry::read_xdr_iter(&mut depth_limit_read)
.collect::<Result<Vec<_>, stellar_xdr::Error>>()?
ScEnvMetaEntry::read_xdr_iter(&mut depth_limit_read).collect::<Result<Vec<_>, _>>()?
} else {
vec![]
};
Expand All @@ -73,8 +72,7 @@ impl ContractSpec {
meta_base64 = Some(base64.encode(meta));
let cursor = Cursor::new(meta);
let mut depth_limit_read = DepthLimitedRead::new(cursor, 100);
ScMetaEntry::read_xdr_iter(&mut depth_limit_read)
.collect::<Result<Vec<_>, stellar_xdr::Error>>()?
ScMetaEntry::read_xdr_iter(&mut depth_limit_read).collect::<Result<Vec<_>, _>>()?
} else {
vec![]
};
Expand All @@ -84,8 +82,7 @@ impl ContractSpec {
spec_base64 = Some(base64.encode(spec));
let cursor = Cursor::new(spec);
let mut depth_limit_read = DepthLimitedRead::new(cursor, 100);
ScSpecEntry::read_xdr_iter(&mut depth_limit_read)
.collect::<Result<Vec<_>, stellar_xdr::Error>>()?
ScSpecEntry::read_xdr_iter(&mut depth_limit_read).collect::<Result<Vec<_>, _>>()?
} else {
vec![]
};
Expand Down
2 changes: 1 addition & 1 deletion cmd/crates/soroban-spec-typescript/src/boilerplate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
io::Write,
path::{Path, PathBuf},
};
use stellar_xdr::ScSpecEntry;
use stellar_xdr::curr::ScSpecEntry;

use super::generate;

Expand Down
4 changes: 2 additions & 2 deletions cmd/crates/soroban-spec-typescript/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::types::Type;
use heck::ToLowerCamelCase;
use itertools::Itertools;
use sha2::{Digest, Sha256};
use stellar_xdr::{ScSpecEntry, WriteXdr};
use stellar_xdr::curr::{ScSpecEntry, WriteXdr};

use types::Entry;

Expand All @@ -27,7 +27,7 @@ pub enum GenerateFromFileError {
#[error("sha256 does not match, expected: {expected}")]
VerifySha256 { expected: String },
#[error("parsing contract spec: {0}")]
Parse(stellar_xdr::Error),
Parse(stellar_xdr::curr::Error),
#[error("getting contract spec: {0}")]
GetSpec(FromWasmError),
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/crates/soroban-spec-typescript/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use serde::Serialize;
use stellar_xdr::{
use stellar_xdr::curr::{
ScSpecEntry, ScSpecFunctionInputV0, ScSpecTypeDef, ScSpecUdtEnumCaseV0,
ScSpecUdtErrorEnumCaseV0, ScSpecUdtStructFieldV0, ScSpecUdtStructV0, ScSpecUdtUnionCaseV0,
};
Expand Down
3 changes: 3 additions & 0 deletions cmd/crates/soroban-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ fs_extra = "1.3.0"
serde_json = "1.0.93"
which = { workspace = true }
tokio = "1.28.1"

[features]
integration = []
11 changes: 6 additions & 5 deletions cmd/crates/soroban-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl TestEnv {
/// ```rust,no_run
/// use soroban_test::TestEnv;
/// TestEnv::with_default(|env| {
/// env.invoke(&["--id", "1", "--", "hello", "--world=world"]).unwrap();
/// env.new_assert_cmd("contract").args(&["invoke", "--id", "1", "--", "hello", "--world=world"]).assert().success();
/// });
/// ```
///
Expand Down Expand Up @@ -122,7 +122,7 @@ impl TestEnv {
}

/// A convenience method for using the invoke command.
pub fn invoke<I: AsRef<str>>(&self, command_str: &[I]) -> Result<String, invoke::Error> {
pub async fn invoke<I: AsRef<str>>(&self, command_str: &[I]) -> Result<String, invoke::Error> {
let cmd = contract::invoke::Cmd::parse_arg_vec(
&command_str
.iter()
Expand All @@ -131,13 +131,13 @@ impl TestEnv {
.collect::<Vec<_>>(),
)
.unwrap();
self.invoke_cmd(cmd)
self.invoke_cmd(cmd).await
}

/// Invoke an already parsed invoke command
pub fn invoke_cmd(&self, mut cmd: invoke::Cmd) -> Result<String, invoke::Error> {
pub async fn invoke_cmd(&self, mut cmd: invoke::Cmd) -> Result<String, invoke::Error> {
cmd.set_pwd(self.dir());
cmd.run_in_sandbox(&global::Args {
cmd.run_against_rpc_server(&global::Args {
locator: config::locator::Args {
global: false,
config_dir: None,
Expand All @@ -148,6 +148,7 @@ impl TestEnv {
very_verbose: false,
list: false,
})
.await
}

/// Reference to current directory of the `TestEnv`.
Expand Down
24 changes: 2 additions & 22 deletions cmd/crates/soroban-test/tests/it/config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use assert_fs::TempDir;
use soroban_test::{temp_ledger_file, TestEnv};
use soroban_test::TestEnv;
use std::{fs, path::Path};

use crate::util::{add_identity, add_test_id, SecretKind, DEFAULT_SEED_PHRASE, HELLO_WORLD};
use crate::util::{add_identity, add_test_id, SecretKind, DEFAULT_SEED_PHRASE};
use soroban_cli::commands::config::network;

const NETWORK_PASSPHRASE: &str = "Local Sandbox Stellar Network ; September 2022";
Expand Down Expand Up @@ -205,26 +205,6 @@ fn seed_phrase() {
.stdout("test_seed\n");
}

#[test]
fn use_different_ledger_file() {
let sandbox = TestEnv::default();
sandbox
.new_assert_cmd("contract")
.arg("invoke")
.arg("--id=1")
.arg("--wasm")
.arg(HELLO_WORLD.path())
.arg("--ledger-file")
.arg(temp_ledger_file())
.arg("--")
.arg("hello")
.arg("--world=world")
.assert()
.stdout("[\"Hello\",\"world\"]\n")
.success();
assert!(fs::read(sandbox.dir().join(".soroban/ledger.json")).is_err());
}

#[test]
fn read_address() {
let sandbox = TestEnv::default();
Expand Down
Loading

0 comments on commit ad28238

Please sign in to comment.